1 /*
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 */
7
8 #include "SkColor.h"
9 #include "SkXfermode.h"
10 #include "Test.h"
11
12 #define ILLEGAL_MODE ((SkXfermode::Mode)-1)
13
test_asMode(skiatest::Reporter * reporter)14 static void test_asMode(skiatest::Reporter* reporter) {
15 for (int mode = 0; mode <= SkXfermode::kLastMode; mode++) {
16 SkXfermode* xfer = SkXfermode::Create((SkXfermode::Mode) mode);
17
18 SkXfermode::Mode reportedMode = ILLEGAL_MODE;
19 REPORTER_ASSERT(reporter, reportedMode != mode);
20
21 // test IsMode
22 REPORTER_ASSERT(reporter, SkXfermode::AsMode(xfer, &reportedMode));
23 REPORTER_ASSERT(reporter, reportedMode == mode);
24
25 // repeat that test, but with asMode instead
26 if (xfer) {
27 reportedMode = (SkXfermode::Mode) -1;
28 REPORTER_ASSERT(reporter, xfer->asMode(&reportedMode));
29 REPORTER_ASSERT(reporter, reportedMode == mode);
30 xfer->unref();
31 } else {
32 REPORTER_ASSERT(reporter, SkXfermode::kSrcOver_Mode == mode);
33 }
34 }
35 }
36
test_IsMode(skiatest::Reporter * reporter)37 static void test_IsMode(skiatest::Reporter* reporter) {
38 REPORTER_ASSERT(reporter, SkXfermode::IsMode(nullptr,
39 SkXfermode::kSrcOver_Mode));
40
41 for (int i = 0; i <= SkXfermode::kLastMode; ++i) {
42 SkXfermode::Mode mode = (SkXfermode::Mode)i;
43
44 SkXfermode* xfer = SkXfermode::Create(mode);
45 REPORTER_ASSERT(reporter, SkXfermode::IsMode(xfer, mode));
46 SkSafeUnref(xfer);
47
48 if (SkXfermode::kSrcOver_Mode != mode) {
49 REPORTER_ASSERT(reporter, !SkXfermode::IsMode(nullptr, mode));
50 }
51 }
52 }
53
DEF_TEST(Xfermode,reporter)54 DEF_TEST(Xfermode, reporter) {
55 test_asMode(reporter);
56 test_IsMode(reporter);
57 }
58