summaryrefslogtreecommitdiff
path: root/tools/slang-test/unit-relative-container.cpp
diff options
context:
space:
mode:
authorjsmall-nvidia <jsmall@nvidia.com>2019-10-24 17:58:24 -0400
committerTim Foley <tfoleyNV@users.noreply.github.com>2019-10-24 14:58:24 -0700
commit89ddb50eaccc1b7b590dbde55032721762711fb2 (patch)
treee61da2c1604e0d52d3a9915363769ccf950b62f3 /tools/slang-test/unit-relative-container.cpp
parent58ad4b1a9ca43098a071c42bd752a4a48405bf0e (diff)
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.
Diffstat (limited to 'tools/slang-test/unit-relative-container.cpp')
-rw-r--r--tools/slang-test/unit-relative-container.cpp94
1 files changed, 0 insertions, 94 deletions
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<Relative32Ptr<RelativeString> > dirs;
- Relative32Ptr<RelativeString> 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> root = container.newObject<Root>();
-
- auto array = container.newArray<Relative32Ptr<RelativeString>>(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);