1+ #include " unit_test_core_normalize_path.h"
2+ #include < vector>
3+ #include < iostream>
4+ #include < wsjcpp_core.h>
5+
6+ REGISTRY_UNIT_TEST (UnitTestCoreNormalizePath)
7+
8+ UnitTestCoreNormalizePath::UnitTestCoreNormalizePath()
9+ : UnitTestBase(" UnitTestFallenNormalizePath" ) {
10+ //
11+ }
12+
13+ // ---------------------------------------------------------------------
14+
15+ void UnitTestCoreNormalizePath::init () {
16+ // nothing
17+ }
18+
19+ // ---------------------------------------------------------------------
20+
21+ bool UnitTestCoreNormalizePath::run () {
22+ std::map<std::string, std::string> mapPaths;
23+ mapPaths.insert (std::pair<std::string, std::string>(" " ," " ));
24+ mapPaths.insert (std::pair<std::string, std::string>(" /usr/local/bin/some" ," /usr/local/bin/some" ));
25+ mapPaths.insert (std::pair<std::string, std::string>(" ./bin/some" ," ./bin/some" ));
26+ mapPaths.insert (std::pair<std::string, std::string>(" .//../bin/some" ," ./../bin/some" ));
27+ mapPaths.insert (std::pair<std::string, std::string>(" .//../bin/some/../" ," ./../bin/" ));
28+ mapPaths.insert (std::pair<std::string, std::string>(" .//../bin/some/.." ," ./../bin" ));
29+ mapPaths.insert (std::pair<std::string, std::string>(" /usr/local/./bin/some" ," /usr/local/bin/some" ));
30+ mapPaths.insert (std::pair<std::string, std::string>(" /usr/local/../bin/some" ," /usr/bin/some" ));
31+ mapPaths.insert (std::pair<std::string, std::string>(" /usr/local/..//bin/some" ," /usr/bin/some" ));
32+ mapPaths.insert (std::pair<std::string, std::string>(" /usr/local/..//bin/some/" ," /usr/bin/some/" ));
33+ mapPaths.insert (std::pair<std::string, std::string>(" /usr/local/..//bin/./some/" ," /usr/bin/some/" ));
34+ mapPaths.insert (std::pair<std::string, std::string>(" /usr/local/../../bin/./some/" ," /bin/some/" ));
35+ mapPaths.insert (std::pair<std::string, std::string>(" /usr/local/../../../bin/./some/" ," ../bin/some/" ));
36+ mapPaths.insert (std::pair<std::string, std::string>(" .//" ," ./" ));
37+ std::map<std::string, std::string>::iterator it;
38+
39+ int nCounter = 0 ;
40+ for ( it = mapPaths.begin (); it != mapPaths.end (); it++ ) {
41+ std::string sSource = it->first ;
42+ std::string sExpected = it->second ;
43+ std::string sGot = WSJCppCore::doNormalizePath (sSource );
44+ if (sGot != sExpected ) {
45+ nCounter++;
46+ WSJCppLog::err (TAG, " Wrong normalize path for: '" + sSource + " '.\n\t Got: '" + sGot + " ', but expected: '" + sExpected + " '" );
47+ }
48+
49+ }
50+ return nCounter == 0 ;
51+ }
0 commit comments