blob: 4802d53e146e3e1d9ebac4422ea39787ea0cd355 [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 "SkError.h"
9#include "SkPath.h"
10#include "SkRect.h"
tfarina@chromium.org8f6884a2014-01-24 20:56:26 +000011#include "Test.h"
humper@google.com75e3ca12013-04-08 21:44:11 +000012
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
tfarina@chromium.orge4fafb12013-12-12 21:11:12 +000030DEF_TEST(Error, reporter) {
mtkleinfbe41362014-09-11 14:41:56 -070031 // Some previous user of this thread may have left an error laying around.
32 SkClearLastError();
33
humper@google.com75e3ca12013-04-08 21:44:11 +000034 SkError err;
skia.committer@gmail.comf91e3d42013-09-20 07:01:33 +000035
commit-bot@chromium.orgc5e57bd2013-09-19 22:11:38 +000036 unsigned int test_value = 0xdeadbeef;
37 ErrorContext context;
38 context.fReporter = reporter;
39 context.fIntPointer = &test_value;
skia.committer@gmail.comf91e3d42013-09-20 07:01:33 +000040
commit-bot@chromium.orgc5e57bd2013-09-19 22:11:38 +000041 SkSetErrorCallback(cb, &context);
skia.committer@gmail.com32840172013-04-09 07:01:27 +000042
humper@google.com75e3ca12013-04-08 21:44:11 +000043 CHECK(kNoError_SkError);
skia.committer@gmail.com32840172013-04-09 07:01:27 +000044
humper@google.com75e3ca12013-04-08 21:44:11 +000045 SkRect r = SkRect::MakeWH(50, 100);
46 CHECK(kNoError_SkError);
47
48 SkPath path;
49 path.addRect(r);
50 CHECK(kNoError_SkError);
skia.committer@gmail.com32840172013-04-09 07:01:27 +000051
humper@google.com75e3ca12013-04-08 21:44:11 +000052 path.addRoundRect(r, 10, 10);
53 CHECK(kNoError_SkError);
54
55 // should trigger the default error callback, which just prints to the screen.
56 path.addRoundRect(r, -10, -10);
57 CHECK(kInvalidArgument_SkError);
58 CHECK(kNoError_SkError);
59
humper@google.com75e3ca12013-04-08 21:44:11 +000060 // should trigger *our* callback.
61 path.addRoundRect(r, -10, -10);
62 CHECK(kInvalidArgument_SkError);
63 CHECK(kNoError_SkError);
humper@google.com75e3ca12013-04-08 21:44:11 +000064}