blob: ed5de0f8607201e818c2abdca6d436164359e787 [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.comed673312009-02-27 16:24:51 +00008#ifndef skiatest_Test_DEFINED
9#define skiatest_Test_DEFINED
10
reed@android.comed673312009-02-27 16:24:51 +000011#include "SkString.h"
12#include "SkTRegistry.h"
commit-bot@chromium.org0506b9d2013-04-22 16:43:07 +000013#include "SkTypes.h"
reed@android.comed673312009-02-27 16:24:51 +000014
bsalomon@google.com67b915d2013-02-04 16:13:32 +000015class GrContextFactory;
bsalomon@google.coma8e686e2011-08-16 15:45:58 +000016
reed@android.comed673312009-02-27 16:24:51 +000017namespace skiatest {
reed@android.com80e39a72009-04-02 16:59:40 +000018
halcanary87f3ba42015-01-20 09:30:20 -080019SkString GetTmpDir();
reed@android.comed673312009-02-27 16:24:51 +000020
halcanary87f3ba42015-01-20 09:30:20 -080021struct Failure {
22 Failure(const char* f, int l, const char* c, const SkString& m)
23 : fileName(f), lineNo(l), condition(c), message(m) {}
24 const char* fileName;
25 int lineNo;
26 const char* condition;
27 SkString message;
28 SkString toString() const;
29};
scroggo0ee26272014-11-07 06:07:32 -080030
halcanary87f3ba42015-01-20 09:30:20 -080031class Reporter : SkNoncopyable {
32public:
33 virtual ~Reporter() {}
34 virtual void bumpTestCount();
35 virtual void reportFailed(const skiatest::Failure&) = 0;
36 virtual bool allowExtendedTest() const;
37 virtual bool verbose() const;
38};
scroggo0ee26272014-11-07 06:07:32 -080039
halcanary87f3ba42015-01-20 09:30:20 -080040#define REPORT_FAILURE(reporter, cond, message) \
41 reporter->reportFailed(skiatest::Failure(__FILE__, __LINE__, cond, message))
scroggo0ee26272014-11-07 06:07:32 -080042
halcanary87f3ba42015-01-20 09:30:20 -080043typedef void (*TestProc)(skiatest::Reporter*, GrContextFactory*);
reed@android.comed673312009-02-27 16:24:51 +000044
halcanary87f3ba42015-01-20 09:30:20 -080045struct Test {
46 Test(const char* n, bool g, TestProc p) : name(n), needsGpu(g), proc(p) {}
47 const char* name;
48 bool needsGpu;
49 TestProc proc;
50};
reed@android.comed673312009-02-27 16:24:51 +000051
halcanary87f3ba42015-01-20 09:30:20 -080052typedef SkTRegistry<Test> TestRegistry;
commit-bot@chromium.orge2eac8b2014-01-14 21:04:37 +000053
54/*
55 Use the following macros to make use of the skiatest classes, e.g.
56
57 #include "Test.h"
58
59 DEF_TEST(TestName, reporter) {
60 ...
61 REPORTER_ASSERT(reporter, x == 15);
62 ...
63 REPORTER_ASSERT_MESSAGE(reporter, x == 15, "x should be 15");
64 ...
65 if (x != 15) {
66 ERRORF(reporter, "x should be 15, but is %d", x);
67 return;
68 }
69 ...
70 }
71*/
halcanary87f3ba42015-01-20 09:30:20 -080072} // namespace skiatest
reed@android.comed673312009-02-27 16:24:51 +000073
halcanary87f3ba42015-01-20 09:30:20 -080074#define REPORTER_ASSERT(r, cond) \
75 do { \
76 if (!(cond)) { \
77 REPORT_FAILURE(r, #cond, SkString()); \
78 } \
79 } while (0)
reed@android.comed673312009-02-27 16:24:51 +000080
halcanary87f3ba42015-01-20 09:30:20 -080081#define REPORTER_ASSERT_MESSAGE(r, cond, message) \
82 do { \
83 if (!(cond)) { \
84 REPORT_FAILURE(r, #cond, SkString(message)); \
85 } \
86 } while (0)
junov@chromium.org1cc8f6f2012-02-22 21:00:42 +000087
halcanary87f3ba42015-01-20 09:30:20 -080088#define ERRORF(r, ...) \
89 do { \
90 REPORT_FAILURE(r, "", SkStringPrintf(__VA_ARGS__)); \
91 } while (0)
reed@android.comed673312009-02-27 16:24:51 +000092
halcanary87f3ba42015-01-20 09:30:20 -080093#define DEF_TEST(name, reporter) \
94 static void test_##name(skiatest::Reporter*, GrContextFactory*); \
95 skiatest::TestRegistry name##TestRegistry( \
96 skiatest::Test(#name, false, test_##name)); \
97 void test_##name(skiatest::Reporter* reporter, GrContextFactory*)
commit-bot@chromium.orge2eac8b2014-01-14 21:04:37 +000098
halcanary87f3ba42015-01-20 09:30:20 -080099#define DEF_GPUTEST(name, reporter, factory) \
100 static void test_##name(skiatest::Reporter*, GrContextFactory*); \
101 skiatest::TestRegistry name##TestRegistry( \
102 skiatest::Test(#name, true, test_##name)); \
103 void test_##name(skiatest::Reporter* reporter, GrContextFactory* factory)
commit-bot@chromium.orge2eac8b2014-01-14 21:04:37 +0000104
reed@android.comed673312009-02-27 16:24:51 +0000105#endif