Introduce CynaraMask - a scoped cynara.service masker 26/33526/3
authorLukasz Wojciechowski <l.wojciechow@partner.samsung.com>
Mon, 12 Jan 2015 16:13:17 +0000 (17:13 +0100)
committerLukasz Wojciechowski <l.wojciechow@partner.samsung.com>
Wed, 14 Jan 2015 06:36:45 +0000 (07:36 +0100)
Creation of CynaraMask object causes cynara.service to be masked and stopped.
Its removal causes cynara to be unmasked and run again.

Change-Id: Id7c20093fbd4ec19cdba783b20225ece04be5dfb

tests/cynara-tests/CMakeLists.txt
tests/cynara-tests/common/cynara_test_cynara_mask.cpp [new file with mode: 0644]
tests/cynara-tests/common/cynara_test_cynara_mask.h [new file with mode: 0644]
tests/cynara-tests/common/cynara_test_env.cpp

index bfbc659..94aeb6e 100644 (file)
@@ -36,6 +36,7 @@ SET(CYNARA_TARGET_TEST_SOURCES
     ${PROJECT_SOURCE_DIR}/tests/cynara-tests/common/cynara_test_client_async_request_monitor.cpp
     ${PROJECT_SOURCE_DIR}/tests/cynara-tests/common/cynara_test_client_async_status_monitor.cpp
     ${PROJECT_SOURCE_DIR}/tests/cynara-tests/common/cynara_test_commons.cpp
+    ${PROJECT_SOURCE_DIR}/tests/cynara-tests/common/cynara_test_cynara_mask.cpp
     ${PROJECT_SOURCE_DIR}/tests/cynara-tests/common/cynara_test_env.cpp
     ${PROJECT_SOURCE_DIR}/tests/cynara-tests/common/cynara_test_file_operations.cpp
     ${PROJECT_SOURCE_DIR}/tests/cynara-tests/cynara-test.cpp
diff --git a/tests/cynara-tests/common/cynara_test_cynara_mask.cpp b/tests/cynara-tests/common/cynara_test_cynara_mask.cpp
new file mode 100644 (file)
index 0000000..afd63d2
--- /dev/null
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *    Licensed under the Apache License, Version 2.0 (the "License");
+ *    you may not use this file except in compliance with the License.
+ *    You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *    Unless required by applicable law or agreed to in writing, software
+ *    distributed under the License is distributed on an "AS IS" BASIS,
+ *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *    See the License for the specific language governing permissions and
+ *    limitations under the License.
+ */
+/**
+ * @file        cynara_test_cynara_mask.cpp
+ * @author      Lukasz Wojciechowski <l.wojciechow@partner.samsung.com>
+ * @version     1.0
+ * @brief       Implementation of scoped cynara service masker
+ */
+
+#include <exception>
+
+#include <cynara_test_commons.h>
+#include <dpl/test/test_runner.h>
+
+#include <cynara_test_cynara_mask.h>
+
+CynaraMask::CynaraMask() : m_dbusAccess(CynaraTestConsts::SERVICE.c_str())
+{
+    m_dbusAccess.maskService();
+    m_dbusAccess.stopService();
+}
+
+CynaraMask::~CynaraMask() noexcept(false)
+{
+    bool oops = std::uncaught_exception();
+    try {
+        m_dbusAccess.unmaskService();
+        m_dbusAccess.startService();
+    } catch (...) {
+        if (!oops)
+            throw;
+        RUNNER_ERROR_MSG("Error: more exceptions thrown while releasing CynaraMask.");
+    }
+}
diff --git a/tests/cynara-tests/common/cynara_test_cynara_mask.h b/tests/cynara-tests/common/cynara_test_cynara_mask.h
new file mode 100644 (file)
index 0000000..1da7754
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *    Licensed under the Apache License, Version 2.0 (the "License");
+ *    you may not use this file except in compliance with the License.
+ *    You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *    Unless required by applicable law or agreed to in writing, software
+ *    distributed under the License is distributed on an "AS IS" BASIS,
+ *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *    See the License for the specific language governing permissions and
+ *    limitations under the License.
+ */
+/**
+ * @file        cynara_test_cynara_mask.h
+ * @author      Lukasz Wojciechowski <l.wojciechow@partner.samsung.com>
+ * @version     1.0
+ * @brief       Definition of scoped cynara service masker
+ */
+
+#ifndef CYNARA_TEST_CYNARA_MASK_H_
+#define CYNARA_TEST_CYNARA_MASK_H_
+
+#include <dbus_access.h>
+
+class CynaraMask
+{
+public:
+    CynaraMask();
+    ~CynaraMask() noexcept(false);
+
+private:
+    DBusAccess m_dbusAccess;
+};
+
+#endif // CYNARA_TEST_CYNARA_MASK_H_
index 8f98d71..d855c69 100644 (file)
@@ -15,6 +15,7 @@
  */
 
 #include <cynara_test_commons.h>
+#include <cynara_test_cynara_mask.h>
 #include <cynara_test_file_operations.h>
 #include <dbus_access.h>
 #include <tests_common.h>
@@ -35,28 +36,21 @@ CynaraTestEnv::~CynaraTestEnv()
 
 void CynaraTestEnv::save()
 {
+    CynaraMask mask;
+
     clear(m_dir);
     removeDirIfExists(m_dir);
 
-    DBusAccess dbusAccess(CynaraTestConsts::SERVICE.c_str());
-    dbusAccess.maskService();
-    dbusAccess.stopService();
-
     m_dbPresent = dirExists(CynaraTestConsts::DB_DIR);
     if (m_dbPresent) {
         makeDir(m_dir);
         copyDir(CynaraTestConsts::DB_DIR, m_dir);
     }
-
-    dbusAccess.unmaskService();
-    dbusAccess.startService();
 }
 
 void CynaraTestEnv::restore()
 {
-    DBusAccess dbusAccess(CynaraTestConsts::SERVICE.c_str());
-    dbusAccess.maskService();
-    dbusAccess.stopService();
+    CynaraMask mask;
 
     clear(CynaraTestConsts::DB_DIR);
     if (m_dbPresent)
@@ -64,9 +58,6 @@ void CynaraTestEnv::restore()
     else
         removeDirIfExists(CynaraTestConsts::DB_DIR);
 
-    dbusAccess.unmaskService();
-    dbusAccess.startService();
-
     clear(m_dir);
     removeDirIfExists(m_dir);
 }