]> git.stg.codes - stg.git/blobdiff - tests/test_admin_conf.cpp
Move strategy into job.
[stg.git] / tests / test_admin_conf.cpp
index add65fb20f22275682ab338bd77527cc7cc74aff..0076860de67ca77e829afd55527864ed0b7852ad 100644 (file)
-#include <iostream>
-
-#include "tut/tut.hpp"
+#define BOOST_TEST_MODULE STGAdminConf
 
 #include "stg/admin_conf.h"
 
-namespace tut
-{
-    struct priv_data {
-        enum {
-            MIX2 = 0x06C6, // 2103210
-            ONES = 0x1555,
-            MIX3 = 0x1B1B, // 3210321
-            TWOS = 0x2AAA,
-            MIX1 = 0x24E4, // 0123012
-            THREES = 0x3FFF
-        };
-    };
-
-    typedef test_group<priv_data> tg;
-    tg priv_test_group("PRIV tests group");
-
-    typedef tg::object testobject;
-
-    template<>
-    template<>
-    void testobject::test<1>()
-    {
-        set_test_name("Check default constructor");
-
-        PRIV zero;
-
-        ensure("zero.userStat == 0", zero.userStat == 0);
-        ensure("zero.userConf == 0", zero.userConf == 0);
-        ensure("zero.userCash == 0", zero.userCash == 0);
-        ensure("zero.userPasswd == 0", zero.userPasswd == 0);
-        ensure("zero.userAddDel == 0", zero.userAddDel == 0);
-        ensure("zero.adminChg == 0", zero.adminChg == 0);
-        ensure("zero.tariffChg == 0", zero.tariffChg == 0);
-
-        ensure("zero.ToInt() == 0", zero.ToInt() == 0);
-    }
-
-    template<>
-    template<>
-    void testobject::test<2>()
-    {
-        set_test_name("Check uint16_t conversions");
-
-        for (uint16_t i = 0; i < 4; ++i) {
-
-            // 'i' is extra trash in high bits
-
-            PRIV priv1(ONES | (i << 0x0E)); // All 1
-
-            ensure_equals("priv1.userStat == 1", priv1.userStat, 1);
-            ensure_equals("priv1.userConf == 1", priv1.userConf, 1);
-            ensure_equals("priv1.userCash == 1", priv1.userCash, 1);
-            ensure_equals("priv1.userPasswd == 1", priv1.userPasswd, 1);
-            ensure_equals("priv1.userAddDel == 1", priv1.userAddDel, 1);
-            ensure_equals("priv1.adminChg == 1", priv1.adminChg, 1);
-            ensure_equals("priv1.tariffChg == 1", priv1.tariffChg, 1);
-
-            ensure_equals("priv1.ToInt() == 0x1555", priv1.ToInt(), static_cast<uint16_t>(ONES));
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wold-style-cast"
+#pragma GCC diagnostic ignored "-Wunused-parameter"
+#pragma GCC diagnostic ignored "-Wsign-compare"
+#pragma GCC diagnostic ignored "-Wparentheses"
+#include <boost/test/unit_test.hpp>
+#pragma GCC diagnostic pop
 
-            PRIV priv2(TWOS | (i << 0x0E)); // All 2
+#include <cstdint>
 
-            ensure_equals("priv2.userStat == 2", priv2.userStat, 2);
-            ensure_equals("priv2.userConf == 2", priv2.userConf, 2);
-            ensure_equals("priv2.userCash == 2", priv2.userCash, 2);
-            ensure_equals("priv2.userPasswd == 2", priv2.userPasswd, 2);
-            ensure_equals("priv2.userAddDel == 2", priv2.userAddDel, 2);
-            ensure_equals("priv2.adminChg == 2", priv2.adminChg, 2);
-            ensure_equals("priv2.tariffChg == 2", priv2.tariffChg, 2);
-
-            ensure_equals("priv2.ToInt() = 0x2AAA", priv2.ToInt(), static_cast<uint16_t>(TWOS));
-
-            PRIV priv3(THREES | (i << 0x0E)); // All 3
-
-            ensure_equals("priv3.userStat == 3", priv3.userStat, 3);
-            ensure_equals("priv3.userConf == 3", priv3.userConf, 3);
-            ensure_equals("priv3.userCash == 3", priv3.userCash, 3);
-            ensure_equals("priv3.userPasswd == 3", priv3.userPasswd, 3);
-            ensure_equals("priv3.userAddDel == 3", priv3.userAddDel, 3);
-            ensure_equals("priv3.adminChg == 3", priv3.adminChg, 3);
-            ensure_equals("priv3.tariffChg == 3", priv3.tariffChg, 3);
-
-            ensure_equals("priv2.ToInt() = 0x3FFF", priv3.ToInt(), static_cast<uint16_t>(THREES));
-
-            PRIV pm1(MIX1 | (i << 0x0E)); // 0123012
-
-            ensure_equals("pm1.userStat == 0", pm1.userStat, 0);
-            ensure_equals("pm1.userConf == 1", pm1.userConf, 1);
-            ensure_equals("pm1.userCash == 2", pm1.userCash, 2);
-            ensure_equals("pm1.userPasswd == 3", pm1.userPasswd, 3);
-            ensure_equals("pm1.userAddDel == 0", pm1.userAddDel, 0);
-            ensure_equals("pm1.adminChg == 1", pm1.adminChg, 1);
-            ensure_equals("pm1.tariffChg == 2", pm1.tariffChg, 2);
-
-            ensure_equals("pm1.ToInt() = 0x24E4", pm1.ToInt(), static_cast<uint16_t>(MIX1));
-
-            PRIV pm2(MIX2 | (i << 0x0E)); // 0123012
-
-            ensure_equals("pm2.userStat == 2", pm2.userStat, 2);
-            ensure_equals("pm2.userConf == 1", pm2.userConf, 1);
-            ensure_equals("pm2.userCash == 0", pm2.userCash, 0);
-            ensure_equals("pm2.userPasswd == 3", pm2.userPasswd, 3);
-            ensure_equals("pm2.userAddDel == 2", pm2.userAddDel, 2);
-            ensure_equals("pm2.adminChg == 1", pm2.adminChg, 1);
-            ensure_equals("pm2.tariffChg == 0", pm2.tariffChg, 0);
-
-            ensure_equals("pm2.ToInt() = 0x06C6", pm2.ToInt(), static_cast<uint16_t>(MIX2));
-
-            PRIV pm3(MIX3 | (i << 0x0E)); // 3210321
+namespace
+{
 
-            ensure_equals("pm3.userStat == 3", pm3.userStat, 3);
-            ensure_equals("pm3.userConf == 2", pm3.userConf, 2);
-            ensure_equals("pm3.userCash == 1", pm3.userCash, 1);
-            ensure_equals("pm3.userPasswd == 0", pm3.userPasswd, 0);
-            ensure_equals("pm3.userAddDel == 3", pm3.userAddDel, 3);
-            ensure_equals("pm3.adminChg == 2", pm3.adminChg, 2);
-            ensure_equals("pm3.tariffChg == 1", pm3.tariffChg, 1);
+constexpr uint32_t MIX2 = 0x0002C6C6; // 210321032
+constexpr uint32_t ONES = 0x00015555;
+constexpr uint32_t MIX3 = 0x00031B1B; // 321032103
+constexpr uint32_t TWOS = 0x0002AAAA;
+constexpr uint32_t MIX1 = 0x0000E4E4; // 012301230
+constexpr uint32_t THREES = 0x0003FFFF;
 
-            ensure_equals("pm3.ToInt() = 0x1B1B", pm3.ToInt(), static_cast<uint16_t>(MIX3));
+}
 
-        }
+BOOST_AUTO_TEST_SUITE(AdminConf)
 
-    }
+BOOST_AUTO_TEST_CASE(DefaultConstructor)
+{
+    STG::Priv zero;
+
+    BOOST_CHECK_EQUAL(zero.userStat, 0);
+    BOOST_CHECK_EQUAL(zero.userConf, 0);
+    BOOST_CHECK_EQUAL(zero.userCash, 0);
+    BOOST_CHECK_EQUAL(zero.userPasswd, 0);
+    BOOST_CHECK_EQUAL(zero.userAddDel, 0);
+    BOOST_CHECK_EQUAL(zero.adminChg, 0);
+    BOOST_CHECK_EQUAL(zero.tariffChg, 0);
+    BOOST_CHECK_EQUAL(zero.serviceChg, 0);
+    BOOST_CHECK_EQUAL(zero.corpChg, 0);
+
+    BOOST_CHECK_EQUAL(zero.toInt(), 0);
+}
 
-    template<>
-    template<>
-    void testobject::test<3>()
+BOOST_AUTO_TEST_CASE(UINT32Conversions)
+{
+    for (uint8_t i = 0; i < 4; ++i)
     {
-        set_test_name("Check explicit uint16_t conversions");
-
-        for (uint16_t i = 0; i < 4; ++i) {
-
-            // 'i' is extra trash in high bits
-
-            PRIV priv1;
-            priv1.FromInt(ONES | (i << 0x0E)); // All 1
-
-            ensure_equals("priv1.userStat == 1", priv1.userStat, 1);
-            ensure_equals("priv1.userConf == 1", priv1.userConf, 1);
-            ensure_equals("priv1.userCash == 1", priv1.userCash, 1);
-            ensure_equals("priv1.userPasswd == 1", priv1.userPasswd, 1);
-            ensure_equals("priv1.userAddDel == 1", priv1.userAddDel, 1);
-            ensure_equals("priv1.adminChg == 1", priv1.adminChg, 1);
-            ensure_equals("priv1.tariffChg == 1", priv1.tariffChg, 1);
-
-            ensure_equals("priv1.ToInt() == 0x1555", priv1.ToInt(), static_cast<uint16_t>(ONES));
-
-            PRIV priv2;
-            priv2.FromInt(TWOS | (i << 0x0E)); // All 2
-
-            ensure_equals("priv2.userStat == 2", priv2.userStat, 2);
-            ensure_equals("priv2.userConf == 2", priv2.userConf, 2);
-            ensure_equals("priv2.userCash == 2", priv2.userCash, 2);
-            ensure_equals("priv2.userPasswd == 2", priv2.userPasswd, 2);
-            ensure_equals("priv2.userAddDel == 2", priv2.userAddDel, 2);
-            ensure_equals("priv2.adminChg == 2", priv2.adminChg, 2);
-            ensure_equals("priv2.tariffChg == 2", priv2.tariffChg, 2);
-
-            ensure_equals("priv2.ToInt() = 0x2AAA", priv2.ToInt(), static_cast<uint16_t>(TWOS));
-
-            PRIV priv3;
-            priv3.FromInt(THREES | (i << 0x0E)); // All 3
-
-            ensure_equals("priv3.userStat == 3", priv3.userStat, 3);
-            ensure_equals("priv3.userConf == 3", priv3.userConf, 3);
-            ensure_equals("priv3.userCash == 3", priv3.userCash, 3);
-            ensure_equals("priv3.userPasswd == 3", priv3.userPasswd, 3);
-            ensure_equals("priv3.userAddDel == 3", priv3.userAddDel, 3);
-            ensure_equals("priv3.adminChg == 3", priv3.adminChg, 3);
-            ensure_equals("priv3.tariffChg == 3", priv3.tariffChg, 3);
-
-            ensure_equals("priv2.ToInt() = 0x3FFF", priv3.ToInt(), static_cast<uint16_t>(THREES));
-
-            PRIV pm1;
-            pm1.FromInt(MIX1 | (i << 0x0E)); // 0123012
-
-            ensure_equals("pm1.userStat == 0", pm1.userStat, 0);
-            ensure_equals("pm1.userConf == 1", pm1.userConf, 1);
-            ensure_equals("pm1.userCash == 2", pm1.userCash, 2);
-            ensure_equals("pm1.userPasswd == 3", pm1.userPasswd, 3);
-            ensure_equals("pm1.userAddDel == 0", pm1.userAddDel, 0);
-            ensure_equals("pm1.adminChg == 1", pm1.adminChg, 1);
-            ensure_equals("pm1.tariffChg == 2", pm1.tariffChg, 2);
-
-            ensure_equals("pm1.ToInt() = 0x24E4", pm1.ToInt(), static_cast<uint16_t>(MIX1));
-
-            PRIV pm2;
-            pm2.FromInt(MIX2 | (i << 0x0E)); // 0123012
-
-            ensure_equals("pm2.userStat == 2", pm2.userStat, 2);
-            ensure_equals("pm2.userConf == 1", pm2.userConf, 1);
-            ensure_equals("pm2.userCash == 0", pm2.userCash, 0);
-            ensure_equals("pm2.userPasswd == 3", pm2.userPasswd, 3);
-            ensure_equals("pm2.userAddDel == 2", pm2.userAddDel, 2);
-            ensure_equals("pm2.adminChg == 1", pm2.adminChg, 1);
-            ensure_equals("pm2.tariffChg == 0", pm2.tariffChg, 0);
-
-            ensure_equals("pm2.ToInt() = 0x06C6", pm2.ToInt(), static_cast<uint16_t>(MIX2));
-
-            PRIV pm3;
-            pm3.FromInt(MIX3 | (i << 0x0E)); // 3210321
-
-            ensure_equals("pm3.userStat == 3", pm3.userStat, 3);
-            ensure_equals("pm3.userConf == 2", pm3.userConf, 2);
-            ensure_equals("pm3.userCash == 1", pm3.userCash, 1);
-            ensure_equals("pm3.userPasswd == 0", pm3.userPasswd, 0);
-            ensure_equals("pm3.userAddDel == 3", pm3.userAddDel, 3);
-            ensure_equals("pm3.adminChg == 2", pm3.adminChg, 2);
-            ensure_equals("pm3.tariffChg == 1", pm3.tariffChg, 1);
-
-            ensure_equals("pm3.ToInt() = 0x1B1B", pm3.ToInt(), static_cast<uint16_t>(MIX3));
-
-        }
-
+        // 'i' is extra garbage in high bits
+
+        STG::Priv priv1(ONES | (i << 0x12)); // All 1
+
+        BOOST_CHECK_EQUAL(priv1.userStat, 1);
+        BOOST_CHECK_EQUAL(priv1.userConf, 1);
+        BOOST_CHECK_EQUAL(priv1.userCash, 1);
+        BOOST_CHECK_EQUAL(priv1.userPasswd, 1);
+        BOOST_CHECK_EQUAL(priv1.userAddDel, 1);
+        BOOST_CHECK_EQUAL(priv1.adminChg, 1);
+        BOOST_CHECK_EQUAL(priv1.tariffChg, 1);
+        BOOST_CHECK_EQUAL(priv1.serviceChg, 1);
+        BOOST_CHECK_EQUAL(priv1.corpChg, 1);
+
+        BOOST_CHECK_EQUAL(priv1.toInt(), static_cast<uint32_t>(ONES));
+
+        STG::Priv priv2(TWOS | (i << 0x12)); // All 2
+
+        BOOST_CHECK_EQUAL(priv2.userStat, 2);
+        BOOST_CHECK_EQUAL(priv2.userConf, 2);
+        BOOST_CHECK_EQUAL(priv2.userCash, 2);
+        BOOST_CHECK_EQUAL(priv2.userPasswd, 2);
+        BOOST_CHECK_EQUAL(priv2.userAddDel, 2);
+        BOOST_CHECK_EQUAL(priv2.adminChg, 2);
+        BOOST_CHECK_EQUAL(priv2.tariffChg, 2);
+        BOOST_CHECK_EQUAL(priv2.serviceChg, 2);
+        BOOST_CHECK_EQUAL(priv2.corpChg, 2);
+
+        BOOST_CHECK_EQUAL(priv2.toInt(), static_cast<uint32_t>(TWOS));
+
+        STG::Priv priv3(THREES | (i << 0x12)); // All 3
+
+        BOOST_CHECK_EQUAL(priv3.userStat, 3);
+        BOOST_CHECK_EQUAL(priv3.userConf, 3);
+        BOOST_CHECK_EQUAL(priv3.userCash, 3);
+        BOOST_CHECK_EQUAL(priv3.userPasswd, 3);
+        BOOST_CHECK_EQUAL(priv3.userAddDel, 3);
+        BOOST_CHECK_EQUAL(priv3.adminChg, 3);
+        BOOST_CHECK_EQUAL(priv3.tariffChg, 3);
+        BOOST_CHECK_EQUAL(priv3.serviceChg, 3);
+        BOOST_CHECK_EQUAL(priv3.corpChg, 3);
+
+        BOOST_CHECK_EQUAL(priv3.toInt(), static_cast<uint32_t>(THREES));
+
+        STG::Priv pm1(MIX1 | (i << 0x12)); // 012301230
+
+        BOOST_CHECK_EQUAL(pm1.userStat, 0);
+        BOOST_CHECK_EQUAL(pm1.userConf, 1);
+        BOOST_CHECK_EQUAL(pm1.userCash, 2);
+        BOOST_CHECK_EQUAL(pm1.userPasswd, 3);
+        BOOST_CHECK_EQUAL(pm1.userAddDel, 0);
+        BOOST_CHECK_EQUAL(pm1.adminChg, 1);
+        BOOST_CHECK_EQUAL(pm1.tariffChg, 2);
+        BOOST_CHECK_EQUAL(pm1.serviceChg, 3);
+        BOOST_CHECK_EQUAL(pm1.corpChg, 0);
+
+        BOOST_CHECK_EQUAL(pm1.toInt(), static_cast<uint32_t>(MIX1));
+
+        STG::Priv pm2(MIX2 | (i << 0x12)); // 210321032
+
+        BOOST_CHECK_EQUAL(pm2.userStat, 2);
+        BOOST_CHECK_EQUAL(pm2.userConf, 1);
+        BOOST_CHECK_EQUAL(pm2.userCash, 0);
+        BOOST_CHECK_EQUAL(pm2.userPasswd, 3);
+        BOOST_CHECK_EQUAL(pm2.userAddDel, 2);
+        BOOST_CHECK_EQUAL(pm2.adminChg, 1);
+        BOOST_CHECK_EQUAL(pm2.tariffChg, 0);
+        BOOST_CHECK_EQUAL(pm2.serviceChg, 3);
+        BOOST_CHECK_EQUAL(pm2.corpChg, 2);
+
+        BOOST_CHECK_EQUAL(pm2.toInt(), static_cast<uint32_t>(MIX2));
+
+        STG::Priv pm3(MIX3 | (i << 0x12)); // 321032103
+
+        BOOST_CHECK_EQUAL(pm3.userStat, 3);
+        BOOST_CHECK_EQUAL(pm3.userConf, 2);
+        BOOST_CHECK_EQUAL(pm3.userCash, 1);
+        BOOST_CHECK_EQUAL(pm3.userPasswd, 0);
+        BOOST_CHECK_EQUAL(pm3.userAddDel, 3);
+        BOOST_CHECK_EQUAL(pm3.adminChg, 2);
+        BOOST_CHECK_EQUAL(pm3.tariffChg, 1);
+        BOOST_CHECK_EQUAL(pm3.serviceChg, 0);
+        BOOST_CHECK_EQUAL(pm3.corpChg, 3);
+
+        BOOST_CHECK_EQUAL(pm3.toInt(), static_cast<uint32_t>(MIX3));
     }
-
 }
+
+BOOST_AUTO_TEST_SUITE_END()