summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 1d75ab0)
raw | patch | inline | side by side (parent: 1d75ab0)
author | Sebastian Harl <sh@tokkee.org> | |
Wed, 1 Jan 2014 23:40:35 +0000 (00:40 +0100) | ||
committer | Sebastian Harl <sh@tokkee.org> | |
Wed, 1 Jan 2014 23:40:35 +0000 (00:40 +0100) |
This function creates a "simple" object without custom initialization and
destructor.
destructor.
src/core/object.c | patch | blob | history | |
src/include/core/object.h | patch | blob | history | |
t/core/object_test.c | patch | blob | history |
diff --git a/src/core/object.c b/src/core/object.c
index 43bb22a8fbf83ee39cb781beab8e34426f9505e9..bcefadbc9911570e837867213d843179a6579de8 100644 (file)
--- a/src/core/object.c
+++ b/src/core/object.c
return obj;
} /* sdb_object_create */
+sdb_object_t *
+sdb_object_create_simple(const char *name, size_t size)
+{
+ sdb_type_t t = { size, NULL, NULL };
+ return sdb_object_create(name, t);
+} /* sdb_object_create_simple */
+
sdb_object_t *
sdb_object_create_wrapper(const char *name,
void *data, void (*destructor)(void *))
index 9169c441383b292803a67efc35e91147528aa1e2..2f6470e01c8ee5350b75a7300029e88162b759a3 100644 (file)
sdb_object_t *
sdb_object_vcreate(const char *name, sdb_type_t type, va_list ap);
+/*
+ * sdb_object_create_simple:
+ * Create a "simple" object without custom initialization and destructor.
+ * See the description of sdb_object_create for more details.
+ */
+sdb_object_t *
+sdb_object_create_simple(const char *name, size_t size);
+
+/*
+ * sdb_object_create_T:
+ * Create a simple object of type 't'.
+ */
+#define sdb_object_create_T(n,t) sdb_object_create_simple((n), sizeof(t))
+
/*
* sdb_object_create_wrapper:
* Create a new sdb_object_t wrapping some arbitrary other object.
diff --git a/t/core/object_test.c b/t/core/object_test.c
index e00d300177b4694a5fd2b6d90a1ee9d9a3e72c84..b741b6cb6bb88b6f0b8e844cfc75c16207a20414 100644 (file)
--- a/t/core/object_test.c
+++ b/t/core/object_test.c
fail_unless(obj->type.size == test_type.size,
"after sdb_object_create(): type size mismatch; got: %zu; "
"expected: %zu", obj->type.size, test_type.size);
+ fail_unless(obj->type.init == obj_init_noop,
+ "after sdb_object_create(): type init = %p; exptected: %p",
+ obj->type.init, obj_init_noop);
+ fail_unless(obj->type.destroy == obj_destroy_noop,
+ "after sdb_object_create(): type destroy = %p; exptected: %p",
+ obj->type.destroy, obj_destroy_noop);
fail_unless(obj->ref_cnt == 1,
"after sdb_object_create(): obj->ref_cnt = %d; expected: 1",
obj->ref_cnt);
fail_unless(obj != NULL,
"sdb_object_create() fails without destroy callback");
sdb_object_deref(obj);
+
+ init_noop_called = 0;
+ obj = sdb_object_create_simple(name, sizeof(struct noop));
+ fail_unless(obj != NULL,
+ "sdb_object_create_simple() = NULL; expected: <obj>");
+ fail_unless(obj->type.size == sizeof(struct noop),
+ "sdb_object_create_simple() created object of size %zu; "
+ "expected: %zu", obj->type.size, sizeof(struct noop));
+ fail_unless(obj->type.init == NULL,
+ "sdb_object_create_simple() did not set init=NULL");
+ fail_unless(obj->type.destroy == NULL,
+ "sdb_object_create_simple() did not set destroy=NULL");
+ fail_unless(init_noop_called == 0,
+ "sdb_object_create_simple() unexpectedly called noop's init");
+ sdb_object_deref(obj);
+
+ obj = sdb_object_create_T(NULL, struct noop);
+ fail_unless(obj != NULL,
+ "sdb_object_create_simple() = NULL; expected: <obj>");
+ fail_unless(obj->type.size == sizeof(struct noop),
+ "sdb_object_create_simple() created object of size %zu; "
+ "expected: %zu", obj->type.size, sizeof(struct noop));
+ fail_unless(obj->type.init == NULL,
+ "sdb_object_create_simple() did not set init=NULL");
+ fail_unless(obj->type.destroy == NULL,
+ "sdb_object_create_simple() did not set destroy=NULL");
+ fail_unless(init_noop_called == 0,
+ "sdb_object_create_simple() unexpectedly called noop's init");
+ sdb_object_deref(obj);
}
END_TEST