Directory: | ./ |
---|---|
File: | TESTS/TEST_ParserModeBase/main.cpp |
Date: | 2024-07-27 10:53:27 |
Exec | Total | Coverage | |
---|---|---|---|
Lines: | 41 | 41 | 100.0% |
Branches: | 70 | 70 | 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 | 2 | OptionParser createOptionParser(){ | |
16 |
2/2✓ Branch 2 taken 2 times.
✓ Branch 5 taken 2 times.
|
4 | OptionParser parser(true, "1.0.0"); |
17 |
2/2✓ Branch 2 taken 2 times.
✓ Branch 5 taken 2 times.
|
2 | parser.addMode("class"); |
18 |
4/4✓ Branch 2 taken 2 times.
✓ Branch 6 taken 2 times.
✓ Branch 10 taken 2 times.
✓ Branch 13 taken 2 times.
|
2 | parser.addOption("name", "n", OptionType::FILENAME, true, "base name of the file to be created"); |
19 |
1/1✓ Branch 2 taken 2 times.
|
2 | std::string templateDef(""); |
20 |
5/5✓ Branch 2 taken 2 times.
✓ Branch 5 taken 2 times.
✓ Branch 9 taken 2 times.
✓ Branch 13 taken 2 times.
✓ Branch 16 taken 2 times.
|
2 | parser.addOption("template", "t", templateDef, "template definition of the class (ex: 'typename T' or 'typename T, typename U', etc"); |
21 |
1/1✓ Branch 1 taken 2 times.
|
2 | parser.closeMode(); |
22 | |||
23 |
2/2✓ Branch 2 taken 2 times.
✓ Branch 5 taken 2 times.
|
2 | parser.addMode("source"); |
24 |
4/4✓ Branch 2 taken 2 times.
✓ Branch 6 taken 2 times.
✓ Branch 10 taken 2 times.
✓ Branch 13 taken 2 times.
|
2 | parser.addOption("name", "n", OptionType::STRING, true, "base name of the file to be created"); |
25 |
1/1✓ Branch 1 taken 2 times.
|
2 | parser.closeMode(); |
26 | 4 | return parser; | |
27 | 2 | } | |
28 | |||
29 | ///Do the same thing but with a const parser | ||
30 | /** @param parser : OptionParser to be used | ||
31 | */ | ||
32 | 2 | void printConstParser(const OptionParser & parser){ | |
33 |
2/2✓ Branch 2 taken 2 times.
✓ Branch 5 taken 2 times.
|
2 | const OptionMode & noneMode = parser.getMode("class"); |
34 | 2 | noneMode.print(); | |
35 | 2 | const OptionMode & defaultMode = parser.getDefaultMode(); | |
36 | 2 | defaultMode.print(); | |
37 | 2 | } | |
38 | |||
39 | 2 | int main(int argc, char** argv){ | |
40 |
1/1✓ Branch 1 taken 2 times.
|
2 | OptionParser parser = createOptionParser(); |
41 |
1/1✓ Branch 1 taken 2 times.
|
2 | parser.print(); |
42 |
1/1✓ Branch 1 taken 2 times.
|
2 | parser.parseArgument(argc, argv); |
43 |
1/1✓ Branch 1 taken 2 times.
|
2 | printConstParser(parser); |
44 |
2/2✓ Branch 2 taken 2 times.
✓ Branch 5 taken 2 times.
|
2 | const OptionMode & classMode = parser.getMode("class"); |
45 |
2/2✓ Branch 2 taken 2 times.
✓ Branch 5 taken 2 times.
|
2 | const OptionMode & sourceMode = parser.getMode("source"); |
46 | |||
47 |
3/3✓ Branch 1 taken 2 times.
✓ Branch 3 taken 1 times.
✓ Branch 4 taken 1 times.
|
2 | if(classMode.isParsed()){ //We are using the class mode |
48 |
2/2✓ Branch 1 taken 1 times.
✓ Branch 4 taken 1 times.
|
1 | std::cout << "Class mode activated" << std::endl; |
49 |
1/1✓ Branch 2 taken 1 times.
|
1 | std::string className(""); |
50 |
2/2✓ Branch 2 taken 1 times.
✓ Branch 5 taken 1 times.
|
1 | classMode.getValue(className, "name"); |
51 |
4/4✓ Branch 1 taken 1 times.
✓ Branch 4 taken 1 times.
✓ Branch 7 taken 1 times.
✓ Branch 10 taken 1 times.
|
1 | std::cout << "name of the class to be generated : '" << className << "'" << std::endl; |
52 | |||
53 |
7/7✓ Branch 2 taken 1 times.
✓ Branch 6 taken 1 times.
✓ Branch 10 taken 1 times.
✓ Branch 14 taken 1 times.
✓ Branch 18 taken 1 times.
✓ Branch 21 taken 1 times.
✓ Branch 24 taken 1 times.
|
1 | phoenix_assert(phoenix_check("Check class name", className, "classname")); |
54 | 1 | } | |
55 | |||
56 |
3/3✓ Branch 1 taken 2 times.
✓ Branch 3 taken 1 times.
✓ Branch 4 taken 1 times.
|
2 | if(sourceMode.isParsed()){ //We are using the source mode |
57 |
2/2✓ Branch 1 taken 1 times.
✓ Branch 4 taken 1 times.
|
1 | std::cout << "Source mode activated" << std::endl; |
58 |
1/1✓ Branch 2 taken 1 times.
|
1 | std::string fileName(""); |
59 |
2/2✓ Branch 2 taken 1 times.
✓ Branch 5 taken 1 times.
|
1 | sourceMode.getValue(fileName, "name"); |
60 |
4/4✓ Branch 1 taken 1 times.
✓ Branch 4 taken 1 times.
✓ Branch 7 taken 1 times.
✓ Branch 10 taken 1 times.
|
1 | std::cout << "name of the header/source files to be generated : " << fileName << "'" << std::endl; |
61 | |||
62 |
7/7✓ Branch 2 taken 1 times.
✓ Branch 6 taken 1 times.
✓ Branch 10 taken 1 times.
✓ Branch 14 taken 1 times.
✓ Branch 18 taken 1 times.
✓ Branch 21 taken 1 times.
✓ Branch 24 taken 1 times.
|
1 | phoenix_assert(phoenix_check("Check file name", fileName, "sourcename")); |
63 | 1 | } | |
64 | 2 | return 0; | |
65 | 2 | } | |
66 | |||
67 | |||
68 |