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