GCC Code Coverage Report


Directory: ./
File: TESTS/TEST_LOWER_UPPER/main.cpp
Date: 2024-11-07 16:05:26
Exec Total Coverage
Lines: 95 95 100.0%
Branches: 330 330 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 <iostream>
9 #include "phoenix_assert.h"
10 #include "phoenix_check.h"
11
12 #include "string_lower_upper.h"
13
14 ///Check string lower expression
15 /** @param testName : name of the test
16 * @param strValue : string to be tested
17 * @param strReference : reference string
18 * @return true is both strings are equal, false otherwise
19 */
20 3 bool checkResultLower(const std::string & testName, const std::string & strValue, const std::string & strReference){
21
1/1
✓ Branch 1 taken 3 times.
3 std::string convertedValue(strToLower(strValue));
22
4/4
✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
✓ Branch 7 taken 3 times.
✓ Branch 10 taken 3 times.
6 return phoenix_check(testName + " Lower (" + strValue + ")", convertedValue, strReference);
23 3 }
24
25 ///Check string upper expression
26 /** @param testName : name of the test
27 * @param strValue : string to be tested
28 * @param strReference : reference string
29 * @return true is both strings are equal, false otherwise
30 */
31 3 bool checkResultUpper(const std::string & testName, const std::string & strValue, const std::string & strReference){
32
1/1
✓ Branch 1 taken 3 times.
3 std::string convertedValue(strToUpper(strValue));
33
4/4
✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
✓ Branch 7 taken 3 times.
✓ Branch 10 taken 3 times.
6 return phoenix_check(testName + " Upper (" + strValue + ")", convertedValue, strReference);
34 3 }
35
36 ///Check string lower expression
37 /** @param testName : name of the test
38 * @param strValue : string to be tested
39 * @param strReference : reference string
40 * @return true is both strings are equal, false otherwise
41 */
42 3 bool checkResultFirstLower(const std::string & testName, const std::string & strValue, const std::string & strReference){
43
1/1
✓ Branch 1 taken 3 times.
3 std::string convertedValue(firstToLower(strValue));
44
4/4
✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
✓ Branch 7 taken 3 times.
✓ Branch 10 taken 3 times.
6 return phoenix_check(testName + " firstToLower (" + strValue + ")", convertedValue, strReference);
45 3 }
46
47 ///Check string upper expression
48 /** @param testName : name of the test
49 * @param strValue : string to be tested
50 * @param strReference : reference string
51 * @return true is both strings are equal, false otherwise
52 */
53 4 bool checkResultFirstUpper(const std::string & testName, const std::string & strValue, const std::string & strReference){
54
1/1
✓ Branch 1 taken 4 times.
4 std::string convertedValue(firstToUpper(strValue));
55
4/4
✓ Branch 1 taken 4 times.
✓ Branch 4 taken 4 times.
✓ Branch 7 taken 4 times.
✓ Branch 10 taken 4 times.
8 return phoenix_check(testName + " firstToUpper (" + strValue + ")", convertedValue, strReference);
56 4 }
57
58 ///Check string lower expression
59 /** @param testName : name of the test
60 * @param strValue : string to be tested
61 * @param strReference : reference string
62 * @return true is both strings are equal, false otherwise
63 */
64 2 bool checkResultLowerUnderscore(const std::string & testName, const std::string & strValue, const std::string & strReference){
65
1/1
✓ Branch 1 taken 2 times.
2 std::string convertedValue(strToLowerUnderscore(strValue));
66
4/4
✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
✓ Branch 7 taken 2 times.
✓ Branch 10 taken 2 times.
4 return phoenix_check(testName + " strToLowerUnderscore (" + strValue + ")", convertedValue, strReference);
67 2 }
68
69 ///Test lower/upper to string
70 1 void testStringLowerUpper(){
71
8/8
✓ 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 22 taken 1 times.
✓ Branch 25 taken 1 times.
✓ Branch 28 taken 1 times.
1 phoenix_assert(checkResultLower("Test", "StRiNg", "string"));
72
8/8
✓ 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 22 taken 1 times.
✓ Branch 25 taken 1 times.
✓ Branch 28 taken 1 times.
1 phoenix_assert(checkResultLower("Test", "StRiNg1234", "string1234"));
73
8/8
✓ 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 22 taken 1 times.
✓ Branch 25 taken 1 times.
✓ Branch 28 taken 1 times.
1 phoenix_assert(checkResultLower("Test", "ABCDEFGHIJKLMNOPQRSTUVWXYZ", "abcdefghijklmnopqrstuvwxyz"));
74
8/8
✓ 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 22 taken 1 times.
✓ Branch 25 taken 1 times.
✓ Branch 28 taken 1 times.
1 phoenix_assert(checkResultUpper("Test", "StRiNg", "STRING"));
75
8/8
✓ 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 22 taken 1 times.
✓ Branch 25 taken 1 times.
✓ Branch 28 taken 1 times.
1 phoenix_assert(checkResultUpper("Test", "StRiNg1234", "STRING1234"));
76
8/8
✓ 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 22 taken 1 times.
✓ Branch 25 taken 1 times.
✓ Branch 28 taken 1 times.
1 phoenix_assert(checkResultUpper("Test", "abcdefghijklmnopqrstuvwxyz", "ABCDEFGHIJKLMNOPQRSTUVWXYZ"));
77
8/8
✓ 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 22 taken 1 times.
✓ Branch 25 taken 1 times.
✓ Branch 28 taken 1 times.
1 phoenix_assert(checkResultFirstLower("Test", "ABC", "aBC"));
78
8/8
✓ 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 22 taken 1 times.
✓ Branch 25 taken 1 times.
✓ Branch 28 taken 1 times.
1 phoenix_assert(checkResultFirstLower("Test", "aBC", "aBC"));
79
8/8
✓ 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 22 taken 1 times.
✓ Branch 25 taken 1 times.
✓ Branch 28 taken 1 times.
1 phoenix_assert(checkResultFirstLower("Test", "Vec", "vec"));
80
8/8
✓ 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 22 taken 1 times.
✓ Branch 25 taken 1 times.
✓ Branch 28 taken 1 times.
1 phoenix_assert(checkResultFirstUpper("Test", "ABC", "ABC"));
81
8/8
✓ 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 22 taken 1 times.
✓ Branch 25 taken 1 times.
✓ Branch 28 taken 1 times.
1 phoenix_assert(checkResultFirstUpper("Test", "Vec", "Vec"));
82
8/8
✓ 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 22 taken 1 times.
✓ Branch 25 taken 1 times.
✓ Branch 28 taken 1 times.
1 phoenix_assert(checkResultFirstUpper("Test", "aBC", "ABC"));
83
8/8
✓ 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 22 taken 1 times.
✓ Branch 25 taken 1 times.
✓ Branch 28 taken 1 times.
1 phoenix_assert(checkResultFirstUpper("Test", "vec", "Vec"));
84
8/8
✓ 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 22 taken 1 times.
✓ Branch 25 taken 1 times.
✓ Branch 28 taken 1 times.
1 phoenix_assert(checkResultLowerUnderscore("Test", "StringType", "stringtype"));
85
8/8
✓ 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 22 taken 1 times.
✓ Branch 25 taken 1 times.
✓ Branch 28 taken 1 times.
1 phoenix_assert(checkResultLowerUnderscore("Test", "String Type", "string_type"));
86 1 }
87
88 ///Test the is lower/upper case
89 1 void testIsLowerUpper(){
90
6/6
✓ Branch 2 taken 1 times.
✓ Branch 6 taken 1 times.
✓ Branch 10 taken 1 times.
✓ Branch 14 taken 1 times.
✓ Branch 17 taken 1 times.
✓ Branch 20 taken 1 times.
1 phoenix_assert(isStrUpperCase("TEST"));
91
6/6
✓ Branch 2 taken 1 times.
✓ Branch 6 taken 1 times.
✓ Branch 10 taken 1 times.
✓ Branch 14 taken 1 times.
✓ Branch 17 taken 1 times.
✓ Branch 20 taken 1 times.
1 phoenix_assert(isStrLowerCase("test"));
92 1 }
93
94 ///Check char type
95 /** @param tabChar : table of characters with the same results
96 * @param isNumber : true if the tabChar is composed of numbers
97 * @param isLetter : true if the tabChar is composed of letters
98 * @param isLowerCase : true if the tabChar is composed of lower cases
99 * @param isUpperCase : true if the tabChar is composed of upper cases
100 * @param isDot : true if the tabChar is composed of dot
101 * @param isStar : true if the tabChar is composed of star
102 * @return true on success, false otherwise
103 */
104 5 bool testCharsType(const std::string & tabChar, bool isNumber, bool isLetter, bool isLowerCase, bool isUpperCase, bool isDot, bool isStar){
105 5 bool b(true);
106
2/2
✓ Branch 1 taken 64 times.
✓ Branch 2 taken 5 times.
69 for(size_t i(0lu); i < tabChar.size(); ++i){
107 64 char ch(tabChar[i]);
108 64 b &= isCharNumber(ch) == isNumber;
109 64 b &= isCharLetter(ch) == isLetter;
110
4/4
✓ Branch 1 taken 54 times.
✓ Branch 2 taken 10 times.
✓ Branch 3 taken 52 times.
✓ Branch 4 taken 2 times.
64 b &= (isCharNumberOrLetter(ch) == (isNumber || isLetter));
111
112 64 b &= isCharLowerCase(ch) == isLowerCase;
113 64 b &= isCharUpperCase(ch) == isUpperCase;
114
6/6
✓ Branch 1 taken 54 times.
✓ Branch 2 taken 10 times.
✓ Branch 3 taken 2 times.
✓ Branch 4 taken 52 times.
✓ Branch 5 taken 1 times.
✓ Branch 6 taken 1 times.
64 b &= isCharNumberOrLetterOrDot(ch) == (isNumber || isLetter || isDot);
115
6/6
✓ Branch 1 taken 54 times.
✓ Branch 2 taken 10 times.
✓ Branch 3 taken 2 times.
✓ Branch 4 taken 52 times.
✓ Branch 5 taken 1 times.
✓ Branch 6 taken 1 times.
64 b &= isCharNumberOrLetterOrStar(ch) == (isNumber || isLetter || isStar);
116
4/4
✓ Branch 1 taken 54 times.
✓ Branch 2 taken 10 times.
✓ Branch 3 taken 1 times.
✓ Branch 4 taken 53 times.
64 b &= isCharNumberOrStar(ch) == (isNumber || isStar);
117
4/4
✓ Branch 1 taken 12 times.
✓ Branch 2 taken 52 times.
✓ Branch 3 taken 1 times.
✓ Branch 4 taken 11 times.
64 b &= isCharLetterOrStar(ch) == (isLetter || isStar);
118
119 }
120 5 std::cout << "testCharsType ("<<tabChar<<", isNumber = "<<isNumber<<", isLetter = "<<isLetter<<", isLowerCase = "<<isLowerCase<<", isUpperCase = "<<isUpperCase<<", isDot = "<<isDot<<", isStar = "<<isStar<<": ";
121
122
2/2
✓ Branch 2 taken 5 times.
✓ Branch 5 taken 5 times.
5 phoenix_functionOk("testCharsType", b);
123 5 return b;
124 }
125
126 ///Test the is lower/upper case
127 1 void testIsType(){
128
6/6
✓ Branch 2 taken 1 times.
✓ Branch 6 taken 1 times.
✓ Branch 10 taken 1 times.
✓ Branch 14 taken 1 times.
✓ Branch 17 taken 1 times.
✓ Branch 20 taken 1 times.
1 phoenix_assert(!isStrNumber(""));
129
6/6
✓ Branch 2 taken 1 times.
✓ Branch 6 taken 1 times.
✓ Branch 10 taken 1 times.
✓ Branch 14 taken 1 times.
✓ Branch 17 taken 1 times.
✓ Branch 20 taken 1 times.
1 phoenix_assert(!isStrNumber("TEST"));
130
6/6
✓ Branch 2 taken 1 times.
✓ Branch 6 taken 1 times.
✓ Branch 10 taken 1 times.
✓ Branch 14 taken 1 times.
✓ Branch 17 taken 1 times.
✓ Branch 20 taken 1 times.
1 phoenix_assert(!isStrNumber("test"));
131
6/6
✓ Branch 2 taken 1 times.
✓ Branch 6 taken 1 times.
✓ Branch 10 taken 1 times.
✓ Branch 14 taken 1 times.
✓ Branch 17 taken 1 times.
✓ Branch 20 taken 1 times.
1 phoenix_assert(isStrNumber("12346"));
132
6/6
✓ Branch 2 taken 1 times.
✓ Branch 6 taken 1 times.
✓ Branch 10 taken 1 times.
✓ Branch 14 taken 1 times.
✓ Branch 17 taken 1 times.
✓ Branch 20 taken 1 times.
1 phoenix_assert(!isStrNumberDotMinusPlusE(""));
133
6/6
✓ Branch 2 taken 1 times.
✓ Branch 6 taken 1 times.
✓ Branch 10 taken 1 times.
✓ Branch 14 taken 1 times.
✓ Branch 17 taken 1 times.
✓ Branch 20 taken 1 times.
1 phoenix_assert(!isStrNumberDotMinusPlusE("Test"));
134
6/6
✓ Branch 2 taken 1 times.
✓ Branch 6 taken 1 times.
✓ Branch 10 taken 1 times.
✓ Branch 14 taken 1 times.
✓ Branch 17 taken 1 times.
✓ Branch 20 taken 1 times.
1 phoenix_assert(isStrNumberDotMinusPlusE("+1e-7"));
135
6/6
✓ Branch 2 taken 1 times.
✓ Branch 6 taken 1 times.
✓ Branch 10 taken 1 times.
✓ Branch 14 taken 1 times.
✓ Branch 17 taken 1 times.
✓ Branch 20 taken 1 times.
1 phoenix_assert(isStrNumberDotMinusPlusE("+1e7"));
136
6/6
✓ Branch 2 taken 1 times.
✓ Branch 6 taken 1 times.
✓ Branch 10 taken 1 times.
✓ Branch 14 taken 1 times.
✓ Branch 17 taken 1 times.
✓ Branch 20 taken 1 times.
1 phoenix_assert(isStrNumberDotMinusPlusE("-1e7"));
137
6/6
✓ Branch 2 taken 1 times.
✓ Branch 6 taken 1 times.
✓ Branch 10 taken 1 times.
✓ Branch 14 taken 1 times.
✓ Branch 17 taken 1 times.
✓ Branch 20 taken 1 times.
1 phoenix_assert(isStrNumberDotMinusPlusE("3.14"));
138
5/5
✓ Branch 2 taken 1 times.
✓ Branch 6 taken 1 times.
✓ Branch 10 taken 1 times.
✓ Branch 13 taken 1 times.
✓ Branch 16 taken 1 times.
1 phoenix_assert(isCharNumberOrDot('.'));
139
6/6
✓ Branch 2 taken 1 times.
✓ Branch 6 taken 1 times.
✓ Branch 10 taken 1 times.
✓ Branch 14 taken 1 times.
✓ Branch 17 taken 1 times.
✓ Branch 20 taken 1 times.
1 phoenix_assert(!isStrNumberOrDot(""));
140
6/6
✓ Branch 2 taken 1 times.
✓ Branch 6 taken 1 times.
✓ Branch 10 taken 1 times.
✓ Branch 14 taken 1 times.
✓ Branch 17 taken 1 times.
✓ Branch 20 taken 1 times.
1 phoenix_assert(!isStrNumberOrDot("test"));
141
6/6
✓ Branch 2 taken 1 times.
✓ Branch 6 taken 1 times.
✓ Branch 10 taken 1 times.
✓ Branch 14 taken 1 times.
✓ Branch 17 taken 1 times.
✓ Branch 20 taken 1 times.
1 phoenix_assert(isStrNumberOrDot("42"));
142
6/6
✓ Branch 2 taken 1 times.
✓ Branch 6 taken 1 times.
✓ Branch 10 taken 1 times.
✓ Branch 14 taken 1 times.
✓ Branch 17 taken 1 times.
✓ Branch 20 taken 1 times.
1 phoenix_assert(isStrNumberOrDot("3.14"));
143
6/6
✓ Branch 2 taken 1 times.
✓ Branch 6 taken 1 times.
✓ Branch 10 taken 1 times.
✓ Branch 14 taken 1 times.
✓ Branch 17 taken 1 times.
✓ Branch 20 taken 1 times.
1 phoenix_assert(testCharsType("0123456789", true, false, false, false, false, false));
144
6/6
✓ Branch 2 taken 1 times.
✓ Branch 6 taken 1 times.
✓ Branch 10 taken 1 times.
✓ Branch 14 taken 1 times.
✓ Branch 17 taken 1 times.
✓ Branch 20 taken 1 times.
1 phoenix_assert(testCharsType("abcdefghijklmnopqrstuvwxyz", false, true, true, false, false, false));
145
6/6
✓ Branch 2 taken 1 times.
✓ Branch 6 taken 1 times.
✓ Branch 10 taken 1 times.
✓ Branch 14 taken 1 times.
✓ Branch 17 taken 1 times.
✓ Branch 20 taken 1 times.
1 phoenix_assert(testCharsType("ABCDEFGHIJKLMNOPQRSTUVWXYZ", false, true, false, true, false, false));
146
6/6
✓ Branch 2 taken 1 times.
✓ Branch 6 taken 1 times.
✓ Branch 10 taken 1 times.
✓ Branch 14 taken 1 times.
✓ Branch 17 taken 1 times.
✓ Branch 20 taken 1 times.
1 phoenix_assert(testCharsType(".", false, false, false, false, true, false));
147
6/6
✓ Branch 2 taken 1 times.
✓ Branch 6 taken 1 times.
✓ Branch 10 taken 1 times.
✓ Branch 14 taken 1 times.
✓ Branch 17 taken 1 times.
✓ Branch 20 taken 1 times.
1 phoenix_assert(testCharsType("*", false, false, false, false, false, true));
148 1 }
149
150 ///Test the is lower/upper case
151 1 void testIsListStrNumber(){
152 1 std::list<std::string> listNb;
153
5/5
✓ Branch 2 taken 1 times.
✓ Branch 6 taken 1 times.
✓ Branch 10 taken 1 times.
✓ Branch 13 taken 1 times.
✓ Branch 16 taken 1 times.
1 phoenix_assert(!isListStrNumber(listNb));
154
2/2
✓ Branch 2 taken 1 times.
✓ Branch 5 taken 1 times.
1 listNb.push_back("10");
155
5/5
✓ Branch 2 taken 1 times.
✓ Branch 6 taken 1 times.
✓ Branch 10 taken 1 times.
✓ Branch 13 taken 1 times.
✓ Branch 16 taken 1 times.
1 phoenix_assert(isListStrNumber(listNb));
156
2/2
✓ Branch 2 taken 1 times.
✓ Branch 5 taken 1 times.
1 listNb.push_back("1");
157
5/5
✓ Branch 2 taken 1 times.
✓ Branch 6 taken 1 times.
✓ Branch 10 taken 1 times.
✓ Branch 13 taken 1 times.
✓ Branch 16 taken 1 times.
1 phoenix_assert(isListStrNumber(listNb));
158
2/2
✓ Branch 2 taken 1 times.
✓ Branch 5 taken 1 times.
1 listNb.push_back("Not a number");
159
5/5
✓ Branch 2 taken 1 times.
✓ Branch 6 taken 1 times.
✓ Branch 10 taken 1 times.
✓ Branch 13 taken 1 times.
✓ Branch 16 taken 1 times.
1 phoenix_assert(!isListStrNumber(listNb));
160 1 }
161
162 1 int main(int argc, char** argv){
163 1 testStringLowerUpper();
164 1 testIsLowerUpper();
165 1 testIsType();
166 1 testIsListStrNumber();
167 1 return 0;
168 }
169
170
171