Chromium Code Reviews| Index: tests/ErrorTest.cpp |
| diff --git a/tests/ErrorTest.cpp b/tests/ErrorTest.cpp |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..f198c038058d769bf3a61041a508d7066ebe938e |
| --- /dev/null |
| +++ b/tests/ErrorTest.cpp |
| @@ -0,0 +1,61 @@ |
| + |
| +/* |
| + * 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()) == kError_##errcode); \ |
|
scroggo
2013/04/08 19:24:53
Minor nit:
I find macros to be more readable if th
humper
2013/04/08 19:43:23
Done.
|
| + if (err != kError_NoError) \ |
| + { \ |
| + 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(NoError); |
| + |
| + SkRect r = SkRect::MakeWH(50, 100); |
| + CHECK(NoError); |
| + |
| + SkPath path; |
| + path.addRect(r); |
| + CHECK(NoError); |
| + |
| + path.addRoundRect(r, 10, 10); |
| + CHECK(NoError); |
| + |
| + // should trigger the default error callback, which just prints to the scren. |
| + path.addRoundRect(r, -10, -10); |
| + CHECK(InvalidArgument); |
| + CHECK(NoError); |
| + |
| + int test_value = 0xdeadbeef; |
| + SkSetErrorCallback(cb, &test_value); |
| + |
| + // should trigger *our* callback. |
| + path.addRoundRect(r, -10, -10); |
| + CHECK(InvalidArgument); |
| + CHECK(NoError); |
| + |
| + // Should trigger the default one again. |
| + SkSetErrorCallback(NULL, NULL); |
| + path.addRoundRect(r, -10, -10); |
| + CHECK(InvalidArgument); |
| + CHECK(NoError); |
| +} |
| + |
| +#include "TestClassDef.h" |
| +DEFINE_TESTCLASS("Error", ErrorTestClass, ErrorTest) |