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/core/SkScalar.h"
10 #include "include/core/SkTypes.h"
11 #include "include/private/base/SkFloatingPoint.h"
12 #include "tests/Test.h"
13
14 #include <array>
15 #include <cstddef>
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.setLTRB(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.
DEF_TEST(InfRect,reporter)26 DEF_TEST(InfRect, reporter) {
27 float inf = SK_FloatInfinity;
28 float nan = SK_FloatNaN;
29 SkASSERT(!(nan == nan));
30 SkScalar small = SkIntToScalar(10);
31 SkScalar big = SkIntToScalar(100);
32
33 REPORTER_ASSERT(reporter, SkRect::MakeEmpty().isFinite());
34
35 SkRect rect = SkRect::MakeXYWH(small, small, big, big);
36 REPORTER_ASSERT(reporter, rect.isFinite());
37
38 const SkScalar invalid[] = { nan, inf, -inf };
39 for (size_t i = 0; i < std::size(invalid); ++i) {
40 check_invalid(reporter, small, small, big, invalid[i]);
41 check_invalid(reporter, small, small, invalid[i], big);
42 check_invalid(reporter, small, invalid[i], big, big);
43 check_invalid(reporter, invalid[i], small, big, big);
44 }
45 }
46
47 // need tests for SkStrSearch
48