diff options
| author | Yong He <yonghe@outlook.com> | 2021-09-24 11:33:44 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-09-24 11:33:44 -0700 |
| commit | bec8e6aec85b6e3f875c58bdd59eb15613978358 (patch) | |
| tree | 0791fb2ce1be786c17e5a6ee489ed3065fc07332 /tools/slang-test/unit-offset-container.cpp | |
| parent | f2a3c933bc11a498c622fa18694c84beca8ca031 (diff) | |
Move existing unit tests to a standalone dll. (#1945)
Diffstat (limited to 'tools/slang-test/unit-offset-container.cpp')
| -rw-r--r-- | tools/slang-test/unit-offset-container.cpp | 119 |
1 files changed, 0 insertions, 119 deletions
diff --git a/tools/slang-test/unit-offset-container.cpp b/tools/slang-test/unit-offset-container.cpp deleted file mode 100644 index d0990d9bb..000000000 --- a/tools/slang-test/unit-offset-container.cpp +++ /dev/null @@ -1,119 +0,0 @@ -// unit-test-path.cpp - -#include "../../source/core/slang-offset-container.h" - -#include "test-context.h" - -using namespace Slang; - -static void _checkEncodeDecode(uint32_t size) -{ - uint8_t encode[OffsetString::kMaxSizeEncodeSize]; - - size_t encodeSize = OffsetString::calcEncodedSize(size, encode); - - size_t decodedSize; - const char* chars = OffsetString::decodeSize((const char*)encode, decodedSize); - - SLANG_CHECK(decodedSize == size); - SLANG_CHECK(chars - (const char*)encode == encodeSize); -} - -namespace { // anonymous - -struct Root -{ - Offset32Array<Offset32Ptr<OffsetString> > dirs; - Offset32Ptr<OffsetString> name; - float value; -}; - -} // anonymous - -static void offsetContainerUnitTest() -{ - _checkEncodeDecode(253); - - for (int64_t i = 0; i < 0x100000000; i += (i / 2) + 1) - { - _checkEncodeDecode(uint32_t(i)); - } - - { - OffsetContainer container; - - const char* strings[] = - { - "Hello", - "World", - nullptr, - }; - - { - auto& base = container.asBase(); - - Offset32Ptr<Root> root = container.newObject<Root>(); - - auto array = container.newArray<Offset32Ptr<OffsetString>>(SLANG_COUNT_OF(strings)); - for (Int i = 0; i < SLANG_COUNT_OF(strings); ++i) - { - base[array[i]] = container.newString(strings[i]); - } - base[root]->dirs = array; - } - - { - List<uint8_t> copy; - copy.addRange(container.getData(), container.getDataCount()); - - MemoryOffsetBase base; - base.set(copy.getBuffer(), copy.getCount()); - - Root* root = (Root*)(copy.getBuffer() + kStartOffset); - - SLANG_CHECK(root->dirs.getCount() == SLANG_COUNT_OF(strings)); - - Int count = root->dirs.getCount(); - for (Int i = 0; i < count; ++i) - { - OffsetString* str = base.asRaw(base.asRaw(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); - } - } - - { - Index index = 0; - for (const auto v : root->dirs) - { - OffsetString* str = base.asRaw(base.asRaw(v)); - const char* check = strings[index]; - if (check) - { - SLANG_CHECK(str != nullptr); - const char* strCstr = str->getCstr(); - SLANG_CHECK(strcmp(strCstr, check) == 0); - } - else - { - SLANG_CHECK(str == nullptr); - } - - index ++; - } - } - } - } -} - -SLANG_UNIT_TEST("OffsetContainer", offsetContainerUnitTest); |
