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

Go to the source code of this file.

Functions

bool checkOptionCompletion (const std::string &program, const std::string &partialOption, const std::string &prevCursorOption, const std::string &cursorOption, const std::string &expectedResult)
 Check the option completion of a program. More...
 
bool checkResult (const std::string &resultCmd, const std::string &expectedResult)
 Check the restut. More...
 
bool checkResultSeparator (const std::string &resultCmd, const std::string &expectedResult, char separator)
 Check the restut. More...
 
void fillMapString (std::map< std::string, bool > &mapStr, const std::list< std::string > &listStr)
 Create a map with a string. More...
 
int main (int argc, char **argv)
 
void testCompletion ()
 Test the completion of the option. More...
 

Function Documentation

◆ checkOptionCompletion()

bool checkOptionCompletion ( const std::string &  program,
const std::string &  partialOption,
const std::string &  prevCursorOption,
const std::string &  cursorOption,
const std::string &  expectedResult 
)

Check the option completion of a program.

Parameters
program: program to be tested
partialOption: partial typed option
prevCursorOption: previous cursor option
cursorOption: option of the cursor
expectedResult: expected completion result
Returns
true on success, false otherwise

Definition at line 69 of file main.cpp.

71 {
72  std::string command(program + " __bashcompletionmode=\""+cursorOption+"\" __bashcompletionmodeprev=\""+prevCursorOption+"\" prgName " + partialOption);
73  std::string resultCmd(phoenix_popen(command));
74 // std::cout << "checkOptionCompletion : command '"<<command<<"':\n\tresult = '"<<resultCmd<<"', expectedResult = '"<<expectedResult<<"'" << std::endl;
75 
76  bool b(checkResult(resultCmd, expectedResult));
77  return b;
78 }

References checkResult(), and phoenix_popen().

+ Here is the call graph for this function:

◆ checkResult()

bool checkResult ( const std::string &  resultCmd,
const std::string &  expectedResult 
)

Check the restut.

Parameters
resultCmd: result
expectedResult: expected result
Returns
true if the results matches the expected result, false otherwise

Definition at line 52 of file main.cpp.

52  {
53  if(!checkResultSeparator(resultCmd, expectedResult, ' ')){
54  if(!checkResultSeparator(resultCmd, expectedResult, '\n')){
55  return false;
56  }
57  }
58  return true;
59 }

References checkResultSeparator().

Referenced by checkOptionCompletion().

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

◆ checkResultSeparator()

bool checkResultSeparator ( const std::string &  resultCmd,
const std::string &  expectedResult,
char  separator 
)

Check the restut.

Parameters
resultCmd: result
expectedResult: expected result
separator: separator to be used to split the results
Returns
true if the results matches the expected result, false otherwise

Definition at line 32 of file main.cpp.

32  {
33  std::list<std::string> listRes = cutStringList(resultCmd, separator);
34  std::list<std::string> listExpectedRes = cutStringList(expectedResult, separator);
35 
36  std::map<std::string, bool> mapExpectedRes;
37  fillMapString(mapExpectedRes, listExpectedRes);
38 
39  bool b(true);
40  for(std::list<std::string>::const_iterator it(listRes.begin()); it != listRes.end(); ++it){
41  b &= mapExpectedRes.find(*it) != mapExpectedRes.end();
42  }
43 
44  return b;
45 }

References cutStringList(), and fillMapString().

Referenced by checkResult().

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

◆ fillMapString()

void fillMapString ( std::map< std::string, bool > &  mapStr,
const std::list< std::string > &  listStr 
)

Create a map with a string.

Parameters
mapStr: map of string to be created
listStr: list of string to be used

Definition at line 20 of file main.cpp.

20  {
21  for(std::list<std::string>::const_iterator it(listStr.begin()); it != listStr.end(); ++it){
22  mapStr[*it] = true;
23  }
24 }

Referenced by checkResultSeparator().

+ Here is the caller graph for this function:

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 100 of file main.cpp.

100  {
101  testCompletion();
102  return 0;
103 }

References testCompletion().

+ Here is the call graph for this function:

◆ testCompletion()

void testCompletion ( )

Test the completion of the option.

Definition at line 81 of file main.cpp.

