2011-02-08 19:28:07 +00:00
|
|
|
#include "Test.h"
|
|
|
|
#include "SkColor.h"
|
|
|
|
#include "SkXfermode.h"
|
|
|
|
|
|
|
|
SkPMColor bogusXfermodeProc(SkPMColor src, SkPMColor dst) {
|
|
|
|
return 42;
|
|
|
|
}
|
|
|
|
|
2011-04-13 21:12:04 +00:00
|
|
|
#define ILLEGAL_MODE ((SkXfermode::Mode)-1)
|
|
|
|
|
2011-02-08 19:28:07 +00:00
|
|
|
static void test_asMode(skiatest::Reporter* reporter) {
|
|
|
|
for (int mode = 0; mode <= SkXfermode::kLastMode; mode++) {
|
|
|
|
SkXfermode* xfer = SkXfermode::Create((SkXfermode::Mode) mode);
|
2011-04-13 21:12:04 +00:00
|
|
|
|
|
|
|
SkXfermode::Mode reportedMode = ILLEGAL_MODE;
|
|
|
|
REPORTER_ASSERT(reporter, reportedMode != mode);
|
|
|
|
|
|
|
|
// test IsMode
|
|
|
|
REPORTER_ASSERT(reporter, SkXfermode::IsMode(xfer, &reportedMode));
|
|
|
|
REPORTER_ASSERT(reporter, reportedMode == mode);
|
|
|
|
|
|
|
|
// repeat that test, but with asMode instead
|
2011-02-08 19:28:07 +00:00
|
|
|
if (xfer) {
|
2011-04-13 21:12:04 +00:00
|
|
|
reportedMode = (SkXfermode::Mode) -1;
|
|
|
|
REPORTER_ASSERT(reporter, xfer->asMode(&reportedMode));
|
|
|
|
REPORTER_ASSERT(reporter, reportedMode == mode);
|
|
|
|
xfer->unref();
|
|
|
|
} else {
|
|
|
|
REPORTER_ASSERT(reporter, SkXfermode::kSrcOver_Mode == mode);
|
2011-02-08 19:28:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SkXfermode* bogusXfer = new SkProcXfermode(bogusXfermodeProc);
|
|
|
|
SkXfermode::Mode reportedMode = (SkXfermode::Mode) -1;
|
|
|
|
REPORTER_ASSERT(reporter, !bogusXfer->asMode(&reportedMode));
|
|
|
|
REPORTER_ASSERT(reporter, reportedMode == -1);
|
2011-04-13 21:12:04 +00:00
|
|
|
REPORTER_ASSERT(reporter, !SkXfermode::IsMode(bogusXfer, &reportedMode));
|
|
|
|
REPORTER_ASSERT(reporter, reportedMode == -1);
|
2011-02-08 19:28:07 +00:00
|
|
|
bogusXfer->unref();
|
|
|
|
}
|
|
|
|
|
|
|
|
#include "TestClassDef.h"
|
|
|
|
DEFINE_TESTCLASS("Xfermode", XfermodeTestClass, test_asMode)
|