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
${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
--- /dev/null
+/*
+ * 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.");
+ }
+}
--- /dev/null
+/*
+ * 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_
*/
#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>
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)
else
removeDirIfExists(CynaraTestConsts::DB_DIR);
- dbusAccess.unmaskService();
- dbusAccess.startService();
-
clear(m_dir);
removeDirIfExists(m_dir);
}