epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | |
| 2 | /* |
| 3 | * Copyright 2011 Google Inc. |
| 4 | * |
| 5 | * Use of this source code is governed by a BSD-style license that can be |
| 6 | * found in the LICENSE file. |
| 7 | */ |
reed@android.com | 80e39a7 | 2009-04-02 16:59:40 +0000 | [diff] [blame] | 8 | /* This file is meant to be included by .cpp files, so it can spew out a |
reed@android.com | d8730ea | 2009-02-27 22:06:06 +0000 | [diff] [blame] | 9 | customized class + global definition. |
reed@android.com | 80e39a7 | 2009-04-02 16:59:40 +0000 | [diff] [blame] | 10 | |
reed@android.com | d8730ea | 2009-02-27 22:06:06 +0000 | [diff] [blame] | 11 | e.g. |
| 12 | #include "TestClassDef.h" |
| 13 | DEFINE_TESTCLASS("MyTest", MyTestClass, MyTestFunction) |
reed@android.com | 80e39a7 | 2009-04-02 16:59:40 +0000 | [diff] [blame] | 14 | |
reed@android.com | d8730ea | 2009-02-27 22:06:06 +0000 | [diff] [blame] | 15 | where MyTestFunction is declared as |
reed@android.com | 80e39a7 | 2009-04-02 16:59:40 +0000 | [diff] [blame] | 16 | |
reed@android.com | d8730ea | 2009-02-27 22:06:06 +0000 | [diff] [blame] | 17 | void MyTestFunction(skiatest::Reporter*) |
| 18 | */ |
| 19 | |
caryclark@google.com | ad65a3e | 2013-04-15 19:13:59 +0000 | [diff] [blame] | 20 | // FIXME: replace all three param callers with the short one param version |
| 21 | #define DEFINE_TESTCLASS_SHORT(function) \ |
| 22 | namespace skiatest { \ |
| 23 | class function##Class : public Test { \ |
| 24 | public: \ |
| 25 | static Test* Factory(void*) { return SkNEW(function##Class); } \ |
| 26 | protected: \ |
| 27 | virtual void onGetName(SkString* name) SK_OVERRIDE { name->set(#function); } \ |
| 28 | virtual void onRun(Reporter* reporter) SK_OVERRIDE { function(reporter); } \ |
| 29 | }; \ |
| 30 | static TestRegistry gReg_##function##Class(function##Class::Factory); \ |
| 31 | } |
| 32 | |
bsalomon@google.com | 67b915d | 2013-02-04 16:13:32 +0000 | [diff] [blame] | 33 | #define DEFINE_TESTCLASS(uiname, classname, function) \ |
| 34 | namespace skiatest { \ |
| 35 | class classname : public Test { \ |
| 36 | public: \ |
| 37 | static Test* Factory(void*) { return SkNEW(classname); } \ |
| 38 | protected: \ |
| 39 | virtual void onGetName(SkString* name) SK_OVERRIDE { name->set(uiname); } \ |
| 40 | virtual void onRun(Reporter* reporter) SK_OVERRIDE { function(reporter); } \ |
| 41 | }; \ |
junov@chromium.org | 995beb6 | 2013-03-28 13:49:22 +0000 | [diff] [blame] | 42 | static TestRegistry gReg_##classname(classname::Factory); \ |
reed@android.com | d8730ea | 2009-02-27 22:06:06 +0000 | [diff] [blame] | 43 | } |
| 44 | |
bsalomon@google.com | 67b915d | 2013-02-04 16:13:32 +0000 | [diff] [blame] | 45 | #define DEFINE_GPUTESTCLASS(uiname, classname, function) \ |
| 46 | namespace skiatest { \ |
| 47 | class classname : public GpuTest { \ |
| 48 | public: \ |
| 49 | static Test* Factory(void*) { return SkNEW(classname); } \ |
| 50 | protected: \ |
| 51 | virtual void onGetName(SkString* name) SK_OVERRIDE { name->set(uiname); } \ |
| 52 | virtual void onRun(Reporter* reporter) SK_OVERRIDE { \ |
| 53 | function(reporter, GetGrContextFactory()); \ |
| 54 | } \ |
| 55 | }; \ |
junov@chromium.org | 995beb6 | 2013-03-28 13:49:22 +0000 | [diff] [blame] | 56 | static TestRegistry gReg_##classname(classname::Factory); \ |
bsalomon@google.com | a8e686e | 2011-08-16 15:45:58 +0000 | [diff] [blame] | 57 | } |
mtklein@google.com | 014f2c4 | 2013-09-19 20:56:46 +0000 | [diff] [blame] | 58 | |
| 59 | |
| 60 | // Yet shorter way to define a test. E.g. |
| 61 | // |
| 62 | // DEF_TEST(some_test_name, r) { |
| 63 | // ... |
| 64 | // REPORTER_ASSERT(r, x == 15); |
| 65 | // } |
| 66 | #define DEF_TEST(name, reporter) \ |
| 67 | static void name(skiatest::Reporter* reporter); \ |
| 68 | DEFINE_TESTCLASS_SHORT(name) \ |
| 69 | static void name(skiatest::Reporter* reporter) |