From: Maxim Mamontov Date: Thu, 26 May 2011 13:49:43 +0000 (+0300) Subject: Test admin and test store added, all three test cases implemented X-Git-Tag: 2.408-alpha~139 X-Git-Url: https://git.stg.codes/stg.git/commitdiff_plain/6d1a13b7d0f517c46b8456acc835bf6f5efb2b67?ds=sidebyside Test admin and test store added, all three test cases implemented --- diff --git a/tests/test_fee_charge_rules.cpp b/tests/test_fee_charge_rules.cpp index e233ae34..f8421b93 100644 --- a/tests/test_fee_charge_rules.cpp +++ b/tests/test_fee_charge_rules.cpp @@ -3,6 +3,7 @@ #include "stg/settings.h" #include "stg/user_property.h" #include "user_impl.h" +#include "tariff_impl.h" const volatile time_t stgTime = 0; @@ -50,7 +51,7 @@ namespace tut TEST_TARIFFS() {} int ReadTariffs () { return 0; } - const TARIFF * FindByName(const std::string & name) const { return NULL; } + const TARIFF * FindByName(const std::string & name) const { return &testTariff; } const TARIFF * GetNoTariff() const { return NULL; } int GetTariffsNum() const { return 0; } int Del(const std::string & name, const ADMIN * admin) { return 0; } @@ -61,8 +62,117 @@ namespace tut const std::string & GetStrError() const { return strError; } + void SetFee(double fee); + private: std::string strError; + TARIFF_IMPL testTariff; + }; + + class TEST_ADMIN : public ADMIN { + public: + TEST_ADMIN() : priv(0xffFFffFF) {} + + ADMIN & operator=(const ADMIN &) { return *this; } + ADMIN & operator=(const ADMIN_CONF &) { return *this; } + bool operator==(const ADMIN & rhs) const { return true; } + bool operator!=(const ADMIN & rhs) const { return false; } + bool operator<(const ADMIN & rhs) const { return true; } + bool operator<=(const ADMIN & rhs) const { return true; } + + const std::string & GetPassword() const { return password; } + const std::string & GetLogin() const { return login; } + PRIV const * GetPriv() const { return &priv; } + uint16_t GetPrivAsInt() const { return priv.ToInt(); } + const ADMIN_CONF & GetConf() const { return conf; } + uint32_t GetIP() const { return ip; } + std::string GetIPStr() const { return inet_ntostring(ip); } + void SetIP(uint32_t ip) { TEST_ADMIN::ip = ip; } + const std::string GetLogStr() const { return ""; } + + private: + std::string password; + std::string login; + PRIV priv; + ADMIN_CONF conf; + uint32_t ip; + }; + + class TEST_STORE : public STORE { + public: + TEST_STORE() {} + + int GetUsersList(std::vector * usersList) const { return 0; } + int AddUser(const std::string & login) const { return 0; } + int DelUser(const std::string & login) const { return 0; } + int SaveUserStat(const USER_STAT & stat, const std::string & login) const { return 0; } + int SaveUserConf(const USER_CONF & conf, const std::string & login) const { return 0; } + int RestoreUserStat(USER_STAT * stat, const std::string & login) const { return 0; } + int RestoreUserConf(USER_CONF * conf, const std::string & login) const { return 0; } + + int WriteUserChgLog(const std::string & login, + const std::string & admLogin, + uint32_t admIP, + const std::string & paramName, + const std::string & oldValue, + const std::string & newValue, + const std::string & message = "") const { return 0; } + + int WriteUserConnect(const std::string & login, uint32_t ip) const { 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 { return 0; } + + int WriteDetailedStat(const TRAFF_STAT & statTree, + time_t lastStat, + const std::string & login) const { return 0; } + + int AddMessage(STG_MSG * msg, const std::string & login) const { return 0; } + int EditMessage(const STG_MSG & msg, const std::string & login) const { return 0; } + int GetMessage(uint64_t id, STG_MSG * msg, const std::string & login) const { return 0; } + int DelMessage(uint64_t id, const std::string & login) const { return 0; } + int GetMessageHdrs(vector * hdrsList, const std::string & login) const { return 0; } + + int SaveMonthStat(const USER_STAT & stat, int month, int year, const std::string & login) const { return 0; } + + int GetAdminsList(std::vector * adminsList) const { return 0; } + int SaveAdmin(const ADMIN_CONF & ac) const { return 0; } + int RestoreAdmin(ADMIN_CONF * ac, const std::string & login) const { return 0; } + int AddAdmin(const std::string & login) const { return 0; } + int DelAdmin(const std::string & login) const { return 0; } + + int GetTariffsList(std::vector * tariffsList) const { return 0; } + int AddTariff(const std::string & name) const { return 0; } + int DelTariff(const std::string & name) const { return 0; } + int SaveTariff(const TARIFF_DATA & td, const std::string & tariffName) const { return 0; } + int RestoreTariff(TARIFF_DATA * td, const std::string & tariffName) const { return 0; } + + int GetCorpsList(std::vector * corpsList) const { return 0; } + int SaveCorp(const CORP_CONF & cc) const { return 0; } + int RestoreCorp(CORP_CONF * cc, const std::string & name) const { return 0; } + int AddCorp(const std::string & name) const { return 0; } + int DelCorp(const std::string & name) const { return 0; } + + int GetServicesList(std::vector * corpsList) const { return 0; } + int SaveService(const SERVICE_CONF & sc) const { return 0; } + int RestoreService(SERVICE_CONF * sc, const std::string & name) const { return 0; } + int AddService(const std::string & name) const { return 0; } + int DelService(const std::string & name) const { return 0; } + + void SetSettings(const MODULE_SETTINGS & s) {} + int ParseSettings() { return 0; } + const std::string & GetStrError() const { return strError; } + const std::string & GetVersion() const { return version; } + + private: + std::string strError; + std::string version; }; template<> @@ -73,12 +183,101 @@ namespace tut TEST_SETTINGS settings(0); TEST_TARIFFS tariffs; - USER_IMPL user(&settings, NULL, &tariffs, NULL, NULL); + TEST_ADMIN admin; + TEST_STORE store; + USER_IMPL user(&settings, &store, &tariffs, &admin, NULL); USER_PROPERTY & cash(user.GetProperty().cash); + USER_PROPERTY & tariffName(user.GetProperty().tariffName); ensure_equals("user.cash == 0", user.GetProperty().cash, 0); cash = 100; - ensure_equals("user.cash == 0", user.GetProperty().cash, 100); + ensure_equals("user.cash == 100", user.GetProperty().cash, 100); + + tariffs.SetFee(50); + tariffName = "test"; + ensure_equals("user.tariffName == 'test'", user.GetProperty().tariffName.ConstData(), "test"); + user.ProcessDayFee(); + ensure_equals("user.cash == 50", user.GetProperty().cash, 50); + user.ProcessDayFee(); + ensure_equals("user.cash == 0", user.GetProperty().cash, 0); + user.ProcessDayFee(); + ensure_equals("user.cash == -50", user.GetProperty().cash, -50); + } + + template<> + template<> + void testobject::test<2>() + { + set_test_name("Check second rules (allow fee if cash value is positive)"); + + TEST_SETTINGS settings(1); + TEST_TARIFFS tariffs; + TEST_ADMIN admin; + TEST_STORE store; + USER_IMPL user(&settings, &store, &tariffs, &admin, NULL); + + USER_PROPERTY & cash(user.GetProperty().cash); + USER_PROPERTY & tariffName(user.GetProperty().tariffName); + + ensure_equals("user.cash == 0", user.GetProperty().cash, 0); + cash = 100; + ensure_equals("user.cash == 100", user.GetProperty().cash, 100); + + tariffs.SetFee(50); + tariffName = "test"; + ensure_equals("user.tariffName == 'test'", user.GetProperty().tariffName.ConstData(), "test"); + user.ProcessDayFee(); + ensure_equals("user.cash == 50", user.GetProperty().cash, 50); + user.ProcessDayFee(); + ensure_equals("user.cash == 0", user.GetProperty().cash, 0); + user.ProcessDayFee(); + ensure_equals("user.cash == 0", user.GetProperty().cash, 0); + cash = 49; + ensure_equals("user.cash == 49", user.GetProperty().cash, 49); + user.ProcessDayFee(); + ensure_equals("user.cash == -1", user.GetProperty().cash, -1); + } + + template<> + template<> + void testobject::test<3>() + { + set_test_name("Check third rules (allow fee if cash value is greater than fee)"); + + TEST_SETTINGS settings(2); + TEST_TARIFFS tariffs; + TEST_ADMIN admin; + TEST_STORE store; + USER_IMPL user(&settings, &store, &tariffs, &admin, NULL); + + USER_PROPERTY & cash(user.GetProperty().cash); + USER_PROPERTY & tariffName(user.GetProperty().tariffName); + + ensure_equals("user.cash == 0", user.GetProperty().cash, 0); + cash = 100; + ensure_equals("user.cash == 100", user.GetProperty().cash, 100); + + tariffs.SetFee(50); + tariffName = "test"; + ensure_equals("user.tariffName == 'test'", user.GetProperty().tariffName.ConstData(), "test"); + user.ProcessDayFee(); + ensure_equals("user.cash == 50", user.GetProperty().cash, 50); + user.ProcessDayFee(); + ensure_equals("user.cash == 50", user.GetProperty().cash, 50); + tariffs.SetFee(49); + user.ProcessDayFee(); + ensure_equals("user.cash == 1", user.GetProperty().cash, 1); + cash = 0; + ensure_equals("user.cash == 0", user.GetProperty().cash, 0); + user.ProcessDayFee(); + ensure_equals("user.cash == 0", user.GetProperty().cash, 0); + } + + void TEST_TARIFFS::SetFee(double fee) + { + TARIFF_DATA td(testTariff.GetTariffData()); + td.tariffConf.fee = fee; + testTariff = td; } }