From ff1ec2f1a8d417236f36d1396182538967e68e1a Mon Sep 17 00:00:00 2001 From: "wjmaclean@chromium.org" Date: Mon, 7 Feb 2011 17:48:40 +0000 Subject: [PATCH] Add unit test for SkRect::hasValidCoordinates(). git-svn-id: http://skia.googlecode.com/svn/trunk@765 2bbb7eff-a529-9590-31e7-b0007b416f81 --- tests/InfRectTest.cpp | 39 +++++++++++++++++++++++++++++++++++++++ tests/tests_files.mk | 3 ++- 2 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 tests/InfRectTest.cpp 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) diff --git a/tests/tests_files.mk b/tests/tests_files.mk index cc21c7c6f7..4aa7cc00a4 100644 --- a/tests/tests_files.mk +++ b/tests/tests_files.mk @@ -23,4 +23,5 @@ SOURCE := \ StringTest.cpp \ Test.cpp \ TestSize.cpp \ - UtilsTest.cpp + UtilsTest.cpp \ + InfRectTest.cpp