4 #include "stg/user_property.h"
7 #include "testsettings.h"
8 #include "testtariffs.h"
10 #include "testservices.h"
14 struct fee_charge_rules_data {
17 typedef test_group<fee_charge_rules_data> tg;
18 tg fee_charge_rules_test_group("Fee charge rules tests group");
20 typedef tg::object testobject;
22 class TEST_SETTINGS_LOCAL : public TEST_SETTINGS {
24 TEST_SETTINGS_LOCAL(unsigned _feeChargeType)
25 : feeChargeType(_feeChargeType)
28 unsigned GetFeeChargeType() const { return feeChargeType; }
31 unsigned feeChargeType;
36 void testobject::test<1>()
38 set_test_name("Check classic rules");
40 TEST_SETTINGS_LOCAL settings(0);
42 STG::Admin admin(STG::Priv(0xFFFF), {}, {});
44 TEST_SERVICES services;
45 STG::UserImpl user(&settings, &store, &tariffs, &admin, NULL, services);
47 STG::UserProperty<double> & cash(user.GetProperties().cash);
48 STG::UserProperty<std::string> & tariffName(user.GetProperties().tariffName);
50 ensure_equals("user.cash == 0 (initial value)", user.GetProperties().cash, 0);
52 ensure_equals("user.cash == 100 (explicitly set)", user.GetProperties().cash, 100);
56 ensure_equals("user.tariffName == 'test' (explicitly set)", user.GetProperties().tariffName.ConstData(), "test");
58 ensure_equals("user.cash == 50 (first fee charge)", user.GetProperties().cash, 50);
60 ensure_equals("user.cash == 0 (second fee charge)", user.GetProperties().cash, 0);
62 ensure_equals("user.cash == -50 (third fee charge)", user.GetProperties().cash, -50);
64 ensure_equals("user.cash == -100 (fourth fee charge)", user.GetProperties().cash, -100);
69 void testobject::test<2>()
71 set_test_name("Check second rules (allow fee if cash value is positive)");
73 TEST_SETTINGS_LOCAL settings(1);
75 STG::Admin admin(STG::Priv(0xFFFF), {}, {});
77 TEST_SERVICES 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 ensure_equals("user.cash == 0 (initial value)", user.GetProperties().cash, 0);
85 ensure_equals("user.credit == 0 (initial value)", user.GetProperties().credit, 0);
87 ensure_equals("user.cash == 100 (explicitly set)", user.GetProperties().cash, 100);
91 ensure_equals("user.tariffName == 'test' (explicitly set)", user.GetProperties().tariffName.ConstData(), "test");
93 ensure_equals("user.cash == 50 (first fee charge)", user.GetProperties().cash, 50);
95 ensure_equals("user.cash == 0 (second fee charge)", user.GetProperties().cash, 0);
97 ensure_equals("user.cash == -50 (third fee charge)", user.GetProperties().cash, -50);
99 ensure_equals("user.cash == -50 (not charging `cause value is negative)", user.GetProperties().cash, -50);
101 ensure_equals("user.cash == 49 (explicitly set)", user.GetProperties().cash, 49);
102 user.ProcessDayFee();
103 ensure_equals("user.cash == -1 (charge to negative value)", user.GetProperties().cash, -1);
104 user.ProcessDayFee();
105 ensure_equals("user.cash == -1 (not charging `cause value is negative)", user.GetProperties().cash, -1);
107 ensure_equals("user.credit == 50 (explicitly set)", user.GetProperties().credit, 50);
108 user.ProcessDayFee();
109 ensure_equals("user.cash == -51 (charging `cause value + credit gives us a positive value)", user.GetProperties().cash, -51);
110 user.ProcessDayFee();
111 ensure_equals("user.cash == -51 (not charging `cause credit now is not enoght)", user.GetProperties().cash, -51);
116 void testobject::test<3>()
118 set_test_name("Check third rules (allow fee if cash value is greater than fee)");
120 TEST_SETTINGS_LOCAL settings(2);
121 TEST_TARIFFS tariffs;
122 STG::Admin admin(STG::Priv(0xFFFF), {}, {});
124 TEST_SERVICES services;
125 STG::UserImpl user(&settings, &store, &tariffs, &admin, NULL, services);
127 STG::UserProperty<double> & cash(user.GetProperties().cash);
128 STG::UserProperty<double> & credit(user.GetProperties().credit);
129 STG::UserProperty<std::string> & tariffName(user.GetProperties().tariffName);
131 ensure_equals("user.cash == 0 (initial value)", user.GetProperties().cash, 0);
133 ensure_equals("user.cash == 100 (explicitly set)", user.GetProperties().cash, 100);
137 ensure_equals("user.tariffName == 'test' (explicitly set)", user.GetProperties().tariffName.ConstData(), "test");
138 user.ProcessDayFee();
139 ensure_equals("user.cash == 50 (first fee charge)", user.GetProperties().cash, 50);
140 user.ProcessDayFee();
141 ensure_equals("user.cash == 0 (second fee charge)", user.GetProperties().cash, 0);
142 user.ProcessDayFee();
143 ensure_equals("user.cash == 0 (not charging `cause value is lower than fee)", user.GetProperties().cash, 0);
145 ensure_equals("user.cash == 50 (explicitly set)", user.GetProperties().cash, 50);
147 user.ProcessDayFee();
148 ensure_equals("user.cash == 50 (not charging `cause value is lower than fee)", user.GetProperties().cash, 50);
150 ensure_equals("user.cash == 0 (explicitly set)", user.GetProperties().cash, 0);
152 ensure_equals("user.credit == 51 (explicitly set)", user.GetProperties().credit, 51);
153 user.ProcessDayFee();
154 ensure_equals("user.cash == -51 (charging `cause value + credit gives us a value greater than fee)", user.GetProperties().cash, -51);
155 user.ProcessDayFee();
156 ensure_equals("user.cash == -51 (not charging `cause credit now is not enought)", user.GetProperties().cash, -51);