blob: 2d10640c68485c29313c24f5ed1117f934315f26 [file] [log] [blame]
humper@google.com75e3ca12013-04-08 21:44:11 +00001
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
commit-bot@chromium.orgc5e57bd2013-09-19 22:11:38 +000013typedef struct {
14 skiatest::Reporter *fReporter;
15 unsigned int *fIntPointer;
16} ErrorContext;
17
humper@google.com75e3ca12013-04-08 21:44:11 +000018#define CHECK(errcode) \
19 REPORTER_ASSERT( reporter, (err = SkGetLastError()) == errcode); \
20 if (err != kNoError_SkError) \
21 { \
humper@google.com75e3ca12013-04-08 21:44:11 +000022 SkClearLastError(); \
23 }
skia.committer@gmail.com32840172013-04-09 07:01:27 +000024
humper@google.com8e029e62013-04-08 21:54:58 +000025static void cb(SkError err, void *context) {
commit-bot@chromium.orgc5e57bd2013-09-19 22:11:38 +000026 ErrorContext *context_ptr = static_cast<ErrorContext *>(context);
27 REPORTER_ASSERT( context_ptr->fReporter, (*(context_ptr->fIntPointer) == 0xdeadbeef) );
humper@google.com75e3ca12013-04-08 21:44:11 +000028}
29
30static void ErrorTest(skiatest::Reporter* reporter) {
31 SkError err;
skia.committer@gmail.comf91e3d42013-09-20 07:01:33 +000032
commit-bot@chromium.orgc5e57bd2013-09-19 22:11:38 +000033 unsigned int test_value = 0xdeadbeef;
34 ErrorContext context;
35 context.fReporter = reporter;
36 context.fIntPointer = &test_value;
skia.committer@gmail.comf91e3d42013-09-20 07:01:33 +000037
commit-bot@chromium.orgc5e57bd2013-09-19 22:11:38 +000038 SkSetErrorCallback(cb, &context);
skia.committer@gmail.com32840172013-04-09 07:01:27 +000039
humper@google.com75e3ca12013-04-08 21:44:11 +000040 CHECK(kNoError_SkError);
skia.committer@gmail.com32840172013-04-09 07:01:27 +000041
humper@google.com75e3ca12013-04-08 21:44:11 +000042 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.com32840172013-04-09 07:01:27 +000048
humper@google.com75e3ca12013-04-08 21:44:11 +000049 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.com75e3ca12013-04-08 21:44:11 +000057 // should trigger *our* callback.
58 path.addRoundRect(r, -10, -10);
59 CHECK(kInvalidArgument_SkError);
60 CHECK(kNoError_SkError);
humper@google.com75e3ca12013-04-08 21:44:11 +000061}
62
63#include "TestClassDef.h"
64DEFINE_TESTCLASS("Error", ErrorTestClass, ErrorTest)