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 */ 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); 21 REPORTER_ASSERT(reporter, s1 == s2); 22 REPORTER_ASSERT(reporter, SkScalarNearlyEqual(s1, expectedLength)); 23 } 24 25 // Tests SkPoint::Normalize() for this (x,y) 26 static void test_Normalize(skiatest::Reporter* reporter, 27 SkScalar x, SkScalar y) { 28 SkPoint point; 29 point.set(x, y); 30 SkScalar oldLength = point.length(); 31 SkScalar returned = SkPoint::Normalize(&point); 32 SkScalar newLength = point.length(); 33 REPORTER_ASSERT(reporter, returned == oldLength); 34 REPORTER_ASSERT(reporter, SkScalarNearlyEqual(newLength, SK_Scalar1)); 35 } 36 37 void PointTest(skiatest::Reporter* reporter) { 38 test_length(reporter, SkIntToScalar(3), SkIntToScalar(4), SkIntToScalar(5)); 39 test_length(reporter, SkFloatToScalar(0.6), SkFloatToScalar(0.8), 40 SK_Scalar1); 41 test_Normalize(reporter, SkIntToScalar(3), SkIntToScalar(4)); 42 test_Normalize(reporter, SkFloatToScalar(0.6), SkFloatToScalar(0.8)); 43 } 44 45 #include "TestClassDef.h" 46 DEFINE_TESTCLASS("Point", PointTestClass, PointTest) 47