X-Git-Url: https://git.stg.codes/stg.git/blobdiff_plain/6d1a13b7d0f517c46b8456acc835bf6f5efb2b67..ce30e86822237a3523fd394943d50d010d70b701:/tests/test_fee_charge_rules.cpp?ds=inline diff --git a/tests/test_fee_charge_rules.cpp b/tests/test_fee_charge_rules.cpp index f8421b93..657a609a 100644 --- a/tests/test_fee_charge_rules.cpp +++ b/tests/test_fee_charge_rules.cpp @@ -1,9 +1,12 @@ #include "tut/tut.hpp" -#include "stg/settings.h" #include "stg/user_property.h" #include "user_impl.h" -#include "tariff_impl.h" + +#include "testsettings.h" +#include "testtariffs.h" +#include "testadmin.h" +#include "teststore.h" const volatile time_t stgTime = 0; @@ -17,171 +20,25 @@ namespace tut typedef tg::object testobject; - class TEST_SETTINGS : public SETTINGS { + class TEST_SETTINGS_LOCAL : public TEST_SETTINGS { public: - TEST_SETTINGS(unsigned _feeChargeType) - : feeChargeType(_feeChargeType) {} + TEST_SETTINGS_LOCAL(unsigned _feeChargeType) + : feeChargeType(_feeChargeType) + {} - const std::string & GetDirName(size_t) const { return dirName; } - const std::string & GetScriptsDir() const { return scriptsDir; } - unsigned GetDetailStatWritePeriod() const { return 10; } - unsigned GetStatWritePeriod() const { return 10; } - unsigned GetDayFee() const { return 0; } - bool GetFullFee() const { return false; } - unsigned GetDayResetTraff() const { return 0; } - bool GetSpreadFee() const { return false; } - bool GetFreeMbAllowInet() const { return false; } - bool GetDayFeeIsLastDay() const { return false; } - bool GetWriteFreeMbTraffCost() const { return false; } - bool GetShowFeeInCash() const { return false; } - unsigned GetMessageTimeout() const { return 0; } - unsigned GetFeeChargeType() const { return feeChargeType; } - const std::string & GetMonitorDir() const { return monitorDir; } - bool GetMonitoring() const { return false; } + unsigned GetFeeChargeType() const { return feeChargeType; } private: - std::string dirName; - std::string scriptsDir; - std::string monitorDir; unsigned feeChargeType; }; - class TEST_TARIFFS : public TARIFFS { - public: - TEST_TARIFFS() {} - - int ReadTariffs () { return 0; } - 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; } - int Add(const std::string & name, const ADMIN * admin) { return 0; } - int Chg(const TARIFF_DATA & td, const ADMIN * admin) { return 0; } - - void GetTariffsData(std::list * tdl) {} - - 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<> template<> void testobject::test<1>() { set_test_name("Check classic rules"); - TEST_SETTINGS settings(0); + TEST_SETTINGS_LOCAL settings(0); TEST_TARIFFS tariffs; TEST_ADMIN admin; TEST_STORE store; @@ -211,7 +68,7 @@ namespace tut { set_test_name("Check second rules (allow fee if cash value is positive)"); - TEST_SETTINGS settings(1); + TEST_SETTINGS_LOCAL settings(1); TEST_TARIFFS tariffs; TEST_ADMIN admin; TEST_STORE store; @@ -245,7 +102,7 @@ namespace tut { set_test_name("Check third rules (allow fee if cash value is greater than fee)"); - TEST_SETTINGS settings(2); + TEST_SETTINGS_LOCAL settings(2); TEST_TARIFFS tariffs; TEST_ADMIN admin; TEST_STORE store; @@ -273,11 +130,4 @@ namespace tut 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; - } }