X-Git-Url: https://git.stg.codes/stg.git/blobdiff_plain/20d4dd0571e75d254444acf755a01b48a691c7c2..bc6cac0e474dfe2feb4983aef98f99e23a98ffc4:/tests/test_disable_session_log.cpp diff --git a/tests/test_disable_session_log.cpp b/tests/test_disable_session_log.cpp index 449f1f78..7dac14ed 100644 --- a/tests/test_disable_session_log.cpp +++ b/tests/test_disable_session_log.cpp @@ -1,4 +1,4 @@ -#include "tut/tut.hpp" +#define BOOST_TEST_MODULE STGAdminConf #include "stg/admin.h" #include "stg/user_property.h" @@ -11,140 +11,136 @@ #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 +#pragma GCC diagnostic pop + +volatile time_t stgTime = 0; + 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: - 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: - 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 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 & 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(0)); - ensure_equals("disconnects = 0", store.GetDisconnects(), static_cast(0)); + STG::UserProperty & 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(0)); + BOOST_CHECK_EQUAL(store.disconnects(), static_cast(0)); - ensure_equals("user.connected = true", user.GetConnected(), true); - ensure_equals("connects = 1", store.GetConnects(), static_cast(1)); - ensure_equals("disconnects = 0", store.GetDisconnects(), static_cast(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(1)); + BOOST_CHECK_EQUAL(store.disconnects(), static_cast(0)); - ensure_equals("user.connected = false", user.GetConnected(), false); - ensure_equals("connects = 1", store.GetConnects(), static_cast(1)); - ensure_equals("disconnects = 1", store.GetDisconnects(), static_cast(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(1)); + BOOST_CHECK_EQUAL(store.disconnects(), static_cast(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 & ips(user.GetProperties().ips); + STG::UserProperty & 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(0)); - ensure_equals("disconnects = 0", store.GetDisconnects(), static_cast(0)); + BOOST_CHECK_EQUAL(user.GetConnected(), false); + BOOST_CHECK_EQUAL(store.connects(), static_cast(0)); + BOOST_CHECK_EQUAL(store.disconnects(), static_cast(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(0)); - ensure_equals("disconnects = 0", store.GetDisconnects(), static_cast(0)); + BOOST_CHECK_EQUAL(user.GetConnected(), true); + BOOST_CHECK_EQUAL(store.connects(), static_cast(0)); + BOOST_CHECK_EQUAL(store.disconnects(), static_cast(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(0)); - ensure_equals("disconnects = 0", store.GetDisconnects(), static_cast(0)); - } + BOOST_CHECK_EQUAL(user.GetConnected(), false); + BOOST_CHECK_EQUAL(store.connects(), static_cast(0)); + BOOST_CHECK_EQUAL(store.disconnects(), static_cast(0)); } + +BOOST_AUTO_TEST_SUITE_END()