2 * common part of test units.
9 #include "../qrencode.h"
10 #include "../qrinput.h"
11 #include "../bitstream.h"
12 #include "../qrencode_inner.h"
14 #define testStart(__arg__) (testStartReal(__func__, __arg__))
15 #define testEndExp(__arg__) (testEnd(!(__arg__)))
18 static int failed = 0;
19 static int assertionFailed = 0;
20 static int assertionNum = 0;
21 static const char *testName = NULL;
22 static const char *testFunc = NULL;
23 char levelChar[4] = {'L', 'M', 'Q', 'H'};
24 const char *modeStr[5] = {"nm", "an", "8", "kj", "st"};
26 void printQRinput(QRinput *input)
35 for(i=0; i<list->size; i++) {
36 printf("0x%02x,", list->data[i]);
43 void printQRinputInfo(QRinput *input)
49 printf("QRinput info:\n");
50 printf(" version: %d\n", input->version);
51 printf(" level : %c\n", levelChar[input->level]);
58 printf(" chunks: %d\n", i);
59 b = QRinput_mergeBitStream(input);
61 printf(" bitstream-size: %d\n", BitStream_size(b));
68 printf("\t#%d: mode = %s, size = %d\n", i, modeStr[list->mode], list->size);
74 void testStartReal(const char *func, const char *name)
81 printf("_____%d: %s: %s...\n", tests, func, name);
84 void testEnd(int result)
86 printf(".....%d: %s: %s, ", tests, testFunc, testName);
95 #define assert_exp(__exp__, ...) \
96 {assertionNum++;if(!(__exp__)) {assertionFailed++; printf(__VA_ARGS__);}}
98 #define assert_zero(__exp__, ...) assert_exp((__exp__) == 0, __VA_ARGS__)
99 #define assert_nonzero(__exp__, ...) assert_exp((__exp__) != 0, __VA_ARGS__)
100 #define assert_null(__ptr__, ...) assert_exp((__ptr__) == NULL, __VA_ARGS__)
101 #define assert_nonnull(__ptr__, ...) assert_exp((__ptr__) != NULL, __VA_ARGS__)
102 #define assert_equal(__e1__, __e2__, ...) assert_exp((__e1__) == (__e2__), __VA_ARGS__)
103 #define assert_notequal(__e1__, __e2__, ...) assert_exp((__e1__) != (__e2__), __VA_ARGS__)
104 #define assert_nothing(__exp__, ...) {printf(__VA_ARGS__); __exp__;}
106 void testFinish(void)
108 printf(".....%d: %s: %s, ", tests, testFunc, testName);
109 if(assertionFailed) {
110 printf("FAILED. (%d assertions failed.)\n", assertionFailed);
113 printf("PASSED. (%d assertions passed.)\n", assertionNum);
119 printf("Total %d tests, %d fails.\n", tests, failed);
123 int ncmpBin(char *correct, BitStream *bstream, int len)
127 if(len != BitStream_size(bstream)) {
128 printf("Length is not match: %d, %d expected.\n", BitStream_size(bstream), len);
132 for(i=0; i<len; i++) {
133 bit = (correct[i] == '1')?1:0;
134 if(bstream->data[i] != bit) return -1;
140 int cmpBin(char *correct, BitStream *bstream)
144 len = strlen(correct);
145 return ncmpBin(correct, bstream, len);
148 char *sprintfBin(int size, unsigned char *data)
155 str = (char *)malloc(size + 1);
188 static char qrModeChar[4] = {'n', 'a', '8', 'k'};
189 void printQrinput(QRinput *input)
194 while(list != NULL) {
195 printf("%c(%d)\n", qrModeChar[list->mode], list->size);
199 #endif /* __COMMON_H__ */