blob: 8f4d65aec5f7f1ec524f2238864c1f5d4926c3a9 [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001/*
2 * Copyright 2011 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
tfarina@chromium.orge4fafb12013-12-12 21:11:12 +00007
vandebo@chromium.org48543272011-02-08 19:28:07 +00008#include "Test.h"
tfarina@chromium.orge4fafb12013-12-12 21:11:12 +00009#include "TestClassDef.h"
vandebo@chromium.org48543272011-02-08 19:28:07 +000010#include "SkColor.h"
11#include "SkXfermode.h"
12
caryclark@google.com42639cd2012-06-06 12:03:39 +000013static SkPMColor bogusXfermodeProc(SkPMColor src, SkPMColor dst) {
vandebo@chromium.org48543272011-02-08 19:28:07 +000014 return 42;
15}
16
reed@google.comc0d4aa22011-04-13 21:12:04 +000017#define ILLEGAL_MODE ((SkXfermode::Mode)-1)
18
vandebo@chromium.org48543272011-02-08 19:28:07 +000019static void test_asMode(skiatest::Reporter* reporter) {
20 for (int mode = 0; mode <= SkXfermode::kLastMode; mode++) {
21 SkXfermode* xfer = SkXfermode::Create((SkXfermode::Mode) mode);
reed@google.comc0d4aa22011-04-13 21:12:04 +000022
23 SkXfermode::Mode reportedMode = ILLEGAL_MODE;
24 REPORTER_ASSERT(reporter, reportedMode != mode);
25
26 // test IsMode
reed@google.com44699382013-10-31 17:28:30 +000027 REPORTER_ASSERT(reporter, SkXfermode::AsMode(xfer, &reportedMode));
reed@google.comc0d4aa22011-04-13 21:12:04 +000028 REPORTER_ASSERT(reporter, reportedMode == mode);
29
30 // repeat that test, but with asMode instead
vandebo@chromium.org48543272011-02-08 19:28:07 +000031 if (xfer) {
reed@google.comc0d4aa22011-04-13 21:12:04 +000032 reportedMode = (SkXfermode::Mode) -1;
33 REPORTER_ASSERT(reporter, xfer->asMode(&reportedMode));
34 REPORTER_ASSERT(reporter, reportedMode == mode);
35 xfer->unref();
36 } else {
rmistry@google.comd6176b02012-08-23 18:14:13 +000037 REPORTER_ASSERT(reporter, SkXfermode::kSrcOver_Mode == mode);
vandebo@chromium.org48543272011-02-08 19:28:07 +000038 }
39 }
40
41 SkXfermode* bogusXfer = new SkProcXfermode(bogusXfermodeProc);
tfarina@chromium.org06910782013-04-15 22:12:43 +000042 SkXfermode::Mode reportedMode = ILLEGAL_MODE;
vandebo@chromium.org48543272011-02-08 19:28:07 +000043 REPORTER_ASSERT(reporter, !bogusXfer->asMode(&reportedMode));
tfarina@chromium.org06910782013-04-15 22:12:43 +000044 REPORTER_ASSERT(reporter, reportedMode == ILLEGAL_MODE);
reed@google.com44699382013-10-31 17:28:30 +000045 REPORTER_ASSERT(reporter, !SkXfermode::AsMode(bogusXfer, &reportedMode));
tfarina@chromium.org06910782013-04-15 22:12:43 +000046 REPORTER_ASSERT(reporter, reportedMode == ILLEGAL_MODE);
vandebo@chromium.org48543272011-02-08 19:28:07 +000047 bogusXfer->unref();
48}
49
mike@reedtribe.org3565f0f2011-11-17 02:27:26 +000050static void test_IsMode(skiatest::Reporter* reporter) {
51 REPORTER_ASSERT(reporter, SkXfermode::IsMode(NULL,
52 SkXfermode::kSrcOver_Mode));
53
54 for (int i = 0; i <= SkXfermode::kLastMode; ++i) {
55 SkXfermode::Mode mode = (SkXfermode::Mode)i;
rmistry@google.comd6176b02012-08-23 18:14:13 +000056
mike@reedtribe.org3565f0f2011-11-17 02:27:26 +000057 SkXfermode* xfer = SkXfermode::Create(mode);
58 REPORTER_ASSERT(reporter, SkXfermode::IsMode(xfer, mode));
59 SkSafeUnref(xfer);
60
61 if (SkXfermode::kSrcOver_Mode != mode) {
62 REPORTER_ASSERT(reporter, !SkXfermode::IsMode(NULL, mode));
63 }
64 }
65}
66
tfarina@chromium.orge4fafb12013-12-12 21:11:12 +000067DEF_TEST(Xfermode, reporter) {
mike@reedtribe.org3565f0f2011-11-17 02:27:26 +000068 test_asMode(reporter);
69 test_IsMode(reporter);
70}