Add a test for ds_allocator 45/296045/1
authorSeunghun Lee <shiin.lee@samsung.com>
Tue, 18 Jul 2023 04:38:43 +0000 (13:38 +0900)
committerTizen Window System <tizen.windowsystem@gmail.com>
Wed, 19 Jul 2023 00:28:27 +0000 (09:28 +0900)
Change-Id: I262bdd0ca20da7b6748e58aa37c9cb4c1621663f

tests/allocator-test.c [new file with mode: 0644]
tests/meson.build

diff --git a/tests/allocator-test.c b/tests/allocator-test.c
new file mode 100644 (file)
index 0000000..9f8a14c
--- /dev/null
@@ -0,0 +1,65 @@
+#include <assert.h>
+#include <stdbool.h>
+#include <stdlib.h>
+
+#include <drm_fourcc.h>
+#include <libds/allocator/shm.h>
+
+static void
+test_allocator_create(void)
+{
+    struct ds_allocator *alloc = ds_shm_allocator_create();
+    assert(alloc);
+
+    ds_allocator_destroy(alloc);
+}
+
+struct test_data {
+    struct wl_listener destroy;
+    bool called;
+};
+
+static void
+handle_allocator_destroy(struct wl_listener *listener, void *d)
+{
+    struct test_data *data;
+
+    data = wl_container_of(listener, data, destroy);
+    data->called = true;
+}
+
+static void
+test_allocator_events_destroy(void)
+{
+    struct ds_allocator *alloc = ds_shm_allocator_create();
+    assert(alloc);
+
+    struct test_data data = {0, };
+    data.destroy.notify = handle_allocator_destroy;
+    ds_allocator_add_destroy_listener(alloc, &data.destroy);
+
+    ds_allocator_destroy(alloc);
+    assert(data.called == true);
+}
+
+static void
+test_allocator_create_buffer()
+{
+    struct ds_allocator *alloc = ds_shm_allocator_create();
+    assert(alloc);
+
+    struct ds_buffer *buffer = ds_allocator_create_buffer(alloc, 123, 456, DRM_FORMAT_ARGB8888);
+    assert(buffer);
+
+    ds_buffer_drop(buffer);
+    ds_allocator_destroy(alloc);
+}
+
+int
+main(int argc, char *argv[])
+{
+    test_allocator_create();
+    test_allocator_events_destroy();
+    test_allocator_create_buffer();
+    return 0;
+}
index 679252d..1d66f1d 100644 (file)
@@ -16,6 +16,7 @@ executable('libds-tests',
 
 tests = [
   'box',
+  'allocator',
 ]
 
 foreach t : tests