From 9296405a2e15c07b5a8b7a002a2fa082232d559b Mon Sep 17 00:00:00 2001 From: jsmall-nvidia Date: Thu, 29 Sep 2022 14:12:15 -0400 Subject: Split out MemoryFileSystem (#2422) * #include an absolute path didn't work - because paths were taken to always be relative. * Remove ref count for Entry in RiffFileSystem. Free up backing Entry types (to work around Dictionary not doing this). * Some small improvements to RiffFileSystem. * Add testing for file systems. * Split out MemoryFileSystem. * Add some documentation around different FileSystems. * Small tiry up - removing unused headers, fixing some comments. Use StringBlob::moveCreate where appropriate. * Small improvement to MemoryFileSystem. Improve documentation comments a little. --- tools/slang-unit-test/unit-test-file-system.cpp | 31 +++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) (limited to 'tools') diff --git a/tools/slang-unit-test/unit-test-file-system.cpp b/tools/slang-unit-test/unit-test-file-system.cpp index f1fd2c6bc..e3e2bb3cf 100644 --- a/tools/slang-unit-test/unit-test-file-system.cpp +++ b/tools/slang-unit-test/unit-test-file-system.cpp @@ -1,9 +1,12 @@ // unit-test-file-system.cpp #include "../../source/core/slang-file-system.h" + #include "../../source/core/slang-riff-file-system.h" #include "../../source/core/slang-zip-file-system.h" +#include "../../source/core/slang-memory-file-system.h" + #include "../../source/core/slang-deflate-compression-system.h" #include "../../source/core/slang-lz4-compression-system.h" @@ -19,6 +22,7 @@ enum class FileSystemType RiffUncompressed, RiffDeflate, RiffLZ4, + Memory, Relative, CountOf, }; @@ -103,6 +107,21 @@ static SlangResult _enumeratePath(ISlangMutableFileSystem* fileSystem, const cha return SLANG_OK; } +static SlangResult _checkSimplifiedPath(ISlangMutableFileSystem* fileSystem, const char* path, const char* normalPath) +{ + ComPtr simplifiedPathBlob; + SLANG_RETURN_ON_FAIL(fileSystem->getSimplifiedPath(path, simplifiedPathBlob.writeRef())); + + auto simplifiedPath = StringUtil::getString(simplifiedPathBlob); + + if (simplifiedPath != normalPath) + { + return SLANG_FAIL; + } + + return SLANG_OK; +} + static SlangResult _test(FileSystemType type) { ComPtr fileSystem; @@ -129,9 +148,14 @@ static SlangResult _test(FileSystemType type) fileSystem = new RiffFileSystem(LZ4CompressionSystem::getSingleton()); break; } + case FileSystemType::Memory: + { + fileSystem = new MemoryFileSystem; + break; + } case FileSystemType::Relative: { - ComPtr memoryFileSystem(new RiffFileSystem(nullptr)); + ComPtr memoryFileSystem(new MemoryFileSystem); memoryFileSystem->createDirectory("base"); fileSystem = new RelativeFileSystem(memoryFileSystem, "base"); @@ -139,7 +163,6 @@ static SlangResult _test(FileSystemType type) } } - SLANG_RETURN_ON_FAIL(_createAndCheckFile(fileSystem, "a", "someText")); SLANG_RETURN_ON_FAIL(_createAndCheckFile(fileSystem, "b", "A longer bit of text....")); @@ -158,6 +181,10 @@ static SlangResult _test(FileSystemType type) const Entry entries[] = { {SLANG_PATH_TYPE_FILE, "a" }, {SLANG_PATH_TYPE_FILE, "b" }, {SLANG_PATH_TYPE_DIRECTORY, "d" } }; SLANG_RETURN_ON_FAIL(_enumeratePath(fileSystem, ".", makeConstArrayView(entries))); } + + { + SLANG_RETURN_ON_FAIL(_checkSimplifiedPath(fileSystem, "d/../a", "a")); + } SLANG_RETURN_ON_FAIL(fileSystem->remove("d/a")); { -- cgit v1.2.3