3 #include "stg/user_property.h"
 
   6 #include "testsettings.h"
 
   7 #include "testtariffs.h"
 
  11 #include "testusers.h"
 
  13 class AFTER_CONNECTED_NOTIFIER : public PROPERTY_NOTIFIER_BASE<bool>,
 
  16     AFTER_CONNECTED_NOTIFIER()
 
  20     void Notify(const bool & oldValue, const bool & newValue);
 
  22     size_t GetConnects() const { return connects; }
 
  23     size_t GetDisconnects() const { return disconnects; }
 
  32     struct reconnect_on_tariff_change_data {
 
  35     typedef test_group<reconnect_on_tariff_change_data> tg;
 
  36     tg reconnect_on_tariff_change_test_group("Reconnect on tariff change tests group");
 
  38     typedef tg::object testobject;
 
  40     class TEST_SETTINGS_LOCAL : public TEST_SETTINGS {
 
  42             TEST_SETTINGS_LOCAL(bool _reconnectOnTariffChange)
 
  43                 : reconnectOnTariffChange(_reconnectOnTariffChange)
 
  46             bool GetReconnectOnTariffChange() const { return reconnectOnTariffChange; }
 
  49             bool reconnectOnTariffChange;
 
  54     void testobject::test<1>()
 
  56         set_test_name("Check normal behaviour");
 
  58         TEST_SETTINGS_LOCAL settings(false);
 
  64         USER_IMPL user(&settings, &store, &tariffs, &admin, &users);
 
  66         AFTER_CONNECTED_NOTIFIER connectionNotifier;
 
  68         user.AddConnectedAfterNotifier(&connectionNotifier);
 
  70         USER_PROPERTY<double> & cash(user.GetProperty().cash);
 
  71         USER_PROPERTY<std::string> & tariffName(user.GetProperty().tariffName);
 
  72         USER_PROPERTY<USER_IPS> & ips(user.GetProperty().ips);
 
  76         ensure_equals("user.connected = false", user.GetConnected(), false);
 
  77         ensure_equals("connects = 0", connectionNotifier.GetConnects(), 0);
 
  78         ensure_equals("disconnects = 0", connectionNotifier.GetDisconnects(), 0);
 
  80         ensure_equals("user.tariffName == NO_TARIFF_NAME", user.GetProperty().tariffName.ConstData(), NO_TARIFF_NAME);
 
  83         ensure_equals("user.tariffName == 'test'", user.GetProperty().tariffName.ConstData(), "test");
 
  85         user.Authorize(inet_strington("127.0.0.1"), 0, &auth);
 
  87         ensure_equals("user.authorised_by = true", user.IsAuthorizedBy(&auth), true);
 
  89         ensure_equals("user.connected = true", user.GetConnected(), true);
 
  90         ensure_equals("connects = 1", connectionNotifier.GetConnects(), 1);
 
  91         ensure_equals("disconnects = 0", connectionNotifier.GetDisconnects(), 0);
 
  95 void AFTER_CONNECTED_NOTIFIER::Notify(const bool & oldValue, const bool & newValue)
 
  97     if (!oldValue && newValue)
 
  99     if (oldValue && !newValue)