3 #include "stg/user_property.h"
6 #include "testsettings.h"
7 #include "testtariffs.h"
11 #include "testusers.h"
12 #include "testservices.h"
17 class TEST_STORE_LOCAL : public TEST_STORE,
24 int WriteUserChgLog(const std::string & /*login*/,
25 const std::string & /*admLogin*/,
27 const std::string & /*paramName*/,
28 const std::string & /*oldValue*/,
29 const std::string & /*newValue*/,
30 const std::string & /*message*/) const { ++entries; return 0; }
32 size_t GetEntries() const { return entries; }
35 mutable size_t entries;
38 class TEST_SETTINGS_LOCAL : public TEST_SETTINGS {
40 void addFilter(const std::string& field) { filter.push_back(field); }
42 const std::vector<std::string>& GetFilterParamsLog() const { return filter; }
45 std::vector<std::string> filter;
52 struct filter_params_log_data {
55 typedef test_group<filter_params_log_data> tg;
56 tg filter_params_log_test_group("Filter params log tests group");
58 typedef tg::object testobject;
62 void testobject::test<1>()
64 set_test_name("Check normal behaviour");
66 TEST_SETTINGS_LOCAL settings;
67 settings.addFilter("*"); // Allow everything by default.
70 TEST_STORE_LOCAL store;
73 TEST_SERVICES services;
74 USER_IMPL user(&settings, &store, &tariffs, &admin, &users, services);
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);
80 address.Set("address", &admin, "", &store, "");
81 note.Set("note", &admin, "", &store, "");
82 group.Set("group", &admin, "", &store, "");
84 ensure_equals("entries = 3", store.GetEntries(), 3);
86 note.Set("another note", &admin, "", &store, "");
88 ensure_equals("entries = 4", store.GetEntries(), 4);
90 address.Set("new address", &admin, "", &store, "");
92 ensure_equals("entries = 5", store.GetEntries(), 5);
94 group.Set("administrative group", &admin, "", &store, "");
96 ensure_equals("entries = 6", store.GetEntries(), 6);
102 void testobject::test<2>()
104 set_test_name("Check single filter entry.");
106 TEST_SETTINGS_LOCAL settings;
107 settings.addFilter("address"); // Allow everything by default.
108 TEST_TARIFFS tariffs;
110 TEST_STORE_LOCAL store;
113 TEST_SERVICES services;
114 USER_IMPL user(&settings, &store, &tariffs, &admin, &users, services);
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);
120 address.Set("address", &admin, "", &store, "");
121 note.Set("note", &admin, "", &store, "");
122 group.Set("group", &admin, "", &store, "");
124 ensure_equals("entries = 1", store.GetEntries(), 1);
126 note.Set("another note", &admin, "", &store, "");
128 ensure_equals("entries = 1", store.GetEntries(), 1);
130 address.Set("new address", &admin, "", &store, "");
132 ensure_equals("entries = 2", store.GetEntries(), 2);
134 group.Set("administrative group", &admin, "", &store, "");
136 ensure_equals("entries = 2", store.GetEntries(), 2);
141 void testobject::test<3>()
143 set_test_name("Check multiple filter entries.");
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;
150 TEST_STORE_LOCAL store;
153 TEST_SERVICES services;
154 USER_IMPL user(&settings, &store, &tariffs, &admin, &users, services);
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);
160 address.Set("address", &admin, "", &store, "");
161 note.Set("note", &admin, "", &store, "");
162 group.Set("group", &admin, "", &store, "");
164 ensure_equals("entries = 2", store.GetEntries(), 2);
166 note.Set("another note", &admin, "", &store, "");
168 ensure_equals("entries = 2", store.GetEntries(), 2);
170 address.Set("new address", &admin, "", &store, "");
172 ensure_equals("entries = 3", store.GetEntries(), 3);
174 group.Set("administrative group", &admin, "", &store, "");
176 ensure_equals("entries = 4", store.GetEntries(), 4);
181 void testobject::test<4>()
183 set_test_name("Check empty filter.");
185 TEST_SETTINGS_LOCAL settings;
186 TEST_TARIFFS tariffs;
188 TEST_STORE_LOCAL store;
191 TEST_SERVICES services;
192 USER_IMPL user(&settings, &store, &tariffs, &admin, &users, services);
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);
198 address.Set("address", &admin, "", &store, "");
199 note.Set("note", &admin, "", &store, "");
200 group.Set("group", &admin, "", &store, "");
202 ensure_equals("entries = 0", store.GetEntries(), 0);
204 note.Set("another note", &admin, "", &store, "");
206 ensure_equals("entries = 0", store.GetEntries(), 0);
208 address.Set("new address", &admin, "", &store, "");
210 ensure_equals("entries = 0", store.GetEntries(), 0);
212 group.Set("administrative group", &admin, "", &store, "");
214 ensure_equals("entries = 0", store.GetEntries(), 0);