• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef MOCK_OHOS_ABILITY_RUNTIME_MOCK_APP_SPAWN_SOCKET_H
17 #define MOCK_OHOS_ABILITY_RUNTIME_MOCK_APP_SPAWN_SOCKET_H
18 
19 #include "gmock/gmock.h"
20 #include "app_spawn_socket.h"
21 #include "app_spawn_msg_wrapper.h"
22 #include "hilog_wrapper.h"
23 #include "securec.h"
24 
25 namespace OHOS {
26 namespace AppExecFwk {
27 class MockAppSpawnSocket : public AppSpawnSocket {
28 public:
MockAppSpawnSocket()29     MockAppSpawnSocket() : AppSpawnSocket(false) {}
30     virtual ~MockAppSpawnSocket() = default;
31 
32     MOCK_METHOD0(OpenAppSpawnConnection, ErrCode());
33     MOCK_METHOD0(CloseAppSpawnConnection, void());
34     MOCK_METHOD2(WriteMessage, ErrCode(const void* buf, const int32_t len));
35     MOCK_METHOD2(ReadMessage, ErrCode(void* buf, int32_t len));
ReadImpl(void * buf,int32_t len)36     ErrCode ReadImpl(void* buf, [[maybe_unused]] int32_t len)
37     {
38         if (buf == nullptr) {
39             return ERR_NO_MEMORY;
40         }
41         AppSpawnPidMsg msg;
42         msg.pid = expectPid_;
43         if (memcpy_s(buf, sizeof(msg), msg.pidBuf, sizeof(msg)) != 0) {
44             return ERR_APPEXECFWK_ASSEMBLE_START_MSG_FAILED;
45         }
46         return ERR_OK;
47     }
48 
SetExpectPid(int32_t expectPid)49     void SetExpectPid(int32_t expectPid)
50     {
51         expectPid_ = expectPid;
52     }
53 
54 private:
55     int32_t expectPid_ = 0;
56 };
57 }  // namespace AppExecFwk
58 }  // namespace OHOS
59 #endif  // MOCK_OHOS_ABILITY_RUNTIME_MOCK_APP_SPAWN_SOCKET_H
60