SET(DBUS_TESTS_SOURCES
${PROJECT_SOURCE_DIR}/tests/cynara-tests/common/cynara_test_admin.cpp
+ ${PROJECT_SOURCE_DIR}/tests/dbus-tests/common/dbus_test_commons.cpp
+ ${PROJECT_SOURCE_DIR}/tests/dbus-tests/common/dbus_test_service.cpp
${PROJECT_SOURCE_DIR}/tests/dbus-tests/common/dbus_test_service_object.cpp
${PROJECT_SOURCE_DIR}/tests/dbus-tests/main.cpp
${PROJECT_SOURCE_DIR}/tests/dbus-tests/common/dbus_test_busconfig_writer.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 dbus_test_commons.cpp
+ * @author Marcin Niesluchowski <m.niesluchow@samsung.com>
+ * @version 1.0
+ * @brief commons for dbus test files
+ */
+
+#include <dbus_test_commons.h>
+
+namespace DBusTest
+{
+
+const std::string CONNECTION_NAME_PREFIX("com.security_tests");
+
+const std::string connectionNameFromStr(const std::string &str)
+{
+ return CONNECTION_NAME_PREFIX + "." + str;
+}
+
+}
--- /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 dbus_test_commons.h
+ * @author Marcin Niesluchowski <m.niesluchow@samsung.com>
+ * @version 1.0
+ * @brief commons for dbus test files
+ */
+
+#ifndef DBUS_TESTS_COMMON_DBUS_TEST_COMMONS_H
+#define DBUS_TESTS_COMMON_DBUS_TEST_COMMONS_H
+
+#include <string>
+
+namespace DBusTest
+{
+
+extern const std::string CONNECTION_NAME_PREFIX;
+
+const std::string connectionNameFromStr(const std::string &str);
+
+}
+
+#endif // DBUS_TESTS_COMMON_DBUS_TEST_COMMONS_H
--- /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 dbus_test_service.cpp
+ * @author Marcin Niesluchowski <m.niesluchow@samsung.com>
+ * @version 1.0
+ * @brief dbus test service definition
+ */
+
+#include <dbus_test_service.h>
+#include <dbus_test_commons.h>
+
+#include <chrono>
+
+#include <dpl/test/test_runner.h>
+
+namespace {
+
+const std::string OBJECT_PATH_DIR("/com/security_tests/");
+const std::string INTERFACE_SUFFIX("TestInterface");
+
+}
+
+namespace DBusTest
+{
+
+ServiceCreds::ServiceCreds(const std::string &name)
+ : m_connectionName(connectionNameFromStr(name))
+ , m_objectPath(OBJECT_PATH_DIR + name)
+ , m_interface(m_connectionName + "." + INTERFACE_SUFFIX)
+{
+}
+
+const std::string& ServiceCreds::connectionName() const
+{
+ return m_connectionName;
+}
+
+const std::string& ServiceCreds::objectPath() const
+{
+ return m_objectPath;
+}
+
+const std::string& ServiceCreds::interface() const
+{
+ return m_interface;
+}
+
+Service::Service(const ServiceCreds &serviceCreds)
+ : m_connection(DBUS_BUS_SYSTEM, true)
+ , m_object(serviceCreds.interface())
+ , m_messageReceived(false)
+ , m_exceptionThrown(false)
+{
+ m_connection.requestName(serviceCreds.connectionName());
+ m_connection.registerObjectPath(serviceCreds.objectPath(),
+ handleMessage,
+ (void*)this);
+}
+
+void Service::insertMethodHandler(const std::string &method,
+ const MessageHandler &messageHandler)
+{
+ m_object.insertMethodHandler(method, messageHandler);
+}
+
+DBusHandlerResult Service::handleMessage(DBusConnection *connection,
+ DBusMessage *message,
+ void *userData)
+{
+ Service* service = reinterpret_cast<Service*>(userData);
+ (void)userData;
+ try {
+ service->m_messageReceived = true;
+ DBus::MessageIn messageIn(message, true);
+ DBus::Connection conn(connection);
+ service->m_object.handleMessage(conn, messageIn, service->m_errorString);
+ } catch(...) {
+ service->m_exceptionThrown = true;
+ }
+ return DBUS_HANDLER_RESULT_HANDLED;
+}
+
+void Service::run(bool &finish, bool timeout)
+{
+ using namespace std::chrono;
+ high_resolution_clock::time_point tpEnd = high_resolution_clock::now() + seconds(5);
+ while (!finish) {
+ m_connection.readWrite(1000);
+
+ high_resolution_clock::time_point tp = high_resolution_clock::now();
+ if (tp > tpEnd) {
+ if (timeout)
+ return;
+ RUNNER_FAIL_MSG("Timeout not expected");
+ }
+
+ while(true) {
+ m_errorString.clear();
+ m_exceptionThrown = false;
+
+ m_connection.dispatch();
+ if (!m_messageReceived)
+ break;
+ m_messageReceived = false;
+
+ RUNNER_ASSERT_MSG(!m_exceptionThrown, "Exception thrown while handling message");
+ RUNNER_ASSERT_MSG(m_errorString.empty(), "Error while handling dispatched message. "
+ << m_errorString);
+ }
+ }
+}
+
+} // namespace DBusTest
--- /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 dbus_test_service.h
+ * @author Marcin Niesluchowski <m.niesluchow@samsung.com>
+ * @version 1.0
+ * @brief dbus test service declaration
+ */
+
+#ifndef DBUS_TESTS_COMMON_DBUS_TEST_SERVICE_H
+#define DBUS_TESTS_COMMON_DBUS_TEST_SERVICE_H
+
+#include <dbus_test_service_object.h>
+
+#include <dbus_connection.h>
+
+#include <string>
+
+namespace DBusTest
+{
+
+class ServiceCreds
+{
+public:
+ ServiceCreds(const std::string &name);
+ ~ServiceCreds() = default;
+
+ const std::string& connectionName() const;
+ const std::string& objectPath() const;
+ const std::string& interface() const;
+
+private:
+ std::string m_connectionName;
+ std::string m_objectPath;
+ std::string m_interface;
+};
+
+class Service
+{
+public:
+ Service(const ServiceCreds &serviceCreds);
+ Service(const Service &other) = delete;
+ ~Service() = default;
+
+ Service& operator=(const Service &other) = delete;
+
+ void insertMethodHandler(const std::string &method,
+ const MessageHandler &messageHandler);
+ void run(bool &finish, bool timeout);
+
+private:
+ static DBusHandlerResult handleMessage(DBusConnection *connection,
+ DBusMessage *message,
+ void *userData);
+
+ DBus::Connection m_connection;
+ ServiceObject m_object;
+ bool m_messageReceived;
+ bool m_exceptionThrown;
+ std::string m_errorString;
+};
+
+} // namespace DBusTest
+
+#endif // DBUS_TESTS_COMMON_DBUS_TEST_SERVICE_H
#include <cynara_test_admin.h>
#include <dbus_connection.h>
#include <dbus_test_busconfig_writer.h>
+#include <dbus_test_commons.h>
#include <smack_access.h>
#include <tests_common.h>
static const std::string ROOT_UID_STR("0");
-static const std::string CONNECTION_NAME_PREFIX("com.security_tests");
-
-static const std::string connectionNameFromStr(const std::string &str)
-{
- return CONNECTION_NAME_PREFIX + "." + str;
-}
-
static const std::string privilegeFromStr(const std::string &str)
{
return str + "Privilege";