--- /dev/null
+/*
+ * 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_request_monitor.h>
+
+#include <dpl/test/test_runner.h>
+
+#include <exception>
+
+namespace CynaraTestClientAsync {
+
+RequestMonitor::~RequestMonitor() noexcept(false)
+{
+ bool oops = std::uncaught_exception();
+ try {
+ for (auto ent : m_requests)
+ {
+ RUNNER_ERROR_MSG("There was no callback for request with:"
+ << "id = " << ent.first << ","
+ << "expectedResponse = " << ent.second.m_expectedResponse << ","
+ << "expectedCause = " << ent.second.m_expectedCause << ".");
+ }
+ RUNNER_ASSERT_MSG(m_requests.empty(),
+ m_requests.size() << "requests does not receive callback.");
+ } catch (...) {
+ if (!oops)
+ throw;
+ RUNNER_ERROR_MSG("Error: more exceptions thrown while releasing"
+ " CynaraTestAsync::RequestMonitor.");
+ }
+}
+
+void RequestMonitor::registerRequest(cynara_check_id id, const RequestEntity &request)
+{
+ auto p = m_requests.insert({id, request});
+ RUNNER_ASSERT_MSG(p.second,
+ "Request with id = " << p.first->first << " already exists.");
+}
+
+void RequestMonitor::updateResponse(cynara_check_id checkId, cynara_async_call_cause cause,
+ int response, void *data)
+{
+ RequestMonitor *monitor = reinterpret_cast<RequestMonitor*>(data);
+ RUNNER_ASSERT_MSG(monitor != nullptr,
+ "Bad user data (nullptr) in response callback.");
+
+ auto it = monitor->m_requests.find(checkId);
+ RUNNER_ASSERT_MSG(it != monitor->m_requests.end(),
+ "Received unexpected callback for request:"
+ << "id = " << checkId << ","
+ << "response = " << response << ","
+ << "cause = " << cause << ".");
+
+ RUNNER_ASSERT_MSG(cause == it->second.m_expectedCause,
+ "Unexpected cause in response callback:"
+ << "id = " << checkId << ","
+ << "received response = " << response << ","
+ << "expected response = " << it->second.m_expectedResponse << ","
+ << "received cause = " << cause << ","
+ << "expected cause = " << it->second.m_expectedCause << ".");
+
+ if (cause == CYNARA_CALL_CAUSE_ANSWER)
+ {
+ RUNNER_ASSERT_MSG(response == it->second.m_expectedResponse,
+ "Unexpected response in response callback:"
+ << "id = " << checkId << ","
+ << "received response = " << response << ","
+ << "expected response = " << it->second.m_expectedResponse << ","
+ << "received cause = " << cause << ","
+ << "expected cause = " << it->second.m_expectedCause << ".");
+ }
+
+ if (it->second.m_userFunction)
+ it->second.m_userFunction();
+
+ monitor->m_requests.erase(it);
+}
+
+}// namespace CynaraTestClientAsync
--- /dev/null
+/*
+ * 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_REQUEST_MONITOR_H
+#define CYNARA_TEST_CLIENT_ASYNC_REQUEST_MONITOR_H
+
+#include <cynara-client-async.h>
+
+#include <functional>
+#include <unordered_map>
+
+namespace CynaraTestClientAsync {
+
+typedef std::function<void(void)> RequestFunction;
+
+struct RequestEntity
+{
+ RequestFunction m_userFunction;
+ int m_expectedResponse;
+ cynara_async_call_cause m_expectedCause;
+};
+
+class RequestMonitor
+{
+public:
+ ~RequestMonitor() noexcept(false);
+
+ void registerRequest(cynara_check_id id, const RequestEntity &request);
+
+ static void updateResponse(cynara_check_id checkId, cynara_async_call_cause cause, int response,
+ void *data);
+
+private:
+ std::unordered_map<cynara_check_id, RequestEntity> m_requests;
+};
+
+}// namespace CynaraTestClientAsync
+
+#endif // CYNARA_TEST_CLIENT_ASYNC_REQUEST_MONITOR_H