From 89ddb50eaccc1b7b590dbde55032721762711fb2 Mon Sep 17 00:00:00 2001 From: jsmall-nvidia Date: Thu, 24 Oct 2019 17:58:24 -0400 Subject: OffsetContainer serialization (#1093) * OffsetContainer with unit tests. * State serialization working with OffsetContainer. * Fixes to make work with OffsetContainer. * Added OffsetContainer documentation. * Remove RelativeContainer. * Fix problem with + on Offset32Ptr on windows x86 target. * * Made OffsetBase a base class of OffsetContainer. * Added MemoryOffsetBase to just handle being a chunk of memory. * * Use operator[] to access contents of OffsetContainer * Fix the type hash to work across different size_t sizes. * Fixed some Offset type related comments. * Fix bug around using asBase, because it returns a reference just using 'auto' will means it becomes a value type. Remove assignment and copy ctor from OffsetBase. * Evaluation order of assignment can lead to wrong behavior with Offset32Ptr/raw pointers. Document the fact, and fix in StateSerializeUtil. --- tools/slang-test/unit-relative-container.cpp | 94 ---------------------------- 1 file changed, 94 deletions(-) delete mode 100644 tools/slang-test/unit-relative-container.cpp (limited to 'tools/slang-test/unit-relative-container.cpp') diff --git a/tools/slang-test/unit-relative-container.cpp b/tools/slang-test/unit-relative-container.cpp deleted file mode 100644 index a9ff7c0fe..000000000 --- a/tools/slang-test/unit-relative-container.cpp +++ /dev/null @@ -1,94 +0,0 @@ -// unit-test-path.cpp - -#include "../../source/core/slang-relative-container.h" - -#include "test-context.h" - -using namespace Slang; - -static void _checkEncodeDecode(uint32_t size) -{ - uint8_t encode[RelativeString::kMaxSizeEncodeSize]; - - size_t encodeSize = RelativeString::calcEncodedSize(size, encode); - - size_t decodedSize; - const char* chars = RelativeString::decodeSize((const char*)encode, decodedSize); - - SLANG_CHECK(decodedSize == size); - SLANG_CHECK(chars - (const char*)encode == encodeSize); -} - -namespace { // anonymous - -struct Root -{ - Relative32Array > dirs; - Relative32Ptr name; - float value; -}; - -} // anonymous - -static void relativeContainerUnitTest() -{ - _checkEncodeDecode(253); - - for (int64_t i = 0; i < 0x100000000; i += (i / 2) + 1) - { - _checkEncodeDecode(uint32_t(i)); - } - - { - RelativeContainer container; - - const char* strings[] = - { - "Hello", - "World", - nullptr, - }; - - { - Safe32Ptr root = container.newObject(); - - auto array = container.newArray>(SLANG_COUNT_OF(strings)); - for (Int i = 0; i < SLANG_COUNT_OF(strings); ++i) - { - array[i] = container.newString(strings[i]); - } - - root->dirs = array; - } - - { - RelativeContainer copy; - copy.set(container.getData(), container.getDataCount()); - - Root* root = (Root*)copy.getData(); - - SLANG_CHECK(root->dirs.getCount() == SLANG_COUNT_OF(strings)); - - Int count = root->dirs.getCount(); - for (Int i = 0; i < count; ++i) - { - RelativeString* str = root->dirs[i]; - - const char* check = strings[i]; - - if (check) - { - SLANG_CHECK(str != nullptr); - const char* strCstr = str->getCstr(); - SLANG_CHECK(strcmp(strCstr, check) == 0); - } - else - { - SLANG_CHECK(str == nullptr); - } - } - } - } -} - -SLANG_UNIT_TEST("RelativeContainer", relativeContainerUnitTest); -- cgit v1.2.3