2013-04-08 21:44:11 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2013 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
2013-12-12 21:11:12 +00:00
|
|
|
|
2013-04-08 21:44:11 +00:00
|
|
|
#include "Test.h"
|
|
|
|
#include "SkError.h"
|
|
|
|
#include "SkPath.h"
|
|
|
|
#include "SkRect.h"
|
|
|
|
|
2013-09-19 22:11:38 +00:00
|
|
|
typedef struct {
|
|
|
|
skiatest::Reporter *fReporter;
|
|
|
|
unsigned int *fIntPointer;
|
|
|
|
} ErrorContext;
|
|
|
|
|
2013-04-08 21:44:11 +00:00
|
|
|
#define CHECK(errcode) \
|
|
|
|
REPORTER_ASSERT( reporter, (err = SkGetLastError()) == errcode); \
|
|
|
|
if (err != kNoError_SkError) \
|
|
|
|
{ \
|
|
|
|
SkClearLastError(); \
|
|
|
|
}
|
2013-04-09 07:01:27 +00:00
|
|
|
|
2013-04-08 21:54:58 +00:00
|
|
|
static void cb(SkError err, void *context) {
|
2013-09-19 22:11:38 +00:00
|
|
|
ErrorContext *context_ptr = static_cast<ErrorContext *>(context);
|
|
|
|
REPORTER_ASSERT( context_ptr->fReporter, (*(context_ptr->fIntPointer) == 0xdeadbeef) );
|
2013-04-08 21:44:11 +00:00
|
|
|
}
|
|
|
|
|
2013-12-12 21:11:12 +00:00
|
|
|
DEF_TEST(Error, reporter) {
|
2013-04-08 21:44:11 +00:00
|
|
|
SkError err;
|
2013-09-20 07:01:33 +00:00
|
|
|
|
2013-09-19 22:11:38 +00:00
|
|
|
unsigned int test_value = 0xdeadbeef;
|
|
|
|
ErrorContext context;
|
|
|
|
context.fReporter = reporter;
|
|
|
|
context.fIntPointer = &test_value;
|
2013-09-20 07:01:33 +00:00
|
|
|
|
2013-09-19 22:11:38 +00:00
|
|
|
SkSetErrorCallback(cb, &context);
|
2013-04-09 07:01:27 +00:00
|
|
|
|
2013-04-08 21:44:11 +00:00
|
|
|
CHECK(kNoError_SkError);
|
2013-04-09 07:01:27 +00:00
|
|
|
|
2013-04-08 21:44:11 +00:00
|
|
|
SkRect r = SkRect::MakeWH(50, 100);
|
|
|
|
CHECK(kNoError_SkError);
|
|
|
|
|
|
|
|
SkPath path;
|
|
|
|
path.addRect(r);
|
|
|
|
CHECK(kNoError_SkError);
|
2013-04-09 07:01:27 +00:00
|
|
|
|
2013-04-08 21:44:11 +00:00
|
|
|
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);
|
|
|
|
|
|
|
|
// should trigger *our* callback.
|
|
|
|
path.addRoundRect(r, -10, -10);
|
|
|
|
CHECK(kInvalidArgument_SkError);
|
|
|
|
CHECK(kNoError_SkError);
|
|
|
|
}
|