Commit 303fc71ec31995f9f736785e97ec17459c17fcf1
1 parent
09f1e801
Add testprogram for new iterable facility
Showing
3 changed files
with
56 additions
and
1 deletions
| @@ -13,7 +13,8 @@ LIBS = $(TRLIBS) \ | @@ -13,7 +13,8 @@ LIBS = $(TRLIBS) \ | ||
| 13 | 13 | ||
| 14 | PROGRAMS = testserver2 \ | 14 | PROGRAMS = testserver2 \ |
| 15 | testtcp \ | 15 | testtcp \ |
| 16 | - testudp | 16 | + testudp \ |
| 17 | + testiterator | ||
| 17 | 18 | ||
| 18 | all: $(PROGRAMS) | 19 | all: $(PROGRAMS) |
| 19 | 20 | ||
| @@ -26,6 +27,9 @@ testtcp: testclient.o | @@ -26,6 +27,9 @@ testtcp: testclient.o | ||
| 26 | testudp: testclient.o | 27 | testudp: testclient.o |
| 27 | $(CC) $(LDFLAGS) -std=c99 $(LIBS) -o $@ $< | 28 | $(CC) $(LDFLAGS) -std=c99 $(LIBS) -o $@ $< |
| 28 | 29 | ||
| 30 | +testiterator: testiterator.o | ||
| 31 | + $(CC) $(LDFLAGS) -std=c99 $(LIBS) -o $@ $< | ||
| 32 | + | ||
| 29 | testudp.o: testclient.c | 33 | testudp.o: testclient.c |
| 30 | $(CC) $(CFLAGS) -DUDP=1 -std=c99 -c -o $@ $< | 34 | $(CC) $(CFLAGS) -DUDP=1 -std=c99 -c -o $@ $< |
| 31 | 35 |
testers/testiterator.c
0 → 100644
| 1 | +#include <stdio.h> | ||
| 2 | + | ||
| 3 | +#include "trbase.h" | ||
| 4 | +#include "trdata.h" | ||
| 5 | + | ||
| 6 | +int | ||
| 7 | +main (int argc, char * argv[]) | ||
| 8 | +{ | ||
| 9 | + TR_List list = TR_new(TR_List); | ||
| 10 | + TR_Queue queue = TR_new(TR_Queue); | ||
| 11 | + | ||
| 12 | + list->free_msgs = 0; | ||
| 13 | + ((TR_List)queue)->free_msgs = 0; | ||
| 14 | + | ||
| 15 | + TR_listPut(list, "a"); | ||
| 16 | + TR_listPut(list, "b"); | ||
| 17 | + TR_listPut(list, "c"); | ||
| 18 | + | ||
| 19 | + TR_iterableForeach(list) { | ||
| 20 | + printf("%s\n", (char *)TR_iterableCurrent(list)); | ||
| 21 | + } | ||
| 22 | + | ||
| 23 | + TR_listGetFirst(list); | ||
| 24 | + | ||
| 25 | + TR_iterableForeach(list) { | ||
| 26 | + printf("%s\n", (char *)TR_iterableCurrent(list)); | ||
| 27 | + } | ||
| 28 | + | ||
| 29 | + TR_queuePut(queue, "1"); | ||
| 30 | + TR_queuePut(queue, "2"); | ||
| 31 | + TR_queuePut(queue, "3"); | ||
| 32 | + | ||
| 33 | + TR_iterableForeach(queue) { | ||
| 34 | + printf("%s\n", (char *)TR_iterableCurrent(queue)); | ||
| 35 | + } | ||
| 36 | + | ||
| 37 | + TR_queueGet(queue); | ||
| 38 | + | ||
| 39 | + TR_iterableForeach(queue) { | ||
| 40 | + printf("%s\n", (char *)TR_iterableCurrent(queue)); | ||
| 41 | + } | ||
| 42 | + | ||
| 43 | + TR_delete(list); | ||
| 44 | + TR_delete(queue); | ||
| 45 | + TR_cleanup(); | ||
| 46 | + | ||
| 47 | + return 0; | ||
| 48 | +} | ||
| 49 | + | ||
| 50 | +// vim: set ts=4 sw=4: |
Please
register
or
login
to post a comment