PhoenixMock  1.8.7
Tools to split/merge/print mock used in Phoenix
main.cpp
Go to the documentation of this file.
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 
15 
20 bool checkResultLower(const std::string & testName, const std::string & strValue, const std::string & strReference){
21  std::string convertedValue(strToLower(strValue));
22  return phoenix_check(testName + " Lower (" + strValue + ")", convertedValue, strReference);
23 }
24 
26 
31 bool checkResultUpper(const std::string & testName, const std::string & strValue, const std::string & strReference){
32  std::string convertedValue(strToUpper(strValue));
33  return phoenix_check(testName + " Upper (" + strValue + ")", convertedValue, strReference);
34 }
35 
37 
42 bool checkResultFirstLower(const std::string & testName, const std::string & strValue, const std::string & strReference){
43  std::string convertedValue(firstToLower(strValue));
44  return phoenix_check(testName + " firstToLower (" + strValue + ")", convertedValue, strReference);
45 }
46 
48 
53 bool checkResultFirstUpper(const std::string & testName, const std::string & strValue, const std::string & strReference){
54  std::string convertedValue(firstToUpper(strValue));
55  return phoenix_check(testName + " firstToUpper (" + strValue + ")", convertedValue, strReference);
56 }
57 
59 
64 bool checkResultLowerUnderscore(const std::string & testName, const std::string & strValue, const std::string & strReference){
65  std::string convertedValue(strToLowerUnderscore(strValue));
66  return phoenix_check(testName + " strToLowerUnderscore (" + strValue + ")", convertedValue, strReference);
67 }
68 
71  phoenix_assert(checkResultLower("Test", "StRiNg", "string"));
72  phoenix_assert(checkResultLower("Test", "StRiNg1234", "string1234"));
73  phoenix_assert(checkResultLower("Test", "ABCDEFGHIJKLMNOPQRSTUVWXYZ", "abcdefghijklmnopqrstuvwxyz"));
74  phoenix_assert(checkResultUpper("Test", "StRiNg", "STRING"));
75  phoenix_assert(checkResultUpper("Test", "StRiNg1234", "STRING1234"));
76  phoenix_assert(checkResultUpper("Test", "abcdefghijklmnopqrstuvwxyz", "ABCDEFGHIJKLMNOPQRSTUVWXYZ"));
77  phoenix_assert(checkResultFirstLower("Test", "ABC", "aBC"));
78  phoenix_assert(checkResultFirstLower("Test", "aBC", "aBC"));
79  phoenix_assert(checkResultFirstLower("Test", "Vec", "vec"));
80  phoenix_assert(checkResultFirstUpper("Test", "ABC", "ABC"));
81  phoenix_assert(checkResultFirstUpper("Test", "Vec", "Vec"));
82  phoenix_assert(checkResultFirstUpper("Test", "aBC", "ABC"));
83  phoenix_assert(checkResultFirstUpper("Test", "vec", "Vec"));
84  phoenix_assert(checkResultLowerUnderscore("Test", "StringType", "stringtype"));
85  phoenix_assert(checkResultLowerUnderscore("Test", "String Type", "string_type"));
86 }
87 
92 }
93 
95 
104 bool testCharsType(const std::string & tabChar, bool isNumber, bool isLetter, bool isLowerCase, bool isUpperCase, bool isDot, bool isStar){
105  bool b(true);
106  for(size_t i(0lu); i < tabChar.size(); ++i){
107  char ch(tabChar[i]);
108  b &= isCharNumber(ch) == isNumber;
109  b &= isCharLetter(ch) == isLetter;
110  b &= (isCharNumberOrLetter(ch) == (isNumber || isLetter));
111 
112  b &= isCharLowerCase(ch) == isLowerCase;
113  b &= isCharUpperCase(ch) == isUpperCase;
114  b &= isCharNumberOrLetterOrDot(ch) == (isNumber || isLetter || isDot);
115  b &= isCharNumberOrLetterOrStar(ch) == (isNumber || isLetter || isStar);
116  b &= isCharNumberOrStar(ch) == (isNumber || isStar);
117  b &= isCharLetterOrStar(ch) == (isLetter || isStar);
118 
119  }
120  std::cout << "testCharsType ("<<tabChar<<", isNumber = "<<isNumber<<", isLetter = "<<isLetter<<", isLowerCase = "<<isLowerCase<<", isUpperCase = "<<isUpperCase<<", isDot = "<<isDot<<", isStar = "<<isStar<<": ";
121 
122  phoenix_functionOk("testCharsType", b);
123  return b;
124 }
125 
127 void testIsType(){
129  phoenix_assert(!isStrNumber("TEST"));
130  phoenix_assert(!isStrNumber("test"));
131  phoenix_assert(isStrNumber("12346"));
143  phoenix_assert(testCharsType("0123456789", true, false, false, false, false, false));
144  phoenix_assert(testCharsType("abcdefghijklmnopqrstuvwxyz", false, true, true, false, false, false));
145  phoenix_assert(testCharsType("ABCDEFGHIJKLMNOPQRSTUVWXYZ", false, true, false, true, false, false));
146  phoenix_assert(testCharsType(".", false, false, false, false, true, false));
147  phoenix_assert(testCharsType("*", false, false, false, false, false, true));
148 }
149 
152  std::list<std::string> listNb;
154  listNb.push_back("10");
156  listNb.push_back("1");
158  listNb.push_back("Not a number");
160 }
161 
162 int main(int argc, char** argv){
165  testIsType();
167  return 0;
168 }
169 
170 
isCharNumberOrLetterOrDot
bool isCharNumberOrLetterOrDot(char ch)
Tels if the character is a letter, number, '.' or '_'.
Definition: string_lower_upper.cpp:114
firstToLower
std::string firstToLower(const std::string &str)
Convert first letter of the std::string in lower case.
Definition: string_lower_upper.cpp:262
isStrUpperCase
bool isStrUpperCase(const std::string &str)
Say if the given std::string is in uppercase.
Definition: string_lower_upper.cpp:162
strToLower
std::string strToLower(const std::string &str)
Convert std::string in lower case.
Definition: string_lower_upper.cpp:190
isCharLetter
bool isCharLetter(char ch)
Tels if the character is a letter or '_'.
Definition: string_lower_upper.cpp:98
phoenix_functionOk
void phoenix_functionOk(const std::string &functionName, bool b)
Print the check function return.
Definition: phoenix_isOk.cpp:23
firstToUpper
std::string firstToUpper(const std::string &str)
Convert first letter of the std::string in upper case.
Definition: string_lower_upper.cpp:248
testCharsType
bool testCharsType(const std::string &tabChar, bool isNumber, bool isLetter, bool isLowerCase, bool isUpperCase, bool isDot, bool isStar)
Check char type.
Definition: main.cpp:104
strToLowerUnderscore
std::string strToLowerUnderscore(const std::string &str)
Convert std::string in lower case and space in '_'.
Definition: string_lower_upper.cpp:228
checkResultLowerUnderscore
bool checkResultLowerUnderscore(const std::string &testName, const std::string &strValue, const std::string &strReference)
Check string lower expression.
Definition: main.cpp:64
checkResultLower
bool checkResultLower(const std::string &testName, const std::string &strValue, const std::string &strReference)
Check string lower expression.
Definition: main.cpp:20
isStrLowerCase
bool isStrLowerCase(const std::string &str)
Say if the given std::string is in lowercase.
Definition: string_lower_upper.cpp:176
testIsListStrNumber
void testIsListStrNumber()
Test the is lower/upper case.
Definition: main.cpp:151
testIsLowerUpper
void testIsLowerUpper()
Test the is lower/upper case.
Definition: main.cpp:89
checkResultUpper
bool checkResultUpper(const std::string &testName, const std::string &strValue, const std::string &strReference)
Check string upper expression.
Definition: main.cpp:31
phoenix_check
bool phoenix_check(const std::string &testName, const std::string &val, const std::string &reference)
Check two string.
Definition: phoenix_check.cpp:17
isCharNumberOrLetterOrStar
bool isCharNumberOrLetterOrStar(char ch)
Tels if the character is letter, number, star or '_'.
Definition: string_lower_upper.cpp:138
isCharUpperCase
bool isCharUpperCase(char ch)
Tels if the character is upper case letter.
Definition: string_lower_upper.cpp:146
testStringLowerUpper
void testStringLowerUpper()
Test lower/upper to string.
Definition: main.cpp:70
isCharLowerCase
bool isCharLowerCase(char ch)
Tels if the character is lower case letter.
Definition: string_lower_upper.cpp:154
isCharNumberOrStar
bool isCharNumberOrStar(char ch)
Tels if the character is number or star.
Definition: string_lower_upper.cpp:122
isStrNumber
bool isStrNumber(const std::string &str)
Tels if std::string contains figures.
Definition: string_lower_upper.cpp:22
isCharNumberOrDot
bool isCharNumberOrDot(char ch)
Tels if the character is a number or a '.'.
Definition: string_lower_upper.cpp:52
string_lower_upper.h
isCharLetterOrStar
bool isCharLetterOrStar(char ch)
Tels if the character is letter, star or '_'.
Definition: string_lower_upper.cpp:130
isListStrNumber
bool isListStrNumber(const std::list< std::string > &listStr)
Say if the list of std::string contains a number.
Definition: string_lower_upper.cpp:37
phoenix_assert
#define phoenix_assert(isOk)
Definition: phoenix_assert.h:19
checkResultFirstUpper
bool checkResultFirstUpper(const std::string &testName, const std::string &strValue, const std::string &strReference)
Check string upper expression.
Definition: main.cpp:53
isCharNumberOrLetter
bool isCharNumberOrLetter(char ch)
Tels if the character is letter, figure or '_'.
Definition: string_lower_upper.cpp:106
testIsType
void testIsType()
Test the is lower/upper case.
Definition: main.cpp:127
isCharNumber
bool isCharNumber(char ch)
Tels if the character is a number or not.
Definition: string_lower_upper.cpp:14
strToUpper
std::string strToUpper(const std::string &str)
Convert std::string in upper case.
Definition: string_lower_upper.cpp:209
phoenix_assert.h
checkResultFirstLower
bool checkResultFirstLower(const std::string &testName, const std::string &strValue, const std::string &strReference)
Check string lower expression.
Definition: main.cpp:42
main
int main(int argc, char **argv)
Definition: main.cpp:85
isStrNumberOrDot
bool isStrNumberOrDot(const std::string &str)
Tels if std::string contains figures or dots.
Definition: string_lower_upper.cpp:68
isStrNumberDotMinusPlusE
bool isStrNumberDotMinusPlusE(const std::string &str)
Tels if std::string std::string contains figures, '.', -, +, e or E.
Definition: string_lower_upper.cpp:83
phoenix_check.h