TestSize.cpp revision 05b6b4d746867a9fb02e14edfe1bf3685abeb813
1215473cea1702d8acc0316da3e5a9bf4ce0130efMike Reed#include "Test.h"
2215473cea1702d8acc0316da3e5a9bf4ce0130efMike Reed#include "SkSize.h"
3215473cea1702d8acc0316da3e5a9bf4ce0130efMike Reed
4215473cea1702d8acc0316da3e5a9bf4ce0130efMike Reedstatic void TestISize(skiatest::Reporter* reporter) {
5215473cea1702d8acc0316da3e5a9bf4ce0130efMike Reed    SkISize  a, b;
6215473cea1702d8acc0316da3e5a9bf4ce0130efMike Reed
7215473cea1702d8acc0316da3e5a9bf4ce0130efMike Reed    a.set(0, 0);
8215473cea1702d8acc0316da3e5a9bf4ce0130efMike Reed    REPORTER_ASSERT(reporter, a.isEmpty());
9215473cea1702d8acc0316da3e5a9bf4ce0130efMike Reed    a.set(5, -5);
10215473cea1702d8acc0316da3e5a9bf4ce0130efMike Reed    REPORTER_ASSERT(reporter, a.isEmpty());
11215473cea1702d8acc0316da3e5a9bf4ce0130efMike Reed    a.clampNegToZero();
12215473cea1702d8acc0316da3e5a9bf4ce0130efMike Reed    REPORTER_ASSERT(reporter, a.isEmpty());
13215473cea1702d8acc0316da3e5a9bf4ce0130efMike Reed    b.set(5, 0);
14215473cea1702d8acc0316da3e5a9bf4ce0130efMike Reed    REPORTER_ASSERT(reporter, a == b);
15215473cea1702d8acc0316da3e5a9bf4ce0130efMike Reed
16215473cea1702d8acc0316da3e5a9bf4ce0130efMike Reed    a.set(3, 5);
17215473cea1702d8acc0316da3e5a9bf4ce0130efMike Reed    REPORTER_ASSERT(reporter, !a.isEmpty());
18215473cea1702d8acc0316da3e5a9bf4ce0130efMike Reed    b = a;
19215473cea1702d8acc0316da3e5a9bf4ce0130efMike Reed    REPORTER_ASSERT(reporter, !b.isEmpty());
20215473cea1702d8acc0316da3e5a9bf4ce0130efMike Reed    REPORTER_ASSERT(reporter, a == b);
21215473cea1702d8acc0316da3e5a9bf4ce0130efMike Reed    REPORTER_ASSERT(reporter, !(a != b));
22215473cea1702d8acc0316da3e5a9bf4ce0130efMike Reed    REPORTER_ASSERT(reporter,
23215473cea1702d8acc0316da3e5a9bf4ce0130efMike Reed                    a.fWidth == b.fWidth && a.fHeight == b.fHeight);
24215473cea1702d8acc0316da3e5a9bf4ce0130efMike Reed}
25215473cea1702d8acc0316da3e5a9bf4ce0130efMike Reed
26215473cea1702d8acc0316da3e5a9bf4ce0130efMike Reedstatic void TestSize(skiatest::Reporter* reporter) {
27215473cea1702d8acc0316da3e5a9bf4ce0130efMike Reed    TestISize(reporter);
28215473cea1702d8acc0316da3e5a9bf4ce0130efMike Reed
29215473cea1702d8acc0316da3e5a9bf4ce0130efMike Reed    SkSize a, b;
30215473cea1702d8acc0316da3e5a9bf4ce0130efMike Reed    int ix = 5;
31215473cea1702d8acc0316da3e5a9bf4ce0130efMike Reed    int iy = 3;
32215473cea1702d8acc0316da3e5a9bf4ce0130efMike Reed    SkScalar x = SkIntToScalar(ix);
33215473cea1702d8acc0316da3e5a9bf4ce0130efMike Reed    SkScalar y = SkIntToScalar(iy);
34215473cea1702d8acc0316da3e5a9bf4ce0130efMike Reed
35215473cea1702d8acc0316da3e5a9bf4ce0130efMike Reed    a.set(0, 0);
36215473cea1702d8acc0316da3e5a9bf4ce0130efMike Reed    REPORTER_ASSERT(reporter, a.isEmpty());
37215473cea1702d8acc0316da3e5a9bf4ce0130efMike Reed    a.set(x, -x);
38215473cea1702d8acc0316da3e5a9bf4ce0130efMike Reed    REPORTER_ASSERT(reporter, a.isEmpty());
39215473cea1702d8acc0316da3e5a9bf4ce0130efMike Reed    a.clampNegToZero();
40215473cea1702d8acc0316da3e5a9bf4ce0130efMike Reed    REPORTER_ASSERT(reporter, a.isEmpty());
41215473cea1702d8acc0316da3e5a9bf4ce0130efMike Reed    b.set(x, 0);
42215473cea1702d8acc0316da3e5a9bf4ce0130efMike Reed    REPORTER_ASSERT(reporter, a == b);
43215473cea1702d8acc0316da3e5a9bf4ce0130efMike Reed
44215473cea1702d8acc0316da3e5a9bf4ce0130efMike Reed    a.set(y, x);
45215473cea1702d8acc0316da3e5a9bf4ce0130efMike Reed    REPORTER_ASSERT(reporter, !a.isEmpty());
46215473cea1702d8acc0316da3e5a9bf4ce0130efMike Reed    b = a;
47215473cea1702d8acc0316da3e5a9bf4ce0130efMike Reed    REPORTER_ASSERT(reporter, !b.isEmpty());
48215473cea1702d8acc0316da3e5a9bf4ce0130efMike Reed    REPORTER_ASSERT(reporter, a == b);
49215473cea1702d8acc0316da3e5a9bf4ce0130efMike Reed    REPORTER_ASSERT(reporter, !(a != b));
50215473cea1702d8acc0316da3e5a9bf4ce0130efMike Reed    REPORTER_ASSERT(reporter,
51215473cea1702d8acc0316da3e5a9bf4ce0130efMike Reed                    a.fWidth == b.fWidth && a.fHeight == b.fHeight);
52215473cea1702d8acc0316da3e5a9bf4ce0130efMike Reed
53215473cea1702d8acc0316da3e5a9bf4ce0130efMike Reed    SkISize ia;
54215473cea1702d8acc0316da3e5a9bf4ce0130efMike Reed    ia.set(ix, iy);
55215473cea1702d8acc0316da3e5a9bf4ce0130efMike Reed    a.set(x, y);
5605b6b4d746867a9fb02e14edfe1bf3685abeb813Derek Sollenberger    REPORTER_ASSERT(reporter, a.toRound() == ia);
57215473cea1702d8acc0316da3e5a9bf4ce0130efMike Reed};
58215473cea1702d8acc0316da3e5a9bf4ce0130efMike Reed
59215473cea1702d8acc0316da3e5a9bf4ce0130efMike Reed#include "TestClassDef.h"
60215473cea1702d8acc0316da3e5a9bf4ce0130efMike ReedDEFINE_TESTCLASS("Size", TestSizeClass, TestSize)
61