|
|
@@ -2,7 +2,7 @@
|
|
|
#include <catch2.hpp>
|
|
|
#include "JsonConvertHelper.hpp"
|
|
|
|
|
|
-TEST_CASE("test normal class", "[json]")
|
|
|
+TEST_CASE("从JSON字符串中获取结构体内容", "[json]")
|
|
|
{
|
|
|
struct DemoObjct
|
|
|
{
|
|
|
@@ -20,7 +20,7 @@ TEST_CASE("test normal class", "[json]")
|
|
|
REQUIRE(demoObj.strValue == "demo object!");
|
|
|
}
|
|
|
|
|
|
-TEST_CASE("JSON字段数据不对应", "[json]")
|
|
|
+TEST_CASE("JSON字段数据不顺序对应", "[json]")
|
|
|
{
|
|
|
struct DemoObjct
|
|
|
{
|
|
|
@@ -38,7 +38,7 @@ TEST_CASE("JSON字段数据不对应", "[json]")
|
|
|
REQUIRE(demoObj.strValue == "demo object!");
|
|
|
}
|
|
|
|
|
|
-TEST_CASE("test normal space class", "[json]")
|
|
|
+TEST_CASE("从JSON字符串中获取结构体内容,声明中添加空格等占位符", "[json]")
|
|
|
{
|
|
|
struct DemoObjct
|
|
|
{
|
|
|
@@ -56,7 +56,7 @@ TEST_CASE("test normal space class", "[json]")
|
|
|
REQUIRE(demoObj.strValue == "demo object!");
|
|
|
}
|
|
|
|
|
|
-TEST_CASE("test rename class", "[json]")
|
|
|
+TEST_CASE("从JSON字符串中获取结构体内容,支持重命名", "[json]")
|
|
|
{
|
|
|
struct DemoObjct
|
|
|
{
|
|
|
@@ -191,4 +191,14 @@ TEST_CASE("嵌套结构体转换转换为JSON字符串", "[json]")
|
|
|
std::string rawString;
|
|
|
REQUIRE(Object2Json(rawString, demoObj));
|
|
|
std::cout << "returned json format: " << rawString << std::endl;
|
|
|
+
|
|
|
+ DemoObjct demoObj2;
|
|
|
+ REQUIRE(Json2Object(demoObj2, std::string(rawString)));
|
|
|
+ REQUIRE(demoObj2.boolValue == true);
|
|
|
+ REQUIRE(demoObj2.intValue == 1234);
|
|
|
+ REQUIRE(demoObj2.strValue == "demo object!");
|
|
|
+
|
|
|
+ REQUIRE(demoObj2.parent.boolValue == true);
|
|
|
+ REQUIRE(demoObj2.parent.intValue == 1234);
|
|
|
+ REQUIRE(demoObj2.parent.strValue == "demo object!");
|
|
|
}
|