]> git.stg.codes - stg.git/blob - tests/test_admin_conf.cpp
Fix the STG-MIB
[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 = 0x06C6, // 2103210
10             ONES = 0x1555,
11             MIX3 = 0x1B1B, // 3210321
12             TWOS = 0x2AAA,
13             MIX1 = 0x24E4, // 0123012
14             THREES = 0x3FFF
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
39         ensure("zero.ToInt() == 0", zero.ToInt() == 0);
40     }
41
42     template<>
43     template<>
44     void testobject::test<2>()
45     {
46         set_test_name("Check uint16_t conversions");
47
48         for (uint16_t i = 0; i < 4; ++i) {
49
50             // 'i' is extra trash in high bits
51
52             PRIV priv1(ONES | (i << 0x0E)); // All 1
53
54             ensure_equals("priv1.userStat == 1", priv1.userStat, 1);
55             ensure_equals("priv1.userConf == 1", priv1.userConf, 1);
56             ensure_equals("priv1.userCash == 1", priv1.userCash, 1);
57             ensure_equals("priv1.userPasswd == 1", priv1.userPasswd, 1);
58             ensure_equals("priv1.userAddDel == 1", priv1.userAddDel, 1);
59             ensure_equals("priv1.adminChg == 1", priv1.adminChg, 1);
60             ensure_equals("priv1.tariffChg == 1", priv1.tariffChg, 1);
61
62             ensure_equals("priv1.ToInt() == 0x1555", priv1.ToInt(), static_cast<uint16_t>(ONES));
63
64             PRIV priv2(TWOS | (i << 0x0E)); // All 2
65
66             ensure_equals("priv2.userStat == 2", priv2.userStat, 2);
67             ensure_equals("priv2.userConf == 2", priv2.userConf, 2);
68             ensure_equals("priv2.userCash == 2", priv2.userCash, 2);
69             ensure_equals("priv2.userPasswd == 2", priv2.userPasswd, 2);
70             ensure_equals("priv2.userAddDel == 2", priv2.userAddDel, 2);
71             ensure_equals("priv2.adminChg == 2", priv2.adminChg, 2);
72             ensure_equals("priv2.tariffChg == 2", priv2.tariffChg, 2);
73
74             ensure_equals("priv2.ToInt() = 0x2AAA", priv2.ToInt(), static_cast<uint16_t>(TWOS));
75
76             PRIV priv3(THREES | (i << 0x0E)); // All 3
77
78             ensure_equals("priv3.userStat == 3", priv3.userStat, 3);
79             ensure_equals("priv3.userConf == 3", priv3.userConf, 3);
80             ensure_equals("priv3.userCash == 3", priv3.userCash, 3);
81             ensure_equals("priv3.userPasswd == 3", priv3.userPasswd, 3);
82             ensure_equals("priv3.userAddDel == 3", priv3.userAddDel, 3);
83             ensure_equals("priv3.adminChg == 3", priv3.adminChg, 3);
84             ensure_equals("priv3.tariffChg == 3", priv3.tariffChg, 3);
85
86             ensure_equals("priv2.ToInt() = 0x3FFF", priv3.ToInt(), static_cast<uint16_t>(THREES));
87
88             PRIV pm1(MIX1 | (i << 0x0E)); // 0123012
89
90             ensure_equals("pm1.userStat == 0", pm1.userStat, 0);
91             ensure_equals("pm1.userConf == 1", pm1.userConf, 1);
92             ensure_equals("pm1.userCash == 2", pm1.userCash, 2);
93             ensure_equals("pm1.userPasswd == 3", pm1.userPasswd, 3);
94             ensure_equals("pm1.userAddDel == 0", pm1.userAddDel, 0);
95             ensure_equals("pm1.adminChg == 1", pm1.adminChg, 1);
96             ensure_equals("pm1.tariffChg == 2", pm1.tariffChg, 2);
97
98             ensure_equals("pm1.ToInt() = 0x24E4", pm1.ToInt(), static_cast<uint16_t>(MIX1));
99
100             PRIV pm2(MIX2 | (i << 0x0E)); // 0123012
101
102             ensure_equals("pm2.userStat == 2", pm2.userStat, 2);
103             ensure_equals("pm2.userConf == 1", pm2.userConf, 1);
104             ensure_equals("pm2.userCash == 0", pm2.userCash, 0);
105             ensure_equals("pm2.userPasswd == 3", pm2.userPasswd, 3);
106             ensure_equals("pm2.userAddDel == 2", pm2.userAddDel, 2);
107             ensure_equals("pm2.adminChg == 1", pm2.adminChg, 1);
108             ensure_equals("pm2.tariffChg == 0", pm2.tariffChg, 0);
109
110             ensure_equals("pm2.ToInt() = 0x06C6", pm2.ToInt(), static_cast<uint16_t>(MIX2));
111
112             PRIV pm3(MIX3 | (i << 0x0E)); // 3210321
113
114             ensure_equals("pm3.userStat == 3", pm3.userStat, 3);
115             ensure_equals("pm3.userConf == 2", pm3.userConf, 2);
116             ensure_equals("pm3.userCash == 1", pm3.userCash, 1);
117             ensure_equals("pm3.userPasswd == 0", pm3.userPasswd, 0);
118             ensure_equals("pm3.userAddDel == 3", pm3.userAddDel, 3);
119             ensure_equals("pm3.adminChg == 2", pm3.adminChg, 2);
120             ensure_equals("pm3.tariffChg == 1", pm3.tariffChg, 1);
121
122             ensure_equals("pm3.ToInt() = 0x1B1B", pm3.ToInt(), static_cast<uint16_t>(MIX3));
123
124         }
125
126     }
127
128     template<>
129     template<>
130     void testobject::test<3>()
131     {
132         set_test_name("Check explicit uint16_t conversions");
133
134         for (uint16_t i = 0; i < 4; ++i) {
135
136             // 'i' is extra trash in high bits
137
138             PRIV priv1;
139             priv1.FromInt(ONES | (i << 0x0E)); // All 1
140
141             ensure_equals("priv1.userStat == 1", priv1.userStat, 1);
142             ensure_equals("priv1.userConf == 1", priv1.userConf, 1);
143             ensure_equals("priv1.userCash == 1", priv1.userCash, 1);
144             ensure_equals("priv1.userPasswd == 1", priv1.userPasswd, 1);
145             ensure_equals("priv1.userAddDel == 1", priv1.userAddDel, 1);
146             ensure_equals("priv1.adminChg == 1", priv1.adminChg, 1);
147             ensure_equals("priv1.tariffChg == 1", priv1.tariffChg, 1);
148
149             ensure_equals("priv1.ToInt() == 0x1555", priv1.ToInt(), static_cast<uint16_t>(ONES));
150
151             PRIV priv2;
152             priv2.FromInt(TWOS | (i << 0x0E)); // All 2
153
154             ensure_equals("priv2.userStat == 2", priv2.userStat, 2);
155             ensure_equals("priv2.userConf == 2", priv2.userConf, 2);
156             ensure_equals("priv2.userCash == 2", priv2.userCash, 2);
157             ensure_equals("priv2.userPasswd == 2", priv2.userPasswd, 2);
158             ensure_equals("priv2.userAddDel == 2", priv2.userAddDel, 2);
159             ensure_equals("priv2.adminChg == 2", priv2.adminChg, 2);
160             ensure_equals("priv2.tariffChg == 2", priv2.tariffChg, 2);
161
162             ensure_equals("priv2.ToInt() = 0x2AAA", priv2.ToInt(), static_cast<uint16_t>(TWOS));
163
164             PRIV priv3;
165             priv3.FromInt(THREES | (i << 0x0E)); // All 3
166
167             ensure_equals("priv3.userStat == 3", priv3.userStat, 3);
168             ensure_equals("priv3.userConf == 3", priv3.userConf, 3);
169             ensure_equals("priv3.userCash == 3", priv3.userCash, 3);
170             ensure_equals("priv3.userPasswd == 3", priv3.userPasswd, 3);
171             ensure_equals("priv3.userAddDel == 3", priv3.userAddDel, 3);
172             ensure_equals("priv3.adminChg == 3", priv3.adminChg, 3);
173             ensure_equals("priv3.tariffChg == 3", priv3.tariffChg, 3);
174
175             ensure_equals("priv2.ToInt() = 0x3FFF", priv3.ToInt(), static_cast<uint16_t>(THREES));
176
177             PRIV pm1;
178             pm1.FromInt(MIX1 | (i << 0x0E)); // 0123012
179
180             ensure_equals("pm1.userStat == 0", pm1.userStat, 0);
181             ensure_equals("pm1.userConf == 1", pm1.userConf, 1);
182             ensure_equals("pm1.userCash == 2", pm1.userCash, 2);
183             ensure_equals("pm1.userPasswd == 3", pm1.userPasswd, 3);
184             ensure_equals("pm1.userAddDel == 0", pm1.userAddDel, 0);
185             ensure_equals("pm1.adminChg == 1", pm1.adminChg, 1);
186             ensure_equals("pm1.tariffChg == 2", pm1.tariffChg, 2);
187
188             ensure_equals("pm1.ToInt() = 0x24E4", pm1.ToInt(), static_cast<uint16_t>(MIX1));
189
190             PRIV pm2;
191             pm2.FromInt(MIX2 | (i << 0x0E)); // 0123012
192
193             ensure_equals("pm2.userStat == 2", pm2.userStat, 2);
194             ensure_equals("pm2.userConf == 1", pm2.userConf, 1);
195             ensure_equals("pm2.userCash == 0", pm2.userCash, 0);
196             ensure_equals("pm2.userPasswd == 3", pm2.userPasswd, 3);
197             ensure_equals("pm2.userAddDel == 2", pm2.userAddDel, 2);
198             ensure_equals("pm2.adminChg == 1", pm2.adminChg, 1);
199             ensure_equals("pm2.tariffChg == 0", pm2.tariffChg, 0);
200
201             ensure_equals("pm2.ToInt() = 0x06C6", pm2.ToInt(), static_cast<uint16_t>(MIX2));
202
203             PRIV pm3;
204             pm3.FromInt(MIX3 | (i << 0x0E)); // 3210321
205
206             ensure_equals("pm3.userStat == 3", pm3.userStat, 3);
207             ensure_equals("pm3.userConf == 2", pm3.userConf, 2);
208             ensure_equals("pm3.userCash == 1", pm3.userCash, 1);
209             ensure_equals("pm3.userPasswd == 0", pm3.userPasswd, 0);
210             ensure_equals("pm3.userAddDel == 3", pm3.userAddDel, 3);
211             ensure_equals("pm3.adminChg == 2", pm3.adminChg, 2);
212             ensure_equals("pm3.tariffChg == 1", pm3.tariffChg, 1);
213
214             ensure_equals("pm3.ToInt() = 0x1B1B", pm3.ToInt(), static_cast<uint16_t>(MIX3));
215
216         }
217
218     }
219
220 }