-#include "tut/tut.hpp"
+#define BOOST_TEST_MODULE STGFilterParamsLog
+#include "stg/admin.h"
#include "stg/user_property.h"
#include "user_impl.h"
#include "testsettings.h"
#include "testtariffs.h"
-#include "testadmin.h"
#include "teststore.h"
#include "testauth.h"
#include "testusers.h"
#include "testservices.h"
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wold-style-cast"
+#pragma GCC diagnostic ignored "-Wunused-parameter"
+#pragma GCC diagnostic ignored "-Wsign-compare"
+#pragma GCC diagnostic ignored "-Wparentheses"
+#include <boost/test/unit_test.hpp>
+#pragma GCC diagnostic pop
+
+volatile time_t stgTime = 0;
+
namespace
{
-class TEST_STORE_LOCAL : public TEST_STORE,
- private NONCOPYABLE {
-public:
- TEST_STORE_LOCAL()
- : entries(0)
- {}
-
- int WriteUserChgLog(const std::string & /*login*/,
- const std::string & /*admLogin*/,
- uint32_t /*admIP*/,
- const std::string & /*paramName*/,
- const std::string & /*oldValue*/,
- const std::string & /*newValue*/,
- const std::string & /*message*/) const { ++entries; return 0; }
-
- size_t GetEntries() const { return entries; }
-
-private:
- mutable size_t entries;
-};
-
-class TEST_SETTINGS_LOCAL : public TEST_SETTINGS {
+class Store : public TestStore
+{
public:
- void addFilter(const std::string& field) { filter.push_back(field); }
+ Store()
+ : m_entries(0)
+ {}
+
+ int WriteUserChgLog(const std::string& /*login*/,
+ const std::string& /*admLogin*/,
+ uint32_t /*admIP*/,
+ const std::string& /*paramName*/,
+ const std::string& /*oldValue*/,
+ const std::string& /*newValue*/,
+ const std::string& /*message*/) const override { ++m_entries; return 0; }
- const std::vector<std::string>& GetFilterParamsLog() const { return filter; }
+ size_t GetEntries() const { return m_entries; }
private:
- std::vector<std::string> filter;
+ mutable size_t m_entries;
};
-}
-
-namespace tut
+class Settings : public TestSettings
{
- struct filter_params_log_data {
- };
-
- typedef test_group<filter_params_log_data> tg;
- tg filter_params_log_test_group("Filter params log tests group");
-
- typedef tg::object testobject;
-
- template<>
- template<>
- void testobject::test<1>()
- {
- set_test_name("Check normal behaviour");
+ public:
+ void addFilter(const std::string& field) { m_filter.push_back(field); }
- TEST_SETTINGS_LOCAL settings;
- settings.addFilter("*"); // Allow everything by default.
- TEST_TARIFFS tariffs;
- TEST_ADMIN admin;
- TEST_STORE_LOCAL store;
- TEST_AUTH auth;
- TEST_USERS users;
- TEST_SERVICES services;
- USER_IMPL user(&settings, &store, &tariffs, &admin, &users, services);
+ const std::vector<std::string>& GetFilterParamsLog() const { return m_filter; }
- USER_PROPERTY_LOGGED<std::string> & address(user.GetProperty().address);
- USER_PROPERTY_LOGGED<std::string> & note(user.GetProperty().note);
- USER_PROPERTY_LOGGED<std::string> & group(user.GetProperty().group);
+ private:
+ std::vector<std::string> m_filter;
+};
- address.Set("address", &admin, "", &store, "");
- note.Set("note", &admin, "", &store, "");
- group.Set("group", &admin, "", &store, "");
+}
- ensure_equals("entries = 3", store.GetEntries(), 3);
+BOOST_AUTO_TEST_SUITE(FilterParamsLog)
- note.Set("another note", &admin, "", &store, "");
+BOOST_AUTO_TEST_CASE(NormalBehavior)
+{
+ Settings settings;
+ settings.addFilter("*"); // Allow everything by default.
+ TestTariffs tariffs;
+ tariffs.ReadTariffs();
+ STG::Admin admin(STG::Priv(0xFFFF), {}, {});
+ Store store;
+ TestAuth auth;
+ TestUsers users;
+ TestServices services;
+ STG::UserImpl user(&settings, &store, &tariffs, &admin, &users, services);
- ensure_equals("entries = 4", store.GetEntries(), 4);
+ auto & address = user.GetProperties().address;
+ auto & note = user.GetProperties().note;
+ auto & group = user.GetProperties().group;
- address.Set("new address", &admin, "", &store, "");
+ address.Set("address", admin, "", store, "");
+ note.Set("note", admin, "", store, "");
+ group.Set("group", admin, "", store, "");
- ensure_equals("entries = 5", store.GetEntries(), 5);
+ BOOST_CHECK_EQUAL(store.GetEntries(), 3);
- group.Set("administrative group", &admin, "", &store, "");
+ note.Set("another note", admin, "", store, "");
- ensure_equals("entries = 6", store.GetEntries(), 6);
- }
+ BOOST_CHECK_EQUAL(store.GetEntries(), 4);
+ address.Set("new address", admin, "", store, "");
- template<>
- template<>
- void testobject::test<2>()
- {
- set_test_name("Check single filter entry.");
+ BOOST_CHECK_EQUAL(store.GetEntries(), 5);
- TEST_SETTINGS_LOCAL settings;
- settings.addFilter("address"); // Allow everything by default.
- TEST_TARIFFS tariffs;
- TEST_ADMIN admin;
- TEST_STORE_LOCAL store;
- TEST_AUTH auth;
- TEST_USERS users;
- TEST_SERVICES services;
- USER_IMPL user(&settings, &store, &tariffs, &admin, &users, services);
+ group.Set("administrative group", admin, "", store, "");
- USER_PROPERTY_LOGGED<std::string> & address(user.GetProperty().address);
- USER_PROPERTY_LOGGED<std::string> & note(user.GetProperty().note);
- USER_PROPERTY_LOGGED<std::string> & group(user.GetProperty().group);
+ BOOST_CHECK_EQUAL(store.GetEntries(), 6);
+}
- address.Set("address", &admin, "", &store, "");
- note.Set("note", &admin, "", &store, "");
- group.Set("group", &admin, "", &store, "");
+BOOST_AUTO_TEST_CASE(SingleFilterEntry)
+{
+ Settings settings;
+ settings.addFilter("address"); // Allow everything by default.
+ TestTariffs tariffs;
+ STG::Admin admin(STG::Priv(0xFFFF), {}, {});
+ Store store;
+ TestAuth auth;
+ TestUsers users;
+ TestServices services;
+ STG::UserImpl user(&settings, &store, &tariffs, &admin, &users, services);
- ensure_equals("entries = 1", store.GetEntries(), 1);
+ auto & address = user.GetProperties().address;
+ auto & note = user.GetProperties().note;
+ auto & group = user.GetProperties().group;
- note.Set("another note", &admin, "", &store, "");
+ address.Set("address", admin, "", store, "");
+ note.Set("note", admin, "", store, "");
+ group.Set("group", admin, "", store, "");
- ensure_equals("entries = 1", store.GetEntries(), 1);
+ BOOST_CHECK_EQUAL(store.GetEntries(), 1);
- address.Set("new address", &admin, "", &store, "");
+ note.Set("another note", admin, "", store, "");
- ensure_equals("entries = 2", store.GetEntries(), 2);
+ BOOST_CHECK_EQUAL(store.GetEntries(), 1);
- group.Set("administrative group", &admin, "", &store, "");
+ address.Set("new address", admin, "", store, "");
- ensure_equals("entries = 2", store.GetEntries(), 2);
- }
+ BOOST_CHECK_EQUAL(store.GetEntries(), 2);
- template<>
- template<>
- void testobject::test<3>()
- {
- set_test_name("Check multiple filter entries.");
+ group.Set("administrative group", admin, "", store, "");
- TEST_SETTINGS_LOCAL settings;
- settings.addFilter("address"); // Allow everything by default.
- settings.addFilter("group"); // Allow everything by default.
- TEST_TARIFFS tariffs;
- TEST_ADMIN admin;
- TEST_STORE_LOCAL store;
- TEST_AUTH auth;
- TEST_USERS users;
- TEST_SERVICES services;
- USER_IMPL user(&settings, &store, &tariffs, &admin, &users, services);
+ BOOST_CHECK_EQUAL(store.GetEntries(), 2);
+}
- USER_PROPERTY_LOGGED<std::string> & address(user.GetProperty().address);
- USER_PROPERTY_LOGGED<std::string> & note(user.GetProperty().note);
- USER_PROPERTY_LOGGED<std::string> & group(user.GetProperty().group);
+BOOST_AUTO_TEST_CASE(MultipleFilterEntries)
+{
+ Settings settings;
+ settings.addFilter("address"); // Allow everything by default.
+ settings.addFilter("group"); // Allow everything by default.
+ TestTariffs tariffs;
+ STG::Admin admin(STG::Priv(0xFFFF), {}, {});
+ Store store;
+ TestAuth auth;
+ TestUsers users;
+ TestServices services;
+ STG::UserImpl user(&settings, &store, &tariffs, &admin, &users, services);
- address.Set("address", &admin, "", &store, "");
- note.Set("note", &admin, "", &store, "");
- group.Set("group", &admin, "", &store, "");
+ auto & address = user.GetProperties().address;
+ auto & note = user.GetProperties().note;
+ auto & group = user.GetProperties().group;
- ensure_equals("entries = 2", store.GetEntries(), 2);
+ address.Set("address", admin, "", store, "");
+ note.Set("note", admin, "", store, "");
+ group.Set("group", admin, "", store, "");
- note.Set("another note", &admin, "", &store, "");
+ BOOST_CHECK_EQUAL(store.GetEntries(), 2);
- ensure_equals("entries = 2", store.GetEntries(), 2);
+ note.Set("another note", admin, "", store, "");
- address.Set("new address", &admin, "", &store, "");
+ BOOST_CHECK_EQUAL(store.GetEntries(), 2);
- ensure_equals("entries = 3", store.GetEntries(), 3);
+ address.Set("new address", admin, "", store, "");
- group.Set("administrative group", &admin, "", &store, "");
+ BOOST_CHECK_EQUAL(store.GetEntries(), 3);
- ensure_equals("entries = 4", store.GetEntries(), 4);
- }
+ group.Set("administrative group", admin, "", store, "");
- template<>
- template<>
- void testobject::test<4>()
- {
- set_test_name("Check empty filter.");
+ BOOST_CHECK_EQUAL(store.GetEntries(), 4);
+}
- TEST_SETTINGS_LOCAL settings;
- TEST_TARIFFS tariffs;
- TEST_ADMIN admin;
- TEST_STORE_LOCAL store;
- TEST_AUTH auth;
- TEST_USERS users;
- TEST_SERVICES services;
- USER_IMPL user(&settings, &store, &tariffs, &admin, &users, services);
+BOOST_AUTO_TEST_CASE(EmptyFilter)
+{
+ Settings settings;
+ TestTariffs tariffs;
+ STG::Admin admin(STG::Priv(0xFFFF), {}, {});
+ Store store;
+ TestAuth auth;
+ TestUsers users;
+ TestServices services;
+ STG::UserImpl user(&settings, &store, &tariffs, &admin, &users, services);
- USER_PROPERTY_LOGGED<std::string> & address(user.GetProperty().address);
- USER_PROPERTY_LOGGED<std::string> & note(user.GetProperty().note);
- USER_PROPERTY_LOGGED<std::string> & group(user.GetProperty().group);
+ auto & address = user.GetProperties().address;
+ auto & note = user.GetProperties().note;
+ auto & group = user.GetProperties().group;
- address.Set("address", &admin, "", &store, "");
- note.Set("note", &admin, "", &store, "");
- group.Set("group", &admin, "", &store, "");
+ address.Set("address", admin, "", store, "");
+ note.Set("note", admin, "", store, "");
+ group.Set("group", admin, "", store, "");
- ensure_equals("entries = 0", store.GetEntries(), 0);
+ BOOST_CHECK_EQUAL(store.GetEntries(), 0);
- note.Set("another note", &admin, "", &store, "");
+ note.Set("another note", admin, "", store, "");
- ensure_equals("entries = 0", store.GetEntries(), 0);
+ BOOST_CHECK_EQUAL(store.GetEntries(), 0);
- address.Set("new address", &admin, "", &store, "");
+ address.Set("new address", admin, "", store, "");
- ensure_equals("entries = 0", store.GetEntries(), 0);
+ BOOST_CHECK_EQUAL(store.GetEntries(), 0);
- group.Set("administrative group", &admin, "", &store, "");
+ group.Set("administrative group", admin, "", store, "");
- ensure_equals("entries = 0", store.GetEntries(), 0);
- }
+ BOOST_CHECK_EQUAL(store.GetEntries(), 0);
}
+
+BOOST_AUTO_TEST_SUITE_END()