Revision 410fd7f8
som/Tests/Makefile | ||
---|---|---|
9 | 9 |
CPPFLAGS = -I$(BASE)/include |
10 | 10 |
CPPFLAGS += -I../TopologyManager |
11 | 11 |
|
12 |
LDFLAGS = -L../TopologyManager -L../ChunkTrading |
|
13 |
LDLIBS = -ltopman -ltrading |
|
12 |
LDFLAGS = -L../TopologyManager -L../ChunkTrading -L ../ChunkBuffer |
|
14 | 13 |
#LDFLAGS += -static |
15 | 14 |
|
16 |
all: topology_test chunk_encoding_test |
|
15 |
all: topology_test chunk_encoding_test cb_test
|
|
17 | 16 |
|
18 | 17 |
topology_test: topology_test.o net_helpers.o |
19 | 18 |
topology_test: ../TopologyManager/net_helper.o |
20 | 19 |
topology_test: ../TopologyManager/libtopman.a |
20 |
topology_test: LDLIBS += -ltopman |
|
21 | 21 |
|
22 | 22 |
chunk_encoding_test: chunk_encoding_test.o |
23 | 23 |
chunk_encoding_test: ../ChunkTrading/libtrading.a |
24 |
chunk_encoding_test: LDLIBS += -ltrading |
|
25 |
|
|
26 |
cb_test: cb_test.o |
|
27 |
cb_test: LDLIBS += -lcb |
|
24 | 28 |
|
25 | 29 |
../TopologyManager/net_helper.o: |
26 | 30 |
../TopologyManager/libtopman.a: |
... | ... | |
29 | 33 |
make -C ../ChunkTrading |
30 | 34 |
|
31 | 35 |
clean: |
32 |
rm -f topology_test chunk_encoding_test |
|
36 |
rm -f topology_test chunk_encoding_test cb_test
|
|
33 | 37 |
rm -f *.o |
34 | 38 |
|
35 | 39 |
allclean: clean |
som/Tests/cb_test.c | ||
---|---|---|
1 |
#include <stdint.h> |
|
2 |
#include <stdlib.h> |
|
3 |
#include <stdio.h> |
|
4 |
#include <string.h> |
|
5 |
#include "chunk.h" |
|
6 |
#include "chunkbuffer.h" |
|
7 |
|
|
8 |
static struct chunk *chunk_forge(int id) |
|
9 |
{ |
|
10 |
struct chunk *c; |
|
11 |
char buff[64]; |
|
12 |
|
|
13 |
c = malloc(sizeof(struct chunk)); |
|
14 |
if (c == NULL) { |
|
15 |
return c; |
|
16 |
} |
|
17 |
|
|
18 |
sprintf(buff, "Chunk %d", id); |
|
19 |
c->id = id; |
|
20 |
c->timestamp = 40 * id; |
|
21 |
c->data = strdup(buff); |
|
22 |
c->size = strlen(c->data) + 1; |
|
23 |
c->attributes_size = 0; |
|
24 |
c->attributes = NULL; |
|
25 |
return c; |
|
26 |
} |
|
27 |
|
|
28 |
static void chunk_add(struct chunk_buffer *cb, int id) |
|
29 |
{ |
|
30 |
struct chunk *c; |
|
31 |
|
|
32 |
printf("Inserting %d\n", id); |
|
33 |
c = chunk_forge(id); |
|
34 |
if (c) { |
|
35 |
cb_add_chunk(cb, c); |
|
36 |
} else { |
|
37 |
printf("Failed to create the chunk"); |
|
38 |
} |
|
39 |
free(c); |
|
40 |
} |
|
41 |
|
|
42 |
static void cb_print(const struct chunk_buffer *cb) |
|
43 |
{ |
|
44 |
struct chunk *buff; |
|
45 |
int i, size; |
|
46 |
|
|
47 |
buff = cb_get_chunks(cb, &size); |
|
48 |
for (i = 0; i < size; i++) { |
|
49 |
printf("C[%d]: %s %d\n", i, buff[i].data, buff[i].id); |
|
50 |
} |
|
51 |
} |
|
52 |
|
|
53 |
int main(int argc, char *argv[]) |
|
54 |
{ |
|
55 |
struct chunk_buffer *b; |
|
56 |
|
|
57 |
b = cb_init("size=32"); |
|
58 |
if (b == NULL) { |
|
59 |
printf("Error initialising the Chunk Buffer\n"); |
|
60 |
|
|
61 |
return -1; |
|
62 |
} |
|
63 |
chunk_add(b, 10); |
|
64 |
chunk_add(b, 5); |
|
65 |
chunk_add(b, 12); |
|
66 |
chunk_add(b, 40); |
|
67 |
chunk_add(b, 51); |
|
68 |
chunk_add(b, 2); |
|
69 |
chunk_add(b, 13); |
|
70 |
chunk_add(b, 11); |
|
71 |
chunk_add(b, 26); |
|
72 |
chunk_add(b, 30); |
|
73 |
cb_print(b); |
|
74 |
|
|
75 |
cb_destroy(b); |
|
76 |
|
|
77 |
return 0; |
|
78 |
} |
Also available in: Unified diff