blob: 466a628c5c723fef11ba95474b080440410f8c3c [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 "SkSize.h"
tfarina@chromium.org8f6884a2014-01-24 20:56:26 +00009#include "Test.h"
reed@android.com6a5a2662009-05-08 16:45:52 +000010
11static void TestISize(skiatest::Reporter* reporter) {
12 SkISize a, b;
rmistry@google.comd6176b02012-08-23 18:14:13 +000013
reed@android.com6a5a2662009-05-08 16:45:52 +000014 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.comd6176b02012-08-23 18:14:13 +000022
reed@android.com6a5a2662009-05-08 16:45:52 +000023 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
tfarina@chromium.orge4fafb12013-12-12 21:11:12 +000033DEF_TEST(Size, reporter) {
reed@android.com6a5a2662009-05-08 16:45:52 +000034 TestISize(reporter);
rmistry@google.comd6176b02012-08-23 18:14:13 +000035
reed@android.com6a5a2662009-05-08 16:45:52 +000036 SkSize a, b;
37 int ix = 5;
38 int iy = 3;
39 SkScalar x = SkIntToScalar(ix);
40 SkScalar y = SkIntToScalar(iy);
rmistry@google.comd6176b02012-08-23 18:14:13 +000041
reed@android.com6a5a2662009-05-08 16:45:52 +000042 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.comd6176b02012-08-23 18:14:13 +000050
reed@android.com6a5a2662009-05-08 16:45:52 +000051 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.comd6176b02012-08-23 18:14:13 +000059
reed@android.com6a5a2662009-05-08 16:45:52 +000060 SkISize ia;
61 ia.set(ix, iy);
62 a.set(x, y);
reed@android.comf5979912010-06-15 00:57:50 +000063 REPORTER_ASSERT(reporter, a.toRound() == ia);
tfarina@chromium.orge4fafb12013-12-12 21:11:12 +000064}