diff --git a/t/core/data_test.c b/t/core/data_test.c
index 7efa5549fed5e8a780cc8fe4080d19ca7630f526..649a7df4bece545e9689953ec31ea39e52f55018 100644 (file)
--- a/t/core/data_test.c
+++ b/t/core/data_test.c
}
END_TEST
}
END_TEST
+START_TEST(test_format)
+{
+ sdb_data_t datum;
+ sdb_strbuf_t *buf;
+ const char *string;
+ const char *expected;
+
+ int check;
+
+ buf = sdb_strbuf_create(1024);
+ fail_unless(buf != NULL,
+ "INTERNAL ERROR: Failed to allocate string buffer");
+
+ datum.type = SDB_TYPE_INTEGER;
+ datum.data.integer = 4711;
+ check = sdb_data_format(&datum, buf);
+ fail_unless(! check,
+ "sdb_data_format(INTEGER) = %d; expected: 0", check);
+ string = sdb_strbuf_string(buf);
+ expected = "4711";
+ fail_unless(! strcmp(string, expected),
+ "sdb_data_format() used wrong format: %s; expected: %s",
+ string, expected);
+
+ datum.type = SDB_TYPE_DECIMAL;
+ datum.data.decimal = 65536.0;
+ sdb_strbuf_clear(buf);
+ check = sdb_data_format(&datum, buf);
+ fail_unless(! check,
+ "sdb_data_format(DECIMAL) = %d; expected: 0", check);
+ string = sdb_strbuf_string(buf);
+ expected = "0x1p+16";
+ fail_unless(! strcmp(string, expected),
+ "sdb_data_format() used wrong format: %s; expected: %s",
+ string, expected);
+
+ datum.type = SDB_TYPE_STRING;
+ datum.data.string = "this is a test";
+ sdb_strbuf_clear(buf);
+ check = sdb_data_format(&datum, buf);
+ fail_unless(! check,
+ "sdb_data_format(STRING) = %d; expected: 0", check);
+ string = sdb_strbuf_string(buf);
+ expected = "\"this is a test\"";
+ fail_unless(! strcmp(string, expected),
+ "sdb_data_format() used wrong format: %s; expected: %s",
+ string, expected);
+
+ datum.data.string = "now using special \\ \" characters";
+ sdb_strbuf_clear(buf);
+ check = sdb_data_format(&datum, buf);
+ fail_unless(! check,
+ "sdb_data_format(STRING) = %d; expected: 0", check);
+ string = sdb_strbuf_string(buf);
+ expected = "\"now using special \\\\ \\\" characters\"";
+ fail_unless(! strcmp(string, expected),
+ "sdb_data_format() used wrong format: %s; expected: %s",
+ string, expected);
+
+ datum.data.string = NULL;
+ sdb_strbuf_clear(buf);
+ check = sdb_data_format(&datum, buf);
+ fail_unless(! check,
+ "sdb_data_format(STRING) = %d; expected: 0", check);
+ string = sdb_strbuf_string(buf);
+ expected = "\"NULL\"";
+ fail_unless(! strcmp(string, expected),
+ "sdb_data_format() used wrong format: %s; expected: %s",
+ string, expected);
+
+ datum.type = SDB_TYPE_DATETIME;
+ datum.data.datetime = 471147114711471100;
+ sdb_strbuf_clear(buf);
+ check = sdb_data_format(&datum, buf);
+ fail_unless(! check,
+ "sdb_data_format(DATETIME) = %d; expected: 0", check);
+ string = sdb_strbuf_string(buf);
+ expected = "\"1984-12-06 02:11:54 +0000\"";
+ fail_unless(! strcmp(string, expected),
+ "sdb_data_format() used wrong format: %s; expected: %s",
+ string, expected);
+
+ datum.type = SDB_TYPE_BINARY;
+ datum.data.binary.datum = (unsigned char *)"binary\0crap\x42";
+ datum.data.binary.length = 12;
+ sdb_strbuf_clear(buf);
+ check = sdb_data_format(&datum, buf);
+ fail_unless(! check,
+ "sdb_data_format(BINARY) = %d; expected: 0", check);
+ string = sdb_strbuf_string(buf);
+ expected =
+ "\"\\x62\\x69\\x6e\\x61\\x72\\x79\\x0\\x63\\x72\\x61\\x70\\x42\"";
+ fail_unless(! strcmp(string, expected),
+ "sdb_data_format() used wrong format: %s; expected: %s",
+ string, expected);
+
+ datum.data.binary.datum = NULL;
+ datum.data.binary.length = 0;
+ sdb_strbuf_clear(buf);
+ check = sdb_data_format(&datum, buf);
+ fail_unless(! check,
+ "sdb_data_format(BINARY) = %d; expected: 0", check);
+ string = sdb_strbuf_string(buf);
+ expected = "\"\"";
+ fail_unless(! strcmp(string, expected),
+ "sdb_data_format() used wrong format: %s; expected: %s",
+ string, expected);
+}
+END_TEST
+
Suite *
core_data_suite(void)
{
Suite *
core_data_suite(void)
{
tc = tcase_create("core");
tcase_add_test(tc, test_data);
tc = tcase_create("core");
tcase_add_test(tc, test_data);
+ tcase_add_test(tc, test_format);
suite_add_tcase(s, tc);
return s;
suite_add_tcase(s, tc);
return s;