| wjmaclean@chromium.org | ff1ec2f | 2011-02-07 17:48:40 +0000 | [diff] [blame] | 1 | #include "Test.h" | 
 | 2 | #include "SkRect.h" | 
 | 3 |  | 
| reed@android.com | d413445 | 2011-02-09 02:24:26 +0000 | [diff] [blame] | 4 | #ifdef SK_SCALAR_IS_FLOAT | 
| reed@google.com | 534240f | 2011-02-07 19:08:59 +0000 | [diff] [blame] | 5 | static float make_zero() { | 
 | 6 |     return sk_float_sin(0); | 
 | 7 | } | 
| reed@android.com | d413445 | 2011-02-09 02:24:26 +0000 | [diff] [blame] | 8 | #endif | 
 | 9 |  | 
 | 10 | static void check_invalid(skiatest::Reporter* reporter, | 
 | 11 |                           SkScalar l, SkScalar t, SkScalar r, SkScalar b) { | 
 | 12 |     SkRect rect; | 
 | 13 |     rect.set(l, t, r, b); | 
 | 14 |     REPORTER_ASSERT(reporter, !rect.hasValidCoordinates()); | 
 | 15 | } | 
| reed@google.com | 534240f | 2011-02-07 19:08:59 +0000 | [diff] [blame] | 16 |  | 
| wjmaclean@chromium.org | ff1ec2f | 2011-02-07 17:48:40 +0000 | [diff] [blame] | 17 | // Tests that hasValidCoordinates() will reject any rect with +/-inf values | 
 | 18 | // as one of its coordinates. | 
 | 19 | static void TestInfRect(skiatest::Reporter* reporter) { | 
| reed@android.com | d413445 | 2011-02-09 02:24:26 +0000 | [diff] [blame] | 20 | #ifdef SK_SCALAR_IS_FLOAT | 
 | 21 |     float invalid = 1 / make_zero();    // infinity | 
 | 22 | #else | 
 | 23 |     SkFixed invalid = SK_FixedNaN; | 
 | 24 | #endif | 
 | 25 |     SkScalar small = SkIntToScalar(10); | 
 | 26 |     SkScalar big = SkIntToScalar(100); | 
| wjmaclean@chromium.org | ff1ec2f | 2011-02-07 17:48:40 +0000 | [diff] [blame] | 27 |  | 
| reed@android.com | d413445 | 2011-02-09 02:24:26 +0000 | [diff] [blame] | 28 |     SkRect rect = SkRect::MakeXYWH(small, small, big, big); | 
| wjmaclean@chromium.org | ff1ec2f | 2011-02-07 17:48:40 +0000 | [diff] [blame] | 29 |     REPORTER_ASSERT(reporter, rect.hasValidCoordinates()); | 
 | 30 |  | 
| reed@android.com | d413445 | 2011-02-09 02:24:26 +0000 | [diff] [blame] | 31 |     check_invalid(reporter, small, small, big, invalid); | 
 | 32 |     check_invalid(reporter, small, small, invalid, big); | 
 | 33 |     check_invalid(reporter, small, invalid, big, big); | 
 | 34 |     check_invalid(reporter, invalid, small, big, big); | 
 | 35 |     check_invalid(reporter, small, small, big, -invalid); | 
 | 36 |     check_invalid(reporter, small, small, -invalid, big); | 
 | 37 |     check_invalid(reporter, small, -invalid, big, big); | 
 | 38 |     check_invalid(reporter, -invalid, small, big, big); | 
| wjmaclean@chromium.org | ff1ec2f | 2011-02-07 17:48:40 +0000 | [diff] [blame] | 39 | } | 
 | 40 |  | 
 | 41 | // need tests for SkStrSearch | 
 | 42 |  | 
 | 43 | #include "TestClassDef.h" | 
 | 44 | DEFINE_TESTCLASS("InfRect", InfRectTestClass, TestInfRect) |