RyanCW пре 1 година
родитељ
комит
5cae33f66b
2 измењених фајлова са 10 додато и 26 уклоњено
  1. 4 5
      RyanJsonExample/RFC8259JsonTest.c
  2. 6 21
      RyanJsonExample/RyanJsonTest.c

+ 4 - 5
RyanJsonExample/RFC8259JsonTest.c

@@ -14,7 +14,7 @@
 #include "yyjson.h"
 #include "valloc.h"
 
-// #define PrintfStrCmpEnable
+#define PrintfStrCmpEnable
 
 typedef int (*jsonParseData)(char *file_name, char *data, uint32_t len);
 
@@ -43,8 +43,6 @@ int testFile(const char *path, jsonParseData jsonParseDataHandle)
 
     DIR *dir = NULL;
     struct dirent *entry;
-    int idx = 0, alc = 0;
-    char **names = NULL, **names_tmp;
 
     int path_len = strlen(path);
     int count = 0;
@@ -107,8 +105,8 @@ int testFile(const char *path, jsonParseData jsonParseDataHandle)
         {
             free(data);
             printf("内存泄漏 %s len: %ld\r\n", data, len);
-            printf("内存泄漏 %x len: %ld\r\n", data, len);
-            printf("内存泄漏 %c len: %ld\r\n", data, len);
+            // printf("内存泄漏 %x len: %ld\r\n", (unsigned int)data, len);
+            // printf("内存泄漏 %c len: %ld\r\n", (int)data, len);
             printf("|||----------->>> area = %d, size = %d\r\n", area, use);
             break;
         }
@@ -164,6 +162,7 @@ int RyanJsonParseData(char *file_name, char *data, uint32_t len)
 
     RyanJsonDelete(json);
     return 0;
+
 err:
     RyanJsonDelete(json);
     return -1;

+ 6 - 21
RyanJsonExample/RyanJsonTest.c

@@ -17,12 +17,6 @@ static RyanJsonBool compare_double(double a, double b)
     return (fabs(a - b) <= maxVal * DBL_EPSILON);
 }
 
-static uint64_t start;
-uint64_t getClock()
-{
-    return clock();
-}
-
 static int rootNodeCheckTest(RyanJson_t json)
 {
     if (!RyanJsonIsInt(RyanJsonGetObjectToKey(json, "inter")) || 16 != RyanJsonGetIntValue(RyanJsonGetObjectToKey(json, "inter")))
@@ -391,8 +385,6 @@ int loadJsonTest()
 
 int createJsonTest()
 {
-
-    char *str = NULL;
     RyanJson_t jsonRoot, item;
 
     // 对象生成测试
@@ -502,7 +494,6 @@ int createJsonTest()
 int changeJsonTest()
 {
 
-    char *str = NULL;
     char jsonstr[] = "{\"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}]}";
 
     RyanJson_t json = RyanJsonParse(jsonstr);
@@ -626,8 +617,6 @@ err:
 
 int compareJsonTest()
 {
-
-    char *str = NULL;
     char jsonstr[] = "{\"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}]}";
     // char jsonstr[] = "{\"inter\":16,\"double\":16.89,\"string\":\"hello\",\"boolTrue\":true,\"boolFalse\":false,\"null\":null}";
 
@@ -860,13 +849,9 @@ err:
 
 int duplicateTest()
 {
-
-    char *str = NULL;
-    RyanJson_t json, item, dupItem;
+    RyanJson_t json, dupItem, jsonRoot = NULL;
     char jsonstr[] = "{\"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}]}";
 
-    // 内存泄漏测试
-
     /**
      * @brief 普通类型
      *
@@ -881,7 +866,7 @@ int duplicateTest()
 
     dupItem = RyanJsonDuplicate(RyanJsonGetObjectToKey(json, "inter"));
     RyanJsonAddItemToObject(json, "test", dupItem);
-    if (RyanJsonFalse == RyanJsonCompare(RyanJsonHasObjectByKey(json, "test"), RyanJsonHasObjectByKey(json, "inter")))
+    if (RyanJsonFalse == RyanJsonCompare(RyanJsonGetObjectToKey(json, "test", "inter"), RyanJsonGetObjectToKey(json, "inter")))
     {
         goto err;
     }
@@ -889,7 +874,7 @@ int duplicateTest()
 
     dupItem = RyanJsonDuplicate(RyanJsonGetObjectToKey(json, "inter"));
     RyanJsonAddItemToObject(json, "test", dupItem);
-    if (RyanJsonFalse == RyanJsonCompare(RyanJsonHasObjectByKey(json, "test"), RyanJsonHasObjectByKey(json, "inter")))
+    if (RyanJsonFalse == RyanJsonCompare(RyanJsonGetObjectToKey(json, "test", "inter"), RyanJsonGetObjectToKey(json, "inter")))
     {
         goto err;
     }
@@ -898,7 +883,7 @@ int duplicateTest()
     json = RyanJsonParse(jsonstr);
     dupItem = RyanJsonDuplicate(RyanJsonGetObjectToKey(json, "inter"));
     RyanJsonAddItemToObject(json, "test", dupItem);
-    if (RyanJsonFalse == RyanJsonCompare(RyanJsonHasObjectByKey(json, "test"), RyanJsonHasObjectByKey(json, "inter")))
+    if (RyanJsonFalse == RyanJsonCompare(RyanJsonGetObjectToKey(json, "test", "inter"), RyanJsonGetObjectToKey(json, "inter")))
     {
         goto err;
     }
@@ -982,7 +967,7 @@ int duplicateTest()
     RyanJsonDelete(json);
 
     json = RyanJsonParse(jsonstr);
-    RyanJson_t jsonRoot = RyanJsonCreateObject();
+    jsonRoot = RyanJsonCreateObject();
     RyanJsonAddBoolToObject(jsonRoot, "arrayItem", RyanJsonTrue);
     int use = 0;
     for (uint8_t i = 0; i < 10; i++)
@@ -1083,7 +1068,7 @@ int forEachTest()
         }
     }
 
-    int strLen;
+    uint32_t strLen;
     RyanJsonObjectForEach(RyanJsonGetObjectToKey(json, "item"), item)
     {
         str = RyanJsonPrint(item, 50, RyanJsonTrue, &strLen);