179a8f5f7f
Add support for feeding the tests with contexts directly to the unit test framework. This fixes the problem where tests are more complex than needed just in order to run the test code with multiple backends. Also makes it possible to change the logic how contexts are created. Instead of direct numbering, the different testable contexts may be generated from filtered cross-product of context options. For example: currently NVPR is a type of context. However, it could be also an on/off feature of any context. In order to test this kind of context, the enumeration can not be just of context type. It's simpler to move the enumeration out of the tests. A test targeting both normal and GPU backends would look like: static void test_obj_behavior(skiatest::Reporter* reporter, SkObj* obj, [other params] ) { ... test with obj and param .. } DEF_TEST(ObjBehavior, reporter) { for (auto& object : generate_object) { for (auto& other_param : generate_other_variant) { test_obj_behavior(reporter, object, other_param); } } } #if SK_SUPPORT_GPU DEF_GPUTEST_FOR_ALL_CONTEXTS(ObjBehavior_Gpu, reporter, context) { for (auto& object : generate_gpu_object) { for (auto& other_param : generate_other_variant) { test_obj_behavior(reporter, object, other_param); } } } #endif Uses the feature in SurfaceTests as an example. Moves SkSurface -related tests from ImageTest to SurfaceTest. BUG=skia:2992 Review URL: https://codereview.chromium.org/1446453003
76 lines
2.4 KiB
C++
76 lines
2.4 KiB
C++
/*
|
|
* Copyright 2015 Google Inc.
|
|
*
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
* found in the LICENSE file.
|
|
*/
|
|
|
|
#include "Test.h"
|
|
|
|
#if SK_SUPPORT_GPU
|
|
#include "GrContext.h"
|
|
#include "gl/SkGLContext.h"
|
|
#endif
|
|
|
|
|
|
// This is an example of a normal test.
|
|
DEF_TEST(TestNormal, reporter) {
|
|
REPORTER_ASSERT(reporter, reporter);
|
|
}
|
|
|
|
// This is an example of a GPU test that uses common GrContextFactory factory to do the test.
|
|
#if SK_SUPPORT_GPU
|
|
DEF_GPUTEST(TestGpuFactory, reporter, factory) {
|
|
REPORTER_ASSERT(reporter, reporter);
|
|
REPORTER_ASSERT(reporter, factory);
|
|
}
|
|
#endif
|
|
|
|
// This is an example of a GPU test that tests a property that should work for all GPU contexts.
|
|
// Note: Some of the contexts might not produce a rendering output.
|
|
#if SK_SUPPORT_GPU
|
|
DEF_GPUTEST_FOR_ALL_CONTEXTS(TestGpuAllContexts, reporter, context) {
|
|
REPORTER_ASSERT(reporter, reporter);
|
|
REPORTER_ASSERT(reporter, context);
|
|
}
|
|
#endif
|
|
|
|
// This is an example of a GPU test that tests a property that should work for all GPU contexts that
|
|
// produce a rendering output.
|
|
#if SK_SUPPORT_GPU
|
|
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(TestGpuRenderingContexts, reporter, context) {
|
|
REPORTER_ASSERT(reporter, reporter);
|
|
REPORTER_ASSERT(reporter, context);
|
|
}
|
|
#endif
|
|
|
|
// This is an example of a GPU test that tests a property that should work at least for the native
|
|
// GPU context. If the test takes a long time to run, it may be appropriate to test only the native
|
|
// context.
|
|
#if SK_SUPPORT_GPU
|
|
DEF_GPUTEST_FOR_NATIVE_CONTEXT(TestGpuNativeContext, reporter, context) {
|
|
REPORTER_ASSERT(reporter, reporter);
|
|
REPORTER_ASSERT(reporter, context);
|
|
}
|
|
#endif
|
|
|
|
// This is an example of a GPU test that tests a property that uses the null GPU context. It should
|
|
// be used if the test tests some behavior that is mocked with the null context.
|
|
#if SK_SUPPORT_GPU
|
|
DEF_GPUTEST_FOR_NULL_CONTEXT(TestGpuNullContext, reporter, context) {
|
|
REPORTER_ASSERT(reporter, reporter);
|
|
REPORTER_ASSERT(reporter, context);
|
|
}
|
|
#endif
|
|
|
|
// This is an example of a GPU test that tests a property that should work for all GPU contexts.
|
|
// It uses the additional SkGLContext* glContext to implement the test.
|
|
#if SK_SUPPORT_GPU
|
|
DEF_GPUTEST_FOR_ALL_CONTEXTS(TestGpuGrContextAndGLContext, reporter, context, glContext) {
|
|
REPORTER_ASSERT(reporter, reporter);
|
|
REPORTER_ASSERT(reporter, context);
|
|
REPORTER_ASSERT(reporter, glContext);
|
|
}
|
|
#endif
|
|
|