blob: afabca8ff98cd4b65e0400f9b8dd4a4682370106 [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001/*
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 */
tfarina@chromium.orge4fafb12013-12-12 21:11:12 +00007
Mike Kleinc0bd9f92019-04-23 12:05:21 -05008#include "include/core/SkRect.h"
9#include "include/private/SkFloatingPoint.h"
10#include "include/utils/SkRandom.h"
11#include "tests/Test.h"
wjmaclean@chromium.orgff1ec2f2011-02-07 17:48:40 +000012
reed@android.comd4134452011-02-09 02:24:26 +000013static void check_invalid(skiatest::Reporter* reporter,
14 SkScalar l, SkScalar t, SkScalar r, SkScalar b) {
15 SkRect rect;
Mike Reed92b33352019-08-24 19:39:13 -040016 rect.setLTRB(l, t, r, b);
reed@google.com16078632011-12-06 18:56:37 +000017 REPORTER_ASSERT(reporter, !rect.isFinite());
reed@android.comd4134452011-02-09 02:24:26 +000018}
reed@google.com534240f2011-02-07 19:08:59 +000019
reed@google.com16078632011-12-06 18:56:37 +000020// Tests that isFinite() will reject any rect with +/-inf values
wjmaclean@chromium.orgff1ec2f2011-02-07 17:48:40 +000021// as one of its coordinates.
tfarina@chromium.orge4fafb12013-12-12 21:11:12 +000022DEF_TEST(InfRect, reporter) {
Mike Kleina4c277b2018-11-06 14:24:55 -050023 float inf = SK_FloatInfinity;
24 float nan = SK_FloatNaN;
reed@google.com7b463ac2012-05-16 13:35:36 +000025 SkASSERT(!(nan == nan));
reed@android.comd4134452011-02-09 02:24:26 +000026 SkScalar small = SkIntToScalar(10);
27 SkScalar big = SkIntToScalar(100);
wjmaclean@chromium.orgff1ec2f2011-02-07 17:48:40 +000028
reed@google.com7b463ac2012-05-16 13:35:36 +000029 REPORTER_ASSERT(reporter, SkRect::MakeEmpty().isFinite());
30
reed@android.comd4134452011-02-09 02:24:26 +000031 SkRect rect = SkRect::MakeXYWH(small, small, big, big);
reed@google.com16078632011-12-06 18:56:37 +000032 REPORTER_ASSERT(reporter, rect.isFinite());
wjmaclean@chromium.orgff1ec2f2011-02-07 17:48:40 +000033
reed@google.com7b463ac2012-05-16 13:35:36 +000034 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 }
wjmaclean@chromium.orgff1ec2f2011-02-07 17:48:40 +000041}
42
43// need tests for SkStrSearch