aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/ErrorTest.cpp
diff options
context:
space:
mode:
authorGravatar humper@google.com <humper@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-04-08 21:44:11 +0000
committerGravatar humper@google.com <humper@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-04-08 21:44:11 +0000
commit75e3ca127cd14fffc9c8df7ea03d6529fb001831 (patch)
treeef98cdcf55fb22388bf648e90f305ac19b9535d0 /tests/ErrorTest.cpp
parent496120185c7baed4edf1c110f4f5b43f29bab1c0 (diff)
Error checking / reporting API
Review URL: https://codereview.chromium.org/13699004 git-svn-id: http://skia.googlecode.com/svn/trunk@8566 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'tests/ErrorTest.cpp')
-rw-r--r--tests/ErrorTest.cpp62
1 files changed, 62 insertions, 0 deletions
diff --git a/tests/ErrorTest.cpp b/tests/ErrorTest.cpp
new file mode 100644
index 0000000000..cbaf9d185b
--- /dev/null
+++ b/tests/ErrorTest.cpp
@@ -0,0 +1,62 @@
+
+/*
+ * Copyright 2013 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+#include "Test.h"
+#include "SkError.h"
+#include "SkPath.h"
+#include "SkRect.h"
+
+#define CHECK(errcode) \
+ REPORTER_ASSERT( reporter, (err = SkGetLastError()) == errcode); \
+ if (err != kNoError_SkError) \
+ { \
+ SkDebugf("Last error string: %s\n", SkGetLastErrorString()); \
+ SkClearLastError(); \
+ }
+
+void cb(SkError err, void *context) {
+ int *context_ptr = static_cast<int *>(context);
+ SkDebugf("CB (0x%x): %s\n", *context_ptr, SkGetLastErrorString());
+}
+
+static void ErrorTest(skiatest::Reporter* reporter) {
+ SkError err;
+
+ CHECK(kNoError_SkError);
+
+ SkRect r = SkRect::MakeWH(50, 100);
+ CHECK(kNoError_SkError);
+
+ SkPath path;
+ path.addRect(r);
+ CHECK(kNoError_SkError);
+
+ path.addRoundRect(r, 10, 10);
+ CHECK(kNoError_SkError);
+
+ // should trigger the default error callback, which just prints to the screen.
+ path.addRoundRect(r, -10, -10);
+ CHECK(kInvalidArgument_SkError);
+ CHECK(kNoError_SkError);
+
+ int test_value = 0xdeadbeef;
+ SkSetErrorCallback(cb, &test_value);
+
+ // should trigger *our* callback.
+ path.addRoundRect(r, -10, -10);
+ CHECK(kInvalidArgument_SkError);
+ CHECK(kNoError_SkError);
+
+ // Should trigger the default one again.
+ SkSetErrorCallback(NULL, NULL);
+ path.addRoundRect(r, -10, -10);
+ CHECK(kInvalidArgument_SkError);
+ CHECK(kNoError_SkError);
+}
+
+#include "TestClassDef.h"
+DEFINE_TESTCLASS("Error", ErrorTestClass, ErrorTest)