epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | |
| 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.org | ff1ec2f | 2011-02-07 17:48:40 +0000 | [diff] [blame] | 8 | #include "Test.h" |
| 9 | #include "SkRect.h" |
| 10 | |
reed@android.com | d413445 | 2011-02-09 02:24:26 +0000 | [diff] [blame] | 11 | #ifdef SK_SCALAR_IS_FLOAT |
reed@google.com | 534240f | 2011-02-07 19:08:59 +0000 | [diff] [blame] | 12 | static float make_zero() { |
| 13 | return sk_float_sin(0); |
| 14 | } |
reed@android.com | d413445 | 2011-02-09 02:24:26 +0000 | [diff] [blame] | 15 | #endif |
| 16 | |
| 17 | static 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.com | 1607863 | 2011-12-06 18:56:37 +0000 | [diff] [blame] | 21 | REPORTER_ASSERT(reporter, !rect.isFinite()); |
reed@android.com | d413445 | 2011-02-09 02:24:26 +0000 | [diff] [blame] | 22 | } |
reed@google.com | 534240f | 2011-02-07 19:08:59 +0000 | [diff] [blame] | 23 | |
reed@google.com | 1607863 | 2011-12-06 18:56:37 +0000 | [diff] [blame] | 24 | // Tests that isFinite() will reject any rect with +/-inf values |
wjmaclean@chromium.org | ff1ec2f | 2011-02-07 17:48:40 +0000 | [diff] [blame] | 25 | // as one of its coordinates. |
| 26 | static void TestInfRect(skiatest::Reporter* reporter) { |
reed@android.com | d413445 | 2011-02-09 02:24:26 +0000 | [diff] [blame] | 27 | #ifdef SK_SCALAR_IS_FLOAT |
reed@google.com | 7b463ac | 2012-05-16 13:35:36 +0000 | [diff] [blame] | 28 | float inf = 1 / make_zero(); // infinity |
| 29 | float nan = inf * 0; |
| 30 | SkASSERT(!(nan == nan)); |
reed@android.com | d413445 | 2011-02-09 02:24:26 +0000 | [diff] [blame] | 31 | #else |
reed@google.com | 7b463ac | 2012-05-16 13:35:36 +0000 | [diff] [blame] | 32 | SkFixed inf = SK_FixedNaN; |
| 33 | SkFixed nan = SK_FixedNaN; |
reed@android.com | d413445 | 2011-02-09 02:24:26 +0000 | [diff] [blame] | 34 | #endif |
| 35 | SkScalar small = SkIntToScalar(10); |
| 36 | SkScalar big = SkIntToScalar(100); |
wjmaclean@chromium.org | ff1ec2f | 2011-02-07 17:48:40 +0000 | [diff] [blame] | 37 | |
reed@google.com | 7b463ac | 2012-05-16 13:35:36 +0000 | [diff] [blame] | 38 | REPORTER_ASSERT(reporter, SkRect::MakeEmpty().isFinite()); |
| 39 | |
reed@android.com | d413445 | 2011-02-09 02:24:26 +0000 | [diff] [blame] | 40 | SkRect rect = SkRect::MakeXYWH(small, small, big, big); |
reed@google.com | 1607863 | 2011-12-06 18:56:37 +0000 | [diff] [blame] | 41 | REPORTER_ASSERT(reporter, rect.isFinite()); |
wjmaclean@chromium.org | ff1ec2f | 2011-02-07 17:48:40 +0000 | [diff] [blame] | 42 | |
reed@google.com | 7b463ac | 2012-05-16 13:35:36 +0000 | [diff] [blame] | 43 | 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.org | ff1ec2f | 2011-02-07 17:48:40 +0000 | [diff] [blame] | 50 | } |
| 51 | |
| 52 | // need tests for SkStrSearch |
| 53 | |
| 54 | #include "TestClassDef.h" |
| 55 | DEFINE_TESTCLASS("InfRect", InfRectTestClass, TestInfRect) |