namespace
{
-class AfterConnectedNotifier : public STG::PropertyNotifierBase<bool>
+class ConnectCtr
{
public:
- AfterConnectedNotifier()
+ ConnectCtr()
: m_connects(0),
m_disconnects(0)
{}
- void notify(const bool& oldValue, const bool& newValue) override
+ void update(bool isConnect)
{
- if (!oldValue && newValue)
+ if (isConnect)
++m_connects;
- if (oldValue && !newValue)
+ else
++m_disconnects;
}
TestServices services;
STG::UserImpl user(&settings, &store, &tariffs, &admin, &users, services);
- AfterConnectedNotifier connectionNotifier;
-
- user.AddConnectedAfterNotifier(&connectionNotifier);
+ ConnectCtr ctr;
+ STG::ScopedConnection conn = user.afterConnectedChange([&ctr](auto, auto newVal){ ctr.update(newVal); });
STG::UserProperty<std::string> & tariffName = user.GetProperties().tariffName;
STG::UserProperty<STG::UserIPs> & ips = user.GetProperties().ips;
ips = STG::UserIPs::parse("*");
BOOST_CHECK_EQUAL(user.GetConnected(), false);
- BOOST_CHECK_EQUAL(connectionNotifier.connects(), static_cast<size_t>(0));
- BOOST_CHECK_EQUAL(connectionNotifier.disconnects(), static_cast<size_t>(0));
+ BOOST_CHECK_EQUAL(ctr.connects(), static_cast<size_t>(0));
+ BOOST_CHECK_EQUAL(ctr.disconnects(), static_cast<size_t>(0));
BOOST_CHECK_EQUAL(user.GetProperties().tariffName.ConstData(), NO_TARIFF_NAME);
BOOST_CHECK_EQUAL(user.IsAuthorizedBy(&auth), true);
BOOST_CHECK_EQUAL(user.GetConnected(), true);
- BOOST_CHECK_EQUAL(connectionNotifier.connects(), static_cast<size_t>(1));
- BOOST_CHECK_EQUAL(connectionNotifier.disconnects(), static_cast<size_t>(0));
+ BOOST_CHECK_EQUAL(ctr.connects(), static_cast<size_t>(1));
+ BOOST_CHECK_EQUAL(ctr.disconnects(), static_cast<size_t>(0));
tariffName = "test";
BOOST_CHECK_EQUAL(user.GetProperties().tariffName.ConstData(), "test");
BOOST_CHECK_EQUAL(user.IsAuthorizedBy(&auth), true);
BOOST_CHECK_EQUAL(user.GetConnected(), true);
- BOOST_CHECK_EQUAL(connectionNotifier.connects(), static_cast<size_t>(1));
- BOOST_CHECK_EQUAL(connectionNotifier.disconnects(), static_cast<size_t>(0));
+ BOOST_CHECK_EQUAL(ctr.connects(), static_cast<size_t>(1));
+ BOOST_CHECK_EQUAL(ctr.disconnects(), static_cast<size_t>(0));
}
BOOST_AUTO_TEST_CASE(Reconnect)
TestServices services;
STG::UserImpl user(&settings, &store, &tariffs, &admin, &users, services);
- AfterConnectedNotifier connectionNotifier;
-
- user.AddConnectedAfterNotifier(&connectionNotifier);
+ ConnectCtr ctr;
+ STG::ScopedConnection conn = user.afterConnectedChange([&ctr](auto, auto newVal){ ctr.update(newVal); });
STG::UserProperty<std::string> & tariffName = user.GetProperties().tariffName;
STG::UserProperty<STG::UserIPs> & ips = user.GetProperties().ips;
ips = STG::UserIPs::parse("*");
BOOST_CHECK_EQUAL(user.GetConnected(), false);
- BOOST_CHECK_EQUAL(connectionNotifier.connects(), static_cast<size_t>(0));
- BOOST_CHECK_EQUAL(connectionNotifier.disconnects(), static_cast<size_t>(0));
+ BOOST_CHECK_EQUAL(ctr.connects(), static_cast<size_t>(0));
+ BOOST_CHECK_EQUAL(ctr.disconnects(), static_cast<size_t>(0));
BOOST_CHECK_EQUAL(user.GetProperties().tariffName.ConstData(), NO_TARIFF_NAME);
BOOST_CHECK_EQUAL(user.IsAuthorizedBy(&auth), true);
BOOST_CHECK_EQUAL(user.GetConnected(), true);
- BOOST_CHECK_EQUAL(connectionNotifier.connects(), static_cast<size_t>(1));
- BOOST_CHECK_EQUAL(connectionNotifier.disconnects(), static_cast<size_t>(0));
+ BOOST_CHECK_EQUAL(ctr.connects(), static_cast<size_t>(1));
+ BOOST_CHECK_EQUAL(ctr.disconnects(), static_cast<size_t>(0));
tariffName = "test";
BOOST_CHECK_EQUAL(user.GetProperties().tariffName.ConstData(), "test");
BOOST_CHECK_EQUAL(user.IsAuthorizedBy(&auth), true);
BOOST_CHECK_EQUAL(user.GetConnected(), true);
- BOOST_CHECK_EQUAL(connectionNotifier.connects(), static_cast<size_t>(2));
- BOOST_CHECK_EQUAL(connectionNotifier.disconnects(), static_cast<size_t>(1));
+ BOOST_CHECK_EQUAL(ctr.connects(), static_cast<size_t>(2));
+ BOOST_CHECK_EQUAL(ctr.disconnects(), static_cast<size_t>(1));
}
BOOST_AUTO_TEST_SUITE_END()