Dummy commit to test new ssh key
[eleutheria.git] / buddy / test5.c
blob3ec2aa8e2909c16304d39064967b94bf19864355
1 /*
2 * Compile with:
3 * gcc test5.c mpool.c -o test5 -Wall -W -Wextra -ansi -pedantic
4 */
6 #include <stdio.h>
7 #include <stdlib.h>
9 #include "mpool.h"
11 int main(void)
13 mpool_t *mpool;
14 mpret_t mpret;
15 char *buffer;
17 /* Initialize memory pool with 1024 bytes */
18 mpret = mpool_init(&mpool, 10, 5);
19 if (mpret == MPOOL_ENOMEM) {
20 fprintf(stderr, "mpool: not enough memory\n");
21 exit(EXIT_FAILURE);
23 else if (mpret == MPOOL_ERANGE) {
24 fprintf(stderr, "mpool: out of range in mpool_init()\n");
25 exit(EXIT_FAILURE);
27 else if (mpret == MPOOL_EBADVAL) {
28 fprintf(stderr, "mpool: bad value passed to mpool_init()\n");
29 exit(EXIT_FAILURE);
32 /* Allocate 1000 bytes for buffer */
33 if ((buffer = mpool_alloc(mpool, 1000)) == NULL) {
34 fprintf(stderr, "mpool: no available block in pool\n");
35 mpool_destroy(mpool);
36 exit(EXIT_FAILURE);
39 /* Free buffer */
40 mpool_free(mpool, buffer);
42 /* Allocate 1000 bytes for buffer */
43 if ((buffer = mpool_alloc(mpool, 1000)) == NULL) {
44 fprintf(stderr, "mpool reports no available block in pool "
45 "although it exists!\n");
46 mpool_destroy(mpool);
47 exit(EXIT_FAILURE);
49 else
50 printf("mpool: PASSED\n");
53 * Free buffer --
54 * could be omitted, since we call mpool_destroy() afterwards
56 mpool_free(mpool, buffer);
58 /* Destroy memory pool and free all resources */
59 mpool_destroy(mpool);
61 return EXIT_SUCCESS;