blob: af00bc96716dec8b1f50ca32eaad6be286d04e74 [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 Kleina4c277b2018-11-06 14:24:55 -05008#include "SkFloatingPoint.h"
reed@google.com6898d522012-11-08 22:36:19 +00009#include "SkRandom.h"
wjmaclean@chromium.orgff1ec2f2011-02-07 17:48:40 +000010#include "SkRect.h"
tfarina@chromium.org8f6884a2014-01-24 20:56:26 +000011#include "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;
16 rect.set(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