diff options
author | reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2011-02-08 21:56:39 +0000 |
---|---|---|
committer | reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2011-02-08 21:56:39 +0000 |
commit | 077910e20cda41d7981084fbd047a108894bc8df (patch) | |
tree | f4dd5f34b703772700e04976a42d52277d86c107 /tests | |
parent | 48543277728fdf66b993f17421f65fba532a23a2 (diff) |
add SkScalarIsFinite(), and use it for a more portable impl of SkRect::isValidCoords()
git-svn-id: http://skia.googlecode.com/svn/trunk@775 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'tests')
-rw-r--r-- | tests/MathTest.cpp | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/tests/MathTest.cpp b/tests/MathTest.cpp index 2555d73866..9aed9f9aa0 100644 --- a/tests/MathTest.cpp +++ b/tests/MathTest.cpp @@ -146,6 +146,40 @@ static void unittest_fastfloat(skiatest::Reporter* reporter) { } } +static float make_zero() { + return sk_float_sin(0); +} + +static void unittest_isfinite(skiatest::Reporter* reporter) { +#ifdef SK_SCALAR_IS_FLOAT + float nan = ::asin(2); + float inf = 1.0 / make_zero(); + float big = 3.40282e+038; + + REPORTER_ASSERT(reporter, SkScalarIsNaN(nan)); + REPORTER_ASSERT(reporter, !SkScalarIsNaN(inf)); + REPORTER_ASSERT(reporter, !SkScalarIsNaN(big)); + REPORTER_ASSERT(reporter, !SkScalarIsNaN(-big)); + REPORTER_ASSERT(reporter, !SkScalarIsNaN(0)); + + REPORTER_ASSERT(reporter, !SkScalarIsFinite(nan)); + REPORTER_ASSERT(reporter, !SkScalarIsFinite(inf)); + REPORTER_ASSERT(reporter, SkScalarIsFinite(big)); + REPORTER_ASSERT(reporter, SkScalarIsFinite(-big)); + REPORTER_ASSERT(reporter, SkScalarIsFinite(0)); +#else + REPORTER_ASSERT(reporter, SkScalarIsNaN(0x80000000)); + REPORTER_ASSERT(reporter, !SkScalarIsNaN(0x7FFFFFFF)); + REPORTER_ASSERT(reporter, !SkScalarIsNaN(0x80000001)); + REPORTER_ASSERT(reporter, !SkScalarIsNaN(0)); + + REPORTER_ASSERT(reporter, !SkScalarIsFinite(0x80000000)); + REPORTER_ASSERT(reporter, SkScalarIsFinite(0x7FFFFFFF)); + REPORTER_ASSERT(reporter, SkScalarIsFinite(0x80000001)); + REPORTER_ASSERT(reporter, SkScalarIsFinite(0)); +#endif +} + #endif static void test_muldiv255(skiatest::Reporter* reporter) { @@ -309,6 +343,7 @@ static void TestMath(skiatest::Reporter* reporter) { #ifdef SK_CAN_USE_FLOAT unittest_fastfloat(reporter); + unittest_isfinite(reporter); #endif #ifdef SkLONGLONG |