]> git.stg.codes - stg.git/blob - tests/test_admin_conf.cpp
52f09eebbd0367a353a1d4234fbecf09c214b7bb
[stg.git] / tests / test_admin_conf.cpp
1 #include <iostream>
2
3 #include "tut/tut.hpp"
4
5 #include "admin_conf.h"
6
7 namespace tut
8 {
9     struct priv_data {
10         enum {
11             MIX2 = 0x06C6, // 2103210
12             ONES = 0x1555,
13             MIX3 = 0x1B1B, // 3210321
14             TWOS = 0x2AAA,
15             MIX1 = 0x24E4, // 0123012
16             THREES = 0x3FFF
17         };
18     };
19
20     typedef test_group<priv_data> tg;
21     tg priv_test_group("PRIV tests group");
22
23     typedef tg::object testobject;
24
25     template<>
26     template<>
27     void testobject::test<1>()
28     {
29         set_test_name("Check default constructor");
30
31         PRIV zero;
32
33         ensure("zero.userStat == 0", zero.userStat == 0);
34         ensure("zero.userConf == 0", zero.userConf == 0);
35         ensure("zero.userCash == 0", zero.userCash == 0);
36         ensure("zero.userPasswd == 0", zero.userPasswd == 0);
37         ensure("zero.userAddDel == 0", zero.userAddDel == 0);
38         ensure("zero.adminChg == 0", zero.adminChg == 0);
39         ensure("zero.tariffChg == 0", zero.tariffChg == 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 uint16_t conversions");
49
50         for (uint16_t i = 0; i < 4; ++i) {
51
52             // 'i' is extra trash in high bits
53
54             PRIV priv1(ONES | (i << 0x0E)); // 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
64             ensure_equals("priv1.ToInt() == 0x1555", priv1.ToInt(), static_cast<uint16_t>(ONES));
65
66             PRIV priv2(TWOS | (i << 0x0E)); // All 2
67
68             ensure_equals("priv2.userStat == 2", priv2.userStat, 2);
69             ensure_equals("priv2.userConf == 2", priv2.userConf, 2);
70             ensure_equals("priv2.userCash == 2", priv2.userCash, 2);
71             ensure_equals("priv2.userPasswd == 2", priv2.userPasswd, 2);
72             ensure_equals("priv2.userAddDel == 2", priv2.userAddDel, 2);
73             ensure_equals("priv2.adminChg == 2", priv2.adminChg, 2);
74             ensure_equals("priv2.tariffChg == 2", priv2.tariffChg, 2);
75
76             ensure_equals("priv2.ToInt() = 0x2AAA", priv2.ToInt(), static_cast<uint16_t>(TWOS));
77
78             PRIV priv3(THREES | (i << 0x0E)); // All 3
79
80             ensure_equals("priv3.userStat == 3", priv3.userStat, 3);
81             ensure_equals("priv3.userConf == 3", priv3.userConf, 3);
82             ensure_equals("priv3.userCash == 3", priv3.userCash, 3);
83             ensure_equals("priv3.userPasswd == 3", priv3.userPasswd, 3);
84             ensure_equals("priv3.userAddDel == 3", priv3.userAddDel, 3);
85             ensure_equals("priv3.adminChg == 3", priv3.adminChg, 3);
86             ensure_equals("priv3.tariffChg == 3", priv3.tariffChg, 3);
87
88             ensure_equals("priv2.ToInt() = 0x3FFF", priv3.ToInt(), static_cast<uint16_t>(THREES));
89
90             PRIV pm1(MIX1 | (i << 0x0E)); // 0123012
91
92             ensure_equals("pm1.userStat == 0", pm1.userStat, 0);
93             ensure_equals("pm1.userConf == 1", pm1.userConf, 1);
94             ensure_equals("pm1.userCash == 2", pm1.userCash, 2);
95             ensure_equals("pm1.userPasswd == 3", pm1.userPasswd, 3);
96             ensure_equals("pm1.userAddDel == 0", pm1.userAddDel, 0);
97             ensure_equals("pm1.adminChg == 1", pm1.adminChg, 1);
98             ensure_equals("pm1.tariffChg == 2", pm1.tariffChg, 2);
99
100             ensure_equals("pm1.ToInt() = 0x24E4", pm1.ToInt(), static_cast<uint16_t>(MIX1));
101
102             PRIV pm2(MIX2 | (i << 0x0E)); // 0123012
103
104             ensure_equals("pm2.userStat == 2", pm2.userStat, 2);
105             ensure_equals("pm2.userConf == 1", pm2.userConf, 1);
106             ensure_equals("pm2.userCash == 0", pm2.userCash, 0);
107             ensure_equals("pm2.userPasswd == 3", pm2.userPasswd, 3);
108             ensure_equals("pm2.userAddDel == 2", pm2.userAddDel, 2);
109             ensure_equals("pm2.adminChg == 1", pm2.adminChg, 1);
110             ensure_equals("pm2.tariffChg == 0", pm2.tariffChg, 0);
111
112             ensure_equals("pm2.ToInt() = 0x06C6", pm2.ToInt(), static_cast<uint16_t>(MIX2));
113
114             PRIV pm3(MIX3 | (i << 0x0E)); // 3210321
115
116             ensure_equals("pm3.userStat == 3", pm3.userStat, 3);
117             ensure_equals("pm3.userConf == 2", pm3.userConf, 2);
118             ensure_equals("pm3.userCash == 1", pm3.userCash, 1);
119             ensure_equals("pm3.userPasswd == 0", pm3.userPasswd, 0);
120             ensure_equals("pm3.userAddDel == 3", pm3.userAddDel, 3);
121             ensure_equals("pm3.adminChg == 2", pm3.adminChg, 2);
122             ensure_equals("pm3.tariffChg == 1", pm3.tariffChg, 1);
123
124             ensure_equals("pm3.ToInt() = 0x1B1B", pm3.ToInt(), static_cast<uint16_t>(MIX3));
125
126         }
127
128     }
129
130     template<>
131     template<>
132     void testobject::test<3>()
133     {
134         set_test_name("Check explicit uint16_t conversions");
135
136         for (uint16_t i = 0; i < 4; ++i) {
137
138             // 'i' is extra trash in high bits
139
140             PRIV priv1;
141             priv1.FromInt(ONES | (i << 0x0E)); // All 1
142
143             ensure_equals("priv1.userStat == 1", priv1.userStat, 1);
144             ensure_equals("priv1.userConf == 1", priv1.userConf, 1);
145             ensure_equals("priv1.userCash == 1", priv1.userCash, 1);
146             ensure_equals("priv1.userPasswd == 1", priv1.userPasswd, 1);
147             ensure_equals("priv1.userAddDel == 1", priv1.userAddDel, 1);
148             ensure_equals("priv1.adminChg == 1", priv1.adminChg, 1);
149             ensure_equals("priv1.tariffChg == 1", priv1.tariffChg, 1);
150
151             ensure_equals("priv1.ToInt() == 0x1555", priv1.ToInt(), static_cast<uint16_t>(ONES));
152
153             PRIV priv2;
154             priv2.FromInt(TWOS | (i << 0x0E)); // All 2
155
156             ensure_equals("priv2.userStat == 2", priv2.userStat, 2);
157             ensure_equals("priv2.userConf == 2", priv2.userConf, 2);
158             ensure_equals("priv2.userCash == 2", priv2.userCash, 2);
159             ensure_equals("priv2.userPasswd == 2", priv2.userPasswd, 2);
160             ensure_equals("priv2.userAddDel == 2", priv2.userAddDel, 2);
161             ensure_equals("priv2.adminChg == 2", priv2.adminChg, 2);
162             ensure_equals("priv2.tariffChg == 2", priv2.tariffChg, 2);
163
164             ensure_equals("priv2.ToInt() = 0x2AAA", priv2.ToInt(), static_cast<uint16_t>(TWOS));
165
166             PRIV priv3;
167             priv3.FromInt(THREES | (i << 0x0E)); // All 3
168
169             ensure_equals("priv3.userStat == 3", priv3.userStat, 3);
170             ensure_equals("priv3.userConf == 3", priv3.userConf, 3);
171             ensure_equals("priv3.userCash == 3", priv3.userCash, 3);
172             ensure_equals("priv3.userPasswd == 3", priv3.userPasswd, 3);
173             ensure_equals("priv3.userAddDel == 3", priv3.userAddDel, 3);
174             ensure_equals("priv3.adminChg == 3", priv3.adminChg, 3);
175             ensure_equals("priv3.tariffChg == 3", priv3.tariffChg, 3);
176
177             ensure_equals("priv2.ToInt() = 0x3FFF", priv3.ToInt(), static_cast<uint16_t>(THREES));
178
179             PRIV pm1;
180             pm1.FromInt(MIX1 | (i << 0x0E)); // 0123012
181
182             ensure_equals("pm1.userStat == 0", pm1.userStat, 0);
183             ensure_equals("pm1.userConf == 1", pm1.userConf, 1);
184             ensure_equals("pm1.userCash == 2", pm1.userCash, 2);
185             ensure_equals("pm1.userPasswd == 3", pm1.userPasswd, 3);
186             ensure_equals("pm1.userAddDel == 0", pm1.userAddDel, 0);
187             ensure_equals("pm1.adminChg == 1", pm1.adminChg, 1);
188             ensure_equals("pm1.tariffChg == 2", pm1.tariffChg, 2);
189
190             ensure_equals("pm1.ToInt() = 0x24E4", pm1.ToInt(), static_cast<uint16_t>(MIX1));
191
192             PRIV pm2;
193             pm2.FromInt(MIX2 | (i << 0x0E)); // 0123012
194
195             ensure_equals("pm2.userStat == 2", pm2.userStat, 2);
196             ensure_equals("pm2.userConf == 1", pm2.userConf, 1);
197             ensure_equals("pm2.userCash == 0", pm2.userCash, 0);
198             ensure_equals("pm2.userPasswd == 3", pm2.userPasswd, 3);
199             ensure_equals("pm2.userAddDel == 2", pm2.userAddDel, 2);
200             ensure_equals("pm2.adminChg == 1", pm2.adminChg, 1);
201             ensure_equals("pm2.tariffChg == 0", pm2.tariffChg, 0);
202
203             ensure_equals("pm2.ToInt() = 0x06C6", pm2.ToInt(), static_cast<uint16_t>(MIX2));
204
205             PRIV pm3;
206             pm3.FromInt(MIX3 | (i << 0x0E)); // 3210321
207
208             ensure_equals("pm3.userStat == 3", pm3.userStat, 3);
209             ensure_equals("pm3.userConf == 2", pm3.userConf, 2);
210             ensure_equals("pm3.userCash == 1", pm3.userCash, 1);
211             ensure_equals("pm3.userPasswd == 0", pm3.userPasswd, 0);
212             ensure_equals("pm3.userAddDel == 3", pm3.userAddDel, 3);
213             ensure_equals("pm3.adminChg == 2", pm3.adminChg, 2);
214             ensure_equals("pm3.tariffChg == 1", pm3.tariffChg, 1);
215
216             ensure_equals("pm3.ToInt() = 0x1B1B", pm3.ToInt(), static_cast<uint16_t>(MIX3));
217
218         }
219
220     }
221
222 }