aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/PointTest.cpp
diff options
context:
space:
mode:
authorGravatar reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-05-06 15:59:51 +0000
committerGravatar reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-05-06 15:59:51 +0000
commitfcc9ca09a56cd43015cc990898a55978bc2bf23d (patch)
treee46adc7e0abfb934fee537cc4718ee1d92608c93 /tests/PointTest.cpp
parentddb45a6ac0f64e08a22f6b63b79a6e46e49333e7 (diff)
by hook or by crook, force gcc to return the value of SkPoint::length() to actually be a float
instead of a double. Otherwise we can't properly test for overflow with large values. R=robertphillips@google.com Review URL: https://codereview.chromium.org/14884011 git-svn-id: http://skia.googlecode.com/svn/trunk@9015 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'tests/PointTest.cpp')
-rw-r--r--tests/PointTest.cpp22
1 files changed, 22 insertions, 0 deletions
diff --git a/tests/PointTest.cpp b/tests/PointTest.cpp
index 0b183c245e..1255a8c65d 100644
--- a/tests/PointTest.cpp
+++ b/tests/PointTest.cpp
@@ -61,6 +61,26 @@ template <typename T> T get_value(skiatest::Reporter* reporter, T value) {
return reporter ? value : 0;
}
+// On linux gcc, 32bit, we are seeing the compiler propagate up the value
+// of SkPoint::length() as a double (which we use sometimes to avoid overflow
+// during the computation), even though the signature says float (SkScalar).
+//
+// force_as_float is meant to capture our latest technique (horrible as
+// it is) to force the value to be a float, so we can test whether it was
+// finite or not.
+static float force_as_float(skiatest::Reporter* reporter, float value) {
+ uint32_t storage;
+ memcpy(&storage, &value, 4);
+ // even the pair of memcpy calls are not sufficient, since those seem to
+ // be no-op'd, so we add a runtime tests (just like get_value) to force
+ // the compiler to give us an actual float.
+ if (NULL == reporter) {
+ storage = ~storage;
+ }
+ memcpy(&value, &storage, 4);
+ return value;
+}
+
// test that we handle very large values correctly. i.e. that we can
// successfully normalize something whose mag overflows a float.
static void test_overflow(skiatest::Reporter* reporter) {
@@ -68,6 +88,8 @@ static void test_overflow(skiatest::Reporter* reporter) {
SkPoint pt = { bigFloat, bigFloat };
SkScalar length = pt.length();
+ length = force_as_float(reporter, length);
+
// expect this to be non-finite, but dump the results if not.
if (SkScalarIsFinite(length)) {
SkDebugf("length(%g, %g) == %g\n", pt.fX, pt.fY, length);