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 | */ |
reed@android.com | 6a5a266 | 2009-05-08 16:45:52 +0000 | [diff] [blame] | 8 | #include "Test.h" |
| 9 | #include "SkSize.h" |
| 10 | |
| 11 | static void TestISize(skiatest::Reporter* reporter) { |
| 12 | SkISize a, b; |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 13 | |
reed@android.com | 6a5a266 | 2009-05-08 16:45:52 +0000 | [diff] [blame] | 14 | a.set(0, 0); |
| 15 | REPORTER_ASSERT(reporter, a.isEmpty()); |
| 16 | a.set(5, -5); |
| 17 | REPORTER_ASSERT(reporter, a.isEmpty()); |
| 18 | a.clampNegToZero(); |
| 19 | REPORTER_ASSERT(reporter, a.isEmpty()); |
| 20 | b.set(5, 0); |
| 21 | REPORTER_ASSERT(reporter, a == b); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 22 | |
reed@android.com | 6a5a266 | 2009-05-08 16:45:52 +0000 | [diff] [blame] | 23 | a.set(3, 5); |
| 24 | REPORTER_ASSERT(reporter, !a.isEmpty()); |
| 25 | b = a; |
| 26 | REPORTER_ASSERT(reporter, !b.isEmpty()); |
| 27 | REPORTER_ASSERT(reporter, a == b); |
| 28 | REPORTER_ASSERT(reporter, !(a != b)); |
| 29 | REPORTER_ASSERT(reporter, |
| 30 | a.fWidth == b.fWidth && a.fHeight == b.fHeight); |
| 31 | } |
| 32 | |
| 33 | static void TestSize(skiatest::Reporter* reporter) { |
| 34 | TestISize(reporter); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 35 | |
reed@android.com | 6a5a266 | 2009-05-08 16:45:52 +0000 | [diff] [blame] | 36 | SkSize a, b; |
| 37 | int ix = 5; |
| 38 | int iy = 3; |
| 39 | SkScalar x = SkIntToScalar(ix); |
| 40 | SkScalar y = SkIntToScalar(iy); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 41 | |
reed@android.com | 6a5a266 | 2009-05-08 16:45:52 +0000 | [diff] [blame] | 42 | a.set(0, 0); |
| 43 | REPORTER_ASSERT(reporter, a.isEmpty()); |
| 44 | a.set(x, -x); |
| 45 | REPORTER_ASSERT(reporter, a.isEmpty()); |
| 46 | a.clampNegToZero(); |
| 47 | REPORTER_ASSERT(reporter, a.isEmpty()); |
| 48 | b.set(x, 0); |
| 49 | REPORTER_ASSERT(reporter, a == b); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 50 | |
reed@android.com | 6a5a266 | 2009-05-08 16:45:52 +0000 | [diff] [blame] | 51 | a.set(y, x); |
| 52 | REPORTER_ASSERT(reporter, !a.isEmpty()); |
| 53 | b = a; |
| 54 | REPORTER_ASSERT(reporter, !b.isEmpty()); |
| 55 | REPORTER_ASSERT(reporter, a == b); |
| 56 | REPORTER_ASSERT(reporter, !(a != b)); |
| 57 | REPORTER_ASSERT(reporter, |
| 58 | a.fWidth == b.fWidth && a.fHeight == b.fHeight); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 59 | |
reed@android.com | 6a5a266 | 2009-05-08 16:45:52 +0000 | [diff] [blame] | 60 | SkISize ia; |
| 61 | ia.set(ix, iy); |
| 62 | a.set(x, y); |
reed@android.com | f597991 | 2010-06-15 00:57:50 +0000 | [diff] [blame] | 63 | REPORTER_ASSERT(reporter, a.toRound() == ia); |
reed@android.com | 6a5a266 | 2009-05-08 16:45:52 +0000 | [diff] [blame] | 64 | }; |
| 65 | |
| 66 | #include "TestClassDef.h" |
| 67 | DEFINE_TESTCLASS("Size", TestSizeClass, TestSize) |