PhoenixMock  1.8.7
Tools to split/merge/print mock used in Phoenix
main.cpp
Go to the documentation of this file.
1 
2 /***************************************
3  Auteur : Pierre Aubert
4  Mail : pierre.aubert@lapp.in2p3.fr
5  Licence : CeCILL-C
6 ****************************************/
7 
8 #include <iostream>
9 #include <vector>
10 #include "phoenix_assert.h"
11 #include "string_filename.h"
12 #include "string_system.h"
13 
19  phoenix_assert(getFileModificationTime("Makefile") != 0l);
21  phoenix_assert(getFileModificationTime("SomeInexistingFile") == -1l);
22  phoenix_assert(getHomeDir() != "");
23 
24  std::list<std::string> listFile;
25  phoenix_assert(getListAllFileInDir(listFile, "./"));
26  phoenix_assert(getListFileInDir(listFile, "./", "\\.cmake"));
27  getListFileInCurrentDir(listFile, "\\.cmake");
28  phoenix_assert(listFile.size() != 0lu);
31  phoenix_assert(!isStringMatchRegex("", "egzg"));
32  phoenix_assert(!isStringMatchRegex("thing.txt", "*.*"));
33  phoenix_assert(isStringMatchRegex("file.txt", "\\.txt"));
34  phoenix_assert(createDirIfNotExist("NewDirectory"));
35  phoenix_assert(createDirIfNotExist("NewDirectory"));
36  phoenix_assert(saveFileContent("NewDirectory/newFile.txt", "some content of the new file"));
37  std::vector<std::string> vecFile1;
38  time_t lastTime = getFileInDirPerTime(vecFile1, "NewDirectory/");
39  phoenix_assert(vecFile1.size() == 1lu);
40  std::vector<std::string> vecFile2;
41  time_t lastTime2 = getFileInDirPerTime(vecFile2, "NewDirectory/", lastTime);
42  phoenix_assert(lastTime2 == lastTime);
43  phoenix_assert(vecFile2.size() == 0lu);
44  std::string currentNode(getCurrentNodeName());
45  phoenix_assert(currentNode != "");
46 
47  phoenix_assert(phoenix_getenv("UNEXISTING_VARIABLE") == "");
48  phoenix_assert(phoenix_setenv("SomeExistingVariable", "42"));
49  phoenix_assert(phoenix_getenv("SomeExistingVariable") == "42");
50  phoenix_assert(phoenix_unsetenv("SomeExistingVariable"));
51  phoenix_assert(phoenix_chmod("Makefile"));
52  phoenix_assert(!phoenix_chmod("UnexistingFile"));
53 
54  std::vector<std::string> vecFoundFile = phoenix_find("./*.cmake");
55  phoenix_assert(vecFoundFile.size() != 0lu);
56 }
57 
58 int main(int argc, char** argv){
59  std::list<std::string> listArg;
60  makeListArgument(listArg, argc, argv);
61  phoenix_assert(listArg.size() != 0lu);
63  return 0;
64 }
65 
66 
getListFileInDir
bool getListFileInDir(std::list< std::string > &listFile, const std::string &dirName, const std::string &expr)
Get the list of files in a directory.
Definition: string_system.cpp:150
getFileModificationTime
time_t getFileModificationTime(const std::string &fileName)
Get the last modification time of the given file.
Definition: string_system.cpp:255
getFileInDirPerTime
time_t getFileInDirPerTime(std::vector< std::string > &vecFile, const std::string &dirName, time_t mostRecentTime)
Get the list of most recent files in a directory.
Definition: string_system.cpp:274
testStringSystem
void testStringSystem()
Test the string system function.
Definition: main.cpp:15
phoenix_getenv
std::string phoenix_getenv(const std::string &varName)
Get the value of the given environment variable.
Definition: string_system.cpp:204
phoenix_unsetenv
bool phoenix_unsetenv(const std::string &name)
Unset a environment variable.
Definition: string_system.cpp:227
saveFileContent
bool saveFileContent(const std::string &filename, const std::string &content)
Save a string in a file.
Definition: string_filename.cpp:300
phoenix_setenv
bool phoenix_setenv(const std::string &name, const std::string &value, int overwrite)
Set a environment variable.
Definition: string_system.cpp:219
isStringMatchRegex
bool isStringMatchRegex(const std::string &str, const std::string &expression)
Fonction qui dit si une chaine de caractère correspond à une expression régulière de regex.
Definition: string_system.cpp:94
phoenix_chmod
bool phoenix_chmod(const std::string &fileName, mode_t __mode)
Change the mode of a file or directory.
Definition: string_system.cpp:395
string_filename.h
createDirIfNotExist
bool createDirIfNotExist(const std::string &directoryName)
Creates a directory if it does not exist.
Definition: string_system.cpp:242
makeListArgument
void makeListArgument(std::list< std::string > &listArgument, int argc, char **argv)
Makes the argument list of a program.
Definition: string_system.cpp:193
getProgramDirectory
std::string getProgramDirectory()
Get the program directory.
Definition: string_system.cpp:317
getCurrentNodeName
std::string getCurrentNodeName()
Get the name of the current node on which the program is running.
Definition: string_system.cpp:406
getListAllFileInDir
bool getListAllFileInDir(std::list< std::string > &listFile, const std::string &dirName)
Get the list of files in a directory.
Definition: string_system.cpp:171
getListFileInCurrentDir
void getListFileInCurrentDir(std::list< std::string > &listFile, const std::string &expr)
Function like a ls in shell.
Definition: string_system.cpp:126
phoenix_assert
#define phoenix_assert(isOk)
Definition: phoenix_assert.h:19
getProgramLocation
std::string getProgramLocation()
Get the program location.
Definition: string_system.cpp:296
getHomeDir
std::string getHomeDir()
Gets the $HOME directory.
Definition: string_system.cpp:234
string_system.h
phoenix_find
void phoenix_find(std::vector< std::string > &vecFile, const std::string &path)
Find all files which matches the path expression (example : /path/*.cpp)
Definition: string_system.cpp:414
phoenix_assert.h
main
int main(int argc, char **argv)
Definition: main.cpp:85
getProgramPrefix
std::string getProgramPrefix()
Get the program prefix (installation directory without /bin)
Definition: string_system.cpp:333