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