Stop ode.socket together with ode.service 82/209182/3
authorKrzysztof Jackiewicz <k.jackiewicz@samsung.com>
Fri, 28 Jun 2019 16:00:22 +0000 (18:00 +0200)
committerKrzysztof Jackiewicz <k.jackiewicz@samsung.com>
Wed, 17 Jul 2019 08:52:52 +0000 (10:52 +0200)
Oded became socket activated. To test the connection refusal the
socket has to be put down as well.

Change-Id: Ifec50d1198ceeee7e5ac131715cbd8ca642427e5

src/ode/ode-tests-common.cpp
src/ode/ode-tests-common.h
src/ode/ode-tests-internal-encryption.cpp
src/ode/ode-tests-keys.cpp

index 651ded7..fd82703 100644 (file)
  *  @brief  Tests for the ODE API
  */
 
+#include <unistd.h>
+
 #include <iostream>
 #include <string>
+#include <utility>
 
 #include <dpl/log/log.h>
 
@@ -83,3 +86,24 @@ HelperInternalEncryption::~HelperInternalEncryption() {
     ode_internal_encryption_umount();
     ode_internal_encryption_clean_password(pass);
 }
+
+std::unique_ptr<ServiceManager, std::function<void(ServiceManager*)>> createScopedOdeStopper() {
+    auto sm_start = [](ServiceManager* sm) {
+        try {
+            sm->startService(true);
+            delete sm;
+            sleep(1);
+            //TODO: startService should wait until the sm is really started but it does not
+            // because of that the sleep is needed
+        } catch (...) {
+            RUNNER_ERROR_MSG("Unexpected exception during service startup");
+        }
+    };
+    std::unique_ptr<ServiceManager, decltype(sm_start)> sm_stop(
+            new ServiceManager("ode.service", { "ode.socket" }),
+            std::move(sm_start));
+
+    sm_stop->stopService(true);
+
+    return sm_stop;
+}
index b15440c..0151b9c 100644 (file)
 #pragma once
 
 #include <utility>
+#include <functional>
+#include <memory>
+
+#include <service_manager.h>
 
 #include <dpl/test/test_runner.h>
 
@@ -120,3 +124,5 @@ public:
     HelperInternalEncryption(const char* password);
     ~HelperInternalEncryption();
 };
+
+std::unique_ptr<ServiceManager, std::function<void(ServiceManager*)>> createScopedOdeStopper();
index 61559ed..881ecaa 100644 (file)
@@ -236,15 +236,7 @@ RUNNER_TEST(T1019_internal_encryption_get_state_1_invalid_parameter)
 
 RUNNER_TEST(T1020_internal_encryption_connection_refused)
 {
-    auto sm_start = [](ServiceManager* sm) {
-        sm->startService(true);
-        delete sm;
-        sleep(1);
-        //TODO: startService should wait until the sm is really started but it does not
-        // because of that the sleep is needed
-    };
-    std::unique_ptr<ServiceManager, decltype(sm_start)> sm_stop(new ServiceManager("ode.service"), sm_start);
-    sm_stop->stopService(true);
+    auto sm_stop = createScopedOdeStopper();
 
     unsigned int options = 0;
     bool result;
index 0fd8d7b..3596a29 100644 (file)
@@ -26,7 +26,6 @@
 #include <app_install_helper.h>
 #include <tests_common.h>
 #include <scoped_installer.h>
-#include <service_manager.h>
 
 #include <ode/keys.h>
 #include "ode-tests-common.h"
@@ -292,12 +291,7 @@ RUNNER_TEST(T2016_ode_keys_connection_refused)
 {
     HelperKeys helper(device1, password);
 
-    auto sm_start = [](ServiceManager* sm) {
-        sm->startService(true);
-        delete sm;
-    };
-    std::unique_ptr<ServiceManager, decltype(sm_start)> sm_stop(new ServiceManager("ode.service"), sm_start);
-    sm_stop->stopService(true);
+    auto sm_stop = createScopedOdeStopper();
 
     bool result;