]> git.stg.codes - stg.git/blob - tests/test_filter_params_log.cpp
Ticket. The time_t currentTime parameter added in
[stg.git] / tests / test_filter_params_log.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 #include "testauth.h"
11 #include "testusers.h"
12 #include "testservices.h"
13
14 namespace
15 {
16
17 class TEST_STORE_LOCAL : public TEST_STORE,
18                          private NONCOPYABLE {
19 public:
20     TEST_STORE_LOCAL()
21         : entries(0)
22     {}
23
24     int WriteUserChgLog(const std::string & /*login*/,
25                         const std::string & /*admLogin*/,
26                         uint32_t /*admIP*/,
27                         const std::string & /*paramName*/,
28                         const std::string & /*oldValue*/,
29                         const std::string & /*newValue*/,
30                         const std::string & /*message*/) const { ++entries; return 0; }
31
32     size_t GetEntries() const { return entries; }
33
34 private:
35     mutable size_t entries;
36 };
37
38 class TEST_SETTINGS_LOCAL : public TEST_SETTINGS {
39     public:
40         void addFilter(const std::string& field) { filter.push_back(field); }
41
42         const std::vector<std::string>& GetFilterParamsLog() const { return filter; }
43
44     private:
45         std::vector<std::string> filter;
46 };
47
48 }
49
50 namespace tut
51 {
52     struct filter_params_log_data {
53     };
54
55     typedef test_group<filter_params_log_data> tg;
56     tg filter_params_log_test_group("Filter params log tests group");
57
58     typedef tg::object testobject;
59
60     template<>
61     template<>
62     void testobject::test<1>()
63     {
64         set_test_name("Check normal behaviour");
65
66         TEST_SETTINGS_LOCAL settings;
67         settings.addFilter("*"); // Allow everything by default.
68         TEST_TARIFFS tariffs;
69         TEST_ADMIN admin;
70         TEST_STORE_LOCAL store;
71         TEST_AUTH auth;
72         TEST_USERS users;
73         TEST_SERVICES services;
74         USER_IMPL user(&settings, &store, &tariffs, &admin, &users, services);
75
76         USER_PROPERTY_LOGGED<std::string> & address(user.GetProperty().address);
77         USER_PROPERTY_LOGGED<std::string> & note(user.GetProperty().note);
78         USER_PROPERTY_LOGGED<std::string> & group(user.GetProperty().group);
79
80         address.Set("address", &admin, "", &store, "");
81         note.Set("note", &admin, "", &store, "");
82         group.Set("group", &admin, "", &store, "");
83
84         ensure_equals("entries = 3", store.GetEntries(), 3);
85
86         note.Set("another note", &admin, "", &store, "");
87
88         ensure_equals("entries = 4", store.GetEntries(), 4);
89
90         address.Set("new address", &admin, "", &store, "");
91
92         ensure_equals("entries = 5", store.GetEntries(), 5);
93
94         group.Set("administrative group", &admin, "", &store, "");
95
96         ensure_equals("entries = 6", store.GetEntries(), 6);
97     }
98
99
100     template<>
101     template<>
102     void testobject::test<2>()
103     {
104         set_test_name("Check single filter entry.");
105
106         TEST_SETTINGS_LOCAL settings;
107         settings.addFilter("address"); // Allow everything by default.
108         TEST_TARIFFS tariffs;
109         TEST_ADMIN admin;
110         TEST_STORE_LOCAL store;
111         TEST_AUTH auth;
112         TEST_USERS users;
113         TEST_SERVICES services;
114         USER_IMPL user(&settings, &store, &tariffs, &admin, &users, services);
115
116         USER_PROPERTY_LOGGED<std::string> & address(user.GetProperty().address);
117         USER_PROPERTY_LOGGED<std::string> & note(user.GetProperty().note);
118         USER_PROPERTY_LOGGED<std::string> & group(user.GetProperty().group);
119
120         address.Set("address", &admin, "", &store, "");
121         note.Set("note", &admin, "", &store, "");
122         group.Set("group", &admin, "", &store, "");
123
124         ensure_equals("entries = 1", store.GetEntries(), 1);
125
126         note.Set("another note", &admin, "", &store, "");
127
128         ensure_equals("entries = 1", store.GetEntries(), 1);
129
130         address.Set("new address", &admin, "", &store, "");
131
132         ensure_equals("entries = 2", store.GetEntries(), 2);
133
134         group.Set("administrative group", &admin, "", &store, "");
135
136         ensure_equals("entries = 2", store.GetEntries(), 2);
137     }
138
139     template<>
140     template<>
141     void testobject::test<3>()
142     {
143         set_test_name("Check multiple filter entries.");
144
145         TEST_SETTINGS_LOCAL settings;
146         settings.addFilter("address"); // Allow everything by default.
147         settings.addFilter("group"); // Allow everything by default.
148         TEST_TARIFFS tariffs;
149         TEST_ADMIN admin;
150         TEST_STORE_LOCAL store;
151         TEST_AUTH auth;
152         TEST_USERS users;
153         TEST_SERVICES services;
154         USER_IMPL user(&settings, &store, &tariffs, &admin, &users, services);
155
156         USER_PROPERTY_LOGGED<std::string> & address(user.GetProperty().address);
157         USER_PROPERTY_LOGGED<std::string> & note(user.GetProperty().note);
158         USER_PROPERTY_LOGGED<std::string> & group(user.GetProperty().group);
159
160         address.Set("address", &admin, "", &store, "");
161         note.Set("note", &admin, "", &store, "");
162         group.Set("group", &admin, "", &store, "");
163
164         ensure_equals("entries = 2", store.GetEntries(), 2);
165
166         note.Set("another note", &admin, "", &store, "");
167
168         ensure_equals("entries = 2", store.GetEntries(), 2);
169
170         address.Set("new address", &admin, "", &store, "");
171
172         ensure_equals("entries = 3", store.GetEntries(), 3);
173
174         group.Set("administrative group", &admin, "", &store, "");
175
176         ensure_equals("entries = 4", store.GetEntries(), 4);
177     }
178
179     template<>
180     template<>
181     void testobject::test<4>()
182     {
183         set_test_name("Check empty filter.");
184
185         TEST_SETTINGS_LOCAL settings;
186         TEST_TARIFFS tariffs;
187         TEST_ADMIN admin;
188         TEST_STORE_LOCAL store;
189         TEST_AUTH auth;
190         TEST_USERS users;
191         TEST_SERVICES services;
192         USER_IMPL user(&settings, &store, &tariffs, &admin, &users, services);
193
194         USER_PROPERTY_LOGGED<std::string> & address(user.GetProperty().address);
195         USER_PROPERTY_LOGGED<std::string> & note(user.GetProperty().note);
196         USER_PROPERTY_LOGGED<std::string> & group(user.GetProperty().group);
197
198         address.Set("address", &admin, "", &store, "");
199         note.Set("note", &admin, "", &store, "");
200         group.Set("group", &admin, "", &store, "");
201
202         ensure_equals("entries = 0", store.GetEntries(), 0);
203
204         note.Set("another note", &admin, "", &store, "");
205
206         ensure_equals("entries = 0", store.GetEntries(), 0);
207
208         address.Set("new address", &admin, "", &store, "");
209
210         ensure_equals("entries = 0", store.GetEntries(), 0);
211
212         group.Set("administrative group", &admin, "", &store, "");
213
214         ensure_equals("entries = 0", store.GetEntries(), 0);
215     }
216 }