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 | ed67331 | 2009-02-27 16:24:51 +0000 | [diff] [blame] | 8 | #ifndef skiatest_Test_DEFINED |
| 9 | #define skiatest_Test_DEFINED |
| 10 | |
reed@android.com | ed67331 | 2009-02-27 16:24:51 +0000 | [diff] [blame] | 11 | #include "SkString.h" |
| 12 | #include "SkTRegistry.h" |
commit-bot@chromium.org | 0506b9d | 2013-04-22 16:43:07 +0000 | [diff] [blame] | 13 | #include "SkTypes.h" |
reed@android.com | ed67331 | 2009-02-27 16:24:51 +0000 | [diff] [blame] | 14 | |
bsalomon@google.com | 67b915d | 2013-02-04 16:13:32 +0000 | [diff] [blame] | 15 | class GrContextFactory; |
bsalomon@google.com | a8e686e | 2011-08-16 15:45:58 +0000 | [diff] [blame] | 16 | |
reed@android.com | ed67331 | 2009-02-27 16:24:51 +0000 | [diff] [blame] | 17 | namespace skiatest { |
reed@android.com | 80e39a7 | 2009-04-02 16:59:40 +0000 | [diff] [blame] | 18 | |
halcanary | 87f3ba4 | 2015-01-20 09:30:20 -0800 | [diff] [blame] | 19 | SkString GetTmpDir(); |
reed@android.com | ed67331 | 2009-02-27 16:24:51 +0000 | [diff] [blame] | 20 | |
halcanary | 87f3ba4 | 2015-01-20 09:30:20 -0800 | [diff] [blame] | 21 | struct 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 | }; |
scroggo | 0ee2627 | 2014-11-07 06:07:32 -0800 | [diff] [blame] | 30 | |
halcanary | 87f3ba4 | 2015-01-20 09:30:20 -0800 | [diff] [blame] | 31 | class Reporter : SkNoncopyable { |
| 32 | public: |
| 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 | }; |
scroggo | 0ee2627 | 2014-11-07 06:07:32 -0800 | [diff] [blame] | 39 | |
halcanary | 87f3ba4 | 2015-01-20 09:30:20 -0800 | [diff] [blame] | 40 | #define REPORT_FAILURE(reporter, cond, message) \ |
| 41 | reporter->reportFailed(skiatest::Failure(__FILE__, __LINE__, cond, message)) |
scroggo | 0ee2627 | 2014-11-07 06:07:32 -0800 | [diff] [blame] | 42 | |
halcanary | 87f3ba4 | 2015-01-20 09:30:20 -0800 | [diff] [blame] | 43 | typedef void (*TestProc)(skiatest::Reporter*, GrContextFactory*); |
reed@android.com | ed67331 | 2009-02-27 16:24:51 +0000 | [diff] [blame] | 44 | |
halcanary | 87f3ba4 | 2015-01-20 09:30:20 -0800 | [diff] [blame] | 45 | struct 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.com | ed67331 | 2009-02-27 16:24:51 +0000 | [diff] [blame] | 51 | |
halcanary | 87f3ba4 | 2015-01-20 09:30:20 -0800 | [diff] [blame] | 52 | typedef SkTRegistry<Test> TestRegistry; |
commit-bot@chromium.org | e2eac8b | 2014-01-14 21:04:37 +0000 | [diff] [blame] | 53 | |
| 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 | */ |
halcanary | 87f3ba4 | 2015-01-20 09:30:20 -0800 | [diff] [blame] | 72 | } // namespace skiatest |
reed@android.com | ed67331 | 2009-02-27 16:24:51 +0000 | [diff] [blame] | 73 | |
halcanary | 87f3ba4 | 2015-01-20 09:30:20 -0800 | [diff] [blame] | 74 | #define REPORTER_ASSERT(r, cond) \ |
| 75 | do { \ |
| 76 | if (!(cond)) { \ |
| 77 | REPORT_FAILURE(r, #cond, SkString()); \ |
| 78 | } \ |
| 79 | } while (0) |
reed@android.com | ed67331 | 2009-02-27 16:24:51 +0000 | [diff] [blame] | 80 | |
halcanary | 87f3ba4 | 2015-01-20 09:30:20 -0800 | [diff] [blame] | 81 | #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.org | 1cc8f6f | 2012-02-22 21:00:42 +0000 | [diff] [blame] | 87 | |
halcanary | 87f3ba4 | 2015-01-20 09:30:20 -0800 | [diff] [blame] | 88 | #define ERRORF(r, ...) \ |
| 89 | do { \ |
| 90 | REPORT_FAILURE(r, "", SkStringPrintf(__VA_ARGS__)); \ |
| 91 | } while (0) |
reed@android.com | ed67331 | 2009-02-27 16:24:51 +0000 | [diff] [blame] | 92 | |
halcanary | 87f3ba4 | 2015-01-20 09:30:20 -0800 | [diff] [blame] | 93 | #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.org | e2eac8b | 2014-01-14 21:04:37 +0000 | [diff] [blame] | 98 | |
halcanary | 87f3ba4 | 2015-01-20 09:30:20 -0800 | [diff] [blame] | 99 | #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.org | e2eac8b | 2014-01-14 21:04:37 +0000 | [diff] [blame] | 104 | |
reed@android.com | ed67331 | 2009-02-27 16:24:51 +0000 | [diff] [blame] | 105 | #endif |