1 #define BOOST_TEST_MODULE STGFilterParamsLog
4 #include "stg/user_property.h"
7 #include "testsettings.h"
8 #include "testtariffs.h"
11 #include "testusers.h"
12 #include "testservices.h"
14 #pragma GCC diagnostic push
15 #pragma GCC diagnostic ignored "-Wold-style-cast"
16 #pragma GCC diagnostic ignored "-Wunused-parameter"
17 #pragma GCC diagnostic ignored "-Wsign-compare"
18 #pragma GCC diagnostic ignored "-Wparentheses"
19 #include <boost/test/unit_test.hpp>
20 #pragma GCC diagnostic pop
22 volatile time_t stgTime = 0;
27 class Store : public TestStore
34 int WriteUserChgLog(const std::string& /*login*/,
35 const std::string& /*admLogin*/,
37 const std::string& /*paramName*/,
38 const std::string& /*oldValue*/,
39 const std::string& /*newValue*/,
40 const std::string& /*message*/) const override { ++m_entries; return 0; }
42 size_t GetEntries() const { return m_entries; }
45 mutable size_t m_entries;
48 class Settings : public TestSettings
51 void addFilter(const std::string& field) { m_filter.push_back(field); }
53 const std::vector<std::string>& GetFilterParamsLog() const { return m_filter; }
56 std::vector<std::string> m_filter;
61 BOOST_AUTO_TEST_SUITE(FilterParamsLog)
63 BOOST_AUTO_TEST_CASE(NormalBehavior)
66 settings.addFilter("*"); // Allow everything by default.
68 tariffs.ReadTariffs();
69 STG::Admin admin(STG::Priv(0xFFFF), {}, {});
73 TestServices 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 BOOST_CHECK_EQUAL(store.GetEntries(), 3);
86 note.Set("another note", admin, "", store, "");
88 BOOST_CHECK_EQUAL(store.GetEntries(), 4);
90 address.Set("new address", admin, "", store, "");
92 BOOST_CHECK_EQUAL(store.GetEntries(), 5);
94 group.Set("administrative group", admin, "", store, "");
96 BOOST_CHECK_EQUAL(store.GetEntries(), 6);
99 BOOST_AUTO_TEST_CASE(SingleFilterEntry)
102 settings.addFilter("address"); // Allow everything by default.
104 STG::Admin admin(STG::Priv(0xFFFF), {}, {});
108 TestServices services;
109 STG::UserImpl user(&settings, &store, &tariffs, &admin, &users, services);
111 auto & address = user.GetProperties().address;
112 auto & note = user.GetProperties().note;
113 auto & group = user.GetProperties().group;
115 address.Set("address", admin, "", store, "");
116 note.Set("note", admin, "", store, "");
117 group.Set("group", admin, "", store, "");
119 BOOST_CHECK_EQUAL(store.GetEntries(), 1);
121 note.Set("another note", admin, "", store, "");
123 BOOST_CHECK_EQUAL(store.GetEntries(), 1);
125 address.Set("new address", admin, "", store, "");
127 BOOST_CHECK_EQUAL(store.GetEntries(), 2);
129 group.Set("administrative group", admin, "", store, "");
131 BOOST_CHECK_EQUAL(store.GetEntries(), 2);
134 BOOST_AUTO_TEST_CASE(MultipleFilterEntries)
137 settings.addFilter("address"); // Allow everything by default.
138 settings.addFilter("group"); // Allow everything by default.
140 STG::Admin admin(STG::Priv(0xFFFF), {}, {});
144 TestServices services;
145 STG::UserImpl user(&settings, &store, &tariffs, &admin, &users, services);
147 auto & address = user.GetProperties().address;
148 auto & note = user.GetProperties().note;
149 auto & group = user.GetProperties().group;
151 address.Set("address", admin, "", store, "");
152 note.Set("note", admin, "", store, "");
153 group.Set("group", admin, "", store, "");
155 BOOST_CHECK_EQUAL(store.GetEntries(), 2);
157 note.Set("another note", admin, "", store, "");
159 BOOST_CHECK_EQUAL(store.GetEntries(), 2);
161 address.Set("new address", admin, "", store, "");
163 BOOST_CHECK_EQUAL(store.GetEntries(), 3);
165 group.Set("administrative group", admin, "", store, "");
167 BOOST_CHECK_EQUAL(store.GetEntries(), 4);
170 BOOST_AUTO_TEST_CASE(EmptyFilter)
174 STG::Admin admin(STG::Priv(0xFFFF), {}, {});
178 TestServices services;
179 STG::UserImpl user(&settings, &store, &tariffs, &admin, &users, services);
181 auto & address = user.GetProperties().address;
182 auto & note = user.GetProperties().note;
183 auto & group = user.GetProperties().group;
185 address.Set("address", admin, "", store, "");
186 note.Set("note", admin, "", store, "");
187 group.Set("group", admin, "", store, "");
189 BOOST_CHECK_EQUAL(store.GetEntries(), 0);
191 note.Set("another note", admin, "", store, "");
193 BOOST_CHECK_EQUAL(store.GetEntries(), 0);
195 address.Set("new address", admin, "", store, "");
197 BOOST_CHECK_EQUAL(store.GetEntries(), 0);
199 group.Set("administrative group", admin, "", store, "");
201 BOOST_CHECK_EQUAL(store.GetEntries(), 0);
204 BOOST_AUTO_TEST_SUITE_END()