Index: tests/MathTest.cpp |
diff --git a/tests/MathTest.cpp b/tests/MathTest.cpp |
index 580cd941fa926bc215165fb30daed5552995501a..9343277f8d8626b471839a1a054fd24896aa957d 100644 |
--- a/tests/MathTest.cpp |
+++ b/tests/MathTest.cpp |
@@ -5,6 +5,8 @@ |
* found in the LICENSE file. |
*/ |
+#include "float.h" |
+ |
#include "SkColorPriv.h" |
#include "SkEndian.h" |
#include "SkFixed.h" |
@@ -697,3 +699,41 @@ DEF_TEST(divmod_s32, r) { |
DEF_TEST(divmod_s64, r) { |
test_divmod<int64_t>(r); |
} |
+ |
+DEF_TEST(PinToFixed, reporter) { |
+ // double |
+ REPORTER_ASSERT(reporter, 0 == SkDoublePinToFixed(0.0)); |
+ REPORTER_ASSERT(reporter, 0x10000 == SkDoublePinToFixed(1.0)); |
+ REPORTER_ASSERT(reporter, 0x7FFFFFFE == SkDoublePinToFixed(32767.999984741)); |
+ REPORTER_ASSERT(reporter, 0x7FFFFFFF == SkDoublePinToFixed(32767.999984742)); |
+ REPORTER_ASSERT(reporter, 0x7FFFFFFF == SkDoublePinToFixed(32767.999999999)); |
+ REPORTER_ASSERT(reporter, 0x7FFFFFFF == SkDoublePinToFixed(32768.0)); |
+ REPORTER_ASSERT(reporter, 0x7FFFFFFF == SkDoublePinToFixed(5e10)); |
+ REPORTER_ASSERT(reporter, 0x7FFFFFFF == SkDoublePinToFixed(DBL_MAX)); |
+ REPORTER_ASSERT(reporter, -0x10000 == SkDoublePinToFixed(-1.0)); |
+ // SK_FixedMin is defined to be -SK_FixedMax. |
+ REPORTER_ASSERT(reporter, -0x7FFFFFFE == SkDoublePinToFixed(-32767.999984741)); |
+ REPORTER_ASSERT(reporter, -0x7FFFFFFF == SkDoublePinToFixed(-32767.999984742)); |
+ REPORTER_ASSERT(reporter, -0x7FFFFFFF == SkDoublePinToFixed(-32767.999999999)); |
+ REPORTER_ASSERT(reporter, -0x7FFFFFFF == SkDoublePinToFixed(-32768.0)); |
+ REPORTER_ASSERT(reporter, -0x7FFFFFFF == SkDoublePinToFixed(-5e10)); |
+ REPORTER_ASSERT(reporter, -0x7FFFFFFF == SkDoublePinToFixed(-DBL_MAX)); |
+ |
+ // float |
+ REPORTER_ASSERT(reporter, 0 == SkFloatPinToFixed(0.0f)); |
+ REPORTER_ASSERT(reporter, 0x10000 == SkFloatPinToFixed(1.0f)); |
+ // SkFixed has more precision than float near SK_FixedMax, so SkFloatPinToFixed will never |
+ // produce output between 0x7FFFFF80 and 0x7FFFFFFF. |
+ REPORTER_ASSERT(reporter, 0x7FFFFF80 == SkFloatPinToFixed(32767.9990f)); |
+ REPORTER_ASSERT(reporter, 0x7FFFFFFF == SkFloatPinToFixed(32767.9991f)); |
+ REPORTER_ASSERT(reporter, 0x7FFFFFFF == SkFloatPinToFixed(32768.0f)); |
+ REPORTER_ASSERT(reporter, 0x7FFFFFFF == SkFloatPinToFixed(5e10f)); |
+ REPORTER_ASSERT(reporter, 0x7FFFFFFF == SkFloatPinToFixed(FLT_MAX)); |
+ REPORTER_ASSERT(reporter, -0x10000 == SkFloatPinToFixed(-1.0f)); |
+ // SK_FixedMin is defined to be -SK_FixedMax. |
+ REPORTER_ASSERT(reporter, -0x7FFFFF80 == SkFloatPinToFixed(-32767.9990f)); |
+ REPORTER_ASSERT(reporter, -0x7FFFFFFF == SkFloatPinToFixed(-32767.9991f)); |
+ REPORTER_ASSERT(reporter, -0x7FFFFFFF == SkFloatPinToFixed(-32768.0f)); |
+ REPORTER_ASSERT(reporter, -0x7FFFFFFF == SkFloatPinToFixed(-5e10f)); |
+ REPORTER_ASSERT(reporter, -0x7FFFFFFF == SkFloatPinToFixed(-FLT_MAX)); |
+} |