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 "SkSize.h" |
tfarina | 12345ae | 2014-06-25 10:39:00 -0700 | [diff] [blame] | 9 | |
tfarina@chromium.org | 8f6884a | 2014-01-24 20:56:26 +0000 | [diff] [blame] | 10 | #include "Test.h" |
reed@android.com | 6a5a266 | 2009-05-08 16:45:52 +0000 | [diff] [blame] | 11 | |
tfarina | 12345ae | 2014-06-25 10:39:00 -0700 | [diff] [blame] | 12 | DEF_TEST(ISize, reporter) { |
reed@android.com | 6a5a266 | 2009-05-08 16:45:52 +0000 | [diff] [blame] | 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 | SkSize a, b; |
| 36 | int ix = 5; |
| 37 | int iy = 3; |
| 38 | SkScalar x = SkIntToScalar(ix); |
| 39 | SkScalar y = SkIntToScalar(iy); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 40 | |
reed@android.com | 6a5a266 | 2009-05-08 16:45:52 +0000 | [diff] [blame] | 41 | a.set(0, 0); |
| 42 | REPORTER_ASSERT(reporter, a.isEmpty()); |
| 43 | a.set(x, -x); |
| 44 | REPORTER_ASSERT(reporter, a.isEmpty()); |
| 45 | a.clampNegToZero(); |
| 46 | REPORTER_ASSERT(reporter, a.isEmpty()); |
| 47 | b.set(x, 0); |
| 48 | REPORTER_ASSERT(reporter, a == b); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 49 | |
reed@android.com | 6a5a266 | 2009-05-08 16:45:52 +0000 | [diff] [blame] | 50 | a.set(y, x); |
| 51 | REPORTER_ASSERT(reporter, !a.isEmpty()); |
| 52 | b = a; |
| 53 | REPORTER_ASSERT(reporter, !b.isEmpty()); |
| 54 | REPORTER_ASSERT(reporter, a == b); |
| 55 | REPORTER_ASSERT(reporter, !(a != b)); |
| 56 | REPORTER_ASSERT(reporter, |
| 57 | a.fWidth == b.fWidth && a.fHeight == b.fHeight); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 58 | |
reed@android.com | 6a5a266 | 2009-05-08 16:45:52 +0000 | [diff] [blame] | 59 | SkISize ia; |
| 60 | ia.set(ix, iy); |
| 61 | a.set(x, y); |
reed@android.com | f597991 | 2010-06-15 00:57:50 +0000 | [diff] [blame] | 62 | REPORTER_ASSERT(reporter, a.toRound() == ia); |
tfarina@chromium.org | e4fafb1 | 2013-12-12 21:11:12 +0000 | [diff] [blame] | 63 | } |