epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | /* |
| 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.org | e4fafb1 | 2013-12-12 21:11:12 +0000 | [diff] [blame] | 7 | |
Mike Klein | a4c277b | 2018-11-06 14:24:55 -0500 | [diff] [blame] | 8 | #include "SkFloatingPoint.h" |
reed@google.com | 6898d52 | 2012-11-08 22:36:19 +0000 | [diff] [blame] | 9 | #include "SkRandom.h" |
wjmaclean@chromium.org | ff1ec2f | 2011-02-07 17:48:40 +0000 | [diff] [blame] | 10 | #include "SkRect.h" |
tfarina@chromium.org | 8f6884a | 2014-01-24 20:56:26 +0000 | [diff] [blame] | 11 | #include "Test.h" |
wjmaclean@chromium.org | ff1ec2f | 2011-02-07 17:48:40 +0000 | [diff] [blame] | 12 | |
reed@android.com | d413445 | 2011-02-09 02:24:26 +0000 | [diff] [blame] | 13 | static 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.com | 1607863 | 2011-12-06 18:56:37 +0000 | [diff] [blame] | 17 | REPORTER_ASSERT(reporter, !rect.isFinite()); |
reed@android.com | d413445 | 2011-02-09 02:24:26 +0000 | [diff] [blame] | 18 | } |
reed@google.com | 534240f | 2011-02-07 19:08:59 +0000 | [diff] [blame] | 19 | |
reed@google.com | 1607863 | 2011-12-06 18:56:37 +0000 | [diff] [blame] | 20 | // Tests that isFinite() will reject any rect with +/-inf values |
wjmaclean@chromium.org | ff1ec2f | 2011-02-07 17:48:40 +0000 | [diff] [blame] | 21 | // as one of its coordinates. |
tfarina@chromium.org | e4fafb1 | 2013-12-12 21:11:12 +0000 | [diff] [blame] | 22 | DEF_TEST(InfRect, reporter) { |
Mike Klein | a4c277b | 2018-11-06 14:24:55 -0500 | [diff] [blame] | 23 | float inf = SK_FloatInfinity; |
| 24 | float nan = SK_FloatNaN; |
reed@google.com | 7b463ac | 2012-05-16 13:35:36 +0000 | [diff] [blame] | 25 | SkASSERT(!(nan == nan)); |
reed@android.com | d413445 | 2011-02-09 02:24:26 +0000 | [diff] [blame] | 26 | SkScalar small = SkIntToScalar(10); |
| 27 | SkScalar big = SkIntToScalar(100); |
wjmaclean@chromium.org | ff1ec2f | 2011-02-07 17:48:40 +0000 | [diff] [blame] | 28 | |
reed@google.com | 7b463ac | 2012-05-16 13:35:36 +0000 | [diff] [blame] | 29 | REPORTER_ASSERT(reporter, SkRect::MakeEmpty().isFinite()); |
| 30 | |
reed@android.com | d413445 | 2011-02-09 02:24:26 +0000 | [diff] [blame] | 31 | SkRect rect = SkRect::MakeXYWH(small, small, big, big); |
reed@google.com | 1607863 | 2011-12-06 18:56:37 +0000 | [diff] [blame] | 32 | REPORTER_ASSERT(reporter, rect.isFinite()); |
wjmaclean@chromium.org | ff1ec2f | 2011-02-07 17:48:40 +0000 | [diff] [blame] | 33 | |
reed@google.com | 7b463ac | 2012-05-16 13:35:36 +0000 | [diff] [blame] | 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); |
| 40 | } |
wjmaclean@chromium.org | ff1ec2f | 2011-02-07 17:48:40 +0000 | [diff] [blame] | 41 | } |
| 42 | |
| 43 | // need tests for SkStrSearch |