OLD | NEW |
1 | |
2 /* | 1 /* |
3 * Copyright 2011 Google Inc. | 2 * Copyright 2011 Google Inc. |
4 * | 3 * |
5 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 5 * found in the LICENSE file. |
7 */ | 6 */ |
| 7 |
8 #include "Test.h" | 8 #include "Test.h" |
| 9 #include "TestClassDef.h" |
9 #include "SkRandom.h" | 10 #include "SkRandom.h" |
10 #include "SkRect.h" | 11 #include "SkRect.h" |
11 | 12 |
12 #ifdef SK_SCALAR_IS_FLOAT | 13 #ifdef SK_SCALAR_IS_FLOAT |
13 static float make_zero() { | 14 static float make_zero() { |
14 return sk_float_sin(0); | 15 return sk_float_sin(0); |
15 } | 16 } |
16 #endif | 17 #endif |
17 | 18 |
18 struct RectCenter { | 19 struct RectCenter { |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 | 51 |
51 static void check_invalid(skiatest::Reporter* reporter, | 52 static void check_invalid(skiatest::Reporter* reporter, |
52 SkScalar l, SkScalar t, SkScalar r, SkScalar b) { | 53 SkScalar l, SkScalar t, SkScalar r, SkScalar b) { |
53 SkRect rect; | 54 SkRect rect; |
54 rect.set(l, t, r, b); | 55 rect.set(l, t, r, b); |
55 REPORTER_ASSERT(reporter, !rect.isFinite()); | 56 REPORTER_ASSERT(reporter, !rect.isFinite()); |
56 } | 57 } |
57 | 58 |
58 // Tests that isFinite() will reject any rect with +/-inf values | 59 // Tests that isFinite() will reject any rect with +/-inf values |
59 // as one of its coordinates. | 60 // as one of its coordinates. |
60 static void TestInfRect(skiatest::Reporter* reporter) { | 61 DEF_TEST(InfRect, reporter) { |
61 #ifdef SK_SCALAR_IS_FLOAT | 62 #ifdef SK_SCALAR_IS_FLOAT |
62 float inf = 1 / make_zero(); // infinity | 63 float inf = 1 / make_zero(); // infinity |
63 float nan = inf * 0; | 64 float nan = inf * 0; |
64 SkASSERT(!(nan == nan)); | 65 SkASSERT(!(nan == nan)); |
65 #else | 66 #else |
66 SkFixed inf = SK_FixedNaN; | 67 SkFixed inf = SK_FixedNaN; |
67 SkFixed nan = SK_FixedNaN; | 68 SkFixed nan = SK_FixedNaN; |
68 #endif | 69 #endif |
69 SkScalar small = SkIntToScalar(10); | 70 SkScalar small = SkIntToScalar(10); |
70 SkScalar big = SkIntToScalar(100); | 71 SkScalar big = SkIntToScalar(100); |
71 | 72 |
72 REPORTER_ASSERT(reporter, SkRect::MakeEmpty().isFinite()); | 73 REPORTER_ASSERT(reporter, SkRect::MakeEmpty().isFinite()); |
73 | 74 |
74 SkRect rect = SkRect::MakeXYWH(small, small, big, big); | 75 SkRect rect = SkRect::MakeXYWH(small, small, big, big); |
75 REPORTER_ASSERT(reporter, rect.isFinite()); | 76 REPORTER_ASSERT(reporter, rect.isFinite()); |
76 | 77 |
77 const SkScalar invalid[] = { nan, inf, -inf }; | 78 const SkScalar invalid[] = { nan, inf, -inf }; |
78 for (size_t i = 0; i < SK_ARRAY_COUNT(invalid); ++i) { | 79 for (size_t i = 0; i < SK_ARRAY_COUNT(invalid); ++i) { |
79 check_invalid(reporter, small, small, big, invalid[i]); | 80 check_invalid(reporter, small, small, big, invalid[i]); |
80 check_invalid(reporter, small, small, invalid[i], big); | 81 check_invalid(reporter, small, small, invalid[i], big); |
81 check_invalid(reporter, small, invalid[i], big, big); | 82 check_invalid(reporter, small, invalid[i], big, big); |
82 check_invalid(reporter, invalid[i], small, big, big); | 83 check_invalid(reporter, invalid[i], small, big, big); |
83 } | 84 } |
84 | 85 |
85 test_center(reporter); | 86 test_center(reporter); |
86 } | 87 } |
87 | 88 |
88 // need tests for SkStrSearch | 89 // need tests for SkStrSearch |
89 | |
90 #include "TestClassDef.h" | |
91 DEFINE_TESTCLASS("InfRect", InfRectTestClass, TestInfRect) | |
OLD | NEW |