summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 9ed08af)
raw | patch | inline | side by side (parent: 9ed08af)
author | Sebastian Harl <sh@tokkee.org> | |
Tue, 7 Oct 2014 19:30:32 +0000 (21:30 +0200) | ||
committer | Sebastian Harl <sh@tokkee.org> | |
Tue, 7 Oct 2014 19:30:32 +0000 (21:30 +0200) |
;-)
t/unit/core/data_test.c | patch | blob | history |
index 9d52d2279f2622fdf845999a9de5bc0a22fa3b0a..636fd13e7523dd403c1ed84f169d494ff0f2cdad 100644 (file)
--- a/t/unit/core/data_test.c
+++ b/t/unit/core/data_test.c
sdb_data_t d2;
int expected;
} golden_data[] = {
- /* same data as for the sdb_data_cmp test; in case the types match,
- * both functions should behave the same (except for some loss in
- * precision, e.g. when formatting datetime values) */
{
{ SDB_TYPE_INTEGER, { .integer = 47 } },
{ SDB_TYPE_INTEGER, { .integer = 4711 } },
1,
},
{
- { SDB_TYPE_DATETIME, { .datetime = 471047114711471100 } },
+ { SDB_TYPE_DATETIME, { .datetime = 471147114711471000 } },
{ SDB_TYPE_DATETIME, { .datetime = 471147114711471100 } },
-1,
},
},
{
{ SDB_TYPE_DATETIME, { .datetime = 471147114711471100 } },
- { SDB_TYPE_DATETIME, { .datetime = 471047114711471100 } },
+ { SDB_TYPE_DATETIME, { .datetime = 471147114711471000 } },
1,
},
{
},
1,
},
- /* type mismatches */
- {
- { SDB_TYPE_INTEGER, { .integer = 123 } },
- { SDB_TYPE_STRING, { .string = "123" } },
- 0,
- },
- {
- { SDB_TYPE_INTEGER, { .integer = 120 } },
- { SDB_TYPE_STRING, { .string = "123" } },
- -1,
- },
- {
- { SDB_TYPE_STRING, { .string = "123" } },
- { SDB_TYPE_INTEGER, { .integer = 120 } },
- 1,
- },
- {
- { SDB_TYPE_STRING, { .string = "12.3" } },
- { SDB_TYPE_DECIMAL, { .decimal = 12.3 } },
- 0,
- },
- {
- { SDB_TYPE_STRING, { .string = "12.0" } },
- { SDB_TYPE_DECIMAL, { .decimal = 12.3 } },
- -1,
- },
- {
- { SDB_TYPE_DECIMAL, { .decimal = 12.3 } },
- { SDB_TYPE_STRING, { .string = "12.0" } },
- 1,
- },
};
size_t i;
for (i = 0; i < SDB_STATIC_ARRAY_LEN(golden_data); ++i) {
- int check = sdb_data_strcmp(&golden_data[i].d1, &golden_data[i].d2);
+ int check = sdb_data_cmp(&golden_data[i].d1, &golden_data[i].d2);
check = check < 0 ? -1 : check > 0 ? 1 : 0;
if (check != golden_data[i].expected) {
char d1_str[64] = "", d2_str[64] = "";
SDB_DOUBLE_QUOTED);
sdb_data_format(&golden_data[i].d2, d2_str, sizeof(d2_str),
SDB_DOUBLE_QUOTED);
- fail("sdb_data_strcmp(%s, %s) = %d; expected: %d",
+ fail("sdb_data_cmp(%s, %s) = %d; expected: %d",
d1_str, d2_str, check, golden_data[i].expected);
}
}
sdb_data_t d2;
int expected;
} golden_data[] = {
+ /* same data as for the sdb_data_cmp test; in case the types match,
+ * both functions should behave the same (except for some loss in
+ * precision, e.g. when formatting datetime values) */
{
{ SDB_TYPE_INTEGER, { .integer = 47 } },
{ SDB_TYPE_INTEGER, { .integer = 4711 } },
1,
},
{
- { SDB_TYPE_DATETIME, { .datetime = 471147114711471000 } },
+ { SDB_TYPE_DATETIME, { .datetime = 471047114711471100 } },
{ SDB_TYPE_DATETIME, { .datetime = 471147114711471100 } },
-1,
},
},
{
{ SDB_TYPE_DATETIME, { .datetime = 471147114711471100 } },
- { SDB_TYPE_DATETIME, { .datetime = 471147114711471000 } },
+ { SDB_TYPE_DATETIME, { .datetime = 471047114711471100 } },
1,
},
{
},
1,
},
+ /* type mismatches */
+ {
+ { SDB_TYPE_INTEGER, { .integer = 123 } },
+ { SDB_TYPE_STRING, { .string = "123" } },
+ 0,
+ },
+ {
+ { SDB_TYPE_INTEGER, { .integer = 120 } },
+ { SDB_TYPE_STRING, { .string = "123" } },
+ -1,
+ },
+ {
+ { SDB_TYPE_STRING, { .string = "123" } },
+ { SDB_TYPE_INTEGER, { .integer = 120 } },
+ 1,
+ },
+ {
+ { SDB_TYPE_STRING, { .string = "12.3" } },
+ { SDB_TYPE_DECIMAL, { .decimal = 12.3 } },
+ 0,
+ },
+ {
+ { SDB_TYPE_STRING, { .string = "12.0" } },
+ { SDB_TYPE_DECIMAL, { .decimal = 12.3 } },
+ -1,
+ },
+ {
+ { SDB_TYPE_DECIMAL, { .decimal = 12.3 } },
+ { SDB_TYPE_STRING, { .string = "12.0" } },
+ 1,
+ },
};
size_t i;
for (i = 0; i < SDB_STATIC_ARRAY_LEN(golden_data); ++i) {
- int check = sdb_data_cmp(&golden_data[i].d1, &golden_data[i].d2);
+ int check = sdb_data_strcmp(&golden_data[i].d1, &golden_data[i].d2);
check = check < 0 ? -1 : check > 0 ? 1 : 0;
if (check != golden_data[i].expected) {
char d1_str[64] = "", d2_str[64] = "";
SDB_DOUBLE_QUOTED);
sdb_data_format(&golden_data[i].d2, d2_str, sizeof(d2_str),
SDB_DOUBLE_QUOTED);
- fail("sdb_data_cmp(%s, %s) = %d; expected: %d",
+ fail("sdb_data_strcmp(%s, %s) = %d; expected: %d",
d1_str, d2_str, check, golden_data[i].expected);
}
}