]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Fixed unit tests
authorFrancesco Chemolli <kinkie@squid-cache.org>
Fri, 2 Jan 2015 10:02:05 +0000 (11:02 +0100)
committerFrancesco Chemolli <kinkie@squid-cache.org>
Fri, 2 Jan 2015 10:02:05 +0000 (11:02 +0100)
test-suite/splay.cc

index 27715fe99b05b6e4b9233abd9d338ab09027e7df..f1fcadbf1584d84e8a8a8abb1652683df0bbb976 100644 (file)
 #include <unistd.h>
 #endif
 
-#if 0
-#define assert(X) {if (!(X)) exit (1);}
 #include "splay.h"
-#undef assert
-#else
-#include "splay.h"
-#endif
-
 #include "util.h"
 
 class intnode
@@ -146,7 +139,10 @@ main(int argc, char *argv[])
         for (i = 0; i < 100; ++i) {
             I = (intnode *)xcalloc(sizeof(intnode), 1);
             I->i = squid_random();
-            top = top->insert(I, compareintvoid);
+            if (top)
+                top = top->insert(I, compareintvoid);
+            else
+                top = new splayNode(static_cast<void*>(new intnode(101)));
         }
 
         SplayCheck::BeginWalk();
@@ -155,15 +151,12 @@ main(int argc, char *argv[])
         SplayCheck::BeginWalk();
         top->walk(SplayCheck::WalkVoid, NULL);
         top->destroy(destintvoid);
-        /* check we don't segfault on NULL splay calls */
-        top = NULL;
-        top->splay((void *)NULL, compareintvoid);
     }
 
     /* test typesafe splay containers */
     {
         /* intnode* */
-        SplayNode<intnode *> *safeTop = NULL;
+        SplayNode<intnode *> *safeTop = new SplayNode<intnode *>(new intnode(101));
 
         for ( int i = 0; i < 100; ++i) {
             intnode *I;
@@ -176,13 +169,10 @@ main(int argc, char *argv[])
         safeTop->walk(SplayCheck::WalkNode, NULL);
 
         safeTop->destroy(destint);
-        /* check we don't segfault on NULL splay calls */
-        safeTop = NULL;
-        safeTop->splay((intnode *)NULL, compareint);
     }
     {
         /* intnode */
-        SplayNode<intnode> *safeTop = NULL;
+        SplayNode<intnode> *safeTop = new SplayNode<intnode>(101);
 
         for (int i = 0; i < 100; ++i) {
             intnode I;
@@ -210,7 +200,7 @@ main(int argc, char *argv[])
 
     {
         /* check for begin() */
-        SplayNode<intnode> *safeTop = NULL;
+        Splay<intnode> *safeTop = new Splay<intnode>();
 
         if (safeTop->start() != NULL)
             exit (1);
@@ -223,15 +213,15 @@ main(int argc, char *argv[])
             I.i = squid_random();
 
             if (I.i > 50 && I.i < 10000000)
-                safeTop = safeTop->insert(I, compareintref);
+                safeTop->insert(I, compareintref);
         }
 
         {
             intnode I;
             I.i = 50;
-            safeTop = safeTop->insert (I, compareintref);
+            safeTop->insert (I, compareintref);
             I.i = 10000000;
-            safeTop = safeTop->insert (I, compareintref);
+            safeTop->insert (I, compareintref);
         }
 
         if (!safeTop->start())
@@ -275,6 +265,8 @@ main(int argc, char *argv[])
             exit (1);
     }
 
+    /* TODO: also test the oher Splay API */
+
     return 0;
 }