4 #include "stg/user_property.h"
7 #include "testsettings.h"
8 #include "testtariffs.h"
11 #include "testusers.h"
12 #include "testservices.h"
17 class TEST_STORE_LOCAL : public TEST_STORE {
23 int WriteUserChgLog(const std::string & /*login*/,
24 const std::string & /*admLogin*/,
26 const std::string & /*paramName*/,
27 const std::string & /*oldValue*/,
28 const std::string & /*newValue*/,
29 const std::string & /*message*/) const override { ++entries; return 0; }
31 size_t GetEntries() const { return entries; }
34 mutable size_t entries;
37 class TEST_SETTINGS_LOCAL : public TEST_SETTINGS {
39 void addFilter(const std::string& field) { filter.push_back(field); }
41 const std::vector<std::string>& GetFilterParamsLog() const { return filter; }
44 std::vector<std::string> filter;
51 struct filter_params_log_data {
54 typedef test_group<filter_params_log_data> tg;
55 tg filter_params_log_test_group("Filter params log tests group");
57 typedef tg::object testobject;
61 void testobject::test<1>()
63 set_test_name("Check normal behaviour");
65 TEST_SETTINGS_LOCAL settings;
66 settings.addFilter("*"); // Allow everything by default.
68 tariffs.ReadTariffs();
69 STG::Admin admin(STG::Priv(0xFFFF), {}, {});
70 TEST_STORE_LOCAL store;
73 TEST_SERVICES services;
74 STG::UserImpl user(&settings, &store, &tariffs, &admin, &users, services);
76 auto & address = user.GetProperties().address;
77 auto & note = user.GetProperties().note;
78 auto & group = user.GetProperties().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;
109 STG::Admin admin(STG::Priv(0xFFFF), {}, {});
110 TEST_STORE_LOCAL store;
113 TEST_SERVICES services;
114 STG::UserImpl user(&settings, &store, &tariffs, &admin, &users, services);
116 auto & address = user.GetProperties().address;
117 auto & note = user.GetProperties().note;
118 auto & group = user.GetProperties().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;
149 STG::Admin admin(STG::Priv(0xFFFF), {}, {});
150 TEST_STORE_LOCAL store;
153 TEST_SERVICES services;
154 STG::UserImpl user(&settings, &store, &tariffs, &admin, &users, services);
156 auto & address = user.GetProperties().address;
157 auto & note = user.GetProperties().note;
158 auto & group = user.GetProperties().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;
187 STG::Admin admin(STG::Priv(0xFFFF), {}, {});
188 TEST_STORE_LOCAL store;
191 TEST_SERVICES services;
192 STG::UserImpl user(&settings, &store, &tariffs, &admin, &users, services);
194 auto & address = user.GetProperties().address;
195 auto & note = user.GetProperties().note;
196 auto & group = user.GetProperties().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);