Skip to content
Snippets Groups Projects
Commit 94b3528f authored by Mark Grondona's avatar Mark Grondona
Browse files

o define TEST macro to clean up body of main render tests clearer

parent 00f975dd
No related branches found
No related tags found
No related merge requests found
...@@ -14,6 +14,17 @@ ...@@ -14,6 +14,17 @@
#include <src/common/pack.h> #include <src/common/pack.h>
#include <src/common/xmalloc.h> #include <src/common/xmalloc.h>
/* Test for failure:
*/
#define TEST(_tst, _msg) do { \
if (_tst) { \
printf("%s\n", _msg); \
failed++; \
} else \
passed++; \
} while (0)
int main (int argc, char *argv[]) int main (int argc, char *argv[])
{ {
int passed = 0; int passed = 0;
...@@ -35,51 +46,37 @@ int main (int argc, char *argv[]) ...@@ -35,51 +46,37 @@ int main (int argc, char *argv[])
packstr(testbytes, &bufp, &len_buf); packstr(testbytes, &bufp, &len_buf);
packstr(teststring, &bufp, &len_buf); packstr(teststring, &bufp, &len_buf);
packstr(nullstr, &bufp, &len_buf); packstr(nullstr, &bufp, &len_buf);
packstr("literal", &bufp, &len_buf);
packstr("", &bufp, &len_buf);
printf("wrote %d bytes\n", len_buf); printf("wrote %d bytes\n", len_buf);
bufp = buffer; bufp = buffer;
len_buf = sizeof(buffer); len_buf = sizeof(buffer);
unpack16(&out16, &bufp, &len_buf); unpack16(&out16, &bufp, &len_buf);
TEST(out16 != test16, "un/pack16 failed");
if (out16 != test16) {
printf("un/pack16 failed\n");
failed++;
} else
passed++;
unpack32(&out32, &bufp, &len_buf); unpack32(&out32, &bufp, &len_buf);
TEST(out32 != test32, "un/pack32 failed");
if (out32 != test32) {
printf("un/pack32 failed\n");
failed++;
} else
passed++;
unpackstr_ptr(&outbytes, &byte_cnt, &bufp, &len_buf); unpackstr_ptr(&outbytes, &byte_cnt, &bufp, &len_buf);
TEST(strcmp(testbytes, outbytes) != 0, "un/packstr_ptr failed");
if (strcmp(testbytes, outbytes) != 0) {
printf("un/packstr_ptr failed\n");
failed++;
} else
passed++;
unpackstr_xmalloc(&outstring, &byte_cnt, &bufp, &len_buf); unpackstr_xmalloc(&outstring, &byte_cnt, &bufp, &len_buf);
TEST(strcmp(teststring, outstring) != 0, "un/packstr_xmalloc failed");
if (strcmp(teststring, outstring) != 0) { xfree(outstring);
printf("un/packstr_xmalloc failed\n");
failed++;
} else {
passed++;
xfree(outstring);
}
unpackstr_xmalloc(&nullstr, &byte_cnt, &bufp, &len_buf); unpackstr_xmalloc(&nullstr, &byte_cnt, &bufp, &len_buf);
TEST(nullstr != NULL, "un/packstr of null string failed.");
unpackstr_xmalloc(&outstring, &byte_cnt, &bufp, &len_buf);
TEST(strcmp("literal", outstring) != 0,
"un/packstr of string literal failed");
xfree(outstring);
unpackstr_xmalloc(&outstring, &byte_cnt, &bufp, &len_buf);
TEST(strcmp("", outstring) != 0, "un/packstr of string \"\" failed");
xfree(outstring);
if (nullstr != NULL) {
printf("un/packstr of null string failed\n");
failed++;
} else
passed++;
printf("%d tests passed, %d failed.\n", passed, failed); printf("%d tests passed, %d failed.\n", passed, failed);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment