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 STG::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 STG::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 STG::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 STG::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 STG::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 STG::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
152 STG::Priv priv1(ONES | (i << 0x12)); // All 1
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);
165 ensure_equals("priv1.toInt() == 0x00015555", priv1.toInt(), static_cast<uint32_t>(ONES));
167 STG::Priv priv2(TWOS | (i << 0x12)); // All 2
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);
179 ensure_equals("priv2.toInt() = 0x0002AAAA", priv2.toInt(), static_cast<uint32_t>(TWOS));
181 STG::Priv priv3(THREES | (i << 0x12)); // All 3
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);
193 ensure_equals("priv3.toInt() = 0x0003FFFF", priv3.toInt(), static_cast<uint32_t>(THREES));
195 STG::Priv pm1(MIX1 | (i << 0x12)); // 012301230
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);
207 ensure_equals("pm1.toInt() = 0xE4E4", pm1.toInt(), static_cast<uint32_t>(MIX1));
209 STG::Priv pm2(MIX2 | (i << 0x12)); // 210321032
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);
221 ensure_equals("pm2.toInt() = 0x0002C6C6", pm2.toInt(), static_cast<uint32_t>(MIX2));
223 STG::Priv pm3(MIX3 | (i << 0x12)); // 321032103
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);
235 ensure_equals("pm3.toInt() = 0x00031B1B", pm3.toInt(), static_cast<uint32_t>(MIX3));