1 /*
2 * Copyright 2011 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8 #include "include/core/SkRect.h"
9 #include "include/private/SkFloatingPoint.h"
10 #include "include/utils/SkRandom.h"
11 #include "tests/Test.h"
12
check_invalid(skiatest::Reporter * reporter,SkScalar l,SkScalar t,SkScalar r,SkScalar b)13 static void check_invalid(skiatest::Reporter* reporter,
14 SkScalar l, SkScalar t, SkScalar r, SkScalar b) {
15 SkRect rect;
16 rect.setLTRB(l, t, r, b);
17 REPORTER_ASSERT(reporter, !rect.isFinite());
18 }
19
20 // Tests that isFinite() will reject any rect with +/-inf values
21 // as one of its coordinates.
DEF_TEST(InfRect,reporter)22 DEF_TEST(InfRect, reporter) {
23 float inf = SK_FloatInfinity;
24 float nan = SK_FloatNaN;
25 SkASSERT(!(nan == nan));
26 SkScalar small = SkIntToScalar(10);
27 SkScalar big = SkIntToScalar(100);
28
29 REPORTER_ASSERT(reporter, SkRect::MakeEmpty().isFinite());
30
31 SkRect rect = SkRect::MakeXYWH(small, small, big, big);
32 REPORTER_ASSERT(reporter, rect.isFinite());
33
34 const SkScalar invalid[] = { nan, inf, -inf };
35 for (size_t i = 0; i < SK_ARRAY_COUNT(invalid); ++i) {
36 check_invalid(reporter, small, small, big, invalid[i]);
37 check_invalid(reporter, small, small, invalid[i], big);
38 check_invalid(reporter, small, invalid[i], big, big);
39 check_invalid(reporter, invalid[i], small, big, big);
40 }
41 }
42
43 // need tests for SkStrSearch
44