blob: 475517a075a59939a1d70685d96f2cefb5077205 [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001/*
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.orge4fafb12013-12-12 21:11:12 +00007
reed@android.com6a5a2662009-05-08 16:45:52 +00008#include "Test.h"
tfarina@chromium.orge4fafb12013-12-12 21:11:12 +00009#include "TestClassDef.h"
reed@android.com6a5a2662009-05-08 16:45:52 +000010#include "SkSize.h"
11
12static void TestISize(skiatest::Reporter* reporter) {
13 SkISize a, b;
rmistry@google.comd6176b02012-08-23 18:14:13 +000014
reed@android.com6a5a2662009-05-08 16:45:52 +000015 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.comd6176b02012-08-23 18:14:13 +000023
reed@android.com6a5a2662009-05-08 16:45:52 +000024 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.orge4fafb12013-12-12 21:11:12 +000034DEF_TEST(Size, reporter) {
reed@android.com6a5a2662009-05-08 16:45:52 +000035 TestISize(reporter);
rmistry@google.comd6176b02012-08-23 18:14:13 +000036
reed@android.com6a5a2662009-05-08 16:45:52 +000037 SkSize a, b;
38 int ix = 5;
39 int iy = 3;
40 SkScalar x = SkIntToScalar(ix);
41 SkScalar y = SkIntToScalar(iy);
rmistry@google.comd6176b02012-08-23 18:14:13 +000042
reed@android.com6a5a2662009-05-08 16:45:52 +000043 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.comd6176b02012-08-23 18:14:13 +000051
reed@android.com6a5a2662009-05-08 16:45:52 +000052 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.comd6176b02012-08-23 18:14:13 +000060
reed@android.com6a5a2662009-05-08 16:45:52 +000061 SkISize ia;
62 ia.set(ix, iy);
63 a.set(x, y);
reed@android.comf5979912010-06-15 00:57:50 +000064 REPORTER_ASSERT(reporter, a.toRound() == ia);
tfarina@chromium.orge4fafb12013-12-12 21:11:12 +000065}