2011-07-28 14:26:00 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2011 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
|
|
|
|
2011-02-08 19:28:07 +00:00
|
|
|
#include "SkColor.h"
|
|
|
|
#include "SkXfermode.h"
|
2014-01-24 20:56:26 +00:00
|
|
|
#include "Test.h"
|
2011-02-08 19:28:07 +00:00
|
|
|
|
2011-04-13 21:12:04 +00:00
|
|
|
#define ILLEGAL_MODE ((SkXfermode::Mode)-1)
|
|
|
|
|
2011-02-08 19:28:07 +00:00
|
|
|
static void test_asMode(skiatest::Reporter* reporter) {
|
|
|
|
for (int mode = 0; mode <= SkXfermode::kLastMode; mode++) {
|
|
|
|
SkXfermode* xfer = SkXfermode::Create((SkXfermode::Mode) mode);
|
2011-04-13 21:12:04 +00:00
|
|
|
|
|
|
|
SkXfermode::Mode reportedMode = ILLEGAL_MODE;
|
|
|
|
REPORTER_ASSERT(reporter, reportedMode != mode);
|
|
|
|
|
|
|
|
// test IsMode
|
2013-10-31 17:28:30 +00:00
|
|
|
REPORTER_ASSERT(reporter, SkXfermode::AsMode(xfer, &reportedMode));
|
2011-04-13 21:12:04 +00:00
|
|
|
REPORTER_ASSERT(reporter, reportedMode == mode);
|
|
|
|
|
|
|
|
// repeat that test, but with asMode instead
|
2011-02-08 19:28:07 +00:00
|
|
|
if (xfer) {
|
2011-04-13 21:12:04 +00:00
|
|
|
reportedMode = (SkXfermode::Mode) -1;
|
|
|
|
REPORTER_ASSERT(reporter, xfer->asMode(&reportedMode));
|
|
|
|
REPORTER_ASSERT(reporter, reportedMode == mode);
|
|
|
|
xfer->unref();
|
|
|
|
} else {
|
2012-08-23 18:14:13 +00:00
|
|
|
REPORTER_ASSERT(reporter, SkXfermode::kSrcOver_Mode == mode);
|
2011-02-08 19:28:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-17 02:27:26 +00:00
|
|
|
static void test_IsMode(skiatest::Reporter* reporter) {
|
|
|
|
REPORTER_ASSERT(reporter, SkXfermode::IsMode(NULL,
|
|
|
|
SkXfermode::kSrcOver_Mode));
|
|
|
|
|
|
|
|
for (int i = 0; i <= SkXfermode::kLastMode; ++i) {
|
|
|
|
SkXfermode::Mode mode = (SkXfermode::Mode)i;
|
2012-08-23 18:14:13 +00:00
|
|
|
|
2011-11-17 02:27:26 +00:00
|
|
|
SkXfermode* xfer = SkXfermode::Create(mode);
|
|
|
|
REPORTER_ASSERT(reporter, SkXfermode::IsMode(xfer, mode));
|
|
|
|
SkSafeUnref(xfer);
|
|
|
|
|
|
|
|
if (SkXfermode::kSrcOver_Mode != mode) {
|
|
|
|
REPORTER_ASSERT(reporter, !SkXfermode::IsMode(NULL, mode));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-12 21:11:12 +00:00
|
|
|
DEF_TEST(Xfermode, reporter) {
|
2011-11-17 02:27:26 +00:00
|
|
|
test_asMode(reporter);
|
|
|
|
test_IsMode(reporter);
|
|
|
|
}
|