# HG changeset patch # User websnarf <github@azillionmonkeys.com> # Date 1446598286 28800 # Tue Nov 03 16:51:26 2015 -0800 # Node ID bf03e83698290370e5dd7d3f0d915dd0fc6f3674 # Parent 31cc8aaa76bf42fdb4dc6543de315cb238634586 Add the experimental macro: bDeclTbstr diff --git a/test.cpp b/test.cpp --- a/test.cpp +++ b/test.cpp @@ -11,6 +11,10 @@ // This file is the C++ unit test for Bstrlib // +#if defined (_MSC_VER) +# define _CRT_SECURE_NO_WARNINGS +#endif + #include <stdio.h> #include <stdarg.h> #include "bstrlib.h" @@ -23,7 +27,7 @@ static bstring dumpOut[dumpOutQty]; static unsigned int rot = 0; -char * dumpBstring (const bstring b) { +const char * dumpBstring (const bstring b) { rot = (rot + 1) % (unsigned) dumpOutQty; if (dumpOut[rot] == NULL) { dumpOut[rot] = bfromcstr (""); @@ -61,7 +65,7 @@ } } } - return (char *) dumpOut[rot]->data; + return (const char *) dumpOut[rot]->data; } int test0 (void) { @@ -1613,6 +1617,66 @@ #define bMultiConcat(dst,...) bMultiConcatNeedNULLAsLastArgument((dst),##__VA_ARGS__,NULL) #define bMultiCatCstr(dst,...) bMultiCatCstrNeedNULLAsLastArgument((dst),##__VA_ARGS__,NULL) +#define bGlue3_aux(a,b,c) a ## b ## c +#define bGlue3(a,b,c) bGlue3_aux(a,b,c) + +#if defined(_MSC_VER) +#define _bDeclTbstrIdx(t,n,...) \ + static unsigned char bGlue3(_btmpuc_,t,n)[] = {__VA_ARGS__, '\0'}; \ + struct tagbstring t = { -32, sizeof(bGlue3(_btmpuc_,t,n))-1, bGlue3(_btmpuc_,t,n)} +#define bDeclTbstr(t,...) _bDeclTbstrIdx(t,__COUNTER__,__VA_ARGS__) +#else +#define bDeclTbstr(t,...) \ + static unsigned char bGlue3(_btmpuc_,t,__LINE__)[] = {__VA_ARGS__, '\0'}; \ + struct tagbstring t = { -__LINE__, sizeof(bGlue3(_btmpuc_,t,__LINE__))-1, bGlue3(_btmpuc_,t,__LINE__)} +#endif + +static int test32(void) { +bstring b1 = bfromStatic ("a"); +bstring b2 = bfromStatic ("e"); +bstring b3 = bfromStatic ("i"); +bstring b4 = bfromStatic (""); +int ret = 0; + + printf ("TEST: bMultiCatCstr, bMultiConcat\n"); + + bMultiCatCstr(b1, "b", "c", "d"); + bMultiCatCstr(b2, "f", "g", "h"); + bMultiCatCstr(b3, "j", "k", "l"); + bMultiConcat(b4, b1, b2, b3); + + ret += 1 != biseqStatic (b1, "abcd"); + ret += 1 != biseqStatic (b2, "efgh"); + ret += 1 != biseqStatic (b3, "ijkl"); + ret += 1 != biseqStatic (b4, "abcdefghijkl"); + + bdestroy (b1); + bdestroy (b2); + bdestroy (b3); + bdestroy (b4); + + printf ("\t# failures: %d\n", ret); + return ret; +} + +static int test33(void) { + bDeclTbstr (t1, 'H','e','l','l','o'); + bDeclTbstr (t2, 32,'w','o','r','l','d'); + bstring b = bfromStatic("["); + int ret; + + printf ("TEST: bDeclTbstr\n"); + + bconcat (b, &t1); + bconcat (b, &t2); + bcatStatic (b, "]"); + ret = 1 != biseqStatic (b, "[Hello world]"); + bdestroy (b); + + printf ("\t# failures: %d\n", ret); + return ret; +} + int main () { int ret = 0; @@ -1652,6 +1716,8 @@ ret += test29 (); ret += test30 (); ret += test31 (); + ret += test32 (); + ret += test33 (); printf ("# test failures: %d\n", ret);