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