yum-mirror/slang
Making it easier to work with shaders
git clone https://git.yummers.dev/yum-mirror/slang
7b570feed
master
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{ 10switch (type ) 11 { 12case CompressionSystemType ::Deflate : 13return DeflateCompressionSystem ::getSingleton (); 14break ; 15case CompressionSystemType ::LZ4 : 16return LZ4CompressionSystem ::getSingleton (); 17break ; 18default : 19break ; 20 } 21return nullptr ; 22} 23 24SLANG_UNIT_TEST (compression ) 25{ 26// Test out compression systems 27for (Index i = 0 ;i < Count (CompressionSystemType ::CountOf );++ i ) 28 { 29ICompressionSystem * system = _getCompressionSystem (CompressionSystemType (i )); 30 31if (!system ) 32 { 33continue ; 34 } 35 36const char src []= "Some text to compress" ; 37size_t srcSize = sizeof (src ); 38 39ComPtr < ISlangBlob > compressedBlob ; 40 41// Use the default style 42CompressionStyle style ; 43 44SLANG_CHECK ( 45SLANG_SUCCEEDED (system -> compress (& style ,src ,srcSize ,compressedBlob .writeRef ()))); 46 47// Now lets decompress 48List < char > decompressedData ; 49decompressedData .setCount (srcSize ); 50 51SLANG_CHECK (SLANG_SUCCEEDED (system -> decompress ( 52compressedBlob -> getBufferPointer (), 53compressedBlob -> getBufferSize (), 54srcSize , 55decompressedData .getBuffer ()))); 56SLANG_CHECK (::memcmp (src ,decompressedData .getBuffer (),srcSize )== 0 ); 57 } 58}