1 /*
2 * Copyright (C) 2022 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 #include <string>
17 #include <vector>
18
19 #include "ipc_debug.h"
20 #include "ipc_skeleton.h"
21 #include "test_client.h"
22
23 using namespace OHOS;
24 using namespace OHOS::HiviewDFX;
25 static constexpr HiLogLabel LABEL = { LOG_CORE, LOG_ID_IPC, "IPCTestClient" };
26
27 enum class TestCommand {
28 TEST_CMD_NONE = 0,
29 TEST_CMD_INT_TRANS = 1,
30 TEST_CMD_STRING_TRANS = 2
31 };
32
33 namespace {
GetArgvOptions(int argc,char ** argv)34 std::vector<std::string> GetArgvOptions(int argc, char **argv)
35 {
36 std::vector<std::string> argvOptions;
37 for (int i = 1; i < argc; i++) {
38 argvOptions.emplace_back(std::string(argv[i]));
39 }
40 return argvOptions;
41 }
42 }
43
main(int argc,char * argv[])44 int main(int argc, char *argv[])
45 {
46 TestCommand commandId = TestCommand::TEST_CMD_INT_TRANS;
47 if (argc > 1) {
48 commandId = TestCommand(atoi(argv[1]));
49 } else {
50 ZLOGE(LABEL, "unknown command");
51 }
52 std::vector<std::string> argvOptions;
53 argvOptions = GetArgvOptions(argc, argv);
54 std::unique_ptr<TestClient> testClient = std::make_unique<TestClient>();
55 if (testClient->ConnectService()) {
56 return -1;
57 }
58
59 ZLOGE(LABEL, "commandId= : %{public}d", commandId);
60 switch (commandId) {
61 case TestCommand::TEST_CMD_INT_TRANS:
62 testClient->StartIntTransaction();
63 break;
64 case TestCommand::TEST_CMD_STRING_TRANS:
65 testClient->StartStringTransaction();
66 break;
67 default:
68 ZLOGI(LABEL, "main arg error");
69 break;
70 }
71
72 IPCSkeleton::JoinWorkThread();
73 return 0;
74 }
75