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

Side by Side Diff: tests/InfRectTest.cpp

Issue 117053002: remove SK_SCALAR_IS_[FLOAT,FIXED] and assume floats (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 7 years 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
OLDNEW
1 /* 1 /*
2 * Copyright 2011 Google Inc. 2 * Copyright 2011 Google Inc.
3 * 3 *
4 * 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
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "Test.h" 8 #include "Test.h"
9 #include "TestClassDef.h" 9 #include "TestClassDef.h"
10 #include "SkRandom.h" 10 #include "SkRandom.h"
11 #include "SkRect.h" 11 #include "SkRect.h"
12 12
13 #ifdef SK_SCALAR_IS_FLOAT
14 static float make_zero() { 13 static float make_zero() {
15 return sk_float_sin(0); 14 return sk_float_sin(0);
16 } 15 }
17 #endif
18 16
19 struct RectCenter { 17 struct RectCenter {
20 SkIRect fRect; 18 SkIRect fRect;
21 SkIPoint fCenter; 19 SkIPoint fCenter;
22 }; 20 };
23 21
24 static void test_center(skiatest::Reporter* reporter) { 22 static void test_center(skiatest::Reporter* reporter) {
25 static const RectCenter gData[] = { 23 static const RectCenter gData[] = {
26 { { 0, 0, 0, 0 }, { 0, 0 } }, 24 { { 0, 0, 0, 0 }, { 0, 0 } },
27 { { 0, 0, 1, 1 }, { 0, 0 } }, 25 { { 0, 0, 1, 1 }, { 0, 0 } },
(...skipping 24 matching lines...) Expand all
52 static void check_invalid(skiatest::Reporter* reporter, 50 static void check_invalid(skiatest::Reporter* reporter,
53 SkScalar l, SkScalar t, SkScalar r, SkScalar b) { 51 SkScalar l, SkScalar t, SkScalar r, SkScalar b) {
54 SkRect rect; 52 SkRect rect;
55 rect.set(l, t, r, b); 53 rect.set(l, t, r, b);
56 REPORTER_ASSERT(reporter, !rect.isFinite()); 54 REPORTER_ASSERT(reporter, !rect.isFinite());
57 } 55 }
58 56
59 // Tests that isFinite() will reject any rect with +/-inf values 57 // Tests that isFinite() will reject any rect with +/-inf values
60 // as one of its coordinates. 58 // as one of its coordinates.
61 DEF_TEST(InfRect, reporter) { 59 DEF_TEST(InfRect, reporter) {
62 #ifdef SK_SCALAR_IS_FLOAT
63 float inf = 1 / make_zero(); // infinity 60 float inf = 1 / make_zero(); // infinity
64 float nan = inf * 0; 61 float nan = inf * 0;
65 SkASSERT(!(nan == nan)); 62 SkASSERT(!(nan == nan));
66 #else
67 SkFixed inf = SK_FixedNaN;
68 SkFixed nan = SK_FixedNaN;
69 #endif
70 SkScalar small = SkIntToScalar(10); 63 SkScalar small = SkIntToScalar(10);
71 SkScalar big = SkIntToScalar(100); 64 SkScalar big = SkIntToScalar(100);
72 65
73 REPORTER_ASSERT(reporter, SkRect::MakeEmpty().isFinite()); 66 REPORTER_ASSERT(reporter, SkRect::MakeEmpty().isFinite());
74 67
75 SkRect rect = SkRect::MakeXYWH(small, small, big, big); 68 SkRect rect = SkRect::MakeXYWH(small, small, big, big);
76 REPORTER_ASSERT(reporter, rect.isFinite()); 69 REPORTER_ASSERT(reporter, rect.isFinite());
77 70
78 const SkScalar invalid[] = { nan, inf, -inf }; 71 const SkScalar invalid[] = { nan, inf, -inf };
79 for (size_t i = 0; i < SK_ARRAY_COUNT(invalid); ++i) { 72 for (size_t i = 0; i < SK_ARRAY_COUNT(invalid); ++i) {
80 check_invalid(reporter, small, small, big, invalid[i]); 73 check_invalid(reporter, small, small, big, invalid[i]);
81 check_invalid(reporter, small, small, invalid[i], big); 74 check_invalid(reporter, small, small, invalid[i], big);
82 check_invalid(reporter, small, invalid[i], big, big); 75 check_invalid(reporter, small, invalid[i], big, big);
83 check_invalid(reporter, invalid[i], small, big, big); 76 check_invalid(reporter, invalid[i], small, big, big);
84 } 77 }
85 78
86 test_center(reporter); 79 test_center(reporter);
87 } 80 }
88 81
89 // need tests for SkStrSearch 82 // need tests for SkStrSearch
OLDNEW
« src/core/SkCanvas.cpp ('K') | « tests/DrawPathTest.cpp ('k') | tests/MathTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698