Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1296)

Unified Diff: tests/MathTest.cpp

Issue 1707023002: Add pinned versions of *ToFixed. (Closed) Base URL: https://skia.googlesource.com/skia@master
Patch Set: Rebase. Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « include/private/SkFixed.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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));
+}
« no previous file with comments | « include/private/SkFixed.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698