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