-
/*
* CUnit - A Unit testing framework library for C.
* Copyright (C) 2001 Anil Kumar
*
- * This library is free software; you can redistribute it and/or
+ * This library is open source software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <stdio.h>
printf("i: %d c: %d\n", i, *(int*) vTest);
i+=stepwidth;
}
-
+ DeleteHashPos(&it);
}
-static void TestHashlistIteratorForward (void)
+static void ValidateBackAndForth(HashList *H)
{
- HashList *H;
-
- H = GetFilledHash (10, 1);
-
test_iterate_hash(H, 1, 1);
printf("\n");
test_iterate_hash(H, 0, 3);
printf("\n");
+}
+
+static void TestHashlistIteratorForward (void)
+{
+ HashList *H;
+
+ H = GetFilledHash (10, 1);
+
+ ValidateBackAndForth(H);
+
+ DeleteHash(&H);
+}
+
+
+static void TestHashlistAddDelete (void)
+{
+ 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);
}
+
/*
Some samples from the original...
CU_ASSERT_EQUAL(10, 10);
+const char *MSetStrings[] = {
+ "11:63",
+ "65",
+ "1,65,77",
+ "1:65,77,80:*",
+ NULL
+};
+
+#define InMSet 0
+#define NotInMSet 1
+const long MessageNumbers[5][2][10] = {
+/* First MSet */
+ {
+ {11, 59, 63, 0, 0, 0, 0, 0, 0, 0}, /* In */
+ {2, 10, 64, 65, 0, 0, 0, 0, 0, 0} /* NotIn */
+ },
+ {
+ {65, 0, 0, 0, 0, 0, 0, 0, 0, 0}, /* In */
+ {1, 64, 66, 0, 0, 0, 0, 0, 0, 0} /* NotIn */
+ },
+
+ {
+ {1, 65, 77, 0, 0, 0, 0, 0, 0, 0}, /* In */
+ {2, 64, 66, 76, 78, 0, 0, 0, 0, 0} /* NotIn */
+ },
+ {
+ {1, 2, 30, 64, 65, 77, 80, 81, 222222, 0}, /* In */
+ {66, 76, 78, 79, 0, 0, 0, 0, 0, 0} /* NotIn */
+ },
+ {
+ {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, /* In */
+ {0, 0, 0, 0, 0, 0, 0, 0, 0, 0} /* NotIn */
+ }
+};
+
+
+
+static void TestMSetHashlist (void)
+{
+ 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("%s", 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("%s", 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);
+}
+
static void AddHashlistTests(void)
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);
}
{
setvbuf(stdout, NULL, _IONBF, 0);
- StartLibCitadel(8);
CU_BOOL Run = CU_FALSE ;
CU_set_output_filename("TestAutomated");