3 #include "stg/user_property.h"
6 #include "testsettings.h"
7 #include "testtariffs.h"
12 class AFTER_CONNECTED_NOTIFIER : public PROPERTY_NOTIFIER_BASE<bool>,
15 AFTER_CONNECTED_NOTIFIER()
19 void Notify(const bool & oldValue, const bool & newValue);
21 size_t GetConnects() const { return connects; }
22 size_t GetDisconnects() const { return disconnects; }
31 struct reconnect_on_tariff_change_data {
34 typedef test_group<reconnect_on_tariff_change_data> tg;
35 tg reconnect_on_tariff_change_test_group("Reconnect on tariff change tests group");
37 typedef tg::object testobject;
39 class TEST_SETTINGS_LOCAL : public TEST_SETTINGS {
41 TEST_SETTINGS_LOCAL(bool _reconnectOnTariffChange)
42 : reconnectOnTariffChange(_reconnectOnTariffChange)
45 bool GetReconnectOnTariffChange() const { return reconnectOnTariffChange; }
48 bool reconnectOnTariffChange;
53 void testobject::test<1>()
55 set_test_name("Check normal behaviour");
57 TEST_SETTINGS_LOCAL settings(false);
62 USER_IMPL user(&settings, &store, &tariffs, &admin, NULL);
64 AFTER_CONNECTED_NOTIFIER connectionNotifier;
66 user.AddConnectedAfterNotifier(&connectionNotifier);
68 USER_PROPERTY<double> & cash(user.GetProperty().cash);
69 USER_PROPERTY<std::string> & tariffName(user.GetProperty().tariffName);
70 USER_PROPERTY<USER_IPS> & ips(user.GetProperty().ips);
74 ensure_equals("user.connected = false", user.GetConnected(), false);
75 ensure_equals("connects = 0", connectionNotifier.GetConnects(), 0);
76 ensure_equals("disconnects = 0", connectionNotifier.GetDisconnects(), 0);
78 ensure_equals("user.tariffName == NO_TARIFF_NAME", user.GetProperty().tariffName.ConstData(), NO_TARIFF_NAME);
81 ensure_equals("user.tariffName == 'test'", user.GetProperty().tariffName.ConstData(), "test");
83 user.Authorize(inet_strington("127.0.0.1"), 0, &auth);
85 ensure_equals("user.connected = true", user.GetConnected(), true);
86 ensure_equals("connects = 1", connectionNotifier.GetConnects(), 1);
87 ensure_equals("disconnects = 0", connectionNotifier.GetDisconnects(), 0);
91 void AFTER_CONNECTED_NOTIFIER::Notify(const bool & oldValue, const bool & newValue)
93 if (!oldValue && newValue)
95 if (oldValue && !newValue)