2 * Copyright (c) 2022 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #ifndef UNIT_TESTS_MOCK_RPC_PORT_MOCK_HH_
18 #define UNIT_TESTS_MOCK_RPC_PORT_MOCK_HH_
21 #include <rpc-port-parcel.h>
22 #include <gmock/gmock.h>
24 #include "mock/module_mock.hh"
26 class RpcPortMock : public virtual ModuleMock {
30 using ::testing::Invoke;
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;
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_) {
43 rpc_port_h port = (rpc_port_h)&dummy;
44 connected_event_cb_("pkgmgr-server", "mockport", port,
45 connected_event_data_);
51 virtual ~RpcPortMock();
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));
64 rpc_port_proxy_connected_event_cb connected_event_cb_ = nullptr;
65 void* connected_event_data_ = nullptr;
68 #endif // UNIT_TESTS_MOCK_RPC_PORT_MOCK_HH_