3 #include "stg/user_property.h"
6 #include "testsettings.h"
7 #include "testtariffs.h"
11 #include "testusers.h"
12 #include "testservices.h"
14 class AFTER_CONNECTED_NOTIFIER : public PROPERTY_NOTIFIER_BASE<bool>,
17 AFTER_CONNECTED_NOTIFIER()
21 void Notify(const bool & oldValue, const bool & newValue);
23 size_t GetConnects() const { return connects; }
24 size_t GetDisconnects() const { return disconnects; }
31 class TEST_SETTINGS_LOCAL : public TEST_SETTINGS {
33 TEST_SETTINGS_LOCAL(bool _reconnectOnTariffChange)
35 reconnectOnTariffChange(_reconnectOnTariffChange)
38 bool GetReconnectOnTariffChange() const { return reconnectOnTariffChange; }
41 bool reconnectOnTariffChange;
46 struct reconnect_on_tariff_change_data {
49 typedef test_group<reconnect_on_tariff_change_data> tg;
50 tg reconnect_on_tariff_change_test_group("Reconnect on tariff change tests group");
52 typedef tg::object testobject;
56 void testobject::test<1>()
58 set_test_name("Check normal behaviour");
60 TEST_SETTINGS_LOCAL settings(false);
66 TEST_SERVICES services;
67 USER_IMPL user(&settings, &store, &tariffs, &admin, &users, services);
69 AFTER_CONNECTED_NOTIFIER connectionNotifier;
71 user.AddConnectedAfterNotifier(&connectionNotifier);
73 USER_PROPERTY<std::string> & tariffName(user.GetProperty().tariffName);
74 USER_PROPERTY<USER_IPS> & ips(user.GetProperty().ips);
78 ensure_equals("user.connected = false", user.GetConnected(), false);
79 ensure_equals("connects = 0", connectionNotifier.GetConnects(), static_cast<size_t>(0));
80 ensure_equals("disconnects = 0", connectionNotifier.GetDisconnects(), static_cast<size_t>(0));
82 ensure_equals("user.tariffName == NO_TARIFF_NAME", user.GetProperty().tariffName.ConstData(), NO_TARIFF_NAME);
84 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(), static_cast<size_t>(1));
91 ensure_equals("disconnects = 0", connectionNotifier.GetDisconnects(), static_cast<size_t>(0));
94 ensure_equals("user.tariffName == 'test'", user.GetProperty().tariffName.ConstData(), "test");
96 ensure_equals("user.authorised_by = true", user.IsAuthorizedBy(&auth), true);
98 ensure_equals("user.connected = true", user.GetConnected(), true);
99 ensure_equals("connects = 1", connectionNotifier.GetConnects(), static_cast<size_t>(1));
100 ensure_equals("disconnects = 0", connectionNotifier.GetDisconnects(), static_cast<size_t>(0));
106 void testobject::test<2>()
108 set_test_name("Check reconnect on tariff change");
110 TEST_SETTINGS_LOCAL settings(true);
112 TEST_SETTINGS * s1 = &settings;
113 SETTINGS * s2 = &settings;
115 ensure("settings.GetReconnectOnTariffChange() == true", settings.GetReconnectOnTariffChange());
116 ensure("s1->GetReconnectOnTariffChange() == true", s1->GetReconnectOnTariffChange());
117 ensure("s2->GetReconnectOnTariffChange() == true", s2->GetReconnectOnTariffChange());
119 TEST_TARIFFS tariffs;
124 TEST_SERVICES services;
125 USER_IMPL user(&settings, &store, &tariffs, &admin, &users, services);
127 AFTER_CONNECTED_NOTIFIER connectionNotifier;
129 user.AddConnectedAfterNotifier(&connectionNotifier);
131 USER_PROPERTY<std::string> & tariffName(user.GetProperty().tariffName);
132 USER_PROPERTY<USER_IPS> & ips(user.GetProperty().ips);
136 ensure_equals("user.connected = false", user.GetConnected(), false);
137 ensure_equals("connects = 0", connectionNotifier.GetConnects(), static_cast<size_t>(0));
138 ensure_equals("disconnects = 0", connectionNotifier.GetDisconnects(), static_cast<size_t>(0));
140 ensure_equals("user.tariffName == NO_TARIFF_NAME", user.GetProperty().tariffName.ConstData(), NO_TARIFF_NAME);
142 user.Authorize(inet_strington("127.0.0.1"), 0, &auth);
145 ensure_equals("user.authorised_by = true", user.IsAuthorizedBy(&auth), true);
147 ensure_equals("user.connected = true", user.GetConnected(), true);
148 ensure_equals("connects = 1", connectionNotifier.GetConnects(), static_cast<size_t>(1));
149 ensure_equals("disconnects = 0", connectionNotifier.GetDisconnects(), static_cast<size_t>(0));
152 ensure_equals("user.tariffName == 'test'", user.GetProperty().tariffName.ConstData(), "test");
154 ensure_equals("user.authorised_by = true", user.IsAuthorizedBy(&auth), true);
156 ensure_equals("user.connected = true", user.GetConnected(), true);
157 ensure_equals("connects = 2", connectionNotifier.GetConnects(), static_cast<size_t>(2));
158 ensure_equals("disconnects = 1", connectionNotifier.GetDisconnects(), static_cast<size_t>(1));
162 void AFTER_CONNECTED_NOTIFIER::Notify(const bool & oldValue, const bool & newValue)
164 if (!oldValue && newValue)
166 if (oldValue && !newValue)