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