diff options
Diffstat (limited to 'tools')
| -rw-r--r-- | tools/slang-unit-test/unit-test-json-native.cpp | 53 |
1 files changed, 50 insertions, 3 deletions
diff --git a/tools/slang-unit-test/unit-test-json-native.cpp b/tools/slang-unit-test/unit-test-json-native.cpp index 1d2085751..6636cc04a 100644 --- a/tools/slang-unit-test/unit-test-json-native.cpp +++ b/tools/slang-unit-test/unit-test-json-native.cpp @@ -11,13 +11,42 @@ using namespace Slang; namespace { // anonymous +struct OtherStruct +{ + typedef OtherStruct ThisType; + + bool operator==(const ThisType& rhs) const { return f == rhs.f && value == rhs.value; } + bool operator!=(const ThisType& rhs) const { return !(*this == rhs); } + + float f = 1.0f; + String value; + + static const StructRttiInfo g_rttiInfo; +}; + +static const StructRttiInfo _makeOtherStructRtti() +{ + OtherStruct obj; + StructRttiBuilder builder(&obj, "OtherStruct", nullptr); + builder.addField("f", &obj.f); + builder.addField("value", &obj.value); + return builder.make(); +} +/* static */const StructRttiInfo OtherStruct::g_rttiInfo = _makeOtherStructRtti(); + struct SomeStruct { typedef SomeStruct ThisType; bool operator==(const ThisType& rhs) const { - return a == rhs.a && b == rhs.b && s == rhs.s && list == rhs.list; + return a == rhs.a && + b == rhs.b && + s == rhs.s && + list == rhs.list && + boolValue == rhs.boolValue && + structList == rhs.structList && + makeConstArrayView(fixedArray) == makeConstArrayView(rhs.fixedArray); } bool operator!=(const ThisType& rhs) const { return !(*this == rhs); } @@ -25,12 +54,15 @@ struct SomeStruct float b = 2.0f; String s; List<String> list; + bool boolValue = false; + + List<OtherStruct> structList; + + int fixedArray[2] = { 0, 0 }; static const StructRttiInfo g_rttiInfo; }; -} // anonymous - static const StructRttiInfo _makeSomeStructRtti() { SomeStruct obj; @@ -40,11 +72,17 @@ static const StructRttiInfo _makeSomeStructRtti() builder.addField("b", &obj.b); builder.addField("s", &obj.s); builder.addField("list", &obj.list); + builder.addField("boolValue", &obj.boolValue); + builder.addField("structList", &obj.structList); + builder.addField("fixedArray", &obj.fixedArray); return builder.make(); } /* static */const StructRttiInfo SomeStruct::g_rttiInfo = _makeSomeStructRtti(); +} // anonymous + + static SlangResult _check() { // Convert into a JSON string @@ -52,6 +90,15 @@ static SlangResult _check() SomeStruct s; s.list.add("Hello!"); s.s = "There"; + s.boolValue = true; + + OtherStruct o; + o.f = 27.5f; + o.value = "This works!"; + + s.structList.add(o); + s.fixedArray[1] = 8; + s.fixedArray[0] = -1; // Try serializing it out |
