2 * Copyright 2011 Google Inc.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
8 #include "include/core/SkRect.h"
9 #include "include/private/SkFloatingPoint.h"
10 #include "include/utils/SkRandom.h"
11 #include "tests/Test.h"
13 static void check_invalid(skiatest::Reporter* reporter,
14 SkScalar l, SkScalar t, SkScalar r, SkScalar b) {
16 rect.setLTRB(l, t, r, b);
17 REPORTER_ASSERT(reporter, !rect.isFinite());
20 // Tests that isFinite() will reject any rect with +/-inf values
21 // as one of its coordinates.
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);
29 REPORTER_ASSERT(reporter, SkRect::MakeEmpty().isFinite());
31 SkRect rect = SkRect::MakeXYWH(small, small, big, big);
32 REPORTER_ASSERT(reporter, rect.isFinite());
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);
43 // need tests for SkStrSearch