blob: 1e1502352a1e55d7f1e59a0a4bc7526347a7b948 [file] [log] [blame]
wjmaclean@chromium.orgff1ec2f2011-02-07 17:48:40 +00001#include "Test.h"
2#include "SkRect.h"
3
reed@android.comd4134452011-02-09 02:24:26 +00004#ifdef SK_SCALAR_IS_FLOAT
reed@google.com534240f2011-02-07 19:08:59 +00005static float make_zero() {
6 return sk_float_sin(0);
7}
reed@android.comd4134452011-02-09 02:24:26 +00008#endif
9
10static 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.com534240f2011-02-07 19:08:59 +000016
wjmaclean@chromium.orgff1ec2f2011-02-07 17:48:40 +000017// Tests that hasValidCoordinates() will reject any rect with +/-inf values
18// as one of its coordinates.
19static void TestInfRect(skiatest::Reporter* reporter) {
reed@android.comd4134452011-02-09 02:24:26 +000020#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.orgff1ec2f2011-02-07 17:48:40 +000027
reed@android.comd4134452011-02-09 02:24:26 +000028 SkRect rect = SkRect::MakeXYWH(small, small, big, big);
wjmaclean@chromium.orgff1ec2f2011-02-07 17:48:40 +000029 REPORTER_ASSERT(reporter, rect.hasValidCoordinates());
30
reed@android.comd4134452011-02-09 02:24:26 +000031 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.orgff1ec2f2011-02-07 17:48:40 +000039}
40
41// need tests for SkStrSearch
42
43#include "TestClassDef.h"
44DEFINE_TESTCLASS("InfRect", InfRectTestClass, TestInfRect)