blob: 9dca9d87d58d83d60aabefb1aa80b601e555e54a [file] [log] [blame]
humper@google.com75e3ca12013-04-08 21:44:11 +00001/*
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.orge4fafb12013-12-12 21:11:12 +00007
humper@google.com75e3ca12013-04-08 21:44:11 +00008#include "Test.h"
tfarina@chromium.orge4fafb12013-12-12 21:11:12 +00009#include "TestClassDef.h"
humper@google.com75e3ca12013-04-08 21:44:11 +000010#include "SkError.h"
11#include "SkPath.h"
12#include "SkRect.h"
13
commit-bot@chromium.orgc5e57bd2013-09-19 22:11:38 +000014typedef struct {
15 skiatest::Reporter *fReporter;
16 unsigned int *fIntPointer;
17} ErrorContext;
18
humper@google.com75e3ca12013-04-08 21:44:11 +000019#define CHECK(errcode) \
20 REPORTER_ASSERT( reporter, (err = SkGetLastError()) == errcode); \
21 if (err != kNoError_SkError) \
22 { \
humper@google.com75e3ca12013-04-08 21:44:11 +000023 SkClearLastError(); \
24 }
skia.committer@gmail.com32840172013-04-09 07:01:27 +000025
humper@google.com8e029e62013-04-08 21:54:58 +000026static void cb(SkError err, void *context) {
commit-bot@chromium.orgc5e57bd2013-09-19 22:11:38 +000027 ErrorContext *context_ptr = static_cast<ErrorContext *>(context);
28 REPORTER_ASSERT( context_ptr->fReporter, (*(context_ptr->fIntPointer) == 0xdeadbeef) );
humper@google.com75e3ca12013-04-08 21:44:11 +000029}
30
tfarina@chromium.orge4fafb12013-12-12 21:11:12 +000031DEF_TEST(Error, reporter) {
humper@google.com75e3ca12013-04-08 21:44:11 +000032 SkError err;
skia.committer@gmail.comf91e3d42013-09-20 07:01:33 +000033
commit-bot@chromium.orgc5e57bd2013-09-19 22:11:38 +000034 unsigned int test_value = 0xdeadbeef;
35 ErrorContext context;
36 context.fReporter = reporter;
37 context.fIntPointer = &test_value;
skia.committer@gmail.comf91e3d42013-09-20 07:01:33 +000038
commit-bot@chromium.orgc5e57bd2013-09-19 22:11:38 +000039 SkSetErrorCallback(cb, &context);
skia.committer@gmail.com32840172013-04-09 07:01:27 +000040
humper@google.com75e3ca12013-04-08 21:44:11 +000041 CHECK(kNoError_SkError);
skia.committer@gmail.com32840172013-04-09 07:01:27 +000042
humper@google.com75e3ca12013-04-08 21:44:11 +000043 SkRect r = SkRect::MakeWH(50, 100);
44 CHECK(kNoError_SkError);
45
46 SkPath path;
47 path.addRect(r);
48 CHECK(kNoError_SkError);
skia.committer@gmail.com32840172013-04-09 07:01:27 +000049
humper@google.com75e3ca12013-04-08 21:44:11 +000050 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
humper@google.com75e3ca12013-04-08 21:44:11 +000058 // should trigger *our* callback.
59 path.addRoundRect(r, -10, -10);
60 CHECK(kInvalidArgument_SkError);
61 CHECK(kNoError_SkError);
humper@google.com75e3ca12013-04-08 21:44:11 +000062}