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 "phoenix_check.h"
12 
13 #include "string_filename.h"
14 
16 
21 bool checkString(const std::string & testName, const std::string & strValue, const std::string & strReference){
22  return phoenix_check(testName, strValue, strReference);
23 }
24 
27  std::string fileName("someDir/someOtherDir/fileName.extention");
28  phoenix_assert(checkString("Test getFileName", getFileName(fileName), "fileName.extention"));
29  phoenix_assert(checkString("Test getDirectory", getDirectory(fileName), "someDir/someOtherDir"));
30  phoenix_assert(checkString("Test eraseExtension", eraseExtension(fileName), "someDir/someOtherDir/fileName"));
31  phoenix_assert(checkString("Test getExtention", getExtention(fileName), "extention"));
32  phoenix_assert(checkString("Test getExtention", getExtention("fileWithoutExtention"), ""));
33  phoenix_assert(checkString("Test eraseExtension", eraseExtension(""), ""));
34  phoenix_assert(checkString("Test eraseExtension", eraseExtension("file.tar.gz"), "file.tar"));
35  phoenix_assert(checkString("Test getLongestExtention", getLongestExtention(fileName), "extention"));
36  phoenix_assert(checkString("Test getLongestExtention", getLongestExtention("fileWithoutExtention"), ""));
37  phoenix_assert(checkString("Test getLongestExtention", getLongestExtention("Shadok.tar.gz"), "tar.gz"));
38  phoenix_assert(checkString("Test getLongestExtention", getLongestExtention("../Shadok.tar.gz"), "tar.gz"));
39  phoenix_assert(checkString("Test eraseLongestExtension", eraseLongestExtension(""), ""));
40  phoenix_assert(checkString("Test eraseLongestExtension", eraseLongestExtension("file.tar.gz"), "file"));
41  phoenix_assert(checkString("Test eraseLongestExtension", eraseLongestExtension("../file.tar.gz"), "../file"));
42  phoenix_assert(isFileOrDirExist("Makefile"));
43  phoenix_assert(isFileOrDirExist("CMakeFiles"));
44 
47 
48  phoenix_assert(isFileExist("./Makefile"));
49  phoenix_assert(!isFileExist("CMakeFiles"));
50  phoenix_assert(!isFileExist("SomeInexistingFile"));
51  phoenix_assert(getFileContent("Makefile") != "");
52  phoenix_assert(phoenix_check("Test getFileContent missing file", getFileContent("SomeInexistingFile"), ""));
53  phoenix_assert(phoenix_check("Test getFileContent NULL", getFileContent(NULL), ""));
54  phoenix_assert(!saveFileContent(NULL, ""));
55  phoenix_assert(!saveFileContent(NULL, "some string"));
56 
57  phoenix_assert(saveFileContent("testFile.txt", "some file content"));
58  phoenix_assert(!saveFileContent("", "some file content"));
60  phoenix_assert(isDirectoryExist("CMakeFiles"));
61  phoenix_assert(phoenix_check("Test isDirectoryExist not dir", isDirectoryExist("SomeInexistingDir"), false));
62 
64  std::vector<std::string> vecDir;
65  phoenix_assert(phoenix_check("Test getExistingFileName empty", getExistingFileName("", vecDir), ""));
66  phoenix_assert(phoenix_check("Test getExistingFileName", getExistingFileName("Makefile", vecDir), ""));
67  vecDir.push_back("SomeInexistingDir");
68  phoenix_assert(getExistingFileName("", vecDir) == "");
69  phoenix_assert(getExistingFileName("Makefile", vecDir) == "");
70  vecDir.push_back("./");
71  phoenix_assert(getExistingFileName("Makefile", vecDir) != "");
73  phoenix_assert(createDirectoriesIfNotExist("someDir/someOtherDir"));
75 
77  phoenix_assert(makeAbsolutePath("./dir") != "");
78  phoenix_assert(makeAbsolutePath("/usr/lib") == "/usr/lib");
79 
80  std::vector<std::string> vecPath;
81  vecPath.push_back("");
82  vecPath.push_back("./dir");
83  vecPath.push_back("/usr/lib");
84  std::vector<std::string> vecAbsolutePath = makeAbsolutePath(vecPath);
85  phoenix_assert(vecAbsolutePath[0lu] != "");
86  phoenix_assert(vecAbsolutePath[1lu] != "");
87  phoenix_assert(vecAbsolutePath[2lu] == "/usr/lib");
89  phoenix_assert(isAbsolutePath("/someting/absolute"));
90  phoenix_assert(!isAbsolutePath("../someting/not/absolute"));
91  phoenix_assert(phoenix_check("getUnderPath : empty", getUnderPath("", ""), ""));
92  phoenix_assert(phoenix_check("getUnderPath : base", getUnderPath("/some/dir/path", "dir"), "path"));
93  phoenix_assert(phoenix_check("getUnderPath : not found", getUnderPath("/some/dir/path", "nothere"), ""));
94 
95  std::vector<std::string> vecUnderPath;
96  vecUnderPath.push_back("/usr/lib/shadok.so");
97  vecUnderPath.push_back("/usr/bin/shadok");
98  std::vector<std::string> vecOutUnderPath = getUnderPath(vecUnderPath, "usr");
99  phoenix_assert(phoenix_check("getUnderPath("+vecUnderPath[0]+")", vecOutUnderPath[0], "lib/shadok.so"));
100  phoenix_assert(phoenix_check("getUnderPath("+vecUnderPath[1]+")", vecOutUnderPath[1], "bin/shadok"));
101  phoenix_assert(phoenix_check("removePathDots : empty", removePathDots(""), ""));
102  phoenix_assert(phoenix_check("removePathDots : relative", removePathDots("./some/path"), "./some/path"));
103  phoenix_assert(phoenix_check("removePathDots : relative path", removePathDots("some/relative/path"), "some/relative/path"));
104  phoenix_assert(phoenix_check("removePathDots : absolute path", removePathDots("/some/absolute/path"), "/some/absolute/path"));
105  phoenix_assert(phoenix_check("removePathDots : dot relative path", removePathDots("some/./relative/path"), "some/relative/path"));
106  phoenix_assert(phoenix_check("removePathDots : dot absolute path", removePathDots("/some/./absolute/path"), "/some/absolute/path"));
107  phoenix_assert(phoenix_check("removePathDots : dots relative path", removePathDots("some/relative/../path"), "some/path"));
108  phoenix_assert(phoenix_check("removePathDots : dots absolute path", removePathDots("/some/absolute/../path"), "/some/path"));
109  phoenix_assert(phoenix_check("removePathDots : dots 2 relative path", removePathDots("some/../relative/../path"), "path"));
110  phoenix_assert(phoenix_check("removePathDots : dots 2 absolute path", removePathDots("/some/../absolute/../path"), "/path"));
111  phoenix_assert(phoenix_check("removePathDots : dots 1.5 relative path", removePathDots("some/./relative/../path"), "some/path"));
112  phoenix_assert(phoenix_check("removePathDots : dots 1.5 absolute path", removePathDots("/some/./absolute/../path"), "/some/path"));
113  phoenix_assert(phoenix_check("removePathDots : dots 1.8 relative path", removePathDots("some//relative/../path"), "some/path"));
114  phoenix_assert(phoenix_check("removePathDots : dots 1.8 absolute path", removePathDots("/some//absolute/../path"), "/some/path"));
115  phoenix_assert(phoenix_check("getDirName : /some/dir", getDirName("/some/dir"), "dir"));
116  phoenix_assert(phoenix_check("getDirName : /some/dir/again/", getDirName("/some/dir/again/"), "again"));
117 }
118 
119 int main(int argc, char** argv){
121  return 0;
122 }
123 
124 
getExistingFileName
std::string getExistingFileName(const std::string &fileName, const std::vector< std::string > &vecDirectory)
Get the fileName with the directory to get a readable file.
Definition: string_filename.cpp:42
createDirectoriesIfNotExist
bool createDirectoriesIfNotExist(const std::string &dirName)
Create the directory if not exists.
Definition: string_filename.cpp:405
saveFileContent
bool saveFileContent(const std::string &filename, const std::string &content)
Save a string in a file.
Definition: string_filename.cpp:300
isDirectoryExist
bool isDirectoryExist(const std::string &dirName)
Says if the given direcotry exists.
Definition: string_filename.cpp:57
getFileContent
std::string getFileContent(const std::string &filename)
Get the file content in a string.
Definition: string_filename.cpp:268
string_filename.h
getLongestExtention
std::string getLongestExtention(const std::string &fileName)
Get the longest file extention.
Definition: string_filename.cpp:343
makeAbsolutePath
std::string makeAbsolutePath(const std::string &path)
Make an absolute path of the given path.
Definition: string_filename.cpp:93
phoenix_check
bool phoenix_check(const std::string &testName, const std::string &val, const std::string &reference)
Check two string.
Definition: phoenix_check.cpp:17
eraseLongestExtension
std::string eraseLongestExtension(const std::string &fileName)
Erase longest extention of the given file.
Definition: string_filename.cpp:392
eraseExtension
std::string eraseExtension(const std::string &fileName)
Erase extention of the given file.
Definition: string_filename.cpp:368
removePathDots
std::string removePathDots(const std::string path)
Remove dots from the path.
Definition: string_filename.cpp:117
testStringFilename
void testStringFilename()
Test the string filename function.
Definition: main.cpp:26
getFileName
std::string getFileName(const std::string &fileName)
fonction qui renvoie le nom du fichier du nom complet de fichier passé en paramètre
Definition: string_filename.cpp:231
phoenix_assert
#define phoenix_assert(isOk)
Definition: phoenix_assert.h:19
getExtention
std::string getExtention(const std::string &fileName)
Get file extention.
Definition: string_filename.cpp:326
isAbsolutePath
bool isAbsolutePath(const std::string &path)
Tel if a path is absolute or not.
Definition: string_filename.cpp:84
isFileExist
bool isFileExist(const std::string &fileName)
Say if a file exsits or not.
Definition: string_filename.cpp:27
getDirectory
std::string getDirectory(const std::string &fileName)
fonction qui renvoie le dossier parent du fichier
Definition: string_filename.cpp:156
getCurrentDirectory
std::string getCurrentDirectory()
Returns the current directory.
Definition: string_filename.cpp:69
phoenix_assert.h
checkString
bool checkString(const std::string &testName, const std::string &strValue, const std::string &strReference)
Check string lower expression.
Definition: main.cpp:21
getUnderPath
std::string getUnderPath(const std::string &fileName, const std::string &pathPart)
Get path which is under the given pathPart ('some/dir/path' with 'dir' will return 'path')
Definition: string_filename.cpp:176
main
int main(int argc, char **argv)
Definition: main.cpp:85
getDirName
std::string getDirName(const std::string &path)
Get the name of the deeper directory.
Definition: string_filename.cpp:246
isFileOrDirExist
bool isFileOrDirExist(const std::string &fileName)
Say if the given path name exsits or not.
Definition: string_filename.cpp:18
phoenix_check.h