PhoenixMock  1.8.7
Tools to split/merge/print mock used in Phoenix
main_split.cpp File Reference
#include "string_utils.h"
#include "convertToString.h"
#include "OptionParser.h"
#include "phoenix_mock.h"
+ Include dependency graph for main_split.cpp:

Go to the source code of this file.

Functions

OptionParser createOptionParser ()
 Create the OptionParser of this program. More...
 
int main (int argc, char **argv)
 
std::string phoenix_mockMakeOutputFile (const std::string &baseFileName, size_t indexFile, const std::string &extentionFile)
 Make the output file name. More...
 
bool splitMock (const std::vector< std::string > &vecInputFile, const std::string &outputFile, size_t offsetPart, size_t sizePart, size_t nbPart)
 Merge mock files. More...
 

Function Documentation

◆ createOptionParser()

OptionParser createOptionParser ( )

Create the OptionParser of this program.

Returns
OptionParser of this program

Definition at line 16 of file main_split.cpp.

16  {
17  OptionParser parser(true, __PROGRAM_VERSION__);
18  parser.setExampleLongOption("phoenix_mock_split --input=file.pmock --output=split.pmock");
19  parser.setExampleShortOption("phoenix_mock_split -i file2.mock file2.pmock -o split.pmock");
20 
21  parser.addOption("input", "i", OptionType::FILENAME, true, "List of input mock to be split");
22 
23  std::string defaultOutputFile("./split.pmock");
24  parser.addOption("output", "o", defaultOutputFile, "Name of the output split mock file");
25 
26  size_t defaultOffset(0lu), defaultSizePart(1lu), defaultNbPart(0lu);
27  parser.addOption("offset", "f", defaultOffset, "Offset of the first message to be extracted in a split mock");
28  parser.addOption("sizepart", "s", defaultSizePart, "Size of each split part (number of messages in each part to be split)");
29  parser.addOption("nbpart", "n", defaultNbPart, "Number of output mock to be created (0 means automatic by respect to --offset and --sizepart)");
30  return parser;
31 }

References OptionType::FILENAME, and createReleaseCurl::parser.

Referenced by main().

+ Here is the caller graph for this function:

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 119 of file main_split.cpp.

119  {
121  parser.parseArgument(argc, argv);
122 
123  const OptionMode & defaultMode = parser.getDefaultMode();
124  std::vector<std::string> vecInputFile;
125  std::string outputFile("");
126  defaultMode.getValue(vecInputFile, "input");
127  defaultMode.getValue(outputFile, "output");
128 
129  size_t offsetPart(0lu), sizePart(1lu), nbPart(0lu);
130  defaultMode.getValue(offsetPart, "offset");
131  defaultMode.getValue(sizePart, "sizepart");
132  defaultMode.getValue(nbPart, "nbpart");
133 
134  return splitMock(vecInputFile, outputFile, offsetPart, sizePart, nbPart) - 1;
135 }

References createOptionParser(), OptionMode::getValue(), createReleaseCurl::parser, and splitMock().

+ Here is the call graph for this function:

◆ phoenix_mockMakeOutputFile()

std::string phoenix_mockMakeOutputFile ( const std::string &  baseFileName,
size_t  indexFile,
const std::string &  extentionFile 
)

Make the output file name.

Parameters
baseFileName: base name of the file
indexFile: index of hte file
extentionFile: extention of the file
Returns
corresponding output file

Definition at line 39 of file main_split.cpp.

39  {
40  std::string extention(extentionFile);
41  if(extention == ""){
42  extention = "pmock";
43  }
44  return baseFileName + "_" + convertToString(indexFile) + "." + extention;
45 }

References convertToString().

Referenced by splitMock().

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

◆ splitMock()

bool splitMock ( const std::vector< std::string > &  vecInputFile,
const std::string &  outputFile,
size_t  offsetPart,
size_t  sizePart,
size_t  nbPart 
)

Merge mock files.

Parameters
vecInputFile: vector of input files to be merged
outputFile: output file name to be saved
offsetPart: offset of the first message to be extracted in a split mock
sizePart: size of each split part (number of messages in each part to be split)
nbPart: number of output mock to be created (0 means automatic by respect to –offset and –sizepart)
Returns
true on success, false otherwise

Definition at line 55 of file main_split.cpp.

