PhoenixMock  1.8.7
Tools to split/merge/print mock used in Phoenix
main.cpp File Reference
#include <iostream>
#include <vector>
#include "phoenix_assert.h"
#include "phoenix_check.h"
#include "string_function.h"
+ Include dependency graph for main.cpp:

Go to the source code of this file.

Functions

bool checkReplaceListStrInStr (const std::string &inputStr, const std::list< std::string > &vecPattern, const std::string &replace, const std::string &strReference)
 Check the replaceVectorStrInStr function. More...
 
bool checkReplaceVectorStrInStr (const std::string &inputStr, const std::vector< std::string > &vecPattern, const std::string &replace, const std::string &strReference)
 Check the replaceVectorStrInStr function. More...
 
bool checkString (const std::string &testName, const std::string &strValue, const std::string &strReference)
 Check string lower expression. More...
 
int main (int argc, char **argv)
 
void testCharToString ()
 Test the phoenix_charToString function. More...
 
void testEscapeString ()
 Test the phoenix_escapeStr function. More...
 
void testFindInListString ()
 Test the find in list string filename function. More...
 
void testGetCommonBegning ()
 Test the phoenix_getCommonBegining function. More...
 
void testReplaceListStrInStr ()
 Test the replaceVectorStrInStr function. More...
 
void testReplaceStrInStrMap ()
 Test the replace of str in str with map. More...
 
void testReplaceVectorStrInStr ()
 Test the replaceVectorStrInStr function. More...
 
void testStringFunction ()
 Test the string filename function. More...
 

Function Documentation

◆ checkReplaceListStrInStr()

bool checkReplaceListStrInStr ( const std::string &  inputStr,
const std::list< std::string > &  vecPattern,
const std::string &  replace,
const std::string &  strReference 
)

Check the replaceVectorStrInStr function.

Parameters
inputStr: input string
vecPattern: list of patterns
replace: substitution string
strReference: expected result
Returns
true on success, false otherwise

Definition at line 181 of file main.cpp.

183 {
184  std::string res(replaceListStrInStr(inputStr, vecPattern, replace));
185  return phoenix_check("", res, strReference);
186 }

References phoenix_check(), and replaceListStrInStr().

Referenced by testReplaceListStrInStr().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ checkReplaceVectorStrInStr()

bool checkReplaceVectorStrInStr ( const std::string &  inputStr,
const std::vector< std::string > &  vecPattern,
const std::string &  replace,
const std::string &  strReference 
)

Check the replaceVectorStrInStr function.

Parameters
inputStr: input string
vecPattern: vector of patterns
replace: substitution string
strReference: expected result
Returns
true on success, false otherwise

Definition at line 155 of file main.cpp.

157 {
158  std::string res(replaceVectorStrInStr(inputStr, vecPattern, replace));
159  return phoenix_check("", res, strReference);
160 }

References phoenix_check(), and replaceVectorStrInStr().

Referenced by testReplaceVectorStrInStr().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ checkString()

bool checkString ( const std::string &  testName,
const std::string &  strValue,
const std::string &  strReference 
)

Check string lower expression.

Parameters
testName: name of the test
strValue: string to be tested
strReference: reference string
Returns
true is both strings are equal, false otherwise

Definition at line 21 of file main.cpp.

21  {
22  return phoenix_check(testName, strValue, strReference);
23 }

References phoenix_check().

+ Here is the call graph for this function:

◆ main()

int main ( int  argc,
char **  argv 
)

◆ testCharToString()

void testCharToString ( )

Test the phoenix_charToString function.

Definition at line 210 of file main.cpp.

210  {
211  phoenix_assert(phoenix_charToString("some string") == "some string");
213 }

References phoenix_assert, and phoenix_charToString().

Referenced by main().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ testEscapeString()

void testEscapeString ( )

Test the phoenix_escapeStr function.

Definition at line 216 of file main.cpp.

216  {
217  phoenix_assert(phoenix_check("", phoenix_escapeStr("some string with escape's \"char\"", " '\"", "\\"), "some\\ string\\ with\\ escape\\'s\\ \\\"char\\\""));
218 }

References phoenix_assert, phoenix_check(), and phoenix_escapeStr().

Referenced by main().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ testFindInListString()

void testFindInListString ( )

