1 #define BOOST_TEST_MODULE STGFeeChargeRules
4 #include "stg/user_property.h"
7 #include "testsettings.h"
8 #include "testtariffs.h"
10 #include "testservices.h"
12 #pragma GCC diagnostic push
13 #pragma GCC diagnostic ignored "-Wold-style-cast"
14 #pragma GCC diagnostic ignored "-Wunused-parameter"
15 #pragma GCC diagnostic ignored "-Wsign-compare"
16 #pragma GCC diagnostic ignored "-Wparentheses"
17 #include <boost/test/unit_test.hpp>
18 #pragma GCC diagnostic pop
20 volatile time_t stgTime = 0;
25 class Settings : public TestSettings
28 Settings(unsigned feeChargeType)
29 : m_feeChargeType(feeChargeType)
32 unsigned GetFeeChargeType() const { return m_feeChargeType; }
35 unsigned m_feeChargeType;
40 BOOST_AUTO_TEST_SUITE(FeeChargeRules)
42 BOOST_AUTO_TEST_CASE(ClassicRules)
46 STG::Admin admin(STG::Priv(0xFFFF), {}, {});
48 TestServices services;
49 STG::UserImpl user(&settings, &store, &tariffs, &admin, NULL, services);
51 STG::UserProperty<double>& cash = user.GetProperties().cash;
52 STG::UserProperty<std::string>& tariffName = user.GetProperties().tariffName;
54 BOOST_CHECK_EQUAL(user.GetProperties().cash, 0);
56 BOOST_CHECK_EQUAL(user.GetProperties().cash, 100);
60 BOOST_CHECK_EQUAL(user.GetProperties().tariffName.ConstData(), "test");
62 BOOST_CHECK_EQUAL(user.GetProperties().cash, 50);
64 BOOST_CHECK_EQUAL(user.GetProperties().cash, 0);
66 BOOST_CHECK_EQUAL(user.GetProperties().cash, -50);
68 BOOST_CHECK_EQUAL(user.GetProperties().cash, -100);
71 BOOST_AUTO_TEST_CASE(PositiveCashRules)
75 STG::Admin admin(STG::Priv(0xFFFF), {}, {});
77 TestServices services;
78 STG::UserImpl user(&settings, &store, &tariffs, &admin, NULL, services);
80 STG::UserProperty<double> & cash(user.GetProperties().cash);
81 STG::UserProperty<double> & credit(user.GetProperties().credit);
82 STG::UserProperty<std::string> & tariffName(user.GetProperties().tariffName);
84 BOOST_CHECK_EQUAL(user.GetProperties().cash, 0);
85 BOOST_CHECK_EQUAL(user.GetProperties().credit, 0);
87 BOOST_CHECK_EQUAL(user.GetProperties().cash, 100);
91 BOOST_CHECK_EQUAL(user.GetProperties().tariffName.ConstData(), "test");
93 BOOST_CHECK_EQUAL(user.GetProperties().cash, 50);
95 BOOST_CHECK_EQUAL(user.GetProperties().cash, 0);
97 BOOST_CHECK_EQUAL(user.GetProperties().cash, -50);
99 BOOST_CHECK_EQUAL(user.GetProperties().cash, -50);
101 BOOST_CHECK_EQUAL(user.GetProperties().cash, 49);
102 user.ProcessDayFee();
103 BOOST_CHECK_EQUAL(user.GetProperties().cash, -1);
104 user.ProcessDayFee();
105 BOOST_CHECK_EQUAL(user.GetProperties().cash, -1);
107 BOOST_CHECK_EQUAL(user.GetProperties().credit, 50);
108 user.ProcessDayFee();
109 BOOST_CHECK_EQUAL(user.GetProperties().cash, -51);
110 user.ProcessDayFee();
111 BOOST_CHECK_EQUAL(user.GetProperties().cash, -51);
114 BOOST_AUTO_TEST_CASE(GreaterThanFeeRules)
116 Settings settings(2);
118 STG::Admin admin(STG::Priv(0xFFFF), {}, {});
120 TestServices services;
121 STG::UserImpl user(&settings, &store, &tariffs, &admin, NULL, services);
123 STG::UserProperty<double> & cash(user.GetProperties().cash);
124 STG::UserProperty<double> & credit(user.GetProperties().credit);
125 STG::UserProperty<std::string> & tariffName(user.GetProperties().tariffName);
127 BOOST_CHECK_EQUAL(user.GetProperties().cash, 0);
129 BOOST_CHECK_EQUAL(user.GetProperties().cash, 100);
133 BOOST_CHECK_EQUAL(user.GetProperties().tariffName.ConstData(), "test");
134 user.ProcessDayFee();
135 BOOST_CHECK_EQUAL(user.GetProperties().cash, 50);
136 user.ProcessDayFee();
137 BOOST_CHECK_EQUAL(user.GetProperties().cash, 0);
138 user.ProcessDayFee();
139 BOOST_CHECK_EQUAL(user.GetProperties().cash, 0);
141 BOOST_CHECK_EQUAL(user.GetProperties().cash, 50);
143 user.ProcessDayFee();
144 BOOST_CHECK_EQUAL(user.GetProperties().cash, 50);
146 BOOST_CHECK_EQUAL(user.GetProperties().cash, 0);
148 BOOST_CHECK_EQUAL(user.GetProperties().credit, 51);
149 user.ProcessDayFee();
150 BOOST_CHECK_EQUAL(user.GetProperties().cash, -51);
151 user.ProcessDayFee();
152 BOOST_CHECK_EQUAL(user.GetProperties().cash, -51);
155 BOOST_AUTO_TEST_SUITE_END()