Add PathIterator class for file system

This commit is contained in:
2017-04-22 01:27:26 -05:00
parent 7bce077ea8
commit 5936a751d3
10 changed files with 200 additions and 5 deletions
+9
View File
@@ -15,10 +15,19 @@ add_executable(
filestoreio.cpp
)
add_executable(
FSTests
tests.cpp
)
target_link_libraries(FileStoreFormat OxFS OxStd)
target_link_libraries(FileSystemFormat OxFS OxStd)
target_link_libraries(FileStoreIO OxFS OxStd)
target_link_libraries(FSTests OxFS OxStd)
add_test("FileStoreFormat" FileStoreFormat)
add_test("FileSystemFormat" FileSystemFormat)
add_test("FileStoreIO" FileStoreIO)
add_test("Test\\ PathIterator1" FSTests PathIterator1)
add_test("Test\\ PathIterator2" FSTests PathIterator2)
add_test("Test\\ PathIterator3" FSTests PathIterator3)
+76
View File
@@ -0,0 +1,76 @@
/*
* Copyright 2015 - 2017 gtalent2@gmail.com
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#include <map>
#include <string>
#include <ox/fs/filesystem.hpp>
#include <ox/fs/pathiterator.hpp>
#include <ox/std/std.hpp>
using namespace std;
using namespace ox::fs;
using namespace ox::std;
map<string, int(*)(string)> tests = {
{
{
"PathIterator1",
[](string) {
int retval = 0;
string path = "/usr/share/charset.gbag";
PathIterator it(path.c_str(), path.size());
const auto buffSize = path.size() + 1;
char buff[buffSize];
retval |= !(it.next(buff, buffSize) == 0 && ox_strcmp(buff, "usr") == 0);
retval |= !(it.next(buff, buffSize) == 0 && ox_strcmp(buff, "share") == 0);
retval |= !(it.next(buff, buffSize) == 0 && ox_strcmp(buff, "charset.gbag") == 0);
return retval;
}
},
{
"PathIterator2",
[](string) {
int retval = 0;
string path = "/usr/share/";
PathIterator it(path.c_str(), path.size());
const auto buffSize = path.size() + 1;
char buff[buffSize];
retval |= !(it.next(buff, buffSize) == 0 && ox_strcmp(buff, "usr") == 0);
retval |= !(it.next(buff, buffSize) == 0 && ox_strcmp(buff, "share") == 0);
return retval;
}
},
{
"PathIterator3",
[](string) {
int retval = 0;
string path = "/";
PathIterator it(path.c_str(), path.size());
const auto buffSize = path.size() + 1;
char buff[buffSize];
retval |= !(it.next(buff, buffSize) == 0 && ox_strcmp(buff, "\0") == 0);
return retval;
}
},
},
};
int main(int argc, const char **args) {
int retval = -1;
if (argc > 1) {
auto testName = args[1];
string testArg = "";
if (args[2]) {
testArg = args[2];
}
if (tests.find(testName) != tests.end()) {
retval = tests[testName](testArg);
}
}
return retval;
}