PhoenixInkscape  2.0.0
Generate multiple png files with svg inkscape files
main.cpp File Reference
#include <map>
#include <iostream>
#include "phoenix_assert.h"
#include "phoenix_check.h"
#include "PString.h"
#include "phoenix_system.h"
+ Include dependency graph for main.cpp:

Go to the source code of this file.

Functions

bool checkOptionCompletion (const PString &program, const PString &partialOption, const PString &prevCursorOption, const PString &cursorOption, const PString &expectedResult)
 Check the option completion of a program. More...
 
bool checkResult (const PString &resultCmd, const PString &expectedResult)
 Check the restut. More...
 
bool checkResultSeparator (const PString &resultCmd, const PString &expectedResult, char separator)
 Check the restut. More...
 
void fillMapString (std::map< PString, bool > &mapStr, const PVecString &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 PString program,
const PString partialOption,
const PString prevCursorOption,
const PString cursorOption,
const PString 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 68 of file main.cpp.

70 {
71  PString command(program + " __bashcompletionmode=\""+cursorOption+"\" __bashcompletionmodeprev=\""+prevCursorOption+"\" prgName " + partialOption);
72  PString resultCmd(phoenix_popen(command));
73 // std::cout << "checkOptionCompletion : command '"<<command<<"':\n\tresult = '"<<resultCmd<<"', expectedResult = '"<<expectedResult<<"'" << std::endl;
74 
75  bool b(checkResult(resultCmd, expectedResult));
76  return b;
77 }
Extends the std::string.
Definition: PString.h:16
PString phoenix_popen(const PString &command)
Execute the given command and returns the output of this command.
bool checkResult(const PString &resultCmd, const PString &expectedResult)
Check the restut.
Definition: main.cpp:51

References checkResult(), and phoenix_popen().

+ Here is the call graph for this function:

◆ checkResult()

bool checkResult ( const PString resultCmd,
const PString expectedResult 
)

Check the restut.

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

Definition at line 51 of file main.cpp.

51  {
52  if(!checkResultSeparator(resultCmd, expectedResult, ' ')){
53  if(!checkResultSeparator(resultCmd, expectedResult, '\n')){
54  return false;
55  }
56  }
57  return true;
58 }
bool checkResultSeparator(const PString &resultCmd, const PString &expectedResult, char separator)
Check the restut.
Definition: main.cpp:31

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 PString resultCmd,
const PString 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 31 of file main.cpp.

31  {
32  PVecString listRes = resultCmd.split(separator);
33  PVecString listExpectedRes = expectedResult.split(separator);
34 
35  std::map<PString, bool> mapExpectedRes;
36  fillMapString(mapExpectedRes, listExpectedRes);
37 
38  bool b(true);
39  for(PVecString::const_iterator it(listRes.begin()); it != listRes.end(); ++it){
40  b &= mapExpectedRes.find(*it) != mapExpectedRes.end();
41  }
42 
43  return b;
44 }
std::vector< PString > PVecString
Definition: PString.h:96
std::vector< PString > split(char separator) const
Cut a PString on the given separator char.
Definition: PString.cpp:420
void fillMapString(std::map< PString, bool > &mapStr, const PVecString &listStr)
Create a map with a string.
Definition: main.cpp:19

References fillMapString(), and PString::split().

Referenced by checkResult().

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

◆ fillMapString()

void fillMapString ( std::map< PString, bool > &  mapStr,
const PVecString 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 19 of file main.cpp.

19  {
20  for(PVecString::const_iterator it(listStr.begin()); it != listStr.end(); ++it){
21  mapStr[*it] = true;
22  }
23 }

Referenced by checkResultSeparator().

+ Here is the caller graph for this function:

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 99 of file main.cpp.

99  {
100  testCompletion();
101  return 0;
102 }
void testCompletion()
Test the completion of the option.
Definition: main.cpp:32

References testCompletion().

+ Here is the call graph for this function:

◆ testCompletion()

void testCompletion ( )

Test the completion of the option.

Definition at line 80 of file main.cpp.

80  {
81  phoenix_assert(checkOptionCompletion(PROGRAM_OPTION_COMPLETION_MODE, "", "", "", "class source --help -h --version -v \n"));
82  phoenix_assert(checkOptionCompletion(PROGRAM_OPTION_COMPLETION_MODE, "class", "class", "", "--name -n --template -t --config -c --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 --template --config --help --version \n"));
85  phoenix_assert(checkOptionCompletion(PROGRAM_OPTION_COMPLETION_MODE, "class", "class", "--n", "--name \n"));
86  phoenix_assert(checkOptionCompletion(PROGRAM_OPTION_COMPLETION_MODE, "class --name=test --", "--name=test", "--", "--template --config --help --version \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 -n \"test\" --", "\"test\"", "--", "--template --config --help --version \n"));
89  phoenix_assert(checkOptionCompletion(PROGRAM_OPTION_COMPLETION_MODE, "source", "source", "", "--name -n --help -h --version -v \n"));
90  phoenix_assert(checkOptionCompletion(PROGRAM_OPTION_COMPLETION_MODE, "class --config ", "--config", "", "./\n"));
91  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"));
92  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"));
93  phoenix_assert(checkOptionCompletion(PROGRAM_OPTION_COMPLETION_MODE, "class --config " DIR_COMPLETION "/0-someDir/someFile.txt", "--config", DIR_COMPLETION "/0-someDir/someFile.txt", "\n"));
94  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"));
95  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"));
96  phoenix_assert(checkOptionCompletion(PROGRAM_OPTION_COMPLETION_MODE_DIR, "class --dir " DIR_COMPLETION, "--dir", DIR_COMPLETION, DIR_COMPLETION "/0-someDir\n\n"));
97 }
#define phoenix_assert(isOk)
bool checkOptionCompletion(const PString &program, const PString &partialOption, const PString &prevCursorOption, const PString &cursorOption, const PString &expectedResult)
Check the option completion of a program.
Definition: main.cpp:21

References checkOptionCompletion(), and phoenix_assert.

+ Here is the call graph for this function: