1+ #include " unit_test_core_extract_filename.h"
2+ #include < vector>
3+ #include < iostream>
4+ #include < wsjcpp_core.h>
5+
6+ REGISTRY_UNIT_TEST (UnitTestCoreExtractFilename)
7+
8+ UnitTestCoreExtractFilename::UnitTestCoreExtractFilename()
9+ : UnitTestBase(" UnitTestCoreExtractFilename" ) {
10+ //
11+ }
12+
13+ // ---------------------------------------------------------------------
14+
15+ void UnitTestCoreExtractFilename::init () {
16+ // nothing
17+ }
18+
19+ // ---------------------------------------------------------------------
20+
21+ bool UnitTestCoreExtractFilename::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" ," some" ));
25+ mapPaths.insert (std::pair<std::string, std::string>(" ./bin/some" ," some" ));
26+ mapPaths.insert (std::pair<std::string, std::string>(" .//../bin/some" ," some" ));
27+ mapPaths.insert (std::pair<std::string, std::string>(" .//../bin/some/../" ," " ));
28+ mapPaths.insert (std::pair<std::string, std::string>(" .//../bin/some/.." ," .." ));
29+ mapPaths.insert (std::pair<std::string, std::string>(" /usr/local/./bin/some" ," some" ));
30+ mapPaths.insert (std::pair<std::string, std::string>(" /usr/local/../bin/some" ," some" ));
31+ mapPaths.insert (std::pair<std::string, std::string>(" /usr/local/..//bin/some" ," some" ));
32+ mapPaths.insert (std::pair<std::string, std::string>(" /usr/local/..//bin/some/." ," ." ));
33+ mapPaths.insert (std::pair<std::string, std::string>(" /usr/local/..//bin/./some/" ," " ));
34+ mapPaths.insert (std::pair<std::string, std::string>(" /usr/local/../../bin/./some/" ," " ));
35+ mapPaths.insert (std::pair<std::string, std::string>(" /usr/local/../../../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::extractFilename (sSource );
44+ if (sGot != sExpected ) {
45+ nCounter++;
46+ WSJCppLog::err (TAG, " Wrong extract filename for: '" + sSource + " '.\n\t Got: '" + sGot + " ', but expected: '" + sExpected + " '" );
47+ }
48+
49+ }
50+ return nCounter == 0 ;
51+ }
0 commit comments