void test_split2(void) { QRinput *input; QRinput_List *list; int err = 0; testStart("Split test: single typed strings (num)"); input = QRinput_new2(0, QR_ECLEVEL_L); Split_splitStringToQRinput("0123", input, QR_MODE_8, 0); list = input->head; if(inputTest(list, "n", 4)) { err++; } testEnd(err); QRinput_free(input); err = 0; testStart("Split test: single typed strings (num2)"); input = QRinput_new2(0, QR_ECLEVEL_L); Split_splitStringToQRinput("12345678901234567890", input, QR_MODE_KANJI, 0); list = input->head; if(inputTest(list, "n", 20)) { err++; } testEnd(err); QRinput_free(input); }
void test_toupper(void) { QRinput *input; QRinput_List *list; int err = 0; testStart("Split test: check dupAndToUpper (lower->upper)"); input = QRinput_new2(0, QR_ECLEVEL_L); Split_splitStringToQRinput("abcde", input, QR_MODE_8, 0); list = input->head; if(inputTest(list, "a", 5)) { err++; } if(strncmp((char *)list->data, "ABCDE", list->size)) { err++; } testEnd(err); QRinput_free(input); err = 0; testStart("Split test: check dupAndToUpper (kanji)"); input = QRinput_new2(0, QR_ECLEVEL_L); Split_splitStringToQRinput("\x83n\x83q\x83t\x83w\x83z", input, QR_MODE_KANJI, 0); list = input->head; if(inputTest(list, "k", 10)) { printQRinputInfo(input); err++; } if(strncmp((char *)list->data, "\x83n\x83q\x83t\x83w\x83z", list->size)) { err++; } testEnd(err); QRinput_free(input); err = 0; testStart("Split test: check dupAndToUpper (8bit)"); input = QRinput_new2(0, QR_ECLEVEL_L); Split_splitStringToQRinput("\x83n\x83q\x83t\x83w\x83z", input, QR_MODE_8, 0); list = input->head; if(inputTest(list, "8", 10)) { printQRinputInfo(input); err++; } if(strncmp((char *)list->data, "\x83N\x83Q\x83T\x83W\x83Z", list->size)) { err++; } testEnd(err); QRinput_free(input); }
void test_encode(void) { QRinput *stream; char num[9] = "01234567"; unsigned char *frame; int err = 0; int x, y, w; int mask; QRcode *qrcode; testStart("Test encode (1-M)"); stream = QRinput_new(); QRinput_append(stream, QR_MODE_NUM, 8, (unsigned char *)num); for(mask=0; mask<8; mask++) { QRinput_setVersion(stream, 1); QRinput_setErrorCorrectionLevel(stream, QR_ECLEVEL_M); qrcode = QRcode_encodeMask(stream, mask); w = qrcode->width; frame = qrcode->data; for(y=0; y<w; y++) { for(x=0; x<w; x++) { if(((m1pat[mask][y] >> (20-x)) & 1) != (frame[y*w+x]&1)) { printf("Diff in mask=%d (%d,%d)\n", mask, x, y); err++; } } } QRcode_free(qrcode); } QRinput_free(stream); testEnd(err); }
void test_format(void) { unsigned int format; int version, l, mask; int type; int err = 0; testStart("Format info test"); for(version=1; version<=MQRSPEC_VERSION_MAX; version++) { for(l=QR_ECLEVEL_L; l<=QR_ECLEVEL_Q; l++) { for(mask=0; mask<4; mask++) { format = MQRspec_getFormatInfo(mask, version, (QRecLevel)l); type = typeTable[version - 1][l]; if(type == -1) { if(format != 0) { printf("Error in version %d, level %d, mask %d\n", version, l, mask); err++; } } else { if(format != calcFormatInfo(type, mask)) { printf("Error in version %d, level %d, mask %d\n", version, l, mask); err++; } } } } } testEnd(err); }
void test_encodeNumericPadded2(void) { QRinput *stream; char num[8] = "0123456"; char *correct; char *correctHead = "000100000001110000001100010101100101100000000000"; BitStream *bstream; int flag, i; testStart("Encoding numeric stream. (7 digits)(padded)"); stream = QRinput_new(); QRinput_append(stream, QR_MODE_NUM, 7, (unsigned char *)num); bstream = QRinput_getBitStream(stream); correct = (char *)malloc(19 * 8 + 1); correct[0] = '\0'; strcat(correct, correctHead); for(i=0; i<13; i++) { strcat(correct, (i&1)?"00010001":"11101100"); } flag = cmpBin(correct, bstream); testEnd(flag); free(correct); QRinput_free(stream); BitStream_free(bstream); }
void test_eccTable(void) { int i, j; int ecc; int data; int err = 0; int spec[5]; testStart("Checking ECC table."); for(i=1; i<=QRSPEC_VERSION_MAX; i++) { for(j=0; j<4; j++) { QRspec_getEccSpec(i, (QRecLevel)j, spec); data = QRspec_rsBlockNum1(spec) * QRspec_rsDataCodes1(spec) + QRspec_rsBlockNum2(spec) * QRspec_rsDataCodes2(spec); ecc = QRspec_rsBlockNum1(spec) * QRspec_rsEccCodes1(spec) + QRspec_rsBlockNum2(spec) * QRspec_rsEccCodes2(spec); if(data + ecc != QRspec_getDataLength(i, (QRecLevel)j) + QRspec_getECCLength(i, (QRecLevel)j)) { printf("Error in version %d, level %d: invalid size\n", i, j); printf("%d %d %d %d %d %d\n", spec[0], spec[1], spec[2], spec[3], spec[4], spec[2]); err++; } if(ecc != QRspec_getECCLength(i, (QRecLevel)j)) { printf("Error in version %d, level %d: invalid data\n", i, j); printf("%d %d %d %d %d %d\n", spec[0], spec[1], spec[2], spec[3], spec[4], spec[2]); err++; } } } testEnd(err); }
void test_iterate() { int i; QRinput *stream; char num[9] = "01234567"; unsigned char *data; QRRawCode *raw; int err = 0; testStart("Test getCode (1-L)"); stream = QRinput_new(); QRinput_setVersion(stream, 1); QRinput_setErrorCorrectionLevel(stream, QR_ECLEVEL_L); QRinput_append(stream, QR_MODE_NUM, 8, (unsigned char *)num); raw = QRraw_new(stream); data = raw->datacode; for(i=0; i<raw->dataLength; i++) { if(data[i] != QRraw_getCode(raw)) { err++; } } QRinput_free(stream); QRraw_free(raw); testEnd(err); }
void test_encodeAn(void) { char *str = "AC-42"; char correct[] = "00100000001010011100111011100111001000010"; testStart("Encoding alphabet-numeric stream."); testEnd(mergeAndCheckBStream(0, QR_MODE_AN, str, correct)); }
void test_encode8(void) { char str[] = "AC-42"; char correct[] = "0100000001010100000101000011001011010011010000110010"; testStart("Encoding 8bit stream."); testEnd(mergeAndCheckBStream(0, QR_MODE_8, str, correct)); }
void test_encodeKanji(void) { char str[5]= {0x93, 0x5f,0xe4, 0xaa, 0x00}; char *correct = "10000000001001101100111111101010101010"; testStart("Encoding kanji stream."); testEnd(mergeAndCheckBStream(0, QR_MODE_KANJI, str, correct)); }
void test_encodeNumeric3(void) { char *str = "0123456"; char *correct = "0001 0000000111 0000001100 0101011001 0110"; testStart("Encoding numeric stream. (7 digits)"); testEnd(mergeAndCheckBStream(0, QR_MODE_NUM, str, correct)); }
void test_bitstream_length() { struct TestSet *ts = testset; int err = 0; testStart("Split_URL test: compare bitstream length"); while(ts->url != NULL) { err += encodeURLandCompare(ts->url, ts->expected_length); ts++; } testEnd(err); }
void test_bytes(void) { BitStream *bstream; unsigned char data[1] = {0x3a}; char correct[] = "00111010"; testStart("New from bytes"); bstream = BitStream_new(); BitStream_appendBytes(bstream, 1, data); testEnd(cmpBin(correct, bstream)); BitStream_free(bstream); }
void test_encodeAn2(void) { QRinput *stream; char str[] = "!,;$%"; int ret; testStart("Encoding INVALID alphabet-numeric stream."); stream = QRinput_new(); ret = QRinput_append(stream, QR_MODE_AN, 5, (unsigned char *)str); testEnd(!ret); QRinput_free(stream); }
void test_split3c(void) { QRinput *input; QRinput_List *list; int err = 0; testStart("Split test: single typed strings (an, case-sensitive)"); input = QRinput_new2(0, QR_ECLEVEL_L); Split_splitStringToQRinput("ab:-E", input, QR_MODE_8, 1); list = input->head; if(inputTest(list, "8", 5)) { err++; } testEnd(err); QRinput_free(input); err = 0; testStart("Split test: num + an"); input = QRinput_new2(0, QR_ECLEVEL_L); Split_splitStringToQRinput("0123abcde", input, QR_MODE_KANJI, 1); list = input->head; if(inputTest(list, "n8", 4, 5)) { err++; } testEnd(err); QRinput_free(input); err = 0; testStart("Split test: an + num + an"); input = QRinput_new2(0, QR_ECLEVEL_L); Split_splitStringToQRinput("Ab345fg", input, QR_MODE_KANJI, 1); list = input->head; if(inputTest(list, "8", 7)) { printQRinputInfo(input); err++; } testEnd(err); QRinput_free(input); }
void test_num(void) { BitStream *bstream; unsigned int data = 0x13579bdf; char correct[] = "0010011010101111001101111011111"; testStart("New from num"); bstream = BitStream_new(); BitStream_appendNum(bstream, 31, data); testEnd(cmpBin(correct, bstream)); BitStream_free(bstream); }
void test_encodeNumeric(void) { QRinput *stream; char num[9] = "01234567"; char correct[] = "00010000001000000000110001010110011000011"; BitStream *bstream; testStart("Encoding numeric stream. (8 digits)"); stream = QRinput_new(); QRinput_append(stream, QR_MODE_NUM, 8, (unsigned char *)num); bstream = QRinput_mergeBitStream(stream); testEnd(cmpBin(correct, bstream)); QRinput_free(stream); BitStream_free(bstream); }
void test_encodeAn(void) { QRinput *stream; char str[] = "AC-42"; char correct[] = "00100000001010011100111011100111001000010"; BitStream *bstream; testStart("Encoding alphabet-numeric stream."); stream = QRinput_new(); QRinput_append(stream, QR_MODE_AN, 5, (unsigned char *)str); bstream = QRinput_mergeBitStream(stream); testEnd(cmpBin(correct, bstream)); QRinput_free(stream); BitStream_free(bstream); }
void test_encode3(void) { QRcode *code1, *code2; QRinput *input; testStart("Compare encodeString and encodeInput"); code1 = QRcode_encodeString("0123456", 0, QR_ECLEVEL_L, QR_MODE_8, 0); input = QRinput_new2(0, QR_ECLEVEL_L); QRinput_append(input, QR_MODE_NUM, 7, (unsigned char *)"0123456"); code2 = QRcode_encodeInput(input); testEnd(memcmp(code1->data, code2->data, code1->width * code1->width)); QRcode_free(code1); QRcode_free(code2); QRinput_free(input); }
void test_split8(void) { QRinput *input; QRinput_List *list; int err = 0; testStart("Split test: terminated with a half of kanji code"); input = QRinput_new2(0, QR_ECLEVEL_L); Split_splitStringToQRinput("\x82\xd9""abcdefgh\x82", input, QR_MODE_KANJI, 0); list = input->head; if(inputTest(list, "ka8", 2, 8, 1)) { err++; } testEnd(err); QRinput_free(input); }
void test_split7(void) { QRinput *input; QRinput_List *list; int err = 0; testStart("Split test: an and num as bits"); input = QRinput_new2(0, QR_ECLEVEL_L); Split_splitStringToQRinput("\x82\xd9""abcde\x82\xb0""12345", input, QR_MODE_8, 0); list = input->head; if(inputTest(list, "8n", 9, 5)) { err++; } testEnd(err); QRinput_free(input); }
void test_split5(void) { QRinput *input; QRinput_List *list; int err = 0; testStart("Split test: bit, an, bit, num"); input = QRinput_new2(0, QR_ECLEVEL_L); Split_splitStringToQRinput("\x82\xd9""abcdeabcdea\x82\xb0""123456", input, QR_MODE_8, 0); list = input->head; if(inputTest(list, "8a8n", 2, 11, 2, 6)) { err++; } testEnd(err); QRinput_free(input); }
void test_splitNum8(void) { QRinput *input; QRinput_List *list; int err = 0; testStart("Split test: num and 8bit to 8bit"); input = QRinput_new2(0, QR_ECLEVEL_L); Split_splitStringToQRinput("1abcdefg", input, QR_MODE_8, 1); list = input->head; if(inputTest(list, "8", 8)) { err++; printQRinputInfo(input); } testEnd(err); QRinput_free(input); }
void test_split6(void) { QRinput *input; QRinput_List *list; int err = 0; testStart("Split test: kanji, an, kanji, num"); input = QRinput_new2(0, QR_ECLEVEL_L); Split_splitStringToQRinput("\x82\xd9""abcdeabcdea\x82\xb0""123456", input, QR_MODE_KANJI, 0); list = input->head; if(inputTest(list, "kakn", 2, 11, 2, 6)) { printQRinputInfo(input); err++; } testEnd(err); QRinput_free(input); }
void test_dataLength(void) { int v, l; int bits; int err = 0; testStart("Test dataLength"); for(v=0; v<4; v++) { for(l=0; l<3; l++) { bits = MQRspec_getDataLengthBit(v+1, (QRecLevel)l); if(bits != datalen[v][l]) { printf("Error in version %d, level %d.\n", v, l); err++; } } } testEnd(err); }
void test_iterate2() { int i; QRinput *stream; char num[9] = "01234567"; QRRawCode *raw; int err = 0; unsigned char correct[] = { 0x10, 0x11, 0xec, 0xec, 0x20, 0xec, 0x11, 0x11, 0x0c, 0x11, 0xec, 0xec, 0x56, 0xec, 0x11, 0x11, 0x61, 0x11, 0xec, 0xec, 0x80, 0xec, 0x11, 0x11, 0xec, 0x11, 0xec, 0xec, 0x11, 0xec, 0x11, 0x11, 0xec, 0x11, 0xec, 0xec, 0x11, 0xec, 0x11, 0x11, 0xec, 0x11, 0xec, 0xec, 0x11, 0x11, 0x5c, 0xde, 0x68, 0x68, 0x4d, 0xb3, 0xdb, 0xdb, 0xd5, 0x14, 0xe1, 0xe1, 0x5b, 0x2a, 0x1f, 0x1f, 0x49, 0xc4, 0x78, 0x78, 0xf7, 0xe0, 0x5b, 0x5b, 0xc3, 0xa7, 0xc1, 0xc1, 0x5d, 0x9a, 0xea, 0xea, 0x48, 0xad, 0x9d, 0x9d, 0x58, 0xb3, 0x3f, 0x3f, 0x10, 0xdb, 0xbf, 0xbf, 0xeb, 0xec, 0x05, 0x05, 0x98, 0x35, 0x83, 0x83, 0xa9, 0x95, 0xa6, 0xa6, 0xea, 0x7b, 0x8d, 0x8d, 0x04, 0x3c, 0x08, 0x08, 0x64, 0xce, 0x3e, 0x3e, 0x4d, 0x9b, 0x30, 0x30, 0x4e, 0x65, 0xd6, 0xd6, 0xe4, 0x53, 0x2c, 0x2c, 0x46, 0x1d, 0x2e, 0x2e, 0x29, 0x16, 0x27, 0x27 }; testStart("Test getCode (5-H)"); stream = QRinput_new(); QRinput_setVersion(stream, 5); QRinput_setErrorCorrectionLevel(stream, QR_ECLEVEL_H); QRinput_append(stream, QR_MODE_NUM, 8, (unsigned char *)num); raw = QRraw_new(stream); for(i=0; i<raw->dataLength; i++) { if(correct[i] != QRraw_getCode(raw)) { err++; } } QRinput_free(stream); QRraw_free(raw); testEnd(err); }
static void $module$TestInitTask (TEST_STR *testStr) { /* S'initialiser comme client */ printf ("client init ..."); if (csClientInit ($MODULE$_MBOX_NAME, $MODULE$_MAX_RQST_SIZE, $MODULE$_MAX_INTERMED_REPLY_SIZE, $MODULE$_MAX_REPLY_SIZE, &TEST_CID(testStr)) != OK) { (void) h2perror("Client init failed"); testEnd(testStr); } /* S'initialiser comme client des posters */ printf ("ok. Poster init ..."); if ($module$PosterInit () != OK) h2perror ("Warning: not found all $module$'s posters"); printf ("ok."); }
void test_encodeNumericPadded2(void) { char *str = "0123456"; char *correct; char *correctHead = "000100000001110000001100010101100101100000000000"; int i, ret; testStart("Encoding numeric stream. (7 digits)(padded)"); correct = (char *)malloc(19 * 8 + 1); correct[0] = '\0'; strcat(correct, correctHead); for(i=0; i<13; i++) { strcat(correct, (i&1)?"00010001":"11101100"); } ret = encodeAndCheckBStream(0, 0, QR_ECLEVEL_L, QR_MODE_NUM, str, correct); testEnd(ret); free(correct); }
void test_encodeKanji(void) { QRinput *stream; unsigned char str[4]= {0x93, 0x5f,0xe4, 0xaa}; unsigned char *buf; char correct[] = "10000000001001101100111111101010101010"; BitStream *bstream; testStart("Encoding kanji stream."); buf = (unsigned char *)malloc(4); memcpy(buf, str, 4); stream = QRinput_new(); QRinput_append(stream, QR_MODE_KANJI, 4, buf); bstream = QRinput_mergeBitStream(stream); testEnd(cmpBin(correct, bstream)); QRinput_free(stream); BitStream_free(bstream); free(buf); }
void test_01234567(void) { QRinput *stream; char num[9] = "01234567"; int i, err = 0; QRcode *qrcode; unsigned char correct[] = { 0xc1, 0xc1, 0xc1, 0xc1, 0xc1, 0xc1, 0xc1, 0xc0, 0x84, 0x03, 0x02, 0x03, 0x03, 0xc0, 0xc1, 0xc1, 0xc1, 0xc1, 0xc1, 0xc1, 0xc1, 0xc1, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc1, 0xc0, 0x84, 0x03, 0x03, 0x03, 0x03, 0xc0, 0xc1, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc1, 0xc1, 0xc0, 0xc1, 0xc1, 0xc1, 0xc0, 0xc1, 0xc0, 0x85, 0x02, 0x02, 0x02, 0x02, 0xc0, 0xc1, 0xc0, 0xc1, 0xc1, 0xc1, 0xc0, 0xc1, 0xc1, 0xc0, 0xc1, 0xc1, 0xc1, 0xc0, 0xc1, 0xc0, 0x85, 0x03, 0x02, 0x02, 0x02, 0xc0, 0xc1, 0xc0, 0xc1, 0xc1, 0xc1, 0xc0, 0xc1, 0xc1, 0xc0, 0xc1, 0xc1, 0xc1, 0xc0, 0xc1, 0xc0, 0x85, 0x02, 0x03, 0x03, 0x03, 0xc0, 0xc1, 0xc0, 0xc1, 0xc1, 0xc1, 0xc0, 0xc1, 0xc1, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc1, 0xc0, 0x85, 0x02, 0x02, 0x02, 0x03, 0xc0, 0xc1, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc1, 0xc1, 0xc1, 0xc1, 0xc1, 0xc1, 0xc1, 0xc1, 0xc0, 0x91, 0x90, 0x91, 0x90, 0x91, 0xc0, 0xc1, 0xc1, 0xc1, 0xc1, 0xc1, 0xc1, 0xc1, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0x85, 0x02, 0x02, 0x03, 0x03, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0x85, 0x84, 0x85, 0x85, 0x85, 0x85, 0x91, 0x84, 0x84, 0x03, 0x02, 0x02, 0x03, 0x84, 0x85, 0x85, 0x85, 0x85, 0x85, 0x84, 0x84, 0x02, 0x02, 0x02, 0x03, 0x02, 0x03, 0x90, 0x03, 0x03, 0x02, 0x03, 0x02, 0x03, 0x02, 0x02, 0x03, 0x02, 0x03, 0x03, 0x02, 0x02, 0x02, 0x02, 0x03, 0x02, 0x02, 0x02, 0x91, 0x03, 0x02, 0x03, 0x02, 0x03, 0x02, 0x03, 0x02, 0x02, 0x03, 0x03, 0x03, 0x03, 0x03, 0x02, 0x02, 0x02, 0x02, 0x03, 0x02, 0x90, 0x02, 0x02, 0x03, 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, 0x03, 0x03, 0x03, 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, 0x03, 0x03, 0x91, 0x03, 0x03, 0x02, 0x02, 0x03, 0x02, 0x03, 0x02, 0x02, 0x03, 0x02, 0x02, 0x02, 0x02, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0x81, 0x02, 0x03, 0x03, 0x03, 0x03, 0x03, 0x02, 0x02, 0x03, 0x03, 0x02, 0x02, 0xc1, 0xc1, 0xc1, 0xc1, 0xc1, 0xc1, 0xc1, 0xc0, 0x84, 0x03, 0x03, 0x02, 0x03, 0x02, 0x03, 0x03, 0x02, 0x02, 0x02, 0x02, 0x02, 0xc1, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc1, 0xc0, 0x85, 0x02, 0x03, 0x03, 0x03, 0x03, 0x03, 0x02, 0x02, 0x02, 0x03, 0x02, 0x03, 0xc1, 0xc0, 0xc1, 0xc1, 0xc1, 0xc0, 0xc1, 0xc0, 0x85, 0x02, 0x02, 0x02, 0x03, 0x02, 0x02, 0x03, 0x02, 0x03, 0x03, 0x02, 0x02, 0xc1, 0xc0, 0xc1, 0xc1, 0xc1, 0xc0, 0xc1, 0xc0, 0x85, 0x03, 0x02, 0x02, 0x03, 0x02, 0x02, 0x03, 0x02, 0x02, 0x02, 0x02, 0x02, 0xc1, 0xc0, 0xc1, 0xc1, 0xc1, 0xc0, 0xc1, 0xc0, 0x85, 0x02, 0x03, 0x03, 0x02, 0x03, 0x02, 0x02, 0x03, 0x02, 0x03, 0x02, 0x02, 0xc1, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc1, 0xc0, 0x84, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, 0x03, 0x02, 0x03, 0x03, 0x02, 0xc1, 0xc1, 0xc1, 0xc1, 0xc1, 0xc1, 0xc1, 0xc0, 0x85, 0x03, 0x03, 0x03, 0x02, 0x03, 0x02, 0x02, 0x03, 0x02, 0x03, 0x02, 0x02}; testStart("Encode 01234567 in 1-M"); stream = QRinput_new2(1, QR_ECLEVEL_M); QRinput_append(stream, QR_MODE_NUM, 8, (unsigned char *)num); qrcode = QRcode_encodeInput(stream); for(i=0; i<qrcode->width * qrcode->width; i++) { if(qrcode->data[i] != correct[i]) { err++; } } testEnd(err); QRinput_free(stream); QRcode_free(qrcode); }