diff options
| author | jsmall-nvidia <jsmall@nvidia.com> | 2019-10-29 08:51:24 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-10-29 08:51:24 -0400 |
| commit | c27b7d91aaf6bc764807a8998a9c885e57c22a1b (patch) | |
| tree | 56dc12c9f326f7d4fe4ddf1bfe5903e8918732bd /tools | |
| parent | c886ca811975e91cedca898a561ff65a5663272d (diff) | |
Feature/container format (#1098)
* WIP RiffContainer.
* WIP riff container.
* Testing out RiffContainer.
* * Naming improvements
* Visitor functions
* Ability to dump riffs.
* Renamed RiffChunk to RiffHeader
* Remove m_ prefix on RiffHeader members.
* Riff stream reading writing.
Simple test of riff reading/writing.
* Fix Riff alignment issue.
Make IR serialization use the RiffContainer API.
* Improve documentation.
* Remove SubChunk fuctionality as not needed with RiffContainer.
Diffstat (limited to 'tools')
| -rw-r--r-- | tools/slang-test/slang-test.vcxproj | 1 | ||||
| -rw-r--r-- | tools/slang-test/slang-test.vcxproj.filters | 3 | ||||
| -rw-r--r-- | tools/slang-test/unit-test-riff.cpp | 106 |
3 files changed, 110 insertions, 0 deletions
diff --git a/tools/slang-test/slang-test.vcxproj b/tools/slang-test/slang-test.vcxproj index b22a3fe60..a7e925ffd 100644 --- a/tools/slang-test/slang-test.vcxproj +++ b/tools/slang-test/slang-test.vcxproj @@ -180,6 +180,7 @@ <ClCompile Include="unit-test-free-list.cpp" /> <ClCompile Include="unit-test-memory-arena.cpp" /> <ClCompile Include="unit-test-path.cpp" /> + <ClCompile Include="unit-test-riff.cpp" /> <ClCompile Include="unit-test-string.cpp" /> </ItemGroup> <ItemGroup> diff --git a/tools/slang-test/slang-test.vcxproj.filters b/tools/slang-test/slang-test.vcxproj.filters index b88490559..afb5b091a 100644 --- a/tools/slang-test/slang-test.vcxproj.filters +++ b/tools/slang-test/slang-test.vcxproj.filters @@ -59,6 +59,9 @@ <ClCompile Include="unit-test-path.cpp"> <Filter>Source Files</Filter> </ClCompile> + <ClCompile Include="unit-test-riff.cpp"> + <Filter>Source Files</Filter> + </ClCompile> <ClCompile Include="unit-test-string.cpp"> <Filter>Source Files</Filter> </ClCompile> diff --git a/tools/slang-test/unit-test-riff.cpp b/tools/slang-test/unit-test-riff.cpp new file mode 100644 index 000000000..58e9a1bb7 --- /dev/null +++ b/tools/slang-test/unit-test-riff.cpp @@ -0,0 +1,106 @@ +// unit-test-riff.cpp + +#include "../../source/core/slang-riff.h" + +#include "test-context.h" + +using namespace Slang; + +static void riffUnitTest() +{ + const FourCC markThings = SLANG_FOUR_CC('T', 'H', 'I', 'N'); + const FourCC markData = SLANG_FOUR_CC('D', 'A', 'T', 'A'); + + { + typedef RiffContainer::ScopeChunk ScopeChunk; + typedef RiffContainer::Chunk::Kind Kind; + + RiffContainer container; + + { + ScopeChunk scopeContainer(&container, Kind::List, markThings); + + { + ScopeChunk scopeChunk(&container, Kind::Data, markData); + + const char hello[] = "Hello "; + const char world[] = "World!"; + + container.write(hello, sizeof(hello)); + container.write(world, sizeof(world)); + } + + { + ScopeChunk scopeChunk(&container, Kind::Data, markData); + + const char test0[] = "Testing... "; + const char test1[] = "Testing!"; + + container.write(test0, sizeof(test0)); + container.write(test1, sizeof(test1)); + } + + { + ScopeChunk innerScopeContainer(&container, Kind::List, markThings); + + { + ScopeChunk scopeChunk(&container, Kind::Data, markData); + + const char another[] = "Another?"; + container.write(another, sizeof(another)); + } + } + } + + SLANG_CHECK(container.isFullyConstructed()); + SLANG_CHECK(RiffContainer::isChunkOk(container.getRoot())); + + { + StringBuilder builder; + { + StringWriter writer(&builder, 0); + RiffUtil::dump(container.getRoot(), &writer); + } + + { + OwnedMemoryStream stream(FileAccess::ReadWrite); + SLANG_CHECK(SLANG_SUCCEEDED(RiffUtil::write(container.getRoot(), true, &stream))); + + stream.seek(SeekOrigin::Start, 0); + + RiffContainer readContainer; + SLANG_CHECK(SLANG_SUCCEEDED(RiffUtil::read(&stream, readContainer))); + + // Dump the read contents + StringBuilder readBuilder; + { + StringWriter writer(&readBuilder, 0); + RiffUtil::dump(readContainer.getRoot(), &writer); + } + + // They should be the same + SLANG_CHECK(readBuilder == builder); + } + } + + } + +#if 0 + { + RiffContainer container; + { + FileStream readStream("ambient-drop.wav", FileMode::Open, FileAccess::Read, FileShare::ReadWrite); + SLANG_CHECK(SLANG_SUCCEEDED(RiffUtil::read(&readStream, container))); + RiffUtil::dump(container.getRoot(), StdWriters::getOut()); + } + // Write it + { + + FileStream writeStream("check.wav", FileMode::Create, FileAccess::Write, FileShare::ReadWrite); + SLANG_CHECK(SLANG_SUCCEEDED(RiffUtil::write(container.getRoot(), true, &writeStream))); + } + } +#endif +} + +SLANG_UNIT_TEST("Riff", riffUnitTest); |
