3 #include "stg/user_property.h"
6 #include "testsettings.h"
7 #include "testtariffs.h"
11 #include "testusers.h"
12 #include "testservices.h"
17 class AFTER_CONNECTED_NOTIFIER : public PROPERTY_NOTIFIER_BASE<bool>,
20 AFTER_CONNECTED_NOTIFIER()
24 void Notify(const bool & oldValue, const bool & newValue);
26 size_t GetConnects() const { return connects; }
27 size_t GetDisconnects() const { return disconnects; }
34 class TEST_SETTINGS_LOCAL : public TEST_SETTINGS {
36 TEST_SETTINGS_LOCAL(bool _reconnectOnTariffChange)
38 reconnectOnTariffChange(_reconnectOnTariffChange)
41 bool GetReconnectOnTariffChange() const { return reconnectOnTariffChange; }
44 bool reconnectOnTariffChange;
51 struct reconnect_on_tariff_change_data {
54 typedef test_group<reconnect_on_tariff_change_data> tg;
55 tg reconnect_on_tariff_change_test_group("Reconnect on tariff change tests group");
57 typedef tg::object testobject;
61 void testobject::test<1>()
63 set_test_name("Check normal behaviour");
65 TEST_SETTINGS_LOCAL settings(false);
71 TEST_SERVICES services;
72 USER_IMPL user(&settings, &store, &tariffs, &admin, &users, services);
74 AFTER_CONNECTED_NOTIFIER connectionNotifier;
76 user.AddConnectedAfterNotifier(&connectionNotifier);
78 USER_PROPERTY<std::string> & tariffName(user.GetProperty().tariffName);
79 USER_PROPERTY<USER_IPS> & ips(user.GetProperty().ips);
83 ensure_equals("user.connected = false", user.GetConnected(), false);
84 ensure_equals("connects = 0", connectionNotifier.GetConnects(), static_cast<size_t>(0));
85 ensure_equals("disconnects = 0", connectionNotifier.GetDisconnects(), static_cast<size_t>(0));
87 ensure_equals("user.tariffName == NO_TARIFF_NAME", user.GetProperty().tariffName.ConstData(), NO_TARIFF_NAME);
89 user.Authorize(inet_strington("127.0.0.1"), 0, &auth);
92 ensure_equals("user.authorised_by = true", user.IsAuthorizedBy(&auth), true);
94 ensure_equals("user.connected = true", user.GetConnected(), true);
95 ensure_equals("connects = 1", connectionNotifier.GetConnects(), static_cast<size_t>(1));
96 ensure_equals("disconnects = 0", connectionNotifier.GetDisconnects(), static_cast<size_t>(0));
99 ensure_equals("user.tariffName == 'test'", user.GetProperty().tariffName.ConstData(), "test");
101 ensure_equals("user.authorised_by = true", user.IsAuthorizedBy(&auth), true);
103 ensure_equals("user.connected = true", user.GetConnected(), true);
104 ensure_equals("connects = 1", connectionNotifier.GetConnects(), static_cast<size_t>(1));
105 ensure_equals("disconnects = 0", connectionNotifier.GetDisconnects(), static_cast<size_t>(0));
111 void testobject::test<2>()
113 set_test_name("Check reconnect on tariff change");
115 TEST_SETTINGS_LOCAL settings(true);
117 TEST_SETTINGS * s1 = &settings;
118 SETTINGS * s2 = &settings;
120 ensure("settings.GetReconnectOnTariffChange() == true", settings.GetReconnectOnTariffChange());
121 ensure("s1->GetReconnectOnTariffChange() == true", s1->GetReconnectOnTariffChange());
122 ensure("s2->GetReconnectOnTariffChange() == true", s2->GetReconnectOnTariffChange());
124 TEST_TARIFFS tariffs;
129 TEST_SERVICES services;
130 USER_IMPL user(&settings, &store, &tariffs, &admin, &users, services);
132 AFTER_CONNECTED_NOTIFIER connectionNotifier;
134 user.AddConnectedAfterNotifier(&connectionNotifier);
136 USER_PROPERTY<std::string> & tariffName(user.GetProperty().tariffName);
137 USER_PROPERTY<USER_IPS> & ips(user.GetProperty().ips);
141 ensure_equals("user.connected = false", user.GetConnected(), false);
142 ensure_equals("connects = 0", connectionNotifier.GetConnects(), static_cast<size_t>(0));
143 ensure_equals("disconnects = 0", connectionNotifier.GetDisconnects(), static_cast<size_t>(0));
145 ensure_equals("user.tariffName == NO_TARIFF_NAME", user.GetProperty().tariffName.ConstData(), NO_TARIFF_NAME);
147 user.Authorize(inet_strington("127.0.0.1"), 0, &auth);
150 ensure_equals("user.authorised_by = true", user.IsAuthorizedBy(&auth), true);
152 ensure_equals("user.connected = true", user.GetConnected(), true);
153 ensure_equals("connects = 1", connectionNotifier.GetConnects(), static_cast<size_t>(1));
154 ensure_equals("disconnects = 0", connectionNotifier.GetDisconnects(), static_cast<size_t>(0));
157 ensure_equals("user.tariffName == 'test'", user.GetProperty().tariffName.ConstData(), "test");
159 ensure_equals("user.authorised_by = true", user.IsAuthorizedBy(&auth), true);
161 ensure_equals("user.connected = true", user.GetConnected(), true);
162 ensure_equals("connects = 2", connectionNotifier.GetConnects(), static_cast<size_t>(2));
163 ensure_equals("disconnects = 1", connectionNotifier.GetDisconnects(), static_cast<size_t>(1));
167 void AFTER_CONNECTED_NOTIFIER::Notify(const bool & oldValue, const bool & newValue)
169 if (!oldValue && newValue)
171 if (oldValue && !newValue)