]> git.stg.codes - stg.git/blob - tests/test_admin_conf.cpp
Another `stgTime` case.
[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         STG::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             STG::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             STG::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             STG::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             STG::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             STG::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             STG::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             STG::Priv priv1(ONES | (i << 0x12)); // All 1
153
154
155             ensure_equals("priv1.userStat == 1", priv1.userStat, 1);
156             ensure_equals("priv1.userConf == 1", priv1.userConf, 1);
157             ensure_equals("priv1.userCash == 1", priv1.userCash, 1);
158             ensure_equals("priv1.userPasswd == 1", priv1.userPasswd, 1);
159             ensure_equals("priv1.userAddDel == 1", priv1.userAddDel, 1);
160             ensure_equals("priv1.adminChg == 1", priv1.adminChg, 1);
161             ensure_equals("priv1.tariffChg == 1", priv1.tariffChg, 1);
162             ensure_equals("priv1.serviceChg == 1", priv1.serviceChg, 1);
163             ensure_equals("priv1.corpChg == 1", priv1.corpChg, 1);
164
165             ensure_equals("priv1.toInt() == 0x00015555", priv1.toInt(), static_cast<uint32_t>(ONES));
166
167             STG::Priv priv2(TWOS | (i << 0x12)); // All 2
168
169             ensure_equals("priv2.userStat == 2", priv2.userStat, 2);
170             ensure_equals("priv2.userConf == 2", priv2.userConf, 2);
171             ensure_equals("priv2.userCash == 2", priv2.userCash, 2);
172             ensure_equals("priv2.userPasswd == 2", priv2.userPasswd, 2);
173             ensure_equals("priv2.userAddDel == 2", priv2.userAddDel, 2);
174             ensure_equals("priv2.adminChg == 2", priv2.adminChg, 2);
175             ensure_equals("priv2.tariffChg == 2", priv2.tariffChg, 2);
176             ensure_equals("priv2.serviceChg == 2", priv2.serviceChg, 2);
177             ensure_equals("priv2.corpChg == 2", priv2.corpChg, 2);
178
179             ensure_equals("priv2.toInt() = 0x0002AAAA", priv2.toInt(), static_cast<uint32_t>(TWOS));
180
181             STG::Priv priv3(THREES | (i << 0x12)); // All 3
182
183             ensure_equals("priv3.userStat == 3", priv3.userStat, 3);
184             ensure_equals("priv3.userConf == 3", priv3.userConf, 3);
185             ensure_equals("priv3.userCash == 3", priv3.userCash, 3);
186             ensure_equals("priv3.userPasswd == 3", priv3.userPasswd, 3);
187             ensure_equals("priv3.userAddDel == 3", priv3.userAddDel, 3);
188             ensure_equals("priv3.adminChg == 3", priv3.adminChg, 3);
189             ensure_equals("priv3.tariffChg == 3", priv3.tariffChg, 3);
190             ensure_equals("priv3.serviceChg == 3", priv3.serviceChg, 3);
191             ensure_equals("priv3.corpChg == 3", priv3.corpChg, 3);
192
193             ensure_equals("priv3.toInt() = 0x0003FFFF", priv3.toInt(), static_cast<uint32_t>(THREES));
194
195             STG::Priv pm1(MIX1 | (i << 0x12)); // 012301230
196
197             ensure_equals("pm1.userStat == 0", pm1.userStat, 0);
198             ensure_equals("pm1.userConf == 1", pm1.userConf, 1);
199             ensure_equals("pm1.userCash == 2", pm1.userCash, 2);
200             ensure_equals("pm1.userPasswd == 3", pm1.userPasswd, 3);
201             ensure_equals("pm1.userAddDel == 0", pm1.userAddDel, 0);
202             ensure_equals("pm1.adminChg == 1", pm1.adminChg, 1);
203             ensure_equals("pm1.tariffChg == 2", pm1.tariffChg, 2);
204             ensure_equals("pm1.serviceChg == 3", pm1.serviceChg, 3);
205             ensure_equals("pm1.corpChg == 0", pm1.corpChg, 0);
206
207             ensure_equals("pm1.toInt() = 0xE4E4", pm1.toInt(), static_cast<uint32_t>(MIX1));
208
209             STG::Priv pm2(MIX2 | (i << 0x12)); // 210321032
210
211             ensure_equals("pm2.userStat == 2", pm2.userStat, 2);
212             ensure_equals("pm2.userConf == 1", pm2.userConf, 1);
213             ensure_equals("pm2.userCash == 0", pm2.userCash, 0);
214             ensure_equals("pm2.userPasswd == 3", pm2.userPasswd, 3);
215             ensure_equals("pm2.userAddDel == 2", pm2.userAddDel, 2);
216             ensure_equals("pm2.adminChg == 1", pm2.adminChg, 1);
217             ensure_equals("pm2.tariffChg == 0", pm2.tariffChg, 0);
218             ensure_equals("pm2.serviceChg == 3", pm2.serviceChg, 3);
219             ensure_equals("pm2.corpChg == 2", pm2.corpChg, 2);
220
221             ensure_equals("pm2.toInt() = 0x0002C6C6", pm2.toInt(), static_cast<uint32_t>(MIX2));
222
223             STG::Priv pm3(MIX3 | (i << 0x12)); // 321032103
224
225             ensure_equals("pm3.userStat == 3", pm3.userStat, 3);
226             ensure_equals("pm3.userConf == 2", pm3.userConf, 2);
227             ensure_equals("pm3.userCash == 1", pm3.userCash, 1);
228             ensure_equals("pm3.userPasswd == 0", pm3.userPasswd, 0);
229             ensure_equals("pm3.userAddDel == 3", pm3.userAddDel, 3);
230             ensure_equals("pm3.adminChg == 2", pm3.adminChg, 2);
231             ensure_equals("pm3.tariffChg == 1", pm3.tariffChg, 1);
232             ensure_equals("pm3.serviceChg == 0", pm3.serviceChg, 0);
233             ensure_equals("pm3.corpChg == 3", pm3.corpChg, 3);
234
235             ensure_equals("pm3.toInt() = 0x00031B1B", pm3.toInt(), static_cast<uint32_t>(MIX3));
236
237         }
238
239     }
240
241 }