]> git.stg.codes - stg.git/blobdiff - tests/test_disable_session_log.cpp
Add subscriptions (to replace notifiers).
[stg.git] / tests / test_disable_session_log.cpp
index 449f1f7841d6b562d6de83f36136e2ff13a7c2f6..7dac14ed79ffab45412c93d461ce801823c2466d 100644 (file)
@@ -1,4 +1,4 @@
-#include "tut/tut.hpp"
+#define BOOST_TEST_MODULE STGAdminConf
 
 #include "stg/admin.h"
 #include "stg/user_property.h"
 
 #include "stg/admin.h"
 #include "stg/user_property.h"
 #include "testusers.h"
 #include "testservices.h"
 
 #include "testusers.h"
 #include "testservices.h"
 
+#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
+
+volatile time_t stgTime = 0;
+
 namespace
 {
 
 namespace
 {
 
-class TEST_STORE_LOCAL : public TEST_STORE {
-public:
-    TEST_STORE_LOCAL()
-        : connects(0),
-          disconnects(0)
-    {}
-    int WriteUserConnect(const std::string & /*login*/, uint32_t /*ip*/) const override { ++connects; return 0; }
-
-    int WriteUserDisconnect(const std::string & /*login*/,
-                            const STG::DirTraff & /*up*/,
-                            const STG::DirTraff & /*down*/,
-                            const STG::DirTraff & /*sessionUp*/,
-                            const STG::DirTraff & /*sessionDown*/,
-                            double /*cash*/,
-                            double /*freeMb*/,
-                            const std::string & /*reason*/) const override { ++disconnects; return 0; }
-
-    size_t GetConnects() const { return connects; }
-    size_t GetDisconnects() const { return disconnects; }
-
-private:
-    mutable size_t connects;
-    mutable size_t disconnects;
-};
-
-class TEST_SETTINGS_LOCAL : public TEST_SETTINGS {
+class Store : public TestStore
+{
     public:
     public:
-        TEST_SETTINGS_LOCAL(bool _disableSessionLog)
-            : disableSessionLog(_disableSessionLog)
+        Store()
+            : m_connects(0),
+              m_disconnects(0)
         {}
         {}
+        int WriteUserConnect(const std::string& /*login*/, uint32_t /*ip*/) const override { ++m_connects; return 0; }
 
 
-        bool GetDisableSessionLog() const { return disableSessionLog; }
+        int WriteUserDisconnect(const std::string& /*login*/,
+                                const STG::DirTraff& /*up*/,
+                                const STG::DirTraff& /*down*/,
+                                const STG::DirTraff& /*sessionUp*/,
+                                const STG::DirTraff& /*sessionDown*/,
+                                double /*cash*/,
+                                double /*freeMb*/,
+                                const std::string& /*reason*/) const override { ++m_disconnects; return 0; }
+
+        size_t connects() const { return m_connects; }
+        size_t disconnects() const { return m_disconnects; }
 
     private:
 
     private:
-        bool disableSessionLog;
+        mutable size_t m_connects;
+        mutable size_t m_disconnects;
 };
 
 };
 
-}
-
-namespace tut
+class Settings : public TestSettings
 {
 {
-    struct disable_session_log_data {
-    };
-
-    typedef test_group<disable_session_log_data> tg;
-    tg disable_session_log_test_group("Disable session log tests group");
+    public:
+        Settings(bool disableSessionLog)
+            : m_disableSessionLog(disableSessionLog)
+        {}
 
 
-    typedef tg::object testobject;
+        bool GetDisableSessionLog() const { return m_disableSessionLog; }
 
 
-    template<>
-    template<>
-    void testobject::test<1>()
-    {
-        set_test_name("Check normal behaviour");
+    private:
+        bool m_disableSessionLog;
+};
 
 
-        TEST_SETTINGS_LOCAL settings(false);
-        TEST_TARIFFS tariffs;
-        STG::Admin admin(STG::Priv(0xFFFF), {}, {});
-        TEST_STORE_LOCAL store;
-        TEST_AUTH auth;
-        TEST_USERS users;
-        TEST_SERVICES services;
-        STG::UserImpl user(&settings, &store, &tariffs, &admin, &users, services);
+}
 
 
-        STG::UserProperty<STG::UserIPs> & ips(user.GetProperties().ips);
+BOOST_AUTO_TEST_SUITE(DisableSessionLog)
 
 
-        ips = STG::UserIPs::parse("*");
+BOOST_AUTO_TEST_CASE(NormalBehavior)
+{
+    Settings settings(false);
+    TestTariffs tariffs;
+    STG::Admin admin(STG::Priv(0xFFFF), {}, {});
+    Store store;
+    TestAuth auth;
+    TestUsers users;
+    TestServices services;
+    STG::UserImpl user(&settings, &store, &tariffs, &admin, &users, services);
 
 
-        ensure_equals("user.connected = false", user.GetConnected(), false);
-        ensure_equals("connects = 0", store.GetConnects(), static_cast<size_t>(0));
-        ensure_equals("disconnects = 0", store.GetDisconnects(), static_cast<size_t>(0));
+    STG::UserProperty<STG::UserIPs> & ips(user.GetProperties().ips);
 
 
-        user.Authorize(inet_strington("127.0.0.1"), 0, &auth);
-        user.Run();
+    ips = STG::UserIPs::parse("*");
 
 
-        ensure_equals("user.authorised_by = true", user.IsAuthorizedBy(&auth), true);
+    BOOST_CHECK_EQUAL(user.GetConnected(), false);
+    BOOST_CHECK_EQUAL(store.connects(), static_cast<size_t>(0));
+    BOOST_CHECK_EQUAL(store.disconnects(), static_cast<size_t>(0));
 
 
-        ensure_equals("user.connected = true", user.GetConnected(), true);
-        ensure_equals("connects = 1", store.GetConnects(), static_cast<size_t>(1));
-        ensure_equals("disconnects = 0", store.GetDisconnects(), static_cast<size_t>(0));
+    user.Authorize(inet_strington("127.0.0.1"), 0, &auth);
+    user.Run();
 
 
-        user.Unauthorize(&auth);
-        user.Run();
+    BOOST_CHECK_EQUAL(user.IsAuthorizedBy(&auth), true);
 
 
-        ensure_equals("user.authorised_by = false", user.IsAuthorizedBy(&auth), false);
+    BOOST_CHECK_EQUAL(user.GetConnected(), true);
+    BOOST_CHECK_EQUAL(store.connects(), static_cast<size_t>(1));
+    BOOST_CHECK_EQUAL(store.disconnects(), static_cast<size_t>(0));
 
 
-        ensure_equals("user.connected = false", user.GetConnected(), false);
-        ensure_equals("connects = 1", store.GetConnects(), static_cast<size_t>(1));
-        ensure_equals("disconnects = 1", store.GetDisconnects(), static_cast<size_t>(1));
-    }
+    user.Unauthorize(&auth);
+    user.Run();
 
 
+    BOOST_CHECK_EQUAL(user.IsAuthorizedBy(&auth), false);
 
 
-    template<>
-    template<>
-    void testobject::test<2>()
-    {
-        set_test_name("Check disabled session log");
+    BOOST_CHECK_EQUAL(user.GetConnected(), false);
+    BOOST_CHECK_EQUAL(store.connects(), static_cast<size_t>(1));
+    BOOST_CHECK_EQUAL(store.disconnects(), static_cast<size_t>(1));
+}
 
 
-        TEST_SETTINGS_LOCAL settings(true);
-        TEST_TARIFFS tariffs;
-        STG::Admin admin(STG::Priv(0xFFFF), {}, {});
-        TEST_STORE_LOCAL store;
-        TEST_AUTH auth;
-        TEST_USERS users;
-        TEST_SERVICES services;
-        STG::UserImpl user(&settings, &store, &tariffs, &admin, &users, services);
+BOOST_AUTO_TEST_CASE(DisabledSessionLog)
+{
+    Settings settings(true);
+    TestTariffs tariffs;
+    STG::Admin admin(STG::Priv(0xFFFF), {}, {});
+    Store store;
+    TestAuth auth;
+    TestUsers users;
+    TestServices services;
+    STG::UserImpl user(&settings, &store, &tariffs, &admin, &users, services);
 
 
-        STG::UserProperty<STG::UserIPs> & ips(user.GetProperties().ips);
+    STG::UserProperty<STG::UserIPs> & ips(user.GetProperties().ips);
 
 
-        ips = STG::UserIPs::parse("*");
+    ips = STG::UserIPs::parse("*");
 
 
-        ensure_equals("user.connected = false", user.GetConnected(), false);
-        ensure_equals("connects = 0", store.GetConnects(), static_cast<size_t>(0));
-        ensure_equals("disconnects = 0", store.GetDisconnects(), static_cast<size_t>(0));
+    BOOST_CHECK_EQUAL(user.GetConnected(), false);
+    BOOST_CHECK_EQUAL(store.connects(), static_cast<size_t>(0));
+    BOOST_CHECK_EQUAL(store.disconnects(), static_cast<size_t>(0));
 
 
-        user.Authorize(inet_strington("127.0.0.1"), 0, &auth);
-        user.Run();
+    user.Authorize(inet_strington("127.0.0.1"), 0, &auth);
+    user.Run();
 
 
-        ensure_equals("user.authorised_by = true", user.IsAuthorizedBy(&auth), true);
+    BOOST_CHECK_EQUAL(user.IsAuthorizedBy(&auth), true);
 
 
-        ensure_equals("user.connected = true", user.GetConnected(), true);
-        ensure_equals("connects = 0", store.GetConnects(), static_cast<size_t>(0));
-        ensure_equals("disconnects = 0", store.GetDisconnects(), static_cast<size_t>(0));
+    BOOST_CHECK_EQUAL(user.GetConnected(), true);
+    BOOST_CHECK_EQUAL(store.connects(), static_cast<size_t>(0));
+    BOOST_CHECK_EQUAL(store.disconnects(), static_cast<size_t>(0));
 
 
-        user.Unauthorize(&auth);
-        user.Run();
+    user.Unauthorize(&auth);
+    user.Run();
 
 
-        ensure_equals("user.authorised_by = false", user.IsAuthorizedBy(&auth), false);
+    BOOST_CHECK_EQUAL(user.IsAuthorizedBy(&auth), false);
 
 
-        ensure_equals("user.connected = false", user.GetConnected(), false);
-        ensure_equals("connects = 0", store.GetConnects(), static_cast<size_t>(0));
-        ensure_equals("disconnects = 0", store.GetDisconnects(), static_cast<size_t>(0));
-    }
+    BOOST_CHECK_EQUAL(user.GetConnected(), false);
+    BOOST_CHECK_EQUAL(store.connects(), static_cast<size_t>(0));
+    BOOST_CHECK_EQUAL(store.disconnects(), static_cast<size_t>(0));
 }
 }
+
+BOOST_AUTO_TEST_SUITE_END()