From 0c663c2932ad112dc995a49d2d251238cabb79e5 Mon Sep 17 00:00:00 2001 From: Lukasz Wojciechowski Date: Thu, 16 Oct 2014 19:21:58 +0200 Subject: [PATCH] Add CynaraTestAsync::Client This is a class that will wrap usage of libcynara-client-async API. Change-Id: I89124b57c811e016854122fec6b2cf0ddbaa0525 --- tests/cynara-tests/CMakeLists.txt | 1 + .../common/cynara_test_client_async_client.cpp | 61 ++++++++++++++++++++++ .../common/cynara_test_client_async_client.h | 42 +++++++++++++++ 3 files changed, 104 insertions(+) create mode 100644 tests/cynara-tests/common/cynara_test_client_async_client.cpp create mode 100644 tests/cynara-tests/common/cynara_test_client_async_client.h diff --git a/tests/cynara-tests/CMakeLists.txt b/tests/cynara-tests/CMakeLists.txt index 6ddafdb..b478871 100644 --- a/tests/cynara-tests/CMakeLists.txt +++ b/tests/cynara-tests/CMakeLists.txt @@ -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 index 0000000..d19a1c2 --- /dev/null +++ b/tests/cynara-tests/common/cynara_test_client_async_client.cpp @@ -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 + +#include + +#include + +#include + +namespace CynaraTestClientAsync { + +Client::Client() + : m_cynara(nullptr) +{ + int ret = cynara_async_initialize(&m_cynara, nullptr, StatusMonitor::updateStatus, + reinterpret_cast(&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 index 0000000..9c57f20 --- /dev/null +++ b/tests/cynara-tests/common/cynara_test_client_async_client.h @@ -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 + +#include + +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 -- 2.7.4