81  {
82  phoenix_assert(checkOptionCompletion(PROGRAM_OPTION_COMPLETION_MODE, "", "", "", "class source --help -h --version -v \n"));
83  phoenix_assert(checkOptionCompletion(PROGRAM_OPTION_COMPLETION_MODE, "class", "class", "", "--name -n --template -t --config -c --help -h --version -v \n"));
84  phoenix_assert(checkOptionCompletion(PROGRAM_OPTION_COMPLETION_MODE, "class", "class", "-", "--name -n --template -t --config -c --help -h --version -v \n"));
85  phoenix_assert(checkOptionCompletion(PROGRAM_OPTION_COMPLETION_MODE, "class", "class", "--", "--name --template --config --help --version \n"));
86  phoenix_assert(checkOptionCompletion(PROGRAM_OPTION_COMPLETION_MODE, "class", "class", "--n", "--name \n"));
87  phoenix_assert(checkOptionCompletion(PROGRAM_OPTION_COMPLETION_MODE, "class --name=test --", "--name=test", "--", "--template --config --help --version \n"));
88  phoenix_assert(checkOptionCompletion(PROGRAM_OPTION_COMPLETION_MODE, "class --name=\"test\" --", "--name=\"test\"", "--", "--template --config --help --version \n"));
89  phoenix_assert(checkOptionCompletion(PROGRAM_OPTION_COMPLETION_MODE, "class -n \"test\" --", "\"test\"", "--", "--template --config --help --version \n"));
90  phoenix_assert(checkOptionCompletion(PROGRAM_OPTION_COMPLETION_MODE, "source", "source", "", "--name -n --help -h --version -v \n"));
91  phoenix_assert(checkOptionCompletion(PROGRAM_OPTION_COMPLETION_MODE, "class --config ", "--config", "", "./\n"));
92  phoenix_assert(checkOptionCompletion(PROGRAM_OPTION_COMPLETION_MODE, "class --config " DIR_COMPLETION, "--config", DIR_COMPLETION, DIR_COMPLETION "/0-someDir\n" DIR_COMPLETION "/1-someFile.txt\n\n"));
93  phoenix_assert(checkOptionCompletion(PROGRAM_OPTION_COMPLETION_MODE, "class --config " DIR_COMPLETION "/0-someDir", "--config", DIR_COMPLETION "/0-someDir", DIR_COMPLETION "/0-someDir/someFile.txt\n\n"));
94  phoenix_assert(checkOptionCompletion(PROGRAM_OPTION_COMPLETION_MODE, "class --config " DIR_COMPLETION "/0-someDir/someFile.txt", "--config", DIR_COMPLETION "/0-someDir/someFile.txt", "\n"));
95  phoenix_assert(checkOptionCompletion(PROGRAM_OPTION_COMPLETION_MODE, "class --config " DIR_COMPLETION "/0-someDir/some", "--config", DIR_COMPLETION "/0-someDir/some", DIR_COMPLETION "/0-someDir/someFile.txt\n\n"));
96  phoenix_assert(checkOptionCompletion(PROGRAM_OPTION_COMPLETION_MODE_DIR, "class --dir " DIR_COMPLETION "/0-some", "--dir", DIR_COMPLETION "/0-some", DIR_COMPLETION "/0-someDir\n\n"));
97  phoenix_assert(checkOptionCompletion(PROGRAM_OPTION_COMPLETION_MODE_DIR, "class --dir " DIR_COMPLETION, "--dir", DIR_COMPLETION, DIR_COMPLETION "/0-someDir\n\n"));
98 }

References checkOptionCompletion(), and phoenix_assert.

+ Here is the call graph for this function:
checkOptionCompletion
bool checkOptionCompletion(const std::string &program, const std::string &partialOption, const std::string &prevCursorOption, const std::string &cursorOption, const std::string &expectedResult)
Check the option completion of a program.
Definition: main.cpp:21
fillMapString
void fillMapString(std::map< std::string, bool > &mapStr, const std::list< std::string > &listStr)
Create a map with a string.
Definition: main.cpp:20
checkResultSeparator
bool checkResultSeparator(const std::string &resultCmd, const std::string &expectedResult, char separator)
Check the restut.
Definition: main.cpp:32
phoenix_popen
std::string phoenix_popen(const std::string &command)
Execute the given command and returns the output of this command.
Definition: string_system.cpp:341
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
testCompletion
void testCompletion()
Test the completion of the option.
Definition: main.cpp:32
phoenix_assert
#define phoenix_assert(isOk)
Definition: phoenix_assert.h:19
checkResult
bool checkResult(const std::string &resultCmd, const std::string &expectedResult)
Check the restut.
Definition: main.cpp:52