Эх сурвалжийг харах

test: 增加数据解析一致性测试,优化测试代码

RyanCW 5 өдөр өмнө
parent
commit
92a59cfb76

+ 162 - 116
test/RyanJsonMemoryFootprintTest.c

@@ -1,10 +1,23 @@
 #include "RyanJsonTest.h"
 
-static void *yy_malloc(void *ctx, size_t size) { return v_malloc_tlsf(size); }
-static void *yy_realloc(void *ctx, void *ptr, size_t old_size, size_t size) { return v_realloc_tlsf(ptr, size); }
-static void yy_free(void *ctx, void *ptr) { v_free_tlsf(ptr); }
+static void *yy_malloc(void *ctx, size_t size)
+{
+	(void)(ctx);
+	return v_malloc_tlsf(size);
+}
+static void *yy_realloc(void *ctx, void *ptr, size_t old_size, size_t size)
+{
+	(void)(ctx);
+	(void)(old_size);
+	return v_realloc_tlsf(ptr, size);
+}
+static void yy_free(void *ctx, void *ptr)
+{
+	(void)(ctx);
+	v_free_tlsf(ptr);
+}
 
-static int RyanJsonMemoryFootprint(char *jsonstr)
+static RyanJsonBool_e RyanJsonMemoryFootprint(char *jsonstr, int32_t *footprint)
 {
 	int32_t use = vallocGetUseByTlsf();
 	RyanJsonInitHooks(v_malloc_tlsf, v_free_tlsf, v_realloc_tlsf);
@@ -13,16 +26,17 @@ static int RyanJsonMemoryFootprint(char *jsonstr)
 	if (json == NULL)
 	{
 		printf("%s:%d 解析失败\r\n", __FILE__, __LINE__);
-		return -1;
+		return RyanJsonFalse;
 	}
 
 	use = vallocGetUseByTlsf() - use;
 
 	RyanJsonDelete(json);
-	return use;
+	*footprint = use;
+	return RyanJsonTrue;
 }
 
-static int cJSONMemoryFootprint(char *jsonstr)
+static RyanJsonBool_e cJSONMemoryFootprint(char *jsonstr, int32_t *footprint)
 {
 	int32_t use = vallocGetUseByTlsf();
 	cJSON_Hooks hooks = {.malloc_fn = v_malloc_tlsf, .free_fn = v_free_tlsf};
@@ -32,44 +46,54 @@ static int cJSONMemoryFootprint(char *jsonstr)
 	if (json == NULL)
 	{
 		printf("%s:%d 解析失败\r\n", __FILE__, __LINE__);
-		return -1;
+		return RyanJsonFalse;
 	}
 
 	use = vallocGetUseByTlsf() - use;
 	cJSON_Delete(json);
-	return use;
+	*footprint = use;
+	return RyanJsonTrue;
 }
 
-static int yyjsonMemoryFootprint(char *jsonstr)
+static RyanJsonBool_e yyjsonMemoryFootprint(char *jsonstr, int32_t *footprint)
 {
 	static yyjson_alc yyalc = {yy_malloc, yy_realloc, yy_free, NULL};
 	int32_t use = vallocGetUseByTlsf();
 
 	// 先解析成只读文档(可用自定义分配器 yyalc)
 	yyjson_doc *doc = yyjson_read_opts(jsonstr, strlen(jsonstr), YYJSON_READ_NOFLAG, &yyalc, NULL);
-	if (doc == NULL) { return -1; }
+	if (doc == NULL) { return RyanJsonFalse; }
 
 	// 从只读文档拷贝为可变文档(用于后续读写修改)
 	yyjson_mut_doc *mdoc = yyjson_doc_mut_copy(doc, &yyalc);
 	yyjson_doc_free(doc);
-	if (mdoc == NULL) { return -1; }
+	if (mdoc == NULL) { return RyanJsonFalse; }
 
 	// 统计当前分配器的占用
 	use = vallocGetUseByTlsf() - use;
 
 	// 用完释放可变文档
 	yyjson_mut_doc_free(mdoc);
-	return use;
+	*footprint = use;
+	return RyanJsonTrue;
 }
 
-static void printfJsonCompera(char *jsonstr)
+static RyanJsonBool_e printfJsonCompare(char *jsonstr)
 {
-	int RyanJsonCount = 0;
-	int cJSONCount = 0;
-	int yyjsonCount = 0;
-	RyanJsonCount = RyanJsonMemoryFootprint(jsonstr);
-	cJSONCount = cJSONMemoryFootprint(jsonstr);
-	yyjsonCount = yyjsonMemoryFootprint(jsonstr);
+	int32_t RyanJsonCount = 0;
+	int32_t cJSONCount = 0;
+	int32_t yyjsonCount = 0;
+	RyanJsonBool_e status = RyanJsonFalse;
+
+	status = RyanJsonMemoryFootprint(jsonstr, &RyanJsonCount);
+	if (RyanJsonTrue != status) { return RyanJsonFalse; }
+
+	status = cJSONMemoryFootprint(jsonstr, &cJSONCount);
+	if (RyanJsonTrue != status) { return RyanJsonFalse; }
+
+	status = yyjsonMemoryFootprint(jsonstr, &yyjsonCount);
+	if (RyanJsonTrue != status) { return RyanJsonFalse; }
+
 	printf("json原始文本长度为 %ld, 序列化后RyanJson内存占用: %d, cJSON内存占用: %d, yyjson内存占用: %d\r\n", strlen(jsonstr),
 	       RyanJsonCount, cJSONCount, yyjsonCount);
 
@@ -77,61 +101,62 @@ static void printfJsonCompera(char *jsonstr)
 	double save_vs_yyjson = 100.0 - ((double)RyanJsonCount * 100.0) / (double)yyjsonCount;
 
 	printf("比cJSON节省: %.2f%% 内存占用, 比yyjson节省: %.2f%% 内存占用\r\n", save_vs_cjson, save_vs_yyjson);
+	return RyanJsonTrue;
 }
 
