summaryrefslogtreecommitdiff
path: root/firmware/test/buflib/test_main.c
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/test/buflib/test_main.c')
-rw-r--r--firmware/test/buflib/test_main.c88
1 files changed, 0 insertions, 88 deletions
diff --git a/firmware/test/buflib/test_main.c b/firmware/test/buflib/test_main.c
deleted file mode 100644
index 83b95e4341..0000000000
--- a/firmware/test/buflib/test_main.c
+++ /dev/null
@@ -1,88 +0,0 @@
1/***************************************************************************
2* __________ __ ___.
3* Open \______ \ ____ ____ | | _\_ |__ _______ ___
4* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7* \/ \/ \/ \/ \/
8* $Id$
9*
10* Copyright (C) 2011 Thomas Martitz
11*
12* This program is free software; you can redistribute it and/or
13* modify it under the terms of the GNU General Public License
14* as published by the Free Software Foundation; either version 2
15* of the License, or (at your option) any later version.
16*
17* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18* KIND, either express or implied.
19*
20****************************************************************************/
21
22#include <stdio.h>
23#include <stdlib.h>
24#include "buflib.h"
25#include "util.h"
26
27#define BUFLIB_BUFFER_SIZE (12<<10)
28static char buflib_buffer[BUFLIB_BUFFER_SIZE];
29static struct buflib_context ctx;
30#define assert(x) do { if (!(x)) exit(1); } while(0)
31
32int move_callback(int handle, void* current, void* new)
33{
34 (void)handle;(void)current;(void)new;
35 printf("Move!\n");
36}
37
38int shrink_callback(int handle, unsigned hints, void* start, size_t old_size)
39{
40 (void)handle;(void)start;(void)old_size;(void)hints;
41 printf("Shrink");
42}
43
44struct buflib_callbacks ops = {
45 .move_callback = move_callback,
46 .shrink_callback = shrink_callback,
47};
48
49int main(int argc, char **argv)
50{
51 buflib_init(&ctx, buflib_buffer, BUFLIB_BUFFER_SIZE);
52
53 int id = buflib_alloc_ex(&ctx, 512, "foo", &ops);
54 int id2 = buflib_alloc_ex(&ctx, 1024, "bar", &ops);
55 int id3 = buflib_alloc_ex(&ctx, 8<<10, "8K", &ops);
56
57 assert(id > 0 && id2 > 0 && id3 > 0);
58
59 #define STR "<TEST>"
60 strncpy(buflib_get_data(&ctx, id3), STR, sizeof STR);
61 if (id > 0)
62 {
63 buflib_print_allocs(&ctx, &print_handle);
64 buflib_free(&ctx, id);
65 buflib_print_allocs(&ctx, &print_handle);
66 buflib_free(&ctx, id2);
67 buflib_print_allocs(&ctx, &print_handle);
68
69 id = buflib_alloc_ex(&ctx, 3<<10, "should compact", &ops);
70 if (id <= 0) printf("compacting alloc failed\n");
71
72 buflib_print_allocs(&ctx, &print_handle);
73
74 printf("id I: %p\n", buflib_get_data(&ctx, id3));
75 id2 = buflib_alloc_ex(&ctx, 3<<10, "should fail", &ops);
76 printf("id II: %p\n", buflib_get_data(&ctx, id3));
77 if (id2 <= 0) printf("failing alloc failed\n");
78 else buflib_free(&ctx, id2);
79
80 if (id > 0)
81 buflib_free(&ctx, id);
82
83 printf("Check string: \"%s\"\n", buflib_get_data(&ctx, id3));
84 buflib_print_allocs(&ctx, &print_handle);
85 }
86
87 return 0;
88}