| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 /* This file is meant to be included by .cpp files, so it can spew out a | 8 /* This file is meant to be included by .cpp files, so it can spew out a |
| 9 customized class + global definition. | 9 customized class + global definition. |
| 10 | 10 |
| 11 e.g. | 11 e.g. |
| 12 #include "TestClassDef.h" | 12 #include "TestClassDef.h" |
| 13 DEFINE_TESTCLASS_SHORT(MyTestFunction) | |
| 14 | 13 |
| 15 where MyTestFunction is declared as: | 14 DEF_TEST(some_test_name, r) { |
| 16 | 15 ... |
| 17 static void MyTestFunction(skiatest::Reporter* reporter) { | 16 REPORTER_ASSERT(r, x == 15); |
| 18 } | 17 } |
| 19 */ | 18 */ |
| 20 | 19 |
| 21 #define DEFINE_TESTCLASS_SHORT(function)
\ | 20 #define DEF_TEST(name, reporter)
\ |
| 22 namespace skiatest {
\ | 21 static void name(skiatest::Reporter* reporter);
\ |
| 23 class function##Class : public Test {
\ | 22 namespace skiatest {
\ |
| 24 public:
\ | 23 class name##Class : public Test {
\ |
| 25 static Test* Factory(void*) { return SkNEW(function##Class); }
\ | 24 public:
\ |
| 26 protected:
\ | 25 static Test* Factory(void*) { return SkNEW(name##Class); }
\ |
| 27 virtual void onGetName(SkString* name) SK_OVERRIDE { name->set(#func
tion); } \ | 26 protected:
\ |
| 28 virtual void onRun(Reporter* reporter) SK_OVERRIDE { function(report
er); } \ | 27 virtual void onGetName(SkString* name) SK_OVERRIDE { name->set(#name
); } \ |
| 29 };
\ | 28 virtual void onRun(Reporter* reporter) SK_OVERRIDE { name(reporter);
} \ |
| 30 static TestRegistry gReg_##function##Class(function##Class::Factory);
\ | 29 };
\ |
| 31 } | 30 static TestRegistry gReg_##name##Class(name##Class::Factory);
\ |
| 31 }
\ |
| 32 static void name(skiatest::Reporter* reporter) |
| 32 | 33 |
| 33 #define DEFINE_GPUTESTCLASS(uiname, classname, function)
\ | 34 #define DEFINE_GPUTESTCLASS(uiname, classname, function)
\ |
| 34 namespace skiatest {
\ | 35 namespace skiatest {
\ |
| 35 class classname : public GpuTest {
\ | 36 class classname : public GpuTest {
\ |
| 36 public:
\ | 37 public:
\ |
| 37 static Test* Factory(void*) { return SkNEW(classname); }
\ | 38 static Test* Factory(void*) { return SkNEW(classname); }
\ |
| 38 protected:
\ | 39 protected:
\ |
| 39 virtual void onGetName(SkString* name) SK_OVERRIDE { name->set(uinam
e); } \ | 40 virtual void onGetName(SkString* name) SK_OVERRIDE { name->set(uinam
e); } \ |
| 40 virtual void onRun(Reporter* reporter) SK_OVERRIDE {
\ | 41 virtual void onRun(Reporter* reporter) SK_OVERRIDE {
\ |
| 41 function(reporter, GetGrContextFactory());
\ | 42 function(reporter, GetGrContextFactory());
\ |
| 42 }
\ | 43 }
\ |
| 43 };
\ | 44 };
\ |
| 44 static TestRegistry gReg_##classname(classname::Factory);
\ | 45 static TestRegistry gReg_##classname(classname::Factory);
\ |
| 45 } | 46 } |
| 46 | |
| 47 | |
| 48 // Yet shorter way to define a test. E.g. | |
| 49 // | |
| 50 // DEF_TEST(some_test_name, r) { | |
| 51 // ... | |
| 52 // REPORTER_ASSERT(r, x == 15); | |
| 53 // } | |
| 54 #define DEF_TEST(name, reporter) \ | |
| 55 static void name(skiatest::Reporter* reporter); \ | |
| 56 DEFINE_TESTCLASS_SHORT(name) \ | |
| 57 static void name(skiatest::Reporter* reporter) | |
| OLD | NEW |