X-Git-Url: https://git.stg.codes/stg.git/blobdiff_plain/08dd72f2d8d3d7766e4fa87f01840c3ed8211091..2196a3a0cdc5384c082febb7f4aa5994cc7d80db:/tests/test_reconnect_on_tariff_change.cpp diff --git a/tests/test_reconnect_on_tariff_change.cpp b/tests/test_reconnect_on_tariff_change.cpp index ca03d6c2..856c85d3 100644 --- a/tests/test_reconnect_on_tariff_change.cpp +++ b/tests/test_reconnect_on_tariff_change.cpp @@ -24,19 +24,19 @@ volatile time_t stgTime = 0; namespace { -class AfterConnectedNotifier : public STG::PropertyNotifierBase +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; } @@ -77,9 +77,8 @@ BOOST_AUTO_TEST_CASE(NormalBehavior) 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 & tariffName = user.GetProperties().tariffName; STG::UserProperty & ips = user.GetProperties().ips; @@ -87,8 +86,8 @@ BOOST_AUTO_TEST_CASE(NormalBehavior) ips = STG::UserIPs::parse("*"); BOOST_CHECK_EQUAL(user.GetConnected(), false); - BOOST_CHECK_EQUAL(connectionNotifier.connects(), static_cast(0)); - BOOST_CHECK_EQUAL(connectionNotifier.disconnects(), static_cast(0)); + BOOST_CHECK_EQUAL(ctr.connects(), static_cast(0)); + BOOST_CHECK_EQUAL(ctr.disconnects(), static_cast(0)); BOOST_CHECK_EQUAL(user.GetProperties().tariffName.ConstData(), NO_TARIFF_NAME); @@ -98,8 +97,8 @@ BOOST_AUTO_TEST_CASE(NormalBehavior) BOOST_CHECK_EQUAL(user.IsAuthorizedBy(&auth), true); BOOST_CHECK_EQUAL(user.GetConnected(), true); - BOOST_CHECK_EQUAL(connectionNotifier.connects(), static_cast(1)); - BOOST_CHECK_EQUAL(connectionNotifier.disconnects(), static_cast(0)); + BOOST_CHECK_EQUAL(ctr.connects(), static_cast(1)); + BOOST_CHECK_EQUAL(ctr.disconnects(), static_cast(0)); tariffName = "test"; BOOST_CHECK_EQUAL(user.GetProperties().tariffName.ConstData(), "test"); @@ -107,8 +106,8 @@ BOOST_AUTO_TEST_CASE(NormalBehavior) BOOST_CHECK_EQUAL(user.IsAuthorizedBy(&auth), true); BOOST_CHECK_EQUAL(user.GetConnected(), true); - BOOST_CHECK_EQUAL(connectionNotifier.connects(), static_cast(1)); - BOOST_CHECK_EQUAL(connectionNotifier.disconnects(), static_cast(0)); + BOOST_CHECK_EQUAL(ctr.connects(), static_cast(1)); + BOOST_CHECK_EQUAL(ctr.disconnects(), static_cast(0)); } BOOST_AUTO_TEST_CASE(Reconnect) @@ -130,9 +129,8 @@ 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 & tariffName = user.GetProperties().tariffName; STG::UserProperty & ips = user.GetProperties().ips; @@ -140,8 +138,8 @@ BOOST_AUTO_TEST_CASE(Reconnect) ips = STG::UserIPs::parse("*"); BOOST_CHECK_EQUAL(user.GetConnected(), false); - BOOST_CHECK_EQUAL(connectionNotifier.connects(), static_cast(0)); - BOOST_CHECK_EQUAL(connectionNotifier.disconnects(), static_cast(0)); + BOOST_CHECK_EQUAL(ctr.connects(), static_cast(0)); + BOOST_CHECK_EQUAL(ctr.disconnects(), static_cast(0)); BOOST_CHECK_EQUAL(user.GetProperties().tariffName.ConstData(), NO_TARIFF_NAME); @@ -151,8 +149,8 @@ BOOST_AUTO_TEST_CASE(Reconnect) BOOST_CHECK_EQUAL(user.IsAuthorizedBy(&auth), true); BOOST_CHECK_EQUAL(user.GetConnected(), true); - BOOST_CHECK_EQUAL(connectionNotifier.connects(), static_cast(1)); - BOOST_CHECK_EQUAL(connectionNotifier.disconnects(), static_cast(0)); + BOOST_CHECK_EQUAL(ctr.connects(), static_cast(1)); + BOOST_CHECK_EQUAL(ctr.disconnects(), static_cast(0)); tariffName = "test"; BOOST_CHECK_EQUAL(user.GetProperties().tariffName.ConstData(), "test"); @@ -160,8 +158,8 @@ BOOST_AUTO_TEST_CASE(Reconnect) BOOST_CHECK_EQUAL(user.IsAuthorizedBy(&auth), true); BOOST_CHECK_EQUAL(user.GetConnected(), true); - BOOST_CHECK_EQUAL(connectionNotifier.connects(), static_cast(2)); - BOOST_CHECK_EQUAL(connectionNotifier.disconnects(), static_cast(1)); + BOOST_CHECK_EQUAL(ctr.connects(), static_cast(2)); + BOOST_CHECK_EQUAL(ctr.disconnects(), static_cast(1)); } BOOST_AUTO_TEST_SUITE_END()