Code

data_test: Print type of datum in case of a test failure.
authorSebastian Harl <sh@tokkee.org>
Thu, 20 Feb 2014 20:57:04 +0000 (21:57 +0100)
committerSebastian Harl <sh@tokkee.org>
Thu, 20 Feb 2014 20:57:04 +0000 (21:57 +0100)
src/include/core/data.h
t/core/data_test.c

index 58e92cde59583dd7b114b163304223ecdb2f5d9c..c7c51b830c3761f91bb0ff55736a26087fb560e1 100644 (file)
@@ -46,6 +46,19 @@ enum {
        SDB_TYPE_BINARY,
 };
 
+#define SDB_TYPE_TO_STRING(t) \
+       (((t) == SDB_TYPE_INTEGER) \
+               ? "INTEGER" \
+               : ((t) == SDB_TYPE_DECIMAL) \
+                       ? "DECIMAL" \
+                       : ((t) == SDB_TYPE_STRING) \
+                               ? "STRING" \
+                               : ((t) == SDB_TYPE_DATETIME) \
+                                       ? "DATETIME" \
+                                       : ((t) == SDB_TYPE_BINARY) \
+                                               ? "BINARY" \
+                                               : "UNKNOWN")
+
 /*
  * sdb_data_t:
  * A datum retrieved from an arbitrary data source.
index 954201451b35c88bd9fbe29a4ba3f038edd635df..d6bd01459bc83019a9fee93f51c399933a24a919 100644 (file)
@@ -163,10 +163,12 @@ START_TEST(test_format)
 
                check = sdb_data_format(&golden_data[i].datum, buf);
                fail_unless(! check,
-                               "sdb_data_format() = %d; expected: 0", check);
+                               "sdb_data_format(type=%s) = %d; expected: 0",
+                               SDB_TYPE_TO_STRING(golden_data[i].datum.type), check);
                string = sdb_strbuf_string(buf);
                fail_unless(! strcmp(string, golden_data[i].expected),
-                               "sdb_data_format() used wrong format: %s; expected: %s",
+                               "sdb_data_format(type=%s) used wrong format: %s; expected: %s",
+                               SDB_TYPE_TO_STRING(golden_data[i].datum.type),
                                string, golden_data[i].expected);
                sdb_strbuf_clear(buf);
        }