hide divide-by-zero from the compiler, to avoid the warning

git-svn-id: http://skia.googlecode.com/svn/trunk@766 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
reed@google.com 2011-02-07 19:08:59 +00:00
parent ff1ec2f1a8
commit 534240f605

View File

@ -1,35 +1,40 @@
#include "Test.h"
#include "SkRect.h"
static float make_zero() {
return sk_float_sin(0);
}
// Tests that hasValidCoordinates() will reject any rect with +/-inf values
// as one of its coordinates.
static void TestInfRect(skiatest::Reporter* reporter) {
float zero = make_zero();
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.
rect = SkRect::MakeXYWH(10.0f, 10.0f, 100.0f, 1.0f/zero); // Make 'inf' value without numeric_limits.
REPORTER_ASSERT(reporter, !rect.hasValidCoordinates());
rect = SkRect::MakeXYWH(10.0f, 10.0f, 1.0f/0.0f, 100.0f);
rect = SkRect::MakeXYWH(10.0f, 10.0f, 1.0f/zero, 100.0f);
REPORTER_ASSERT(reporter, !rect.hasValidCoordinates());
rect = SkRect::MakeXYWH(1.0f/0.0f, 10.0f, 100.0f, 100.0f);
rect = SkRect::MakeXYWH(1.0f/zero, 10.0f, 100.0f, 100.0f);
REPORTER_ASSERT(reporter, !rect.hasValidCoordinates());
rect = SkRect::MakeXYWH(10.0f, 1.0f/0.0f, 100.0f, 100.0f);
rect = SkRect::MakeXYWH(10.0f, 1.0f/zero, 100.0f, 100.0f);
REPORTER_ASSERT(reporter, !rect.hasValidCoordinates());
rect = SkRect::MakeXYWH(10.0f, 10.0f, 100.0f, -1.0f/0.0f);
rect = SkRect::MakeXYWH(10.0f, 10.0f, 100.0f, -1.0f/zero);
REPORTER_ASSERT(reporter, !rect.hasValidCoordinates());
rect = SkRect::MakeXYWH(10.0f, 10.0f, -1.0f/0.0f, 100.0f);
rect = SkRect::MakeXYWH(10.0f, 10.0f, -1.0f/zero, 100.0f);
REPORTER_ASSERT(reporter, !rect.hasValidCoordinates());
rect = SkRect::MakeXYWH(-1.0f/0.0f, 10.0f, 100.0f, 100.0f);
rect = SkRect::MakeXYWH(-1.0f/zero, 10.0f, 100.0f, 100.0f);
REPORTER_ASSERT(reporter, !rect.hasValidCoordinates());
rect = SkRect::MakeXYWH(10.0f, -1.0f/0.0f, 100.0f, 100.0f);
rect = SkRect::MakeXYWH(10.0f, -1.0f/zero, 100.0f, 100.0f);
REPORTER_ASSERT(reporter, !rect.hasValidCoordinates());
}