-RyanJsonBool_e RyanJsonMemoryFootprintTest(void)
+static RyanJsonBool_e testMixedJsonMemory(void)
 {
-	char *jsonstr;
-
-	printf("\r\n--------------------------- 混合类型json数据测试 --------------------------\r\n");
-	jsonstr = "{\"item1\":{\"inter\":16,\"double\":16.89,\"string\":\"hello\",\"boolTrue\":true,\"boolFalse\":false,\"null\":null,"
-		  "\"item\":{\"inter\":16,"
-		  "\"double\":16.89,\"string\":\"hello\","
-		  "\"boolTrue\":true,\"boolFalse\":false,\"null\":null},\"arrayInt\":[16,16,16,16,16],\"arrayDouble\":[16.89,16.89,16.89,"
-		  "16.89,16.89],"
-		  "\"arrayString\":[\"hello\",\"hello\",\"hello\","
-		  "\"hello\",\"hello\"],\"array\":[16,16.89,\"hello\",true,false,null],\"arrayItem\":[{\"inter\":16,\"double\":16.89,"
-		  "\"string\":\"hello\","
-		  "\"boolTrue\":true,\"boolFalse\":false,"
-		  "\"null\":null},{\"inter\":16,\"double\":16.89,\"string\":\"hello\",\"boolTrue\":true,\"boolFalse\":false,\"null\":null}]"
-		  "},\"item2\":{"
-		  "\"inter\":16,\"double\":16.89,\"string\":"
-		  "\"hello\",\"boolTrue\":true,\"boolFalse\":false,\"null\":null,\"item\":{\"inter\":16,\"double\":16.89,\"string\":"
-		  "\"hello\",\"boolTrue\":"
-		  "true,\"boolFalse\":false,\"null\":null},"
-		  "\"arrayInt\":[16,16,16,16,16],\"arrayDouble\":[16.89,16.89,16.89,16.89,16.89],\"arrayString\":[\"hello\",\"hello\","
-		  "\"hello\",\"hello\","
-		  "\"hello\"],\"array\":[16,16.89,\"hello\","
-		  "true,false,null],\"arrayItem\":[{\"inter\":16,\"double\":16.89,\"string\":\"hello\",\"boolTrue\":true,\"boolFalse\":"
-		  "false,\"null\":null},{"
-		  "\"inter\":16,\"double\":16.89,\"string\":"
-		  "\"hello\",\"boolTrue\":true,\"boolFalse\":false,\"null\":null}]},\"item3\":{\"inter\":16,\"double\":16.89,\"string\":"
-		  "\"hello\",\"boolTrue\":"
-		  "true,\"boolFalse\":false,\"null\":null,"
-		  "\"item\":{\"inter\":16,\"double\":16.89,\"string\":\"hello\",\"boolTrue\":true,\"boolFalse\":false,\"null\":null},"
-		  "\"arrayInt\":[16,16,16,16,"
-		  "16],\"arrayDouble\":[16.89,16.89,16.89,"
-		  "16.89,16.89],\"arrayString\":[\"hello\",\"hello\",\"hello\",\"hello\",\"hello\"],\"array\":[16,16.89,\"hello\",true,"
-		  "false,null],"
-		  "\"arrayItem\":[{\"inter\":16,\"double\":16.89,"
-		  "\"string\":\"hello\",\"boolTrue\":true,\"boolFalse\":false,\"null\":null},{\"inter\":16,\"double\":16.89,\"string\":"
-		  "\"hello\",\"boolTrue\":"
-		  "true,\"boolFalse\":false,\"null\":null}]}"
-		  ",\"item4\":{\"inter\":16,\"double\":16.89,\"string\":\"hello\",\"boolTrue\":true,\"boolFalse\":false,\"null\":null,"
-		  "\"item\":{\"inter\":16,"
-		  "\"double\":16.89,\"string\":\"hello\","
-		  "\"boolTrue\":true,\"boolFalse\":false,\"null\":null},\"arrayInt\":[16,16,16,16,16],\"arrayDouble\":[16.89,16.89,16.89,"
-		  "16.89,16.89],"
-		  "\"arrayString\":[\"hello\",\"hello\",\"hello\","
-		  "\"hello\",\"hello\"],\"array\":[16,16.89,\"hello\",true,false,null],\"arrayItem\":[{\"inter\":16,\"double\":16.89,"
-		  "\"string\":\"hello\","
-		  "\"boolTrue\":true,\"boolFalse\":false,"
-		  "\"null\":null},{\"inter\":16,\"double\":16.89,\"string\":\"hello\",\"boolTrue\":true,\"boolFalse\":false,\"null\":null}]"
-		  "}}";
-	printfJsonCompera(jsonstr);
+	char *jsonstr =
+		"{\"item1\":{\"inter\":16,\"double\":16.89,\"string\":\"hello\",\"boolTrue\":true,\"boolFalse\":false,\"null\":null,"
+		"\"item\":{\"inter\":16,"
+		"\"double\":16.89,\"string\":\"hello\","
+		"\"boolTrue\":true,\"boolFalse\":false,\"null\":null},\"arrayInt\":[16,16,16,16,16],\"arrayDouble\":[16.89,16.89,16.89,"
+		"16.89,16.89],"
+		"\"arrayString\":[\"hello\",\"hello\",\"hello\","
+		"\"hello\",\"hello\"],\"array\":[16,16.89,\"hello\",true,false,null],\"arrayItem\":[{\"inter\":16,\"double\":16.89,"
+		"\"string\":\"hello\","
+		"\"boolTrue\":true,\"boolFalse\":false,"
+		"\"null\":null},{\"inter\":16,\"double\":16.89,\"string\":\"hello\",\"boolTrue\":true,\"boolFalse\":false,\"null\":null}]"
+		"},\"item2\":{"
+		"\"inter\":16,\"double\":16.89,\"string\":"
+		"\"hello\",\"boolTrue\":true,\"boolFalse\":false,\"null\":null,\"item\":{\"inter\":16,\"double\":16.89,\"string\":"
+		"\"hello\",\"boolTrue\":"
+		"true,\"boolFalse\":false,\"null\":null},"
+		"\"arrayInt\":[16,16,16,16,16],\"arrayDouble\":[16.89,16.89,16.89,16.89,16.89],\"arrayString\":[\"hello\",\"hello\","
+		"\"hello\",\"hello\","
+		"\"hello\"],\"array\":[16,16.89,\"hello\","
+		"true,false,null],\"arrayItem\":[{\"inter\":16,\"double\":16.89,\"string\":\"hello\",\"boolTrue\":true,\"boolFalse\":"
+		"false,\"null\":null},{"
+		"\"inter\":16,\"double\":16.89,\"string\":"
+		"\"hello\",\"boolTrue\":true,\"boolFalse\":false,\"null\":null}]},\"item3\":{\"inter\":16,\"double\":16.89,\"string\":"
+		"\"hello\",\"boolTrue\":"
+		"true,\"boolFalse\":false,\"null\":null,"
+		"\"item\":{\"inter\":16,\"double\":16.89,\"string\":\"hello\",\"boolTrue\":true,\"boolFalse\":false,\"null\":null},"
+		"\"arrayInt\":[16,16,16,16,"
+		"16],\"arrayDouble\":[16.89,16.89,16.89,"
+		"16.89,16.89],\"arrayString\":[\"hello\",\"hello\",\"hello\",\"hello\",\"hello\"],\"array\":[16,16.89,\"hello\",true,"
+		"false,null],"
+		"\"arrayItem\":[{\"inter\":16,\"double\":16.89,"
+		"\"string\":\"hello\",\"boolTrue\":true,\"boolFalse\":false,\"null\":null},{\"inter\":16,\"double\":16.89,\"string\":"
+		"\"hello\",\"boolTrue\":"
+		"true,\"boolFalse\":false,\"null\":null}]}"
+		",\"item4\":{\"inter\":16,\"double\":16.89,\"string\":\"hello\",\"boolTrue\":true,\"boolFalse\":false,\"null\":null,"
+		"\"item\":{\"inter\":16,"
+		"\"double\":16.89,\"string\":\"hello\","
+		"\"boolTrue\":true,\"boolFalse\":false,\"null\":null},\"arrayInt\":[16,16,16,16,16],\"arrayDouble\":[16.89,16.89,16.89,"
+		"16.89,16.89],"
+		"\"arrayString\":[\"hello\",\"hello\",\"hello\","
+		"\"hello\",\"hello\"],\"array\":[16,16.89,\"hello\",true,false,null],\"arrayItem\":[{\"inter\":16,\"double\":16.89,"
+		"\"string\":\"hello\","
+		"\"boolTrue\":true,\"boolFalse\":false,"
+		"\"null\":null},{\"inter\":16,\"double\":16.89,\"string\":\"hello\",\"boolTrue\":true,\"boolFalse\":false,\"null\":null}]"
+		"}}";
+	return printfJsonCompare(jsonstr);
+}
 
-	printf("\r\n--------------------------- 全是对象json数据测试 --------------------------\r\n");
-	jsonstr =
+static RyanJsonBool_e testObjectJsonMemory(void)
+{
+	char *jsonstr =
 		"{\"message\":\"success感谢又拍云(upyun.com)提供CDN赞助\",\"status\":200,\"date\":\"20230822\",\"time\":\"2023-08-22 "
 		"09:44:54\",\"cityInfo\":{\"city\":\"郑州市\",\"citykey\":\"101180101\",\"parent\":\"河南\",\"updateTime\":\"07:46\"},"
 		"\"data\":{\"shidu\":"
@@ -203,56 +228,77 @@ RyanJsonBool_e RyanJsonMemoryFootprintTest(void)
 		"星期一\",\"sunrise\":\"05:50\",\"sunset\":\"19:07\",\"aqi\":60,\"fx\":\"西风\",\"fl\":\"2级\",\"type\":\"小雨\","
 		"\"notice\":"
 		"\"雨虽小,注意保暖别感冒\"}}}";
-	printfJsonCompera(jsonstr);
+	return printfJsonCompare(jsonstr);
+}
 
