summaryrefslogtreecommitdiffstats
path: root/tools/slang-unit-test/unit-test-compression.cpp
diff options
context:
space:
mode:
authorjsmall-nvidia <jsmall@nvidia.com>2022-10-03 21:09:16 -0400
committerGitHub <noreply@github.com>2022-10-03 18:09:16 -0700
commit0b51ea6bb54b1d8a12695ccc2c259fd591069791 (patch)
tree1ff0587eb1454891bf8421a86b95ed5e95419e75 /tools/slang-unit-test/unit-test-compression.cpp
parentcc3548c92b1cf028b94d7a264a55df83e6d4d212 (diff)
IMutableFileSystem::saveFileBlob (#2427)
* #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. * Added PathKind * * Make MemoryFileSystem not have implicit directories * Make RelativeFileSystem only allow access to files in file system (kind of like chroot) * Added Path::simplifyAbsolute * Special handling for root of MemoryFileSystem * Improvements around paths for different impls * More improvements around RelativeFileSystem. Special case root handling. * Test archive serialization. Move testinf from compression. Remove the implicit directory test -> doesn't work on all file systems. * Small optimization that removes need for check for a parent unless an item is being *created*. * Add implicit path testing. * Add support for saveFileBlob Add testing for saveFileBlob * Removed TemporaryFileSet Added PlatformUtil::outputDebugMessage * Some small improvements around RelativeFileSystem. * Split out ImplicitDirectoryCollector so can use without requiring compression systems. * Split out StringSliceIndexMap into own files.
Diffstat (limited to 'tools/slang-unit-test/unit-test-compression.cpp')
-rw-r--r--tools/slang-unit-test/unit-test-compression.cpp172
1 files changed, 15 insertions, 157 deletions
diff --git a/tools/slang-unit-test/unit-test-compression.cpp b/tools/slang-unit-test/unit-test-compression.cpp
index e3bcbcf00..486a252b2 100644
--- a/tools/slang-unit-test/unit-test-compression.cpp
+++ b/tools/slang-unit-test/unit-test-compression.cpp
@@ -1,174 +1,32 @@
// unit-compression.cpp
-
#include "tools/unit-test/slang-unit-test.h"
-#include "source/core/slang-io.h"
-#include "../../source/core/slang-zip-file-system.h"
-
#include "../../source/core/slang-lz4-compression-system.h"
#include "../../source/core/slang-deflate-compression-system.h"
-#include "../../source/core/slang-destroyable.h"
-
using namespace Slang;
-static bool _equals(const void* data, size_t size, ISlangBlob* blob)
-{
- return blob && blob->getBufferSize() == size && memcmp(blob->getBufferPointer(), data, size) == 0;
-}
-
-template <size_t SIZE>
-static bool _equals(const char (&text)[SIZE], ISlangBlob* blob)
-{
- return _equals(text, SIZE, blob);
-}
-
-static List<String> _getContents(ISlangFileSystemExt* fileSystem, const char* path)
+static ICompressionSystem* _getCompressionSystem(CompressionSystemType type)
{
- List<String> objs;
-
- fileSystem->enumeratePathContents(path, [](SlangPathType pathType, const char* name, void* userData) {
- List<String>& out = *(List<String>*)userData;
- out.add(name);
- }, &objs);
-
- return objs;
+ switch (type)
+ {
+ case CompressionSystemType::Deflate: return DeflateCompressionSystem::getSingleton(); break;
+ case CompressionSystemType::LZ4: return LZ4CompressionSystem::getSingleton(); break;
+ default: break;
+ }
+ return nullptr;
}
SLANG_UNIT_TEST(compression)
{
- const SlangArchiveType archiveTypes[] =
- {
- SLANG_ARCHIVE_TYPE_RIFF,
- SLANG_ARCHIVE_TYPE_RIFF_DEFLATE,
- SLANG_ARCHIVE_TYPE_RIFF_LZ4,
- SLANG_ARCHIVE_TYPE_ZIP
- };
-
- for (auto archiveType : archiveTypes)
- {
- // Test out archive file systems
- ComPtr<ISlangMutableFileSystem> fileSystem;
- SLANG_CHECK(SLANG_SUCCEEDED(createArchiveFileSystem(archiveType, fileSystem)));
-
- const char contents[] = "I'm compressed";
- const char contents2[] = "Some more stuff";
- const char contents3[] = "Replace it";
-
- {
- SLANG_CHECK(SLANG_SUCCEEDED(fileSystem->createDirectory("hello")));
- SLANG_CHECK(SLANG_SUCCEEDED(fileSystem->createDirectory("hello2")));
- SLANG_CHECK(SLANG_SUCCEEDED(fileSystem->remove("hello")));
- SLANG_CHECK(SLANG_SUCCEEDED(fileSystem->createDirectory("hello")));
-
- SLANG_CHECK(SLANG_SUCCEEDED(fileSystem->saveFile("file.txt", contents, SLANG_COUNT_OF(contents))));
-
- SLANG_CHECK(SLANG_SUCCEEDED(fileSystem->saveFile("file2.txt", contents2, SLANG_COUNT_OF(contents2))));
-
- ComPtr<ISlangBlob> blob;
- SLANG_CHECK(SLANG_SUCCEEDED(fileSystem->loadFile("file.txt", blob.writeRef())));
- SLANG_CHECK(_equals(contents, blob));
-
- SLANG_CHECK(SLANG_SUCCEEDED(fileSystem->loadFile("file2.txt", blob.writeRef())));
- SLANG_CHECK(_equals(contents2, blob));
-
- SLANG_CHECK(SLANG_SUCCEEDED(fileSystem->saveFile("file2.txt", contents3, SLANG_COUNT_OF(contents3))));
-
- SLANG_CHECK(SLANG_SUCCEEDED(fileSystem->loadFile("file2.txt", blob.writeRef())));
- SLANG_CHECK(_equals(contents3, blob));
-
- // Check the path type
- {
- SlangPathType pathType;
- SLANG_CHECK(SLANG_SUCCEEDED(fileSystem->getPathType("file2.txt", &pathType)));
- SLANG_CHECK(pathType == SLANG_PATH_TYPE_FILE);
-
- SLANG_CHECK(SLANG_SUCCEEDED(fileSystem->getPathType("hello", &pathType)));
- SLANG_CHECK(pathType == SLANG_PATH_TYPE_DIRECTORY);
- }
-
- // Enumerate
- {
- for (const auto& obj : _getContents(fileSystem, ""))
- {
- // All of these should exist
- SlangPathType pathType;
- SLANG_CHECK(SLANG_SUCCEEDED(fileSystem->getPathType(obj.getBuffer(), &pathType)));
- }
- }
-
- SLANG_CHECK(SLANG_SUCCEEDED(fileSystem->saveFile("implicit-path/file2.txt", contents3, SLANG_COUNT_OF(contents3))));
-
- {
- SlangPathType pathType;
- SLANG_CHECK(SLANG_SUCCEEDED(fileSystem->getPathType("implicit-path", &pathType)));
-
- SLANG_CHECK(pathType == SLANG_PATH_TYPE_DIRECTORY);
-
- List<String> objs = _getContents(fileSystem, "implicit-path");
-
- // It contains a file
- SLANG_CHECK(objs.getCount() == 1);
-
- for (const auto& obj : objs)
- {
- String path = Path::combine("implicit-path", obj);
-
- // All of these should exist
- SlangPathType pathType;
- SLANG_CHECK(SLANG_SUCCEEDED(fileSystem->getPathType(path.getBuffer(), &pathType)));
- }
-
- // Make an explicit path, and see whe have the same results
- fileSystem->createDirectory("implicit-path");
-
- objs = _getContents(fileSystem, "implicit-path");
- SLANG_CHECK(objs.getCount() == 1);
- }
- }
-
-
- // Load and check its okay
-
- {
- IArchiveFileSystem* archiveFileSystem = as<IArchiveFileSystem>(fileSystem);
-
- ComPtr<ISlangBlob> archiveBlob;
- SLANG_CHECK(SLANG_SUCCEEDED(archiveFileSystem->storeArchive(false, archiveBlob.writeRef())));
-
-
- ComPtr<ISlangFileSystemExt> fileSystem;
-#if 0
- SLANG_CHECK(SLANG_SUCCEEDED(createArchiveFileSystem(archiveType, fileSystem)));
-
- SLANG_CHECK(SLANG_SUCCEEDED(fileSystem->loadArchive(archiveBlob->getBufferPointer(), archiveBlob->getBufferSize())));
-#else
- SLANG_CHECK(SLANG_SUCCEEDED(loadArchiveFileSystem(archiveBlob->getBufferPointer(), archiveBlob->getBufferSize(), fileSystem)));
-#endif
-
- ComPtr<ISlangBlob> blob;
-
- SLANG_CHECK(SLANG_SUCCEEDED(fileSystem->loadFile("file.txt", blob.writeRef())));
- SLANG_CHECK(_equals(contents, blob));
-
- SLANG_CHECK(SLANG_SUCCEEDED(fileSystem->loadFile("file2.txt", blob.writeRef())));
- SLANG_CHECK(_equals(contents3, blob));
- }
- }
-
// Test out compression systems
- for (Index i = 0; i < 2; ++i)
+ for (Index i = 0; i < Count(CompressionSystemType::CountOf); ++i)
{
- // Lets try lz4
-
- ICompressionSystem* system = nullptr;
- if (i == 0)
+ ICompressionSystem* system = _getCompressionSystem(CompressionSystemType(i));
+
+ if (!system)
{
- system = LZ4CompressionSystem::getSingleton();
- }
- else
- {
- system = DeflateCompressionSystem::getSingleton();
+ continue;
}
const char src[] = "Some text to compress";
@@ -176,16 +34,16 @@ SLANG_UNIT_TEST(compression)
ComPtr<ISlangBlob> compressedBlob;
+ // Use the default style
CompressionStyle style;
SLANG_CHECK(SLANG_SUCCEEDED(system->compress(&style, src, srcSize, compressedBlob.writeRef())));
// Now lets decompress
-
List<char> decompressedData;
decompressedData.setCount(srcSize);
SLANG_CHECK(SLANG_SUCCEEDED(system->decompress(compressedBlob->getBufferPointer(), compressedBlob->getBufferSize(), srcSize, decompressedData.getBuffer())));
- SLANG_CHECK(memcmp(src, decompressedData.getBuffer(), srcSize) == 0);
+ SLANG_CHECK(::memcmp(src, decompressedData.getBuffer(), srcSize) == 0);
}
}