humper@google.com | 75e3ca1 | 2013-04-08 21:44:11 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2013 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 | e4fafb1 | 2013-12-12 21:11:12 +0000 | [diff] [blame] | 7 | |
humper@google.com | 75e3ca1 | 2013-04-08 21:44:11 +0000 | [diff] [blame] | 8 | #include "Test.h" |
tfarina@chromium.org | e4fafb1 | 2013-12-12 21:11:12 +0000 | [diff] [blame] | 9 | #include "TestClassDef.h" |
humper@google.com | 75e3ca1 | 2013-04-08 21:44:11 +0000 | [diff] [blame] | 10 | #include "SkError.h" |
| 11 | #include "SkPath.h" |
| 12 | #include "SkRect.h" |
| 13 | |
commit-bot@chromium.org | c5e57bd | 2013-09-19 22:11:38 +0000 | [diff] [blame] | 14 | typedef struct { |
| 15 | skiatest::Reporter *fReporter; |
| 16 | unsigned int *fIntPointer; |
| 17 | } ErrorContext; |
| 18 | |
humper@google.com | 75e3ca1 | 2013-04-08 21:44:11 +0000 | [diff] [blame] | 19 | #define CHECK(errcode) \ |
| 20 | REPORTER_ASSERT( reporter, (err = SkGetLastError()) == errcode); \ |
| 21 | if (err != kNoError_SkError) \ |
| 22 | { \ |
humper@google.com | 75e3ca1 | 2013-04-08 21:44:11 +0000 | [diff] [blame] | 23 | SkClearLastError(); \ |
| 24 | } |
skia.committer@gmail.com | 3284017 | 2013-04-09 07:01:27 +0000 | [diff] [blame] | 25 | |
humper@google.com | 8e029e6 | 2013-04-08 21:54:58 +0000 | [diff] [blame] | 26 | static void cb(SkError err, void *context) { |
commit-bot@chromium.org | c5e57bd | 2013-09-19 22:11:38 +0000 | [diff] [blame] | 27 | ErrorContext *context_ptr = static_cast<ErrorContext *>(context); |
| 28 | REPORTER_ASSERT( context_ptr->fReporter, (*(context_ptr->fIntPointer) == 0xdeadbeef) ); |
humper@google.com | 75e3ca1 | 2013-04-08 21:44:11 +0000 | [diff] [blame] | 29 | } |
| 30 | |
tfarina@chromium.org | e4fafb1 | 2013-12-12 21:11:12 +0000 | [diff] [blame] | 31 | DEF_TEST(Error, reporter) { |
humper@google.com | 75e3ca1 | 2013-04-08 21:44:11 +0000 | [diff] [blame] | 32 | SkError err; |
skia.committer@gmail.com | f91e3d4 | 2013-09-20 07:01:33 +0000 | [diff] [blame] | 33 | |
commit-bot@chromium.org | c5e57bd | 2013-09-19 22:11:38 +0000 | [diff] [blame] | 34 | unsigned int test_value = 0xdeadbeef; |
| 35 | ErrorContext context; |
| 36 | context.fReporter = reporter; |
| 37 | context.fIntPointer = &test_value; |
skia.committer@gmail.com | f91e3d4 | 2013-09-20 07:01:33 +0000 | [diff] [blame] | 38 | |
commit-bot@chromium.org | c5e57bd | 2013-09-19 22:11:38 +0000 | [diff] [blame] | 39 | SkSetErrorCallback(cb, &context); |
skia.committer@gmail.com | 3284017 | 2013-04-09 07:01:27 +0000 | [diff] [blame] | 40 | |
humper@google.com | 75e3ca1 | 2013-04-08 21:44:11 +0000 | [diff] [blame] | 41 | CHECK(kNoError_SkError); |
skia.committer@gmail.com | 3284017 | 2013-04-09 07:01:27 +0000 | [diff] [blame] | 42 | |
humper@google.com | 75e3ca1 | 2013-04-08 21:44:11 +0000 | [diff] [blame] | 43 | SkRect r = SkRect::MakeWH(50, 100); |
| 44 | CHECK(kNoError_SkError); |
| 45 | |
| 46 | SkPath path; |
| 47 | path.addRect(r); |
| 48 | CHECK(kNoError_SkError); |
skia.committer@gmail.com | 3284017 | 2013-04-09 07:01:27 +0000 | [diff] [blame] | 49 | |
humper@google.com | 75e3ca1 | 2013-04-08 21:44:11 +0000 | [diff] [blame] | 50 | path.addRoundRect(r, 10, 10); |
| 51 | CHECK(kNoError_SkError); |
| 52 | |
| 53 | // should trigger the default error callback, which just prints to the screen. |
| 54 | path.addRoundRect(r, -10, -10); |
| 55 | CHECK(kInvalidArgument_SkError); |
| 56 | CHECK(kNoError_SkError); |
| 57 | |
humper@google.com | 75e3ca1 | 2013-04-08 21:44:11 +0000 | [diff] [blame] | 58 | // should trigger *our* callback. |
| 59 | path.addRoundRect(r, -10, -10); |
| 60 | CHECK(kInvalidArgument_SkError); |
| 61 | CHECK(kNoError_SkError); |
humper@google.com | 75e3ca1 | 2013-04-08 21:44:11 +0000 | [diff] [blame] | 62 | } |