Refactor slp-pkgmgr with tidl
[platform/core/appfw/slp-pkgmgr.git] / test / unit_tests / mock / rpc_port_mock.hh
1 /*
2  * Copyright (c) 2022 Samsung Electronics Co., Ltd.
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 UNIT_TESTS_MOCK_RPC_PORT_MOCK_HH_
18 #define UNIT_TESTS_MOCK_RPC_PORT_MOCK_HH_
19
20 #include <rpc-port.h>
21 #include <rpc-port-parcel.h>
22 #include <gmock/gmock.h>
23
24 #include "mock/module_mock.hh"
25
26 class RpcPortMock : public virtual ModuleMock {
27  public:
28   RpcPortMock() {
29     using ::testing::_;
30     using ::testing::Invoke;
31
32     ON_CALL(*this, rpc_port_proxy_add_connected_event_cb(_, _, _))
33         .WillByDefault(Invoke([&](rpc_port_proxy_h h,
34             rpc_port_proxy_connected_event_cb cb, void* data) {
35           connected_event_cb_ = cb;
36           connected_event_data_ = data;
37           return 0;
38         }));
39     ON_CALL(*this, rpc_port_proxy_connect_sync(_, _, _))
40         .WillByDefault(Invoke([&](rpc_port_proxy_h, const char*, const char*) {
41           if (connected_event_cb_) {
42             static int dummy;
43             rpc_port_h port = (rpc_port_h)&dummy;
44             connected_event_cb_("pkgmgr-server", "mockport", port,
45                 connected_event_data_);
46           }
47           return 0;
48         }));
49   }
50
51   virtual ~RpcPortMock();
52
53   MOCK_METHOD(int, rpc_port_proxy_connect_sync, (rpc_port_proxy_h,
54       const char*, const char*));
55   MOCK_METHOD(int, rpc_port_read, (rpc_port_h, void*, unsigned int));
56   MOCK_METHOD(int, rpc_port_write, (rpc_port_h, const void*, unsigned int));
57   MOCK_METHOD(int, rpc_port_proxy_add_connected_event_cb,
58       (rpc_port_proxy_h, rpc_port_proxy_connected_event_cb, void*));
59   MOCK_METHOD(int, rpc_port_parcel_create_from_port,
60       (rpc_port_parcel_h*, rpc_port_h));
61   MOCK_METHOD(int, rpc_port_parcel_send, (rpc_port_parcel_h, rpc_port_h));
62
63  private:
64   rpc_port_proxy_connected_event_cb connected_event_cb_ = nullptr;
65   void* connected_event_data_ = nullptr;
66 };
67
68 #endif  // UNIT_TESTS_MOCK_RPC_PORT_MOCK_HH_