PhoenixMock  1.1.0
Tools to split/merge/print mock
Loading...
Searching...
No Matches
main_restore.cpp File Reference
#include "OptionParser.h"
#include "phoenix_mock.h"
+ Include dependency graph for main_restore.cpp:

Go to the source code of this file.

Functions

OptionParser createOptionParser ()
 Create the OptionParser of this program.
 
int main (int argc, char **argv)
 
bool restoreAllMock (const std::vector< PPath > &vecInputFile)
 Restore all mock files.
 
bool restoreMockFile (const PPath &inputFile)
 Restore a mock file.
 

Function Documentation

◆ createOptionParser()

OptionParser createOptionParser ( )

Create the OptionParser of this program.

Returns
OptionParser of this program

Definition at line 14 of file main_restore.cpp.

14 {
15 OptionParser parser(true, __PROGRAM_VERSION__);
16 parser.setExampleLongOption("phoenix_mock_restore --input=file.pmock");
17 parser.setExampleShortOption("phoenix_mock_restore -i file2.mock file2.pmock");
18
19 parser.addOption("input", "i", OptionType::FILENAME, true, "List of input mock to get the info");
20 return parser;
21}

Referenced by main().

+ Here is the caller graph for this function:

◆ main()

int main ( int argc,
char ** argv )

Definition at line 60 of file main_restore.cpp.

60 {
61 OptionParser parser = createOptionParser();
62 parser.parseArgument(argc, argv);
63 const OptionMode & defaultMode = parser.getDefaultMode();
64 std::vector<PPath> vecInputFile;
65 defaultMode.getValue(vecInputFile, "input");
66 return restoreAllMock(vecInputFile) - 1;
67}
bool restoreAllMock(const std::vector< PPath > &vecInputFile)
Restore all mock files.
OptionParser createOptionParser()
Create the OptionParser of this program.

References createOptionParser(), and restoreAllMock().

+ Here is the call graph for this function:

◆ restoreAllMock()

bool restoreAllMock ( const std::vector< PPath > & vecInputFile)

Restore all mock files.

Parameters
vecInputFile: vector of input files to restore
Returns
true on success, false otherwise

Definition at line 52 of file main_restore.cpp.

52 {
53 bool b(true);
54 for(std::vector<PPath>::const_iterator itFile(vecInputFile.begin()); itFile != vecInputFile.end(); ++itFile){
55 b &= restoreMockFile(*itFile);
56 }
57 return b;
58}
bool restoreMockFile(const PPath &inputFile)
Restore a mock file.

References restoreMockFile().

Referenced by main().

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

◆ restoreMockFile()

bool restoreMockFile ( const PPath & inputFile)

Restore a mock file.

Parameters
inputFile: input file to be restored
Returns
true on success, false otherwise

Definition at line 27 of file main_restore.cpp.

27 {
28 FILE* fp = fopen(inputFile.c_str(), "r+");
29 if(fp == NULL){
30 std::cerr << "restoreMockFile : cannot open file '"<<inputFile<<"'" << std::endl;
31 return false;
32 }
33 size_t nbMessage(0lu);
34 bool isReadFileOk = fseek(fp, sizeof(size_t), SEEK_SET) == 0; //We can skip the possible broken number of messages in the mock
35 while(isReadFileOk){
36 size_t nbByteInMessage(0lu);
37 isReadFileOk &= data_load(fp, nbByteInMessage);
38 isReadFileOk &= fseek(fp, sizeof(size_t) + nbByteInMessage, SEEK_CUR) == 0; //let's jump until the next message
39 nbMessage += isReadFileOk;
40 }
41 fseek(fp, 0lu, SEEK_SET);
42 bool b = data_save(fp, nbMessage);
43 fseek(fp, 0l, SEEK_END);
44 fclose(fp);
45 return b;
46}

Referenced by restoreAllMock().

+ Here is the caller graph for this function: