blob: 9dccdeb6b3938e264fc45a222dc7ab28e44c65bb [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"
tfarina12345ae2014-06-25 10:39:00 -07009
tfarina@chromium.org8f6884a2014-01-24 20:56:26 +000010#include "Test.h"
reed@android.com6a5a2662009-05-08 16:45:52 +000011
tfarina12345ae2014-06-25 10:39:00 -070012DEF_TEST(ISize, reporter) {
reed@android.com6a5a2662009-05-08 16:45:52 +000013 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());
Hal Canaryfafe1352017-04-11 12:12:02 -040019 a = SkISize{5, 0};
reed@android.com6a5a2662009-05-08 16:45:52 +000020 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 SkSize a, b;
36 int ix = 5;
37 int iy = 3;
38 SkScalar x = SkIntToScalar(ix);
39 SkScalar y = SkIntToScalar(iy);
rmistry@google.comd6176b02012-08-23 18:14:13 +000040
reed@android.com6a5a2662009-05-08 16:45:52 +000041 a.set(0, 0);
42 REPORTER_ASSERT(reporter, a.isEmpty());
43 a.set(x, -x);
44 REPORTER_ASSERT(reporter, a.isEmpty());
Hal Canaryfafe1352017-04-11 12:12:02 -040045 a = SkSize{x, 0};
reed@android.com6a5a2662009-05-08 16:45:52 +000046 REPORTER_ASSERT(reporter, a.isEmpty());
47 b.set(x, 0);
48 REPORTER_ASSERT(reporter, a == b);
rmistry@google.comd6176b02012-08-23 18:14:13 +000049
reed@android.com6a5a2662009-05-08 16:45:52 +000050 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.comd6176b02012-08-23 18:14:13 +000058
reed@android.com6a5a2662009-05-08 16:45:52 +000059 SkISize ia;
60 ia.set(ix, iy);
61 a.set(x, y);
reed@android.comf5979912010-06-15 00:57:50 +000062 REPORTER_ASSERT(reporter, a.toRound() == ia);
tfarina@chromium.orge4fafb12013-12-12 21:11:12 +000063}