]> git.mxchange.org Git - simgear.git/blob - simgear/misc/CSSBorder_test.cxx
HTTP: Rename urlretrieve/urlload to save/load.
[simgear.git] / simgear / misc / CSSBorder_test.cxx
1 #include <simgear/compiler.h>
2
3 #include "CSSBorder.hxx"
4
5 #include <cmath>
6 #include <iostream>
7
8 #define COMPARE(a, b) \
9   if( std::fabs((a) - (b)) > 1e-4 ) \
10   { \
11     std::cerr << "line " << __LINE__ << ": failed: "\
12               << #a << " != " << #b << " d = " << ((a) - (b)) << std::endl; \
13     return 1; \
14   }
15
16 #define VERIFY(a) \
17   if( !(a) ) \
18   { \
19     std::cerr << "line " << __LINE__ << ": failed: "\
20               << #a << std::endl; \
21     return 1; \
22   }
23
24 using namespace simgear;
25
26 int main (int ac, char ** av)
27 {
28   CSSBorder b = CSSBorder::parse("5");
29   VERIFY(b.isValid());
30   VERIFY(!b.isNone());
31   CSSBorder::Offsets o = b.getAbsOffsets(SGRect<int>());
32   COMPARE(o.t, 5);
33   COMPARE(o.r, 5);
34   COMPARE(o.b, 5);
35   COMPARE(o.l, 5);
36
37   b = CSSBorder::parse("5 10");
38   o = b.getAbsOffsets(SGRect<int>());
39   COMPARE(o.t, 5);
40   COMPARE(o.r, 10);
41   COMPARE(o.b, 5);
42   COMPARE(o.l, 10);
43
44   b = CSSBorder::parse("5 10 15");
45   o = b.getAbsOffsets(SGRect<int>());
46   COMPARE(o.t, 5);
47   COMPARE(o.r, 10);
48   COMPARE(o.b, 15);
49   COMPARE(o.l, 10);
50
51   b = CSSBorder::parse("5 10 15 20");
52   o = b.getAbsOffsets(SGRect<int>());
53   COMPARE(o.t, 5);
54   COMPARE(o.r, 10);
55   COMPARE(o.b, 15);
56   COMPARE(o.l, 20);
57
58   b = CSSBorder::parse("5 10 15 20");
59   o = b.getRelOffsets(SGRect<int>(0,0,100,200));
60   COMPARE(o.t, 0.025);
61   COMPARE(o.r, 0.1);
62   COMPARE(o.b, 0.075);
63   COMPARE(o.l, 0.2);
64
65   b = CSSBorder::parse("5% 10% 15% 20%");
66   o = b.getAbsOffsets(SGRect<int>(0,0,100,200));
67   COMPARE(o.t, 10);
68   COMPARE(o.r, 10);
69   COMPARE(o.b, 30);
70   COMPARE(o.l, 20);
71
72   o = b.getRelOffsets(SGRect<int>(0,0,100,200));
73   COMPARE(o.t, 0.05);
74   COMPARE(o.r, 0.1);
75   COMPARE(o.b, 0.15);
76   COMPARE(o.l, 0.2);
77
78   b = CSSBorder::parse("5% none");
79   o = b.getAbsOffsets(SGRect<int>(0,0,200,200));
80   COMPARE(o.t, 0);
81   COMPARE(o.r, 0);
82   COMPARE(o.b, 0);
83   COMPARE(o.l, 0);
84   VERIFY(b.getKeyword().empty());
85   VERIFY(b.isNone());
86
87   b = CSSBorder::parse("none");
88   o = b.getRelOffsets(SGRect<int>(0,0,200,200));
89   COMPARE(o.t, 0);
90   COMPARE(o.r, 0);
91   COMPARE(o.b, 0);
92   COMPARE(o.l, 0);
93   VERIFY(b.getKeyword().empty());
94   VERIFY(b.isNone());
95
96   CSSBorder b2;
97   VERIFY(!b2.isValid());
98   o = b.getAbsOffsets(SGRect<int>(0,0,200,200));
99   COMPARE(o.t, 0);
100   COMPARE(o.r, 0);
101   COMPARE(o.b, 0);
102   COMPARE(o.l, 0);
103   o = b.getRelOffsets(SGRect<int>(0,0,200,200));
104   COMPARE(o.t, 0);
105   COMPARE(o.r, 0);
106   COMPARE(o.b, 0);
107   COMPARE(o.l, 0);
108
109   std::cout << "all tests passed successfully!" << std::endl;
110   return 0;
111 }