OLD | NEW |
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 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 // | 67 // |
68 // force_as_float is meant to capture our latest technique (horrible as | 68 // force_as_float is 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 | 69 // it is) to force the value to be a float, so we can test whether it was |
70 // finite or not. | 70 // finite or not. |
71 static float force_as_float(skiatest::Reporter* reporter, float value) { | 71 static float force_as_float(skiatest::Reporter* reporter, float value) { |
72 uint32_t storage; | 72 uint32_t storage; |
73 memcpy(&storage, &value, 4); | 73 memcpy(&storage, &value, 4); |
74 // even the pair of memcpy calls are not sufficient, since those seem to | 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 | 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. | 76 // the compiler to give us an actual float. |
77 if (NULL == reporter) { | 77 if (nullptr == reporter) { |
78 storage = ~storage; | 78 storage = ~storage; |
79 } | 79 } |
80 memcpy(&value, &storage, 4); | 80 memcpy(&value, &storage, 4); |
81 return value; | 81 return value; |
82 } | 82 } |
83 | 83 |
84 // 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 |
85 // successfully normalize something whose mag overflows a float. | 85 // successfully normalize something whose mag overflows a float. |
86 static void test_overflow(skiatest::Reporter* reporter) { | 86 static void test_overflow(skiatest::Reporter* reporter) { |
87 SkScalar bigFloat = get_value(reporter, 3.4e38f); | 87 SkScalar bigFloat = get_value(reporter, 3.4e38f); |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 slow.setLength(tests[i]); | 149 slow.setLength(tests[i]); |
150 fast.setLengthFast(tests[i]); | 150 fast.setLengthFast(tests[i]); |
151 | 151 |
152 if (slow.length() < FLT_MIN && fast.length() < FLT_MIN) continue; | 152 if (slow.length() < FLT_MIN && fast.length() < FLT_MIN) continue; |
153 | 153 |
154 SkScalar ratio = slow.length() / fast.length(); | 154 SkScalar ratio = slow.length() / fast.length(); |
155 REPORTER_ASSERT(reporter, ratio > 0.999f); | 155 REPORTER_ASSERT(reporter, ratio > 0.999f); |
156 REPORTER_ASSERT(reporter, ratio < 1.001f); | 156 REPORTER_ASSERT(reporter, ratio < 1.001f); |
157 } | 157 } |
158 } | 158 } |
OLD | NEW |