Add CynaraTestAsync::StatusMonitor 95/28895/6
authorLukasz Wojciechowski <l.wojciechow@partner.samsung.com>
Thu, 16 Oct 2014 15:25:13 +0000 (17:25 +0200)
committerLukasz Wojciechowski <l.wojciechow@partner.samsung.com>
Thu, 30 Oct 2014 10:22:11 +0000 (11:22 +0100)
Added class wraps functionality of status callbacks.

Change-Id: I8c42a80d02b9092e89d930367632110ca33e3fa9

packaging/security-tests.spec
tests/cynara-tests/CMakeLists.txt
tests/cynara-tests/common/cynara_test_client_async_status_monitor.cpp [new file with mode: 0644]
tests/cynara-tests/common/cynara_test_client_async_status_monitor.h [new file with mode: 0644]

index 10deacb71472be13decaeb3615aeb40e67a7cdf4..cbebcc6ad1e3b8babf5d886d2b9bfafb6e867c04 100644 (file)
@@ -23,6 +23,7 @@ BuildRequires: pkgconfig(libiri)
 BuildRequires: pkgconfig(sqlite3)
 BuildRequires: pkgconfig(cynara-admin)
 BuildRequires: pkgconfig(cynara-client)
+BuildRequires: pkgconfig(cynara-client-async)
 BuildRequires: pkgconfig(libtzplatform-config)
 BuildRequires: boost-devel
 Requires:   smack
index 8f6983541bb71399fce37953424470d8fb336d33..6ddafdbef2f2c23924ec523576bf7a5e0f071d47 100644 (file)
@@ -8,6 +8,7 @@ PKG_CHECK_MODULES(CYNARA_TARGET_DEP
     libprivilege-control
     cynara-admin
     cynara-client
+    cynara-client-async
     dbus-1
     dbus-glib-1
     )
@@ -16,6 +17,7 @@ PKG_CHECK_MODULES(CYNARA_TARGET_DEP
 SET(CYNARA_TARGET_TEST_SOURCES
     ${PROJECT_SOURCE_DIR}/tests/cynara-tests/common/cynara_test_admin.cpp
     ${PROJECT_SOURCE_DIR}/tests/cynara-tests/common/cynara_test_client.cpp
+    ${PROJECT_SOURCE_DIR}/tests/cynara-tests/common/cynara_test_client_async_status_monitor.cpp
     ${PROJECT_SOURCE_DIR}/tests/cynara-tests/common/cynara_test_env.cpp
     ${PROJECT_SOURCE_DIR}/tests/cynara-tests/cynara-test.cpp
     ${PROJECT_SOURCE_DIR}/tests/cynara-tests/test_cases.cpp
diff --git a/tests/cynara-tests/common/cynara_test_client_async_status_monitor.cpp b/tests/cynara-tests/common/cynara_test_client_async_status_monitor.cpp
new file mode 100644 (file)
index 0000000..cef7fce
--- /dev/null
@@ -0,0 +1,63 @@
+/*
+ * Copyright (c) 2014 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.
+ */
+
+#include <cynara_test_client_async_status_monitor.h>
+
+#include <dpl/test/test_runner.h>
+
+namespace CynaraTestClientAsync {
+
+StatusMonitor::StatusMonitor()
+    : m_fd(-1), m_status(CYNARA_STATUS_FOR_READ)
+{
+}
+
+void StatusMonitor::updateStatus(int oldFd, int newFd, cynara_async_status status, void *data)
+{
+    StatusMonitor *monitor = reinterpret_cast<StatusMonitor*>(data);
+    RUNNER_ASSERT_MSG(monitor != nullptr,
+                         "Bad user data (nullptr) in status callback.");
+
+    RUNNER_ASSERT_MSG(monitor->m_fd == oldFd,
+                         "fd value mismatch: "
+                             << " last saved fd = " << monitor->m_fd << ","
+                             << " callback oldFd = " << oldFd << ".");
+
+    monitor->m_fd = newFd;
+    monitor->m_status = status;
+}
+
+int StatusMonitor::getFd(void) const
+{
+    return m_fd;
+}
+
+enum SocketStatus StatusMonitor::getStatus(void) const
+{
+    if (m_fd == -1)
+        return DISCONNECTED;
+
+    switch (m_status) {
+        case CYNARA_STATUS_FOR_READ:
+            return READ;
+        case CYNARA_STATUS_FOR_RW:
+            return READWRITE;
+    }
+    RUNNER_FAIL_MSG("Unknown cynara socket status = " << m_status << ","
+                        << " fd = " << m_fd << ".");
+}
+
+}// namespace CynaraTestClientAsync
diff --git a/tests/cynara-tests/common/cynara_test_client_async_status_monitor.h b/tests/cynara-tests/common/cynara_test_client_async_status_monitor.h
new file mode 100644 (file)
index 0000000..30a099d
--- /dev/null
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) 2014 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.
+ */
+
+#ifndef CYNARA_TEST_CLIENT_ASYNC_STATUS_MONITOR_H
+#define CYNARA_TEST_CLIENT_ASYNC_STATUS_MONITOR_H
+
+#include <cynara-client-async.h>
+
+namespace CynaraTestClientAsync {
+
+enum SocketStatus
+{
+    READ,
+    READWRITE,
+    DISCONNECTED,
+};
+
+class StatusMonitor
+{
+public:
+
+    StatusMonitor();
+
+    static void updateStatus(int oldFd, int newFd, cynara_async_status status, void *data);
+
+    int getFd(void) const;
+    enum SocketStatus getStatus(void) const;
+
+private:
+    int m_fd;
+    cynara_async_status m_status;
+};
+
+}// namespace CynaraTestClientAsync
+
+#endif // CYNARA_TEST_CLIENT_ASYNC_STATUS_MONITOR_H