blob: 12356d9c2f841b4ed90f19b0305c4d56368cf8ae [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
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);
wjmaclean@chromium.orgff1ec2f2011-02-07 17:48:40 +000034
reed@android.comd4134452011-02-09 02:24:26 +000035 SkRect rect = SkRect::MakeXYWH(small, small, big, big);
reed@google.com16078632011-12-06 18:56:37 +000036 REPORTER_ASSERT(reporter, rect.isFinite());
wjmaclean@chromium.orgff1ec2f2011-02-07 17:48:40 +000037
reed@android.comd4134452011-02-09 02:24:26 +000038 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);
wjmaclean@chromium.orgff1ec2f2011-02-07 17:48:40 +000046}
47
48// need tests for SkStrSearch
49
50#include "TestClassDef.h"
51DEFINE_TESTCLASS("InfRect", InfRectTestClass, TestInfRect)