epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 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 | */ |
tfarina@chromium.org | e4fafb1 | 2013-12-12 21:11:12 +0000 | [diff] [blame] | 7 | |
vandebo@chromium.org | 4854327 | 2011-02-08 19:28:07 +0000 | [diff] [blame] | 8 | #include "SkColor.h" |
| 9 | #include "SkXfermode.h" |
tfarina@chromium.org | 8f6884a | 2014-01-24 20:56:26 +0000 | [diff] [blame] | 10 | #include "Test.h" |
vandebo@chromium.org | 4854327 | 2011-02-08 19:28:07 +0000 | [diff] [blame] | 11 | |
reed@google.com | c0d4aa2 | 2011-04-13 21:12:04 +0000 | [diff] [blame] | 12 | #define ILLEGAL_MODE ((SkXfermode::Mode)-1) |
| 13 | |
vandebo@chromium.org | 4854327 | 2011-02-08 19:28:07 +0000 | [diff] [blame] | 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); |
reed@google.com | c0d4aa2 | 2011-04-13 21:12:04 +0000 | [diff] [blame] | 17 | |
| 18 | SkXfermode::Mode reportedMode = ILLEGAL_MODE; |
| 19 | REPORTER_ASSERT(reporter, reportedMode != mode); |
| 20 | |
| 21 | // test IsMode |
reed@google.com | 4469938 | 2013-10-31 17:28:30 +0000 | [diff] [blame] | 22 | REPORTER_ASSERT(reporter, SkXfermode::AsMode(xfer, &reportedMode)); |
reed@google.com | c0d4aa2 | 2011-04-13 21:12:04 +0000 | [diff] [blame] | 23 | REPORTER_ASSERT(reporter, reportedMode == mode); |
| 24 | |
| 25 | // repeat that test, but with asMode instead |
vandebo@chromium.org | 4854327 | 2011-02-08 19:28:07 +0000 | [diff] [blame] | 26 | if (xfer) { |
reed@google.com | c0d4aa2 | 2011-04-13 21:12:04 +0000 | [diff] [blame] | 27 | reportedMode = (SkXfermode::Mode) -1; |
| 28 | REPORTER_ASSERT(reporter, xfer->asMode(&reportedMode)); |
| 29 | REPORTER_ASSERT(reporter, reportedMode == mode); |
| 30 | xfer->unref(); |
| 31 | } else { |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 32 | REPORTER_ASSERT(reporter, SkXfermode::kSrcOver_Mode == mode); |
vandebo@chromium.org | 4854327 | 2011-02-08 19:28:07 +0000 | [diff] [blame] | 33 | } |
| 34 | } |
vandebo@chromium.org | 4854327 | 2011-02-08 19:28:07 +0000 | [diff] [blame] | 35 | } |
| 36 | |
mike@reedtribe.org | 3565f0f | 2011-11-17 02:27:26 +0000 | [diff] [blame] | 37 | static void test_IsMode(skiatest::Reporter* reporter) { |
| 38 | REPORTER_ASSERT(reporter, SkXfermode::IsMode(NULL, |
| 39 | SkXfermode::kSrcOver_Mode)); |
| 40 | |
| 41 | for (int i = 0; i <= SkXfermode::kLastMode; ++i) { |
| 42 | SkXfermode::Mode mode = (SkXfermode::Mode)i; |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 43 | |
mike@reedtribe.org | 3565f0f | 2011-11-17 02:27:26 +0000 | [diff] [blame] | 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(NULL, mode)); |
| 50 | } |
| 51 | } |
| 52 | } |
| 53 | |
tfarina@chromium.org | e4fafb1 | 2013-12-12 21:11:12 +0000 | [diff] [blame] | 54 | DEF_TEST(Xfermode, reporter) { |
mike@reedtribe.org | 3565f0f | 2011-11-17 02:27:26 +0000 | [diff] [blame] | 55 | test_asMode(reporter); |
| 56 | test_IsMode(reporter); |
| 57 | } |