OLD | NEW |
1 | |
2 /* | 1 /* |
3 * Copyright 2013 Google Inc. | 2 * Copyright 2013 Google Inc. |
4 * | 3 * |
5 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 5 * found in the LICENSE file. |
7 */ | 6 */ |
| 7 |
8 #include "Test.h" | 8 #include "Test.h" |
| 9 #include "TestClassDef.h" |
9 #include "SkError.h" | 10 #include "SkError.h" |
10 #include "SkPath.h" | 11 #include "SkPath.h" |
11 #include "SkRect.h" | 12 #include "SkRect.h" |
12 | 13 |
13 typedef struct { | 14 typedef struct { |
14 skiatest::Reporter *fReporter; | 15 skiatest::Reporter *fReporter; |
15 unsigned int *fIntPointer; | 16 unsigned int *fIntPointer; |
16 } ErrorContext; | 17 } ErrorContext; |
17 | 18 |
18 #define CHECK(errcode) \ | 19 #define CHECK(errcode) \ |
19 REPORTER_ASSERT( reporter, (err = SkGetLastError()) == errcode); \ | 20 REPORTER_ASSERT( reporter, (err = SkGetLastError()) == errcode); \ |
20 if (err != kNoError_SkError) \ | 21 if (err != kNoError_SkError) \ |
21 { \ | 22 { \ |
22 SkClearLastError(); \ | 23 SkClearLastError(); \ |
23 } | 24 } |
24 | 25 |
25 static void cb(SkError err, void *context) { | 26 static void cb(SkError err, void *context) { |
26 ErrorContext *context_ptr = static_cast<ErrorContext *>(context); | 27 ErrorContext *context_ptr = static_cast<ErrorContext *>(context); |
27 REPORTER_ASSERT( context_ptr->fReporter, (*(context_ptr->fIntPointer) == 0xd
eadbeef) ); | 28 REPORTER_ASSERT( context_ptr->fReporter, (*(context_ptr->fIntPointer) == 0xd
eadbeef) ); |
28 } | 29 } |
29 | 30 |
30 static void ErrorTest(skiatest::Reporter* reporter) { | 31 DEF_TEST(Error, reporter) { |
31 SkError err; | 32 SkError err; |
32 | 33 |
33 unsigned int test_value = 0xdeadbeef; | 34 unsigned int test_value = 0xdeadbeef; |
34 ErrorContext context; | 35 ErrorContext context; |
35 context.fReporter = reporter; | 36 context.fReporter = reporter; |
36 context.fIntPointer = &test_value; | 37 context.fIntPointer = &test_value; |
37 | 38 |
38 SkSetErrorCallback(cb, &context); | 39 SkSetErrorCallback(cb, &context); |
39 | 40 |
40 CHECK(kNoError_SkError); | 41 CHECK(kNoError_SkError); |
(...skipping 11 matching lines...) Expand all Loading... |
52 // should trigger the default error callback, which just prints to the scree
n. | 53 // should trigger the default error callback, which just prints to the scree
n. |
53 path.addRoundRect(r, -10, -10); | 54 path.addRoundRect(r, -10, -10); |
54 CHECK(kInvalidArgument_SkError); | 55 CHECK(kInvalidArgument_SkError); |
55 CHECK(kNoError_SkError); | 56 CHECK(kNoError_SkError); |
56 | 57 |
57 // should trigger *our* callback. | 58 // should trigger *our* callback. |
58 path.addRoundRect(r, -10, -10); | 59 path.addRoundRect(r, -10, -10); |
59 CHECK(kInvalidArgument_SkError); | 60 CHECK(kInvalidArgument_SkError); |
60 CHECK(kNoError_SkError); | 61 CHECK(kNoError_SkError); |
61 } | 62 } |
62 | |
63 #include "TestClassDef.h" | |
64 DEFINE_TESTCLASS("Error", ErrorTestClass, ErrorTest) | |
OLD | NEW |