Skip to content
Snippets Groups Projects
Commit bf03e8369829 authored by websnarf's avatar websnarf
Browse files

Add the experimental macro: bDeclTbstr

parent 31cc8aaa76bf
Branches
No related tags found
No related merge requests found
...@@ -11,6 +11,10 @@ ...@@ -11,6 +11,10 @@
// This file is the C++ unit test for Bstrlib // This file is the C++ unit test for Bstrlib
// //
#if defined (_MSC_VER)
# define _CRT_SECURE_NO_WARNINGS
#endif
#include <stdio.h> #include <stdio.h>
#include <stdarg.h> #include <stdarg.h>
#include "bstrlib.h" #include "bstrlib.h"
...@@ -23,7 +27,7 @@ ...@@ -23,7 +27,7 @@
static bstring dumpOut[dumpOutQty]; static bstring dumpOut[dumpOutQty];
static unsigned int rot = 0; static unsigned int rot = 0;
char * dumpBstring (const bstring b) { const char * dumpBstring (const bstring b) {
rot = (rot + 1) % (unsigned) dumpOutQty; rot = (rot + 1) % (unsigned) dumpOutQty;
if (dumpOut[rot] == NULL) { if (dumpOut[rot] == NULL) {
dumpOut[rot] = bfromcstr (""); dumpOut[rot] = bfromcstr ("");
...@@ -61,7 +65,7 @@ ...@@ -61,7 +65,7 @@
} }
} }
} }
return (char *) dumpOut[rot]->data; return (const char *) dumpOut[rot]->data;
} }
int test0 (void) { int test0 (void) {
...@@ -1613,6 +1617,66 @@ ...@@ -1613,6 +1617,66 @@
#define bMultiConcat(dst,...) bMultiConcatNeedNULLAsLastArgument((dst),##__VA_ARGS__,NULL) #define bMultiConcat(dst,...) bMultiConcatNeedNULLAsLastArgument((dst),##__VA_ARGS__,NULL)
#define bMultiCatCstr(dst,...) bMultiCatCstrNeedNULLAsLastArgument((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 main () {
int ret = 0; int ret = 0;
...@@ -1652,6 +1716,8 @@ ...@@ -1652,6 +1716,8 @@
ret += test29 (); ret += test29 ();
ret += test30 (); ret += test30 ();
ret += test31 (); ret += test31 ();
ret += test32 ();
ret += test33 ();
printf ("# test failures: %d\n", ret); printf ("# test failures: %d\n", ret);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment