GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: tmp_project/StringUtils/TESTS/TEST_LOWER_UPPER/main.cpp Lines: 90 90 100.0 %
Date: 2024-12-09 15:30:52 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
3
	std::string convertedValue(strToLower(strValue));
22

6
	return phoenix_check(testName + " Lower (" + strValue + ")", convertedValue, strReference);
23
}
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
3
	std::string convertedValue(strToUpper(strValue));
33

6
	return phoenix_check(testName + " Upper (" + strValue + ")", convertedValue, strReference);
34
}
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
3
	std::string convertedValue(firstToLower(strValue));
44

6
	return phoenix_check(testName + " firstToLower (" + strValue + ")", convertedValue, strReference);
45
}
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
4
	std::string convertedValue(firstToUpper(strValue));
55

8
	return phoenix_check(testName + " firstToUpper (" + strValue + ")", convertedValue, strReference);
56
}
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
2
	std::string convertedValue(strToLowerUnderscore(strValue));
66

4
	return phoenix_check(testName + " strToLowerUnderscore (" + strValue + ")", convertedValue, strReference);
67
}
68
69
///Test lower/upper to string
70
1
void testStringLowerUpper(){
71


1
	phoenix_assert(checkResultLower("Test", "StRiNg", "string"));
72


1
	phoenix_assert(checkResultLower("Test", "StRiNg1234", "string1234"));
73


1
	phoenix_assert(checkResultLower("Test", "ABCDEFGHIJKLMNOPQRSTUVWXYZ", "abcdefghijklmnopqrstuvwxyz"));
74


1
	phoenix_assert(checkResultUpper("Test", "StRiNg", "STRING"));
75


1
	phoenix_assert(checkResultUpper("Test", "StRiNg1234", "STRING1234"));
76


1
	phoenix_assert(checkResultUpper("Test", "abcdefghijklmnopqrstuvwxyz", "ABCDEFGHIJKLMNOPQRSTUVWXYZ"));
77


1
	phoenix_assert(checkResultFirstLower("Test", "ABC", "aBC"));
78


1
	phoenix_assert(checkResultFirstLower("Test", "aBC", "aBC"));
79


1
	phoenix_assert(checkResultFirstLower("Test", "Vec", "vec"));
80


1
	phoenix_assert(checkResultFirstUpper("Test", "ABC", "ABC"));
81


1
	phoenix_assert(checkResultFirstUpper("Test", "Vec", "Vec"));
82


1
	phoenix_assert(checkResultFirstUpper("Test", "aBC", "ABC"));
83


1
	phoenix_assert(checkResultFirstUpper("Test", "vec", "Vec"));
84


1
	phoenix_assert(checkResultLowerUnderscore("Test", "StringType", "stringtype"));
85


1
	phoenix_assert(checkResultLowerUnderscore("Test", "String Type", "string_type"));
86
1
}
87
88
///Test the is lower/upper case
89
1
void testIsLowerUpper(){
90

1
	phoenix_assert(isStrUpperCase("TEST"));
91

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
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

64
		b &= (isCharNumberOrLetter(ch) == (isNumber || isLetter));
111
112
64
		b &= isCharLowerCase(ch) == isLowerCase;
113
64
		b &= isCharUpperCase(ch) == isUpperCase;
114

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

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

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

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
5
	phoenix_functionOk("testCharsType", b);
123
5
	return b;
124
}
125
126
///Test the is lower/upper case
127
1
void testIsType(){
128

1
	phoenix_assert(!isStrNumber(""));
129

1
	phoenix_assert(!isStrNumber("TEST"));
130

1
	phoenix_assert(!isStrNumber("test"));
131

1
	phoenix_assert(isStrNumber("12346"));
132

1
	phoenix_assert(!isStrNumberDotMinusPlusE(""));
133

1
	phoenix_assert(!isStrNumberDotMinusPlusE("Test"));
134

1
	phoenix_assert(isStrNumberDotMinusPlusE("+1e-7"));
135

1
	phoenix_assert(isStrNumberDotMinusPlusE("+1e7"));
136

1
	phoenix_assert(isStrNumberDotMinusPlusE("-1e7"));
137

1
	phoenix_assert(isStrNumberDotMinusPlusE("3.14"));
138

1
	phoenix_assert(isCharNumberOrDot('.'));
139

1
	phoenix_assert(!isStrNumberOrDot(""));
140

1
	phoenix_assert(!isStrNumberOrDot("test"));
141

1
	phoenix_assert(isStrNumberOrDot("42"));
142

1
	phoenix_assert(isStrNumberOrDot("3.14"));
143

1
	phoenix_assert(testCharsType("0123456789", true, false, false, false, false, false));
144

1
	phoenix_assert(testCharsType("abcdefghijklmnopqrstuvwxyz", false, true, true, false, false, false));
145

1
	phoenix_assert(testCharsType("ABCDEFGHIJKLMNOPQRSTUVWXYZ", false, true, false, true, false, false));
146

1
	phoenix_assert(testCharsType(".", false, false, false, false, true, false));
147

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

1
	phoenix_assert(!isListStrNumber(listNb));
154
1
	listNb.push_back("10");
155

1
	phoenix_assert(isListStrNumber(listNb));
156
1
	listNb.push_back("1");
157

1
	phoenix_assert(isListStrNumber(listNb));
158
1
	listNb.push_back("Not a number");
159

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