summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorAkira TAGOH <akira@tagoh.org>2006-04-24 14:04:21 +0000
committerAkira TAGOH <akira@tagoh.org>2006-04-24 14:04:21 +0000
commitc874b9402315dc2e4d57093a36d0effed1c18ca4 (patch)
treefd02abfe90f4591a990a556e14dd9cff5114e0b5 /tests
parentbbf9ae7d0b5627593a8716ac241872eb052f81b0 (diff)
2006-04-24 Akira TAGOH <at@gclab.org>
* hieroglyph/hgallocator-bfit.c (_hg_bfit_block_new): store a heap id. (_hg_allocator_bfit_get_free_block): update the amount of the used heap in pool. (_hg_allocator_bfit_relocate): new function. (_hg_allocator_bfit_real_free): update the amount of the used heap in pool. (_hg_allocator_bfit_real_resize): implemented.
Diffstat (limited to 'tests')
-rw-r--r--tests/hgmem.c54
1 files changed, 52 insertions, 2 deletions
diff --git a/tests/hgmem.c b/tests/hgmem.c
index 0b2594c..345202b 100644
--- a/tests/hgmem.c
+++ b/tests/hgmem.c
@@ -1,16 +1,17 @@
#include <stdio.h>
#include <string.h>
#include <hieroglyph/hgallocator-ffit.h>
+#include <hieroglyph/hgallocator-bfit.h>
#include <hieroglyph/hgmem.h>
int
-main(void)
+test_ffit(void)
{
HgAllocator *allocator;
HgMemPool *pool;
gchar *s, *s2;
- hg_mem_init();
+ g_print("ffit\n");
allocator = hg_allocator_new(hg_allocator_ffit_get_vtable());
pool = hg_mem_pool_new(allocator, "test", 256, TRUE);
if (pool == NULL) {
@@ -35,6 +36,55 @@ main(void)
hg_mem_free(s);
hg_mem_pool_destroy(pool);
hg_allocator_destroy(allocator);
+
+ return 0;
+}
+
+int
+test_bfit(void)
+{
+ HgAllocator *allocator;
+ HgMemPool *pool;
+ gchar *s, *s2;
+
+ allocator = hg_allocator_new(hg_allocator_bfit_get_vtable());
+ pool = hg_mem_pool_new(allocator, "test", 256, TRUE);
+ 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, 256);
+ printf("%p:%p\n", s, 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);
+
+ return 0;
+}
+
+int
+main(void)
+{
+ hg_mem_init();
+
+ if (test_ffit() != 0)
+ return 1;
+ if (test_bfit() != 0)
+ return 1;
+
hg_mem_finalize();
return 0;