[ox/fs] Make format method static
This commit is contained in:
18
deps/ox/src/ox/fs/test/filestore_format.cpp
vendored
18
deps/ox/src/ox/fs/test/filestore_format.cpp
vendored
@@ -1,18 +0,0 @@
|
||||
/*
|
||||
* Copyright 2015 - 2018 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 <ox/fs/filestore.hpp>
|
||||
|
||||
using namespace ox;
|
||||
|
||||
int main() {
|
||||
const auto size = 65535;
|
||||
uint8_t volume[size];
|
||||
uint32_t err = 0;
|
||||
FileStore32::format(volume, size);
|
||||
return err;
|
||||
}
|
68
deps/ox/src/ox/fs/test/filestoreio.cpp
vendored
68
deps/ox/src/ox/fs/test/filestoreio.cpp
vendored
@@ -1,68 +0,0 @@
|
||||
/*
|
||||
* Copyright 2015 - 2018 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 <stdio.h>
|
||||
#include <ox/std/std.hpp>
|
||||
#include <ox/fs/filestore.hpp>
|
||||
|
||||
using namespace ox;
|
||||
|
||||
template<typename FileStore>
|
||||
int test() {
|
||||
const uint16_t size = ~0;
|
||||
uint8_t volume[size];
|
||||
char out[6];
|
||||
typename FileStore::FsSize_t outSize;
|
||||
FileStore::format(volume, size);
|
||||
FileStore *fs = (FileStore*) volume;
|
||||
|
||||
if (fs->write(1, (void*) "Hello", 6) ||
|
||||
fs->read(1, (char*) out, &outSize) ||
|
||||
ox_strcmp("Hello", out)) {
|
||||
printf("Failure 1\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (fs->write(2, (void*) "World", 6) ||
|
||||
fs->read(2, (char*) out, &outSize) ||
|
||||
ox_strcmp("World", out)) {
|
||||
printf("Failure 2\n");
|
||||
return 2;
|
||||
}
|
||||
|
||||
// make sure first value was not overwritten
|
||||
if (fs->read(1, (char*) out, &outSize) ||
|
||||
ox_strcmp("Hello", out)) {
|
||||
printf("Failure 3\n");
|
||||
return 3;
|
||||
}
|
||||
|
||||
if (fs->remove(1)) {
|
||||
printf("Failure 4\n");
|
||||
return 4;
|
||||
}
|
||||
|
||||
// make sure inode is not found
|
||||
if (fs->read(1, (char*) out, &outSize) == 0) {
|
||||
printf("Failure 5\n");
|
||||
return 5;
|
||||
}
|
||||
|
||||
// make sure 2 is still available
|
||||
if (fs->write(2, (void*) "World", 6) ||
|
||||
fs->read(2, (char*) out, &outSize) ||
|
||||
ox_strcmp("World", out)) {
|
||||
printf("Failure 6\n");
|
||||
return 6;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main() {
|
||||
return test<FileStore16>() || test<FileStore32>() | test<FileStore64>();
|
||||
}
|
23
deps/ox/src/ox/fs/test/filesystem_format.cpp
vendored
23
deps/ox/src/ox/fs/test/filesystem_format.cpp
vendored
@@ -1,23 +0,0 @@
|
||||
/*
|
||||
* Copyright 2015 - 2018 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 <ox/fs/fs.hpp>
|
||||
|
||||
using namespace ox;
|
||||
|
||||
template<typename FileSystem>
|
||||
int test() {
|
||||
const uint16_t size = ~0;
|
||||
uint8_t volume[size];
|
||||
FileSystem::format(volume, size, true);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main() {
|
||||
return test<FileSystem16>() | test<FileSystem32>() | test<FileSystem64>();
|
||||
}
|
20
deps/ox/src/ox/fs/test/tests.cpp
vendored
20
deps/ox/src/ox/fs/test/tests.cpp
vendored
@@ -137,7 +137,7 @@ map<string, int(*)(string)> tests = {
|
||||
[](string) {
|
||||
int err = 0;
|
||||
constexpr auto buffLen = 5000;
|
||||
auto list = new (ox_alloca(buffLen)) ox::ptrarith::NodeBuffer<uint32_t, ox::fs::FileStoreItem<uint32_t>>(buffLen);
|
||||
auto list = new (ox_alloca(buffLen)) ox::ptrarith::NodeBuffer<uint32_t, ox::FileStoreItem<uint32_t>>(buffLen);
|
||||
oxAssert(list->malloc(50).valid(), "NodeBuffer::insert: malloc 1 failed");
|
||||
oxAssert(list->malloc(50).valid(), "NodeBuffer::insert: malloc 2 failed");
|
||||
auto first = list->firstItem();
|
||||
@@ -154,9 +154,9 @@ map<string, int(*)(string)> tests = {
|
||||
constexpr auto str1Len = ox_strlen(str1) + 1;
|
||||
constexpr auto str2 = "Hello, Moon!";
|
||||
constexpr auto str2Len = ox_strlen(str2) + 1;
|
||||
auto list = new (ox_alloca(buffLen)) ox::ptrarith::NodeBuffer<uint32_t, ox::fs::FileStoreItem<uint32_t>>(buffLen);
|
||||
ox::fs::FileStore32 fileStore(list, buffLen);
|
||||
oxAssert(fileStore.format() == 0, "FileStore::format failed.");
|
||||
auto list = new (ox_alloca(buffLen)) ox::ptrarith::NodeBuffer<uint32_t, ox::FileStoreItem<uint32_t>>(buffLen);
|
||||
oxAssert(ox::FileStore32::format(list, buffLen) == 0, "FileStore::format failed.");
|
||||
ox::FileStore32 fileStore(list, buffLen);
|
||||
oxAssert(fileStore.write(4, const_cast<char*>(str1), str1Len, 1) == 0, "FileStore::write 1 failed.");
|
||||
oxAssert(fileStore.write(5, const_cast<char*>(str2), str2Len, 1) == 0, "FileStore::write 2 failed.");
|
||||
|
||||
@@ -171,9 +171,9 @@ map<string, int(*)(string)> tests = {
|
||||
"Directory",
|
||||
[](string) {
|
||||
std::array<uint8_t, 5000> fsBuff;
|
||||
ox::fs::FileStore32 fileStore(fsBuff.data(), fsBuff.size());
|
||||
fileStore.format();
|
||||
auto dir = ox_malloca(1000, ox::fs::Directory32, &fileStore, 100);
|
||||
ox::FileStore32::format(fsBuff.data(), fsBuff.size());
|
||||
ox::FileStore32 fileStore(fsBuff.data(), fsBuff.size());
|
||||
auto dir = ox_malloca(1000, ox::Directory32, fileStore, 100);
|
||||
|
||||
oxTrace("ox::fs::test::Directory") << "Init";
|
||||
oxAssert(dir->init(), "Init failed");
|
||||
@@ -198,11 +198,9 @@ map<string, int(*)(string)> tests = {
|
||||
"FileSystem",
|
||||
[](string) {
|
||||
std::array<uint8_t, 5000> fsBuff;
|
||||
ox::fs::FileStore32 fileStore(fsBuff.data(), fsBuff.size());
|
||||
ox::fs::FileSystem32 fs(&fileStore);
|
||||
|
||||
oxTrace("ox::fs::test::FileSystem") << "format";
|
||||
oxAssert(fs.format(), "FileSystem format failed");
|
||||
oxAssert(ox::FileSystem32::format(fsBuff.data(), fsBuff.size()), "FileSystem format failed");
|
||||
ox::FileSystem32 fs(ox::FileStore32(fsBuff.data(), fsBuff.size()));
|
||||
|
||||
oxTrace("ox::fs::test::FileSystem") << "mkdir";
|
||||
oxAssert(fs.mkdir("/l1d1/l2d1/l3d1", true), "mkdir failed");
|
||||
|
Reference in New Issue
Block a user