epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 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 | */ |
tfarina@chromium.org | e4fafb1 | 2013-12-12 21:11:12 +0000 | [diff] [blame^] | 7 | |
reed@android.com | 6a5a266 | 2009-05-08 16:45:52 +0000 | [diff] [blame] | 8 | #include "Test.h" |
tfarina@chromium.org | e4fafb1 | 2013-12-12 21:11:12 +0000 | [diff] [blame^] | 9 | #include "TestClassDef.h" |
reed@android.com | 6a5a266 | 2009-05-08 16:45:52 +0000 | [diff] [blame] | 10 | #include "SkSize.h" |
| 11 | |
| 12 | static void TestISize(skiatest::Reporter* reporter) { |
| 13 | SkISize a, b; |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 14 | |
reed@android.com | 6a5a266 | 2009-05-08 16:45:52 +0000 | [diff] [blame] | 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); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 23 | |
reed@android.com | 6a5a266 | 2009-05-08 16:45:52 +0000 | [diff] [blame] | 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 | |
tfarina@chromium.org | e4fafb1 | 2013-12-12 21:11:12 +0000 | [diff] [blame^] | 34 | DEF_TEST(Size, reporter) { |
reed@android.com | 6a5a266 | 2009-05-08 16:45:52 +0000 | [diff] [blame] | 35 | TestISize(reporter); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 36 | |
reed@android.com | 6a5a266 | 2009-05-08 16:45:52 +0000 | [diff] [blame] | 37 | SkSize a, b; |
| 38 | int ix = 5; |
| 39 | int iy = 3; |
| 40 | SkScalar x = SkIntToScalar(ix); |
| 41 | SkScalar y = SkIntToScalar(iy); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 42 | |
reed@android.com | 6a5a266 | 2009-05-08 16:45:52 +0000 | [diff] [blame] | 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); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 51 | |
reed@android.com | 6a5a266 | 2009-05-08 16:45:52 +0000 | [diff] [blame] | 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); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 60 | |
reed@android.com | 6a5a266 | 2009-05-08 16:45:52 +0000 | [diff] [blame] | 61 | SkISize ia; |
| 62 | ia.set(ix, iy); |
| 63 | a.set(x, y); |
reed@android.com | f597991 | 2010-06-15 00:57:50 +0000 | [diff] [blame] | 64 | REPORTER_ASSERT(reporter, a.toRound() == ia); |
tfarina@chromium.org | e4fafb1 | 2013-12-12 21:11:12 +0000 | [diff] [blame^] | 65 | } |