Code

object: Added SDB_OBJECT_STATIC.
authorSebastian Harl <sh@tokkee.org>
Wed, 9 Jul 2014 19:36:49 +0000 (21:36 +0200)
committerSebastian Harl <sh@tokkee.org>
Wed, 9 Jul 2014 19:36:49 +0000 (21:36 +0200)
This is a helper to initialize static, named objects.

Replaced SSTRING_OBJ (which was basically the same) used by unit tests.

src/include/core/object.h
t/unit/libsysdb_test.h
t/unit/utils/avltree_test.c
t/unit/utils/llist_test.c

index a92fb53945676f65fbbada4bfe4f680d22427093..b91e9b88cebf815fe1dd6e22234c0140bb2d682f 100644 (file)
@@ -57,6 +57,10 @@ struct sdb_object {
 #define SDB_OBJECT_INIT { SDB_TYPE_INIT, 1, NULL }
 #define SDB_OBJECT_TYPED_INIT(t) { (t), 1, NULL }
 
+#define SDB_OBJECT_STATIC(name) { \
+       /* type */ { sizeof(sdb_object_t), NULL, NULL }, \
+       /* ref-cnt */ 1, (name) }
+
 typedef struct {
        sdb_object_t super;
        void *data;
index 861623f8916a1f5a2b99b31885de57a1964d8e2e..beefdfcd0dd5fad3cf42a5e997cf699580cbcf35 100644 (file)
 #include <check.h>
 #include <string.h>
 
-/*
- * private testing helpers
- */
-
-/* static string object:
- * Any such object may is of type sdb_object_t but may never be destroyed. */
-#define SSTRING_OBJ(name) { \
-       /* type = */ { sizeof(sdb_object_t), NULL, NULL }, \
-       /* ref_cnt = */ 1, /* name = */ (name) }
-
 /*
  * test-related data-types
  */
index f1ea1fc09fd27baa7aac336cd3b3ba5047b43bbb..0488693d112d139afb935b333ab79941318cb739 100644 (file)
@@ -49,21 +49,21 @@ teardown(void)
 
 /* 'a' thru 'o' */
 static sdb_object_t test_data[] = {
-       SSTRING_OBJ("h"),
-       SSTRING_OBJ("j"),
-       SSTRING_OBJ("i"),
-       SSTRING_OBJ("f"),
-       SSTRING_OBJ("e"),
-       SSTRING_OBJ("g"),
-       SSTRING_OBJ("k"),
-       SSTRING_OBJ("l"),
-       SSTRING_OBJ("m"),
-       SSTRING_OBJ("n"),
-       SSTRING_OBJ("o"),
-       SSTRING_OBJ("d"),
-       SSTRING_OBJ("c"),
-       SSTRING_OBJ("b"),
-       SSTRING_OBJ("a"),
+       SDB_OBJECT_STATIC("h"),
+       SDB_OBJECT_STATIC("j"),
+       SDB_OBJECT_STATIC("i"),
+       SDB_OBJECT_STATIC("f"),
+       SDB_OBJECT_STATIC("e"),
+       SDB_OBJECT_STATIC("g"),
+       SDB_OBJECT_STATIC("k"),
+       SDB_OBJECT_STATIC("l"),
+       SDB_OBJECT_STATIC("m"),
+       SDB_OBJECT_STATIC("n"),
+       SDB_OBJECT_STATIC("o"),
+       SDB_OBJECT_STATIC("d"),
+       SDB_OBJECT_STATIC("c"),
+       SDB_OBJECT_STATIC("b"),
+       SDB_OBJECT_STATIC("a"),
 };
 
 static void
@@ -76,7 +76,7 @@ populate(void)
 
 START_TEST(test_null)
 {
-       sdb_object_t o1 = SSTRING_OBJ("obj");
+       sdb_object_t o1 = SDB_OBJECT_STATIC("obj");
        sdb_object_t *o2;
        sdb_avltree_iter_t *iter;
        int check;
index 5ae771f5951bd1d82a1fb4cb67ac512d0d20a38f..71a6c8c9332a16564dd2518ac1b21069768d6cfb 100644 (file)
  */
 
 static sdb_object_t golden_data[] = {
-       SSTRING_OBJ("abc"),
-       SSTRING_OBJ("bcd"),
-       SSTRING_OBJ("cde"),
-       SSTRING_OBJ("def"),
-       SSTRING_OBJ("efg"),
-       SSTRING_OBJ("fgh"),
-       SSTRING_OBJ("ghi")
+       SDB_OBJECT_STATIC("abc"),
+       SDB_OBJECT_STATIC("bcd"),
+       SDB_OBJECT_STATIC("cde"),
+       SDB_OBJECT_STATIC("def"),
+       SDB_OBJECT_STATIC("efg"),
+       SDB_OBJECT_STATIC("fgh"),
+       SDB_OBJECT_STATIC("ghi")
 };
 
 static char *unused_names[] = {