]> git.stg.codes - stg.git/commitdiff
Connection notifier and watcher added
authorMaxim Mamontov <faust@gts.dp.ua>
Thu, 26 May 2011 16:13:59 +0000 (19:13 +0300)
committerMaxim Mamontov <faust@gts.dp.ua>
Thu, 26 May 2011 16:13:59 +0000 (19:13 +0300)
tests/test_reconnect_on_tariff_change.cpp

index e60e59890c10c22ad9d2c1b6d84b15846b4d810c..a5f1ce7387d0e96b6043b156eace2c4fbcbd7997 100644 (file)
@@ -8,6 +8,23 @@
 #include "testadmin.h"
 #include "teststore.h"
 
+class AFTER_CONNECTED_NOTIFIER : public PROPERTY_NOTIFIER_BASE<bool>,
+                                 private NONCOPYABLE {
+public:
+    AFTER_CONNECTED_NOTIFIER()
+        : connects(0),
+          disconnects(0)
+    {}
+    void Notify(const bool & oldValue, const bool & newValue);
+
+    size_t GetConnects() const { return connects; }
+    size_t GetDisconnects() const { return disconnects; }
+
+private:
+    size_t connects;
+    size_t disconnects;
+};
+
 namespace tut
 {
     struct reconnect_on_tariff_change_data {
@@ -42,10 +59,25 @@ namespace tut
         TEST_STORE store;
         USER_IMPL user(&settings, &store, &tariffs, &admin, NULL);
 
+        AFTER_CONNECTED_NOTIFIER connectionNotifier;
+
+        user.AddConnectedAfterNotifier(&connectionNotifier);
+
         USER_PROPERTY<std::string> & tariffName(user.GetProperty().tariffName);
 
+        ensure_equals("connects = 0", connectionNotifier.GetConnects(), 0);
+        ensure_equals("disconnects = 0", connectionNotifier.GetDisconnects(), 0);
+
         ensure_equals("user.tariffName == NO_TARIFF_NAME", user.GetProperty().tariffName.ConstData(), NO_TARIFF_NAME);
         tariffName = "test";
         ensure_equals("user.tariffName == 'test'", user.GetProperty().tariffName.ConstData(), "test");
     }
 }
+
+void AFTER_CONNECTED_NOTIFIER::Notify(const bool & oldValue, const bool & newValue)
+{
+    if (!oldValue && newValue)
+        ++connects;
+    if (oldValue && !newValue)
+        ++disconnects;
+}