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);
94 void testobject::test<2>()
96 set_test_name("Check single filter entry.");
98 TEST_SETTINGS_LOCAL settings;
99 settings.addFilter("address"); // Allow everything by default.
100 TEST_TARIFFS tariffs;
102 TEST_STORE_LOCAL store;
105 TEST_SERVICES services;
106 USER_IMPL user(&settings, &store, &tariffs, &admin, &users, services);
108 USER_PROPERTY_LOGGED<std::string> & address(user.GetProperty().address);
109 USER_PROPERTY_LOGGED<std::string> & note(user.GetProperty().note);
110 USER_PROPERTY_LOGGED<std::string> & group(user.GetProperty().group);
112 address.Set("address", &admin, "", &store, "");
113 note.Set("note", &admin, "", &store, "");
114 group.Set("group", &admin, "", &store, "");
116 ensure_equals("entries = 1", store.GetEntries(), 1);
118 note.Set("another note", &admin, "", &store, "");
120 ensure_equals("entries = 1", store.GetEntries(), 1);
122 address.Set("new address", &admin, "", &store, "");
124 ensure_equals("entries = 2", store.GetEntries(), 2);
129 void testobject::test<3>()
131 set_test_name("Check multiple filter entries.");
133 TEST_SETTINGS_LOCAL settings;
134 settings.addFilter("address"); // Allow everything by default.
135 settings.addFilter("group"); // Allow everything by default.
136 TEST_TARIFFS tariffs;
138 TEST_STORE_LOCAL store;
141 TEST_SERVICES services;
142 USER_IMPL user(&settings, &store, &tariffs, &admin, &users, services);
144 USER_PROPERTY_LOGGED<std::string> & address(user.GetProperty().address);
145 USER_PROPERTY_LOGGED<std::string> & note(user.GetProperty().note);
146 USER_PROPERTY_LOGGED<std::string> & group(user.GetProperty().group);
148 address.Set("address", &admin, "", &store, "");
149 note.Set("note", &admin, "", &store, "");
150 group.Set("group", &admin, "", &store, "");
152 ensure_equals("entries = 2", store.GetEntries(), 2);
154 note.Set("another note", &admin, "", &store, "");
156 ensure_equals("entries = 2", store.GetEntries(), 2);
158 address.Set("new address", &admin, "", &store, "");
160 ensure_equals("entries = 3", store.GetEntries(), 3);
162 group.Set("administrative group", &admin, "", &store, "");
164 ensure_equals("entries = 4", store.GetEntries(), 4);