PhoenixInkscape  2.0.0
Generate multiple png files with svg inkscape files
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 "phoenix_assert.h"
10 #include "phoenix_check.h"
11 
12 #include "PPath.h"
13 
15 
20 bool checkString(const std::string & testName, const std::string & strValue, const std::string & strReference){
21  return phoenix_check(testName, strValue, strReference);
22 }
23 
26  phoenix_assert(!PPath("").isExist());
27  phoenix_assert(!PPath("Unexisting/path").isExist());
28  phoenix_assert(!PPath("Unexisting/path/to/file").isFileExist());
29  phoenix_assert(!PPath("Unexisting/path/to/dir").isDirectoryExist());
30 }
31 
34  phoenix_assert(PPath("/absolute/Path/").isAbsolutePath());
35  phoenix_assert(!PPath("no/absolute/Path/").isAbsolutePath());
36 }
37 
40  phoenix_assert(phoenix_check("Test getFileName", PPath("").getFileName(), ""));
41  phoenix_assert(phoenix_check("Test getFileName", PPath("/some/path/with/file.txt").getFileName(), "file.txt"));
42  phoenix_assert(phoenix_check("Test getDirectoryName", PPath("").getDirectoryName(), ""));
43  phoenix_assert(phoenix_check("Test getDirectoryName", PPath("/some/path/to/directory").getDirectoryName(), "directory"));
44  phoenix_assert(phoenix_check("Test getDirectoryName", PPath("/some/path/to/directory/").getDirectoryName(), "directory"));
45 
46  phoenix_assert(checkString("Test getParentDirectory", PPath("").getParentDirectory(), ""));
47  phoenix_assert(checkString("Test getParentDirectory", PPath("/some/path/to/directory").getParentDirectory(), "/some/path/to"));
48  phoenix_assert(checkString("Test getParentDirectory", PPath("../some/path/to/directory").getParentDirectory(), "../some/path/to"));
49  phoenix_assert(checkString("Test getParentDirectory", PPath("/some/path/to/directory/").getParentDirectory(), "/some/path/to"));
50  phoenix_assert(checkString("Test getParentDirectory", PPath("/some/path/to/directory///").getParentDirectory(), "/some/path/to"));
51  phoenix_assert(checkString("Test getParentDirectory", PPath("../some/path/to/directory/").getParentDirectory(), "../some/path/to"));
52 }
53 
56  phoenix_assert(phoenix_check("Test getExtension", PPath("").getExtension(), ""));
57  phoenix_assert(phoenix_check("Test getExtension", PPath("path/without/extention").getExtension(), ""));
58  phoenix_assert(phoenix_check("Test getExtension", PPath("path/with/extention.txt").getExtension(), "txt"));
59  phoenix_assert(phoenix_check("Test getExtension", PPath("path/with/extention.tar.gz").getExtension(), "gz"));
60 
61  phoenix_assert(phoenix_check("Test getLongestExtension", PPath("").getLongestExtension(), ""));
62  phoenix_assert(phoenix_check("Test getLongestExtension", PPath("path/without/extention").getLongestExtension(), ""));
63  phoenix_assert(phoenix_check("Test getLongestExtension", PPath("path/with/extention.txt").getLongestExtension(), "txt"));
64  phoenix_assert(phoenix_check("Test getLongestExtension", PPath("path/with/extention.tar.gz").getLongestExtension(), "tar.gz"));
65 
66  phoenix_assert(phoenix_check("Test eraseExtension", PPath("").eraseExtension(), ""));
67  phoenix_assert(phoenix_check("Test eraseExtension", PPath("path/without/extention").eraseExtension(), "path/without/extention"));
68  phoenix_assert(phoenix_check("Test eraseExtension", PPath("path/with/extention.txt").eraseExtension(), "path/with/extention"));
69  phoenix_assert(phoenix_check("Test eraseExtension", PPath("path/with/extention.tar.gz").eraseExtension(), "path/with/extention.tar"));
70 
71  phoenix_assert(phoenix_check("Test eraseLongestExtension", PPath("").eraseLongestExtension(), ""));
72  phoenix_assert(phoenix_check("Test eraseLongestExtension", PPath("path/without/extention").eraseLongestExtension(), "path/without/extention"));
73  phoenix_assert(phoenix_check("Test eraseLongestExtension", PPath("path/with/extention.txt").eraseLongestExtension(), "path/with/extention"));
74  phoenix_assert(phoenix_check("Test eraseLongestExtension", PPath("path/with/extention.tar.gz").eraseLongestExtension(), "path/with/extention"));
75 }
76 
79  phoenix_assert(!PPath("").createDirectory());
80  phoenix_assert(PPath(".").createDirectory());
81  phoenix_assert(PPath("someDirectory").createDirectory());
82  phoenix_assert(PPath("some/Directory/with/sub/directories").createDirectory());
83  phoenix_assert(PPath("someDirectory").isDirectoryExist());
84  phoenix_assert(PPath("some/Directory/with/sub/directories").isDirectoryExist());
85 }
86 
89  phoenix_assert(phoenix_check("getUnderPath : empty", PPath("").getUnderPath(""), ""));
90  phoenix_assert(phoenix_check("getUnderPath : base", PPath("/some/dir/path").getUnderPath("dir"), "path"));
91  phoenix_assert(phoenix_check("getUnderPath : not found", PPath("/some/dir/path").getUnderPath("nothere"), ""));
92 }
93 
96  phoenix_assert(PPath("testFile.txt").saveFileContent("some file content"));
97  phoenix_assert(!PPath("").saveFileContent("some file content"));
98 
99  phoenix_assert(PPath("testFile.txt").loadFileContent() == "some file content");
100  phoenix_assert(PPath("testFile.txt").getFileSize() == 17lu);
101  phoenix_assert(PPath("testUnexistingFile.txt").getFileSize() == 0lu);
102 
103  phoenix_assert(PPath("").checkFileBegning("") == false);
104  phoenix_assert(!PPath("UnexistingFile").checkFileBegning(""));
105  phoenix_assert(!PPath("testFile.txt").checkFileBegning(""));
106  phoenix_assert(!PPath("testFile.txt").checkFileBegning("# Not the match"));
107  phoenix_assert(PPath("testFile.txt").checkFileBegning("some file"));
108 
109  phoenix_assert(!PPath("").changeMode());
110  phoenix_assert(!PPath("testUnexistingFile.txt").changeMode());
111  phoenix_assert(PPath("testFile.txt").changeMode());
112 
113  phoenix_assert(PPath("testFile.txt").getFileModificationTime() != 0l);
114  phoenix_assert(PPath("").getFileModificationTime() == -1l);
115  phoenix_assert(PPath("SomeInexistingFile").getFileModificationTime() == -1l);
116 }
117 
120  phoenix_assert(phoenix_check("testPPathRemoveDots : empty", PPath("").simplify(), ""));
121  phoenix_assert(phoenix_check("testPPathRemoveDots : relative", PPath("./some/path").simplify(), "./some/path"));
122  phoenix_assert(phoenix_check("testPPathRemoveDots : relative path", PPath("some/relative/path").simplify(), "some/relative/path"));
123  phoenix_assert(phoenix_check("testPPathRemoveDots : absolute path", PPath("/some/absolute/path").simplify(), "/some/absolute/path"));
124  phoenix_assert(phoenix_check("testPPathRemoveDots : dot relative path", PPath("some/./relative/path").simplify(), "some/relative/path"));
125  phoenix_assert(phoenix_check("testPPathRemoveDots : dot absolute path", PPath("/some/./absolute/path").simplify(), "/some/absolute/path"));
126  phoenix_assert(phoenix_check("testPPathRemoveDots : dots relative path", PPath("some/relative/../path").simplify(), "some/path"));
127  phoenix_assert(phoenix_check("testPPathRemoveDots : dots absolute path", PPath("/some/absolute/../path").simplify(), "/some/path"));
128  phoenix_assert(phoenix_check("testPPathRemoveDots : dots 2 relative path", PPath("some/../relative/../path").simplify(), "path"));
129  phoenix_assert(phoenix_check("testPPathRemoveDots : dots 2 absolute path", PPath("/some/../absolute/../path").simplify(), "/path"));
130  phoenix_assert(phoenix_check("testPPathRemoveDots : dots 1.5 relative path", PPath("some/./relative/../path").simplify(), "some/path"));
131  phoenix_assert(phoenix_check("testPPathRemoveDots : dots 1.5 absolute path", PPath("/some/./absolute/../path").simplify(), "/some/path"));
132  phoenix_assert(phoenix_check("testPPathRemoveDots : dots 1.8 relative path", PPath("some//relative/../path").simplify(), "some/path"));
133  phoenix_assert(phoenix_check("testPPathRemoveDots : dots 1.8 absolute path", PPath("/some//absolute/../path").simplify(), "/some/path"));
134 }
135 
138  phoenix_assert(PPath("").makeAbsolute() != "");
139  phoenix_assert(PPath("./dir").makeAbsolute() != "");
140  phoenix_assert(PPath("/usr/lib").makeAbsolute() == "/usr/lib");
141 }
142 
151  std::cout << "testPPathGetProgram : PPath::getProgramLocation() = '" << PPath::getProgramLocation() << "'" << std::endl;
152  std::cout << "testPPathGetProgram : PPath::getProgramDirectory() = '" << PPath::getProgramDirectory() << "'" << std::endl;
153  std::cout << "testPPathGetProgram : PPath::getProgramPrefix() = '" << PPath::getProgramPrefix() << "'" << std::endl;
154  std::cout << "testPPathGetProgram : PPath::getHomeDir() = '" << PPath::getHomeDir() << "'" << std::endl;
155  std::cout << "testPPathGetProgram : PPath::getCurrentDirectory() = '" << PPath::getCurrentDirectory() << "'" << std::endl;
156  std::cout << "testPPathGetProgram : PPath::getCurrentNodeName() = '" << PPath::getCurrentNodeName() << "'" << std::endl;
157 }
158 
161  PPath path1("some/Path"), path2("and/other");
162  phoenix_assert(phoenix_check("testPPathOperator /", PPath(path1 / path2), "some/Path/and/other"));
163  phoenix_assert(phoenix_check("testPPathOperator +", PPath(path1 + path2), "some/Pathand/other"));
164 }
165 
168  phoenix_assert(PPath("./").getAllFileInDir().size() != 0lu);
169  phoenix_assert(PPath("./").getAllElementInDir().size() != 0lu);
170 
171  PPath testDirectory("./TestDirectory");
172  PVecPath vecElement = testDirectory.getAllElementInDir();
173  phoenix_assert(phoenix_check("TestDirectory nb elements in TestDirectory", vecElement.size(), 4lu));
174 
175  PVecPath vecFile = testDirectory.getAllFileInDir();
176  phoenix_assert(phoenix_check("TestDirectory nb files in TestDirectory", vecFile.size(), 2lu));
177 
178  PVecPath vecDir = testDirectory.getAllDirectoryInDir();
179  phoenix_assert(phoenix_check("TestDirectory nb directories in TestDirectory", vecDir.size(), 2lu));
180 }
181 
182 int main(int argc, char** argv){
195  return 0;
196 }
197 
198 
std::vector< PPath > PVecPath
Definition: PPath.h:75
Path of a directory or a file.
Definition: PPath.h:17
std::vector< PPath > getAllDirectoryInDir() const
Get the list of files in a directory.
Definition: PPath.cpp:479
static PPath getCurrentDirectory()
Returns the current directory.
Definition: PPath.cpp:636
static PString getCurrentNodeName()
Get the name of the current node on which the program is running.
Definition: PPath.cpp:650
static PPath getHomeDir()
Gets the $HOME directory.
Definition: PPath.cpp:629
static PPath getProgramPrefix()
Get the program prefix (installation directory without /bin)
Definition: PPath.cpp:622
static PPath getProgramLocation()
Get the program location.
Definition: PPath.cpp:585
std::vector< PPath > getAllFileInDir() const
Get the list of files in a directory.
Definition: PPath.cpp:457
std::vector< PPath > getAllElementInDir() const
Get the list of all elements in a directory.
Definition: PPath.cpp:503
static PPath getProgramDirectory()
Get the program directory.
Definition: PPath.cpp:606
#define phoenix_assert(isOk)
bool phoenix_check(const std::string &testName, const std::string &val, const std::string &reference)
Check two string.
int main(int argc, char **argv)
Definition: main.cpp:290
void testPPathIsAbsolute()
Test isAbsolute path.
Definition: main.cpp:33
void testPPathCreateDirectory()
Test the createDirectory.
Definition: main.cpp:78
void testPPathOperator()
Test PPath operators.
Definition: main.cpp:160
void testPPathGetExtention()
Test the getExtension of PPath.
Definition: main.cpp:55
bool checkString(const std::string &testName, const std::string &strValue, const std::string &strReference)
Check string lower expression.
Definition: main.cpp:20
void testPPathGetUnderPath()
Test the getUnderPath.
Definition: main.cpp:88
void testPPathRemoveDots()
Test the simplify.
Definition: main.cpp:119
void testPPathGetFileDirName()
Test the getFileName and getDirectoryName.
Definition: main.cpp:39
void testPPathMakeAbsolute()
Test the PPath makeAbsolute.
Definition: main.cpp:137
void testPPathFileContent()
Test load and save file content.
Definition: main.cpp:95
void testPPathIsExist()
Test the PString.
Definition: main.cpp:25
void testPPathGetProgram()
Test getProgramDirectory, getProgramLocation and getProgramPrefix.
Definition: main.cpp:144
void testPPathListAllFileInDir()
Test the getAllFileInDir.
Definition: main.cpp:167