Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 | 1 |
| 2 /* | 2 /* |
| 3 * Copyright 2013 Google Inc. | 3 * Copyright 2013 Google Inc. |
| 4 * | 4 * |
| 5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
| 6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
| 7 */ | 7 */ |
| 8 #include "Test.h" | 8 #include "Test.h" |
| 9 #include "SkError.h" | 9 #include "SkError.h" |
| 10 #include "SkPath.h" | 10 #include "SkPath.h" |
| 11 #include "SkRect.h" | 11 #include "SkRect.h" |
| 12 | 12 |
| 13 typedef struct { | |
|
tfarina
2013/09/11 19:39:25
typedef should not be necessary here as we compile
tfarina
2013/09/11 19:39:25
I think this can be simply:
struct ErrorContext {
| |
| 14 skiatest::Reporter *fReporter; | |
| 15 unsigned int *fIntPointer; | |
| 16 } ErrorContext; | |
|
tfarina
2013/09/11 19:39:25
this is creating a variable as far as I can see. D
mtklein
2013/09/11 20:51:19
Oh how I love C++ syntax!
typedef struct { ... }
| |
| 17 | |
| 13 #define CHECK(errcode) \ | 18 #define CHECK(errcode) \ |
| 14 REPORTER_ASSERT( reporter, (err = SkGetLastError()) == errcode); \ | 19 REPORTER_ASSERT( reporter, (err = SkGetLastError()) == errcode); \ |
| 15 if (err != kNoError_SkError) \ | 20 if (err != kNoError_SkError) \ |
| 16 { \ | 21 { \ |
| 17 SkDebugf("Last error string: %s\n", SkGetLastErrorString()); \ | |
| 18 SkClearLastError(); \ | 22 SkClearLastError(); \ |
| 19 } | 23 } |
| 20 | 24 |
| 21 static void cb(SkError err, void *context) { | 25 static void cb(SkError err, void *context) { |
| 22 int *context_ptr = static_cast<int *>(context); | 26 ErrorContext *context_ptr = static_cast<ErrorContext *>(context); |
| 23 SkDebugf("CB (0x%x): %s\n", *context_ptr, SkGetLastErrorString()); | 27 REPORTER_ASSERT( context_ptr->fReporter, (*(context_ptr->fIntPointer) == 0xd eadbeef) ); |
| 24 } | 28 } |
| 25 | 29 |
| 26 static void ErrorTest(skiatest::Reporter* reporter) { | 30 static void ErrorTest(skiatest::Reporter* reporter) { |
| 27 SkError err; | 31 SkError err; |
| 32 | |
| 33 unsigned int test_value = 0xdeadbeef; | |
| 34 ErrorContext context; | |
| 35 context.fReporter = reporter; | |
| 36 context.fIntPointer = &test_value; | |
| 37 | |
| 38 SkSetErrorCallback(cb, &context); | |
| 28 | 39 |
| 29 CHECK(kNoError_SkError); | 40 CHECK(kNoError_SkError); |
| 30 | 41 |
| 31 SkRect r = SkRect::MakeWH(50, 100); | 42 SkRect r = SkRect::MakeWH(50, 100); |
| 32 CHECK(kNoError_SkError); | 43 CHECK(kNoError_SkError); |
| 33 | 44 |
| 34 SkPath path; | 45 SkPath path; |
| 35 path.addRect(r); | 46 path.addRect(r); |
| 36 CHECK(kNoError_SkError); | 47 CHECK(kNoError_SkError); |
| 37 | 48 |
| 38 path.addRoundRect(r, 10, 10); | 49 path.addRoundRect(r, 10, 10); |
| 39 CHECK(kNoError_SkError); | 50 CHECK(kNoError_SkError); |
| 40 | 51 |
| 41 // should trigger the default error callback, which just prints to the scree n. | 52 // should trigger the default error callback, which just prints to the scree n. |
| 42 path.addRoundRect(r, -10, -10); | 53 path.addRoundRect(r, -10, -10); |
| 43 CHECK(kInvalidArgument_SkError); | 54 CHECK(kInvalidArgument_SkError); |
| 44 CHECK(kNoError_SkError); | 55 CHECK(kNoError_SkError); |
| 45 | 56 |
| 46 int test_value = 0xdeadbeef; | |
| 47 SkSetErrorCallback(cb, &test_value); | |
| 48 | |
| 49 // should trigger *our* callback. | 57 // should trigger *our* callback. |
| 50 path.addRoundRect(r, -10, -10); | 58 path.addRoundRect(r, -10, -10); |
| 51 CHECK(kInvalidArgument_SkError); | 59 CHECK(kInvalidArgument_SkError); |
| 52 CHECK(kNoError_SkError); | 60 CHECK(kNoError_SkError); |
| 53 | |
| 54 // Should trigger the default one again. | |
| 55 SkSetErrorCallback(NULL, NULL); | |
| 56 path.addRoundRect(r, -10, -10); | |
| 57 CHECK(kInvalidArgument_SkError); | |
| 58 CHECK(kNoError_SkError); | |
| 59 } | 61 } |
| 60 | 62 |
| 61 #include "TestClassDef.h" | 63 #include "TestClassDef.h" |
| 62 DEFINE_TESTCLASS("Error", ErrorTestClass, ErrorTest) | 64 DEFINE_TESTCLASS("Error", ErrorTestClass, ErrorTest) |
| OLD | NEW |