Revision: 14365
Author: adrian.chadd
Date: Tue Nov 10 06:39:38 2009
Log: Add in a basic test case for the busted-ass radix tree behaviour I've  
just noted.


http://code.google.com/p/lusca-cache/source/detail?r=14365

Added:
  /branches/LUSCA_HEAD/test-suite/libcore/test_libcore_2.c
Modified:
  /branches/LUSCA_HEAD/test-suite/libcore/build

=======================================
--- /dev/null
+++ /branches/LUSCA_HEAD/test-suite/libcore/test_libcore_2.c    Tue Nov 10  
06:39:38 2009
@@ -0,0 +1,69 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include <math.h>
+#include <fcntl.h>
+
+
+#include "include/Array.h"
+#include "include/Stack.h"
+
+#include "libcore/tools.h"
+#include "libcore/radix.h"
+
+static radix_node_t *
+prefix_add(radix_tree_t *rt, const char *a)
+{
+       struct in_addr addr;
+       prefix_t *p;
+       radix_node_t *rn;
+
+       (void) inet_aton(a, &addr);
+       p = New_Prefix(AF_INET, &addr, 32, NULL);
+
+       rn = radix_lookup(rt, p);
+       printf("prefix_add: %s: -> %p\n", inet_ntoa(addr), rn);
+       return rn;
+}
+
+static void
+test1a(void)
+{
+       radix_tree_t *rt;
+       radix_node_t *rn;
+       Stack s;
+
+       rt = New_Radix();
+
+       /* add a prefix */
+       rn = prefix_add(rt, "192.168.9.13");
+
+       /* add a second prefix */
+       rn = prefix_add(rt, "192.168.9.10");
+
+       /* add a third prefix */
+       rn = prefix_add(rt, "127.0.0.1");
+
+       /* Now, walk the array, populating the stack */
+       stackInit(&s);
+       RADIX_WALK(rt->head, rn) {
+               printf("adding: %p\n", rn);
+               stackPush(&s, rn);
+       } RADIX_WALK_END;
+
+       /* now walk the stack, clearing things */
+       while ( (rn = stackPop(&s)) != NULL) {
+               printf("removing: %p\n", rn);
+               radix_remove(rt, rn);
+       }
+}
+
+int
+main(int argc, const char *argv[])
+{
+       printf("%s: initializing\n", argv[0]);
+       test1a();
+       exit(0);
+}
+
=======================================
--- /branches/LUSCA_HEAD/test-suite/libcore/build       Wed Jul  8 15:49:14 2009
+++ /branches/LUSCA_HEAD/test-suite/libcore/build       Tue Nov 10 06:39:38 2009
@@ -1,11 +1,13 @@
  #!/bin/sh

  CFLAGS="-g -Wall -Werror -I../.."
-LDFLAGS="-L../../libcore"
-LIBS="-lcore -lm"
+LDFLAGS="-L../../libcore -L../../lib"
+LIBS="-lcore -lmiscutil -lm"

  rm test_libcore_1

  gcc ${CFLAGS}  test_libcore_1.c -o test_libcore_1 ${LDFLAGS} ${LIBS}
+gcc ${CFLAGS}  test_libcore_2.c -o test_libcore_2 ${LDFLAGS} ${LIBS}

  ./test_libcore_1
+./test_libcore_2

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"lusca-commit" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/lusca-commit?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to