SC_TEST_CONFIG_INSTALL_DIR "/client/ut-client/test-dbus-daemon.conf";
struct Loop {
- Loop() { sc_start_glib_loop(); };
- ~Loop() { sc_stop_glib_loop(); };
+ Loop() { sc_start_glib_loop(); }
+ ~Loop() { sc_stop_glib_loop(); }
};
struct Fixture {
Fixture(): cm(TEST_DBUS_CONFIG_PATH)
{
cm.startAll();
- };
+ }
};
const int EVENT_TIMEOUT = 5000; ///< ms
return i;
}
-Latch signalReceivedLatch;
-std::vector< std::tuple<std::string, std::string, std::string> > receivedSignalMsg;
-
-void NotificationTestCallback(const char* container, const char* application, const char* message)
-{
- receivedSignalMsg.push_back(std::make_tuple(container, application, message));
- signalReceivedLatch.set();
-}
-
} // namespace
BOOST_FIXTURE_TEST_SUITE(Client, Fixture)
BOOST_AUTO_TEST_CASE(NotificationTest)
{
+ // TODO add a void* to callback parameter and pass this two variables
+ // so that they no longer need to be global
+ static Latch signalReceivedLatch;
+ static std::vector< std::tuple<std::string, std::string, std::string> > receivedSignalMsg;
+
+ auto callback = [](const char* container, const char* application, const char* message) {
+ receivedSignalMsg.push_back(std::make_tuple(container, application, message));
+ signalReceivedLatch.set();
+ };
+
std::map<std::string, ScClient> clients;
for (const auto& it : EXPECTED_DBUSES_STARTED) {
ScClient client = sc_client_create();
clients[it.first] = client;
}
for (auto& client : clients) {
- ScStatus status = sc_notification(client.second, NotificationTestCallback);
+ ScStatus status = sc_notification(client.second, callback);
BOOST_REQUIRE_EQUAL(SCCLIENT_SUCCESS, status);
}
for (auto& client : clients) {
ScopedDbusDaemon daemon;
ScopedGlibLoop loop;
Latch nameAcquired;
+ Latch callDone;
DbusConnection::Pointer conn1 = DbusConnection::create(DBUS_ADDRESS);
DbusConnection::Pointer conn2 = DbusConnection::create(DBUS_ADDRESS);
};
conn1->registerObject(TESTAPI_OBJECT_PATH, TESTAPI_DEFINITION, handler);
- Latch callDone;
-
auto asyncResult1 = [&](dbus::AsyncMethodCallResult& asyncMethodCallResult) {
BOOST_CHECK(g_variant_is_of_type(asyncMethodCallResult.get(), G_VARIANT_TYPE_UNIT));
callDone.set();
ScopedDbusDaemon daemon;
ScopedGlibLoop loop;
Latch nameAcquired;
+ Latch handlerDone;
+ Latch callDone;
DbusConnection::Pointer conn1 = DbusConnection::create(DBUS_ADDRESS);
DbusConnection::Pointer conn2 = DbusConnection::create(DBUS_ADDRESS);
[] {});
BOOST_REQUIRE(nameAcquired.wait(EVENT_TIMEOUT));
- Latch handlerDone;
std::string strResult;
MethodResultBuilder::Pointer deferredResult;
};
conn1->registerObject(TESTAPI_OBJECT_PATH, TESTAPI_DEFINITION, handler);
- Latch callDone;
-
auto asyncResult = [&](dbus::AsyncMethodCallResult& asyncMethodCallResult) {
const gchar* ret = NULL;
g_variant_get(asyncMethodCallResult.get(), "(&s)", &ret);
ContainersManager cm(TEST_DBUS_CONFIG_PATH);
cm.startAll();
+ Latch signalReceivedLatch;
+ std::map<int, std::vector<std::string>> signalReceivedSourcesMap;
+
std::map<int, std::unique_ptr<DbusAccessory>> dbuses;
for (int i = 1; i <= TEST_DBUS_CONNECTION_CONTAINERS_COUNT; ++i) {
dbuses[i] = std::unique_ptr<DbusAccessory>(new DbusAccessory(i));
}
- Latch signalReceivedLatch;
- std::map<int, std::vector<std::string>> signalReceivedSourcesMap;
auto handler = [](Latch& latch,
std::vector<std::string>& receivedSignalSources,
const std::string& /*senderBusName*/,
ContainersManager cm(TEST_DBUS_CONFIG_PATH);
cm.startAll();
+ Latch notificationLatch;
+ std::string notificationSource;
+ std::string notificationPath;
+ std::string notificationRetcode;
+
std::map<int, std::unique_ptr<DbusAccessory>> dbuses;
for (int i = 1; i <= 2; ++i) {
dbuses[i] = std::unique_ptr<DbusAccessory>(new DbusAccessory(i));
}
- Latch notificationLatch;
- std::string notificationSource;
- std::string notificationPath;
- std::string notificationRetcode;
auto handler = [&](const std::string& /*senderBusName*/,
const std::string& objectPath,
const std::string& interface,
BOOST_AUTO_TEST_CASE(ContainerDbusesSignalsTest)
{
- DbusAccessory host(DbusAccessory::HOST_ID);
-
Latch signalLatch;
DbusAccessory::Dbuses collectedDbuses;
+ DbusAccessory host(DbusAccessory::HOST_ID);
+
auto onSignal = [&] (const std::string& /*senderBusName*/,
const std::string& objectPath,
const std::string& interface,
InputMonitorException);
}
+namespace {
+
void sendNEvents(Fixture& f, unsigned int noOfEventsToSend)
{
Latch eventLatch;
BOOST_CHECK(!eventLatch.wait(10));
}
+} // namespace
+
BOOST_AUTO_TEST_CASE(Event_oneAtATime)
{
sendNEvents(*this, 1);
sendNEvents(*this, 10);
}
+namespace {
+
void sendNEventsWithPauses(Fixture& f, unsigned int noOfEventsToSend)
{
Latch eventLatch;
BOOST_CHECK(!eventLatch.wait(10));
}
+} // namespace
+
BOOST_AUTO_TEST_CASE(Event_oneAtATimeWithPauses)
{
sendNEventsWithPauses(*this, 1);
BOOST_AUTO_TEST_CASE(ThreadTest)
{
- CallbackGuard guard;
Latch trackerCreated;
Latch trackerCanBeDestroyed;
+ CallbackGuard guard;
std::future<bool> future = std::async(std::launch::async, [&]() -> bool {
CallbackGuard::Tracker tracker = guard.spawn();
#include "utils/latch.hpp"
#include "utils/glib-loop.hpp"
-#include <memory>
+#include <atomic>
BOOST_AUTO_TEST_SUITE(UtilsGlibLoopSuite)
BOOST_AUTO_TEST_CASE(GlibTimerEventTest)
{
ScopedGlibLoop loop;
- CallbackGuard guard;
Latch latch;
+ std::atomic_uint counter(0);
+
+ CallbackGuard guard;
Glib::OnTimerEventCallback callback = [&]()->bool {
- static unsigned int counter = 0;
latch.set();
if (++counter >= TIMER_NUMBER) {
return false;