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 "Test.h" |
tfarina@chromium.org | e4fafb1 | 2013-12-12 21:11:12 +0000 | [diff] [blame] | 9 | #include "TestClassDef.h" |
vandebo@chromium.org | 4854327 | 2011-02-08 19:28:07 +0000 | [diff] [blame] | 10 | #include "SkColor.h" |
| 11 | #include "SkXfermode.h" |
| 12 | |
caryclark@google.com | 42639cd | 2012-06-06 12:03:39 +0000 | [diff] [blame] | 13 | static SkPMColor bogusXfermodeProc(SkPMColor src, SkPMColor dst) { |
vandebo@chromium.org | 4854327 | 2011-02-08 19:28:07 +0000 | [diff] [blame] | 14 | return 42; |
| 15 | } |
| 16 | |
reed@google.com | c0d4aa2 | 2011-04-13 21:12:04 +0000 | [diff] [blame] | 17 | #define ILLEGAL_MODE ((SkXfermode::Mode)-1) |
| 18 | |
vandebo@chromium.org | 4854327 | 2011-02-08 19:28:07 +0000 | [diff] [blame] | 19 | static 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.com | c0d4aa2 | 2011-04-13 21:12:04 +0000 | [diff] [blame] | 22 | |
| 23 | SkXfermode::Mode reportedMode = ILLEGAL_MODE; |
| 24 | REPORTER_ASSERT(reporter, reportedMode != mode); |
| 25 | |
| 26 | // test IsMode |
reed@google.com | 4469938 | 2013-10-31 17:28:30 +0000 | [diff] [blame] | 27 | REPORTER_ASSERT(reporter, SkXfermode::AsMode(xfer, &reportedMode)); |
reed@google.com | c0d4aa2 | 2011-04-13 21:12:04 +0000 | [diff] [blame] | 28 | REPORTER_ASSERT(reporter, reportedMode == mode); |
| 29 | |
| 30 | // repeat that test, but with asMode instead |
vandebo@chromium.org | 4854327 | 2011-02-08 19:28:07 +0000 | [diff] [blame] | 31 | if (xfer) { |
reed@google.com | c0d4aa2 | 2011-04-13 21:12:04 +0000 | [diff] [blame] | 32 | reportedMode = (SkXfermode::Mode) -1; |
| 33 | REPORTER_ASSERT(reporter, xfer->asMode(&reportedMode)); |
| 34 | REPORTER_ASSERT(reporter, reportedMode == mode); |
| 35 | xfer->unref(); |
| 36 | } else { |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 37 | REPORTER_ASSERT(reporter, SkXfermode::kSrcOver_Mode == mode); |
vandebo@chromium.org | 4854327 | 2011-02-08 19:28:07 +0000 | [diff] [blame] | 38 | } |
| 39 | } |
| 40 | |
| 41 | SkXfermode* bogusXfer = new SkProcXfermode(bogusXfermodeProc); |
tfarina@chromium.org | 0691078 | 2013-04-15 22:12:43 +0000 | [diff] [blame] | 42 | SkXfermode::Mode reportedMode = ILLEGAL_MODE; |
vandebo@chromium.org | 4854327 | 2011-02-08 19:28:07 +0000 | [diff] [blame] | 43 | REPORTER_ASSERT(reporter, !bogusXfer->asMode(&reportedMode)); |
tfarina@chromium.org | 0691078 | 2013-04-15 22:12:43 +0000 | [diff] [blame] | 44 | REPORTER_ASSERT(reporter, reportedMode == ILLEGAL_MODE); |
reed@google.com | 4469938 | 2013-10-31 17:28:30 +0000 | [diff] [blame] | 45 | REPORTER_ASSERT(reporter, !SkXfermode::AsMode(bogusXfer, &reportedMode)); |
tfarina@chromium.org | 0691078 | 2013-04-15 22:12:43 +0000 | [diff] [blame] | 46 | REPORTER_ASSERT(reporter, reportedMode == ILLEGAL_MODE); |
vandebo@chromium.org | 4854327 | 2011-02-08 19:28:07 +0000 | [diff] [blame] | 47 | bogusXfer->unref(); |
| 48 | } |
| 49 | |
mike@reedtribe.org | 3565f0f | 2011-11-17 02:27:26 +0000 | [diff] [blame] | 50 | static 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.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 56 | |
mike@reedtribe.org | 3565f0f | 2011-11-17 02:27:26 +0000 | [diff] [blame] | 57 | 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.org | e4fafb1 | 2013-12-12 21:11:12 +0000 | [diff] [blame] | 67 | DEF_TEST(Xfermode, reporter) { |
mike@reedtribe.org | 3565f0f | 2011-11-17 02:27:26 +0000 | [diff] [blame] | 68 | test_asMode(reporter); |
| 69 | test_IsMode(reporter); |
| 70 | } |