mirror of
https://gitee.com/Lyon1998/pikapython.git
synced 2025-01-29 17:22:56 +08:00
construct cjson is test ok
This commit is contained in:
parent
84a528bc19
commit
607591d78c
@ -218,6 +218,7 @@ void pika_cjson_cJSON_addItemToArray(PikaObj* self, PikaObj* item) {
|
||||
cJSON* self_item = obj_getPtr(self, "item");
|
||||
cJSON* item_item = obj_getPtr(item, "item");
|
||||
cJSON_AddItemToArray(self_item, item_item);
|
||||
obj_setInt(item, "needfree", 0);
|
||||
}
|
||||
|
||||
void pika_cjson_cJSON_addItemToObject(PikaObj* self,
|
||||
@ -226,4 +227,5 @@ void pika_cjson_cJSON_addItemToObject(PikaObj* self,
|
||||
cJSON* self_item = obj_getPtr(self, "item");
|
||||
cJSON* item_item = obj_getPtr(item, "item");
|
||||
cJSON_AddItemToObject(self_item, string, item_item);
|
||||
obj_setInt(item, "needfree", 0);
|
||||
}
|
||||
|
@ -9,6 +9,9 @@ class BaseObj(TinyObj):
|
||||
class pointer:
|
||||
pass
|
||||
|
||||
class any:
|
||||
pass
|
||||
|
||||
def print(val: any):
|
||||
pass
|
||||
|
||||
|
@ -218,6 +218,7 @@ void pika_cjson_cJSON_addItemToArray(PikaObj* self, PikaObj* item) {
|
||||
cJSON* self_item = obj_getPtr(self, "item");
|
||||
cJSON* item_item = obj_getPtr(item, "item");
|
||||
cJSON_AddItemToArray(self_item, item_item);
|
||||
obj_setInt(item, "needfree", 0);
|
||||
}
|
||||
|
||||
void pika_cjson_cJSON_addItemToObject(PikaObj* self,
|
||||
@ -226,4 +227,5 @@ void pika_cjson_cJSON_addItemToObject(PikaObj* self,
|
||||
cJSON* self_item = obj_getPtr(self, "item");
|
||||
cJSON* item_item = obj_getPtr(item, "item");
|
||||
cJSON_AddItemToObject(self_item, string, item_item);
|
||||
obj_setInt(item, "needfree", 0);
|
||||
}
|
||||
|
@ -204,3 +204,41 @@ TEST(cJSON, item) {
|
||||
obj_deinit(pikaMain);
|
||||
EXPECT_EQ(pikaMemNow(), 0);
|
||||
}
|
||||
|
||||
TEST(cJSON, construct) {
|
||||
/* init */
|
||||
pikaMemInfo.heapUsedMax = 0;
|
||||
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
|
||||
/* run */
|
||||
__platform_printf("BEGIN\r\n");
|
||||
obj_run(pikaMain,
|
||||
"import pika_cjson as cjson\n"
|
||||
"root = cjson.Object()\n"
|
||||
"root.addItemToObject('name', cjson.String('mculover666'))\n"
|
||||
"root.addItemToObject('age', cjson.Number(22))\n"
|
||||
"root.addItemToObject('weight', cjson.Number(55.5))\n"
|
||||
"address = cjson.Object()\n"
|
||||
"address.addItemToObject('country', cjson.String('China'))\n"
|
||||
"address.addItemToObject('zip-code', cjson.String('111111'))\n"
|
||||
"root.addItemToObject('address', address)\n"
|
||||
"skill = cjson.Array()\n"
|
||||
"skill.addItemToArray(cjson.String('c'))\n"
|
||||
"skill.addItemToArray(cjson.String('Java'))\n"
|
||||
"skill.addItemToArray(cjson.String('Python'))\n"
|
||||
"root.addItemToObject('skill', skill)\n"
|
||||
"root.addItemToObject('student', cjson.False_())\n"
|
||||
"root.print()\n");
|
||||
/* collect */
|
||||
/* assert */
|
||||
EXPECT_STREQ(
|
||||
log_buff[0],
|
||||
"{\n\t\"name\":\t\"mculover666\",\n\t\"age\":\t22,\n\t\"weight\":\t55."
|
||||
"5,\n\t\"address\":\t{\n\t\t\"country\":\t\"China\",\n\t\t\"zip-code\":"
|
||||
"\t\"111111\"\n\t},\n\t\"skill\":\t[\"c\", \"Java\", "
|
||||
"\"Python\"],\n\t\"student\":\tfalse\n}\r\n");
|
||||
EXPECT_STREQ(log_buff[1], "BEGIN\r\n");
|
||||
/* deinit */
|
||||
obj_deinit(pikaMain);
|
||||
|
||||
EXPECT_EQ(pikaMemNow(), 0);
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
#define LOG_BUFF_MAX 100
|
||||
#define LOG_SIZE 128
|
||||
#define LOG_SIZE 512
|
||||
|
||||
void mem_pool_init(void);
|
||||
void mem_pool_deinit(void);
|
Loading…
x
Reference in New Issue
Block a user