index a848756a185385ae1431fb43c9119fc855bfe181..71dae2acbb65f673d011d935e562eba65243a495 100644 (file)
--- a/t/unit/core/data_test.c
+++ b/t/unit/core/data_test.c
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+#if HAVE_CONFIG_H
+# include "config.h"
+#endif
+
#include "core/data.h"
-#include "libsysdb_test.h"
+#include "testutils.h"
#include <assert.h>
#include <check.h>
START_TEST(test_cmp)
{
+ regex_t dummy_re;
int64_t int_values1[] = { 1, 2, 3 };
int64_t int_values2[] = { 1, 3, 2 };
+ double dec_values1[] = { 12.34, 47.11 };
+ double dec_values2[] = { 47.11, 12.34 };
char *string_values1[] = { "a", "b", "c" };
char *string_values2[] = { "a", "c", "b" };
+ sdb_time_t dt_values1[] = { 4711, 1234567890123456789L };
+ sdb_time_t dt_values2[] = { 1234567890123456789L, 4711 };
+ struct {
+ size_t length;
+ unsigned char *datum;
+ } bin_values1[] = {
+ { 3, (unsigned char *)"\x1\x2\x3" },
+ { 4, (unsigned char *)"\x42\x0\xa\x1b" },
+ };
+ struct {
+ size_t length;
+ unsigned char *datum;
+ } bin_values2[] = {
+ { 4, (unsigned char *)"\x42\x0\xa\x1b" },
+ { 3, (unsigned char *)"\x1\x2\x3" },
+ };
+ struct {
+ char *raw;
+ regex_t regex;
+ } re_values1[] = {
+ { "dummy regex A", dummy_re },
+ };
+ struct {
+ char *raw;
+ regex_t regex;
+ } re_values2[] = {
+ { "dummy regex B", dummy_re },
+ };
struct {
sdb_data_t d1;
},
1,
},
+ {
+ {
+ SDB_TYPE_ARRAY | SDB_TYPE_DECIMAL,
+ { .array = { SDB_STATIC_ARRAY_LEN(dec_values1), dec_values1 } },
+ },
+ {
+ SDB_TYPE_ARRAY | SDB_TYPE_DECIMAL,
+ { .array = { SDB_STATIC_ARRAY_LEN(dec_values1), dec_values1 } },
+ },
+ 0,
+ },
+ {
+ {
+ SDB_TYPE_ARRAY | SDB_TYPE_DECIMAL,
+ { .array = { SDB_STATIC_ARRAY_LEN(dec_values1), dec_values1 } },
+ },
+ {
+ SDB_TYPE_ARRAY | SDB_TYPE_DECIMAL,
+ { .array = { SDB_STATIC_ARRAY_LEN(dec_values2), dec_values2 } },
+ },
+ -1,
+ },
+ {
+ {
+ SDB_TYPE_ARRAY | SDB_TYPE_DECIMAL,
+ { .array = { SDB_STATIC_ARRAY_LEN(dec_values2), dec_values2 } },
+ },
+ {
+ SDB_TYPE_ARRAY | SDB_TYPE_DECIMAL,
+ { .array = { SDB_STATIC_ARRAY_LEN(dec_values1), dec_values1 } },
+ },
+ 1,
+ },
{
{ SDB_TYPE_ARRAY | SDB_TYPE_STRING, { .array = { 0, NULL } } },
{ SDB_TYPE_ARRAY | SDB_TYPE_STRING, { .array = { 0, NULL } } },
},
1,
},
+ {
+ {
+ SDB_TYPE_ARRAY | SDB_TYPE_DATETIME,
+ { .array = { SDB_STATIC_ARRAY_LEN(dt_values1), dt_values1 } },
+ },
+ {
+ SDB_TYPE_ARRAY | SDB_TYPE_DATETIME,
+ { .array = { SDB_STATIC_ARRAY_LEN(dt_values1), dt_values1 } },
+ },
+ 0,
+ },
+ {
+ {
+ SDB_TYPE_ARRAY | SDB_TYPE_DATETIME,
+ { .array = { SDB_STATIC_ARRAY_LEN(dt_values1), dt_values1 } },
+ },
+ {
+ SDB_TYPE_ARRAY | SDB_TYPE_DATETIME,
+ { .array = { SDB_STATIC_ARRAY_LEN(dt_values2), dt_values2 } },
+ },
+ -1,
+ },
+ {
+ {
+ SDB_TYPE_ARRAY | SDB_TYPE_DATETIME,
+ { .array = { SDB_STATIC_ARRAY_LEN(dt_values2), dt_values2 } },
+ },
+ {
+ SDB_TYPE_ARRAY | SDB_TYPE_DATETIME,
+ { .array = { SDB_STATIC_ARRAY_LEN(dt_values1), dt_values1 } },
+ },
+ 1,
+ },
+ {
+ {
+ SDB_TYPE_ARRAY | SDB_TYPE_BINARY,
+ { .array = { SDB_STATIC_ARRAY_LEN(bin_values1), bin_values1 } },
+ },
+ {
+ SDB_TYPE_ARRAY | SDB_TYPE_BINARY,
+ { .array = { SDB_STATIC_ARRAY_LEN(bin_values1), bin_values1 } },
+ },
+ 0,
+ },
+ {
+ {
+ SDB_TYPE_ARRAY | SDB_TYPE_BINARY,
+ { .array = { SDB_STATIC_ARRAY_LEN(bin_values1), bin_values1 } },
+ },
+ {
+ SDB_TYPE_ARRAY | SDB_TYPE_BINARY,
+ { .array = { SDB_STATIC_ARRAY_LEN(bin_values2), bin_values2 } },
+ },
+ -1,
+ },
+ {
+ {
+ SDB_TYPE_ARRAY | SDB_TYPE_BINARY,
+ { .array = { SDB_STATIC_ARRAY_LEN(bin_values2), bin_values2 } },
+ },
+ {
+ SDB_TYPE_ARRAY | SDB_TYPE_BINARY,
+ { .array = { SDB_STATIC_ARRAY_LEN(bin_values1), bin_values1 } },
+ },
+ 1,
+ },
+ {
+ {
+ SDB_TYPE_ARRAY | SDB_TYPE_REGEX,
+ { .array = { SDB_STATIC_ARRAY_LEN(re_values1), re_values1 } },
+ },
+ {
+ SDB_TYPE_ARRAY | SDB_TYPE_REGEX,
+ { .array = { SDB_STATIC_ARRAY_LEN(re_values1), re_values1 } },
+ },
+ 0,
+ },
+ {
+ {
+ SDB_TYPE_ARRAY | SDB_TYPE_REGEX,
+ { .array = { SDB_STATIC_ARRAY_LEN(re_values1), re_values1 } },
+ },
+ {
+ SDB_TYPE_ARRAY | SDB_TYPE_REGEX,
+ { .array = { SDB_STATIC_ARRAY_LEN(re_values2), re_values2 } },
+ },
+ -1,
+ },
+ {
+ {
+ SDB_TYPE_ARRAY | SDB_TYPE_REGEX,
+ { .array = { SDB_STATIC_ARRAY_LEN(re_values2), re_values2 } },
+ },
+ {
+ SDB_TYPE_ARRAY | SDB_TYPE_REGEX,
+ { .array = { SDB_STATIC_ARRAY_LEN(re_values1), re_values1 } },
+ },
+ 1,
+ },
};
size_t i;
golden_data[i].input, type);
if (type == SDB_TYPE_STRING)
- fail_unless(golden_data[i].input == result.data.string,
- "sdb_data_parse(%s, %d, <d>) modified input string",
+ fail_unless(golden_data[i].input != result.data.string,
+ "sdb_data_parse(%s, %d, <d>) copied input string",
golden_data[i].input, type);
if (type == SDB_TYPE_BINARY)
- fail_unless(golden_data[i].input == (char *)result.data.binary.datum,
- "sdb_data_parse(%s, %d, <d>) modified input string",
+ fail_unless(golden_data[i].input != (char *)result.data.binary.datum,
+ "sdb_data_parse(%s, %d, <d>) copied input string",
golden_data[i].input, type);
- if (type == SDB_TYPE_REGEX) {
+ if (type == SDB_TYPE_REGEX)
fail_unless(golden_data[i].input != result.data.re.raw,
"sdb_data_parse(%s, %d, <d>) copied input string",
golden_data[i].input, type);
- sdb_data_free_datum(&result);
- }
+ sdb_data_free_datum(&result);
}
}
END_TEST
-Suite *
-core_data_suite(void)
+TEST_MAIN("core::data")
{
- Suite *s = suite_create("core::data");
- TCase *tc;
-
- tc = tcase_create("core");
+ TCase *tc = tcase_create("core");
tcase_add_test(tc, test_data);
tcase_add_test(tc, test_cmp);
tcase_add_test(tc, test_strcmp);
tcase_add_test(tc, test_expr_eval);
tcase_add_test(tc, test_format);
tcase_add_test(tc, test_parse);
- suite_add_tcase(s, tc);
-
- return s;
-} /* core_data_suite */
+ ADD_TCASE(tc);
+}
+TEST_MAIN_END
/* vim: set tw=78 sw=4 ts=4 noexpandtab : */