-	printf("\r\n--------------------------- 数组占多json数据测试 --------------------------\r\n");
-	jsonstr = "{\"item1\":{\"arrayInt\":[16,16,16,16,16,16,16,16,16,16],\"arrayDouble\":[16.89,16.89,16.89,16.89,16.89,16.89,16.89,16."
-		  "89,16.89,16.89],"
-		  "\"arrayString\":[\"hello\",\"hello\","
-		  "\"hello\",\"hello\",\"hello\",\"hello\",\"hello\",\"hello\",\"hello\",\"hello\"],\"array\":[16,16.89,\"hello\",true,"
-		  "false,null,16,16.89,"
-		  "\"hello\",true,false,null]},\"item2\":{"
-		  "\"arrayInt\":[16,16,16,16,16,16,16,16,16,16],\"arrayDouble\":[16.89,16.89,16.89,16.89,16.89,16.89,16.89,16.89,16.89,16."
-		  "89],\"arrayString\":["
-		  "\"hello\",\"hello\",\"hello\",\"hello\","
-		  "\"hello\",\"hello\",\"hello\",\"hello\",\"hello\",\"hello\"],\"array\":[16,16.89,\"hello\",true,false,null,16,16.89,"
-		  "\"hello\",true,false,"
-		  "null]},\"item3\":{\"arrayInt\":[16,16,16,"
-		  "16,16,16,16,16,16,16],\"arrayDouble\":[16.89,16.89,16.89,16.89,16.89,16.89,16.89,16.89,16.89,16.89],\"arrayString\":["
-		  "\"hello\",\"hello\","
-		  "\"hello\",\"hello\",\"hello\",\"hello\","
-		  "\"hello\",\"hello\",\"hello\",\"hello\"],\"array\":[16,16.89,\"hello\",true,false,null,16,16.89,\"hello\",true,false,"
-		  "null]},\"item4\":{"
-		  "\"arrayInt\":[16,16,16,16,16,16,16,16,16,16],"
-		  "\"arrayDouble\":[16.89,16.89,16.89,16.89,16.89,16.89,16.89,16.89,16.89,16.89],\"arrayString\":[\"hello\",\"hello\","
-		  "\"hello\",\"hello\","
-		  "\"hello\",\"hello\",\"hello\",\"hello\","
-		  "\"hello\",\"hello\"],\"array\":[16,16.89,\"hello\",true,false,null,16,16.89,\"hello\",true,false,null]}}";
-	printfJsonCompera(jsonstr);
+static RyanJsonBool_e testArrayJsonMemory(void)
+{
+	char *jsonstr =
+		"{\"item1\":{\"arrayInt\":[16,16,16,16,16,16,16,16,16,16],\"arrayDouble\":[16.89,16.89,16.89,16.89,16.89,16.89,16.89,16."
+		"89,16.89,16.89],"
+		"\"arrayString\":[\"hello\",\"hello\","
+		"\"hello\",\"hello\",\"hello\",\"hello\",\"hello\",\"hello\",\"hello\",\"hello\"],\"array\":[16,16.89,\"hello\",true,"
+		"false,null,16,16.89,"
+		"\"hello\",true,false,null]},\"item2\":{"
+		"\"arrayInt\":[16,16,16,16,16,16,16,16,16,16],\"arrayDouble\":[16.89,16.89,16.89,16.89,16.89,16.89,16.89,16.89,16.89,16."
+		"89],\"arrayString\":["
+		"\"hello\",\"hello\",\"hello\",\"hello\","
+		"\"hello\",\"hello\",\"hello\",\"hello\",\"hello\",\"hello\"],\"array\":[16,16.89,\"hello\",true,false,null,16,16.89,"
+		"\"hello\",true,false,"
+		"null]},\"item3\":{\"arrayInt\":[16,16,16,"
+		"16,16,16,16,16,16,16],\"arrayDouble\":[16.89,16.89,16.89,16.89,16.89,16.89,16.89,16.89,16.89,16.89],\"arrayString\":["
+		"\"hello\",\"hello\","
+		"\"hello\",\"hello\",\"hello\",\"hello\","
+		"\"hello\",\"hello\",\"hello\",\"hello\"],\"array\":[16,16.89,\"hello\",true,false,null,16,16.89,\"hello\",true,false,"
+		"null]},\"item4\":{"
+		"\"arrayInt\":[16,16,16,16,16,16,16,16,16,16],"
+		"\"arrayDouble\":[16.89,16.89,16.89,16.89,16.89,16.89,16.89,16.89,16.89,16.89],\"arrayString\":[\"hello\",\"hello\","
+		"\"hello\",\"hello\","
+		"\"hello\",\"hello\",\"hello\",\"hello\","
+		"\"hello\",\"hello\"],\"array\":[16,16.89,\"hello\",true,false,null,16,16.89,\"hello\",true,false,null]}}";
+	return printfJsonCompare(jsonstr);
+}
 
-	printf("\r\n--------------------------- 小对象json 混合类型内存占用测试 --------------------------\r\n");
-	jsonstr = "{\"inter\":16,\"double\":16.89,\"string\":\"hello\",\"boolTrue\":true,\"boolFalse\":false,\"null\":null}";
-	printfJsonCompera(jsonstr);
+static RyanJsonBool_e testSmallMixedJsonMemory(void)
+{
+	char *jsonstr = "{\"inter\":16,\"double\":16.89,\"string\":\"hello\",\"boolTrue\":true,\"boolFalse\":false,\"null\":null}";
+	return printfJsonCompare(jsonstr);
+}
 
-	printf("\r\n--------------------------- 小对象json 纯字符串内存占用测试 --------------------------\r\n");
-	jsonstr = "{\"inter\":\"16\",\"double\":\"16.89\",\"string\":\"hello\",\"boolTrue\":\"true\",\"boolFalse\":\"false\",\"null\":"
-		  "\"null\"}";
-	printfJsonCompera(jsonstr);
+static RyanJsonBool_e testSmallStringJsonMemory(void)
+{
+	char *jsonstr =
+		"{\"inter\":\"16\",\"double\":\"16.89\",\"string\":\"hello\",\"boolTrue\":\"true\",\"boolFalse\":\"false\",\"null\":"
+		"\"null\"}";
+	return printfJsonCompare(jsonstr);
+}
 
-	printf("\r\n--------------------------- 压缩后的json业务对象内存占用测试 --------------------------\r\n");
-	jsonstr = "{\"0\":\"0\",\"1\":\"189774523\",\"2\":{\"7\":\"3\",\"8\":\"103\",\"9\":\"37\",\"20\":\"0\",\"26\":\"37\",\"27\":"
-		  "\"367\",\"28\":\"367\",\"s\":\"0\",\"t\":\"0\",\"a\":\"24.98\",\"2a\":\"0\",\"1p\":\"23628\"},\"3\":\"0\",\"22\":"
-		  "\"epmgrow1105\",\"23\":\"0\",\"29\":\"0\",\"i\":\"4\",\"b\":\"900\",\"c\":\"1\",\"rsrp\":\"-111\",\"rsrq\":\"-4\","
-		  "\"sinr\":\"0\",\"soc\":\"XXXXXXX\",\"j\":\"0\",\"g\":\"898604asdf0210\",\"h\":\"866968798839\",\"d\":\"1.3.5."
-		  "00.20991231\",\"f\":\"0\",\"k\":\"1\",\"l\":\"20000\",\"m\":\"20000\",\"u\":\"0\",\"v\":\"0\",\"e\":\"1\",\"w\":\"0."
-		  "00\",\"n\":\"0\",\"2h\":\"0\",\"o\":\"30\",\"1v\":\"12000\",\"2c\":\"0\",\"p\":\"1\",\"q\":\"1\",\"x\":\"0\",\"y\":"
-		  "\"167\",\"r\":\"0\",\"1x\":\"0\",\"1w\":\"0\",\"1y\":\"100.00\",\"1u\":\"0\"}";
-	printfJsonCompera(jsonstr);
+static RyanJsonBool_e testCompressedBusinessJsonMemory(void)
+{
+	char *jsonstr =
+		"{\"0\":\"0\",\"1\":\"189774523\",\"2\":{\"7\":\"3\",\"8\":\"103\",\"9\":\"37\",\"20\":\"0\",\"26\":\"37\",\"27\":"
+		"\"367\",\"28\":\"367\",\"s\":\"0\",\"t\":\"0\",\"a\":\"24.98\",\"2a\":\"0\",\"1p\":\"23628\"},\"3\":\"0\",\"22\":"
+		"\"epmgrow1105\",\"23\":\"0\",\"29\":\"0\",\"i\":\"4\",\"b\":\"900\",\"c\":\"1\",\"rsrp\":\"-111\",\"rsrq\":\"-4\","
+		"\"sinr\":\"0\",\"soc\":\"XXXXXXX\",\"j\":\"0\",\"g\":\"898604asdf0210\",\"h\":\"866968798839\",\"d\":\"1.3.5."
+		"00.20991231\",\"f\":\"0\",\"k\":\"1\",\"l\":\"20000\",\"m\":\"20000\",\"u\":\"0\",\"v\":\"0\",\"e\":\"1\",\"w\":\"0."
+		"00\",\"n\":\"0\",\"2h\":\"0\",\"o\":\"30\",\"1v\":\"12000\",\"2c\":\"0\",\"p\":\"1\",\"q\":\"1\",\"x\":\"0\",\"y\":"
+		"\"167\",\"r\":\"0\",\"1x\":\"0\",\"1w\":\"0\",\"1y\":\"100.00\",\"1u\":\"0\"}";
+	printfJsonCompare(jsonstr);
+	return RyanJsonTrue;
+}
+
+RyanJsonBool_e RyanJsonMemoryFootprintTest(void)
+{
+	int32_t result = 0;
+	uint32_t testRunCount = 0;
+	uint64_t funcStartMs;
 
-	/**
-	 * @brief 反序列化为文本,内存占用没什么特别的优化点,和cjson实现思路差不多,内存占用也就差不多,就不进行对比了
-	 *
-	 */
+	runTestWithLogAndTimer(testMixedJsonMemory);
+	runTestWithLogAndTimer(testObjectJsonMemory);
+	runTestWithLogAndTimer(testArrayJsonMemory);
+	runTestWithLogAndTimer(testSmallMixedJsonMemory);
+	runTestWithLogAndTimer(testSmallStringJsonMemory);
+	runTestWithLogAndTimer(testCompressedBusinessJsonMemory);
 
 	return RyanJsonTrue;
 }

