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) { |
mtklein | fbe4136 | 2014-09-11 14:41:56 -0700 | [diff] [blame] | 31 | // Some previous user of this thread may have left an error laying around. |
| 32 | SkClearLastError(); |
| 33 | |
humper@google.com | 75e3ca1 | 2013-04-08 21:44:11 +0000 | [diff] [blame] | 34 | SkError err; |
skia.committer@gmail.com | f91e3d4 | 2013-09-20 07:01:33 +0000 | [diff] [blame] | 35 | |
commit-bot@chromium.org | c5e57bd | 2013-09-19 22:11:38 +0000 | [diff] [blame] | 36 | unsigned int test_value = 0xdeadbeef; |
| 37 | ErrorContext context; |
| 38 | context.fReporter = reporter; |
| 39 | context.fIntPointer = &test_value; |
skia.committer@gmail.com | f91e3d4 | 2013-09-20 07:01:33 +0000 | [diff] [blame] | 40 | |
commit-bot@chromium.org | c5e57bd | 2013-09-19 22:11:38 +0000 | [diff] [blame] | 41 | SkSetErrorCallback(cb, &context); |
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 | CHECK(kNoError_SkError); |
skia.committer@gmail.com | 3284017 | 2013-04-09 07:01:27 +0000 | [diff] [blame] | 44 | |
humper@google.com | 75e3ca1 | 2013-04-08 21:44:11 +0000 | [diff] [blame] | 45 | SkRect r = SkRect::MakeWH(50, 100); |
| 46 | CHECK(kNoError_SkError); |
| 47 | |
| 48 | SkPath path; |
| 49 | path.addRect(r); |
| 50 | CHECK(kNoError_SkError); |
skia.committer@gmail.com | 3284017 | 2013-04-09 07:01:27 +0000 | [diff] [blame] | 51 | |
humper@google.com | 75e3ca1 | 2013-04-08 21:44:11 +0000 | [diff] [blame] | 52 | path.addRoundRect(r, 10, 10); |
| 53 | CHECK(kNoError_SkError); |
| 54 | |
| 55 | // should trigger the default error callback, which just prints to the screen. |
| 56 | path.addRoundRect(r, -10, -10); |
| 57 | CHECK(kInvalidArgument_SkError); |
| 58 | CHECK(kNoError_SkError); |
| 59 | |
humper@google.com | 75e3ca1 | 2013-04-08 21:44:11 +0000 | [diff] [blame] | 60 | // should trigger *our* callback. |
| 61 | path.addRoundRect(r, -10, -10); |
| 62 | CHECK(kInvalidArgument_SkError); |
| 63 | CHECK(kNoError_SkError); |
humper@google.com | 75e3ca1 | 2013-04-08 21:44:11 +0000 | [diff] [blame] | 64 | } |