X-Git-Url: https://git.stg.codes/stg.git/blobdiff_plain/d1c864e3feaf4295d366e2ef497495738ce15337..2196a3a0cdc5384c082febb7f4aa5994cc7d80db:/tests/test_disable_session_log.cpp diff --git a/tests/test_disable_session_log.cpp b/tests/test_disable_session_log.cpp index 75e81568..7dac14ed 100644 --- a/tests/test_disable_session_log.cpp +++ b/tests/test_disable_session_log.cpp @@ -1,152 +1,146 @@ -#include "tut/tut.hpp" +#define BOOST_TEST_MODULE STGAdminConf +#include "stg/admin.h" #include "stg/user_property.h" #include "user_impl.h" #include "testsettings.h" #include "testtariffs.h" -#include "testadmin.h" #include "teststore.h" #include "testauth.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 +#pragma GCC diagnostic pop + +volatile time_t stgTime = 0; + namespace { -class TEST_STORE_LOCAL : public TEST_STORE, - private NONCOPYABLE { -public: - TEST_STORE_LOCAL() - : connects(0), - disconnects(0) - {} - int WriteUserConnect(const std::string & /*login*/, uint32_t /*ip*/) const { ++connects; return 0; } - - int WriteUserDisconnect(const std::string & /*login*/, - const DIR_TRAFF & /*up*/, - const DIR_TRAFF & /*down*/, - const DIR_TRAFF & /*sessionUp*/, - const DIR_TRAFF & /*sessionDown*/, - double /*cash*/, - double /*freeMb*/, - const std::string & /*reason*/) const { ++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) - : TEST_SETTINGS(), - 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; - TEST_ADMIN admin; - TEST_STORE_LOCAL store; - TEST_AUTH auth; - TEST_USERS users; - TEST_SERVICES services; - USER_IMPL user(&settings, &store, &tariffs, &admin, &users, services); +} - USER_PROPERTY & ips(user.GetProperty().ips); +BOOST_AUTO_TEST_SUITE(DisableSessionLog) - ips = StrToIPS("*"); +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; - TEST_ADMIN admin; - TEST_STORE_LOCAL store; - TEST_AUTH auth; - TEST_USERS users; - TEST_SERVICES services; - USER_IMPL 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); - USER_PROPERTY & ips(user.GetProperty().ips); + STG::UserProperty & ips(user.GetProperties().ips); - ips = StrToIPS("*"); + 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()