aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/InfRectTest.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/InfRectTest.cpp')
-rw-r--r--tests/InfRectTest.cpp39
1 files changed, 39 insertions, 0 deletions
diff --git a/tests/InfRectTest.cpp b/tests/InfRectTest.cpp
new file mode 100644
index 0000000000..fc9c6eba8a
--- /dev/null
+++ b/tests/InfRectTest.cpp
@@ -0,0 +1,39 @@
+#include "Test.h"
+#include "SkRect.h"
+
+// Tests that hasValidCoordinates() will reject any rect with +/-inf values
+// as one of its coordinates.
+static void TestInfRect(skiatest::Reporter* reporter) {
+
+ SkRect rect = SkRect::MakeXYWH(10.0f, 10.0f, 100.0f, 100.0f);
+ REPORTER_ASSERT(reporter, rect.hasValidCoordinates());
+
+ rect = SkRect::MakeXYWH(10.0f, 10.0f, 100.0f, 1.0f/0.0f); // Make 'inf' value without numeric_limits.
+ REPORTER_ASSERT(reporter, !rect.hasValidCoordinates());
+
+ rect = SkRect::MakeXYWH(10.0f, 10.0f, 1.0f/0.0f, 100.0f);
+ REPORTER_ASSERT(reporter, !rect.hasValidCoordinates());
+
+ rect = SkRect::MakeXYWH(1.0f/0.0f, 10.0f, 100.0f, 100.0f);
+ REPORTER_ASSERT(reporter, !rect.hasValidCoordinates());
+
+ rect = SkRect::MakeXYWH(10.0f, 1.0f/0.0f, 100.0f, 100.0f);
+ REPORTER_ASSERT(reporter, !rect.hasValidCoordinates());
+
+ rect = SkRect::MakeXYWH(10.0f, 10.0f, 100.0f, -1.0f/0.0f);
+ REPORTER_ASSERT(reporter, !rect.hasValidCoordinates());
+
+ rect = SkRect::MakeXYWH(10.0f, 10.0f, -1.0f/0.0f, 100.0f);
+ REPORTER_ASSERT(reporter, !rect.hasValidCoordinates());
+
+ rect = SkRect::MakeXYWH(-1.0f/0.0f, 10.0f, 100.0f, 100.0f);
+ REPORTER_ASSERT(reporter, !rect.hasValidCoordinates());
+
+ rect = SkRect::MakeXYWH(10.0f, -1.0f/0.0f, 100.0f, 100.0f);
+ REPORTER_ASSERT(reporter, !rect.hasValidCoordinates());
+}
+
+// need tests for SkStrSearch
+
+#include "TestClassDef.h"
+DEFINE_TESTCLASS("InfRect", InfRectTestClass, TestInfRect)