diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/PMFloatTest.cpp | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/tests/PMFloatTest.cpp b/tests/PMFloatTest.cpp new file mode 100644 index 0000000000..94cd663a53 --- /dev/null +++ b/tests/PMFloatTest.cpp @@ -0,0 +1,29 @@ +#include "SkPMFloat.h" +#include "Test.h" + +DEF_TEST(SkPMFloat, r) { + SkPMColor c = SkPreMultiplyColor(0xFFCC9933); + + SkPMFloat pmf; + pmf.set(c); + REPORTER_ASSERT(r, SkScalarNearlyEqual(1.0f, pmf.a())); + REPORTER_ASSERT(r, SkScalarNearlyEqual(0.8f, pmf.r())); + REPORTER_ASSERT(r, SkScalarNearlyEqual(0.6f, pmf.g())); + REPORTER_ASSERT(r, SkScalarNearlyEqual(0.2f, pmf.b())); + + REPORTER_ASSERT(r, c == pmf.get()); + + SkPMFloat unclamped; + unclamped.setA(+2.0f); + unclamped.setR(+0.2f); + unclamped.setG(-0.2f); + unclamped.setB(-5.0f); + + SkPMFloat clamped; + clamped.set(unclamped.clamped()); + + REPORTER_ASSERT(r, SkScalarNearlyEqual(1.0f, clamped.a())); + REPORTER_ASSERT(r, SkScalarNearlyEqual(0.2f, clamped.r())); + REPORTER_ASSERT(r, SkScalarNearlyEqual(0.0f, clamped.g())); + REPORTER_ASSERT(r, SkScalarNearlyEqual(0.0f, clamped.b())); +} |