blob: 620fbf4c93abe5224e119a3602e164e752fad61b [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001
2/*
3 * Copyright 2011 Google Inc.
4 *
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
7 */
vandebo@chromium.org48543272011-02-08 19:28:07 +00008#include "Test.h"
9#include "SkColor.h"
10#include "SkXfermode.h"
11
caryclark@google.com42639cd2012-06-06 12:03:39 +000012static SkPMColor bogusXfermodeProc(SkPMColor src, SkPMColor dst) {
vandebo@chromium.org48543272011-02-08 19:28:07 +000013 return 42;
14}
15
reed@google.comc0d4aa22011-04-13 21:12:04 +000016#define ILLEGAL_MODE ((SkXfermode::Mode)-1)
17
vandebo@chromium.org48543272011-02-08 19:28:07 +000018static void test_asMode(skiatest::Reporter* reporter) {
19 for (int mode = 0; mode <= SkXfermode::kLastMode; mode++) {
20 SkXfermode* xfer = SkXfermode::Create((SkXfermode::Mode) mode);
reed@google.comc0d4aa22011-04-13 21:12:04 +000021
22 SkXfermode::Mode reportedMode = ILLEGAL_MODE;
23 REPORTER_ASSERT(reporter, reportedMode != mode);
24
25 // test IsMode
26 REPORTER_ASSERT(reporter, SkXfermode::IsMode(xfer, &reportedMode));
27 REPORTER_ASSERT(reporter, reportedMode == mode);
28
29 // repeat that test, but with asMode instead
vandebo@chromium.org48543272011-02-08 19:28:07 +000030 if (xfer) {
reed@google.comc0d4aa22011-04-13 21:12:04 +000031 reportedMode = (SkXfermode::Mode) -1;
32 REPORTER_ASSERT(reporter, xfer->asMode(&reportedMode));
33 REPORTER_ASSERT(reporter, reportedMode == mode);
34 xfer->unref();
35 } else {
rmistry@google.comd6176b02012-08-23 18:14:13 +000036 REPORTER_ASSERT(reporter, SkXfermode::kSrcOver_Mode == mode);
vandebo@chromium.org48543272011-02-08 19:28:07 +000037 }
38 }
39
40 SkXfermode* bogusXfer = new SkProcXfermode(bogusXfermodeProc);
tfarina@chromium.org06910782013-04-15 22:12:43 +000041 SkXfermode::Mode reportedMode = ILLEGAL_MODE;
vandebo@chromium.org48543272011-02-08 19:28:07 +000042 REPORTER_ASSERT(reporter, !bogusXfer->asMode(&reportedMode));
tfarina@chromium.org06910782013-04-15 22:12:43 +000043 REPORTER_ASSERT(reporter, reportedMode == ILLEGAL_MODE);
reed@google.comc0d4aa22011-04-13 21:12:04 +000044 REPORTER_ASSERT(reporter, !SkXfermode::IsMode(bogusXfer, &reportedMode));
tfarina@chromium.org06910782013-04-15 22:12:43 +000045 REPORTER_ASSERT(reporter, reportedMode == ILLEGAL_MODE);
vandebo@chromium.org48543272011-02-08 19:28:07 +000046 bogusXfer->unref();
47}
48
mike@reedtribe.org3565f0f2011-11-17 02:27:26 +000049static void test_IsMode(skiatest::Reporter* reporter) {
50 REPORTER_ASSERT(reporter, SkXfermode::IsMode(NULL,
51 SkXfermode::kSrcOver_Mode));
52
53 for (int i = 0; i <= SkXfermode::kLastMode; ++i) {
54 SkXfermode::Mode mode = (SkXfermode::Mode)i;
rmistry@google.comd6176b02012-08-23 18:14:13 +000055
mike@reedtribe.org3565f0f2011-11-17 02:27:26 +000056 SkXfermode* xfer = SkXfermode::Create(mode);
57 REPORTER_ASSERT(reporter, SkXfermode::IsMode(xfer, mode));
58 SkSafeUnref(xfer);
59
60 if (SkXfermode::kSrcOver_Mode != mode) {
61 REPORTER_ASSERT(reporter, !SkXfermode::IsMode(NULL, mode));
62 }
63 }
64}
65
66static void test_xfermodes(skiatest::Reporter* reporter) {
67 test_asMode(reporter);
68 test_IsMode(reporter);
69}
70
vandebo@chromium.org48543272011-02-08 19:28:07 +000071#include "TestClassDef.h"
mike@reedtribe.org3565f0f2011-11-17 02:27:26 +000072DEFINE_TESTCLASS("Xfermode", XfermodeTestClass, test_xfermodes)