3 #include "stg/user_property.h"
6 #include "testsettings.h"
7 #include "testtariffs.h"
11 const volatile time_t stgTime = 0;
15 struct fee_charge_rules_data {
18 typedef test_group<fee_charge_rules_data> tg;
19 tg fee_charge_rules_test_group("Fee charge rules tests group");
21 typedef tg::object testobject;
23 class TEST_SETTINGS_LOCAL : public TEST_SETTINGS {
25 TEST_SETTINGS_LOCAL(unsigned _feeChargeType)
26 : feeChargeType(_feeChargeType)
29 unsigned GetFeeChargeType() const { return feeChargeType; }
32 unsigned feeChargeType;
37 void testobject::test<1>()
39 set_test_name("Check classic rules");
41 TEST_SETTINGS_LOCAL settings(0);
45 USER_IMPL user(&settings, &store, &tariffs, &admin, NULL);
47 USER_PROPERTY<double> & cash(user.GetProperty().cash);
48 USER_PROPERTY<std::string> & tariffName(user.GetProperty().tariffName);
50 ensure_equals("user.cash == 0", user.GetProperty().cash, 0);
52 ensure_equals("user.cash == 100", user.GetProperty().cash, 100);
56 ensure_equals("user.tariffName == 'test'", user.GetProperty().tariffName.ConstData(), "test");
58 ensure_equals("user.cash == 50", user.GetProperty().cash, 50);
60 ensure_equals("user.cash == 0", user.GetProperty().cash, 0);
62 ensure_equals("user.cash == -50", user.GetProperty().cash, -50);
67 void testobject::test<2>()
69 set_test_name("Check second rules (allow fee if cash value is positive)");
71 TEST_SETTINGS_LOCAL settings(1);
75 USER_IMPL user(&settings, &store, &tariffs, &admin, NULL);
77 USER_PROPERTY<double> & cash(user.GetProperty().cash);
78 USER_PROPERTY<std::string> & tariffName(user.GetProperty().tariffName);
80 ensure_equals("user.cash == 0", user.GetProperty().cash, 0);
82 ensure_equals("user.cash == 100", user.GetProperty().cash, 100);
86 ensure_equals("user.tariffName == 'test'", user.GetProperty().tariffName.ConstData(), "test");
88 ensure_equals("user.cash == 50", user.GetProperty().cash, 50);
90 ensure_equals("user.cash == 0", user.GetProperty().cash, 0);
92 ensure_equals("user.cash == 0", user.GetProperty().cash, 0);
94 ensure_equals("user.cash == 49", user.GetProperty().cash, 49);
96 ensure_equals("user.cash == -1", user.GetProperty().cash, -1);
101 void testobject::test<3>()
103 set_test_name("Check third rules (allow fee if cash value is greater than fee)");
105 TEST_SETTINGS_LOCAL settings(2);
106 TEST_TARIFFS tariffs;
109 USER_IMPL user(&settings, &store, &tariffs, &admin, NULL);
111 USER_PROPERTY<double> & cash(user.GetProperty().cash);
112 USER_PROPERTY<std::string> & tariffName(user.GetProperty().tariffName);
114 ensure_equals("user.cash == 0", user.GetProperty().cash, 0);
116 ensure_equals("user.cash == 100", user.GetProperty().cash, 100);
120 ensure_equals("user.tariffName == 'test'", user.GetProperty().tariffName.ConstData(), "test");
121 user.ProcessDayFee();
122 ensure_equals("user.cash == 50", user.GetProperty().cash, 50);
123 user.ProcessDayFee();
124 ensure_equals("user.cash == 50", user.GetProperty().cash, 50);
126 user.ProcessDayFee();
127 ensure_equals("user.cash == 1", user.GetProperty().cash, 1);
129 ensure_equals("user.cash == 0", user.GetProperty().cash, 0);
130 user.ProcessDayFee();
131 ensure_equals("user.cash == 0", user.GetProperty().cash, 0);