blob: 89124c78faa8b8f063975f52e1b32fbc2cf91195 [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001
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.com80e39a72009-04-02 16:59:40 +00008/* This file is meant to be included by .cpp files, so it can spew out a
reed@android.comd8730ea2009-02-27 22:06:06 +00009 customized class + global definition.
reed@android.com80e39a72009-04-02 16:59:40 +000010
reed@android.comd8730ea2009-02-27 22:06:06 +000011 e.g.
12 #include "TestClassDef.h"
13 DEFINE_TESTCLASS("MyTest", MyTestClass, MyTestFunction)
reed@android.com80e39a72009-04-02 16:59:40 +000014
reed@android.comd8730ea2009-02-27 22:06:06 +000015 where MyTestFunction is declared as
reed@android.com80e39a72009-04-02 16:59:40 +000016
reed@android.comd8730ea2009-02-27 22:06:06 +000017 void MyTestFunction(skiatest::Reporter*)
18*/
19
caryclark@google.comad65a3e2013-04-15 19:13:59 +000020// 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.com67b915d2013-02-04 16:13:32 +000033#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.org995beb62013-03-28 13:49:22 +000042 static TestRegistry gReg_##classname(classname::Factory); \
reed@android.comd8730ea2009-02-27 22:06:06 +000043 }
44
bsalomon@google.com67b915d2013-02-04 16:13:32 +000045#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.org995beb62013-03-28 13:49:22 +000056 static TestRegistry gReg_##classname(classname::Factory); \
bsalomon@google.coma8e686e2011-08-16 15:45:58 +000057 }
mtklein@google.com014f2c42013-09-19 20:56:46 +000058
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)