1 /* 2 * Copyright 2011 Google Inc. 3 * 4 * Use of this source code is governed by a BSD-style license that can be 5 * found in the LICENSE file. 6 */ 7 8 #include "Test.h" 9 #include "TestClassDef.h" 10 #include "SkSize.h" 11 12 static void TestISize(skiatest::Reporter* reporter) { 13 SkISize a, b; 14 15 a.set(0, 0); 16 REPORTER_ASSERT(reporter, a.isEmpty()); 17 a.set(5, -5); 18 REPORTER_ASSERT(reporter, a.isEmpty()); 19 a.clampNegToZero(); 20 REPORTER_ASSERT(reporter, a.isEmpty()); 21 b.set(5, 0); 22 REPORTER_ASSERT(reporter, a == b); 23 24 a.set(3, 5); 25 REPORTER_ASSERT(reporter, !a.isEmpty()); 26 b = a; 27 REPORTER_ASSERT(reporter, !b.isEmpty()); 28 REPORTER_ASSERT(reporter, a == b); 29 REPORTER_ASSERT(reporter, !(a != b)); 30 REPORTER_ASSERT(reporter, 31 a.fWidth == b.fWidth && a.fHeight == b.fHeight); 32 } 33 34 DEF_TEST(Size, reporter) { 35 TestISize(reporter); 36 37 SkSize a, b; 38 int ix = 5; 39 int iy = 3; 40 SkScalar x = SkIntToScalar(ix); 41 SkScalar y = SkIntToScalar(iy); 42 43 a.set(0, 0); 44 REPORTER_ASSERT(reporter, a.isEmpty()); 45 a.set(x, -x); 46 REPORTER_ASSERT(reporter, a.isEmpty()); 47 a.clampNegToZero(); 48 REPORTER_ASSERT(reporter, a.isEmpty()); 49 b.set(x, 0); 50 REPORTER_ASSERT(reporter, a == b); 51 52 a.set(y, x); 53 REPORTER_ASSERT(reporter, !a.isEmpty()); 54 b = a; 55 REPORTER_ASSERT(reporter, !b.isEmpty()); 56 REPORTER_ASSERT(reporter, a == b); 57 REPORTER_ASSERT(reporter, !(a != b)); 58 REPORTER_ASSERT(reporter, 59 a.fWidth == b.fWidth && a.fHeight == b.fHeight); 60 61 SkISize ia; 62 ia.set(ix, iy); 63 a.set(x, y); 64 REPORTER_ASSERT(reporter, a.toRound() == ia); 65 } 66