yum-mirror/slang

Making it easier to work with shaders

git clone https://git.yummers.dev/yum-mirror/slang

Ellie HermaszewskaCorrect include dir for libslang (#5539)7b570feed

master
1.6 KiB58 linesraw
1// unit-compression.cpp
2#include "../../source/core/slang-deflate-compression-system.h"
3#include "../../source/core/slang-lz4-compression-system.h"
4#include "unit-test/slang-unit-test.h"
5
6using namespace Slang;
7
8static ICompressionSystem* _getCompressionSystem(CompressionSystemType type)
9{
10    switch (type)
11    {
12    case CompressionSystemType::Deflate:
13        return DeflateCompressionSystem::getSingleton();
14        break;
15    case CompressionSystemType::LZ4:
16        return LZ4CompressionSystem::getSingleton();
17        break;
18    default:
19        break;
20    }
21    return nullptr;
22}
23
24SLANG_UNIT_TEST(compression)
25{
26    // Test out compression systems
27    for (Index i = 0; i < Count(CompressionSystemType::CountOf); ++i)
28    {
29        ICompressionSystem* system = _getCompressionSystem(CompressionSystemType(i));
30
31        if (!system)
32        {
33            continue;
34        }
35
36        const char src[] = "Some text to compress";
37        size_t srcSize = sizeof(src);
38
39        ComPtr<ISlangBlob> compressedBlob;
40
41        // Use the default style
42        CompressionStyle style;
43
44        SLANG_CHECK(
45            SLANG_SUCCEEDED(system->compress(&style, src, srcSize, compressedBlob.writeRef())));
46
47        // Now lets decompress
48        List<char> decompressedData;
49        decompressedData.setCount(srcSize);
50
51        SLANG_CHECK(SLANG_SUCCEEDED(system->decompress(
52            compressedBlob->getBufferPointer(),
53            compressedBlob->getBufferSize(),
54            srcSize,
55            decompressedData.getBuffer())));
56        SLANG_CHECK(::memcmp(src, decompressedData.getBuffer(), srcSize) == 0);
57    }
58}