epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | |
| 2 | /* |
| 3 | * Copyright 2011 Google Inc. |
| 4 | * |
| 5 | * Use of this source code is governed by a BSD-style license that can be |
| 6 | * found in the LICENSE file. |
| 7 | */ |
epoger@google.com | 1fd56dc | 2011-06-15 18:04:58 +0000 | [diff] [blame] | 8 | // Unit tests for src/core/SkPoint.cpp and its header |
| 9 | |
| 10 | #include "SkPoint.h" |
| 11 | #include "Test.h" |
| 12 | |
| 13 | // Tests that SkPoint::length() and SkPoint::Length() both return |
| 14 | // approximately expectedLength for this (x,y). |
| 15 | static void test_length(skiatest::Reporter* reporter, SkScalar x, SkScalar y, |
| 16 | SkScalar expectedLength) { |
| 17 | SkPoint point; |
| 18 | point.set(x, y); |
| 19 | SkScalar s1 = point.length(); |
| 20 | SkScalar s2 = SkPoint::Length(x, y); |
bungeman@google.com | b7b5d93 | 2012-08-24 19:53:58 +0000 | [diff] [blame] | 21 | //The following should be exactly the same, but need not be. |
borenet@google.com | 98a9e1f | 2012-08-27 13:14:46 +0000 | [diff] [blame] | 22 | //See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=323 |
bungeman@google.com | b7b5d93 | 2012-08-24 19:53:58 +0000 | [diff] [blame] | 23 | REPORTER_ASSERT(reporter, SkScalarNearlyEqual(s1, s2)); |
epoger@google.com | 1fd56dc | 2011-06-15 18:04:58 +0000 | [diff] [blame] | 24 | REPORTER_ASSERT(reporter, SkScalarNearlyEqual(s1, expectedLength)); |
| 25 | } |
| 26 | |
| 27 | // Tests SkPoint::Normalize() for this (x,y) |
| 28 | static void test_Normalize(skiatest::Reporter* reporter, |
| 29 | SkScalar x, SkScalar y) { |
| 30 | SkPoint point; |
| 31 | point.set(x, y); |
| 32 | SkScalar oldLength = point.length(); |
| 33 | SkScalar returned = SkPoint::Normalize(&point); |
| 34 | SkScalar newLength = point.length(); |
bungeman@google.com | b7b5d93 | 2012-08-24 19:53:58 +0000 | [diff] [blame] | 35 | REPORTER_ASSERT(reporter, SkScalarNearlyEqual(returned, oldLength)); |
epoger@google.com | 1fd56dc | 2011-06-15 18:04:58 +0000 | [diff] [blame] | 36 | REPORTER_ASSERT(reporter, SkScalarNearlyEqual(newLength, SK_Scalar1)); |
| 37 | } |
| 38 | |
caryclark@google.com | 42639cd | 2012-06-06 12:03:39 +0000 | [diff] [blame] | 39 | static void PointTest(skiatest::Reporter* reporter) { |
epoger@google.com | 1fd56dc | 2011-06-15 18:04:58 +0000 | [diff] [blame] | 40 | test_length(reporter, SkIntToScalar(3), SkIntToScalar(4), SkIntToScalar(5)); |
tomhudson@google.com | 7558925 | 2012-04-10 17:42:21 +0000 | [diff] [blame] | 41 | test_length(reporter, SkFloatToScalar(0.6f), SkFloatToScalar(0.8f), |
epoger@google.com | 1fd56dc | 2011-06-15 18:04:58 +0000 | [diff] [blame] | 42 | SK_Scalar1); |
| 43 | test_Normalize(reporter, SkIntToScalar(3), SkIntToScalar(4)); |
tomhudson@google.com | 7558925 | 2012-04-10 17:42:21 +0000 | [diff] [blame] | 44 | test_Normalize(reporter, SkFloatToScalar(0.6f), SkFloatToScalar(0.8f)); |
epoger@google.com | 1fd56dc | 2011-06-15 18:04:58 +0000 | [diff] [blame] | 45 | } |
| 46 | |
| 47 | #include "TestClassDef.h" |
| 48 | DEFINE_TESTCLASS("Point", PointTestClass, PointTest) |