1 #define BOOST_TEST_MODULE STGAdminConf
3 #include "stg/admin_conf.h"
5 #pragma GCC diagnostic push
6 #pragma GCC diagnostic ignored "-Wold-style-cast"
7 #pragma GCC diagnostic ignored "-Wunused-parameter"
8 #pragma GCC diagnostic ignored "-Wsign-compare"
9 #pragma GCC diagnostic ignored "-Wparentheses"
10 #include <boost/test/unit_test.hpp>
11 #pragma GCC diagnostic pop
18 constexpr uint32_t MIX2 = 0x0002C6C6; // 210321032
19 constexpr uint32_t ONES = 0x00015555;
20 constexpr uint32_t MIX3 = 0x00031B1B; // 321032103
21 constexpr uint32_t TWOS = 0x0002AAAA;
22 constexpr uint32_t MIX1 = 0x0000E4E4; // 012301230
23 constexpr uint32_t THREES = 0x0003FFFF;
27 BOOST_AUTO_TEST_SUITE(AdminConf)
29 BOOST_AUTO_TEST_CASE(DefaultConstructor)
33 BOOST_CHECK_EQUAL(zero.userStat, 0);
34 BOOST_CHECK_EQUAL(zero.userConf, 0);
35 BOOST_CHECK_EQUAL(zero.userCash, 0);
36 BOOST_CHECK_EQUAL(zero.userPasswd, 0);
37 BOOST_CHECK_EQUAL(zero.userAddDel, 0);
38 BOOST_CHECK_EQUAL(zero.adminChg, 0);
39 BOOST_CHECK_EQUAL(zero.tariffChg, 0);
40 BOOST_CHECK_EQUAL(zero.serviceChg, 0);
41 BOOST_CHECK_EQUAL(zero.corpChg, 0);
43 BOOST_CHECK_EQUAL(zero.toInt(), 0);
46 BOOST_AUTO_TEST_CASE(UINT32Conversions)
48 for (uint8_t i = 0; i < 4; ++i)
50 // 'i' is extra garbage in high bits
52 STG::Priv priv1(ONES | (i << 0x12)); // All 1
54 BOOST_CHECK_EQUAL(priv1.userStat, 1);
55 BOOST_CHECK_EQUAL(priv1.userConf, 1);
56 BOOST_CHECK_EQUAL(priv1.userCash, 1);
57 BOOST_CHECK_EQUAL(priv1.userPasswd, 1);
58 BOOST_CHECK_EQUAL(priv1.userAddDel, 1);
59 BOOST_CHECK_EQUAL(priv1.adminChg, 1);
60 BOOST_CHECK_EQUAL(priv1.tariffChg, 1);
61 BOOST_CHECK_EQUAL(priv1.serviceChg, 1);
62 BOOST_CHECK_EQUAL(priv1.corpChg, 1);
64 BOOST_CHECK_EQUAL(priv1.toInt(), static_cast<uint32_t>(ONES));
66 STG::Priv priv2(TWOS | (i << 0x12)); // All 2
68 BOOST_CHECK_EQUAL(priv2.userStat, 2);
69 BOOST_CHECK_EQUAL(priv2.userConf, 2);
70 BOOST_CHECK_EQUAL(priv2.userCash, 2);
71 BOOST_CHECK_EQUAL(priv2.userPasswd, 2);
72 BOOST_CHECK_EQUAL(priv2.userAddDel, 2);
73 BOOST_CHECK_EQUAL(priv2.adminChg, 2);
74 BOOST_CHECK_EQUAL(priv2.tariffChg, 2);
75 BOOST_CHECK_EQUAL(priv2.serviceChg, 2);
76 BOOST_CHECK_EQUAL(priv2.corpChg, 2);
78 BOOST_CHECK_EQUAL(priv2.toInt(), static_cast<uint32_t>(TWOS));
80 STG::Priv priv3(THREES | (i << 0x12)); // All 3
82 BOOST_CHECK_EQUAL(priv3.userStat, 3);
83 BOOST_CHECK_EQUAL(priv3.userConf, 3);
84 BOOST_CHECK_EQUAL(priv3.userCash, 3);
85 BOOST_CHECK_EQUAL(priv3.userPasswd, 3);
86 BOOST_CHECK_EQUAL(priv3.userAddDel, 3);
87 BOOST_CHECK_EQUAL(priv3.adminChg, 3);
88 BOOST_CHECK_EQUAL(priv3.tariffChg, 3);
89 BOOST_CHECK_EQUAL(priv3.serviceChg, 3);
90 BOOST_CHECK_EQUAL(priv3.corpChg, 3);
92 BOOST_CHECK_EQUAL(priv3.toInt(), static_cast<uint32_t>(THREES));
94 STG::Priv pm1(MIX1 | (i << 0x12)); // 012301230
96 BOOST_CHECK_EQUAL(pm1.userStat, 0);
97 BOOST_CHECK_EQUAL(pm1.userConf, 1);
98 BOOST_CHECK_EQUAL(pm1.userCash, 2);
99 BOOST_CHECK_EQUAL(pm1.userPasswd, 3);
100 BOOST_CHECK_EQUAL(pm1.userAddDel, 0);
101 BOOST_CHECK_EQUAL(pm1.adminChg, 1);
102 BOOST_CHECK_EQUAL(pm1.tariffChg, 2);
103 BOOST_CHECK_EQUAL(pm1.serviceChg, 3);
104 BOOST_CHECK_EQUAL(pm1.corpChg, 0);
106 BOOST_CHECK_EQUAL(pm1.toInt(), static_cast<uint32_t>(MIX1));
108 STG::Priv pm2(MIX2 | (i << 0x12)); // 210321032
110 BOOST_CHECK_EQUAL(pm2.userStat, 2);
111 BOOST_CHECK_EQUAL(pm2.userConf, 1);
112 BOOST_CHECK_EQUAL(pm2.userCash, 0);
113 BOOST_CHECK_EQUAL(pm2.userPasswd, 3);
114 BOOST_CHECK_EQUAL(pm2.userAddDel, 2);
115 BOOST_CHECK_EQUAL(pm2.adminChg, 1);
116 BOOST_CHECK_EQUAL(pm2.tariffChg, 0);
117 BOOST_CHECK_EQUAL(pm2.serviceChg, 3);
118 BOOST_CHECK_EQUAL(pm2.corpChg, 2);
120 BOOST_CHECK_EQUAL(pm2.toInt(), static_cast<uint32_t>(MIX2));
122 STG::Priv pm3(MIX3 | (i << 0x12)); // 321032103
124 BOOST_CHECK_EQUAL(pm3.userStat, 3);
125 BOOST_CHECK_EQUAL(pm3.userConf, 2);
126 BOOST_CHECK_EQUAL(pm3.userCash, 1);
127 BOOST_CHECK_EQUAL(pm3.userPasswd, 0);
128 BOOST_CHECK_EQUAL(pm3.userAddDel, 3);
129 BOOST_CHECK_EQUAL(pm3.adminChg, 2);
130 BOOST_CHECK_EQUAL(pm3.tariffChg, 1);
131 BOOST_CHECK_EQUAL(pm3.serviceChg, 0);
132 BOOST_CHECK_EQUAL(pm3.corpChg, 3);
134 BOOST_CHECK_EQUAL(pm3.toInt(), static_cast<uint32_t>(MIX3));
138 BOOST_AUTO_TEST_SUITE_END()