Beispiel #1
0
static cJSON *get_object_item(const cJSON * const object, const char* name, const cJSON_bool case_sensitive)
{
    if (case_sensitive)
    {
        return cJSON_GetObjectItemCaseSensitive(object, name);
    }

    return cJSON_GetObjectItem(object, name);
}
Beispiel #2
0
static void cjson_add_bool_should_add_bool(void)
{
    cJSON *root = cJSON_CreateObject();
    cJSON *true_item = NULL;
    cJSON *false_item = NULL;

    /* true */
    cJSON_AddBoolToObject(root, "true", true);
    TEST_ASSERT_NOT_NULL(true_item = cJSON_GetObjectItemCaseSensitive(root, "true"));
    TEST_ASSERT_EQUAL_INT(true_item->type, cJSON_True);

    /* false */
    cJSON_AddBoolToObject(root, "false", false);
    TEST_ASSERT_NOT_NULL(false_item = cJSON_GetObjectItemCaseSensitive(root, "false"));
    TEST_ASSERT_EQUAL_INT(false_item->type, cJSON_False);

    cJSON_Delete(root);
}
Beispiel #3
0
static void cJSON_add_array_should_add_array(void)
{
    cJSON *root = cJSON_CreateObject();
    cJSON *array = NULL;

    cJSON_AddArrayToObject(root, "array");
    TEST_ASSERT_NOT_NULL(array = cJSON_GetObjectItemCaseSensitive(root, "array"));
    TEST_ASSERT_EQUAL_INT(array->type, cJSON_Array);

    cJSON_Delete(root);
}
Beispiel #4
0
static void cJSON_add_object_should_add_object(void)
{
    cJSON *root = cJSON_CreateObject();
    cJSON *object = NULL;

    cJSON_AddObjectToObject(root, "object");
    TEST_ASSERT_NOT_NULL(object = cJSON_GetObjectItemCaseSensitive(root, "object"));
    TEST_ASSERT_EQUAL_INT(object->type, cJSON_Object);

    cJSON_Delete(root);
}
Beispiel #5
0
static void cjson_add_true_should_add_true(void)
{
    cJSON *root = cJSON_CreateObject();
    cJSON *true_item = NULL;

    cJSON_AddTrueToObject(root, "true");

    TEST_ASSERT_NOT_NULL(true_item = cJSON_GetObjectItemCaseSensitive(root, "true"));
    TEST_ASSERT_EQUAL_INT(true_item->type, cJSON_True);

    cJSON_Delete(root);
}
Beispiel #6
0
static void cjson_add_null_should_add_null(void)
{
    cJSON *root = cJSON_CreateObject();
    cJSON *null = NULL;

    cJSON_AddNullToObject(root, "null");

    TEST_ASSERT_NOT_NULL(null = cJSON_GetObjectItemCaseSensitive(root, "null"));
    TEST_ASSERT_EQUAL_INT(null->type, cJSON_NULL);

    cJSON_Delete(root);
}
Beispiel #7
0
static void cjson_add_false_should_add_false(void)
{
    cJSON *root = cJSON_CreateObject();
    cJSON *false_item = NULL;

    cJSON_AddFalseToObject(root, "false");

    TEST_ASSERT_NOT_NULL(false_item = cJSON_GetObjectItemCaseSensitive(root, "false"));
    TEST_ASSERT_EQUAL_INT(false_item->type, cJSON_False);

    cJSON_Delete(root);
}
Beispiel #8
0
static void cjson_add_raw_should_add_raw(void)
{
    cJSON *root = cJSON_CreateObject();
    cJSON *raw = NULL;

    cJSON_AddRawToObject(root, "raw", "{}");

    TEST_ASSERT_NOT_NULL(raw = cJSON_GetObjectItemCaseSensitive(root, "raw"));
    TEST_ASSERT_EQUAL_INT(raw->type, cJSON_Raw);
    TEST_ASSERT_EQUAL_STRING(raw->valuestring, "{}");

    cJSON_Delete(root);
}
Beispiel #9
0
static void cjson_add_string_should_add_string(void)
{
    cJSON *root = cJSON_CreateObject();
    cJSON *string = NULL;

    cJSON_AddStringToObject(root, "string", "Hello World!");

    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!");

    cJSON_Delete(root);
}
Beispiel #10
0
static void cjson_add_number_should_add_number(void)
{
    cJSON *root = cJSON_CreateObject();
    cJSON *number = NULL;

    cJSON_AddNumberToObject(root, "number", 42);

    TEST_ASSERT_NOT_NULL(number = cJSON_GetObjectItemCaseSensitive(root, "number"));

    TEST_ASSERT_EQUAL_INT(number->type, cJSON_Number);
    TEST_ASSERT_EQUAL_DOUBLE(number->valuedouble, 42);
    TEST_ASSERT_EQUAL_INT(number->valueint, 42);

    cJSON_Delete(root);
}
void
treasure_map_initialize_from_json_object(struct treasure_map *treasure_map,
                                         struct cJSON *json_object)
{
    treasure_map_initialize(treasure_map);

    if ( ! cJSON_IsObject(json_object)) return;
    if ( ! json_object_has_struct_member(json_object, "treasure_map")) return;

    treasure_map->is_false = json_object_get_bool_value(json_object, "is_false", false);

    struct cJSON *treasure = cJSON_GetObjectItemCaseSensitive(json_object, "treasure");
    treasure_initialize_from_json_object(&treasure_map->treasure, treasure);

    treasure_map->true_description = json_object_alloc_string_value(json_object, "true_description", NULL);
}