Test the find in list string filename function.

Definition at line 26 of file main.cpp.

26  {
27  std::list<std::string> listStrRef;
28  phoenix_assert(!findInListString(listStrRef, ""));
29  listStrRef.push_back("one");
30  phoenix_assert(!findInListString(listStrRef, ""));
31  phoenix_assert(!findInListString(listStrRef, "other"));
32  phoenix_assert(findInListString(listStrRef, "one"));
33  listStrRef.push_back("two");
34  phoenix_assert(!findInListString(listStrRef, "other"));
35  phoenix_assert(findInListString(listStrRef, "two"));
36  listStrRef.push_back("three");
37  phoenix_assert(!findInListString(listStrRef, "other"));
38  phoenix_assert(findInListString(listStrRef, "two"));
39  phoenix_assert(findInListString(listStrRef, "three"));
40 
41  std::vector<std::string> vecStrRef;
42  phoenix_assert(!findInVectorString(vecStrRef, ""));
43  vecStrRef.push_back("one");
44  phoenix_assert(!findInVectorString(vecStrRef, ""));
45  phoenix_assert(!findInVectorString(vecStrRef, "other"));
46  phoenix_assert(findInVectorString(vecStrRef, "one"));
47  vecStrRef.push_back("two");
48  phoenix_assert(!findInVectorString(vecStrRef, "other"));
49  phoenix_assert(findInVectorString(vecStrRef, "two"));
50  vecStrRef.push_back("three");
51  phoenix_assert(!findInVectorString(vecStrRef, "other"));
52  phoenix_assert(findInVectorString(vecStrRef, "two"));
53  phoenix_assert(findInVectorString(vecStrRef, "three"));
54 
55  phoenix_assert(eraseLastCharsInStr("", "afe") == "");
56 
57  phoenix_assert(replaceStrInStr("", "", "") == "");
58  phoenix_assert(replaceStrInStr("", "o", "") == "");
59  phoenix_assert(replaceStrInStr("o", "", "") == "");
60 }

References eraseLastCharsInStr(), findInListString(), findInVectorString(), phoenix_assert, and replaceStrInStr().

Referenced by main().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ testGetCommonBegning()

void testGetCommonBegning ( )

Test the phoenix_getCommonBegining function.

Definition at line 221 of file main.cpp.

221  {
223  phoenix_assert(phoenix_getCommonBegining("someString", "") == "");
224  phoenix_assert(phoenix_getCommonBegining("", "someString") == "");
225  phoenix_assert(phoenix_getCommonBegining("someString", "someOtherString") == "some");
226  phoenix_assert(phoenix_getCommonBegining("someString", "AndsomeOtherString") == "");
227 }

References phoenix_assert, and phoenix_getCommonBegining().

Referenced by main().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ testReplaceListStrInStr()

void testReplaceListStrInStr ( )

Test the replaceVectorStrInStr function.

Definition at line 189 of file main.cpp.

189  {
190  std::list<std::string> vecStrPattern;
191  phoenix_assert(checkReplaceListStrInStr("", vecStrPattern, "", ""));
192  phoenix_assert(checkReplaceListStrInStr("something", vecStrPattern, "", "something"));
193  vecStrPattern.push_back("key");
194  phoenix_assert(checkReplaceListStrInStr("", vecStrPattern, "", ""));
195  phoenix_assert(checkReplaceListStrInStr("convert value to key", vecStrPattern, "value", "convert value to value"));
196  vecStrPattern.push_back("value");
197  phoenix_assert(checkReplaceListStrInStr("convert value to key", vecStrPattern, "thing", "convert thing to thing"));
198 }

References checkReplaceListStrInStr(), and phoenix_assert.

Referenced by main().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ testReplaceStrInStrMap()

void testReplaceStrInStrMap ( )

Test the replace of str in str with map.

Definition at line 201 of file main.cpp.

201  {
202  std::map<std::string, std::string> mapReplace;
203  phoenix_assert(replaceStrInStr("some string to convert", mapReplace) == "some string to convert");
204  mapReplace["string"] = "value";
205  mapReplace["convert"] = "replace";
206  phoenix_assert(replaceStrInStr("some string to convert", mapReplace) == "some value to replace");
207 }

References phoenix_assert, and replaceStrInStr().

Referenced by main().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ testReplaceVectorStrInStr()

void testReplaceVectorStrInStr ( )

Test the replaceVectorStrInStr function.

Definition at line 163 of file main.cpp.

163  {
164  std::vector<std::string> vecStrPattern;
165  phoenix_assert(checkReplaceVectorStrInStr("", vecStrPattern, "", ""));
166  phoenix_assert(checkReplaceVectorStrInStr("something", vecStrPattern, "", "something"));
167  vecStrPattern.push_back("key");
168  phoenix_assert(checkReplaceVectorStrInStr("", vecStrPattern, "", ""));
169  phoenix_assert(checkReplaceVectorStrInStr("convert value to key", vecStrPattern, "value", "convert value to value"));
170  vecStrPattern.push_back("value");
171  phoenix_assert(checkReplaceVectorStrInStr("convert value to key", vecStrPattern, "thing", "convert thing to thing"));
172 }

References checkReplaceVectorStrInStr(), and phoenix_assert.

Referenced by main().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ testStringFunction()

void testStringFunction ( )

Test the string filename function.

Definition at line 63 of file main.cpp.

63  {
64  std::string testString("some string to be used");
65 
66  phoenix_assert(checkString("Test replaceCharInStr", replaceCharInStr(testString, 'o', "O"), "sOme string tO be used"));
67  phoenix_assert(checkString("Test replaceCharsInStr", replaceCharsInStr(testString, "ot", 'X'), "sXme sXring XX be used"));
68  phoenix_assert(checkString("Test replaceStrInStr", replaceStrInStr(testString, "string", "text"), "some text to be used"));
69  phoenix_assert(checkString("Test replaceStrInStr full", replaceStrInStr("string", "string", "text"), "text"));
70  std::vector<std::string> vecStringToReplace;
71  vecStringToReplace.push_back(testString);
72  std::vector<std::string> vecReplacedString = replaceStrInStr(vecStringToReplace, "string", "text");
73  phoenix_assert(checkString("Test replaceStrInStr vector", vecReplacedString[0], "some text to be used"));
74  phoenix_assert(checkString("Test copyStr", copyStr("Some string", 2lu, 4lu), "me s"));
75  phoenix_assert(checkString("Test eraseCharInStr", eraseCharInStr(testString, 'o'), "sme string t be used"));
76  phoenix_assert(checkString("Test eraseCharInStr", eraseCharInStr("", 'o'), ""));
77  phoenix_assert(checkString("Test eraseCharsInStr", eraseCharsInStr(testString, "o"), "sme string t be used"));
78  phoenix_assert(checkString("Test eraseCharsInStr", eraseCharsInStr(testString, "oxi"), "sme strng t be used"));
79  phoenix_assert(checkString("Test eraseCharsInStr", eraseCharsInStr("", "o"), ""));
80  phoenix_assert(checkString("Test replaceCharsInStr", replaceCharsInStr("", "o", 'd'), ""));
81  phoenix_assert(checkString("Test replaceCharsInStr", replaceCharsInStr("", "", 'd'), ""));
82  phoenix_assert(checkString("Test replaceCharsInStr", replaceCharsInStr("o", "", 'd'), "o"));
83 
84  std::vector<std::string> vecStrRef;
85  vecStrRef.push_back("one");
86  vecStrRef.push_back("two");
87  vecStrRef.push_back("three");
88 
89  std::list<std::string> listStr(cutStringList("one two three", ' '));
90  std::vector<std::string> vecStr(cutStringVector("one two three", ' '));
91 
92  std::list<std::string> listSpaceStr(cutStringOnSpacesList("one two three"));
93  std::vector<std::string> vecSpaceStr(cutStringOnSpacesVector("one two three"));
94 
95  std::list<std::string>::iterator itList(listStr.begin());
96  std::list<std::string>::iterator itSpaceList(listSpaceStr.begin());
97  std::vector<std::string>::iterator itVec(vecStr.begin());
98  std::vector<std::string>::iterator itSpaceVec(vecSpaceStr.begin());
99  std::vector<std::string>::iterator itVecRef(vecStrRef.begin());
100 
101  while(itList != listStr.end() && itVec != vecStr.end() && itVecRef != vecStrRef.end() && itSpaceList != listSpaceStr.end() && itSpaceVec != vecSpaceStr.end()){
102  phoenix_assert(*itList == *itVec && *itVec ==* itVecRef);
103  phoenix_assert(*itSpaceList == *itVec && *itSpaceVec == *itVec);
104 
105  ++itList;
106  ++itVec;
107  ++itVecRef;
108  ++itSpaceList;
109  ++itSpaceVec;
110  }
111 
112  phoenix_assert(!findInString("", 'a'));
113  phoenix_assert(findInString("abc", 'a'));
114  phoenix_assert(findInString("abc", 'b'));
115  phoenix_assert(findInString("abc", 'c'));
116  phoenix_assert(!findInString("abc", 'd'));
119  phoenix_assert(!findCharsInString("abc", ""));
120  phoenix_assert(findCharsInString("abc", "a"));
121  phoenix_assert(findCharsInString("abc", "b"));
122  phoenix_assert(findCharsInString("abc", "c"));
123  phoenix_assert(!findCharsInString("abc", "d"));
124  phoenix_assert(findCharsInString("abc", "xa"));
125  phoenix_assert(findCharsInString("abc", "xb"));
126  phoenix_assert(findCharsInString("abc", "xc"));
127  phoenix_assert(!findCharsInString("abc", "xd"));
128  phoenix_assert(findCharsInString("abc", "ax"));
129  phoenix_assert(findCharsInString("abc", "bx"));
130  phoenix_assert(findCharsInString("abc", "cx"));
131  phoenix_assert(!findCharsInString("abc", "dx"));
132  phoenix_assert(countNbChar("", 'o') == 0lu);
133  phoenix_assert(countNbChar("some thing to count", 'o') == 3lu);
134  phoenix_assert(countNbChar("some thing to count", 'w') == 0lu);
136  phoenix_assert(!isSameBegining("", "d"));
137  phoenix_assert(isSameBegining("start", "start"));
138  phoenix_assert(isSameBegining("start", "st"));
139  phoenix_assert(!isSameBegining("st", "start"));
140 
141  phoenix_assert(countStrInStr("some string with text", "") == 0lu);
142  phoenix_assert(countStrInStr("", "nothing") == 0lu);
143  phoenix_assert(countStrInStr("", "") == 0lu);
144  phoenix_assert(countStrInStr("some string with text", "with") == 1lu);
145  phoenix_assert(countStrInStr("one char and two chars", "char") == 2lu);
146 }

