Commit 303fc71ec31995f9f736785e97ec17459c17fcf1

Authored by Georg Hopp
1 parent 09f1e801

Add testprogram for new iterable facility

... ... @@ -43,4 +43,5 @@ tags
43 43 /testers/testserver2
44 44 /testers/testtcp
45 45 /testers/testudp
  46 +/testers/testiterator
46 47 /testers/*.o
... ...
... ... @@ -13,7 +13,8 @@ LIBS = $(TRLIBS) \
13 13
14 14 PROGRAMS = testserver2 \
15 15 testtcp \
16   - testudp
  16 + testudp \
  17 + testiterator
17 18
18 19 all: $(PROGRAMS)
19 20
... ... @@ -26,6 +27,9 @@ testtcp: testclient.o
26 27 testudp: testclient.o
27 28 $(CC) $(LDFLAGS) -std=c99 $(LIBS) -o $@ $<
28 29
  30 +testiterator: testiterator.o
  31 + $(CC) $(LDFLAGS) -std=c99 $(LIBS) -o $@ $<
  32 +
29 33 testudp.o: testclient.c
30 34 $(CC) $(CFLAGS) -DUDP=1 -std=c99 -c -o $@ $<
31 35
... ...
  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