Add CynaraTestAsync::Client 97/28897/7
authorLukasz Wojciechowski <l.wojciechow@partner.samsung.com>
Thu, 16 Oct 2014 17:21:58 +0000 (19:21 +0200)
committerLukasz Wojciechowski <l.wojciechow@partner.samsung.com>
Thu, 30 Oct 2014 10:34:36 +0000 (11:34 +0100)
This is a class that will wrap usage of libcynara-client-async API.

Change-Id: I89124b57c811e016854122fec6b2cf0ddbaa0525

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

index 6ddafdbef2f2c23924ec523576bf7a5e0f071d47..b47887199aca575ab5e87bdca7454217cce114e6 100644 (file)
@@ -17,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_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
diff --git a/tests/cynara-tests/common/cynara_test_client_async_client.cpp b/tests/cynara-tests/common/cynara_test_client_async_client.cpp
new file mode 100644 (file)
index 0000000..d19a1c2
--- /dev/null
@@ -0,0 +1,61 @@
+/*
+ * 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_client.h>
+
+#include <dpl/test/test_runner.h>
+
+#include <cynara-client-async.h>
+
+#include <exception>
+
+namespace CynaraTestClientAsync {
+
+Client::Client()
+    : m_cynara(nullptr)
+{
+    int ret = cynara_async_initialize(&m_cynara, nullptr, StatusMonitor::updateStatus,
+                                      reinterpret_cast<void*>(&m_statusMonitor));
+    RUNNER_ASSERT_MSG(ret == CYNARA_API_SUCCESS,
+                         "cynara_async_initialize() failed. ret = " << ret << ".");
+    RUNNER_ASSERT_MSG(m_cynara != nullptr, "cynara_async struct was not initialized.");
+
+    assertStatus(DISCONNECTED);
+}
+
+Client::~Client() noexcept(false)
+{
+    bool oops = std::uncaught_exception();
+    try {
+        cynara_async_finish(m_cynara);
+        assertStatus(DISCONNECTED);
+    } catch (...) {
+        if (!oops)
+            throw;
+        RUNNER_ERROR_MSG("Error: more exceptions thrown while releasing CynaraTestAsync::Client.");
+    }
+}
+
+void Client::assertStatus(enum SocketStatus expectedStatus)
+{
+    enum SocketStatus currentStatus = m_statusMonitor.getStatus();
+    RUNNER_ASSERT_MSG(currentStatus == expectedStatus,
+                         "SocketStatus mismatch: "
+                             << " currentStatus = " << currentStatus << ","
+                             << " expectedStatus = " << expectedStatus << ".");
+}
+
+}// namespace CynaraTestClientAsync
diff --git a/tests/cynara-tests/common/cynara_test_client_async_client.h b/tests/cynara-tests/common/cynara_test_client_async_client.h
new file mode 100644 (file)
index 0000000..9c57f20
--- /dev/null
@@ -0,0 +1,42 @@
+/*
+ * 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_CLIENT_H
+#define CYNARA_TEST_CLIENT_ASYNC_CLIENT_H
+
+#include <cynara_test_client_async_status_monitor.h>
+
+#include <cynara-client-async.h>
+
+namespace CynaraTestClientAsync {
+
+class Client
+{
+public:
+    Client();
+    ~Client() noexcept(false);
+
+    void assertStatus(enum SocketStatus expectedStatus);
+
+private:
+    struct cynara_async *m_cynara;
+
+    StatusMonitor m_statusMonitor;
+};
+
+}// namespace CynaraTestClientAsync
+
+#endif // CYNARA_TEST_CLIENT_ASYNC_CLIENT_H