References checkString(), copyStr(), countNbChar(), countStrInStr(), cutStringList(), cutStringOnSpacesList(), cutStringOnSpacesVector(), cutStringVector(), eraseCharInStr(), eraseCharsInStr(), findCharsInString(), findInString(), isSameBegining(), phoenix_assert, replaceCharInStr(), replaceCharsInStr(), and replaceStrInStr().

Referenced by main().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:
testCharToString
void testCharToString()
Test the phoenix_charToString function.
Definition: main.cpp:210
cutStringOnSpacesVector
std::vector< std::string > cutStringOnSpacesVector(const std::string &str)
Cut a string on white characters ('&#92;t' ou ' ')
Definition: string_function.cpp:490
testStringFunction
void testStringFunction()
Test the string filename function.
Definition: main.cpp:63
eraseCharInStr
std::string eraseCharInStr(const std::string &str, char ch)
copie la string str en effaçant le caractère ch
Definition: string_function.cpp:160
findInVectorString
bool findInVectorString(const std::vector< std::string > &vecStr, const std::string &str)
Find a string in a vector of string.
Definition: string_function.cpp:61
replaceListStrInStr
void replaceListStrInStr(std::string &srcDest, const std::list< std::string > &listPatern, const std::string &replace)
Replace all the list patern in the string srcDest by the replace string.
Definition: string_function.cpp:346
phoenix_charToString
std::string phoenix_charToString(const char *ch)
Convert a char pointer into a string (event if the char pointer is NULL)
Definition: string_function.cpp:547
cutStringOnSpacesList
std::list< std::string > cutStringOnSpacesList(const std::string &str)
Cut a string on white characters ('&#92;t' ou ' ')
Definition: string_function.cpp:467
findCharsInString
bool findCharsInString(const std::string &str, const std::string &chars)
Find multiple chars in a string.
Definition: string_function.cpp:29
testFindInListString
void testFindInListString()
Test the find in list string filename function.
Definition: main.cpp:26
findInString
bool findInString(const std::string &str, char ch)
Find a char in a string.
Definition: string_function.cpp:15
replaceCharInStr
std::string replaceCharInStr(const std::string &str, char find, char replace)
fonction qui remplace un caractère par un autre dans une string
Definition: string_function.cpp:187
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
isSameBegining
bool isSameBegining(const std::string &str, const std::string &beginig)
Check if two string start the same way.
Definition: string_function.cpp:531
checkReplaceVectorStrInStr
bool checkReplaceVectorStrInStr(const std::string &inputStr, const std::vector< std::string > &vecPattern, const std::string &replace, const std::string &strReference)
Check the replaceVectorStrInStr function.
Definition: main.cpp:155
cutStringList
std::list< std::string > cutStringList(const std::string &str, char separator)
Cut a string the the given separator char.
Definition: string_function.cpp:428
replaceVectorStrInStr
void replaceVectorStrInStr(std::string &srcDest, const std::vector< std::string > &vecPatern, const std::string &replace)
Replace all the vector patern in the string srcDest by the replace string.
Definition: string_function.cpp:334
copyStr
std::string copyStr(const std::string &str, long unsigned int begin, long unsigned int nbCh)
Copy a string of nbCh starting from begin char.
Definition: string_function.cpp:515
eraseCharsInStr
std::string eraseCharsInStr(const std::string &str, const std::string &rmchs)
copie la string str en effaçant les caractères rmchs
Definition: string_function.cpp:173
testReplaceVectorStrInStr
void testReplaceVectorStrInStr()
Test the replaceVectorStrInStr function.
Definition: main.cpp:163
testReplaceStrInStrMap
void testReplaceStrInStrMap()
Test the replace of str in str with map.
Definition: main.cpp:201
findInListString
bool findInListString(const std::list< std::string > &listStr, const std::string &str)
Find a string in a list of string.
Definition: string_function.cpp:45
testEscapeString
void testEscapeString()
Test the phoenix_escapeStr function.
Definition: main.cpp:216
countStrInStr
size_t countStrInStr(const std::string &src, const std::string &patern)
Count the number of patern in string.
Definition: string_function.cpp:237
testReplaceListStrInStr
void testReplaceListStrInStr()
Test the replaceVectorStrInStr function.
Definition: main.cpp:189
replaceCharsInStr
std::string replaceCharsInStr(const std::string &str, const std::string &strFind, char replace)
Replace all char in the strFind by char replace.
Definition: string_function.cpp:205
phoenix_assert
#define phoenix_assert(isOk)
Definition: phoenix_assert.h:19
eraseLastCharsInStr
std::string eraseLastCharsInStr(const std::string &str, const std::string &chars)
Erase first and last char in a string.
Definition: string_function.cpp:97
phoenix_escapeStr
std::string phoenix_escapeStr(const std::string &src, const std::string &strCharToEscape, const std::string &escapeStr)
Escape given string with passed characters.
Definition: string_function.cpp:411
cutStringVector
std::vector< std::string > cutStringVector(const std::string &str, char separator)
Cut a string the the given separator char.
Definition: string_function.cpp:448
replaceStrInStr
void replaceStrInStr(std::string &out, const std::string &src, const std::string &patern, const std::string &replace)
Replace a patern by an other in the input string.
Definition: string_function.cpp:272
phoenix_getCommonBegining
std::string phoenix_getCommonBegining(const std::string &str1, const std::string &str2)
Get the common begining between str1 and str2.
Definition: string_function.cpp:561
countNbChar
size_t countNbChar(const std::string &str, char ch)
Count number of chararacters ch in string.
Definition: string_function.cpp:145
checkString
bool checkString(const std::string &testName, const std::string &strValue, const std::string &strReference)
Check string lower expression.
Definition: main.cpp:21
checkReplaceListStrInStr
bool checkReplaceListStrInStr(const std::string &inputStr, const std::list< std::string > &vecPattern, const std::string &replace, const std::string &strReference)
Check the replaceVectorStrInStr function.
Definition: main.cpp:181
testGetCommonBegning
void testGetCommonBegning()
Test the phoenix_getCommonBegining function.
Definition: main.cpp:221