From 8f5978b88a6b7c30bb1f952b8f48d2cb9ece8d36 Mon Sep 17 00:00:00 2001 From: "chuanjie.jian" Date: Thu, 29 Apr 2021 11:24:19 +0800 Subject: [PATCH] test: add substring test for cJSON_AddStringWithLengthToObject --- tests/cjson_add.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/cjson_add.c b/tests/cjson_add.c index fd20736..d04354e 100644 --- a/tests/cjson_add.c +++ b/tests/cjson_add.c @@ -320,12 +320,18 @@ static void cjson_add_string_with_length_should_add_string(void) cJSON *root = cJSON_CreateObject(); cJSON *string = NULL; + cJSON_AddStringWithLengthToObject(root, "string", "Hello World!", strlen("Hello World!")); + cJSON_AddStringWithLengthToObject(root, "substring", "Hello World!", strlen("Hello World!") - 7); TEST_ASSERT_NOT_NULL(string = cJSON_GetObjectItemCaseSensitive(root, "string")); TEST_ASSERT_EQUAL_INT(string->type, cJSON_String); TEST_ASSERT_EQUAL_STRING(string->valuestring, "Hello World!"); + TEST_ASSERT_NOT_NULL(string = cJSON_GetObjectItemCaseSensitive(root, "substring")); + TEST_ASSERT_EQUAL_INT(string->type, cJSON_String); + TEST_ASSERT_EQUAL_STRING(string->valuestring, "Hello"); + cJSON_Delete(root); }