]> git.stg.codes - stg.git/blobdiff - tests/test_filter_params_log.cpp
Non-virtual admin.
[stg.git] / tests / test_filter_params_log.cpp
index ab7a30977c54deb33a02bd50b563e72f48f7788c..3223df83d988b4e466589034fbccd865887c9392 100644 (file)
@@ -1,11 +1,11 @@
 #include "tut/tut.hpp"
 
+#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"
@@ -14,8 +14,7 @@
 namespace
 {
 
-class TEST_STORE_LOCAL : public TEST_STORE,
-                         private NONCOPYABLE {
+class TEST_STORE_LOCAL : public TEST_STORE {
 public:
     TEST_STORE_LOCAL()
         : entries(0)
@@ -27,7 +26,7 @@ public:
                         const std::string & /*paramName*/,
                         const std::string & /*oldValue*/,
                         const std::string & /*newValue*/,
-                        const std::string & /*message*/) const { ++entries; return 0; }
+                        const std::string & /*message*/) const override { ++entries; return 0; }
 
     size_t GetEntries() const { return entries; }
 
@@ -66,26 +65,34 @@ namespace tut
         TEST_SETTINGS_LOCAL settings;
         settings.addFilter("*"); // Allow everything by default.
         TEST_TARIFFS tariffs;
-        TEST_ADMIN admin;
+        STG::Admin admin(STG::Priv(0xFFFF), {}, {});
         TEST_STORE_LOCAL store;
         TEST_AUTH auth;
         TEST_USERS users;
         TEST_SERVICES services;
-        USER_IMPL user(&settings, &store, &tariffs, &admin, &users, 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 = 3", store.GetEntries(), 3);
 
-        note.Set("another note", &admin, "", &store, "");
+        note.Set("another note", admin, "", store, "");
 
         ensure_equals("entries = 4", store.GetEntries(), 4);
+
+        address.Set("new address", admin, "", store, "");
+
+        ensure_equals("entries = 5", store.GetEntries(), 5);
+
+        group.Set("administrative group", admin, "", store, "");
+
+        ensure_equals("entries = 6", store.GetEntries(), 6);
     }
 
 
@@ -98,28 +105,32 @@ namespace tut
         TEST_SETTINGS_LOCAL settings;
         settings.addFilter("address"); // Allow everything by default.
         TEST_TARIFFS tariffs;
-        TEST_ADMIN admin;
+        STG::Admin admin(STG::Priv(0xFFFF), {}, {});
         TEST_STORE_LOCAL store;
         TEST_AUTH auth;
         TEST_USERS users;
         TEST_SERVICES services;
-        USER_IMPL user(&settings, &store, &tariffs, &admin, &users, 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 = 1", store.GetEntries(), 1);
 
-        note.Set("another note", &admin, "", &store, "");
+        note.Set("another note", admin, "", store, "");
 
         ensure_equals("entries = 1", store.GetEntries(), 1);
 
-        address.Set("new address", &admin, "", &store, "");
+        address.Set("new address", admin, "", store, "");
+
+        ensure_equals("entries = 2", store.GetEntries(), 2);
+
+        group.Set("administrative group", admin, "", store, "");
 
         ensure_equals("entries = 2", store.GetEntries(), 2);
     }
@@ -134,33 +145,71 @@ namespace tut
         settings.addFilter("address"); // Allow everything by default.
         settings.addFilter("group"); // Allow everything by default.
         TEST_TARIFFS tariffs;
-        TEST_ADMIN admin;
+        STG::Admin admin(STG::Priv(0xFFFF), {}, {});
         TEST_STORE_LOCAL store;
         TEST_AUTH auth;
         TEST_USERS users;
         TEST_SERVICES services;
-        USER_IMPL user(&settings, &store, &tariffs, &admin, &users, 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 = 2", store.GetEntries(), 2);
 
-        note.Set("another note", &admin, "", &store, "");
+        note.Set("another note", admin, "", store, "");
 
         ensure_equals("entries = 2", store.GetEntries(), 2);
 
-        address.Set("new address", &admin, "", &store, "");
+        address.Set("new address", admin, "", store, "");
 
         ensure_equals("entries = 3", store.GetEntries(), 3);
 
-        group.Set("administrative group", &admin, "", &store, "");
+        group.Set("administrative group", admin, "", store, "");
 
         ensure_equals("entries = 4", store.GetEntries(), 4);
     }
+
+    template<>
+    template<>
+    void testobject::test<4>()
+    {
+        set_test_name("Check empty filter.");
+
+        TEST_SETTINGS_LOCAL settings;
+        TEST_TARIFFS tariffs;
+        STG::Admin admin(STG::Priv(0xFFFF), {}, {});
+        TEST_STORE_LOCAL store;
+        TEST_AUTH auth;
+        TEST_USERS users;
+        TEST_SERVICES services;
+        STG::UserImpl user(&settings, &store, &tariffs, &admin, &users, services);
+
+        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, "");
+
+        ensure_equals("entries = 0", store.GetEntries(), 0);
+
+        note.Set("another note", admin, "", store, "");
+
+        ensure_equals("entries = 0", store.GetEntries(), 0);
+
+        address.Set("new address", admin, "", store, "");
+
+        ensure_equals("entries = 0", store.GetEntries(), 0);
+
+        group.Set("administrative group", admin, "", store, "");
+
+        ensure_equals("entries = 0", store.GetEntries(), 0);
+    }
 }