aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/TestSize.cpp
blob: 6551509e8dd579db8f98bf365d53c0c37fe1d72b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include "Test.h"
#include "SkSize.h"

static void TestISize(skiatest::Reporter* reporter) {
    SkISize  a, b;
    
    a.set(0, 0);
    REPORTER_ASSERT(reporter, a.isEmpty());
    a.set(5, -5);
    REPORTER_ASSERT(reporter, a.isEmpty());
    a.clampNegToZero();
    REPORTER_ASSERT(reporter, a.isEmpty());
    b.set(5, 0);
    REPORTER_ASSERT(reporter, a == b);
    
    a.set(3, 5);
    REPORTER_ASSERT(reporter, !a.isEmpty());
    b = a;
    REPORTER_ASSERT(reporter, !b.isEmpty());
    REPORTER_ASSERT(reporter, a == b);
    REPORTER_ASSERT(reporter, !(a != b));
    REPORTER_ASSERT(reporter,
                    a.fWidth == b.fWidth && a.fHeight == b.fHeight);
}

static void TestSize(skiatest::Reporter* reporter) {
    TestISize(reporter);
    
    SkSize a, b;
    int ix = 5;
    int iy = 3;
    SkScalar x = SkIntToScalar(ix);
    SkScalar y = SkIntToScalar(iy);
    
    a.set(0, 0);
    REPORTER_ASSERT(reporter, a.isEmpty());
    a.set(x, -x);
    REPORTER_ASSERT(reporter, a.isEmpty());
    a.clampNegToZero();
    REPORTER_ASSERT(reporter, a.isEmpty());
    b.set(x, 0);
    REPORTER_ASSERT(reporter, a == b);
    
    a.set(y, x);
    REPORTER_ASSERT(reporter, !a.isEmpty());
    b = a;
    REPORTER_ASSERT(reporter, !b.isEmpty());
    REPORTER_ASSERT(reporter, a == b);
    REPORTER_ASSERT(reporter, !(a != b));
    REPORTER_ASSERT(reporter,
                    a.fWidth == b.fWidth && a.fHeight == b.fHeight);
    
    SkISize ia;
    ia.set(ix, iy);
    a.set(x, y);
    REPORTER_ASSERT(reporter, a.round() == ia);
};

#include "TestClassDef.h"
DEFINE_TESTCLASS("Size", TestSizeClass, TestSize)