Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(101)

Unified Diff: tests/ErrorTest.cpp

Issue 13699004: first draft of error checking / reporting API (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: remove unnecessary include, delete Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/core/SkPath.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/ErrorTest.cpp
diff --git a/tests/ErrorTest.cpp b/tests/ErrorTest.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..cbaf9d185b389f9ee0563576ec241804735a5023
--- /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)
« no previous file with comments | « src/core/SkPath.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698