3 #include "stg/admin_conf.h"
9 MIX2 = 0x0002C6C6, // 210321032
11 MIX3 = 0x00031B1B, // 321032103
13 MIX1 = 0x0000E4E4, // 012301230
18 typedef test_group<priv_data> tg;
19 tg priv_test_group("PRIV tests group");
21 typedef tg::object testobject;
25 void testobject::test<1>()
27 set_test_name("Check default constructor");
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);
41 ensure("zero.ToInt() == 0", zero.ToInt() == 0);
46 void testobject::test<2>()
48 set_test_name("Check uint32_t conversions");
50 for (uint8_t i = 0; i < 4; ++i) {
52 // 'i' is extra trash in high bits
54 PRIV priv1(ONES | (i << 0x12)); // All 1
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);
66 ensure_equals("priv1.ToInt() == 0x00015555", priv1.ToInt(), static_cast<uint32_t>(ONES));
68 PRIV priv2(TWOS | (i << 0x12)); // All 2
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);
80 ensure_equals("priv2.ToInt() = 0x0002AAAA", priv2.ToInt(), static_cast<uint32_t>(TWOS));
82 PRIV priv3(THREES | (i << 0x12)); // All 3
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);
94 ensure_equals("priv3.ToInt() = 0x0003FFFF", priv3.ToInt(), static_cast<uint32_t>(THREES));
96 PRIV pm1(MIX1 | (i << 0x12)); // 012301230
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);
108 ensure_equals("pm1.ToInt() = 0xE4E4", pm1.ToInt(), static_cast<uint32_t>(MIX1));
110 PRIV pm2(MIX2 | (i << 0x12)); // 210321032
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);
122 ensure_equals("pm2.ToInt() = 0x0002C6C6", pm2.ToInt(), static_cast<uint32_t>(MIX2));
124 PRIV pm3(MIX3 | (i << 0x12)); // 321032103
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);
136 ensure_equals("pm3.ToInt() = 0x00031B1B", pm3.ToInt(), static_cast<uint32_t>(MIX3));
144 void testobject::test<3>()
146 set_test_name("Check explicit uint32_t conversions");
148 for (uint8_t i = 0; i < 4; ++i) {
150 // 'i' is extra trash in high bits
153 priv1.FromInt(ONES | (i << 0x12)); // All 1
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);
166 ensure_equals("priv1.ToInt() == 0x00015555", priv1.ToInt(), static_cast<uint32_t>(ONES));
169 priv2.FromInt(TWOS | (i << 0x12)); // All 2
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);
181 ensure_equals("priv2.ToInt() = 0x0002AAAA", priv2.ToInt(), static_cast<uint32_t>(TWOS));
184 priv3.FromInt(THREES | (i << 0x12)); // All 3
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);
196 ensure_equals("priv3.ToInt() = 0x0003FFFF", priv3.ToInt(), static_cast<uint32_t>(THREES));
199 pm1.FromInt(MIX1 | (i << 0x12)); // 012301230
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);
211 ensure_equals("pm1.ToInt() = 0xE4E4", pm1.ToInt(), static_cast<uint32_t>(MIX1));
214 pm2.FromInt(MIX2 | (i << 0x12)); // 210321032
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);
226 ensure_equals("pm2.ToInt() = 0x0002C6C6", pm2.ToInt(), static_cast<uint32_t>(MIX2));
229 pm3.FromInt(MIX3 | (i << 0x12)); // 321032103
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);
241 ensure_equals("pm3.ToInt() = 0x00031B1B", pm3.ToInt(), static_cast<uint32_t>(MIX3));