3 #include "stg/user_property.h"
6 #include "testsettings.h"
7 #include "testtariffs.h"
13 struct fee_charge_rules_data {
16 typedef test_group<fee_charge_rules_data> tg;
17 tg fee_charge_rules_test_group("Fee charge rules tests group");
19 typedef tg::object testobject;
21 class TEST_SETTINGS_LOCAL : public TEST_SETTINGS {
23 TEST_SETTINGS_LOCAL(unsigned _feeChargeType)
24 : feeChargeType(_feeChargeType)
27 unsigned GetFeeChargeType() const { return feeChargeType; }
30 unsigned feeChargeType;
35 void testobject::test<1>()
37 set_test_name("Check classic rules");
39 TEST_SETTINGS_LOCAL settings(0);
43 USER_IMPL user(&settings, &store, &tariffs, &admin, NULL);
45 USER_PROPERTY<double> & cash(user.GetProperty().cash);
46 USER_PROPERTY<std::string> & tariffName(user.GetProperty().tariffName);
48 ensure_equals("user.cash == 0", user.GetProperty().cash, 0);
50 ensure_equals("user.cash == 100", user.GetProperty().cash, 100);
54 ensure_equals("user.tariffName == 'test'", user.GetProperty().tariffName.ConstData(), "test");
56 ensure_equals("user.cash == 50", user.GetProperty().cash, 50);
58 ensure_equals("user.cash == 0", user.GetProperty().cash, 0);
60 ensure_equals("user.cash == -50", user.GetProperty().cash, -50);
65 void testobject::test<2>()
67 set_test_name("Check second rules (allow fee if cash value is positive)");
69 TEST_SETTINGS_LOCAL settings(1);
73 USER_IMPL user(&settings, &store, &tariffs, &admin, NULL);
75 USER_PROPERTY<double> & cash(user.GetProperty().cash);
76 USER_PROPERTY<std::string> & tariffName(user.GetProperty().tariffName);
78 ensure_equals("user.cash == 0", user.GetProperty().cash, 0);
80 ensure_equals("user.cash == 100", user.GetProperty().cash, 100);
84 ensure_equals("user.tariffName == 'test'", user.GetProperty().tariffName.ConstData(), "test");
86 ensure_equals("user.cash == 50", user.GetProperty().cash, 50);
88 ensure_equals("user.cash == 0", user.GetProperty().cash, 0);
90 ensure_equals("user.cash == 0", user.GetProperty().cash, 0);
92 ensure_equals("user.cash == 49", user.GetProperty().cash, 49);
94 ensure_equals("user.cash == -1", user.GetProperty().cash, -1);
99 void testobject::test<3>()
101 set_test_name("Check third rules (allow fee if cash value is greater than fee)");
103 TEST_SETTINGS_LOCAL settings(2);
104 TEST_TARIFFS tariffs;
107 USER_IMPL user(&settings, &store, &tariffs, &admin, NULL);
109 USER_PROPERTY<double> & cash(user.GetProperty().cash);
110 USER_PROPERTY<std::string> & tariffName(user.GetProperty().tariffName);
112 ensure_equals("user.cash == 0", user.GetProperty().cash, 0);
114 ensure_equals("user.cash == 100", user.GetProperty().cash, 100);
118 ensure_equals("user.tariffName == 'test'", user.GetProperty().tariffName.ConstData(), "test");
119 user.ProcessDayFee();
120 ensure_equals("user.cash == 50", user.GetProperty().cash, 50);
121 user.ProcessDayFee();
122 ensure_equals("user.cash == 50", user.GetProperty().cash, 50);
124 user.ProcessDayFee();
125 ensure_equals("user.cash == 1", user.GetProperty().cash, 1);
127 ensure_equals("user.cash == 0", user.GetProperty().cash, 0);
128 user.ProcessDayFee();
129 ensure_equals("user.cash == 0", user.GetProperty().cash, 0);