blob: 9e0aaaa8c9a3aa17a449ef65ba4ad61aae69a8da [file] [log] [blame]
reed@android.com6a5a2662009-05-08 16:45:52 +00001#include "Test.h"
2#include "SkSize.h"
3
4static void TestISize(skiatest::Reporter* reporter) {
5 SkISize a, b;
6
7 a.set(0, 0);
8 REPORTER_ASSERT(reporter, a.isEmpty());
9 a.set(5, -5);
10 REPORTER_ASSERT(reporter, a.isEmpty());
11 a.clampNegToZero();
12 REPORTER_ASSERT(reporter, a.isEmpty());
13 b.set(5, 0);
14 REPORTER_ASSERT(reporter, a == b);
15
16 a.set(3, 5);
17 REPORTER_ASSERT(reporter, !a.isEmpty());
18 b = a;
19 REPORTER_ASSERT(reporter, !b.isEmpty());
20 REPORTER_ASSERT(reporter, a == b);
21 REPORTER_ASSERT(reporter, !(a != b));
22 REPORTER_ASSERT(reporter,
23 a.fWidth == b.fWidth && a.fHeight == b.fHeight);
24}
25
26static void TestSize(skiatest::Reporter* reporter) {
27 TestISize(reporter);
28
29 SkSize a, b;
30 int ix = 5;
31 int iy = 3;
32 SkScalar x = SkIntToScalar(ix);
33 SkScalar y = SkIntToScalar(iy);
34
35 a.set(0, 0);
36 REPORTER_ASSERT(reporter, a.isEmpty());
37 a.set(x, -x);
38 REPORTER_ASSERT(reporter, a.isEmpty());
39 a.clampNegToZero();
40 REPORTER_ASSERT(reporter, a.isEmpty());
41 b.set(x, 0);
42 REPORTER_ASSERT(reporter, a == b);
43
44 a.set(y, x);
45 REPORTER_ASSERT(reporter, !a.isEmpty());
46 b = a;
47 REPORTER_ASSERT(reporter, !b.isEmpty());
48 REPORTER_ASSERT(reporter, a == b);
49 REPORTER_ASSERT(reporter, !(a != b));
50 REPORTER_ASSERT(reporter,
51 a.fWidth == b.fWidth && a.fHeight == b.fHeight);
52
53 SkISize ia;
54 ia.set(ix, iy);
55 a.set(x, y);
reed@android.comf5979912010-06-15 00:57:50 +000056 REPORTER_ASSERT(reporter, a.toRound() == ia);
reed@android.com6a5a2662009-05-08 16:45:52 +000057};
58
59#include "TestClassDef.h"
60DEFINE_TESTCLASS("Size", TestSizeClass, TestSize)