1
2 /*
3 * Copyright 2011 Google Inc.
4 *
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
7 */
8 #include "Test.h"
9 #include "SkRect.h"
10
11 #ifdef SK_SCALAR_IS_FLOAT
make_zero()12 static float make_zero() {
13 return sk_float_sin(0);
14 }
15 #endif
16
check_invalid(skiatest::Reporter * reporter,SkScalar l,SkScalar t,SkScalar r,SkScalar b)17 static void check_invalid(skiatest::Reporter* reporter,
18 SkScalar l, SkScalar t, SkScalar r, SkScalar b) {
19 SkRect rect;
20 rect.set(l, t, r, b);
21 REPORTER_ASSERT(reporter, !rect.isFinite());
22 }
23
24 // Tests that isFinite() will reject any rect with +/-inf values
25 // as one of its coordinates.
TestInfRect(skiatest::Reporter * reporter)26 static void TestInfRect(skiatest::Reporter* reporter) {
27 #ifdef SK_SCALAR_IS_FLOAT
28 float invalid = 1 / make_zero(); // infinity
29 #else
30 SkFixed invalid = SK_FixedNaN;
31 #endif
32 SkScalar small = SkIntToScalar(10);
33 SkScalar big = SkIntToScalar(100);
34
35 SkRect rect = SkRect::MakeXYWH(small, small, big, big);
36 REPORTER_ASSERT(reporter, rect.isFinite());
37
38 check_invalid(reporter, small, small, big, invalid);
39 check_invalid(reporter, small, small, invalid, big);
40 check_invalid(reporter, small, invalid, big, big);
41 check_invalid(reporter, invalid, small, big, big);
42 check_invalid(reporter, small, small, big, -invalid);
43 check_invalid(reporter, small, small, -invalid, big);
44 check_invalid(reporter, small, -invalid, big, big);
45 check_invalid(reporter, -invalid, small, big, big);
46 }
47
48 // need tests for SkStrSearch
49
50 #include "TestClassDef.h"
51 DEFINE_TESTCLASS("InfRect", InfRectTestClass, TestInfRect)
52