summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorAkira TAGOH <akira@tagoh.org>2006-04-12 17:18:15 +0000
committerAkira TAGOH <akira@tagoh.org>2006-04-12 17:18:15 +0000
commit356b6612c8fd3bf5b34e84c18a507725fb698f59 (patch)
tree13d95720172e2fce55b7943dafe86098c0764ad6 /tests
parentb2205654f8e6a88830a0955c7440a7eaca86a2f1 (diff)
2006-04-13 Akira TAGOH <at@gclab.org>
* hieroglyph/hgallocator-bfit.[ch]: added the best fit algorithm memory allocator.
Diffstat (limited to 'tests')
-rw-r--r--tests/Makefile.am6
-rw-r--r--tests/hgallocator-bfit.c41
2 files changed, 47 insertions, 0 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 7494266..0ae37ae 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -13,6 +13,7 @@ LDADDS = \
noinst_PROGRAMS = \
test-hgbtree \
+ test-hgallocator-bfit \
test-hgmem \
test-hgfile \
test-hgstring \
@@ -31,6 +32,11 @@ test_hgbtree_SOURCES = \
$(NULL)
test_hgbtree_LDADD = $(LDADDS)
+test_hgallocator_bfit_SOURCES = \
+ hgallocator-bfit.c \
+ $(NULL)
+test_hgallocator_bfit_LDADD = $(LDADDS)
+
test_hgmem_SOURCES = \
hgmem.c \
$(NULL)
diff --git a/tests/hgallocator-bfit.c b/tests/hgallocator-bfit.c
new file mode 100644
index 0000000..77f55da
--- /dev/null
+++ b/tests/hgallocator-bfit.c
@@ -0,0 +1,41 @@
+#include <stdio.h>
+#include <string.h>
+#include <hieroglyph/hgallocator-bfit.h>
+#include <hieroglyph/hgmem.h>
+
+int
+main(void)
+{
+ HgAllocator *allocator;
+ HgMemPool *pool;
+ gchar *s, *s2;
+
+ hg_mem_init();
+ allocator = hg_allocator_new(hg_allocator_bfit_get_vtable());
+ pool = hg_mem_pool_new(allocator, "test", 256, FALSE);
+ if (pool == NULL) {
+ g_print("Failed to create a pool.\n");
+ return 1;
+ }
+ s = hg_mem_alloc(pool, 16);
+ printf("%p\n", s);
+ s2 = hg_mem_alloc(pool, 32);
+ printf("%p\n", s2);
+ if (s == NULL || s2 == NULL) {
+ g_print("Failed to alloc a memory: %p %p.\n", s, s2);
+ return 1;
+ }
+ strcpy(s, "test");
+ strcpy(s2, "test");
+ if (strcmp(s, s2)) {
+ g_print("Failed to compare the memory.\n");
+ return 1;
+ }
+ hg_mem_free(s2);
+ hg_mem_free(s);
+ hg_mem_pool_destroy(pool);
+ hg_allocator_destroy(allocator);
+ hg_mem_finalize();
+
+ return 0;
+}