Back to index

libcitadel  8.12
Defines | Functions | Variables
hashlist_test.c File Reference
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "stringbuf_test.h"
#include "../lib/libcitadel.h"

Go to the source code of this file.

Defines

#define InMSet   0
#define NotInMSet   1

Functions

static HashListGetFilledHash (int n, int stepwidth)
static void test_iterate_hash (HashList *testh, int forward, int stepwidth)
static void ValidateBackAndForth (HashList *H)
static void TestHashlistIteratorForward (void)
static void TestHashlistAddDelete (void)
static void TestMSetHashlist (void)
static void AddHashlistTests (void)
int main (int argc, char *argv[])

Variables

const char * MSetStrings []
const long MessageNumbers [5][2][10]

Define Documentation

#define InMSet   0

Definition at line 182 of file hashlist_test.c.

#define NotInMSet   1

Definition at line 183 of file hashlist_test.c.


Function Documentation

static void AddHashlistTests ( void  ) [static]

Definition at line 299 of file hashlist_test.c.

{
       CU_pSuite pGroup = NULL;
       CU_pTest pTest = NULL;

       pGroup = CU_add_suite("TestStringBufSimpleAppenders", NULL, NULL);
       pTest = CU_add_test(pGroup, "TestHashListIteratorForward", TestHashlistIteratorForward);
       pTest = CU_add_test(pGroup, "TestHashlistAddDelete", TestHashlistAddDelete);
       pTest = CU_add_test(pGroup, "TestMSetHashlist", TestMSetHashlist);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static HashList* GetFilledHash ( int  n,
int  stepwidth 
) [static]

Definition at line 24 of file hashlist_test.c.

{
       HashList* TestHash;
       int i;
       int *val;

       TestHash = NewHash(1, Flathash);

       for (i = 0; i < n;  i+=stepwidth)
       {
              val = (int*) malloc(sizeof(int));
              *val = i;
              Put(TestHash, IKEY(i), val, NULL);
       }
       return TestHash;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int main ( int  argc,
char *  argv[] 
)

CU_automated_run_tests();

Definition at line 311 of file hashlist_test.c.

{
       setvbuf(stdout, NULL, _IONBF, 0);

       StartLibCitadel(8);
       CU_BOOL Run = CU_FALSE ;
       
       CU_set_output_filename("TestAutomated");
       if (CU_initialize_registry()) {
              printf("\nInitialize of test Registry failed.");
       }
       
       Run = CU_TRUE ;
       AddHashlistTests();
       
       if (CU_TRUE == Run) {
              //CU_console_run_tests();
    printf("\nTests completed with return value %d.\n", CU_basic_run_tests());
    
       }
       
       CU_cleanup_registry();

       return 0;
}

Here is the call graph for this function:

static void test_iterate_hash ( HashList testh,
int  forward,
int  stepwidth 
) [static]

Definition at line 43 of file hashlist_test.c.

{
       int i = 0;
       HashPos  *it;
       void *vTest;
       long len = 0;
       const char *Key;
       int dir = 1;

       if (forward == 0)
              dir = -1;
       it = GetNewHashPos(testh, dir * stepwidth);
       while (GetNextHashPos(testh, it, &len, &Key, &vTest) &&
               (vTest != NULL)) {

              printf("i: %d c: %d\n", i, *(int*) vTest);
              i+=stepwidth;
       }
       DeleteHashPos(&it);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void TestHashlistAddDelete ( void  ) [static]

Definition at line 97 of file hashlist_test.c.

{
       HashList *H;
       HashPos *at;
       int *val, i;

       H = GetFilledHash (10, 1);

       at = GetNewHashPos(H, 0);

       printf("Remove first\n");
       DeleteEntryFromHash(H, at);
       DeleteHashPos(&at);

       ValidateBackAndForth(H);

       printf("Insert 15\n");
       i = 15;
       val = (int*) malloc(sizeof(int));
       *val = i;
       Put(H, IKEY(i), val, NULL);

       ValidateBackAndForth(H);

       printf("Remove third\n");
       at = GetNewHashPos(H, 0);
       NextHashPos(H, at);
       NextHashPos(H, at);
       NextHashPos(H, at);
       DeleteEntryFromHash(H, at);

       ValidateBackAndForth(H);
       printf("Insert -15\n");

       i = -15;
       val = (int*) malloc(sizeof(int));
       *val = i;
       Put(H, IKEY(i), val, NULL);

       ValidateBackAndForth(H);

       DeleteHashPos(&at);
       DeleteHash(&H);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void TestHashlistIteratorForward ( void  ) [static]

Definition at line 85 of file hashlist_test.c.

{
       HashList *H;

       H = GetFilledHash (10, 1);

       ValidateBackAndForth(H);

       DeleteHash(&H);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void TestMSetHashlist ( void  ) [static]

Definition at line 211 of file hashlist_test.c.

{
       int nTest = 0;
       int j;
       StrBuf *MSetStr;
       StrBuf *Assert;
       MSet *OneMSet;
       

       MSetStr = NewStrBuf();
       Assert = NewStrBuf();
       while (MSetStrings[nTest] != NULL)
       {
              StrBufPlain(MSetStr, MSetStrings[nTest], -1);
              ParseMSet(&OneMSet, MSetStr);

//#ifdef VERBOSE_TEST
              printf("---%s---\n", ChrPtr(MSetStr));
              {
                     const char *HashKey;
                     long HKLen;
                     HashList *ScanMe = (HashList*) OneMSet;
                     HashPos *at;
                     void *vMsg;
                     long *end;

                     at = GetNewHashPos(ScanMe, 0);
                     while (GetNextHashPos(ScanMe, at, &HKLen, &HashKey, &vMsg)) {
                            /* Are you a new message, or an old message? */
                            end = (long*) vMsg;
                            printf("[%ld][%ld]\n", *(long*)HashKey, *end);
                     }
                     DeleteHashPos(&at);
              }
//#endif

              j = 0;
              while (MessageNumbers[nTest][InMSet][j] != 0)
              {
                     if (!IsInMSetList(OneMSet, MessageNumbers[nTest][InMSet][j]))
                     {
                            StrBufPrintf(Assert, "InFail: %s <-> %ld\n", 
                                        ChrPtr(MSetStr), 
                                        MessageNumbers[nTest][InMSet][j]);
                            CU_FAIL(ChrPtr(Assert));
                            printf(ChrPtr(Assert));
                     }
                     else
                     {
                            StrBufPrintf(Assert, "InPass: %s <-> %ld\n", 
                                        ChrPtr(MSetStr), 
                                        MessageNumbers[nTest][InMSet][j]);
                            CU_PASS(ChrPtr(Assert));
                     }
                     j++;   
              }
              j = 0;
              while (MessageNumbers[nTest][NotInMSet][j] != 0)
              {
                     if (IsInMSetList(OneMSet, MessageNumbers[nTest][NotInMSet][j]))
                     {
                            StrBufPrintf(Assert, "NOT-InFail: %s <-> %ld\n", 
                                        ChrPtr(MSetStr), 
                                        MessageNumbers[nTest][NotInMSet][j]);
                            CU_FAIL(ChrPtr(Assert));
                            printf(ChrPtr(Assert));
                     }
                     else
                     {
                            StrBufPrintf(Assert, "NOT-InPass: %s <-> %ld\n", 
                                        ChrPtr(MSetStr), 
                                        MessageNumbers[nTest][InMSet][j]);
                            CU_PASS(ChrPtr(Assert));
                     }
                     j++;
              }
              

              DeleteMSet(&OneMSet);
              nTest++;
              
       }
       FreeStrBuf(&MSetStr);
       FreeStrBuf(&Assert);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void ValidateBackAndForth ( HashList H) [static]

Definition at line 64 of file hashlist_test.c.

{
       test_iterate_hash(H, 1, 1);
       printf("\n");

       test_iterate_hash(H, 0, 1);
       printf("\n");

       test_iterate_hash(H, 1, 2);
       printf("\n");

       test_iterate_hash(H, 0, 2);
       printf("\n");

       test_iterate_hash(H, 1, 3);
       printf("\n");

       test_iterate_hash(H, 0, 3);
       printf("\n");
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

const long MessageNumbers[5][2][10]
Initial value:
 {

       {
              {11, 59, 63, 0, 0, 0, 0, 0, 0, 0}, 
              {2, 10, 64, 65, 0, 0, 0, 0, 0, 0} 
       },
       {
              {65, 0, 0, 0, 0, 0, 0, 0, 0, 0}, 
              {1, 64, 66, 0, 0, 0, 0, 0, 0, 0} 
       },

       {
              {1, 65, 77, 0, 0, 0, 0, 0, 0, 0}, 
              {2, 64, 66, 76, 78, 0, 0, 0, 0, 0} 
       },
       {
              {1, 2, 30, 64, 65, 77, 80, 81, 222222, 0}, 
              {66, 76, 78, 79, 0, 0, 0, 0, 0, 0} 
       },
       {
              {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, 
              {0, 0, 0, 0, 0, 0, 0, 0, 0, 0} 
       }
}

Definition at line 184 of file hashlist_test.c.

const char* MSetStrings[]
Initial value:
 {
       "11:63",
       "65",
       "1,65,77",
       "1:65,77,80:*",
       NULL
}

Definition at line 174 of file hashlist_test.c.