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

Side by Side Diff: trunk/tests/PointTest.cpp

Issue 14884011: by hook or by crook, force gcc to return the value of SkPoint::length() to actually be a float (Closed) Base URL: http://skia.googlecode.com/svn/
Patch Set: Created 7 years, 7 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 1
2 /* 2 /*
3 * Copyright 2011 Google Inc. 3 * Copyright 2011 Google Inc.
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 // Unit tests for src/core/SkPoint.cpp and its header 8 // Unit tests for src/core/SkPoint.cpp and its header
9 9
10 #include "SkPoint.h" 10 #include "SkPoint.h"
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 // Ugh. Windows compiler can dive into other .cpp files, and sometimes 53 // Ugh. Windows compiler can dive into other .cpp files, and sometimes
54 // notices that I will generate an overflow... which is exactly the point 54 // notices that I will generate an overflow... which is exactly the point
55 // of this test! 55 // of this test!
56 // 56 //
57 // To avoid this warning, I need to convince the compiler that I might not 57 // To avoid this warning, I need to convince the compiler that I might not
58 // use that big value, hence this hacky helper function: reporter is 58 // use that big value, hence this hacky helper function: reporter is
59 // ALWAYS non-null. (shhhhhh, don't tell the compiler that). 59 // ALWAYS non-null. (shhhhhh, don't tell the compiler that).
60 template <typename T> T get_value(skiatest::Reporter* reporter, T value) { 60 template <typename T> T get_value(skiatest::Reporter* reporter, T value) {
61 return reporter ? value : 0; 61 return reporter ? value : 0;
62 } 62 }
63 63
robertphillips 2013/05/06 15:42:23 propagate
64 // On linux gcc, 32bit, we are seeing the compiler propogate up the value
65 // of SkPoint::length() as a double (which we use sometimes to avoid overflow
66 // during the computation), even though the signature says float (SkScalar).
67 //
robertphillips 2013/05/06 15:42:23 rm "must"?
68 // force_as_float is must meant to capture our latest technique (horrible as
69 // it is) to force the value to be a float, so we can test whether it was
70 // finite or not.
71 static float force_as_float(skiatest::Reporter* reporter, float value) {
72 uint32_t storage;
73 memcpy(&storage, &value, 4);
74 // even the pair of memcpy calls are not sufficient, since those seem to
75 // be no-op'd, so we add a runtime tests (just like get_value) to force
76 // the compiler to give us an actual float.
77 if (NULL == reporter) {
78 storage = ~storage;
79 }
80 memcpy(&value, &storage, 4);
81 return value;
82 }
83
64 // test that we handle very large values correctly. i.e. that we can 84 // test that we handle very large values correctly. i.e. that we can
65 // successfully normalize something whose mag overflows a float. 85 // successfully normalize something whose mag overflows a float.
66 static void test_overflow(skiatest::Reporter* reporter) { 86 static void test_overflow(skiatest::Reporter* reporter) {
67 SkScalar bigFloat = get_value(reporter, SkFloatToScalar(3.4e38f)); 87 SkScalar bigFloat = get_value(reporter, SkFloatToScalar(3.4e38f));
68 SkPoint pt = { bigFloat, bigFloat }; 88 SkPoint pt = { bigFloat, bigFloat };
69 89
70 SkScalar length = pt.length(); 90 SkScalar length = pt.length();
91 length = force_as_float(reporter, length);
92
71 // expect this to be non-finite, but dump the results if not. 93 // expect this to be non-finite, but dump the results if not.
72 if (SkScalarIsFinite(length)) { 94 if (SkScalarIsFinite(length)) {
73 SkDebugf("length(%g, %g) == %g\n", pt.fX, pt.fY, length); 95 SkDebugf("length(%g, %g) == %g\n", pt.fX, pt.fY, length);
74 REPORTER_ASSERT(reporter, !SkScalarIsFinite(length)); 96 REPORTER_ASSERT(reporter, !SkScalarIsFinite(length));
75 } 97 }
76 98
77 // this should succeed, even though we can't represent length 99 // this should succeed, even though we can't represent length
78 REPORTER_ASSERT(reporter, pt.setLength(SK_Scalar1)); 100 REPORTER_ASSERT(reporter, pt.setLength(SK_Scalar1));
79 101
80 // now that pt is normalized, we check its length 102 // now that pt is normalized, we check its length
(...skipping 29 matching lines...) Expand all
110 for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); ++i) { 132 for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); ++i) {
111 test_length(reporter, gRec[i].fX, gRec[i].fY, gRec[i].fLength); 133 test_length(reporter, gRec[i].fX, gRec[i].fY, gRec[i].fLength);
112 } 134 }
113 135
114 test_underflow(reporter); 136 test_underflow(reporter);
115 test_overflow(reporter); 137 test_overflow(reporter);
116 } 138 }
117 139
118 #include "TestClassDef.h" 140 #include "TestClassDef.h"
119 DEFINE_TESTCLASS("Point", PointTestClass, PointTest) 141 DEFINE_TESTCLASS("Point", PointTestClass, PointTest)
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698