summaryrefslogtreecommitdiffstats
path: root/tools/slang-unit-test/unit-test-file-system.cpp
diff options
context:
space:
mode:
authorjsmall-nvidia <jsmall@nvidia.com>2022-09-29 14:12:15 -0400
committerGitHub <noreply@github.com>2022-09-29 14:12:15 -0400
commit9296405a2e15c07b5a8b7a002a2fa082232d559b (patch)
tree9dd7bff82645e04f1dc53fbff8f5e366bda49cb9 /tools/slang-unit-test/unit-test-file-system.cpp
parent8e0750fb193a8d2b9e8c3a0d81e367d6a9bdeb30 (diff)
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.
Diffstat (limited to 'tools/slang-unit-test/unit-test-file-system.cpp')
-rw-r--r--tools/slang-unit-test/unit-test-file-system.cpp31
1 files changed, 29 insertions, 2 deletions
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<ISlangBlob> 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<ISlangMutableFileSystem> 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<ISlangMutableFileSystem> memoryFileSystem(new RiffFileSystem(nullptr));
+ ComPtr<ISlangMutableFileSystem> 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"));
{