Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(11)

Side by Side Diff: trunk/tests/PointTest.cpp

Issue 12530010: add asScalars() to document when we want to treat SkPoint or SkRect as an array (Closed) Base URL: http://skia.googlecode.com/svn/
Patch Set: Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « trunk/include/core/SkRect.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 1
2 /* 2 /*
3 * Copyright 2011 Google Inc. 3 * Copyright 2011 Google Inc.
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 // Unit tests for src/core/SkPoint.cpp and its header 8 // Unit tests for src/core/SkPoint.cpp and its header
9 9
10 #include "SkPoint.h" 10 #include "SkPoint.h"
11 #include "SkRect.h"
11 #include "Test.h" 12 #include "Test.h"
12 13
14 static void test_casts(skiatest::Reporter* reporter) {
15 SkPoint p = { 0, 0 };
16 SkRect r = { 0, 0, 0, 0 };
17
18 const SkScalar* pPtr = SkTCast<const SkScalar*>(&p);
19 const SkScalar* rPtr = SkTCast<const SkScalar*>(&r);
20
21 REPORTER_ASSERT(reporter, p.asScalars() == pPtr);
22 REPORTER_ASSERT(reporter, r.asScalars() == rPtr);
23 }
24
13 // Tests that SkPoint::length() and SkPoint::Length() both return 25 // Tests that SkPoint::length() and SkPoint::Length() both return
14 // approximately expectedLength for this (x,y). 26 // approximately expectedLength for this (x,y).
15 static void test_length(skiatest::Reporter* reporter, SkScalar x, SkScalar y, 27 static void test_length(skiatest::Reporter* reporter, SkScalar x, SkScalar y,
16 SkScalar expectedLength) { 28 SkScalar expectedLength) {
17 SkPoint point; 29 SkPoint point;
18 point.set(x, y); 30 point.set(x, y);
19 SkScalar s1 = point.length(); 31 SkScalar s1 = point.length();
20 SkScalar s2 = SkPoint::Length(x, y); 32 SkScalar s2 = SkPoint::Length(x, y);
21 //The following should be exactly the same, but need not be. 33 //The following should be exactly the same, but need not be.
22 //See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=323 34 //See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=323
23 REPORTER_ASSERT(reporter, SkScalarNearlyEqual(s1, s2)); 35 REPORTER_ASSERT(reporter, SkScalarNearlyEqual(s1, s2));
24 REPORTER_ASSERT(reporter, SkScalarNearlyEqual(s1, expectedLength)); 36 REPORTER_ASSERT(reporter, SkScalarNearlyEqual(s1, expectedLength));
25 } 37 }
26 38
27 // Tests SkPoint::Normalize() for this (x,y) 39 // Tests SkPoint::Normalize() for this (x,y)
28 static void test_Normalize(skiatest::Reporter* reporter, 40 static void test_Normalize(skiatest::Reporter* reporter,
29 SkScalar x, SkScalar y) { 41 SkScalar x, SkScalar y) {
30 SkPoint point; 42 SkPoint point;
31 point.set(x, y); 43 point.set(x, y);
32 SkScalar oldLength = point.length(); 44 SkScalar oldLength = point.length();
33 SkScalar returned = SkPoint::Normalize(&point); 45 SkScalar returned = SkPoint::Normalize(&point);
34 SkScalar newLength = point.length(); 46 SkScalar newLength = point.length();
35 REPORTER_ASSERT(reporter, SkScalarNearlyEqual(returned, oldLength)); 47 REPORTER_ASSERT(reporter, SkScalarNearlyEqual(returned, oldLength));
36 REPORTER_ASSERT(reporter, SkScalarNearlyEqual(newLength, SK_Scalar1)); 48 REPORTER_ASSERT(reporter, SkScalarNearlyEqual(newLength, SK_Scalar1));
37 } 49 }
38 50
39 static void PointTest(skiatest::Reporter* reporter) { 51 static void PointTest(skiatest::Reporter* reporter) {
52 test_casts(reporter);
53
40 test_length(reporter, SkIntToScalar(3), SkIntToScalar(4), SkIntToScalar(5)); 54 test_length(reporter, SkIntToScalar(3), SkIntToScalar(4), SkIntToScalar(5));
41 test_length(reporter, SkFloatToScalar(0.6f), SkFloatToScalar(0.8f), 55 test_length(reporter, SkFloatToScalar(0.6f), SkFloatToScalar(0.8f),
42 SK_Scalar1); 56 SK_Scalar1);
43 test_Normalize(reporter, SkIntToScalar(3), SkIntToScalar(4)); 57 test_Normalize(reporter, SkIntToScalar(3), SkIntToScalar(4));
44 test_Normalize(reporter, SkFloatToScalar(0.6f), SkFloatToScalar(0.8f)); 58 test_Normalize(reporter, SkFloatToScalar(0.6f), SkFloatToScalar(0.8f));
45 } 59 }
46 60
47 #include "TestClassDef.h" 61 #include "TestClassDef.h"
48 DEFINE_TESTCLASS("Point", PointTestClass, PointTest) 62 DEFINE_TESTCLASS("Point", PointTestClass, PointTest)
OLDNEW
« no previous file with comments | « trunk/include/core/SkRect.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698