From: Sebastian Harl Date: Wed, 12 Nov 2014 21:59:03 +0000 (+0100) Subject: data: Let concat support empty arrays; add various tests for empty arrays. X-Git-Tag: sysdb-0.6.0~4 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=d0ca7dd7178ff194a2510115702f69b1c6f66786;p=sysdb.git data: Let concat support empty arrays; add various tests for empty arrays. --- diff --git a/src/core/data.c b/src/core/data.c index 88c7f82..3186aa2 100644 --- a/src/core/data.c +++ b/src/core/data.c @@ -390,8 +390,6 @@ data_concat(const sdb_data_t *d1, const sdb_data_t *d2, sdb_data_t *res) else return -1; - assert(s1 && s2); - new = malloc(len1 + len2 + 1); if (! new) return -1; diff --git a/t/unit/core/data_test.c b/t/unit/core/data_test.c index 956cf31..a848756 100644 --- a/t/unit/core/data_test.c +++ b/t/unit/core/data_test.c @@ -405,6 +405,27 @@ START_TEST(test_cmp) { SDB_TYPE_REGEX, { .re = { "a", empty_re } } }, 1, }, + { + { SDB_TYPE_ARRAY | SDB_TYPE_INTEGER, { .array = { 0, NULL } } }, + { SDB_TYPE_ARRAY | SDB_TYPE_INTEGER, { .array = { 0, NULL } } }, + 0, + }, + { + { SDB_TYPE_ARRAY | SDB_TYPE_INTEGER, { .array = { 0, NULL } } }, + { + SDB_TYPE_ARRAY | SDB_TYPE_INTEGER, + { .array = { SDB_STATIC_ARRAY_LEN(int_values1), int_values1 } }, + }, + -1, + }, + { + { + SDB_TYPE_ARRAY | SDB_TYPE_INTEGER, + { .array = { SDB_STATIC_ARRAY_LEN(int_values1), int_values1 } }, + }, + { SDB_TYPE_ARRAY | SDB_TYPE_INTEGER, { .array = { 0, NULL } } }, + 1, + }, { { SDB_TYPE_ARRAY | SDB_TYPE_INTEGER, @@ -438,6 +459,27 @@ START_TEST(test_cmp) }, 1, }, + { + { SDB_TYPE_ARRAY | SDB_TYPE_STRING, { .array = { 0, NULL } } }, + { SDB_TYPE_ARRAY | SDB_TYPE_STRING, { .array = { 0, NULL } } }, + 0, + }, + { + { SDB_TYPE_ARRAY | SDB_TYPE_STRING, { .array = { 0, NULL } } }, + { + SDB_TYPE_ARRAY | SDB_TYPE_STRING, + { .array = { SDB_STATIC_ARRAY_LEN(string_values1), string_values1 } }, + }, + -1, + }, + { + { + SDB_TYPE_ARRAY | SDB_TYPE_STRING, + { .array = { SDB_STATIC_ARRAY_LEN(string_values1), string_values1 } }, + }, + { SDB_TYPE_ARRAY | SDB_TYPE_STRING, { .array = { 0, NULL } } }, + 1, + }, { { SDB_TYPE_ARRAY | SDB_TYPE_STRING, @@ -707,6 +749,7 @@ START_TEST(test_strcmp) { SDB_TYPE_STRING, { .string = "/regex/" } }, 0, }, + /* TODO: add support for arrays */ }; size_t i; @@ -817,6 +860,30 @@ START_TEST(test_inarray) { string_array3, string_array, 0 }, { int_array2, string_array, 0 }, { dec_array2, string_array, 0 }, + { + { SDB_TYPE_INTEGER | SDB_TYPE_ARRAY, { .array = { 0, NULL } } }, + int_array, 1, + }, + { + { SDB_TYPE_INTEGER | SDB_TYPE_ARRAY, { .array = { 0, NULL } } }, + dec_array, 0, + }, + { + { SDB_TYPE_DECIMAL | SDB_TYPE_ARRAY, { .array = { 0, NULL } } }, + dec_array, 1, + }, + { + { SDB_TYPE_DECIMAL | SDB_TYPE_ARRAY, { .array = { 0, NULL } } }, + int_array, 0, + }, + { + { SDB_TYPE_STRING | SDB_TYPE_ARRAY, { .array = { 0, NULL } } }, + string_array, 1, + }, + { + { SDB_TYPE_STRING | SDB_TYPE_ARRAY, { .array = { 0, NULL } } }, + dec_array, 0, + }, }; size_t i; @@ -877,6 +944,18 @@ START_TEST(test_array_get) { string_array, 4, { -1, { .integer = 0 } } }, { { SDB_TYPE_INTEGER, { .integer = 666 } }, 0, { -1, { .integer = 0 } } }, { { SDB_TYPE_INTEGER, { .integer = 666 } }, 1, { -1, { .integer = 0 } } }, + { + { SDB_TYPE_ARRAY | SDB_TYPE_INTEGER, { .array = { 0, NULL } } }, + 0, { -1, { .integer = 0 } }, + }, + { + { SDB_TYPE_ARRAY | SDB_TYPE_DECIMAL, { .array = { 0, NULL } } }, + 0, { -1, { .integer = 0 } }, + }, + { + { SDB_TYPE_ARRAY | SDB_TYPE_STRING, { .array = { 0, NULL } } }, + 0, { -1, { .integer = 0 } }, + }, }; size_t i; @@ -1223,6 +1302,70 @@ START_TEST(test_expr_eval) } }, }, }, + { + { SDB_TYPE_INTEGER | SDB_TYPE_ARRAY, { .array = { 0, NULL } } }, + { + SDB_TYPE_INTEGER | SDB_TYPE_ARRAY, + { .array = { SDB_STATIC_ARRAY_LEN(int_values), int_values } }, + }, + err, + err, + err, + err, + err, + { + SDB_TYPE_INTEGER | SDB_TYPE_ARRAY, + { .array = { SDB_STATIC_ARRAY_LEN(int_values), int_values } }, + }, + }, + { + { + SDB_TYPE_INTEGER | SDB_TYPE_ARRAY, + { .array = { SDB_STATIC_ARRAY_LEN(int_values), int_values } }, + }, + { SDB_TYPE_INTEGER | SDB_TYPE_ARRAY, { .array = { 0, NULL } } }, + err, + err, + err, + err, + err, + { + SDB_TYPE_INTEGER | SDB_TYPE_ARRAY, + { .array = { SDB_STATIC_ARRAY_LEN(int_values), int_values } }, + }, + }, + { + { SDB_TYPE_STRING | SDB_TYPE_ARRAY, { .array = { 0, NULL } } }, + { + SDB_TYPE_STRING | SDB_TYPE_ARRAY, + { .array = { SDB_STATIC_ARRAY_LEN(string_values), string_values } }, + }, + err, + err, + err, + err, + err, + { + SDB_TYPE_STRING | SDB_TYPE_ARRAY, + { .array = { SDB_STATIC_ARRAY_LEN(string_values), string_values } }, + }, + }, + { + { + SDB_TYPE_STRING | SDB_TYPE_ARRAY, + { .array = { SDB_STATIC_ARRAY_LEN(string_values), string_values } }, + }, + { SDB_TYPE_STRING | SDB_TYPE_ARRAY, { .array = { 0, NULL } } }, + err, + err, + err, + err, + err, + { + SDB_TYPE_STRING | SDB_TYPE_ARRAY, + { .array = { SDB_STATIC_ARRAY_LEN(string_values), string_values } }, + }, + }, { { SDB_TYPE_NULL, { .integer = 0 } }, { SDB_TYPE_NULL, { .integer = 0 } }, @@ -1765,6 +1908,10 @@ START_TEST(test_format) { SDB_TYPE_REGEX, { .re = { "some regex", empty_re } } }, "\"/some regex/\"", }, + { + { SDB_TYPE_INTEGER | SDB_TYPE_ARRAY, { .array = { 0, NULL } } }, + "[]", + }, { { SDB_TYPE_INTEGER | SDB_TYPE_ARRAY,