epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2011 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
tfarina@chromium.org | 9f9d582 | 2013-12-18 22:15:12 +0000 | [diff] [blame^] | 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" |
tfarina@chromium.org | 9f9d582 | 2013-12-18 22:15:12 +0000 | [diff] [blame^] | 13 | DEFINE_TESTCLASS_SHORT(MyTestFunction) |
reed@android.com | 80e39a7 | 2009-04-02 16:59:40 +0000 | [diff] [blame] | 14 | |
tfarina@chromium.org | 9f9d582 | 2013-12-18 22:15:12 +0000 | [diff] [blame^] | 15 | where MyTestFunction is declared as: |
reed@android.com | 80e39a7 | 2009-04-02 16:59:40 +0000 | [diff] [blame] | 16 | |
tfarina@chromium.org | 9f9d582 | 2013-12-18 22:15:12 +0000 | [diff] [blame^] | 17 | static void MyTestFunction(skiatest::Reporter* reporter) { |
| 18 | } |
reed@android.com | d8730ea | 2009-02-27 22:06:06 +0000 | [diff] [blame] | 19 | */ |
| 20 | |
caryclark@google.com | ad65a3e | 2013-04-15 19:13:59 +0000 | [diff] [blame] | 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_GPUTESTCLASS(uiname, classname, function) \ |
| 34 | namespace skiatest { \ |
| 35 | class classname : public GpuTest { \ |
| 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 { \ |
| 41 | function(reporter, GetGrContextFactory()); \ |
| 42 | } \ |
| 43 | }; \ |
junov@chromium.org | 995beb6 | 2013-03-28 13:49:22 +0000 | [diff] [blame] | 44 | static TestRegistry gReg_##classname(classname::Factory); \ |
bsalomon@google.com | a8e686e | 2011-08-16 15:45:58 +0000 | [diff] [blame] | 45 | } |
mtklein@google.com | 014f2c4 | 2013-09-19 20:56:46 +0000 | [diff] [blame] | 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) |