blob: 294d63db59adb490f4045d2752f1660c467bd8ce [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 "SkColor.h"
9#include "SkXfermode.h"
tfarina@chromium.org8f6884a2014-01-24 20:56:26 +000010#include "Test.h"
vandebo@chromium.org48543272011-02-08 19:28:07 +000011
reed@google.comc0d4aa22011-04-13 21:12:04 +000012#define ILLEGAL_MODE ((SkXfermode::Mode)-1)
13
vandebo@chromium.org48543272011-02-08 19:28:07 +000014static void test_asMode(skiatest::Reporter* reporter) {
15 for (int mode = 0; mode <= SkXfermode::kLastMode; mode++) {
16 SkXfermode* xfer = SkXfermode::Create((SkXfermode::Mode) mode);
reed@google.comc0d4aa22011-04-13 21:12:04 +000017
18 SkXfermode::Mode reportedMode = ILLEGAL_MODE;
19 REPORTER_ASSERT(reporter, reportedMode != mode);
20
21 // test IsMode
reed@google.com44699382013-10-31 17:28:30 +000022 REPORTER_ASSERT(reporter, SkXfermode::AsMode(xfer, &reportedMode));
reed@google.comc0d4aa22011-04-13 21:12:04 +000023 REPORTER_ASSERT(reporter, reportedMode == mode);
24
25 // repeat that test, but with asMode instead
vandebo@chromium.org48543272011-02-08 19:28:07 +000026 if (xfer) {
reed@google.comc0d4aa22011-04-13 21:12:04 +000027 reportedMode = (SkXfermode::Mode) -1;
28 REPORTER_ASSERT(reporter, xfer->asMode(&reportedMode));
29 REPORTER_ASSERT(reporter, reportedMode == mode);
30 xfer->unref();
31 } else {
rmistry@google.comd6176b02012-08-23 18:14:13 +000032 REPORTER_ASSERT(reporter, SkXfermode::kSrcOver_Mode == mode);
vandebo@chromium.org48543272011-02-08 19:28:07 +000033 }
34 }
vandebo@chromium.org48543272011-02-08 19:28:07 +000035}
36
mike@reedtribe.org3565f0f2011-11-17 02:27:26 +000037static void test_IsMode(skiatest::Reporter* reporter) {
halcanary96fcdcc2015-08-27 07:41:13 -070038 REPORTER_ASSERT(reporter, SkXfermode::IsMode(nullptr,
mike@reedtribe.org3565f0f2011-11-17 02:27:26 +000039 SkXfermode::kSrcOver_Mode));
40
41 for (int i = 0; i <= SkXfermode::kLastMode; ++i) {
42 SkXfermode::Mode mode = (SkXfermode::Mode)i;
rmistry@google.comd6176b02012-08-23 18:14:13 +000043
mike@reedtribe.org3565f0f2011-11-17 02:27:26 +000044 SkXfermode* xfer = SkXfermode::Create(mode);
45 REPORTER_ASSERT(reporter, SkXfermode::IsMode(xfer, mode));
46 SkSafeUnref(xfer);
47
48 if (SkXfermode::kSrcOver_Mode != mode) {
halcanary96fcdcc2015-08-27 07:41:13 -070049 REPORTER_ASSERT(reporter, !SkXfermode::IsMode(nullptr, mode));
mike@reedtribe.org3565f0f2011-11-17 02:27:26 +000050 }
51 }
52}
53
tfarina@chromium.orge4fafb12013-12-12 21:11:12 +000054DEF_TEST(Xfermode, reporter) {
mike@reedtribe.org3565f0f2011-11-17 02:27:26 +000055 test_asMode(reporter);
56 test_IsMode(reporter);
57}