Merging tizen into ckm. Stage 1.
[platform/core/test/security-tests.git] / tests / cynara-tests / common / cynara_test_client_async_client.h
1 /*
2  * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  *    Licensed under the Apache License, Version 2.0 (the "License");
5  *    you may not use this file except in compliance with the License.
6  *    You may obtain a copy of the License at
7  *
8  *        http://www.apache.org/licenses/LICENSE-2.0
9  *
10  *    Unless required by applicable law or agreed to in writing, software
11  *    distributed under the License is distributed on an "AS IS" BASIS,
12  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  *    See the License for the specific language governing permissions and
14  *    limitations under the License.
15  */
16
17 #ifndef CYNARA_TEST_CLIENT_ASYNC_CLIENT_H
18 #define CYNARA_TEST_CLIENT_ASYNC_CLIENT_H
19
20 #include <cynara_test_client_async_request_monitor.h>
21 #include <cynara_test_client_async_status_monitor.h>
22 #include <cynara_test_commons.h>
23
24 #include <cynara-client-async.h>
25
26 #include <string>
27 #include <sys/types.h>
28
29 namespace CynaraTestClientAsync {
30
31 struct CheckData
32 {
33     std::string m_client;
34     std::string m_session;
35     std::string m_user;
36     std::string m_privilege;
37
38     CheckData(const std::string &major, const std::string &minor = "");
39     CheckData(const std::string &major, int minor);
40
41     CheckKey toAdminPolicy();
42 };
43
44 class Client
45 {
46 public:
47     enum TimeoutExpectation {
48         EXPECT_TIMEOUT,
49         EXPECT_NO_TIMEOUT,
50         IGNORE_TIMEOUT,
51     };
52
53     Client(const StatusFunction &userFunction = StatusFunction());
54     ~Client() noexcept(false);
55
56     void assertStatus(enum SocketStatus expectedStatus);
57     void checkCache(const CheckData &checkData, int expectedResult);
58     void createRequest(const CheckData &checkData, cynara_check_id &id,
59                        const RequestEntity &callbackData, int expectedResult = CYNARA_API_SUCCESS);
60     void process(int expectedResult = CYNARA_API_SUCCESS,
61                  enum TimeoutExpectation timeoutExpectation = EXPECT_NO_TIMEOUT,
62                  time_t timeoutSeconds = 3);
63     void cancel(cynara_check_id id, int expectedResult = CYNARA_API_SUCCESS);
64
65 private:
66     struct cynara_async *m_cynara;
67
68     StatusMonitor m_statusMonitor;
69     RequestMonitor m_requestMonitor;
70 };
71
72 }// namespace CynaraTestClientAsync
73
74 #endif // CYNARA_TEST_CLIENT_ASYNC_CLIENT_H