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 HIPERF_OPTION_TEST_H
17 #define HIPERF_OPTION_TEST_H
18
19 #include <gmock/gmock.h>
20 #include <gtest/gtest.h>
21
22 #include "option.h"
23
24 namespace OHOS {
25 namespace Developtools {
26 namespace HiPerf {
27 static std::string TEST_OPTION_CMD_EMPTY = "";
28 static std::string TEST_OPTION_CMD_NO_PREFIX = "TEST_OPTION_CMD";
29 static std::string TEST_OPTION_CMD_ERR_PREFIX = "TEST_OPTION_CMD";
30 static std::string TEST_OPTION_CMD_1 = "-TEST_OPTION_CMD_1";
31 static std::string TEST_OPTION_CMD_2 = "-TEST_OPTION_CMD_2";
32 static std::string TEST_OPTION_CMD_3 = "-TEST_OPTION_CMD_3";
33 static std::string TEST_NO_OPTION_CMD = "TEST_NO_OPTION_CMD";
34 static std::string TEST_OPTION_BRIEF = " TEST_BRIEF\n";
35 static std::string TEST_OPTION_HELP = " TEST_HELP\n";
36
37 static std::string OPTION_NAME = "--debug";
38 static std::string OPTION_ERROR_NAME = "--nodebug";
39 static std::string OPTION_NAME_ONLY = "--nameonly";
40 static std::string OPTION_NAME_VOID = "--void";
41 static std::string OPTION_ILLEGAL_NAME = "illegal";
42 static std::string OPTION_STRING_VALUE = "3";
43 static std::string OPTION_STRING_THREE_VALUES = "1,2,3";
44 static std::string OPTION_STRING_THREE_ILLEGAL_VALUES = "1,a,3";
45 static std::string OPTION_ERROR_VALUE = "4";
46 static const std::string OPTION_ILLEGAL_INT = "illegal_int";
47 static const int OPTION_INT_VALUE = std::stoi(OPTION_STRING_VALUE);
48
49 static const std::vector<std::string> ONE_ARGS = {OPTION_NAME};
50 static const std::vector<std::string> ONE_ARGS_WITH_VALUE = {OPTION_NAME, OPTION_STRING_VALUE};
51
52 static const std::vector<std::string> TWO_ARGS = {OPTION_NAME, OPTION_NAME};
53 static const std::vector<std::string> TWO_ARGS_WITH_VALUE = {
54 OPTION_NAME,
55 OPTION_STRING_VALUE,
56 OPTION_NAME,
57 OPTION_STRING_VALUE,
58 };
59
60 static const std::vector<std::string> TWO_ERROR_ARGS = {OPTION_ERROR_NAME, OPTION_ERROR_NAME};
61 static const std::vector<std::string> TWO_ERROR_WITH_VALUE = {
62 OPTION_ERROR_NAME,
63 OPTION_STRING_VALUE,
64 OPTION_ERROR_NAME,
65 OPTION_STRING_VALUE,
66 };
67
68 static const std::vector<std::string> MIX_ARGS_1 = {
69 OPTION_NAME,
70 OPTION_ERROR_NAME,
71 };
72 static const std::vector<std::string> MIX_ARGS_1_WITH_VALUE = {
73 OPTION_NAME,
74 OPTION_STRING_VALUE,
75 OPTION_ERROR_NAME,
76 OPTION_STRING_VALUE,
77 };
78 static const std::vector<std::string> MIX_ARGS_2 = {
79 OPTION_ERROR_NAME,
80 OPTION_NAME,
81 };
82 static const std::vector<std::string> MIX_ARGS_2_WITH_VALUE = {
83 OPTION_ERROR_NAME,
84 OPTION_STRING_VALUE,
85 OPTION_NAME,
86 OPTION_STRING_VALUE,
87 };
88
89 static const std::vector<std::string> MIX_ARGS_2_WITH_ILLEGAL_VALUE = {
90 OPTION_ERROR_NAME,
91 OPTION_ILLEGAL_INT,
92 OPTION_NAME,
93 OPTION_ILLEGAL_INT,
94 };
95
OptionAlwaysFalse(const std::vector<std::string> & args)96 static bool OptionAlwaysFalse(const std::vector<std::string> &args)
97 {
98 printf("'%s'\n", __FUNCTION__);
99 return false;
100 }
OptionAlwaysTrue(const std::vector<std::string> & args)101 static bool OptionAlwaysTrue(const std::vector<std::string> &args)
102 {
103 return true;
104 }
105 } // namespace HiPerf
106 } // namespace Developtools
107 } // namespace OHOS
108 #endif // HIPERF_OPTION_TEST_H