GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: tmp_project/StringUtils/TESTS/TEST_LOWER_UPPER/main.cpp Lines: 100 100 100.0 %
Date: 2023-10-11 10:52:07 Branches: 175 175 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_check.h"
10
11
#include "string_lower_upper.h"
12
13
///Check string lower expression
14
/**	@param testName : name of the test
15
 * 	@param strValue : string to be tested
16
 * 	@param strReference : reference string
17
 * 	@return true is both strings are equal, false otherwise
18
*/
19
3
bool checkResultLower(const std::string & testName, const std::string & strValue, const std::string & strReference){
20
3
	std::string convertedValue(strToLower(strValue));
21

6
	return phoenix_check(testName + " Lower (" + strValue + ")", convertedValue, strReference);
22
}
23
24
///Check string upper expression
25
/**	@param testName : name of the test
26
 * 	@param strValue : string to be tested
27
 * 	@param strReference : reference string
28
 * 	@return true is both strings are equal, false otherwise
29
*/
30
3
bool checkResultUpper(const std::string & testName, const std::string & strValue, const std::string & strReference){
31
3
	std::string convertedValue(strToUpper(strValue));
32

6
	return phoenix_check(testName + " Upper (" + strValue + ")", convertedValue, strReference);
33
}
34
35
///Check string lower expression
36
/**	@param testName : name of the test
37
 * 	@param strValue : string to be tested
38
 * 	@param strReference : reference string
39
 * 	@return true is both strings are equal, false otherwise
40
*/
41
3
bool checkResultFirstLower(const std::string & testName, const std::string & strValue, const std::string & strReference){
42
3
	std::string convertedValue(firstToLower(strValue));
43

6
	return phoenix_check(testName + " firstToLower (" + strValue + ")", convertedValue, strReference);
44
}
45
46
///Check string upper expression
47
/**	@param testName : name of the test
48
 * 	@param strValue : string to be tested
49
 * 	@param strReference : reference string
50
 * 	@return true is both strings are equal, false otherwise
51
*/
52
4
bool checkResultFirstUpper(const std::string & testName, const std::string & strValue, const std::string & strReference){
53
4
	std::string convertedValue(firstToUpper(strValue));
54

8
	return phoenix_check(testName + " firstToUpper (" + strValue + ")", convertedValue, strReference);
55
}
56
57
///Check string lower expression
58
/**	@param testName : name of the test
59
 * 	@param strValue : string to be tested
60
 * 	@param strReference : reference string
61
 * 	@return true is both strings are equal, false otherwise
62
*/
63
2
bool checkResultLowerUnderscore(const std::string & testName, const std::string & strValue, const std::string & strReference){
64
2
	std::string convertedValue(strToLowerUnderscore(strValue));
65

4
	return phoenix_check(testName + " strToLowerUnderscore (" + strValue + ")", convertedValue, strReference);
66
}
67
68
///Test lower/upper to string
69
/**	@return true on success, false otherwise
70
*/
71
1
bool testStringLowerUpper(){
72
1
	bool b(true);
73

1
	b &= checkResultLower("Test", "StRiNg", "string");
74

1
	b &= checkResultLower("Test", "StRiNg1234", "string1234");
75

1
	b &= checkResultLower("Test", "ABCDEFGHIJKLMNOPQRSTUVWXYZ", "abcdefghijklmnopqrstuvwxyz");
76
77

1
	b &= checkResultUpper("Test", "StRiNg", "STRING");
78

1
	b &= checkResultUpper("Test", "StRiNg1234", "STRING1234");
79

1
	b &= checkResultUpper("Test", "abcdefghijklmnopqrstuvwxyz", "ABCDEFGHIJKLMNOPQRSTUVWXYZ");
80
81

1
	b &= checkResultFirstLower("Test", "ABC", "aBC");
82

1
	b &= checkResultFirstLower("Test", "aBC", "aBC");
83

1
	b &= checkResultFirstLower("Test", "Vec", "vec");
84
85

1
	b &= checkResultFirstUpper("Test", "ABC", "ABC");
86

1
	b &= checkResultFirstUpper("Test", "Vec", "Vec");
87

1
	b &= checkResultFirstUpper("Test", "aBC", "ABC");
88

1
	b &= checkResultFirstUpper("Test", "vec", "Vec");
89
90

1
	b &= checkResultLowerUnderscore("Test", "StringType", "stringtype");
91

1
	b &= checkResultLowerUnderscore("Test", "String Type", "string_type");
92
1
	phoenix_functionOk("testStringLowerUpper", b);
93
1
	return b;
94
}
95
96
///Test the is lower/upper case
97
/**	@return true on success, false otherwise
98
*/
99
1
bool testIsLowerUpper(){
100
1
	bool b(true);
101
1
	b &= isStrUpperCase("TEST");
102
1
	b &= isStrLowerCase("test");
103
104
1
	phoenix_functionOk("testIsLowerUpper", b);
105
1
	return b;
106
}
107
108
///Check char type
109
/**	@param tabChar : table of characters with the same results
110
 * 	@param isNumber : true if the tabChar is composed of numbers
111
 * 	@param isLetter : true if the tabChar is composed of letters
112
 * 	@param isLowerCase : true if the tabChar is composed of lower cases
113
 * 	@param isUpperCase : true if the tabChar is composed of upper cases
114
 * 	@param isDot : true if the tabChar is composed of dot
115
 * 	@param isStar : true if the tabChar is composed of star
116
 * 	@return true on success, false otherwise
117
*/
118
5
bool testCharsType(const std::string & tabChar, bool isNumber, bool isLetter, bool isLowerCase, bool isUpperCase, bool isDot, bool isStar){
119
5
	bool b(true);
120
69
	for(size_t i(0lu); i < tabChar.size(); ++i){
121
64
		char ch(tabChar[i]);
122
64
		b &= isCharNumber(ch) == isNumber;
123
64
		b &= isCharLetter(ch) == isLetter;
124

64
		b &= (isCharNumberOrLetter(ch) == (isNumber || isLetter));
125
126
64
		b &= isCharLowerCase(ch) == isLowerCase;
127
64
		b &= isCharUpperCase(ch) == isUpperCase;
128

64
		b &= isCharNumberOrLetterOrDot(ch) == (isNumber || isLetter || isDot);
129

64
		b &= isCharNumberOrLetterOrStar(ch) == (isNumber || isLetter || isStar);
130

64
		b &= isCharNumberOrStar(ch) == (isNumber || isStar);
131

64
		b &= isCharLetterOrStar(ch) == (isLetter || isStar);
132
133
	}
134
5
	std::cout << "testCharsType ("<<tabChar<<", isNumber = "<<isNumber<<", isLetter = "<<isLetter<<", isLowerCase = "<<isLowerCase<<", isUpperCase = "<<isUpperCase<<", isDot = "<<isDot<<", isStar = "<<isStar<<": ";
135
136
5
	phoenix_functionOk("testCharsType", b);
137
5
	return b;
138
}
139
140
///Test the is lower/upper case
141
/**	@return true on success, false otherwise
142
*/
143
1
bool testIsType(){
144
1
	bool b(true);
145
1
	b &= !isStrNumber("");
146
1
	b &= !isStrNumber("TEST");
147
1
	b &= !isStrNumber("test");
148
1
	b &= isStrNumber("12346");
149
1
	b &= !isStrNumberDotMinusPlusE("");
150
1
	b &= !isStrNumberDotMinusPlusE("Test");
151
1
	b &= isStrNumberDotMinusPlusE("+1e-7");
152
1
	b &= isStrNumberDotMinusPlusE("+1e7");
153
1
	b &= isStrNumberDotMinusPlusE("-1e7");
154
1
	b &= isStrNumberDotMinusPlusE("3.14");
155
1
	b &= isCharNumberOrDot('.');
156
157
1
	b &= !isStrNumberOrDot("");
158
1
	b &= !isStrNumberOrDot("test");
159
1
	b &= isStrNumberOrDot("42");
160
1
	b &= isStrNumberOrDot("3.14");
161
162
1
	b &= testCharsType("0123456789", true, false, false, false, false, false);
163
1
	b &= testCharsType("abcdefghijklmnopqrstuvwxyz", false, true, true, false, false, false);
164
1
	b &= testCharsType("ABCDEFGHIJKLMNOPQRSTUVWXYZ", false, true, false, true, false, false);
165
166
1
	b &= testCharsType(".", false, false, false, false, true, false);
167
1
	b &= testCharsType("*", false, false, false, false, false, true);
168
169
1
	phoenix_functionOk("testIsType", b);
170
1
	return b;
171
}
172
173
///Test the is lower/upper case
174
/**	@return true on success, false otherwise
175
*/
176
1
bool testIsListStrNumber(){
177
1
	bool b(true);
178
1
	std::list<std::string> listNb;
179
1
	b &= !isListStrNumber(listNb);
180
1
	listNb.push_back("10");
181
1
	b &= isListStrNumber(listNb);
182
1
	listNb.push_back("1");
183
1
	b &= isListStrNumber(listNb);
184
1
	listNb.push_back("Not a number");
185
1
	b &= !isListStrNumber(listNb);
186
187
1
	phoenix_functionOk("testIsListStrNumber", b);
188
2
	return b;
189
}
190
191
1
int main(int argc, char** argv){
192
1
	bool b(true);
193
1
	b &= testStringLowerUpper();
194
1
	b &= testIsLowerUpper();
195
1
	b &= testIsType();
196
1
	b &= testIsListStrNumber();
197
198
1
	phoenix_functionOk("final", b);
199
1
	return b - 1;
200
}
201
202