epoger@google.com | 1fd56dc | 2011-06-15 18:04:58 +0000 | [diff] [blame] | 1 | // Unit tests for src/core/SkPoint.cpp and its header |
| 2 | |
| 3 | #include "SkPoint.h" |
| 4 | #include "Test.h" |
| 5 | |
| 6 | // Tests that SkPoint::length() and SkPoint::Length() both return |
| 7 | // approximately expectedLength for this (x,y). |
| 8 | static void test_length(skiatest::Reporter* reporter, SkScalar x, SkScalar y, |
| 9 | SkScalar expectedLength) { |
| 10 | SkPoint point; |
| 11 | point.set(x, y); |
| 12 | SkScalar s1 = point.length(); |
| 13 | SkScalar s2 = SkPoint::Length(x, y); |
| 14 | REPORTER_ASSERT(reporter, s1 == s2); |
| 15 | REPORTER_ASSERT(reporter, SkScalarNearlyEqual(s1, expectedLength)); |
| 16 | } |
| 17 | |
| 18 | // Tests SkPoint::Normalize() for this (x,y) |
| 19 | static void test_Normalize(skiatest::Reporter* reporter, |
| 20 | SkScalar x, SkScalar y) { |
| 21 | SkPoint point; |
| 22 | point.set(x, y); |
| 23 | SkScalar oldLength = point.length(); |
| 24 | SkScalar returned = SkPoint::Normalize(&point); |
| 25 | SkScalar newLength = point.length(); |
| 26 | REPORTER_ASSERT(reporter, returned == oldLength); |
| 27 | REPORTER_ASSERT(reporter, SkScalarNearlyEqual(newLength, SK_Scalar1)); |
| 28 | } |
| 29 | |
| 30 | void PointTest(skiatest::Reporter* reporter) { |
| 31 | test_length(reporter, SkIntToScalar(3), SkIntToScalar(4), SkIntToScalar(5)); |
| 32 | test_length(reporter, SkFloatToScalar(0.6), SkFloatToScalar(0.8), |
| 33 | SK_Scalar1); |
| 34 | test_Normalize(reporter, SkIntToScalar(3), SkIntToScalar(4)); |
| 35 | test_Normalize(reporter, SkFloatToScalar(0.6), SkFloatToScalar(0.8)); |
| 36 | } |
| 37 | |
| 38 | #include "TestClassDef.h" |
| 39 | DEFINE_TESTCLASS("Point", PointTestClass, PointTest) |