From bf0e740b86dda6f3db8c3b92d2b5dc814a0dcbd7 Mon Sep 17 00:00:00 2001 From: Francesco Chemolli Date: Fri, 2 Jan 2015 11:02:05 +0100 Subject: [PATCH] Fixed unit tests --- test-suite/splay.cc | 32 ++++++++++++-------------------- 1 file changed, 12 insertions(+), 20 deletions(-) diff --git a/test-suite/splay.cc b/test-suite/splay.cc index 27715fe99b..f1fcadbf15 100644 --- a/test-suite/splay.cc +++ b/test-suite/splay.cc @@ -18,14 +18,7 @@ #include #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(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 *safeTop = NULL; + SplayNode *safeTop = new SplayNode(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 *safeTop = NULL; + SplayNode *safeTop = new SplayNode(101); for (int i = 0; i < 100; ++i) { intnode I; @@ -210,7 +200,7 @@ main(int argc, char *argv[]) { /* check for begin() */ - SplayNode *safeTop = NULL; + Splay *safeTop = new Splay(); 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; } -- 2.47.3