1b1994897Sopenharmony_ci/*
2b1994897Sopenharmony_ci * Copyright (c) 2021-2022 Huawei Device Co., Ltd.
3b1994897Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4b1994897Sopenharmony_ci * you may not use this file except in compliance with the License.
5b1994897Sopenharmony_ci * You may obtain a copy of the License at
6b1994897Sopenharmony_ci *
7b1994897Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0
8b1994897Sopenharmony_ci *
9b1994897Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10b1994897Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11b1994897Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12b1994897Sopenharmony_ci * See the License for the specific language governing permissions and
13b1994897Sopenharmony_ci * limitations under the License.
14b1994897Sopenharmony_ci */
15b1994897Sopenharmony_ci
16b1994897Sopenharmony_ci#include "utils/pandargs.h"
17b1994897Sopenharmony_ci
18b1994897Sopenharmony_ci#include <gtest/gtest.h>
19b1994897Sopenharmony_ci
20b1994897Sopenharmony_cinamespace panda::test {
21b1994897Sopenharmony_ci
22b1994897Sopenharmony_cistatic const bool REF_DEF_BOOL = false;
23b1994897Sopenharmony_cistatic const int REF_DEF_INT = 0;
24b1994897Sopenharmony_cistatic const double REF_DEF_DOUBLE = 1.0;
25b1994897Sopenharmony_cistatic const std::string REF_DEF_STRING = "noarg";
26b1994897Sopenharmony_cistatic const uint32_t REF_DEF_UINT32 = 0;
27b1994897Sopenharmony_cistatic const uint64_t REF_DEF_UINT64 = 0;
28b1994897Sopenharmony_cistatic const arg_list_t REF_DEF_DLIST = arg_list_t();
29b1994897Sopenharmony_cistatic const arg_list_t REF_DEF_LIST = arg_list_t();
30b1994897Sopenharmony_ci
31b1994897Sopenharmony_ciPandArg<bool> PAB("bool", REF_DEF_BOOL, "Sample boolean argument");
32b1994897Sopenharmony_ciPandArg<int> PAI("int", REF_DEF_INT, "Sample integer argument");
33b1994897Sopenharmony_ciPandArg<double> PAD("double", REF_DEF_DOUBLE, "Sample rational argument");
34b1994897Sopenharmony_ciPandArg<std::string> PAS("string", REF_DEF_STRING, "Sample string argument");
35b1994897Sopenharmony_ciPandArg<uint32_t> PAU32("uint32", REF_DEF_UINT32, "Sample uint32 argument");
36b1994897Sopenharmony_ciPandArg<uint64_t> PAU64("uint64", REF_DEF_UINT64, "Sample uint64 argument");
37b1994897Sopenharmony_ciPandArg<arg_list_t> PALD("dlist", REF_DEF_DLIST, "Sample delimiter list argument", ":");
38b1994897Sopenharmony_ciPandArg<arg_list_t> PAL("list", REF_DEF_LIST, "Sample list argument");
39b1994897Sopenharmony_ci
40b1994897Sopenharmony_ci// The numbers -100 and 100 are used to initialize the range of the variable PAIR
41b1994897Sopenharmony_ciPandArg<int> PAIR("rint", REF_DEF_INT, "Integer argument with range", -100, 100);
42b1994897Sopenharmony_ci
43b1994897Sopenharmony_ci// The numbers 0 and 1000000000 are used to initialize the range of the variable PAUR32
44b1994897Sopenharmony_ciPandArg<uint32_t> PAUR32("ruint32", REF_DEF_UINT64, "uint32 argument with range", 0, 1000000000);
45b1994897Sopenharmony_ci
46b1994897Sopenharmony_ci// The numbers 0 and 100000000000 are used to initialize the range of the variable PAUR64
47b1994897Sopenharmony_ciPandArg<uint64_t> PAUR64("ruint64", REF_DEF_UINT64, "uint64 argument with range", 0, 100000000000);
48b1994897Sopenharmony_ci
49b1994897Sopenharmony_ciPandArgParser PA_PARSER;
50b1994897Sopenharmony_ci
51b1994897Sopenharmony_ciHWTEST(libpandargs, TestAdd, testing::ext::TestSize.Level0)
52b1994897Sopenharmony_ci{
53b1994897Sopenharmony_ci    EXPECT_FALSE(PA_PARSER.Add(nullptr));
54b1994897Sopenharmony_ci    EXPECT_TRUE(PA_PARSER.Add(&PAB));
55b1994897Sopenharmony_ci    EXPECT_TRUE(PA_PARSER.Add(&PAI));
56b1994897Sopenharmony_ci    EXPECT_TRUE(PA_PARSER.Add(&PAD));
57b1994897Sopenharmony_ci    EXPECT_TRUE(PA_PARSER.Add(&PAS));
58b1994897Sopenharmony_ci    EXPECT_TRUE(PA_PARSER.Add(&PAU32));
59b1994897Sopenharmony_ci    EXPECT_TRUE(PA_PARSER.Add(&PAU64));
60b1994897Sopenharmony_ci    EXPECT_TRUE(PA_PARSER.Add(&PALD));
61b1994897Sopenharmony_ci    EXPECT_TRUE(PA_PARSER.Add(&PAL));
62b1994897Sopenharmony_ci    EXPECT_TRUE(PA_PARSER.Add(&PAIR));
63b1994897Sopenharmony_ci    EXPECT_TRUE(PA_PARSER.Add(&PAUR32));
64b1994897Sopenharmony_ci    EXPECT_TRUE(PA_PARSER.Add(&PAUR64));
65b1994897Sopenharmony_ci}
66b1994897Sopenharmony_ci
67b1994897Sopenharmony_ciPandArg<bool> T_PAB("tail_bool", REF_DEF_BOOL, "Sample tail boolean argument");
68b1994897Sopenharmony_ciPandArg<int> T_PAI("tail_int", REF_DEF_INT, "Sample tail integer argument");
69b1994897Sopenharmony_ciPandArg<double> T_PAD("tail_double", REF_DEF_DOUBLE, "Sample tail rational argument");
70b1994897Sopenharmony_ciPandArg<std::string> T_PAS("tail_string", REF_DEF_STRING, "Sample tail string argument");
71b1994897Sopenharmony_ciPandArg<uint32_t> T_PAU32("tail_uint32", REF_DEF_UINT32, "Sample tail uint32 argument");
72b1994897Sopenharmony_ciPandArg<uint64_t> T_PAU64("tail_uint64", REF_DEF_UINT64, "Sample tail uint64 argument");
73b1994897Sopenharmony_ci
74b1994897Sopenharmony_ci// expect all arguments are set in parser
75b1994897Sopenharmony_ciHWTEST(libpandargs, TestIsArgSet, testing::ext::TestSize.Level0)
76b1994897Sopenharmony_ci{
77b1994897Sopenharmony_ci    EXPECT_TRUE(PA_PARSER.IsArgSet(&PAB));
78b1994897Sopenharmony_ci    EXPECT_TRUE(PA_PARSER.IsArgSet(PAB.GetName()));
79b1994897Sopenharmony_ci    EXPECT_TRUE(PA_PARSER.IsArgSet(&PAI));
80b1994897Sopenharmony_ci    EXPECT_TRUE(PA_PARSER.IsArgSet(PAI.GetName()));
81b1994897Sopenharmony_ci    EXPECT_TRUE(PA_PARSER.IsArgSet(&PAD));
82b1994897Sopenharmony_ci    EXPECT_TRUE(PA_PARSER.IsArgSet(PAD.GetName()));
83b1994897Sopenharmony_ci    EXPECT_TRUE(PA_PARSER.IsArgSet(&PAS));
84b1994897Sopenharmony_ci    EXPECT_TRUE(PA_PARSER.IsArgSet(PAS.GetName()));
85b1994897Sopenharmony_ci    EXPECT_TRUE(PA_PARSER.IsArgSet(&PAU32));
86b1994897Sopenharmony_ci    EXPECT_TRUE(PA_PARSER.IsArgSet(PAU32.GetName()));
87b1994897Sopenharmony_ci    EXPECT_TRUE(PA_PARSER.IsArgSet(&PAU64));
88b1994897Sopenharmony_ci    EXPECT_TRUE(PA_PARSER.IsArgSet(PAU64.GetName()));
89b1994897Sopenharmony_ci    EXPECT_TRUE(PA_PARSER.IsArgSet(&PALD));
90b1994897Sopenharmony_ci    EXPECT_TRUE(PA_PARSER.IsArgSet(PALD.GetName()));
91b1994897Sopenharmony_ci    EXPECT_TRUE(PA_PARSER.IsArgSet(&PAL));
92b1994897Sopenharmony_ci    EXPECT_TRUE(PA_PARSER.IsArgSet(PAL.GetName()));
93b1994897Sopenharmony_ci    EXPECT_TRUE(PA_PARSER.IsArgSet(&PAIR));
94b1994897Sopenharmony_ci    EXPECT_TRUE(PA_PARSER.IsArgSet(PAIR.GetName()));
95b1994897Sopenharmony_ci    EXPECT_TRUE(PA_PARSER.IsArgSet(&PAUR32));
96b1994897Sopenharmony_ci    EXPECT_TRUE(PA_PARSER.IsArgSet(PAUR32.GetName()));
97b1994897Sopenharmony_ci    EXPECT_TRUE(PA_PARSER.IsArgSet(&PAUR64));
98b1994897Sopenharmony_ci    EXPECT_TRUE(PA_PARSER.IsArgSet(PAUR64.GetName()));
99b1994897Sopenharmony_ci}
100b1994897Sopenharmony_ci
101b1994897Sopenharmony_ci// expect default values and types are consistent
102b1994897Sopenharmony_ciHWTEST(libpandargs, TestConsistent, testing::ext::TestSize.Level0)
103b1994897Sopenharmony_ci{
104b1994897Sopenharmony_ci    EXPECT_EQ(PAB.GetDefaultValue(), REF_DEF_BOOL);
105b1994897Sopenharmony_ci    EXPECT_EQ(PAB.GetDefaultValue(), PAB.GetValue());
106b1994897Sopenharmony_ci    EXPECT_EQ(PAB.GetType(), PandArgType::BOOL);
107b1994897Sopenharmony_ci
108b1994897Sopenharmony_ci    EXPECT_EQ(PAI.GetDefaultValue(), REF_DEF_INT);
109b1994897Sopenharmony_ci    EXPECT_EQ(PAI.GetDefaultValue(), PAI.GetValue());
110b1994897Sopenharmony_ci    EXPECT_EQ(PAI.GetType(), PandArgType::INTEGER);
111b1994897Sopenharmony_ci
112b1994897Sopenharmony_ci    EXPECT_DOUBLE_EQ(PAD.GetValue(), REF_DEF_DOUBLE);
113b1994897Sopenharmony_ci    EXPECT_DOUBLE_EQ(PAD.GetDefaultValue(), PAD.GetValue());
114b1994897Sopenharmony_ci    EXPECT_EQ(PAD.GetType(), PandArgType::DOUBLE);
115b1994897Sopenharmony_ci
116b1994897Sopenharmony_ci    EXPECT_EQ(PAS.GetDefaultValue(), REF_DEF_STRING);
117b1994897Sopenharmony_ci    EXPECT_EQ(PAS.GetDefaultValue(), PAS.GetValue());
118b1994897Sopenharmony_ci    EXPECT_EQ(PAS.GetType(), PandArgType::STRING);
119b1994897Sopenharmony_ci
120b1994897Sopenharmony_ci    EXPECT_EQ(PAU32.GetDefaultValue(), REF_DEF_UINT32);
121b1994897Sopenharmony_ci    EXPECT_EQ(PAU32.GetDefaultValue(), PAU32.GetValue());
122b1994897Sopenharmony_ci    EXPECT_EQ(PAU32.GetType(), PandArgType::UINT32);
123b1994897Sopenharmony_ci
124b1994897Sopenharmony_ci    EXPECT_EQ(PAU64.GetDefaultValue(), REF_DEF_UINT64);
125b1994897Sopenharmony_ci    EXPECT_EQ(PAU64.GetDefaultValue(), PAU64.GetValue());
126b1994897Sopenharmony_ci    EXPECT_EQ(PAU64.GetType(), PandArgType::UINT64);
127b1994897Sopenharmony_ci
128b1994897Sopenharmony_ci    EXPECT_TRUE(PALD.GetValue().empty());
129b1994897Sopenharmony_ci    EXPECT_EQ(PALD.GetDefaultValue(), PALD.GetValue());
130b1994897Sopenharmony_ci    EXPECT_EQ(PALD.GetType(), PandArgType::LIST);
131b1994897Sopenharmony_ci
132b1994897Sopenharmony_ci    EXPECT_TRUE(PAL.GetValue().empty());
133b1994897Sopenharmony_ci    EXPECT_EQ(PAL.GetDefaultValue(), PAL.GetValue());
134b1994897Sopenharmony_ci    EXPECT_EQ(PAL.GetType(), PandArgType::LIST);
135b1994897Sopenharmony_ci
136b1994897Sopenharmony_ci    EXPECT_EQ(PAIR.GetDefaultValue(), REF_DEF_INT);
137b1994897Sopenharmony_ci    EXPECT_EQ(PAIR.GetDefaultValue(), PAIR.GetValue());
138b1994897Sopenharmony_ci    EXPECT_EQ(PAIR.GetType(), PandArgType::INTEGER);
139b1994897Sopenharmony_ci
140b1994897Sopenharmony_ci    EXPECT_EQ(PAUR32.GetDefaultValue(), REF_DEF_UINT64);
141b1994897Sopenharmony_ci    EXPECT_EQ(PAUR32.GetDefaultValue(), PAUR32.GetValue());
142b1994897Sopenharmony_ci    EXPECT_EQ(PAUR32.GetType(), PandArgType::UINT32);
143b1994897Sopenharmony_ci
144b1994897Sopenharmony_ci    EXPECT_EQ(PAUR64.GetDefaultValue(), REF_DEF_UINT64);
145b1994897Sopenharmony_ci    EXPECT_EQ(PAUR64.GetDefaultValue(), PAUR64.GetValue());
146b1994897Sopenharmony_ci    EXPECT_EQ(PAUR64.GetType(), PandArgType::UINT64);
147b1994897Sopenharmony_ci}
148b1994897Sopenharmony_ci
149b1994897Sopenharmony_ci// expect false on duplicate argument
150b1994897Sopenharmony_ciHWTEST(libpandargs, TestDuplicate, testing::ext::TestSize.Level0)
151b1994897Sopenharmony_ci{
152b1994897Sopenharmony_ci    PandArg<int> pai_dup("int", 0, "Integer number 0");
153b1994897Sopenharmony_ci    EXPECT_TRUE(PA_PARSER.IsArgSet(pai_dup.GetName()));
154b1994897Sopenharmony_ci    EXPECT_FALSE(PA_PARSER.Add(&pai_dup));
155b1994897Sopenharmony_ci}
156b1994897Sopenharmony_ci
157b1994897Sopenharmony_ci// add tail argument, expect false on duplicate
158b1994897Sopenharmony_ci// erase tail, expect 0 tail size
159b1994897Sopenharmony_ciHWTEST(libpandargs, TestTail, testing::ext::TestSize.Level0)
160b1994897Sopenharmony_ci{
161b1994897Sopenharmony_ci    {
162b1994897Sopenharmony_ci        EXPECT_EQ(PA_PARSER.GetTailSize(), 0U);
163b1994897Sopenharmony_ci        EXPECT_TRUE(PA_PARSER.PushBackTail(&T_PAI));
164b1994897Sopenharmony_ci        EXPECT_EQ(PA_PARSER.GetTailSize(), 1U);
165b1994897Sopenharmony_ci        EXPECT_FALSE(PA_PARSER.PushBackTail(&T_PAI));
166b1994897Sopenharmony_ci        PA_PARSER.PopBackTail();
167b1994897Sopenharmony_ci        EXPECT_EQ(PA_PARSER.GetTailSize(), 0U);
168b1994897Sopenharmony_ci    }
169b1994897Sopenharmony_ci
170b1994897Sopenharmony_ci    {
171b1994897Sopenharmony_ci        ASSERT_EQ(PA_PARSER.GetTailSize(), 0U);
172b1994897Sopenharmony_ci        ASSERT_FALSE(PA_PARSER.PushBackTail(nullptr));
173b1994897Sopenharmony_ci        ASSERT_EQ(PA_PARSER.GetTailSize(), 0U);
174b1994897Sopenharmony_ci        ASSERT_FALSE(PA_PARSER.PopBackTail());
175b1994897Sopenharmony_ci    }
176b1994897Sopenharmony_ci}
177b1994897Sopenharmony_ci
178b1994897Sopenharmony_ci// expect help string formed right
179b1994897Sopenharmony_ciHWTEST(libpandargs, TestString, testing::ext::TestSize.Level0)
180b1994897Sopenharmony_ci{
181b1994897Sopenharmony_ci    std::string ref_string = "--" + PAB.GetName() + ": " + PAB.GetDesc() + "\n";
182b1994897Sopenharmony_ci    ref_string += "--" + PALD.GetName() + ": " + PALD.GetDesc() + "\n";
183b1994897Sopenharmony_ci    ref_string += "--" + PAD.GetName() + ": " + PAD.GetDesc() + "\n";
184b1994897Sopenharmony_ci    ref_string += "--" + PAI.GetName() + ": " + PAI.GetDesc() + "\n";
185b1994897Sopenharmony_ci    ref_string += "--" + PAL.GetName() + ": " + PAL.GetDesc() + "\n";
186b1994897Sopenharmony_ci    ref_string += "--" + PAIR.GetName() + ": " + PAIR.GetDesc() + "\n";
187b1994897Sopenharmony_ci    ref_string += "--" + PAUR32.GetName() + ": " + PAUR32.GetDesc() + "\n";
188b1994897Sopenharmony_ci    ref_string += "--" + PAUR64.GetName() + ": " + PAUR64.GetDesc() + "\n";
189b1994897Sopenharmony_ci    ref_string += "--" + PAS.GetName() + ": " + PAS.GetDesc() + "\n";
190b1994897Sopenharmony_ci    ref_string += "--" + PAU32.GetName() + ": " + PAU32.GetDesc() + "\n";
191b1994897Sopenharmony_ci    ref_string += "--" + PAU64.GetName() + ": " + PAU64.GetDesc() + "\n";
192b1994897Sopenharmony_ci    EXPECT_EQ(PA_PARSER.GetHelpString(), ref_string);
193b1994897Sopenharmony_ci}
194b1994897Sopenharmony_ci
195b1994897Sopenharmony_ci// expect regular args list formed right
196b1994897Sopenharmony_ciHWTEST(libpandargs, TestRegular, testing::ext::TestSize.Level0)
197b1994897Sopenharmony_ci{
198b1994897Sopenharmony_ci    arg_list_t ref_arg_dlist = PALD.GetValue();
199b1994897Sopenharmony_ci    arg_list_t ref_arg_list = PAL.GetValue();
200b1994897Sopenharmony_ci    std::string ref_string = "--" + PAB.GetName() + "=" + std::to_string(PAB.GetValue()) + "\n";
201b1994897Sopenharmony_ci    ref_string += "--" + PALD.GetName() + "=";
202b1994897Sopenharmony_ci    for (const auto &i : ref_arg_dlist) {
203b1994897Sopenharmony_ci        ref_string += i + ", ";
204b1994897Sopenharmony_ci    }
205b1994897Sopenharmony_ci    ref_string += "\n";
206b1994897Sopenharmony_ci    ref_string += "--" + PAD.GetName() + "=" + std::to_string(PAD.GetValue()) + "\n";
207b1994897Sopenharmony_ci    ref_string += "--" + PAI.GetName() + "=" + std::to_string(PAI.GetValue()) + "\n";
208b1994897Sopenharmony_ci    ref_string += "--" + PAL.GetName() + "=";
209b1994897Sopenharmony_ci    for (const auto &i : ref_arg_list) {
210b1994897Sopenharmony_ci        ref_string += i + ", ";
211b1994897Sopenharmony_ci    }
212b1994897Sopenharmony_ci    ref_string += "\n";
213b1994897Sopenharmony_ci    ref_string += "--" + PAIR.GetName() + "=" + std::to_string(PAIR.GetValue()) + "\n";
214b1994897Sopenharmony_ci    ref_string += "--" + PAUR32.GetName() + "=" + std::to_string(PAUR32.GetValue()) + "\n";
215b1994897Sopenharmony_ci    ref_string += "--" + PAUR64.GetName() + "=" + std::to_string(PAUR64.GetValue()) + "\n";
216b1994897Sopenharmony_ci    ref_string += "--" + PAS.GetName() + "=" + PAS.GetValue() + "\n";
217b1994897Sopenharmony_ci    ref_string += "--" + PAU32.GetName() + "=" + std::to_string(PAU32.GetValue()) + "\n";
218b1994897Sopenharmony_ci    ref_string += "--" + PAU64.GetName() + "=" + std::to_string(PAU64.GetValue()) + "\n";
219b1994897Sopenharmony_ci    EXPECT_EQ(PA_PARSER.GetRegularArgs(), ref_string);
220b1994897Sopenharmony_ci}
221b1994897Sopenharmony_ci
222b1994897Sopenharmony_ci// expect all boolean values processed right
223b1994897Sopenharmony_ciHWTEST(libpandargs, TestAllBoolean, testing::ext::TestSize.Level0)
224b1994897Sopenharmony_ci{
225b1994897Sopenharmony_ci    static const char *true_values[] = {"true", "on", "1"};
226b1994897Sopenharmony_ci    static const char *false_values[] = {"false", "off", "0"};
227b1994897Sopenharmony_ci    static const int argc_bool_only = 3;
228b1994897Sopenharmony_ci    static const char *argv_bool_only[argc_bool_only];
229b1994897Sopenharmony_ci    argv_bool_only[0] = "gtest_app";
230b1994897Sopenharmony_ci    std::string s = "--" + PAB.GetName();
231b1994897Sopenharmony_ci    argv_bool_only[1] = s.c_str();
232b1994897Sopenharmony_ci
233b1994897Sopenharmony_ci    for (int i = 0; i < 3; i++) {
234b1994897Sopenharmony_ci        argv_bool_only[2] = true_values[i];
235b1994897Sopenharmony_ci        EXPECT_TRUE(PA_PARSER.Parse(argc_bool_only, argv_bool_only));
236b1994897Sopenharmony_ci        EXPECT_TRUE(PAB.GetValue());
237b1994897Sopenharmony_ci    }
238b1994897Sopenharmony_ci    for (int i = 0; i < 3; i++) {
239b1994897Sopenharmony_ci        argv_bool_only[2] = false_values[i];
240b1994897Sopenharmony_ci        EXPECT_TRUE(PA_PARSER.Parse(argc_bool_only, argv_bool_only));
241b1994897Sopenharmony_ci        EXPECT_FALSE(PAB.GetValue());
242b1994897Sopenharmony_ci    }
243b1994897Sopenharmony_ci}
244b1994897Sopenharmony_ci
245b1994897Sopenharmony_ci// expect wrong boolean arguments with "=" processed right
246b1994897Sopenharmony_ciHWTEST(libpandargs, TestWrongBoolean, testing::ext::TestSize.Level0)
247b1994897Sopenharmony_ci{
248b1994897Sopenharmony_ci    static const int argc_bool_only = 2;
249b1994897Sopenharmony_ci    static const char *argv_bool_only[argc_bool_only];
250b1994897Sopenharmony_ci    argv_bool_only[0] = "gtest_app";
251b1994897Sopenharmony_ci    std::string s = "--" + PAB.GetName() + "=";
252b1994897Sopenharmony_ci    argv_bool_only[1] = s.c_str();
253b1994897Sopenharmony_ci    EXPECT_FALSE(PA_PARSER.Parse(argc_bool_only, argv_bool_only));
254b1994897Sopenharmony_ci}
255b1994897Sopenharmony_ci
256b1994897Sopenharmony_ci// expect boolean at the end of arguments line is true
257b1994897Sopenharmony_ciHWTEST(libpandargs, TestBooleanEnd, testing::ext::TestSize.Level0)
258b1994897Sopenharmony_ci{
259b1994897Sopenharmony_ci    static const int argc_bool_only = 2;
260b1994897Sopenharmony_ci    static const char *argv_bool_only[argc_bool_only];
261b1994897Sopenharmony_ci    argv_bool_only[0] = "gtest_app";
262b1994897Sopenharmony_ci    std::string s = "--" + PAB.GetName();
263b1994897Sopenharmony_ci    argv_bool_only[1] = s.c_str();
264b1994897Sopenharmony_ci    EXPECT_TRUE(PA_PARSER.Parse(argc_bool_only, argv_bool_only));
265b1994897Sopenharmony_ci    EXPECT_TRUE(PAB.GetValue());
266b1994897Sopenharmony_ci}
267b1994897Sopenharmony_ci
268b1994897Sopenharmony_ci// expect positive and negative integer values processed right
269b1994897Sopenharmony_ciHWTEST(libpandargs, TestInteger, testing::ext::TestSize.Level0)
270b1994897Sopenharmony_ci{
271b1994897Sopenharmony_ci    static const int ref_int_pos = 42422424;
272b1994897Sopenharmony_ci    static const int ref_int_neg = -42422424;
273b1994897Sopenharmony_ci    static const int argc_int_only = 3;
274b1994897Sopenharmony_ci    static const char *argv_int_only[argc_int_only];
275b1994897Sopenharmony_ci    argv_int_only[0] = "gtest_app";
276b1994897Sopenharmony_ci    std::string s = "--" + PAI.GetName();
277b1994897Sopenharmony_ci    argv_int_only[1] = s.c_str();
278b1994897Sopenharmony_ci    argv_int_only[2] = "42422424";
279b1994897Sopenharmony_ci    EXPECT_TRUE(PA_PARSER.Parse(argc_int_only, argv_int_only));
280b1994897Sopenharmony_ci    EXPECT_EQ(PAI.GetValue(), ref_int_pos);
281b1994897Sopenharmony_ci    argv_int_only[2] = "-42422424";
282b1994897Sopenharmony_ci    EXPECT_TRUE(PA_PARSER.Parse(argc_int_only, argv_int_only));
283b1994897Sopenharmony_ci    EXPECT_EQ(PAI.GetValue(), ref_int_neg);
284b1994897Sopenharmony_ci}
285b1994897Sopenharmony_ci
286b1994897Sopenharmony_ci// expect positive and negative double values processed right
287b1994897Sopenharmony_ciHWTEST(libpandargs, TestDouble, testing::ext::TestSize.Level0)
288b1994897Sopenharmony_ci{
289b1994897Sopenharmony_ci    static const double ref_double_pos = 4242.2424;
290b1994897Sopenharmony_ci    static const double ref_double_neg = -4242.2424;
291b1994897Sopenharmony_ci    static const int argc_double_only = 3;
292b1994897Sopenharmony_ci    static const char *argv_double_only[argc_double_only];
293b1994897Sopenharmony_ci    argv_double_only[0] = "gtest_app";
294b1994897Sopenharmony_ci    std::string s = "--" + PAD.GetName();
295b1994897Sopenharmony_ci    argv_double_only[1] = s.c_str();
296b1994897Sopenharmony_ci    argv_double_only[2] = "4242.2424";
297b1994897Sopenharmony_ci    EXPECT_TRUE(PA_PARSER.Parse(argc_double_only, argv_double_only));
298b1994897Sopenharmony_ci    EXPECT_EQ(PAD.GetValue(), ref_double_pos);
299b1994897Sopenharmony_ci    argv_double_only[2] = "-4242.2424";
300b1994897Sopenharmony_ci    EXPECT_TRUE(PA_PARSER.Parse(argc_double_only, argv_double_only));
301b1994897Sopenharmony_ci    EXPECT_EQ(PAD.GetValue(), ref_double_neg);
302b1994897Sopenharmony_ci}
303b1994897Sopenharmony_ci
304b1994897Sopenharmony_ci// expect hex values processed right
305b1994897Sopenharmony_ciHWTEST(libpandargs, TestHex, testing::ext::TestSize.Level0)
306b1994897Sopenharmony_ci{
307b1994897Sopenharmony_ci    static const uint64_t refUint64 = 274877906959;
308b1994897Sopenharmony_ci    static const uint64_t refInt = 64;
309b1994897Sopenharmony_ci    static const int argcUint64Int = 3;
310b1994897Sopenharmony_ci    static const char* argvUint64Int[argcUint64Int];
311b1994897Sopenharmony_ci    argvUint64Int[0] = "gtest_app";
312b1994897Sopenharmony_ci    std::string s = "--" + PAU64.GetName();
313b1994897Sopenharmony_ci    argvUint64Int[1] = s.c_str();
314b1994897Sopenharmony_ci    argvUint64Int[2] = "0x400000000f";
315b1994897Sopenharmony_ci    EXPECT_TRUE(PA_PARSER.Parse(argcUint64Int, argvUint64Int));
316b1994897Sopenharmony_ci    EXPECT_EQ(PAU64.GetValue(), refUint64);
317b1994897Sopenharmony_ci    argvUint64Int[2] = "0x40";
318b1994897Sopenharmony_ci    EXPECT_TRUE(PA_PARSER.Parse(argcUint64Int, argvUint64Int));
319b1994897Sopenharmony_ci    EXPECT_EQ(PAU64.GetValue(), refInt);
320b1994897Sopenharmony_ci}
321b1994897Sopenharmony_ci
322b1994897Sopenharmony_ci// expect uint32_t values processed right
323b1994897Sopenharmony_ciHWTEST(libpandargs, TestUint32, testing::ext::TestSize.Level0)
324b1994897Sopenharmony_ci{
325b1994897Sopenharmony_ci    static const uint32_t ref_uint32_pos = 4242422424;
326b1994897Sopenharmony_ci    static const int argc_uint32_only = 3;
327b1994897Sopenharmony_ci    static const char *argv_uint32_only[argc_uint32_only];
328b1994897Sopenharmony_ci    argv_uint32_only[0] = "gtest_app";
329b1994897Sopenharmony_ci    std::string s = "--" + PAU32.GetName();
330b1994897Sopenharmony_ci    argv_uint32_only[1] = s.c_str();
331b1994897Sopenharmony_ci    argv_uint32_only[2] = "4242422424";
332b1994897Sopenharmony_ci    EXPECT_TRUE(PA_PARSER.Parse(argc_uint32_only, argv_uint32_only));
333b1994897Sopenharmony_ci    EXPECT_EQ(PAU32.GetValue(), ref_uint32_pos);
334b1994897Sopenharmony_ci}
335b1994897Sopenharmony_ci
336b1994897Sopenharmony_ci// expect uint64_t values processed right
337b1994897Sopenharmony_ciHWTEST(libpandargs, TestUint64, testing::ext::TestSize.Level0)
338b1994897Sopenharmony_ci{
339b1994897Sopenharmony_ci    static const uint64_t ref_uint64_pos = 424242422424;
340b1994897Sopenharmony_ci    static const int argc_uint64_only = 3;
341b1994897Sopenharmony_ci    static const char *argv_uint64_only[argc_uint64_only];
342b1994897Sopenharmony_ci    argv_uint64_only[0] = "gtest_app";
343b1994897Sopenharmony_ci    std::string s = "--" + PAU64.GetName();
344b1994897Sopenharmony_ci    argv_uint64_only[1] = s.c_str();
345b1994897Sopenharmony_ci    argv_uint64_only[2] = "424242422424";
346b1994897Sopenharmony_ci    EXPECT_TRUE(PA_PARSER.Parse(argc_uint64_only, argv_uint64_only));
347b1994897Sopenharmony_ci    EXPECT_EQ(PAU64.GetValue(), ref_uint64_pos);
348b1994897Sopenharmony_ci}
349b1994897Sopenharmony_ci
350b1994897Sopenharmony_ci// expect hex values processed right
351b1994897Sopenharmony_ciHWTEST(libpandargs, TestHexValues, testing::ext::TestSize.Level0)
352b1994897Sopenharmony_ci{
353b1994897Sopenharmony_ci    static const uint64_t ref_uint64 = 274877906944;
354b1994897Sopenharmony_ci    static const uint64_t ref_int = 64;
355b1994897Sopenharmony_ci    static const int argc_uint64_int = 3;
356b1994897Sopenharmony_ci    static const char *argv_uint64_int[argc_uint64_int];
357b1994897Sopenharmony_ci    argv_uint64_int[0] = "gtest_app";
358b1994897Sopenharmony_ci    std::string s = "--" + PAU64.GetName();
359b1994897Sopenharmony_ci    argv_uint64_int[1] = s.c_str();
360b1994897Sopenharmony_ci    argv_uint64_int[2] = "0x4000000000";
361b1994897Sopenharmony_ci    EXPECT_TRUE(PA_PARSER.Parse(argc_uint64_int, argv_uint64_int));
362b1994897Sopenharmony_ci    EXPECT_EQ(PAU64.GetValue(), ref_uint64);
363b1994897Sopenharmony_ci    argv_uint64_int[2] = "0x40";
364b1994897Sopenharmony_ci    EXPECT_TRUE(PA_PARSER.Parse(argc_uint64_int, argv_uint64_int));
365b1994897Sopenharmony_ci    EXPECT_EQ(PAU64.GetValue(), ref_int);
366b1994897Sopenharmony_ci}
367b1994897Sopenharmony_ci
368b1994897Sopenharmony_ci// expect out of range uint32_t values processed right
369b1994897Sopenharmony_ciHWTEST(libpandargs, TestOutUint32, testing::ext::TestSize.Level0)
370b1994897Sopenharmony_ci{
371b1994897Sopenharmony_ci    static const int argc_uint32_only = 3;
372b1994897Sopenharmony_ci    static const char *argv_uint32_only[argc_uint32_only];
373b1994897Sopenharmony_ci    argv_uint32_only[0] = "gtest_app";
374b1994897Sopenharmony_ci    std::string s = "--" + PAU32.GetName();
375b1994897Sopenharmony_ci    argv_uint32_only[1] = s.c_str();
376b1994897Sopenharmony_ci    argv_uint32_only[2] = "424224244242242442422424";
377b1994897Sopenharmony_ci    EXPECT_FALSE(PA_PARSER.Parse(argc_uint32_only, argv_uint32_only));
378b1994897Sopenharmony_ci    argv_uint32_only[2] = "0xffffffffffffffffffffffffff";
379b1994897Sopenharmony_ci    EXPECT_FALSE(PA_PARSER.Parse(argc_uint32_only, argv_uint32_only));
380b1994897Sopenharmony_ci}
381b1994897Sopenharmony_ci
382b1994897Sopenharmony_ci// expect out of range uint64_t values processed right
383b1994897Sopenharmony_ciHWTEST(libpandargs, TestOutUint64, testing::ext::TestSize.Level0)
384b1994897Sopenharmony_ci{
385b1994897Sopenharmony_ci    static const int argc_uint64_only = 3;
386b1994897Sopenharmony_ci    static const char *argv_uint64_only[argc_uint64_only];
387b1994897Sopenharmony_ci    argv_uint64_only[0] = "gtest_app";
388b1994897Sopenharmony_ci    std::string s = "--" + PAU64.GetName();
389b1994897Sopenharmony_ci    argv_uint64_only[1] = s.c_str();
390b1994897Sopenharmony_ci    argv_uint64_only[2] = "424224244242242442422424";
391b1994897Sopenharmony_ci    EXPECT_FALSE(PA_PARSER.Parse(argc_uint64_only, argv_uint64_only));
392b1994897Sopenharmony_ci    argv_uint64_only[2] = "0xffffffffffffffffffffffffff";
393b1994897Sopenharmony_ci    EXPECT_FALSE(PA_PARSER.Parse(argc_uint64_only, argv_uint64_only));
394b1994897Sopenharmony_ci}
395b1994897Sopenharmony_ci
396b1994897Sopenharmony_ci// expect string argument of one word and multiple word processed right
397b1994897Sopenharmony_ciHWTEST(libpandargs, TestStringRange, testing::ext::TestSize.Level0)
398b1994897Sopenharmony_ci{
399b1994897Sopenharmony_ci    static const std::string ref_one_string = "string";
400b1994897Sopenharmony_ci    static const std::string ref_multiple_string = "this is a string";
401b1994897Sopenharmony_ci    static const char *str_argname = "--string";
402b1994897Sopenharmony_ci    static const int argc_one_string = 3;
403b1994897Sopenharmony_ci    static const char *argv_one_string[argc_one_string] = {"gtest_app", str_argname, "string"};
404b1994897Sopenharmony_ci    static const int argc_multiple_string = 3;
405b1994897Sopenharmony_ci    static const char *argv_multiple_string[argc_multiple_string] = {"gtest_app", str_argname, "this is a string"};
406b1994897Sopenharmony_ci    EXPECT_TRUE(PA_PARSER.Parse(argc_multiple_string, argv_multiple_string));
407b1994897Sopenharmony_ci    EXPECT_EQ(PAS.GetValue(), ref_multiple_string);
408b1994897Sopenharmony_ci    EXPECT_TRUE(PA_PARSER.Parse(argc_one_string, argv_one_string));
409b1994897Sopenharmony_ci    EXPECT_EQ(PAS.GetValue(), ref_one_string);
410b1994897Sopenharmony_ci}
411b1994897Sopenharmony_ci
412b1994897Sopenharmony_ci// expect string at the end of line is an empty string
413b1994897Sopenharmony_ciHWTEST(libpandargs, TestStringLine, testing::ext::TestSize.Level0)
414b1994897Sopenharmony_ci{
415b1994897Sopenharmony_ci    static const int argc_string_only = 2;
416b1994897Sopenharmony_ci    static const char *argv_string_only[argc_string_only];
417b1994897Sopenharmony_ci    argv_string_only[0] = "gtest_app";
418b1994897Sopenharmony_ci    std::string s = "--" + PAS.GetName();
419b1994897Sopenharmony_ci    argv_string_only[1] = s.c_str();
420b1994897Sopenharmony_ci    EXPECT_TRUE(PA_PARSER.Parse(argc_string_only, argv_string_only));
421b1994897Sopenharmony_ci    EXPECT_EQ(PAS.GetValue(), "");
422b1994897Sopenharmony_ci}
423b1994897Sopenharmony_ci
424b1994897Sopenharmony_ci// expect list argument processed right
425b1994897Sopenharmony_ciHWTEST(libpandargs, TestList, testing::ext::TestSize.Level0)
426b1994897Sopenharmony_ci{
427b1994897Sopenharmony_ci    PALD.ResetDefaultValue();
428b1994897Sopenharmony_ci    static const arg_list_t ref_list = {"list1", "list2", "list3"};
429b1994897Sopenharmony_ci    std::string s = "--" + PALD.GetName();
430b1994897Sopenharmony_ci    static const char *list_argname = s.c_str();
431b1994897Sopenharmony_ci    static const int argc_list_only = 7;
432b1994897Sopenharmony_ci    static const char *argv_list_only[argc_list_only] = {"gtest_app", list_argname, "list1",
433b1994897Sopenharmony_ci        list_argname, "list2", list_argname, "list3"};
434b1994897Sopenharmony_ci    EXPECT_TRUE(PA_PARSER.Parse(argc_list_only, argv_list_only));
435b1994897Sopenharmony_ci    ASSERT_EQ(PALD.GetValue().size(), ref_list.size());
436b1994897Sopenharmony_ci    for (std::size_t i = 0; i < ref_list.size(); ++i) {
437b1994897Sopenharmony_ci        EXPECT_EQ(PALD.GetValue()[i], ref_list[i]);
438b1994897Sopenharmony_ci    }
439b1994897Sopenharmony_ci}
440b1994897Sopenharmony_ci
441b1994897Sopenharmony_ci// expect list argument without delimiter processed right
442b1994897Sopenharmony_ciHWTEST(libpandargs, TestListDelimiter, testing::ext::TestSize.Level0)
443b1994897Sopenharmony_ci{
444b1994897Sopenharmony_ci    PAL.ResetDefaultValue();
445b1994897Sopenharmony_ci    static const arg_list_t ref_list = {"list1", "list2", "list3", "list4"};
446b1994897Sopenharmony_ci    std::string s = "--" + PAL.GetName();
447b1994897Sopenharmony_ci    static const char *list_argname = s.c_str();
448b1994897Sopenharmony_ci    static const int argc_list_only = 9;
449b1994897Sopenharmony_ci    static const char *argv_list_only[argc_list_only] = {"gtest_app",
450b1994897Sopenharmony_ci        list_argname, "list1", list_argname, "list2", list_argname, "list3", list_argname, "list4"};
451b1994897Sopenharmony_ci    EXPECT_TRUE(PA_PARSER.Parse(argc_list_only, argv_list_only));
452b1994897Sopenharmony_ci    ASSERT_EQ(PAL.GetValue().size(), ref_list.size());
453b1994897Sopenharmony_ci    for (std::size_t i = 0; i < ref_list.size(); ++i) {
454b1994897Sopenharmony_ci        EXPECT_EQ(PAL.GetValue()[i], ref_list[i]);
455b1994897Sopenharmony_ci    }
456b1994897Sopenharmony_ci}
457b1994897Sopenharmony_ci
458b1994897Sopenharmony_ci// expect delimiter list argument processed right
459b1994897Sopenharmony_ciHWTEST(libpandargs, TestDelimiter, testing::ext::TestSize.Level0)
460b1994897Sopenharmony_ci{
461b1994897Sopenharmony_ci    PALD.ResetDefaultValue();
462b1994897Sopenharmony_ci    static const arg_list_t ref_dlist = {"dlist1", "dlist2", "dlist3"};
463b1994897Sopenharmony_ci    std::string s = "--" + PALD.GetName();
464b1994897Sopenharmony_ci    static const char *list_argname = s.c_str();
465b1994897Sopenharmony_ci    static const int argc_dlist_only = 3;
466b1994897Sopenharmony_ci    static const char *argv_dlist_only[argc_dlist_only] = {"gtest_app", list_argname, "dlist1:dlist2:dlist3"};
467b1994897Sopenharmony_ci    EXPECT_TRUE(PA_PARSER.Parse(argc_dlist_only, argv_dlist_only));
468b1994897Sopenharmony_ci    ASSERT_EQ(PALD.GetValue().size(), ref_dlist.size());
469b1994897Sopenharmony_ci    for (std::size_t i = 0; i < ref_dlist.size(); ++i) {
470b1994897Sopenharmony_ci        EXPECT_EQ(PALD.GetValue()[i], ref_dlist[i]);
471b1994897Sopenharmony_ci    }
472b1994897Sopenharmony_ci}
473b1994897Sopenharmony_ci
474b1994897Sopenharmony_ci// expect delimiter and multiple list argument processed right
475b1994897Sopenharmony_ciHWTEST(libpandargs, TestDelimiterList, testing::ext::TestSize.Level0)
476b1994897Sopenharmony_ci{
477b1994897Sopenharmony_ci    PALD.ResetDefaultValue();
478b1994897Sopenharmony_ci    static const arg_list_t ref_list = {"dlist1", "dlist2", "list1", "list2", "dlist3", "dlist4"};
479b1994897Sopenharmony_ci    std::string s = "--" + PALD.GetName();
480b1994897Sopenharmony_ci    static const char *list_argname = s.c_str();
481b1994897Sopenharmony_ci    static const int argc_list = 9;
482b1994897Sopenharmony_ci    static const char *argv_list[argc_list] = {"gtest_app",  list_argname, "dlist1:dlist2", list_argname, "list1",
483b1994897Sopenharmony_ci        list_argname, "list2", list_argname, "dlist3:dlist4"};
484b1994897Sopenharmony_ci    EXPECT_TRUE(PA_PARSER.Parse(argc_list, argv_list));
485b1994897Sopenharmony_ci    ASSERT_EQ(PALD.GetValue().size(), ref_list.size());
486b1994897Sopenharmony_ci    for (std::size_t i = 0; i < ref_list.size(); ++i) {
487b1994897Sopenharmony_ci        EXPECT_EQ(PALD.GetValue()[i], ref_list[i]);
488b1994897Sopenharmony_ci    }
489b1994897Sopenharmony_ci}
490b1994897Sopenharmony_ci
491b1994897Sopenharmony_ci// expect positive and negative integer values with range processed right
492b1994897Sopenharmony_ciHWTEST(libpandargs, TestIntegerRange, testing::ext::TestSize.Level0)
493b1994897Sopenharmony_ci{
494b1994897Sopenharmony_ci    static const int ref_int_pos = 99;
495b1994897Sopenharmony_ci    static const int ref_int_neg = -99;
496b1994897Sopenharmony_ci    static const int argc_int_only = 3;
497b1994897Sopenharmony_ci    static const char *argv_int_only[argc_int_only];
498b1994897Sopenharmony_ci    argv_int_only[0] = "gtest_app";
499b1994897Sopenharmony_ci    std::string s = "--" + PAIR.GetName();
500b1994897Sopenharmony_ci    argv_int_only[1] = s.c_str();
501b1994897Sopenharmony_ci    argv_int_only[2] = "99";
502b1994897Sopenharmony_ci    EXPECT_TRUE(PA_PARSER.Parse(argc_int_only, argv_int_only));
503b1994897Sopenharmony_ci    EXPECT_EQ(PAIR.GetValue(), ref_int_pos);
504b1994897Sopenharmony_ci    argv_int_only[2] = "-99";
505b1994897Sopenharmony_ci    EXPECT_TRUE(PA_PARSER.Parse(argc_int_only, argv_int_only));
506b1994897Sopenharmony_ci    EXPECT_EQ(PAIR.GetValue(), ref_int_neg);
507b1994897Sopenharmony_ci}
508b1994897Sopenharmony_ci
509b1994897Sopenharmony_ci// expect wrong positive and negative integer values with range processed right
510b1994897Sopenharmony_ciHWTEST(libpandargs, TestWrongInteger, testing::ext::TestSize.Level0)
511b1994897Sopenharmony_ci{
512b1994897Sopenharmony_ci    static const int argc_int_only = 3;
513b1994897Sopenharmony_ci    static const char *argv_int_only[argc_int_only];
514b1994897Sopenharmony_ci    argv_int_only[0] = "gtest_app";
515b1994897Sopenharmony_ci    std::string s = "--" + PAIR.GetName();
516b1994897Sopenharmony_ci    argv_int_only[1] = s.c_str();
517b1994897Sopenharmony_ci    argv_int_only[2] = "101";
518b1994897Sopenharmony_ci    EXPECT_FALSE(PA_PARSER.Parse(argc_int_only, argv_int_only));
519b1994897Sopenharmony_ci    argv_int_only[2] = "-101";
520b1994897Sopenharmony_ci    EXPECT_FALSE(PA_PARSER.Parse(argc_int_only, argv_int_only));
521b1994897Sopenharmony_ci}
522b1994897Sopenharmony_ci
523b1994897Sopenharmony_ci// expect uint32_t values with range processed right
524b1994897Sopenharmony_ciHWTEST(libpandargs, TestUint32Range, testing::ext::TestSize.Level0)
525b1994897Sopenharmony_ci{
526b1994897Sopenharmony_ci    static const uint32_t ref_int_min = 1;
527b1994897Sopenharmony_ci    static const uint32_t ref_int_max = 990000000;
528b1994897Sopenharmony_ci    static const int argc_int_only = 3;
529b1994897Sopenharmony_ci    static const char *argv_int_only[argc_int_only];
530b1994897Sopenharmony_ci    argv_int_only[0] = "gtest_app";
531b1994897Sopenharmony_ci    std::string s = "--" + PAUR32.GetName();
532b1994897Sopenharmony_ci    argv_int_only[1] = s.c_str();
533b1994897Sopenharmony_ci    argv_int_only[2] = "1";
534b1994897Sopenharmony_ci    EXPECT_TRUE(PA_PARSER.Parse(argc_int_only, argv_int_only));
535b1994897Sopenharmony_ci    EXPECT_EQ(PAUR32.GetValue(), ref_int_min);
536b1994897Sopenharmony_ci    argv_int_only[2] = "990000000";
537b1994897Sopenharmony_ci    EXPECT_TRUE(PA_PARSER.Parse(argc_int_only, argv_int_only));
538b1994897Sopenharmony_ci    EXPECT_EQ(PAUR32.GetValue(), ref_int_max);
539b1994897Sopenharmony_ci}
540b1994897Sopenharmony_ci
541b1994897Sopenharmony_ci// expect wrong uint32_t values with range processed right
542b1994897Sopenharmony_ciHWTEST(libpandargs, TestWrongUint32, testing::ext::TestSize.Level0)
543b1994897Sopenharmony_ci{
544b1994897Sopenharmony_ci    static const int argc_int_only = 3;
545b1994897Sopenharmony_ci    static const char *argv_int_only[argc_int_only];
546b1994897Sopenharmony_ci    argv_int_only[0] = "gtest_app";
547b1994897Sopenharmony_ci    std::string s = "--" + PAUR32.GetName();
548b1994897Sopenharmony_ci    argv_int_only[1] = s.c_str();
549b1994897Sopenharmony_ci    argv_int_only[2] = "-1";
550b1994897Sopenharmony_ci    EXPECT_FALSE(PA_PARSER.Parse(argc_int_only, argv_int_only));
551b1994897Sopenharmony_ci    argv_int_only[2] = "1000000001";
552b1994897Sopenharmony_ci    EXPECT_FALSE(PA_PARSER.Parse(argc_int_only, argv_int_only));
553b1994897Sopenharmony_ci}
554b1994897Sopenharmony_ci
555b1994897Sopenharmony_ci// expect uint64_t values with range processed right
556b1994897Sopenharmony_ciHWTEST(libpandargs, TestUint64Range, testing::ext::TestSize.Level0)
557b1994897Sopenharmony_ci{
558b1994897Sopenharmony_ci    static const uint64_t ref_int_min = 1;
559b1994897Sopenharmony_ci    static const uint64_t ref_int_max = 99000000000;
560b1994897Sopenharmony_ci    static const int argc_int_only = 3;
561b1994897Sopenharmony_ci    static const char *argv_int_only[argc_int_only];
562b1994897Sopenharmony_ci    argv_int_only[0] = "gtest_app";
563b1994897Sopenharmony_ci    std::string s = "--" + PAUR64.GetName();
564b1994897Sopenharmony_ci    argv_int_only[1] = s.c_str();
565b1994897Sopenharmony_ci    argv_int_only[2] = "1";
566b1994897Sopenharmony_ci    EXPECT_TRUE(PA_PARSER.Parse(argc_int_only, argv_int_only));
567b1994897Sopenharmony_ci    EXPECT_EQ(PAUR64.GetValue(), ref_int_min);
568b1994897Sopenharmony_ci    argv_int_only[2] = "99000000000";
569b1994897Sopenharmony_ci    EXPECT_TRUE(PA_PARSER.Parse(argc_int_only, argv_int_only));
570b1994897Sopenharmony_ci    EXPECT_EQ(PAUR64.GetValue(), ref_int_max);
571b1994897Sopenharmony_ci}
572b1994897Sopenharmony_ci
573b1994897Sopenharmony_ci// expect wrong uint64_t values with range processed right
574b1994897Sopenharmony_ciHWTEST(libpandargs, TestWrongUint364, testing::ext::TestSize.Level0)
575b1994897Sopenharmony_ci{
576b1994897Sopenharmony_ci    static const int argc_int_only = 3;
577b1994897Sopenharmony_ci    static const char *argv_int_only[argc_int_only];
578b1994897Sopenharmony_ci    argv_int_only[0] = "gtest_app";
579b1994897Sopenharmony_ci    std::string s = "--" + PAUR64.GetName();
580b1994897Sopenharmony_ci    argv_int_only[1] = s.c_str();
581b1994897Sopenharmony_ci    argv_int_only[2] = "-1";
582b1994897Sopenharmony_ci    EXPECT_FALSE(PA_PARSER.Parse(argc_int_only, argv_int_only));
583b1994897Sopenharmony_ci    argv_int_only[2] = "100000000001";
584b1994897Sopenharmony_ci    EXPECT_FALSE(PA_PARSER.Parse(argc_int_only, argv_int_only));
585b1994897Sopenharmony_ci}
586b1994897Sopenharmony_ci
587b1994897Sopenharmony_ci// expect list at the end of line is a list with empty string
588b1994897Sopenharmony_ciHWTEST(libpandargs, TestListRange, testing::ext::TestSize.Level0)
589b1994897Sopenharmony_ci{
590b1994897Sopenharmony_ci    PALD.ResetDefaultValue();
591b1994897Sopenharmony_ci    static const arg_list_t ref_list = {""};
592b1994897Sopenharmony_ci    static const int argc_list_only = 2;
593b1994897Sopenharmony_ci    static const char *argv_list_only[argc_list_only];
594b1994897Sopenharmony_ci    argv_list_only[0] = "gtest_app";
595b1994897Sopenharmony_ci    std::string s = "--" + PALD.GetName();
596b1994897Sopenharmony_ci    argv_list_only[1] = s.c_str();
597b1994897Sopenharmony_ci    EXPECT_TRUE(PA_PARSER.Parse(argc_list_only, argv_list_only));
598b1994897Sopenharmony_ci    EXPECT_EQ(PALD.GetValue(), ref_list);
599b1994897Sopenharmony_ci}
600b1994897Sopenharmony_ci
601b1994897Sopenharmony_ci// expect true on IsTailEnabled when tail is enabled, false otherwise
602b1994897Sopenharmony_ciHWTEST(libpandargs, TestIsTailEnabled, testing::ext::TestSize.Level0)
603b1994897Sopenharmony_ci{
604b1994897Sopenharmony_ci    PA_PARSER.EnableTail();
605b1994897Sopenharmony_ci    EXPECT_TRUE(PA_PARSER.IsTailEnabled());
606b1994897Sopenharmony_ci    PA_PARSER.DisableTail();
607b1994897Sopenharmony_ci    EXPECT_FALSE(PA_PARSER.IsTailEnabled());
608b1994897Sopenharmony_ci}
609b1994897Sopenharmony_ci
610b1994897Sopenharmony_ci// expect tail only argument is consistent
611b1994897Sopenharmony_ciHWTEST(libpandargs, TestTailConsistent, testing::ext::TestSize.Level0)
612b1994897Sopenharmony_ci{
613b1994897Sopenharmony_ci    static const int argc_tail_only = 2;
614b1994897Sopenharmony_ci    static const char *argv_tail_only[] = {"gtest_app", "tail1"};
615b1994897Sopenharmony_ci    static const std::string ref_str_tail = "tail1";
616b1994897Sopenharmony_ci    PA_PARSER.EnableTail();
617b1994897Sopenharmony_ci    PA_PARSER.PushBackTail(&T_PAS);
618b1994897Sopenharmony_ci    EXPECT_TRUE(PA_PARSER.Parse(argc_tail_only, argv_tail_only));
619b1994897Sopenharmony_ci    ASSERT_EQ(T_PAS.GetValue(), ref_str_tail);
620b1994897Sopenharmony_ci    PA_PARSER.DisableTail();
621b1994897Sopenharmony_ci    PA_PARSER.EraseTail();
622b1994897Sopenharmony_ci}
623b1994897Sopenharmony_ci
624b1994897Sopenharmony_ci// expect multiple tail only argument is consistent
625b1994897Sopenharmony_ciHWTEST(libpandargs, TestMultipleTail, testing::ext::TestSize.Level0)
626b1994897Sopenharmony_ci{
627b1994897Sopenharmony_ci    static const int argc_tail_only = 7;
628b1994897Sopenharmony_ci    static const char *argv_tail_only[] = {"gtest_app", "str_tail", "off", "-4", "3.14", "2", "4"};
629b1994897Sopenharmony_ci    static const std::string str_ref = "str_tail";
630b1994897Sopenharmony_ci    static const bool bool_ref = false;
631b1994897Sopenharmony_ci    static const int int_ref = -4;
632b1994897Sopenharmony_ci    static const double double_ref = 3.14;
633b1994897Sopenharmony_ci    static const uint32_t uint32_ref = 2;
634b1994897Sopenharmony_ci    static const uint64_t uint64_ref = 4;
635b1994897Sopenharmony_ci    PA_PARSER.EnableTail();
636b1994897Sopenharmony_ci    PA_PARSER.PushBackTail(&T_PAS);
637b1994897Sopenharmony_ci    PA_PARSER.PushBackTail(&T_PAB);
638b1994897Sopenharmony_ci    PA_PARSER.PushBackTail(&T_PAI);
639b1994897Sopenharmony_ci    PA_PARSER.PushBackTail(&T_PAD);
640b1994897Sopenharmony_ci    PA_PARSER.PushBackTail(&T_PAU32);
641b1994897Sopenharmony_ci    PA_PARSER.PushBackTail(&T_PAU64);
642b1994897Sopenharmony_ci    EXPECT_EQ(PA_PARSER.GetTailSize(), 6U);
643b1994897Sopenharmony_ci    EXPECT_TRUE(PA_PARSER.Parse(argc_tail_only, argv_tail_only));
644b1994897Sopenharmony_ci    EXPECT_EQ(T_PAS.GetValue(), str_ref);
645b1994897Sopenharmony_ci    EXPECT_EQ(T_PAB.GetValue(), bool_ref);
646b1994897Sopenharmony_ci    EXPECT_EQ(T_PAI.GetValue(), int_ref);
647b1994897Sopenharmony_ci    EXPECT_DOUBLE_EQ(T_PAD.GetValue(), double_ref);
648b1994897Sopenharmony_ci    EXPECT_EQ(T_PAU32.GetValue(), uint32_ref);
649b1994897Sopenharmony_ci    EXPECT_EQ(T_PAU64.GetValue(), uint64_ref);
650b1994897Sopenharmony_ci    PA_PARSER.DisableTail();
651b1994897Sopenharmony_ci    PA_PARSER.EraseTail();
652b1994897Sopenharmony_ci    EXPECT_EQ(PA_PARSER.GetTailSize(), 0U);
653b1994897Sopenharmony_ci}
654b1994897Sopenharmony_ci
655b1994897Sopenharmony_ci// expect parse fail on wrong tail argument type
656b1994897Sopenharmony_ciHWTEST(libpandargs, TestRrongTail, testing::ext::TestSize.Level0)
657b1994897Sopenharmony_ci{
658b1994897Sopenharmony_ci    PA_PARSER.EnableTail();
659b1994897Sopenharmony_ci    static const int argc_tail_only = 3;
660b1994897Sopenharmony_ci    // boolean value instead of integer
661b1994897Sopenharmony_ci    static const char *argv_tail_only[] = {"gtest_app", "str_tail", "off"};
662b1994897Sopenharmony_ci    static const std::string str_ref = "str_tail";
663b1994897Sopenharmony_ci    PA_PARSER.PushBackTail(&T_PAS);
664b1994897Sopenharmony_ci    PA_PARSER.PushBackTail(&T_PAI);
665b1994897Sopenharmony_ci    EXPECT_EQ(PA_PARSER.GetTailSize(), 2U);
666b1994897Sopenharmony_ci    EXPECT_FALSE(PA_PARSER.Parse(argc_tail_only, argv_tail_only));
667b1994897Sopenharmony_ci    EXPECT_EQ(T_PAS.GetValue(), str_ref);
668b1994897Sopenharmony_ci    PA_PARSER.DisableTail();
669b1994897Sopenharmony_ci    PA_PARSER.EraseTail();
670b1994897Sopenharmony_ci    EXPECT_EQ(PA_PARSER.GetTailSize(), 0U);
671b1994897Sopenharmony_ci}
672b1994897Sopenharmony_ci
673b1994897Sopenharmony_ci// expect right tail argument processing after preceiding string argument
674b1994897Sopenharmony_ciHWTEST(libpandargs, TestRightTail, testing::ext::TestSize.Level0)
675b1994897Sopenharmony_ci{
676b1994897Sopenharmony_ci    PA_PARSER.EnableTail();
677b1994897Sopenharmony_ci    static const char *str_argname = "--string";
678b1994897Sopenharmony_ci    static const std::string ref_string = "this is a reference string";
679b1994897Sopenharmony_ci    static const std::string ref_t_str = "string";
680b1994897Sopenharmony_ci    static const double ref_t_double = 0.1;
681b1994897Sopenharmony_ci    static const bool ref_t_bool = true;
682b1994897Sopenharmony_ci    static const uint32_t ref_t_uint32 = 32;
683b1994897Sopenharmony_ci    static const uint64_t ref_t_uint64 = 64;
684b1994897Sopenharmony_ci    static const int argc_tail_string = 8;
685b1994897Sopenharmony_ci    static const char *argv_tail_string[] = {"gtest_app",
686b1994897Sopenharmony_ci        str_argname, "this is a reference string", "string", ".1", "on", "32", "64"};
687b1994897Sopenharmony_ci    PA_PARSER.PushBackTail(&T_PAS);
688b1994897Sopenharmony_ci    PA_PARSER.PushBackTail(&T_PAD);
689b1994897Sopenharmony_ci    PA_PARSER.PushBackTail(&T_PAB);
690b1994897Sopenharmony_ci    PA_PARSER.PushBackTail(&T_PAU32);
691b1994897Sopenharmony_ci    PA_PARSER.PushBackTail(&T_PAU64);
692b1994897Sopenharmony_ci    EXPECT_TRUE(PA_PARSER.Parse(argc_tail_string, argv_tail_string));
693b1994897Sopenharmony_ci    EXPECT_EQ(PAS.GetValue(), ref_string);
694b1994897Sopenharmony_ci    EXPECT_EQ(T_PAS.GetValue(), ref_t_str);
695b1994897Sopenharmony_ci    EXPECT_EQ(T_PAD.GetValue(), ref_t_double);
696b1994897Sopenharmony_ci    EXPECT_EQ(T_PAB.GetValue(), ref_t_bool);
697b1994897Sopenharmony_ci    EXPECT_EQ(T_PAU32.GetValue(), ref_t_uint32);
698b1994897Sopenharmony_ci    EXPECT_EQ(T_PAU64.GetValue(), ref_t_uint64);
699b1994897Sopenharmony_ci    PA_PARSER.DisableTail();
700b1994897Sopenharmony_ci    PA_PARSER.EraseTail();
701b1994897Sopenharmony_ci}
702b1994897Sopenharmony_ci
703b1994897Sopenharmony_ci// expect right tail argument processing after preceiding list argument
704b1994897Sopenharmony_ciHWTEST(libpandargs, TestTailProceiding, testing::ext::TestSize.Level0)
705b1994897Sopenharmony_ci{
706b1994897Sopenharmony_ci    PALD.ResetDefaultValue();
707b1994897Sopenharmony_ci    PA_PARSER.EnableTail();
708b1994897Sopenharmony_ci    static const char *list_argname = "--dlist";
709b1994897Sopenharmony_ci    static const arg_list_t ref_list = {"list1", "list2", "list3", "list4", "list5"};
710b1994897Sopenharmony_ci    static const double ref_t_double = -7;
711b1994897Sopenharmony_ci    static const bool ref_t_bool = true;
712b1994897Sopenharmony_ci    static const int ref_t_int = 255;
713b1994897Sopenharmony_ci    static const uint32_t ref_t_uint32 = 32;
714b1994897Sopenharmony_ci    static const uint64_t ref_t_uint64 = 64;
715b1994897Sopenharmony_ci    static const int argc_tail_list = 16;
716b1994897Sopenharmony_ci    static const char *argv_tail_list[] = {"gtest_app", list_argname, "list1", list_argname, "list2", list_argname,
717b1994897Sopenharmony_ci        "list3", list_argname, "list4", list_argname, "list5", "true", "255", "-7", "32", "64"};
718b1994897Sopenharmony_ci    PA_PARSER.PushBackTail(&T_PAB);
719b1994897Sopenharmony_ci    PA_PARSER.PushBackTail(&T_PAI);
720b1994897Sopenharmony_ci    PA_PARSER.PushBackTail(&T_PAD);
721b1994897Sopenharmony_ci    PA_PARSER.PushBackTail(&T_PAU32);
722b1994897Sopenharmony_ci    PA_PARSER.PushBackTail(&T_PAU64);
723b1994897Sopenharmony_ci    EXPECT_TRUE(PA_PARSER.Parse(argc_tail_list, argv_tail_list));
724b1994897Sopenharmony_ci    ASSERT_EQ(PALD.GetValue().size(), ref_list.size());
725b1994897Sopenharmony_ci    for (std::size_t i = 0; i < ref_list.size(); i++) {
726b1994897Sopenharmony_ci        EXPECT_EQ(PALD.GetValue()[i], ref_list[i]);
727b1994897Sopenharmony_ci    }
728b1994897Sopenharmony_ci    EXPECT_EQ(T_PAB.GetValue(), ref_t_bool);
729b1994897Sopenharmony_ci    EXPECT_EQ(T_PAI.GetValue(), ref_t_int);
730b1994897Sopenharmony_ci    EXPECT_DOUBLE_EQ(T_PAD.GetValue(), ref_t_double);
731b1994897Sopenharmony_ci    EXPECT_EQ(T_PAU32.GetValue(), ref_t_uint32);
732b1994897Sopenharmony_ci    EXPECT_EQ(T_PAU64.GetValue(), ref_t_uint64);
733b1994897Sopenharmony_ci
734b1994897Sopenharmony_ci    PA_PARSER.DisableTail();
735b1994897Sopenharmony_ci    PA_PARSER.EraseTail();
736b1994897Sopenharmony_ci}
737b1994897Sopenharmony_ci
738b1994897Sopenharmony_ci// expect right tail argument processing after noparam boolean argument
739b1994897Sopenharmony_ciHWTEST(libpandargs, TestTailBoolean, testing::ext::TestSize.Level0)
740b1994897Sopenharmony_ci{
741b1994897Sopenharmony_ci    PA_PARSER.EnableTail();
742b1994897Sopenharmony_ci    PandArg<std::string> t_pas0("tail_string0", REF_DEF_STRING, "Sample tail string argument 0");
743b1994897Sopenharmony_ci    PandArg<std::string> t_pas1("tail_string1", REF_DEF_STRING, "Sample tail string argument 1");
744b1994897Sopenharmony_ci    static const std::string ref_t_str1 = "offtail1";
745b1994897Sopenharmony_ci    static const std::string ref_t_str2 = "offtail2";
746b1994897Sopenharmony_ci    static const std::string ref_t_str3 = "offtail3";
747b1994897Sopenharmony_ci    static const int argc_tail_bool = 5;
748b1994897Sopenharmony_ci    static const char *argv_tail_bool[] = {"gtest_app", "--bool", "offtail1", "offtail2", "offtail3"};
749b1994897Sopenharmony_ci    PA_PARSER.PushBackTail(&T_PAS);
750b1994897Sopenharmony_ci    PA_PARSER.PushBackTail(&t_pas0);
751b1994897Sopenharmony_ci    PA_PARSER.PushBackTail(&t_pas1);
752b1994897Sopenharmony_ci    EXPECT_TRUE(PA_PARSER.Parse(argc_tail_bool, argv_tail_bool));
753b1994897Sopenharmony_ci    EXPECT_TRUE(PAB.GetValue());
754b1994897Sopenharmony_ci    EXPECT_EQ(T_PAS.GetValue(), ref_t_str1);
755b1994897Sopenharmony_ci    EXPECT_EQ(t_pas0.GetValue(), ref_t_str2);
756b1994897Sopenharmony_ci    EXPECT_EQ(t_pas1.GetValue(), ref_t_str3);
757b1994897Sopenharmony_ci    PA_PARSER.DisableTail();
758b1994897Sopenharmony_ci    PA_PARSER.EraseTail();
759b1994897Sopenharmony_ci}
760b1994897Sopenharmony_ci
761b1994897Sopenharmony_ci// expect fail on amount of tail arguments more then PA_PARSER may have
762b1994897Sopenharmony_ciHWTEST(libpandargs, TestTailPa_parser, testing::ext::TestSize.Level0)
763b1994897Sopenharmony_ci{
764b1994897Sopenharmony_ci    PA_PARSER.EnableTail();
765b1994897Sopenharmony_ci    static const int argc_tail = 5;
766b1994897Sopenharmony_ci    static const char *argv_tail[] = {"gtest_app", "gdb", "--args", "file.bin", "entry"};
767b1994897Sopenharmony_ci
768b1994897Sopenharmony_ci    PandArg<std::string> t_pas1("tail_string1", REF_DEF_STRING, "Sample tail string argument 1");
769b1994897Sopenharmony_ci    PA_PARSER.PushBackTail(&T_PAS);
770b1994897Sopenharmony_ci    PA_PARSER.PushBackTail(&t_pas1);
771b1994897Sopenharmony_ci
772b1994897Sopenharmony_ci    EXPECT_EQ(PA_PARSER.GetTailSize(), 2U);
773b1994897Sopenharmony_ci    EXPECT_FALSE(PA_PARSER.Parse(argc_tail, argv_tail));
774b1994897Sopenharmony_ci    PA_PARSER.DisableTail();
775b1994897Sopenharmony_ci    PA_PARSER.EraseTail();
776b1994897Sopenharmony_ci}
777b1994897Sopenharmony_ci
778b1994897Sopenharmony_ci// expect remainder arguments only parsed as expected
779b1994897Sopenharmony_ciHWTEST(libpandargs, TestRemainder, testing::ext::TestSize.Level0)
780b1994897Sopenharmony_ci{
781b1994897Sopenharmony_ci    PA_PARSER.EnableRemainder();
782b1994897Sopenharmony_ci    static const arg_list_t ref_rem = {"rem1", "rem2", "rem3"};
783b1994897Sopenharmony_ci    static int argc_rem = 5;
784b1994897Sopenharmony_ci    static const char *argv_rem[] = {"gtest_app", "--", "rem1", "rem2", "rem3"};
785b1994897Sopenharmony_ci    PA_PARSER.Parse(argc_rem, argv_rem);
786b1994897Sopenharmony_ci    arg_list_t remainder = PA_PARSER.GetRemainder();
787b1994897Sopenharmony_ci    EXPECT_EQ(remainder.size(), ref_rem.size());
788b1994897Sopenharmony_ci    for (std::size_t i = 0; i < remainder.size(); i++) {
789b1994897Sopenharmony_ci        EXPECT_EQ(remainder[i], ref_rem[i]);
790b1994897Sopenharmony_ci    }
791b1994897Sopenharmony_ci    PA_PARSER.DisableRemainder();
792b1994897Sopenharmony_ci}
793b1994897Sopenharmony_ci
794b1994897Sopenharmony_ci// expect regular argument before remainder parsed right
795b1994897Sopenharmony_ciHWTEST(libpandargs, TestRegularRemainder, testing::ext::TestSize.Level0)
796b1994897Sopenharmony_ci{
797b1994897Sopenharmony_ci    PA_PARSER.EnableRemainder();
798b1994897Sopenharmony_ci    static const arg_list_t ref_rem = {"rem1", "rem2", "rem3"};
799b1994897Sopenharmony_ci    std::string bool_name = "--" + PAB.GetName();
800b1994897Sopenharmony_ci    static int argc_rem = 6;
801b1994897Sopenharmony_ci    static const char *argv_rem[] = {"gtest_app", bool_name.c_str(), "--", "rem1", "rem2", "rem3"};
802b1994897Sopenharmony_ci    PA_PARSER.Parse(argc_rem, argv_rem);
803b1994897Sopenharmony_ci    EXPECT_TRUE(PAB.GetValue());
804b1994897Sopenharmony_ci    arg_list_t remainder = PA_PARSER.GetRemainder();
805b1994897Sopenharmony_ci    EXPECT_EQ(remainder.size(), ref_rem.size());
806b1994897Sopenharmony_ci    for (std::size_t i = 0; i < remainder.size(); i++) {
807b1994897Sopenharmony_ci        EXPECT_EQ(remainder[i], ref_rem[i]);
808b1994897Sopenharmony_ci    }
809b1994897Sopenharmony_ci    PA_PARSER.DisableRemainder();
810b1994897Sopenharmony_ci}
811b1994897Sopenharmony_ci
812b1994897Sopenharmony_cistatic const char *ARGV_CONSISTENT[] = {"gtest_app", "--bool", "on", "--int=42", "--string", "this is a string",
813b1994897Sopenharmony_ci    "--double", ".42", "--uint32=4294967295", "--uint64=18446744073709551615", "--dlist=dlist1:dlist2:dlist3:dlist4",
814b1994897Sopenharmony_ci    "--rint=42", "--ruint32=990000000", "--ruint64=99000000000", "tail1", "tail2 tail3", "tail4", "--", "rem1",
815b1994897Sopenharmony_ci    "rem2", "rem3"};
816b1994897Sopenharmony_ci
817b1994897Sopenharmony_ci// expect that all arguments parsed as expected
818b1994897Sopenharmony_ciHWTEST(libpandargs, TestAll, testing::ext::TestSize.Level0)
819b1994897Sopenharmony_ci{
820b1994897Sopenharmony_ci    PALD.ResetDefaultValue();
821b1994897Sopenharmony_ci    PA_PARSER.EnableTail();
822b1994897Sopenharmony_ci    PA_PARSER.EnableRemainder();
823b1994897Sopenharmony_ci    static const arg_list_t ref_rem = {"rem1", "rem2", "rem3"};
824b1994897Sopenharmony_ci    PandArg<std::string> t_pas0("tail_string0", REF_DEF_STRING, "Sample tail string argument 0");
825b1994897Sopenharmony_ci    PandArg<std::string> t_pas1("tail_string1", REF_DEF_STRING, "Sample tail string argument 1");
826b1994897Sopenharmony_ci    static const bool ref_bool = true;
827b1994897Sopenharmony_ci    static const int ref_int = 42;
828b1994897Sopenharmony_ci    static const arg_list_t ref_dlist = {"dlist1", "dlist2", "dlist3", "dlist4"};
829b1994897Sopenharmony_ci    static const std::string ref_t_str1 = "tail1";
830b1994897Sopenharmony_ci    static const std::string ref_t_str2 = "tail2 tail3";
831b1994897Sopenharmony_ci    static const std::string ref_t_str3 = "tail4";
832b1994897Sopenharmony_ci    static const std::string ref_str = "this is a string";
833b1994897Sopenharmony_ci    static const double ref_dbl = 0.42;
834b1994897Sopenharmony_ci    static const uint32_t ref_uint32 = std::numeric_limits<std::uint32_t>::max();
835b1994897Sopenharmony_ci    static const uint32_t ref_uint32r = 990000000;
836b1994897Sopenharmony_ci    static const uint64_t ref_uint64 = std::numeric_limits<std::uint64_t>::max();
837b1994897Sopenharmony_ci    static const uint64_t ref_uint64r = 99000000000;
838b1994897Sopenharmony_ci    static int argc_consistent = 21;
839b1994897Sopenharmony_ci    PA_PARSER.PushBackTail(&T_PAS);
840b1994897Sopenharmony_ci    PA_PARSER.PushBackTail(&t_pas0);
841b1994897Sopenharmony_ci    PA_PARSER.PushBackTail(&t_pas1);
842b1994897Sopenharmony_ci    EXPECT_TRUE(PA_PARSER.Parse(argc_consistent, ARGV_CONSISTENT));
843b1994897Sopenharmony_ci    EXPECT_EQ(PAB.GetValue(), ref_bool);
844b1994897Sopenharmony_ci    EXPECT_EQ(PAI.GetValue(), ref_int);
845b1994897Sopenharmony_ci    EXPECT_EQ(PAS.GetValue(), ref_str);
846b1994897Sopenharmony_ci    EXPECT_DOUBLE_EQ(PAD.GetValue(), ref_dbl);
847b1994897Sopenharmony_ci    EXPECT_EQ(PAU32.GetValue(), ref_uint32);
848b1994897Sopenharmony_ci    EXPECT_EQ(PAU64.GetValue(), ref_uint64);
849b1994897Sopenharmony_ci    ASSERT_EQ(PALD.GetValue().size(), ref_dlist.size());
850b1994897Sopenharmony_ci    for (std::size_t i = 0; i < ref_dlist.size(); ++i) {
851b1994897Sopenharmony_ci        EXPECT_EQ(PALD.GetValue()[i], ref_dlist[i]);
852b1994897Sopenharmony_ci    }
853b1994897Sopenharmony_ci    EXPECT_EQ(PAIR.GetValue(), ref_int);
854b1994897Sopenharmony_ci    EXPECT_EQ(PAUR32.GetValue(), ref_uint32r);
855b1994897Sopenharmony_ci    EXPECT_EQ(PAUR64.GetValue(), ref_uint64r);
856b1994897Sopenharmony_ci    EXPECT_EQ(T_PAS.GetValue(), ref_t_str1);
857b1994897Sopenharmony_ci    EXPECT_EQ(t_pas0.GetValue(), ref_t_str2);
858b1994897Sopenharmony_ci    EXPECT_EQ(t_pas1.GetValue(), ref_t_str3);
859b1994897Sopenharmony_ci    arg_list_t remainder = PA_PARSER.GetRemainder();
860b1994897Sopenharmony_ci    EXPECT_EQ(remainder.size(), ref_rem.size());
861b1994897Sopenharmony_ci    for (std::size_t i = 0; i < remainder.size(); i++) {
862b1994897Sopenharmony_ci        EXPECT_EQ(remainder[i], ref_rem[i]);
863b1994897Sopenharmony_ci    }
864b1994897Sopenharmony_ci    PA_PARSER.DisableRemainder();
865b1994897Sopenharmony_ci    PA_PARSER.DisableTail();
866b1994897Sopenharmony_ci    PA_PARSER.EraseTail();
867b1994897Sopenharmony_ci}
868b1994897Sopenharmony_ci
869b1994897Sopenharmony_ciPandArg<bool> SUB_BOOL_ARG("bool", false, "Sample boolean argument");
870b1994897Sopenharmony_ci
871b1994897Sopenharmony_ci// The number 12 is the default parameter for variable SUB_INT_ARG
872b1994897Sopenharmony_ciPandArg<int> SUB_INT_ARG("int", 12, "Sample integer argument");
873b1994897Sopenharmony_ci
874b1994897Sopenharmony_ci// The number 123.45 is the default parameter for variable SUB_DOUBLE_ARG
875b1994897Sopenharmony_ciPandArg<double> SUB_DOUBLE_ARG("double", 123.45, "Sample rational argument");
876b1994897Sopenharmony_ci
877b1994897Sopenharmony_ciPandArg<std::string> SUB_STRING_ARG("string", "Hello", "Sample string argument");
878b1994897Sopenharmony_ci
879b1994897Sopenharmony_ci// The number 123 is the default parameter for variable INT_ARG
880b1994897Sopenharmony_ciPandArg<int> INT_ARG("global_int", 123, "Global integer argument");
881b1994897Sopenharmony_ci
882b1994897Sopenharmony_ciPandArgCompound PARENT("compound", "Sample boolean argument", {
883b1994897Sopenharmony_ci    &SUB_BOOL_ARG, &SUB_INT_ARG, &SUB_DOUBLE_ARG, &SUB_STRING_ARG});
884b1994897Sopenharmony_ci
885b1994897Sopenharmony_ciPandArgParser C_PARSER;
886b1994897Sopenharmony_ci
887b1994897Sopenharmony_ciHWTEST(libpandargs, CompoundArgsAdd, testing::ext::TestSize.Level0)
888b1994897Sopenharmony_ci{
889b1994897Sopenharmony_ci    ASSERT_TRUE(C_PARSER.Add(&INT_ARG));
890b1994897Sopenharmony_ci    ASSERT_TRUE(C_PARSER.Add(&PARENT));
891b1994897Sopenharmony_ci}
892b1994897Sopenharmony_ci
893b1994897Sopenharmony_ci// Should work well with no sub arguments
894b1994897Sopenharmony_ciHWTEST(libpandargs, CompoundArgsNoSub, testing::ext::TestSize.Level0)
895b1994897Sopenharmony_ci{
896b1994897Sopenharmony_ci    {
897b1994897Sopenharmony_ci        PARENT.ResetDefaultValue();
898b1994897Sopenharmony_ci        static const char *argv[] = {"gtest_app", "--compound"};
899b1994897Sopenharmony_ci        ASSERT_TRUE(C_PARSER.Parse(2, argv)) << C_PARSER.GetErrorString();
900b1994897Sopenharmony_ci        ASSERT_EQ(PARENT.GetValue(), true);
901b1994897Sopenharmony_ci        ASSERT_EQ(SUB_BOOL_ARG.GetValue(), false);
902b1994897Sopenharmony_ci        ASSERT_EQ(SUB_INT_ARG.GetValue(), 12);
903b1994897Sopenharmony_ci        ASSERT_EQ(SUB_DOUBLE_ARG.GetValue(), 123.45);
904b1994897Sopenharmony_ci        ASSERT_EQ(SUB_STRING_ARG.GetValue(), "Hello");
905b1994897Sopenharmony_ci    }
906b1994897Sopenharmony_ci
907b1994897Sopenharmony_ci    {
908b1994897Sopenharmony_ci        PARENT.ResetDefaultValue();
909b1994897Sopenharmony_ci        static const char *argv[] = {"gtest_app", "--compound:bool,int=2,double=54.321,string=World"};
910b1994897Sopenharmony_ci        ASSERT_TRUE(C_PARSER.Parse(2, argv)) << C_PARSER.GetErrorString();
911b1994897Sopenharmony_ci        ASSERT_EQ(PARENT.GetValue(), true);
912b1994897Sopenharmony_ci        ASSERT_EQ(SUB_BOOL_ARG.GetValue(), true);
913b1994897Sopenharmony_ci        ASSERT_EQ(SUB_INT_ARG.GetValue(), 2);
914b1994897Sopenharmony_ci        ASSERT_EQ(SUB_DOUBLE_ARG.GetValue(), 54.321);
915b1994897Sopenharmony_ci        ASSERT_EQ(SUB_STRING_ARG.GetValue(), "World");
916b1994897Sopenharmony_ci    }
917b1994897Sopenharmony_ci}
918b1994897Sopenharmony_ci
919b1994897Sopenharmony_ci// ResetDefaultValue should reset all sub arguments
920b1994897Sopenharmony_ciHWTEST(libpandargs, CompoundArgsResetDefaultValue, testing::ext::TestSize.Level0)
921b1994897Sopenharmony_ci{
922b1994897Sopenharmony_ci    {
923b1994897Sopenharmony_ci        PARENT.ResetDefaultValue();
924b1994897Sopenharmony_ci        ASSERT_EQ(PARENT.GetValue(), false);
925b1994897Sopenharmony_ci        ASSERT_EQ(SUB_BOOL_ARG.GetValue(), false);
926b1994897Sopenharmony_ci        ASSERT_EQ(SUB_INT_ARG.GetValue(), 12);
927b1994897Sopenharmony_ci        ASSERT_EQ(SUB_DOUBLE_ARG.GetValue(), 123.45);
928b1994897Sopenharmony_ci        ASSERT_EQ(SUB_STRING_ARG.GetValue(), "Hello");
929b1994897Sopenharmony_ci    }
930b1994897Sopenharmony_ci
931b1994897Sopenharmony_ci    {
932b1994897Sopenharmony_ci        static const char *argv[] = {"gtest_app", "--compound:bool=true"};
933b1994897Sopenharmony_ci        ASSERT_TRUE(C_PARSER.Parse(2, argv)) << C_PARSER.GetErrorString();
934b1994897Sopenharmony_ci        ASSERT_EQ(PARENT.GetValue(), true);
935b1994897Sopenharmony_ci        ASSERT_EQ(SUB_BOOL_ARG.GetValue(), true);
936b1994897Sopenharmony_ci    }
937b1994897Sopenharmony_ci
938b1994897Sopenharmony_ci    {
939b1994897Sopenharmony_ci        PARENT.ResetDefaultValue();
940b1994897Sopenharmony_ci        static const char *argv[] = {"gtest_app", "--compound:bool"};
941b1994897Sopenharmony_ci        ASSERT_TRUE(C_PARSER.Parse(2, argv)) << C_PARSER.GetErrorString();
942b1994897Sopenharmony_ci        ASSERT_EQ(PARENT.GetValue(), true);
943b1994897Sopenharmony_ci        ASSERT_EQ(SUB_BOOL_ARG.GetValue(), true);
944b1994897Sopenharmony_ci    }
945b1994897Sopenharmony_ci
946b1994897Sopenharmony_ci    {
947b1994897Sopenharmony_ci        static const char *argv[] = {"gtest_app", "--compound:bool=false"};
948b1994897Sopenharmony_ci        ASSERT_TRUE(C_PARSER.Parse(2, argv)) << C_PARSER.GetErrorString();
949b1994897Sopenharmony_ci        ASSERT_EQ(PARENT.GetValue(), true);
950b1994897Sopenharmony_ci        ASSERT_EQ(SUB_BOOL_ARG.GetValue(), false);
951b1994897Sopenharmony_ci    }
952b1994897Sopenharmony_ci
953b1994897Sopenharmony_ci    {
954b1994897Sopenharmony_ci        PARENT.ResetDefaultValue();
955b1994897Sopenharmony_ci        static const char *argv[] = {"gtest_app", "--global_int=321"};
956b1994897Sopenharmony_ci        ASSERT_TRUE(C_PARSER.Parse(2, argv)) << C_PARSER.GetErrorString();
957b1994897Sopenharmony_ci        ASSERT_EQ(PARENT.GetValue(), false);
958b1994897Sopenharmony_ci        ASSERT_EQ(INT_ARG.GetValue(), 321);
959b1994897Sopenharmony_ci    }
960b1994897Sopenharmony_ci
961b1994897Sopenharmony_ci    {
962b1994897Sopenharmony_ci        PARENT.ResetDefaultValue();
963b1994897Sopenharmony_ci        static const char *argv[] = {"gtest_app", "--compound", "--global_int", "321"};
964b1994897Sopenharmony_ci        ASSERT_TRUE(C_PARSER.Parse(4, argv)) << C_PARSER.GetErrorString();
965b1994897Sopenharmony_ci        ASSERT_EQ(PARENT.GetValue(), true);
966b1994897Sopenharmony_ci        ASSERT_EQ(INT_ARG.GetValue(), 321);
967b1994897Sopenharmony_ci    }
968b1994897Sopenharmony_ci}
969b1994897Sopenharmony_ci
970b1994897Sopenharmony_ci// Test that sub arguments are not visible in the global space
971b1994897Sopenharmony_ciHWTEST(libpandargs, CompoundArgsSubArguments, testing::ext::TestSize.Level0)
972b1994897Sopenharmony_ci{
973b1994897Sopenharmony_ci    {
974b1994897Sopenharmony_ci        static const char *argv[] = {"gtest_app", "--bool"};
975b1994897Sopenharmony_ci        ASSERT_FALSE(C_PARSER.Parse(2, argv));
976b1994897Sopenharmony_ci    }
977b1994897Sopenharmony_ci    {
978b1994897Sopenharmony_ci        static const char *argv[] = {"gtest_app", "--int=2"};
979b1994897Sopenharmony_ci        ASSERT_FALSE(C_PARSER.Parse(2, argv));
980b1994897Sopenharmony_ci    }
981b1994897Sopenharmony_ci    {
982b1994897Sopenharmony_ci        static const char *argv[] = {"gtest_app", "--double=54.321"};
983b1994897Sopenharmony_ci        ASSERT_FALSE(C_PARSER.Parse(2, argv));
984b1994897Sopenharmony_ci    }
985b1994897Sopenharmony_ci    {
986b1994897Sopenharmony_ci        static const char *argv[] = {"gtest_app", "--string=World"};
987b1994897Sopenharmony_ci        ASSERT_FALSE(C_PARSER.Parse(2, argv));
988b1994897Sopenharmony_ci    }
989b1994897Sopenharmony_ci}
990b1994897Sopenharmony_ci
991b1994897Sopenharmony_ciHWTEST(libpandargs, GetHelpString, testing::ext::TestSize.Level0)
992b1994897Sopenharmony_ci{
993b1994897Sopenharmony_ci    PandArg<bool> g_pab("bool", false, "Sample boolean argument");
994b1994897Sopenharmony_ci    PandArg<int> g_pai("int", 0, "Sample integer argument");
995b1994897Sopenharmony_ci    PandArg<std::string> g_pas("tail_string", "arg", "Sample tail string argument");
996b1994897Sopenharmony_ci    PandArgCompound g_pac("compound", "Sample compound argument", {&g_pab, &g_pai});
997b1994897Sopenharmony_ci
998b1994897Sopenharmony_ci    PandArgParser g_parser;
999b1994897Sopenharmony_ci    ASSERT_TRUE(g_parser.Add(&g_pab));
1000b1994897Sopenharmony_ci    ASSERT_TRUE(g_parser.Add(&g_pai));
1001b1994897Sopenharmony_ci    ASSERT_TRUE(g_parser.PushBackTail(&g_pas));
1002b1994897Sopenharmony_ci    ASSERT_TRUE(g_parser.Add(&g_pac));
1003b1994897Sopenharmony_ci
1004b1994897Sopenharmony_ci    std::string ref_string = "--" + g_pab.GetName() + ": " + g_pab.GetDesc() + "\n";
1005b1994897Sopenharmony_ci    ref_string += "--" + g_pac.GetName() + ": " + g_pac.GetDesc() + "\n";
1006b1994897Sopenharmony_ci    ref_string += "  Sub arguments:\n";
1007b1994897Sopenharmony_ci    ref_string += "    " + g_pab.GetName() + ": " + g_pab.GetDesc() + "\n";
1008b1994897Sopenharmony_ci    ref_string += "    " + g_pai.GetName() + ": " + g_pai.GetDesc() + "\n";
1009b1994897Sopenharmony_ci    ref_string += "--" + g_pai.GetName() + ": " + g_pai.GetDesc() + "\n";
1010b1994897Sopenharmony_ci    ref_string += "Tail arguments:\n";
1011b1994897Sopenharmony_ci    ref_string += g_pas.GetName() + ": " + g_pas.GetDesc() + "\n";
1012b1994897Sopenharmony_ci    ASSERT_EQ(g_parser.GetHelpString(), ref_string);
1013b1994897Sopenharmony_ci}
1014b1994897Sopenharmony_ci
1015b1994897Sopenharmony_ci}  // namespace panda::test
1016b1994897Sopenharmony_ci
1017