Directory: | ./ |
---|---|
File: | TESTS/TEST_ParserOptionInt/main.cpp |
Date: | 2024-07-27 10:53:27 |
Exec | Total | Coverage | |
---|---|---|---|
Lines: | 29 | 29 | 100.0% |
Branches: | 34 | 34 | 100.0% |
Line | Branch | Exec | Source |
---|---|---|---|
1 | |||
2 | /*************************************** | ||
3 | Auteur : Pierre Aubert | ||
4 | Mail : pierre.aubert@lapp.in2p3.fr | ||
5 | Licence : CeCILL-C | ||
6 | ****************************************/ | ||
7 | |||
8 | #include "phoenix_assert.h" | ||
9 | #include "phoenix_check.h" | ||
10 | #include "OptionParser.h" | ||
11 | |||
12 | ///Create the OptionParser of this program | ||
13 | /** @return OptionParser of this program | ||
14 | */ | ||
15 | 8 | OptionParser createOptionParser(){ | |
16 |
2/2✓ Branch 2 taken 8 times.
✓ Branch 5 taken 8 times.
|
16 | OptionParser parser(true, "1.0.0"); |
17 |
2/2✓ Branch 2 taken 8 times.
✓ Branch 5 taken 8 times.
|
8 | parser.setExampleLongOption("test_plib_optionparser_int --value=42"); |
18 |
2/2✓ Branch 2 taken 8 times.
✓ Branch 5 taken 8 times.
|
8 | parser.setExampleShortOption("test_plib_optionparser_int -n 42"); |
19 |
4/4✓ Branch 2 taken 8 times.
✓ Branch 6 taken 8 times.
✓ Branch 10 taken 8 times.
✓ Branch 13 taken 8 times.
|
8 | parser.addOption("value", "n", OptionType::INT, true, "Required option"); |
20 | 8 | return parser; | |
21 | } | ||
22 | |||
23 | ///Do the same thing but with a const parser | ||
24 | /** @param parser : OptionParser to be used | ||
25 | */ | ||
26 | 2 | void printConstParser(const OptionParser & parser){ | |
27 |
2/2✓ Branch 2 taken 2 times.
✓ Branch 5 taken 2 times.
|
2 | const OptionMode & noneMode = parser.getMode("NotExistingMode"); |
28 | 2 | noneMode.print(); | |
29 | 2 | const OptionMode & defaultMode = parser.getDefaultMode(); | |
30 | 2 | defaultMode.print(); | |
31 | 2 | } | |
32 | |||
33 | 8 | int main(int argc, char** argv){ | |
34 |
1/1✓ Branch 1 taken 8 times.
|
8 | OptionParser parser = createOptionParser(); |
35 |
1/1✓ Branch 1 taken 2 times.
|
8 | parser.parseArgument(argc, argv); |
36 |
1/1✓ Branch 1 taken 2 times.
|
2 | parser.print(); |
37 |
1/1✓ Branch 1 taken 2 times.
|
2 | printConstParser(parser); |
38 |
2/2✓ Branch 2 taken 2 times.
✓ Branch 5 taken 2 times.
|
2 | const OptionMode & noneMode = parser.getMode("NotExistingMode"); |
39 |
1/1✓ Branch 1 taken 2 times.
|
2 | noneMode.print(); |
40 | |||
41 |
3/3✓ Branch 1 taken 2 times.
✓ Branch 5 taken 2 times.
✓ Branch 8 taken 2 times.
|
4 | OptionParser parser2(parser), parser3; |
42 |
1/1✓ Branch 1 taken 2 times.
|
2 | parser2.print(); |
43 |
1/1✓ Branch 1 taken 2 times.
|
2 | parser3 = parser; |
44 |
1/1✓ Branch 1 taken 2 times.
|
2 | parser3.print(); |
45 | |||
46 |
1/1✓ Branch 1 taken 2 times.
|
2 | const OptionMode & defaultMode = parser.getDefaultMode(); |
47 | 2 | int value(0); | |
48 |
2/2✓ Branch 2 taken 2 times.
✓ Branch 5 taken 2 times.
|
2 | defaultMode.getValue(value, "value"); |
49 | // std::cout << "value = '" << value << "'" << std::endl; | ||
50 | |||
51 |
6/6✓ Branch 2 taken 2 times.
✓ Branch 6 taken 2 times.
✓ Branch 10 taken 2 times.
✓ Branch 14 taken 2 times.
✓ Branch 17 taken 2 times.
✓ Branch 20 taken 2 times.
|
2 | phoenix_assert(phoenix_check("Value", value, 42)); |
52 | 2 | return 0; | |
53 | 2 | } | |
54 | |||
55 | |||
56 |