blob: 1dc6ca7d0c52d2cb84823c6cb9baf2615fbd1e38 [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001
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 */
wjmaclean@chromium.orgff1ec2f2011-02-07 17:48:40 +00008#include "Test.h"
9#include "SkRect.h"
10
reed@android.comd4134452011-02-09 02:24:26 +000011#ifdef SK_SCALAR_IS_FLOAT
reed@google.com534240f2011-02-07 19:08:59 +000012static float make_zero() {
13 return sk_float_sin(0);
14}
reed@android.comd4134452011-02-09 02:24:26 +000015#endif
16
17static 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);
reed@google.com16078632011-12-06 18:56:37 +000021 REPORTER_ASSERT(reporter, !rect.isFinite());
reed@android.comd4134452011-02-09 02:24:26 +000022}
reed@google.com534240f2011-02-07 19:08:59 +000023
reed@google.com16078632011-12-06 18:56:37 +000024// Tests that isFinite() will reject any rect with +/-inf values
wjmaclean@chromium.orgff1ec2f2011-02-07 17:48:40 +000025// as one of its coordinates.
26static void TestInfRect(skiatest::Reporter* reporter) {
reed@android.comd4134452011-02-09 02:24:26 +000027#ifdef SK_SCALAR_IS_FLOAT
reed@google.com7b463ac2012-05-16 13:35:36 +000028 float inf = 1 / make_zero(); // infinity
29 float nan = inf * 0;
30 SkASSERT(!(nan == nan));
reed@android.comd4134452011-02-09 02:24:26 +000031#else
reed@google.com7b463ac2012-05-16 13:35:36 +000032 SkFixed inf = SK_FixedNaN;
33 SkFixed nan = SK_FixedNaN;
reed@android.comd4134452011-02-09 02:24:26 +000034#endif
35 SkScalar small = SkIntToScalar(10);
36 SkScalar big = SkIntToScalar(100);
wjmaclean@chromium.orgff1ec2f2011-02-07 17:48:40 +000037
reed@google.com7b463ac2012-05-16 13:35:36 +000038 REPORTER_ASSERT(reporter, SkRect::MakeEmpty().isFinite());
39
reed@android.comd4134452011-02-09 02:24:26 +000040 SkRect rect = SkRect::MakeXYWH(small, small, big, big);
reed@google.com16078632011-12-06 18:56:37 +000041 REPORTER_ASSERT(reporter, rect.isFinite());
wjmaclean@chromium.orgff1ec2f2011-02-07 17:48:40 +000042
reed@google.com7b463ac2012-05-16 13:35:36 +000043 const SkScalar invalid[] = { nan, inf, -inf };
44 for (size_t i = 0; i < SK_ARRAY_COUNT(invalid); ++i) {
45 check_invalid(reporter, small, small, big, invalid[i]);
46 check_invalid(reporter, small, small, invalid[i], big);
47 check_invalid(reporter, small, invalid[i], big, big);
48 check_invalid(reporter, invalid[i], small, big, big);
49 }
wjmaclean@chromium.orgff1ec2f2011-02-07 17:48:40 +000050}
51
52// need tests for SkStrSearch
53
54#include "TestClassDef.h"
55DEFINE_TESTCLASS("InfRect", InfRectTestClass, TestInfRect)