]> git.stg.codes - stg.git/blob - tests/test_admin_conf.cpp
Initialize arcs member in all OID constructors
[stg.git] / tests / test_admin_conf.cpp
1 #include "tut/tut.hpp"
2
3 #include "stg/admin_conf.h"
4
5 namespace tut
6 {
7     struct priv_data {
8         enum {
9             MIX2 = 0x0002C6C6, // 210321032
10             ONES = 0x00015555,
11             MIX3 = 0x00031B1B, // 321032103
12             TWOS = 0x0002AAAA,
13             MIX1 = 0x0000E4E4, // 012301230
14             THREES = 0x0003FFFF
15         };
16     };
17
18     typedef test_group<priv_data> tg;
19     tg priv_test_group("PRIV tests group");
20
21     typedef tg::object testobject;
22
23     template<>
24     template<>
25     void testobject::test<1>()
26     {
27         set_test_name("Check default constructor");
28
29         PRIV zero;
30
31         ensure("zero.userStat == 0", zero.userStat == 0);
32         ensure("zero.userConf == 0", zero.userConf == 0);
33         ensure("zero.userCash == 0", zero.userCash == 0);
34         ensure("zero.userPasswd == 0", zero.userPasswd == 0);
35         ensure("zero.userAddDel == 0", zero.userAddDel == 0);
36         ensure("zero.adminChg == 0", zero.adminChg == 0);
37         ensure("zero.tariffChg == 0", zero.tariffChg == 0);
38         ensure("zero.serviceChg == 0", zero.serviceChg == 0);
39         ensure("zero.corpChg == 0", zero.corpChg == 0);
40
41         ensure("zero.ToInt() == 0", zero.ToInt() == 0);
42     }
43
44     template<>
45     template<>
46     void testobject::test<2>()
47     {
48         set_test_name("Check uint32_t conversions");
49
50         for (uint8_t i = 0; i < 4; ++i) {
51
52             // 'i' is extra trash in high bits
53
54             PRIV priv1(ONES | (i << 0x12)); // All 1
55
56             ensure_equals("priv1.userStat == 1", priv1.userStat, 1);
57             ensure_equals("priv1.userConf == 1", priv1.userConf, 1);
58             ensure_equals("priv1.userCash == 1", priv1.userCash, 1);
59             ensure_equals("priv1.userPasswd == 1", priv1.userPasswd, 1);
60             ensure_equals("priv1.userAddDel == 1", priv1.userAddDel, 1);
61             ensure_equals("priv1.adminChg == 1", priv1.adminChg, 1);
62             ensure_equals("priv1.tariffChg == 1", priv1.tariffChg, 1);
63             ensure_equals("priv1.serviceChg == 1", priv1.serviceChg, 1);
64             ensure_equals("priv1.corpChg == 1", priv1.corpChg, 1);
65
66             ensure_equals("priv1.ToInt() == 0x00015555", priv1.ToInt(), static_cast<uint32_t>(ONES));
67
68             PRIV priv2(TWOS | (i << 0x12)); // All 2
69
70             ensure_equals("priv2.userStat == 2", priv2.userStat, 2);
71             ensure_equals("priv2.userConf == 2", priv2.userConf, 2);
72             ensure_equals("priv2.userCash == 2", priv2.userCash, 2);
73             ensure_equals("priv2.userPasswd == 2", priv2.userPasswd, 2);
74             ensure_equals("priv2.userAddDel == 2", priv2.userAddDel, 2);
75             ensure_equals("priv2.adminChg == 2", priv2.adminChg, 2);
76             ensure_equals("priv2.tariffChg == 2", priv2.tariffChg, 2);
77             ensure_equals("priv2.serviceChg == 2", priv2.serviceChg, 2);
78             ensure_equals("priv2.corpChg == 2", priv2.corpChg, 2);
79
80             ensure_equals("priv2.ToInt() = 0x0002AAAA", priv2.ToInt(), static_cast<uint32_t>(TWOS));
81
82             PRIV priv3(THREES | (i << 0x12)); // All 3
83
84             ensure_equals("priv3.userStat == 3", priv3.userStat, 3);
85             ensure_equals("priv3.userConf == 3", priv3.userConf, 3);
86             ensure_equals("priv3.userCash == 3", priv3.userCash, 3);
87             ensure_equals("priv3.userPasswd == 3", priv3.userPasswd, 3);
88             ensure_equals("priv3.userAddDel == 3", priv3.userAddDel, 3);
89             ensure_equals("priv3.adminChg == 3", priv3.adminChg, 3);
90             ensure_equals("priv3.tariffChg == 3", priv3.tariffChg, 3);
91             ensure_equals("priv3.serviceChg == 3", priv3.serviceChg, 3);
92             ensure_equals("priv3.corpChg == 3", priv3.corpChg, 3);
93
94             ensure_equals("priv3.ToInt() = 0x0003FFFF", priv3.ToInt(), static_cast<uint32_t>(THREES));
95
96             PRIV pm1(MIX1 | (i << 0x12)); // 012301230
97
98             ensure_equals("pm1.userStat == 0", pm1.userStat, 0);
99             ensure_equals("pm1.userConf == 1", pm1.userConf, 1);
100             ensure_equals("pm1.userCash == 2", pm1.userCash, 2);
101             ensure_equals("pm1.userPasswd == 3", pm1.userPasswd, 3);
102             ensure_equals("pm1.userAddDel == 0", pm1.userAddDel, 0);
103             ensure_equals("pm1.adminChg == 1", pm1.adminChg, 1);
104             ensure_equals("pm1.tariffChg == 2", pm1.tariffChg, 2);
105             ensure_equals("pm1.serviceChg == 3", pm1.serviceChg, 3);
106             ensure_equals("pm1.corpChg == 0", pm1.corpChg, 0);
107
108             ensure_equals("pm1.ToInt() = 0xE4E4", pm1.ToInt(), static_cast<uint32_t>(MIX1));
109
110             PRIV pm2(MIX2 | (i << 0x12)); // 210321032
111
112             ensure_equals("pm2.userStat == 2", pm2.userStat, 2);
113             ensure_equals("pm2.userConf == 1", pm2.userConf, 1);
114             ensure_equals("pm2.userCash == 0", pm2.userCash, 0);
115             ensure_equals("pm2.userPasswd == 3", pm2.userPasswd, 3);
116             ensure_equals("pm2.userAddDel == 2", pm2.userAddDel, 2);
117             ensure_equals("pm2.adminChg == 1", pm2.adminChg, 1);
118             ensure_equals("pm2.tariffChg == 0", pm2.tariffChg, 0);
119             ensure_equals("pm2.serviceChg == 3", pm2.serviceChg, 3);
120             ensure_equals("pm2.corpChg == 2", pm2.corpChg, 2);
121
122             ensure_equals("pm2.ToInt() = 0x0002C6C6", pm2.ToInt(), static_cast<uint32_t>(MIX2));
123
124             PRIV pm3(MIX3 | (i << 0x12)); // 321032103
125
126             ensure_equals("pm3.userStat == 3", pm3.userStat, 3);
127             ensure_equals("pm3.userConf == 2", pm3.userConf, 2);
128             ensure_equals("pm3.userCash == 1", pm3.userCash, 1);
129             ensure_equals("pm3.userPasswd == 0", pm3.userPasswd, 0);
130             ensure_equals("pm3.userAddDel == 3", pm3.userAddDel, 3);
131             ensure_equals("pm3.adminChg == 2", pm3.adminChg, 2);
132             ensure_equals("pm3.tariffChg == 1", pm3.tariffChg, 1);
133             ensure_equals("pm3.serviceChg == 0", pm3.serviceChg, 0);
134             ensure_equals("pm3.corpChg == 3", pm3.corpChg, 3);
135
136             ensure_equals("pm3.ToInt() = 0x00031B1B", pm3.ToInt(), static_cast<uint32_t>(MIX3));
137
138         }
139
140     }
141
142     template<>
143     template<>
144     void testobject::test<3>()
145     {
146         set_test_name("Check explicit uint32_t conversions");
147
148         for (uint8_t i = 0; i < 4; ++i) {
149
150             // 'i' is extra trash in high bits
151
152             PRIV priv1;
153             priv1.FromInt(ONES | (i << 0x12)); // All 1
154
155
156             ensure_equals("priv1.userStat == 1", priv1.userStat, 1);
157             ensure_equals("priv1.userConf == 1", priv1.userConf, 1);
158             ensure_equals("priv1.userCash == 1", priv1.userCash, 1);
159             ensure_equals("priv1.userPasswd == 1", priv1.userPasswd, 1);
160             ensure_equals("priv1.userAddDel == 1", priv1.userAddDel, 1);
161             ensure_equals("priv1.adminChg == 1", priv1.adminChg, 1);
162             ensure_equals("priv1.tariffChg == 1", priv1.tariffChg, 1);
163             ensure_equals("priv1.serviceChg == 1", priv1.serviceChg, 1);
164             ensure_equals("priv1.corpChg == 1", priv1.corpChg, 1);
165
166             ensure_equals("priv1.ToInt() == 0x00015555", priv1.ToInt(), static_cast<uint32_t>(ONES));
167
168             PRIV priv2;
169             priv2.FromInt(TWOS | (i << 0x12)); // All 2
170
171             ensure_equals("priv2.userStat == 2", priv2.userStat, 2);
172             ensure_equals("priv2.userConf == 2", priv2.userConf, 2);
173             ensure_equals("priv2.userCash == 2", priv2.userCash, 2);
174             ensure_equals("priv2.userPasswd == 2", priv2.userPasswd, 2);
175             ensure_equals("priv2.userAddDel == 2", priv2.userAddDel, 2);
176             ensure_equals("priv2.adminChg == 2", priv2.adminChg, 2);
177             ensure_equals("priv2.tariffChg == 2", priv2.tariffChg, 2);
178             ensure_equals("priv2.serviceChg == 2", priv2.serviceChg, 2);
179             ensure_equals("priv2.corpChg == 2", priv2.corpChg, 2);
180
181             ensure_equals("priv2.ToInt() = 0x0002AAAA", priv2.ToInt(), static_cast<uint32_t>(TWOS));
182
183             PRIV priv3;
184             priv3.FromInt(THREES | (i << 0x12)); // All 3
185
186             ensure_equals("priv3.userStat == 3", priv3.userStat, 3);
187             ensure_equals("priv3.userConf == 3", priv3.userConf, 3);
188             ensure_equals("priv3.userCash == 3", priv3.userCash, 3);
189             ensure_equals("priv3.userPasswd == 3", priv3.userPasswd, 3);
190             ensure_equals("priv3.userAddDel == 3", priv3.userAddDel, 3);
191             ensure_equals("priv3.adminChg == 3", priv3.adminChg, 3);
192             ensure_equals("priv3.tariffChg == 3", priv3.tariffChg, 3);
193             ensure_equals("priv3.serviceChg == 3", priv3.serviceChg, 3);
194             ensure_equals("priv3.corpChg == 3", priv3.corpChg, 3);
195
196             ensure_equals("priv3.ToInt() = 0x0003FFFF", priv3.ToInt(), static_cast<uint32_t>(THREES));
197
198             PRIV pm1;
199             pm1.FromInt(MIX1 | (i << 0x12)); // 012301230
200
201             ensure_equals("pm1.userStat == 0", pm1.userStat, 0);
202             ensure_equals("pm1.userConf == 1", pm1.userConf, 1);
203             ensure_equals("pm1.userCash == 2", pm1.userCash, 2);
204             ensure_equals("pm1.userPasswd == 3", pm1.userPasswd, 3);
205             ensure_equals("pm1.userAddDel == 0", pm1.userAddDel, 0);
206             ensure_equals("pm1.adminChg == 1", pm1.adminChg, 1);
207             ensure_equals("pm1.tariffChg == 2", pm1.tariffChg, 2);
208             ensure_equals("pm1.serviceChg == 3", pm1.serviceChg, 3);
209             ensure_equals("pm1.corpChg == 0", pm1.corpChg, 0);
210
211             ensure_equals("pm1.ToInt() = 0xE4E4", pm1.ToInt(), static_cast<uint32_t>(MIX1));
212
213             PRIV pm2;
214             pm2.FromInt(MIX2 | (i << 0x12)); // 210321032
215
216             ensure_equals("pm2.userStat == 2", pm2.userStat, 2);
217             ensure_equals("pm2.userConf == 1", pm2.userConf, 1);
218             ensure_equals("pm2.userCash == 0", pm2.userCash, 0);
219             ensure_equals("pm2.userPasswd == 3", pm2.userPasswd, 3);
220             ensure_equals("pm2.userAddDel == 2", pm2.userAddDel, 2);
221             ensure_equals("pm2.adminChg == 1", pm2.adminChg, 1);
222             ensure_equals("pm2.tariffChg == 0", pm2.tariffChg, 0);
223             ensure_equals("pm2.serviceChg == 3", pm2.serviceChg, 3);
224             ensure_equals("pm2.corpChg == 2", pm2.corpChg, 2);
225
226             ensure_equals("pm2.ToInt() = 0x0002C6C6", pm2.ToInt(), static_cast<uint32_t>(MIX2));
227
228             PRIV pm3;
229             pm3.FromInt(MIX3 | (i << 0x12)); // 321032103
230
231             ensure_equals("pm3.userStat == 3", pm3.userStat, 3);
232             ensure_equals("pm3.userConf == 2", pm3.userConf, 2);
233             ensure_equals("pm3.userCash == 1", pm3.userCash, 1);
234             ensure_equals("pm3.userPasswd == 0", pm3.userPasswd, 0);
235             ensure_equals("pm3.userAddDel == 3", pm3.userAddDel, 3);
236             ensure_equals("pm3.adminChg == 2", pm3.adminChg, 2);
237             ensure_equals("pm3.tariffChg == 1", pm3.tariffChg, 1);
238             ensure_equals("pm3.serviceChg == 0", pm3.serviceChg, 0);
239             ensure_equals("pm3.corpChg == 3", pm3.corpChg, 3);
240
241             ensure_equals("pm3.ToInt() = 0x00031B1B", pm3.ToInt(), static_cast<uint32_t>(MIX3));
242
243         }
244
245     }
246
247 }