+ 8 - 1
test/RyanJsonTest.c

@@ -15,6 +15,14 @@ static void printfTitle(char *title)
 	printf("*****************************************************************************\r\n");
 }
 
+uint64_t platformUptimeMs(void)
+{
+	struct timespec ts;
+	// CLOCK_MONOTONIC: 单调递增,不受系统时间修改影响,适合做耗时统计
+	clock_gettime(CLOCK_MONOTONIC, &ts);
+	return (uint64_t)ts.tv_sec * 1000 + ts.tv_nsec / 1000000;
+}
+
 static tlsf_t tlsfHandler;
 
 static size_t total2 = LV_MEM_SIZE, used2 = 0, available = 0;
@@ -50,7 +58,6 @@ int32_t vallocGetUseByTlsf(void)
 void *v_malloc_tlsf(size_t size)
 {
 	if (size == 0) { return NULL; }
-
 	return tlsf_malloc(tlsfHandler, RyanJsonAlign(size + RyanJsonMallocHeaderSize - 4, RyanJsonMallocAlign));
 }
 

+ 14 - 0
test/RyanJsonTest.h

@@ -13,6 +13,7 @@ extern "C" {
 #include <sys/stat.h>
 #include <dirent.h>
 #include <ctype.h>
+#include <inttypes.h>
 #include "valloc.h"
 #include "RyanJson.h"
 #include "RyanJsonUtils.h"
@@ -44,6 +45,19 @@ extern void *v_realloc_tlsf(void *block, size_t size);
 extern int32_t vallocGetUseByTlsf(void);
 
 // 定义结构体类型
+uint64_t platformUptimeMs(void);
+
+#define runTestWithLogAndTimer(fun)                                                                                                        \
+	do                                                                                                                                 \
+	{                                                                                                                                  \
+		testRunCount++;                                                                                                            \
+		printf("┌── [TEST %d] 开始执行: " #fun "()\r\n", testRunCount);                                                            \
+		funcStartMs = platformUptimeMs();                                                                                          \
+		result = fun();                                                                                                            \
+		printf("└── [TEST %" PRIu32 "] 结束执行: 返回值 = %" PRId32 " %s | 耗时: %" PRIu64 " ms\x1b[0m\r\n\r\n", testRunCount,     \
+		       result, (result == RyanJsonTrue) ? "✅" : "❌", (platformUptimeMs() - funcStartMs));                                \
+		RyanJsonCheckCodeNoReturn(RyanJsonTrue == result, { return RyanJsonFalse; });                                              \
+	} while (0)
 
 /* extern variables-----------------------------------------------------------*/
 extern RyanJsonBool_e RyanJsonExample(void);

+ 6 - 20
test/baseTest/RyanJsonBaseTest.c

@@ -40,31 +40,11 @@ static RyanJsonBool_e likeReferenceTest()
 	return 0;
 }
 
-uint64_t platformUptimeMs(void)
-{
-	struct timespec ts;
-	// CLOCK_MONOTONIC: 单调递增,不受系统时间修改影响,适合做耗时统计
-	clock_gettime(CLOCK_MONOTONIC, &ts);
-	return (uint64_t)ts.tv_sec * 1000 + ts.tv_nsec / 1000000;
-}
-
 RyanJsonBool_e RyanJsonBaseTest(void)
 {
 	int32_t result = 0;
-
 	uint32_t testRunCount = 0;
 	uint64_t funcStartMs;
-#define runTestWithLogAndTimer(fun)                                                                                                        \
-	do                                                                                                                                 \
-	{                                                                                                                                  \
-		testRunCount++;                                                                                                            \
-		printf("┌── [TEST %d] 开始执行: " #fun "()\r\n", testRunCount);                                                            \
-		funcStartMs = platformUptimeMs();                                                                                          \
-		result = fun();                                                                                                            \
-		printf("└── [TEST %" PRIu32 "] 结束执行: 返回值 = %" PRId32 " %s | 耗时: %" PRIu64 " ms\x1b[0m\r\n\r\n", testRunCount,     \
-		       result, (result == RyanJsonTrue) ? "✅" : "❌", (platformUptimeMs() - funcStartMs));                                \
-		RyanJsonCheckCodeNoReturn(RyanJsonTrue == result, { goto __exit; });                                                       \
-	} while (0)
 
 	runTestWithLogAndTimer(RyanJsonBaseTestChangeJson);    // 验证 JSON 动态更新及存储模式切换逻辑
 	runTestWithLogAndTimer(RyanJsonBaseTestCompareJson);   // 验证节点及其属性的深度一致性比较逻辑
@@ -76,6 +56,12 @@ RyanJsonBool_e RyanJsonBaseTest(void)
 	runTestWithLogAndTimer(RyanJsonBaseTestLoadJson);      // 验证复杂 JSON 文本解析与内存映射的健壮性
 	runTestWithLogAndTimer(RyanJsonBaseTestReplaceJson);   // 验证节点就地替换与成员管理机制的有效性
 
+	// 验证节点属性一致性
+	runTestWithLogAndTimer(RyanJsonBaseTestEqualityBool);   // 验证布尔值一致性
+	runTestWithLogAndTimer(RyanJsonBaseTestEqualityDouble); // 验证浮点数一致性
+	runTestWithLogAndTimer(RyanJsonBaseTestEqualityInt);    // 验证整数一致性
+	runTestWithLogAndTimer(RyanJsonBaseTestEqualityString); // 验证字符串一致性
+
 	// result = likeReferenceTest(); // 模仿 引用类型实现 示例
 	// if (0 != result)
 	// {

+ 5 - 1
test/baseTest/RyanJsonBaseTest.h

@@ -26,7 +26,6 @@ extern "C" {
 
 /* extern variables-----------------------------------------------------------*/
 
-extern RyanJsonBool_e compare_double(double a, double b);
 extern void printJsonDebug(RyanJson_t json);
 extern RyanJsonBool_e rootNodeCheckTest(RyanJson_t json);
 extern RyanJsonBool_e itemNodeCheckTest(RyanJson_t json);
@@ -44,6 +43,11 @@ extern RyanJsonBool_e RyanJsonBaseTestForEachJson(void);
 extern RyanJsonBool_e RyanJsonBaseTestLoadJson(void);
 extern RyanJsonBool_e RyanJsonBaseTestReplaceJson(void);
 
+extern RyanJsonBool_e RyanJsonBaseTestEqualityBool(void);
+extern RyanJsonBool_e RyanJsonBaseTestEqualityDouble(void);
+extern RyanJsonBool_e RyanJsonBaseTestEqualityInt(void);
+extern RyanJsonBool_e RyanJsonBaseTestEqualityString(void);
+
 #ifdef __cplusplus
 }
 #endif

+ 6 - 6
test/baseTest/RyanJsonBaseTestChangeJson.c

@@ -28,7 +28,7 @@ RyanJsonBool_e RyanJsonBaseTestChangeJson(void)
 
 	RyanJsonChangeDoubleValue(RyanJsonGetObjectToKey(jsonRoot, "double"), 20.89);
 	RyanJsonCheckCode(RyanJsonIsDouble(RyanJsonGetObjectToKey(jsonRoot, "double")) &&
-				  compare_double(RyanJsonGetDoubleValue(RyanJsonGetObjectToKey(jsonRoot, "double")), 20.89),
+				  RyanJsonCompareDouble(RyanJsonGetDoubleValue(RyanJsonGetObjectToKey(jsonRoot, "double")), 20.89),
 			  { goto err; });
 
 	// inline模式只修改key,并且不超过inline长度
@@ -95,11 +95,11 @@ RyanJsonBool_e RyanJsonBaseTestChangeJson(void)
 	 * @brief 修改数组元素 (arrayDouble)
 	 */
 	RyanJsonChangeDoubleValue(RyanJsonGetObjectToIndex(RyanJsonGetObjectToKey(jsonRoot, "arrayDouble"), 1), 99.99);
-	RyanJsonCheckCode(
-		RyanJsonIsDouble(RyanJsonGetObjectToIndex(RyanJsonGetObjectToKey(jsonRoot, "arrayDouble"), 1)) &&
-			compare_double(RyanJsonGetDoubleValue(RyanJsonGetObjectToIndex(RyanJsonGetObjectToKey(jsonRoot, "arrayDouble"), 1)),
-				       99.99),
-		{ goto err; });
+	RyanJsonCheckCode(RyanJsonIsDouble(RyanJsonGetObjectToIndex(RyanJsonGetObjectToKey(jsonRoot, "arrayDouble"), 1)) &&
+				  RyanJsonCompareDouble(RyanJsonGetDoubleValue(RyanJsonGetObjectToIndex(
+								RyanJsonGetObjectToKey(jsonRoot, "arrayDouble"), 1)),
+							99.99),
+			  { goto err; });
 
 	/**
 	 * @brief 修改数组元素 (arrayString)

+ 1 - 1
test/baseTest/RyanJsonBaseTestForEachJson.c

@@ -20,7 +20,7 @@ RyanJsonBool_e RyanJsonBaseTestForEachJson(void)
 	RyanJson_t item = NULL;
 	RyanJsonArrayForEach(RyanJsonGetObjectToKey(json, "arrayDouble"), item)
 	{
-		if (!RyanJsonIsDouble(item) || !compare_double(16.89, RyanJsonGetDoubleValue(item))) { goto err; }
+		if (!RyanJsonIsDouble(item) || !RyanJsonCompareDouble(16.89, RyanJsonGetDoubleValue(item))) { goto err; }
 	}
 
 	RyanJsonArrayForEach(RyanJsonGetObjectToKey(json, "arrayInt"), item)

+ 2 - 8
test/baseTest/RyanJsonBaseTestUtile.c

@@ -2,12 +2,6 @@
 #include "RyanJsonBaseTest.h"
 
 /* --------------------------------------- jsonTest ------------------------------------------- */
-// !(fabs(RyanJsonGetDoubleValue(RyanJsonGetObjectToKey(json, "double")) - 16.89) < 1e-6)
-RyanJsonBool_e compare_double(double a, double b)
-{
-	double maxVal = fabs(a) > fabs(b) ? fabs(a) : fabs(b);
-	return (fabs(a - b) <= maxVal * DBL_EPSILON);
-}
 
 void printJsonDebug(RyanJson_t json)
 {
@@ -24,7 +18,7 @@ RyanJsonBool_e rootNodeCheckTest(RyanJson_t json)
 	}
 
 	if (!RyanJsonIsDouble(RyanJsonGetObjectToKey(json, "double")) ||
-	    !compare_double(RyanJsonGetDoubleValue(RyanJsonGetObjectToKey(json, "double")), 16.89))
+	    !RyanJsonCompareDouble(RyanJsonGetDoubleValue(RyanJsonGetObjectToKey(json, "double")), 16.89))
 	{
 		RyanJsonCheckReturnFalse(NULL);
 	}
@@ -85,7 +79,7 @@ RyanJsonBool_e arrayNodeCheckTest(RyanJson_t json)
 	}
 
 	if (!RyanJsonIsDouble(RyanJsonGetObjectByIndex(RyanJsonGetObjectToKey(json, "array"), 1)) ||
-	    !compare_double(RyanJsonGetDoubleValue(RyanJsonGetObjectByIndex(RyanJsonGetObjectToKey(json, "array"), 1)), 16.89))
+	    !RyanJsonCompareDouble(RyanJsonGetDoubleValue(RyanJsonGetObjectByIndex(RyanJsonGetObjectToKey(json, "array"), 1)), 16.89))
 	{
 		printf("%s:%d 解析失败 %f\r\n", __FILE__, __LINE__,
 		       RyanJsonGetDoubleValue(RyanJsonGetObjectByIndex(RyanJsonGetObjectToKey(json, "array"), 1)));

+ 86 - 0
test/baseTest/equality/RyanJsonBaseTestEqualityBool.c

@@ -0,0 +1,86 @@
+#include "RyanJsonBaseTest.h"
+
+// 布尔值一致性测试
+RyanJsonBool_e RyanJsonBaseTestEqualityBool(void)
+{
+	// 测试 true
+	{
+		const char *jsonBoolStr = "{\"bool\":true}";
+		RyanJson_t jsonRoot = RyanJsonParse(jsonBoolStr);
+		RyanJsonCheckReturnFalse(NULL != jsonRoot);
+		RyanJsonCheckReturnFalse(RyanJsonIsBool(RyanJsonGetObjectToKey(jsonRoot, "bool")));
+		RyanJsonCheckReturnFalse(RyanJsonTrue == RyanJsonGetBoolValue(RyanJsonGetObjectToKey(jsonRoot, "bool")));
+
+		// 往返测试
+		char *serializedStr = RyanJsonPrint(jsonRoot, 64, RyanJsonFalse, NULL);
+		RyanJsonDelete(jsonRoot);
+
+		RyanJson_t roundtripJson = RyanJsonParse(serializedStr);
+		RyanJsonFree(serializedStr);
+		RyanJsonCheckReturnFalse(NULL != roundtripJson);
+		RyanJsonCheckReturnFalse(RyanJsonIsBool(RyanJsonGetObjectToKey(roundtripJson, "bool")));
+		RyanJsonCheckReturnFalse(RyanJsonTrue == RyanJsonGetBoolValue(RyanJsonGetObjectToKey(roundtripJson, "bool")));
+
+		RyanJsonDelete(roundtripJson);
+	}
+
+	// 测试 false
+	{
+		const char *jsonBoolStr = "{\"bool\":false}";
+		RyanJson_t jsonRoot = RyanJsonParse(jsonBoolStr);
+		RyanJsonCheckReturnFalse(NULL != jsonRoot);
+		RyanJsonCheckReturnFalse(RyanJsonIsBool(RyanJsonGetObjectToKey(jsonRoot, "bool")));
+		RyanJsonCheckReturnFalse(RyanJsonFalse == RyanJsonGetBoolValue(RyanJsonGetObjectToKey(jsonRoot, "bool")));
+
+		// 往返测试
+		char *serializedStr = RyanJsonPrint(jsonRoot, 64, RyanJsonFalse, NULL);
+		RyanJsonDelete(jsonRoot);
+
+		RyanJson_t roundtripJson = RyanJsonParse(serializedStr);
+		RyanJsonFree(serializedStr);
+		RyanJsonCheckReturnFalse(NULL != roundtripJson);
+		RyanJsonCheckReturnFalse(RyanJsonIsBool(RyanJsonGetObjectToKey(roundtripJson, "bool")));
+		RyanJsonCheckReturnFalse(RyanJsonFalse == RyanJsonGetBoolValue(RyanJsonGetObjectToKey(roundtripJson, "bool")));
+
+		RyanJsonDelete(roundtripJson);
+	}
+
+	// 测试数组中的布尔值
+	{
+		const char *jsonArrayStr = "[true, false, true, false]";
+		RyanJson_t jsonRoot = RyanJsonParse(jsonArrayStr);
+		RyanJsonCheckReturnFalse(NULL != jsonRoot);
+		RyanJsonCheckReturnFalse(4 == RyanJsonGetArraySize(jsonRoot));
+
+		RyanJsonBool_e expected[] = {RyanJsonTrue, RyanJsonFalse, RyanJsonTrue, RyanJsonFalse};
+		int idx = 0;
+		RyanJson_t item = NULL;
+		RyanJsonArrayForEach(jsonRoot, item)
+		{
+			RyanJsonCheckReturnFalse(RyanJsonIsBool(item));
+			RyanJsonCheckReturnFalse(expected[idx] == RyanJsonGetBoolValue(item));
+			idx++;
+		}
+
+		// 往返测试
+		char *serializedStr = RyanJsonPrint(jsonRoot, 64, RyanJsonFalse, NULL);
+		RyanJsonDelete(jsonRoot);
+
+		RyanJson_t roundtripJson = RyanJsonParse(serializedStr);
+		RyanJsonFree(serializedStr);
+		RyanJsonCheckReturnFalse(NULL != roundtripJson);
+		RyanJsonCheckReturnFalse(4 == RyanJsonGetArraySize(roundtripJson));
+
+		idx = 0;
+		RyanJsonArrayForEach(roundtripJson, item)
+		{
+			RyanJsonCheckReturnFalse(RyanJsonIsBool(item));
+			RyanJsonCheckReturnFalse(expected[idx] == RyanJsonGetBoolValue(item));
+			idx++;
+		}
+
+		RyanJsonDelete(roundtripJson);
+	}
+
+	return RyanJsonTrue;
+}

+ 172 - 0
test/baseTest/equality/RyanJsonBaseTestEqualityDouble.c

@@ -0,0 +1,172 @@
+#include "RyanJsonBaseTest.h"
+
+#define DoubleList                                                                                                                         \
+	/* ========== 零值测试 ========== */                                                                                               \
+	X(0.0)                                                                                                                             \
+	/* ========== 正负整数边界 ========== */                                                                                           \
+	X(1.0)                                                                                                                             \
+	X(-1.0)                                                                                                                            \
+	X(2.0)                                                                                                                             \
+	X(-2.0)                                                                                                                            \
+	X(10.0)                                                                                                                            \
+	X(-10.0)                                                                                                                           \
+	X(100.0)                                                                                                                           \
+	X(1000.0)                                                                                                                          \
+	X(10000.0)                                                                                                                         \
+	X(100000.0)                                                                                                                        \
+	/* ========== 简单小数(二进制精确表示) ========== */                                                                               \
+	X(0.5)                                                                                                                             \
+	X(-0.5)                                                                                                                            \
+	X(0.25)                                                                                                                            \
+	X(-0.25)                                                                                                                           \
+	X(0.125)                                                                                                                           \
+	X(0.0625)                                                                                                                          \
+	X(0.03125)                                                                                                                         \
+	X(0.015625)                                                                                                                        \
+	/* ========== 常见小数 ========== */                                                                                               \
+	X(16.89)                                                                                                                           \
+	X(-16.89)                                                                                                                          \
+	X(123.456)                                                                                                                         \
+	X(-123.456)                                                                                                                        \
+	X(99.99)                                                                                                                           \
+	X(-99.99)                                                                                                                          \
+	X(1.5)                                                                                                                             \
+	X(2.5)                                                                                                                             \
+	X(3.5)                                                                                                                             \
+	/* ========== 小于1的小数 ========== */                                                                                            \
+	X(0.001)                                                                                                                           \
+	X(-0.001)                                                                                                                          \
+	X(0.0001)                                                                                                                          \
+	X(0.00001)                                                                                                                         \
+	X(0.000001)                                                                                                                        \
+	X(0.123456789)                                                                                                                     \
+	X(0.987654321)                                                                                                                     \
+	X(0.111111111111111)                                                                                                               \
+	/* ========== 大数测试 ========== */                                                                                               \
+	X(999999.999999)                                                                                                                   \
+	X(-999999.999999)                                                                                                                  \
+	X(12345678.9)                                                                                                                      \
+	X(99999999.0)                                                                                                                      \
+	X(123456789.123456)                                                                                                                \
+	X(9876543210.12345)                                                                                                                \
+	/* ========== 科学计数法 - 大数 ========== */                                                                                      \
+	X(1.5e10)                                                                                                                          \
+	X(-1.5e10)                                                                                                                         \
+	X(1.23e8)                                                                                                                          \
+	X(9.99e12)                                                                                                                         \
+	X(1.0e15)                                                                                                                          \
+	X(1.0e18)                                                                                                                          \
+	X(1.0e20)                                                                                                                          \
+	X(5.55e15)                                                                                                                         \
+	/* ========== 科学计数法 - 小数 ========== */                                                                                      \
+	X(1.5e-10)                                                                                                                         \
+	X(-1.5e-10)                                                                                                                        \
+	X(9.87e-5)                                                                                                                         \
+	X(1.0e-15)                                                                                                                         \
+	X(5.5e-8)                                                                                                                          \
+	X(1.0e-18)                                                                                                                         \
+	X(1.0e-20)                                                                                                                         \
+	X(1.23e-3)                                                                                                                         \
+	X(-9.87e-7)                                                                                                                        \
+	/* ========== 数学常量 ========== */                                                                                               \
+	X(3.14159265358979)                                                                                                                \
+	X(2.71828182845904)                                                                                                                \
+	X(1.41421356237309)                                                                                                                \
+	X(1.73205080756888)                                                                                                                \
+	X(1.61803398874989)                                                                                                                \
+	X(0.69314718055994)                                                                                                                \
+	/* ========== 浮点精度经典测试 ========== */                                                                                       \
+	X(0.1)                                                                                                                             \
+	X(0.2)                                                                                                                             \
+	X(0.3)                                                                                                                             \
+	X(0.6)                                                                                                                             \
+	X(0.7)                                                                                                                             \
+	X(0.9)                                                                                                                             \
+	/* ========== 整数边界值 ========== */                                                                                             \
+	X(2147483647.0)                                                                                                                    \
+	X(-2147483648.0)                                                                                                                   \
+	X(4294967295.0)                                                                                                                    \
+	X(9007199254740991.0)                                                                                                              \
+	X(-9007199254740991.0)                                                                                                             \
+	/* ========== 极端小值 ========== */                                                                                               \
+	X(1.0e-100)                                                                                                                        \
+	X(-1.0e-100)                                                                                                                       \
+	X(1.0e-200)                                                                                                                        \
+	X(1.0e-300)                                                                                                                        \
+	X(2.225073858507201e-308)                                                                                                          \
+	/* ========== 极端大值 ========== */                                                                                               \
+	X(1.0e100)                                                                                                                         \
+	X(-1.0e100)                                                                                                                        \
+	X(1.0e200)                                                                                                                         \
+	X(1.0e300)                                                                                                                         \
+	X(1.797693134862315e308)                                                                                                           \
+	/* ========== 特殊精度值 ========== */                                                                                             \
+	X(1.0000000000001)                                                                                                                 \
+	X(0.9999999999999)                                                                                                                 \
+	X(1.23456789012345)                                                                                                                \
+	X(9.87654321098765)                                                                                                                \
+	/* ========== 重复数字模式 ========== */                                                                                           \
+	X(1.1111111111111)                                                                                                                 \
+	X(2.2222222222222)                                                                                                                 \
+	X(9.9999999999999)                                                                                                                 \
+	/* ========== 混合符号和指数 ========== */                                                                                         \
+	X(-1.23e-45)                                                                                                                       \
+	X(-9.87e67)                                                                                                                        \
+	X(1.11e-11)                                                                                                                        \
+	X(-2.22e22)
+
+static const double DoubleValueTable[] = {
+#define X(a) a,
+	DoubleList
+#undef X
+};
+
+static const char *DoubleStringTable[] = {
+#define X(a) "{\"double\":" #a "}",
+	DoubleList
+#undef X
+};
+
+// 浮点数一致性测试
+RyanJsonBool_e RyanJsonBaseTestEqualityDouble(void)
+{
+
+	for (uint32_t i = 0; i < sizeof(DoubleValueTable) / sizeof(DoubleValueTable[0]); i++)
+	{
+		const char *jsondoubleStr = DoubleStringTable[i];
+		RyanJson_t jsonRoot = RyanJsonParse(jsondoubleStr);
+		RyanJsonCheckReturnFalse(NULL != jsonRoot);
+		RyanJsonCheckReturnFalse(RyanJsonIsDouble(RyanJsonGetObjectToKey(jsonRoot, "double")));
+
+		// 验证解析后的数值是否正确
+		double doubleValue = RyanJsonGetDoubleValue(RyanJsonGetObjectToKey(jsonRoot, "double"));
+		RyanJsonCheckCode(RyanJsonCompareDouble(doubleValue, DoubleValueTable[i]), {
+			jsonLog("str: %s, expected: %g, got: %g", jsondoubleStr, DoubleValueTable[i], doubleValue);
+			RyanJsonDelete(jsonRoot);
+			goto err;
+		});
+
+		// 验证序列化后再解析,然后判断double是否一致(往返测试)
+		char *serializedStr = RyanJsonPrint(jsonRoot, 128, RyanJsonFalse, NULL);
+		RyanJsonDelete(jsonRoot);
+
+		RyanJson_t roundtripJson = RyanJsonParse(serializedStr);
+		RyanJsonFree(serializedStr);
+		RyanJsonCheckReturnFalse(NULL != roundtripJson);
+		RyanJsonCheckReturnFalse(RyanJsonIsDouble(RyanJsonGetObjectToKey(roundtripJson, "double")));
+
+		double roundtripValue = RyanJsonGetDoubleValue(RyanJsonGetObjectToKey(roundtripJson, "double"));
+		RyanJsonCheckCode(RyanJsonCompareDouble(roundtripValue, DoubleValueTable[i]), {
+			jsonLog("roundtrip failed: expected: %g, got: %g ", DoubleValueTable[i], roundtripValue);
+			RyanJsonDelete(roundtripJson);
+			goto err;
+		});
+
+		RyanJsonDelete(roundtripJson);
+	}
+
+	return RyanJsonTrue;
+
+err:
+	return RyanJsonFalse;
+}

+ 141 - 0
test/baseTest/equality/RyanJsonBaseTestEqualityInt.c

@@ -0,0 +1,141 @@
+#include "RyanJsonBaseTest.h"
+
+#define IntList                                                                                                                            \
+	/* ========== 零值测试 ========== */                                                                                               \
+	X(0)                                                                                                                               \
+	/* ========== 正负边界 ========== */                                                                                               \
+	X(1)                                                                                                                               \
+	X(-1)                                                                                                                              \
+	X(2)                                                                                                                               \
+	X(-2)                                                                                                                              \
+	/* ========== 常见小整数 ========== */                                                                                             \
+	X(10)                                                                                                                              \
+	X(-10)                                                                                                                             \
+	X(100)                                                                                                                             \
+	X(-100)                                                                                                                            \
+	X(255)                                                                                                                             \
+	X(-255)                                                                                                                            \
+	X(256)                                                                                                                             \
+	X(-256)                                                                                                                            \
+	/* ========== 常见数值 ========== */                                                                                               \
+	X(1000)                                                                                                                            \
+	X(-1000)                                                                                                                           \
+	X(9999)                                                                                                                            \
+	X(-9999)                                                                                                                           \
+	X(12345)                                                                                                                           \
+	X(-12345)                                                                                                                          \
+	X(65535)                                                                                                                           \
+	X(-65535)                                                                                                                          \
+	X(65536)                                                                                                                           \
+	X(-65536)                                                                                                                          \
+	/* ========== 大整数 ========== */                                                                                                 \
+	X(100000)                                                                                                                          \
+	X(-100000)                                                                                                                         \
+	X(1000000)                                                                                                                         \
+	X(-1000000)                                                                                                                        \
+	X(10000000)                                                                                                                        \
+	X(-10000000)                                                                                                                       \
+	X(100000000)                                                                                                                       \
+	X(-100000000)                                                                                                                      \
+	X(1000000000)                                                                                                                      \
+	X(-1000000000)                                                                                                                     \
+	/* ========== 8位边界 ========== */                                                                                                \
+	X(127)                                                                                                                             \
+	X(-128)                                                                                                                            \
+	/* ========== 16位边界 ========== */                                                                                               \
+	X(32767)                                                                                                                           \
+	X(-32768)                                                                                                                          \
+	/* ========== 32位边界 ========== */                                                                                               \
+	X(2147483647)                                                                                                                      \
+	X(-2147483648)                                                                                                                     \
+	/* ========== 特殊模式 ========== */                                                                                               \
+	X(1234567890)                                                                                                                      \
+	X(-1234567890)                                                                                                                     \
+	X(123456789)                                                                                                                       \
+	X(-123456789)                                                                                                                      \
+	/* ========== 2的幂次 ========== */                                                                                                \
+	X(2)                                                                                                                               \
+	X(4)                                                                                                                               \
+	X(8)                                                                                                                               \
+	X(16)                                                                                                                              \
+	X(32)                                                                                                                              \
+	X(64)                                                                                                                              \
+	X(128)                                                                                                                             \
+	X(512)                                                                                                                             \
+	X(1024)                                                                                                                            \
+	X(2048)                                                                                                                            \
+	X(4096)                                                                                                                            \
+	X(8192)                                                                                                                            \
+	X(16384)                                                                                                                           \
+	X(32768)                                                                                                                           \
+	X(65536)                                                                                                                           \
+	X(131072)                                                                                                                          \
+	X(262144)                                                                                                                          \
+	X(524288)                                                                                                                          \
+	X(1048576)                                                                                                                         \
+	X(2097152)                                                                                                                         \
+	X(4194304)                                                                                                                         \
+	X(8388608)                                                                                                                         \
+	X(16777216)                                                                                                                        \
+	X(33554432)                                                                                                                        \
+	X(67108864)                                                                                                                        \
+	X(134217728)                                                                                                                       \
+	X(268435456)                                                                                                                       \
+	X(536870912)                                                                                                                       \
+	X(1073741824)
+
+static const int32_t IntValueTable[] = {
+#define X(a) a,
+	IntList
+#undef X
+};
+
+static const char *IntStringTable[] = {
+#define X(a) "{\"int\":" #a "}",
+	IntList
+#undef X
+};
+
+// 整数一致性测试
+RyanJsonBool_e RyanJsonBaseTestEqualityInt(void)
+{
+
+	for (uint32_t i = 0; i < sizeof(IntValueTable) / sizeof(IntValueTable[0]); i++)
+	{
+		const char *jsonIntStr = IntStringTable[i];
+		RyanJson_t jsonRoot = RyanJsonParse(jsonIntStr);
+		RyanJsonCheckReturnFalse(NULL != jsonRoot);
+		RyanJsonCheckReturnFalse(RyanJsonIsInt(RyanJsonGetObjectToKey(jsonRoot, "int")));
+
+		// 验证解析后的数值是否正确
+		int32_t intValue = RyanJsonGetIntValue(RyanJsonGetObjectToKey(jsonRoot, "int"));
+		RyanJsonCheckCode(intValue == IntValueTable[i], {
+			jsonLog("str: %s, expected: %" PRId32 ", got: %" PRId32, jsonIntStr, IntValueTable[i], intValue);
+			RyanJsonDelete(jsonRoot);
+			goto err;
+		});
+
+		// 验证序列化后再解析,然后判断int是否一致(往返测试)
+		char *serializedStr = RyanJsonPrint(jsonRoot, 128, RyanJsonFalse, NULL);
+		RyanJsonDelete(jsonRoot);
+
+		RyanJson_t roundtripJson = RyanJsonParse(serializedStr);
+		RyanJsonFree(serializedStr);
+		RyanJsonCheckReturnFalse(NULL != roundtripJson);
+		RyanJsonCheckReturnFalse(RyanJsonIsInt(RyanJsonGetObjectToKey(roundtripJson, "int")));
+
+		int32_t roundtripValue = RyanJsonGetIntValue(RyanJsonGetObjectToKey(roundtripJson, "int"));
+		RyanJsonCheckCode(roundtripValue == IntValueTable[i], {
+			jsonLog("roundtrip failed: expected: %" PRId32 ", got: %" PRId32, IntValueTable[i], roundtripValue);
+			RyanJsonDelete(roundtripJson);
+			goto err;
+		});
+
+		RyanJsonDelete(roundtripJson);
+	}
+
+	return RyanJsonTrue;
+
+err:
+	return RyanJsonFalse;
+}

+ 171 - 0
test/baseTest/equality/RyanJsonBaseTestEqualityString.c

@@ -0,0 +1,171 @@
+#include "RyanJsonBaseTest.h"
+
+// ========== 简单字符串(使用X-macro) ==========
+#define SimpleStringList                                                                                                                   \
+	X("")                                                                                                                              \
+	X("hello")                                                                                                                         \
+	X("world")                                                                                                                         \
+	X("test")                                                                                                                          \
+	X("RyanJson")                                                                                                                      \
+	X("123")                                                                                                                           \
+	X("0")                                                                                                                             \
+	X("-1")                                                                                                                            \
+	X("3.14")                                                                                                                          \
+	X("1e10")                                                                                                                          \
+	X("hello world")                                                                                                                   \
+	X("path/to/file")                                                                                                                  \
+	X("abcdefghijklmnopqrstuvwxyz")                                                                                                    \
+	X("ABCDEFGHIJKLMNOPQRSTUVWXYZ")                                                                                                    \
+	X("0123456789")                                                                                                                    \
+	X("The quick brown fox jumps over the lazy dog")                                                                                   \
+	X(" ")                                                                                                                             \
+	X("  ")                                                                                                                            \
+	X("   leading")                                                                                                                    \
+	X("trailing   ")                                                                                                                   \
+	X("  both  ")                                                                                                                      \
+	X("true")                                                                                                                          \
+	X("false")                                                                                                                         \
+	X("null")                                                                                                                          \
+	X("@#$%^&*()")                                                                                                                     \
+	X("!@#$%")                                                                                                                         \
+	X("a=b&c=d")                                                                                                                       \
+	X("user@example.com")                                                                                                              \
+	X("中文测试")                                                                                                                      \
+	X("日本語テスト")                                                                                                                  \
+	X("한국어테스트")                                                                                                                  \
+	X("混合Mixed混合")                                                                                                                 \
+	X("Привет мир")                                                                                                                    \
+	X("مرحبا بالعالم")                                                                                                                 \
+	X("שלום עולם")
+
+static const char *SimpleStringValueTable[] = {
+#define X(a) a,
+	SimpleStringList
+#undef X
+};
+
+static const char *SimpleStringJsonTable[] = {
+#define X(a) "{\"str\":\"" a "\"}",
+	SimpleStringList
+#undef X
+};
+
+// ========== 转义字符(需分离JSON和值) ==========
+typedef struct
+{
+	const char *json;     // JSON字符串(带转义)
+	const char *expected; // 期望的C字符串值
+} EscapeTestCase;
+
+static const EscapeTestCase EscapeTestCases[] = {
+    // 制表符
+    {"{\"str\":\"hello\\tworld\"}", "hello\tworld"},
+    {"{\"str\":\"tab\\there\"}", "tab\there"},
+    // 换行符
+    {"{\"str\":\"hello\\nworld\"}", "hello\nworld"},
+    {"{\"str\":\"line1\\nline2\\nline3\"}", "line1\nline2\nline3"},
+    // 回车符
+    {"{\"str\":\"hello\\rworld\"}", "hello\rworld"},
+    // 引号转义
+    {"{\"str\":\"quote\\\"inside\"}", "quote\"inside"},
+    {"{\"str\":\"say \\\"hello\\\"\"}", "say \"hello\""},
+    // 反斜杠转义
+    {"{\"str\":\"backslash\\\\here\"}", "backslash\\here"},
+    {"{\"str\":\"C:\\\\Windows\\\\System32\"}", "C:\\Windows\\System32"},
+    {"{\"str\":\"path\\\\to\\\\file\"}", "path\\to\\file"},
+    // 斜杠(可选转义)
+    {"{\"str\":\"a\\/b\"}", "a/b"},
+    // 退格符
+    {"{\"str\":\"back\\bspace\"}", "back\bspace"},
+    // 换页符
+    {"{\"str\":\"form\\ffeed\"}", "form\ffeed"},
+    // 组合转义
+    {"{\"str\":\"line1\\nline2\\ttab\"}", "line1\nline2\ttab"},
+    {"{\"str\":\"\\\"quoted\\\" and \\\\escaped\\\\\"}", "\"quoted\" and \\escaped\\"},
+    // Unicode转义
+    {"{\"str\":\"\\u0048\\u0065\\u006C\\u006C\\u006F\"}", "Hello"},
+    {"{\"str\":\"\\u4E2D\\u6587\"}", "中文"},
+    {"{\"str\":\"euro: \\u20AC\"}", "euro: €"},
+    {"{\"str\":\"smile: \\u263A\"}", "smile: ☺"},
+};
+
+// 字符串一致性测试
+RyanJsonBool_e RyanJsonBaseTestEqualityString(void)
+{
+	// ========== 测试简单字符串 ==========
+	for (uint32_t i = 0; i < sizeof(SimpleStringValueTable) / sizeof(SimpleStringValueTable[0]); i++)
+	{
+		const char *jsonStrInput = SimpleStringJsonTable[i];
+		RyanJson_t jsonRoot = RyanJsonParse(jsonStrInput);
+		RyanJsonCheckReturnFalse(NULL != jsonRoot);
+		RyanJsonCheckReturnFalse(RyanJsonIsString(RyanJsonGetObjectToKey(jsonRoot, "str")));
+
+		const char *strValue = RyanJsonGetStringValue(RyanJsonGetObjectToKey(jsonRoot, "str"));
+		RyanJsonCheckCode(0 == strcmp(strValue, SimpleStringValueTable[i]), {
+			jsonLog("simple str failed: expected: %s, got: %s\n", SimpleStringValueTable[i], strValue);
+			RyanJsonDelete(jsonRoot);
+			goto err;
+		});
+
+		// 往返测试
+		char *serializedStr = RyanJsonPrint(jsonRoot, 128, RyanJsonFalse, NULL);
+		RyanJsonDelete(jsonRoot);
+
+		RyanJson_t roundtripJson = RyanJsonParse(serializedStr);
+		RyanJsonFree(serializedStr);
+		RyanJsonCheckReturnFalse(NULL != roundtripJson);
+
+		const char *roundtripValue = RyanJsonGetStringValue(RyanJsonGetObjectToKey(roundtripJson, "str"));
+		RyanJsonCheckCode(0 == strcmp(roundtripValue, SimpleStringValueTable[i]), {
+			jsonLog("simple roundtrip failed: expected: %s, got: %s\n", SimpleStringValueTable[i], roundtripValue);
+			RyanJsonDelete(roundtripJson);
+			goto err;
+		});
+
+		RyanJsonDelete(roundtripJson);
+	}
+
+	// ========== 测试转义字符 ==========
+	for (uint32_t i = 0; i < sizeof(EscapeTestCases) / sizeof(EscapeTestCases[0]); i++)
+	{
+		const EscapeTestCase *tc = &EscapeTestCases[i];
+		RyanJson_t jsonRoot = RyanJsonParse(tc->json);
+		RyanJsonCheckCode(NULL != jsonRoot, {
+			jsonLog("escape parse failed: %s\n", tc->json);
+			goto err;
+		});
+		RyanJsonCheckReturnFalse(RyanJsonIsString(RyanJsonGetObjectToKey(jsonRoot, "str")));
+
+		const char *strValue = RyanJsonGetStringValue(RyanJsonGetObjectToKey(jsonRoot, "str"));
+		RyanJsonCheckCode(0 == strcmp(strValue, tc->expected), {
+			jsonLog("escape str failed: json=%s, expected=%s, got=%s\n", tc->json, tc->expected, strValue);
+			RyanJsonDelete(jsonRoot);
+			goto err;
+		});
+
+		// 往返测试
+		char *serializedStr = RyanJsonPrint(jsonRoot, 128, RyanJsonFalse, NULL);
+		RyanJsonDelete(jsonRoot);
+
+		RyanJson_t roundtripJson = RyanJsonParse(serializedStr);
+		RyanJsonFree(serializedStr);
+		RyanJsonCheckCode(NULL != roundtripJson, {
+			jsonLog("escape roundtrip parse failed\n");
+			goto err;
+		});
+
+		const char *roundtripValue = RyanJsonGetStringValue(RyanJsonGetObjectToKey(roundtripJson, "str"));
+		RyanJsonCheckCode(0 == strcmp(roundtripValue, tc->expected), {
+			jsonLog("escape roundtrip failed: expected=%s, got=%s\n", tc->expected, roundtripValue);
+			RyanJsonDelete(roundtripJson);
+			goto err;
+		});
+
+		RyanJsonDelete(roundtripJson);
+	}
+
+	return RyanJsonTrue;
+
+err:
+	return RyanJsonFalse;
+}

+ 5 - 3
xmake.lua

@@ -14,9 +14,9 @@ target("RyanJson", function()
 
     -- 定义宏:启用 Fuzzer 功能
     -- Fuzzer 与覆盖率相关编译/链接选项
-    -- add_defines("isEnableFuzzer")
-    -- add_cxflags("-fsanitize=fuzzer", {force = true})
-    -- add_ldflags("-fsanitize=fuzzer", {force = true})
+    add_defines("isEnableFuzzer")
+    add_cxflags("-fsanitize=fuzzer", {force = true})
+    add_ldflags("-fsanitize=fuzzer", {force = true})
     add_cxflags("-fprofile-instr-generate", "-fcoverage-mapping", {force = true})
     add_ldflags("-fprofile-instr-generate", "-fcoverage-mapping", {force = true})
 
@@ -126,6 +126,7 @@ target("RyanJson", function()
     add_includedirs('./test/fuzzer', {public = true})
     add_includedirs('./test', {public = true})
     add_includedirs('./test/baseTest', {public = true})
+    add_includedirs('./test/baseTest/equality', {public = true})
     add_includedirs('./test/externalModule/valloc', {public = true})
     add_includedirs('./test/externalModule/tlsf', {public = true})
     add_includedirs('./test/externalModule/cJSON', {public = true})
@@ -137,6 +138,7 @@ target("RyanJson", function()
     add_files('./test/fuzzer/*.c', {public = true})
     add_files('./test/*.c', {public = true}, {cxflags = "-w"})          -- 测试代码,关闭警告
     add_files('./test/baseTest/*.c', {public = true}, {cxflags = "-w"}) -- 基础测试,关闭警告
+    add_files('./test/baseTest/equality/*.c', {public = true}, {cxflags = "-w"}) -- 一致性测试
     add_files('./test/externalModule/valloc/*.c', {public = true}, {cxflags = "-w"})   -- valloc,关闭警告
     add_files('./test/externalModule/tlsf/*.c', {public = true}, {cxflags = "-w"})     -- tlsf,关闭警告
     add_files('./test/externalModule/cJSON/*.c', {public = true}, {cxflags = "-w"}) -- 第三方库 cJSON,关闭警告