Home | History | Annotate | Download | only in tests
      1 #include "Test.h"
      2 #include "SkRect.h"
      3 
      4 #ifdef SK_SCALAR_IS_FLOAT
      5 static float make_zero() {
      6     return sk_float_sin(0);
      7 }
      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 }
     16 
     17 // Tests that hasValidCoordinates() will reject any rect with +/-inf values
     18 // as one of its coordinates.
     19 static void TestInfRect(skiatest::Reporter* reporter) {
     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);
     27 
     28     SkRect rect = SkRect::MakeXYWH(small, small, big, big);
     29     REPORTER_ASSERT(reporter, rect.hasValidCoordinates());
     30 
     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);
     39 }
     40 
     41 // need tests for SkStrSearch
     42 
     43 #include "TestClassDef.h"
     44 DEFINE_TESTCLASS("InfRect", InfRectTestClass, TestInfRect)
     45