]> git.stg.codes - stg.git/blob - tests/test_fee_charge_rules.cpp
Add assertions on OpenSearch result
[stg.git] / tests / test_fee_charge_rules.cpp
1 #include "tut/tut.hpp"
2
3 #include "stg/user_property.h"
4 #include "user_impl.h"
5
6 #include "testsettings.h"
7 #include "testtariffs.h"
8 #include "testadmin.h"
9 #include "teststore.h"
10
11 namespace tut
12 {
13     struct fee_charge_rules_data {
14     };
15
16     typedef test_group<fee_charge_rules_data> tg;
17     tg fee_charge_rules_test_group("Fee charge rules tests group");
18
19     typedef tg::object testobject;
20
21     class TEST_SETTINGS_LOCAL : public TEST_SETTINGS {
22         public:
23             TEST_SETTINGS_LOCAL(unsigned _feeChargeType)
24                 : feeChargeType(_feeChargeType)
25             {}
26
27             unsigned GetFeeChargeType() const { return feeChargeType; }
28
29         private:
30             unsigned feeChargeType;
31     };
32
33     template<>
34     template<>
35     void testobject::test<1>()
36     {
37         set_test_name("Check classic rules");
38
39         TEST_SETTINGS_LOCAL settings(0);
40         TEST_TARIFFS tariffs;
41         TEST_ADMIN admin;
42         TEST_STORE store;
43         USER_IMPL user(&settings, &store, &tariffs, &admin, NULL);
44
45         USER_PROPERTY<double> & cash(user.GetProperty().cash);
46         USER_PROPERTY<std::string> & tariffName(user.GetProperty().tariffName);
47
48         ensure_equals("user.cash == 0", user.GetProperty().cash, 0);
49         cash = 100;
50         ensure_equals("user.cash == 100", user.GetProperty().cash, 100);
51
52         tariffs.SetFee(50);
53         tariffName = "test";
54         ensure_equals("user.tariffName == 'test'", user.GetProperty().tariffName.ConstData(), "test");
55         user.ProcessDayFee();
56         ensure_equals("user.cash == 50", user.GetProperty().cash, 50);
57         user.ProcessDayFee();
58         ensure_equals("user.cash == 0", user.GetProperty().cash, 0);
59         user.ProcessDayFee();
60         ensure_equals("user.cash == -50", user.GetProperty().cash, -50);
61     }
62
63     template<>
64     template<>
65     void testobject::test<2>()
66     {
67         set_test_name("Check second rules (allow fee if cash value is positive)");
68
69         TEST_SETTINGS_LOCAL settings(1);
70         TEST_TARIFFS tariffs;
71         TEST_ADMIN admin;
72         TEST_STORE store;
73         USER_IMPL user(&settings, &store, &tariffs, &admin, NULL);
74
75         USER_PROPERTY<double> & cash(user.GetProperty().cash);
76         USER_PROPERTY<std::string> & tariffName(user.GetProperty().tariffName);
77
78         ensure_equals("user.cash == 0", user.GetProperty().cash, 0);
79         cash = 100;
80         ensure_equals("user.cash == 100", user.GetProperty().cash, 100);
81
82         tariffs.SetFee(50);
83         tariffName = "test";
84         ensure_equals("user.tariffName == 'test'", user.GetProperty().tariffName.ConstData(), "test");
85         user.ProcessDayFee();
86         ensure_equals("user.cash == 50", user.GetProperty().cash, 50);
87         user.ProcessDayFee();
88         ensure_equals("user.cash == 0", user.GetProperty().cash, 0);
89         user.ProcessDayFee();
90         ensure_equals("user.cash == 0", user.GetProperty().cash, 0);
91         cash = 49;
92         ensure_equals("user.cash == 49", user.GetProperty().cash, 49);
93         user.ProcessDayFee();
94         ensure_equals("user.cash == -1", user.GetProperty().cash, -1);
95     }
96
97     template<>
98     template<>
99     void testobject::test<3>()
100     {
101         set_test_name("Check third rules (allow fee if cash value is greater than fee)");
102
103         TEST_SETTINGS_LOCAL settings(2);
104         TEST_TARIFFS tariffs;
105         TEST_ADMIN admin;
106         TEST_STORE store;
107         USER_IMPL user(&settings, &store, &tariffs, &admin, NULL);
108
109         USER_PROPERTY<double> & cash(user.GetProperty().cash);
110         USER_PROPERTY<std::string> & tariffName(user.GetProperty().tariffName);
111
112         ensure_equals("user.cash == 0", user.GetProperty().cash, 0);
113         cash = 100;
114         ensure_equals("user.cash == 100", user.GetProperty().cash, 100);
115
116         tariffs.SetFee(50);
117         tariffName = "test";
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);
123         tariffs.SetFee(49);
124         user.ProcessDayFee();
125         ensure_equals("user.cash == 1", user.GetProperty().cash, 1);
126         cash = 0;
127         ensure_equals("user.cash == 0", user.GetProperty().cash, 0);
128         user.ProcessDayFee();
129         ensure_equals("user.cash == 0", user.GetProperty().cash, 0);
130     }
131 }