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 */ 7 8 #include "Test.h" 9 #include "TestClassDef.h" 10 #include "SkError.h" 11 #include "SkPath.h" 12 #include "SkRect.h" 13 14 typedef struct { 15 skiatest::Reporter *fReporter; 16 unsigned int *fIntPointer; 17 } ErrorContext; 18 19 #define CHECK(errcode) \ 20 REPORTER_ASSERT( reporter, (err = SkGetLastError()) == errcode); \ 21 if (err != kNoError_SkError) \ 22 { \ 23 SkClearLastError(); \ 24 } 25 26 static void cb(SkError err, void *context) { 27 ErrorContext *context_ptr = static_cast<ErrorContext *>(context); 28 REPORTER_ASSERT( context_ptr->fReporter, (*(context_ptr->fIntPointer) == 0xdeadbeef) ); 29 } 30 31 DEF_TEST(Error, reporter) { 32 SkError err; 33 34 unsigned int test_value = 0xdeadbeef; 35 ErrorContext context; 36 context.fReporter = reporter; 37 context.fIntPointer = &test_value; 38 39 SkSetErrorCallback(cb, &context); 40 41 CHECK(kNoError_SkError); 42 43 SkRect r = SkRect::MakeWH(50, 100); 44 CHECK(kNoError_SkError); 45 46 SkPath path; 47 path.addRect(r); 48 CHECK(kNoError_SkError); 49 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 58 // should trigger *our* callback. 59 path.addRoundRect(r, -10, -10); 60 CHECK(kInvalidArgument_SkError); 61 CHECK(kNoError_SkError); 62 } 63