예제 #1
0
파일: tests.c 프로젝트: Kutoc/parson
void test_suite_8(void) {
    const char *filename = "tests/test_2.txt";
    const char *temp_filename = "tests/test_2_serialized.txt";
    JSON_Value *a = NULL;
    JSON_Value *b = NULL;
    a = json_parse_file(filename);
    TEST(json_serialize_to_file(a, temp_filename) == JSONSuccess);
    b = json_parse_file(temp_filename);
    TEST(json_value_equals(a, b));
    remove(temp_filename);
}
예제 #2
0
파일: tests.c 프로젝트: xiaodezhang/cgi
void test_suite_8(void) {
	const char *filename = "tests/test_2.txt";
	const char *temp_filename = "tests/test_2_serialized.txt";
	JSON_Value *a = NULL;
	JSON_Value *b = NULL;
	char *buf = NULL;
	size_t serialization_size = 0;
	a = json_parse_file(filename);
	TEST(json_serialize_to_file(a, temp_filename) == JSONSuccess);
	b = json_parse_file(temp_filename);
	TEST(json_value_equals(a, b));
	remove(temp_filename);
	serialization_size = json_serialization_size(a);
	buf = json_serialize_to_string(a);
	TEST((strlen(buf) + 1) == serialization_size);
}
예제 #3
0
파일: tests.c 프로젝트: Kutoc/parson
void persistence_example(void) {
    JSON_Value *schema = json_parse_string("{\"name\":\"\"}");
    JSON_Value *user_data = json_parse_file("user_data.json");
    char buf[256];
    const char *name = NULL;
    if (user_data == NULL || json_validate(schema, user_data) != JSONSuccess) {
        puts("Enter your name:");
        scanf("%s", buf);
        user_data = json_value_init_object();
        json_object_set_string(json_object(user_data), "name", buf);
        json_serialize_to_file(user_data, "user_data.json");
    }
    name = json_object_get_string(json_object(user_data), "name");
    printf("Hello, %s.", name);
    json_value_free(schema);
    json_value_free(user_data);
    return;
}