From: Wilfried Göesgens Date: Mon, 7 Sep 2009 21:00:59 +0000 (+0000) Subject: * define StrBufNOTNULL, we use it for the Next-Tokenizer to signal that we reached... X-Git-Tag: v7.86~873 X-Git-Url: https://code.citadel.org/?a=commitdiff_plain;h=e60b2fec0c675e95bd829f86c0552288fa7524d7;p=citadel.git * define StrBufNOTNULL, we use it for the Next-Tokenizer to signal that we reached the end; NULL already indicates that we're starting to parse --- diff --git a/libcitadel/lib/libcitadel.h b/libcitadel/lib/libcitadel.h index c77f57b6e..92f76f07a 100644 --- a/libcitadel/lib/libcitadel.h +++ b/libcitadel/lib/libcitadel.h @@ -65,6 +65,11 @@ enum LogLevel { #define IsEmptyStr(a) ((a)[0] == '\0') #endif +/* + * another word to indicate n/a for a pointer if NULL already has a "meaning" + */ +extern const char *StrBufNOTNULL; + /* * Misc declarations */ diff --git a/libcitadel/lib/stringbuf.c b/libcitadel/lib/stringbuf.c index 5d6d4125b..a7beafe5c 100644 --- a/libcitadel/lib/stringbuf.c +++ b/libcitadel/lib/stringbuf.c @@ -27,6 +27,8 @@ int ZEXPORT compress_gzip(Bytef * dest, size_t * destLen, #endif int BaseStrBufSize = 64; +const char *StrBufNOTNULL = ((char*) NULL) - 1; + /** * Private Structure for the Stringbuffer */ @@ -1314,10 +1316,8 @@ unsigned long StrBufExtract_unsigned_long(const StrBuf* Source, int parmnum, cha */ int StrBufHaveNextToken(const StrBuf *Source, const char **pStart) { - const char *Null = NULL; - Null --; if ((Source == NULL) || - (*pStart == Null) || + (*pStart == StrBufNOTNULL) || (Source->BufUsed == 0)) { return 0; @@ -1356,8 +1356,7 @@ int StrBufExtract_NextToken(StrBuf *dest, const StrBuf *Source, const char **pSt if ((Source == NULL) || (Source->BufUsed == 0) ) { - *pStart = NULL; - (*pStart) --; /* move it to the end of all being via underflow */ + *pStart = StrBufNOTNULL; return -1; } @@ -1421,8 +1420,7 @@ int StrBufExtract_NextToken(StrBuf *dest, const StrBuf *Source, const char **pSt /* did we reach the end? */ if ((s > EndBuffer)) { - EndBuffer = NULL; - EndBuffer --; + EndBuffer = StrBufNOTNULL; *pStart = EndBuffer; } else { diff --git a/libcitadel/tests/stringbuf_test.c b/libcitadel/tests/stringbuf_test.c index 4552e9ae9..231dee0c9 100644 --- a/libcitadel/tests/stringbuf_test.c +++ b/libcitadel/tests/stringbuf_test.c @@ -54,6 +54,17 @@ static void test2(void) CU_ASSERT((char *)3 == "THis is negative test. test 2"); } */ + + +static void TestRevalidateStrBuf(StrBuf *Buf) +{ + CU_ASSERT(strlen(ChrPtr(Buf)) == StrLength(Buf)); + + + +} + + static void TestCreateBuf(void) { StrBuf *Buf; @@ -67,6 +78,7 @@ static void TestCreateBuf(void) CU_ASSERT(Buf == NULL); Buf = NewStrBufPlain(HKEY("ABC")); + TestRevalidateStrBuf(Buf); CU_ASSERT(StrLength(Buf) == 3); CU_ASSERT_NSTRING_EQUAL("ABC", ChrPtr(Buf), 3); @@ -75,13 +87,14 @@ static void TestCreateBuf(void) { StrBufAppendBufPlain(Buf, HKEY("ABC"), 0); len += 3; - CU_ASSERT(StrLength(Buf) == len); + CU_ASSERT(StrLength(Buf) == len); } StrBufShrinkToFit(Buf, 1); FreeStrBuf(&Buf); CU_ASSERT(Buf == NULL); Buf = NewStrBufPlain(HKEY("ABC")); + TestRevalidateStrBuf(Buf); len = StrLength(Buf); for (i=0; i< 500; i ++) { @@ -89,7 +102,9 @@ static void TestCreateBuf(void) len += 3; CU_ASSERT(StrLength(Buf) == len); } + TestRevalidateStrBuf(Buf); StrBufShrinkToFit(Buf, 1); + TestRevalidateStrBuf(Buf); Buf2 = NewStrBufDup(Buf); CU_ASSERT(StrLength(Buf) == StrLength(Buf2)); @@ -119,16 +134,13 @@ static void TestCreateBuf(void) static void NextTokenizerIterateBuf(StrBuf *Buf, int NTokens) { const char *pCh = NULL; - char *NotNull; StrBuf *Buf2; long CountTokens = 0; long HaveNextToken = 0; long HaveNextTokenF = 0; - NotNull = NULL; - NotNull --; - printf("\n\nTemplate: >%s<\n", ChrPtr(Buf)); + TestRevalidateStrBuf(Buf); Buf2 = NewStrBuf(); while (HaveNextToken = StrBufHaveNextToken(Buf, &pCh), @@ -139,9 +151,11 @@ static void NextTokenizerIterateBuf(StrBuf *Buf, int NTokens) printf("Token: >%s< >%s< %ld:%ld\n", ChrPtr(Buf2), - ((pCh != NULL) && (pCh != NotNull))? pCh : "N/A", + ((pCh != NULL) && (pCh != StrBufNOTNULL))? pCh : "N/A", HaveNextToken, HaveNextTokenF); + TestRevalidateStrBuf(Buf2); + CU_ASSERT(HaveNextToken == (HaveNextTokenF >= 0)); CU_ASSERT(CountTokens <= NTokens); @@ -196,105 +210,35 @@ static void TestNextTokenizer_One(void) -static void testSuccessAssertTrue(void) -{ - CU_ASSERT_TRUE(CU_TRUE); - CU_ASSERT_TRUE(!CU_FALSE); -} - -static void testSuccessAssertFalse(void) -{ - CU_ASSERT_FALSE(CU_FALSE); - CU_ASSERT_FALSE(!CU_TRUE); -} - -static void testSuccessAssertEqual(void) -{ +/* +Some samples from the original... CU_ASSERT_EQUAL(10, 10); - CU_ASSERT_EQUAL(0, 0); CU_ASSERT_EQUAL(0, -0); CU_ASSERT_EQUAL(-12, -12); -} - -static void testSuccessAssertNotEqual(void) -{ CU_ASSERT_NOT_EQUAL(10, 11); CU_ASSERT_NOT_EQUAL(0, -1); CU_ASSERT_NOT_EQUAL(-12, -11); -} - -static void testSuccessAssertPtrEqual(void) -{ CU_ASSERT_PTR_EQUAL((void*)0x100, (void*)0x100); -} - -static void testSuccessAssertPtrNotEqual(void) -{ CU_ASSERT_PTR_NOT_EQUAL((void*)0x100, (void*)0x101); -} - -static void testSuccessAssertPtrNull(void) -{ CU_ASSERT_PTR_NULL(NULL); CU_ASSERT_PTR_NULL(0x0); -} - -static void testSuccessAssertPtrNotNull(void) -{ CU_ASSERT_PTR_NOT_NULL((void*)0x23); -} - -static void testSuccessAssertStringEqual(void) -{ - char str1[] = "test" ; - char str2[] = "test" ; - CU_ASSERT_STRING_EQUAL(str1, str2); -} - -static void testSuccessAssertStringNotEqual(void) -{ - char str1[] = "test" ; - char str2[] = "testtsg" ; - CU_ASSERT_STRING_NOT_EQUAL(str1, str2); -} - -static void testSuccessAssertNStringEqual(void) -{ - char str1[] = "test" ; - char str2[] = "testgfsg" ; - CU_ASSERT_NSTRING_EQUAL(str1, str2, strlen(str1)); CU_ASSERT_NSTRING_EQUAL(str1, str1, strlen(str1)); CU_ASSERT_NSTRING_EQUAL(str1, str1, strlen(str1) + 1); -} - -static void testSuccessAssertNStringNotEqual(void) -{ - char str1[] = "test" ; - char str2[] = "teet" ; - char str3[] = "testgfsg" ; - CU_ASSERT_NSTRING_NOT_EQUAL(str1, str2, 3); CU_ASSERT_NSTRING_NOT_EQUAL(str1, str3, strlen(str1) + 1); -} - -static void testSuccessAssertDoubleEqual(void) -{ CU_ASSERT_DOUBLE_EQUAL(10, 10.0001, 0.0001); CU_ASSERT_DOUBLE_EQUAL(10, 10.0001, -0.0001); CU_ASSERT_DOUBLE_EQUAL(-10, -10.0001, 0.0001); CU_ASSERT_DOUBLE_EQUAL(-10, -10.0001, -0.0001); -} - -static void testSuccessAssertDoubleNotEqual(void) -{ CU_ASSERT_DOUBLE_NOT_EQUAL(10, 10.001, 0.0001); CU_ASSERT_DOUBLE_NOT_EQUAL(10, 10.001, -0.0001); CU_ASSERT_DOUBLE_NOT_EQUAL(-10, -10.001, 0.0001); CU_ASSERT_DOUBLE_NOT_EQUAL(-10, -10.001, -0.0001); -} +*/ static void AddTests(void) { diff --git a/libcitadel/tests/stringbuf_test.h b/libcitadel/tests/stringbuf_test.h index 5199378bc..adea2ed68 100644 --- a/libcitadel/tests/stringbuf_test.h +++ b/libcitadel/tests/stringbuf_test.h @@ -3,6 +3,7 @@ #define CUNIT_AUTOMATED_H_SEEN #include +#include #include