epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | |
| 2 | /* |
| 3 | * Copyright 2011 Google Inc. |
| 4 | * |
| 5 | * Use of this source code is governed by a BSD-style license that can be |
| 6 | * found in the LICENSE file. |
| 7 | */ |
vandebo@chromium.org | 4854327 | 2011-02-08 19:28:07 +0000 | [diff] [blame] | 8 | #include "Test.h" |
| 9 | #include "SkColor.h" |
| 10 | #include "SkXfermode.h" |
| 11 | |
caryclark@google.com | 42639cd | 2012-06-06 12:03:39 +0000 | [diff] [blame] | 12 | static SkPMColor bogusXfermodeProc(SkPMColor src, SkPMColor dst) { |
vandebo@chromium.org | 4854327 | 2011-02-08 19:28:07 +0000 | [diff] [blame] | 13 | return 42; |
| 14 | } |
| 15 | |
reed@google.com | c0d4aa2 | 2011-04-13 21:12:04 +0000 | [diff] [blame] | 16 | #define ILLEGAL_MODE ((SkXfermode::Mode)-1) |
| 17 | |
vandebo@chromium.org | 4854327 | 2011-02-08 19:28:07 +0000 | [diff] [blame] | 18 | static void test_asMode(skiatest::Reporter* reporter) { |
| 19 | for (int mode = 0; mode <= SkXfermode::kLastMode; mode++) { |
| 20 | SkXfermode* xfer = SkXfermode::Create((SkXfermode::Mode) mode); |
reed@google.com | c0d4aa2 | 2011-04-13 21:12:04 +0000 | [diff] [blame] | 21 | |
| 22 | SkXfermode::Mode reportedMode = ILLEGAL_MODE; |
| 23 | REPORTER_ASSERT(reporter, reportedMode != mode); |
| 24 | |
| 25 | // test IsMode |
| 26 | REPORTER_ASSERT(reporter, SkXfermode::IsMode(xfer, &reportedMode)); |
| 27 | REPORTER_ASSERT(reporter, reportedMode == mode); |
| 28 | |
| 29 | // repeat that test, but with asMode instead |
vandebo@chromium.org | 4854327 | 2011-02-08 19:28:07 +0000 | [diff] [blame] | 30 | if (xfer) { |
reed@google.com | c0d4aa2 | 2011-04-13 21:12:04 +0000 | [diff] [blame] | 31 | reportedMode = (SkXfermode::Mode) -1; |
| 32 | REPORTER_ASSERT(reporter, xfer->asMode(&reportedMode)); |
| 33 | REPORTER_ASSERT(reporter, reportedMode == mode); |
| 34 | xfer->unref(); |
| 35 | } else { |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 36 | REPORTER_ASSERT(reporter, SkXfermode::kSrcOver_Mode == mode); |
vandebo@chromium.org | 4854327 | 2011-02-08 19:28:07 +0000 | [diff] [blame] | 37 | } |
| 38 | } |
| 39 | |
| 40 | SkXfermode* bogusXfer = new SkProcXfermode(bogusXfermodeProc); |
tfarina@chromium.org | 0691078 | 2013-04-15 22:12:43 +0000 | [diff] [blame] | 41 | SkXfermode::Mode reportedMode = ILLEGAL_MODE; |
vandebo@chromium.org | 4854327 | 2011-02-08 19:28:07 +0000 | [diff] [blame] | 42 | REPORTER_ASSERT(reporter, !bogusXfer->asMode(&reportedMode)); |
tfarina@chromium.org | 0691078 | 2013-04-15 22:12:43 +0000 | [diff] [blame] | 43 | REPORTER_ASSERT(reporter, reportedMode == ILLEGAL_MODE); |
reed@google.com | c0d4aa2 | 2011-04-13 21:12:04 +0000 | [diff] [blame] | 44 | REPORTER_ASSERT(reporter, !SkXfermode::IsMode(bogusXfer, &reportedMode)); |
tfarina@chromium.org | 0691078 | 2013-04-15 22:12:43 +0000 | [diff] [blame] | 45 | REPORTER_ASSERT(reporter, reportedMode == ILLEGAL_MODE); |
vandebo@chromium.org | 4854327 | 2011-02-08 19:28:07 +0000 | [diff] [blame] | 46 | bogusXfer->unref(); |
| 47 | } |
| 48 | |
mike@reedtribe.org | 3565f0f | 2011-11-17 02:27:26 +0000 | [diff] [blame] | 49 | static void test_IsMode(skiatest::Reporter* reporter) { |
| 50 | REPORTER_ASSERT(reporter, SkXfermode::IsMode(NULL, |
| 51 | SkXfermode::kSrcOver_Mode)); |
| 52 | |
| 53 | for (int i = 0; i <= SkXfermode::kLastMode; ++i) { |
| 54 | SkXfermode::Mode mode = (SkXfermode::Mode)i; |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 55 | |
mike@reedtribe.org | 3565f0f | 2011-11-17 02:27:26 +0000 | [diff] [blame] | 56 | SkXfermode* xfer = SkXfermode::Create(mode); |
| 57 | REPORTER_ASSERT(reporter, SkXfermode::IsMode(xfer, mode)); |
| 58 | SkSafeUnref(xfer); |
| 59 | |
| 60 | if (SkXfermode::kSrcOver_Mode != mode) { |
| 61 | REPORTER_ASSERT(reporter, !SkXfermode::IsMode(NULL, mode)); |
| 62 | } |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | static void test_xfermodes(skiatest::Reporter* reporter) { |
| 67 | test_asMode(reporter); |
| 68 | test_IsMode(reporter); |
| 69 | } |
| 70 | |
vandebo@chromium.org | 4854327 | 2011-02-08 19:28:07 +0000 | [diff] [blame] | 71 | #include "TestClassDef.h" |
mike@reedtribe.org | 3565f0f | 2011-11-17 02:27:26 +0000 | [diff] [blame] | 72 | DEFINE_TESTCLASS("Xfermode", XfermodeTestClass, test_xfermodes) |