57 {
58  if(sizePart == 0lu && nbPart == 0lu){
59  std::cerr << "Error sizePart cannot be 0 id nbPart == 0, aborting split" << std::endl;
60  return false;
61  }
62  std::string outputExtension(getExtention(outputFile)), baseOutputFile(eraseExtension(outputFile));
63  bool b(true);
64  for(std::vector<std::string>::const_iterator itFile(vecInputFile.begin()); itFile != vecInputFile.end() && b; ++itFile){
65  std::vector<std::vector<char> > vecTmpFile;
66  if(data_load(*itFile, vecTmpFile)){
67  size_t nbMessageIn(vecTmpFile.size());
68  if(sizePart == 0lu){
69  if(offsetPart <= nbMessageIn){
70  sizePart = (nbMessageIn - offsetPart)/nbPart;
71  if(sizePart == 0lu){
72  std::cerr << "splitMock : cannot split nbMessageIn = " << nbMessageIn << ", into nbPart = "<<nbPart<<" of size sizePart = "<<sizePart<<" and offset offsetPart = " << offsetPart << std::endl;
73  b = false;
74  }else{
75  for(size_t i(0lu); i < nbPart; ++i){
76  std::vector<std::vector<char> > vecMessage;
77  splitVecMessage(vecMessage, vecTmpFile, offsetPart + i*sizePart, sizePart);
78  b &= data_save(phoenix_mockMakeOutputFile(baseOutputFile, i, outputExtension), vecMessage);
79  }
80  }
81  }else{
82  std::vector<std::vector<char> > vecMessage;
83 // splitVecMessage(vecMessage, vecTmpFile, offsetPart, sizePart);
84  b &= data_save(phoenix_mockMakeOutputFile(baseOutputFile, 0lu, outputExtension), vecMessage);
85  }
86 
87  }else if(nbPart == 0lu){
88  if((sizePart + offsetPart) <= nbMessageIn){
89  nbPart = (nbMessageIn-offsetPart)/sizePart;
90  for(size_t i(0lu); i < nbPart; ++i){
91  std::vector<std::vector<char> > vecMessage;
92  splitVecMessage(vecMessage, vecTmpFile, offsetPart + i*sizePart, sizePart);
93  b &= data_save(phoenix_mockMakeOutputFile(baseOutputFile, i, outputExtension), vecMessage);
94  }
95  }else{
96  std::vector<std::vector<char> > vecMessage;
97 // splitVecMessage(vecMessage, vecTmpFile, offsetPart, sizePart);
98  b &= data_save(phoenix_mockMakeOutputFile(baseOutputFile, 0lu, outputExtension), vecMessage);
99  }
100  }else{
101  if((sizePart*nbPart + offsetPart) <= nbMessageIn){
102  for(size_t i(0lu); i < nbPart; ++i){
103  std::vector<std::vector<char> > vecMessage;
104  splitVecMessage(vecMessage, vecTmpFile, offsetPart + i*sizePart, sizePart);
105  b &= data_save(phoenix_mockMakeOutputFile(baseOutputFile, i, outputExtension), vecMessage);
106  }
107  }else{
108  std::cerr << "splitMock : cannot split nbMessageIn = " << nbMessageIn << ", into nbPart = "<<nbPart<<" of size sizePart = "<<sizePart<<" and offset offsetPart = " << offsetPart << std::endl;
109  b = false;
110  }
111  }
112  }else{
113  b = false;
114  }
115  }
116  return b;
117 }

References data_load(), data_save(), eraseExtension(), getExtention(), phoenix_mockMakeOutputFile(), and splitVecMessage().

Referenced by main().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:
convertToString
std::string convertToString(const T &val)
Convert a type into a string.
Definition: convertToString_impl.h:17
createOptionParser
OptionParser createOptionParser()
Create the OptionParser of this program.
Definition: main_split.cpp:16
OptionMode::getValue
bool getValue(T &value, const std::string &optionName) const
Get the value of the option.
Definition: OptionMode_impl.h:18
phoenix_mockMakeOutputFile
std::string phoenix_mockMakeOutputFile(const std::string &baseFileName, size_t indexFile, const std::string &extentionFile)
Make the output file name.
Definition: main_split.cpp:39
createReleaseCurl.parser
parser
Definition: createReleaseCurl.py:123
eraseExtension
std::string eraseExtension(const std::string &fileName)
Erase extention of the given file.
Definition: string_filename.cpp:368
OptionParser
Parse the options passed to a program.
Definition: OptionParser.h:15
data_save
bool data_save(FILE *iter, const T &data)
Save data in a message.
Definition: data_file.h:18
data_load
bool data_load(FILE *iter, T &data)
Load data from a message.
Definition: data_file.h:39
getExtention
std::string getExtention(const std::string &fileName)
Get file extention.
Definition: string_filename.cpp:326
splitVecMessage
void splitVecMessage(std::vector< std::vector< char > > &vecOutput, const std::vector< std::vector< char > > vecInput, size_t offsetPart, size_t sizePart)
Split a vector of messages into an other.
Definition: phoenix_mock.cpp:26
splitMock
bool splitMock(const std::vector< std::string > &vecInputFile, const std::string &outputFile, size_t offsetPart, size_t sizePart, size_t nbPart)
Merge mock files.
Definition: main_split.cpp:55
OptionMode
Describe a mode in the program arguments.
Definition: OptionMode.h:13
OptionType::FILENAME
@ FILENAME
Definition: OptionType.h:26