void test_encode8_versionup(void) { QRinput *stream; BitStream *bstream; char *str; int version; testStart("Encoding 8bit stream. (auto-version up test)"); str = (char *)malloc(2900); memset(str, 0xff, 2900); stream = QRinput_new(); bstream = BitStream_new(); QRinput_append(stream, QR_MODE_8, 2900, (unsigned char *)str); QRinput_mergeBitStream(stream, bstream); version = QRinput_getVersion(stream); assert_equal(version, 40, "Version is %d (40 expected).\n", version); testFinish(); QRinput_free(stream); BitStream_free(bstream); free(str); }
int mergeAndCheckBStream(int mqr, QRencodeMode mode, char *data, char *correct) { QRinput *input; BitStream *bstream; int ret; if(mqr) { input = QRinput_newMQR(1, QR_ECLEVEL_L); } else { input = QRinput_new(); } QRinput_append(input, mode, strlen(data), (unsigned char *)data); bstream = BitStream_new(); QRinput_mergeBitStream(input, bstream); ret = cmpBin(correct, bstream); QRinput_free(input); BitStream_free(bstream); return ret; }
void test_insertStructuredAppendHeader(void) { QRinput *stream; char correct[] = "0011000011111010010101000000000101000001"; BitStream *bstream; int ret; testStart("Insert a structured-append header"); stream = QRinput_new(); bstream = BitStream_new(); QRinput_append(stream, QR_MODE_8, 1, (unsigned char *)"A"); ret = QRinput_insertStructuredAppendHeader(stream, 16, 1, 0xa5); assert_zero(ret, "QRinput_insertStructuredAppendHeader() returns nonzero.\n"); QRinput_mergeBitStream(stream, bstream); assert_nonnull(bstream->data, "Bstream->data is null."); assert_zero(cmpBin(correct, bstream), "bitstream is wrong."); testFinish(); QRinput_free(stream); BitStream_free(bstream); }
void test_encodeNumeric_versionup(void) { QRinput *stream; BitStream *bstream; char *str; int version; testStart("Encoding numeric stream. (auto-version up test)"); str = (char *)malloc(1050); memset(str, '1', 1050); stream = QRinput_new2(0, QR_ECLEVEL_L); bstream = BitStream_new(); QRinput_append(stream, QR_MODE_NUM, 1050, (unsigned char *)str); QRinput_mergeBitStream(stream, bstream); version = QRinput_getVersion(stream); assert_equal(version, 14, "Version is %d (14 expected).", version); testFinish(); QRinput_free(stream); BitStream_free(bstream); free(str); }
void test_toByte(void) { BitStream *bstream; unsigned char correct[] = { 0x8a, 0xff, 0xff, 0x12, 0x34, 0x56, 0x78 }; unsigned char *result; testStart("Convert to a byte array"); bstream = BitStream_new(); BitStream_appendBytes(bstream, 1, &correct[0]); BitStream_appendBytes(bstream, 2, &correct[1]); BitStream_appendBytes(bstream, 4, &correct[3]); result = BitStream_toByte(bstream); testEnd(memcmp(correct, result, 7)); BitStream_free(bstream); free(result); }
void test_appendNum(void) { BitStream *bstream; char correct[] = "10001010 11111111 11111111 00010010001101000101011001111000"; testStart("Append Num"); bstream = BitStream_new(); BitStream_appendNum(bstream, 8, 0x0000008a); assert_zero(ncmpBin(correct, bstream, 8), "Internal data is incorrect.\n"); BitStream_appendNum(bstream, 16, 0x0000ffff); assert_zero(ncmpBin(correct, bstream, 24), "Internal data is incorrect.\n"); BitStream_appendNum(bstream, 32, 0x12345678); assert_zero(cmpBin(correct, bstream), "Internal data is incorrect.\n"); testFinish(); BitStream_free(bstream); }
void test_padding(void) { QRinput *input; BitStream *bstream; int i, size; char data[] = "0123456789ABCDeFG"; unsigned char c; testStart("Padding bit check. (less than 5 bits)"); input = QRinput_new2(0, QR_ECLEVEL_L); QRinput_append(input, QR_MODE_8, 17, (unsigned char *)data); bstream = QRinput_getBitStream(input); size = BitStream_size(bstream); assert_equal(size, 152, "# of bit is incorrect (%d != 152).\n", size); c = 0; for(i=0; i<4; i++) { c += bstream->data[size - i - 1]; } assert_zero(c, "Padding bits are not zero."); testFinish(); QRinput_free(input); BitStream_free(bstream); }
void test_encode_an(int num) { int ret; int len; len = fillANData(); QRcode *qrcode; QRdata *qrdata; FILE *fp; char buf[256]; qrcode = QRcode_encodeString((char *)data, 0, num % 4, QR_MODE_8, num % 2); if(qrcode == NULL) { if(errno == ERANGE) return; perror("test_encode_an aborted at QRcode_encodeString():"); printf("Length: %d\n", len); printf("Level: %d\n", num % 4); return; } qrdata = QRcode_decode(qrcode); if(qrdata == NULL) { printf("#%d: Failed to decode this code.\n", num); QRcode_free(qrcode); return; } if(qrdata->size != len) { printf("#%d: length mismatched (orig: %d, decoded: %d)\n", num, len, qrdata->size); } ret = memcmp(qrdata->data, data, len); if(ret != 0) { unsigned char *frame, *p; int x,y, c; QRinput *input; QRcode *origcode; BitStream *bstream; int spec[5]; printf("#%d: data mismatched.\n", num); printf("Version: %d\n", qrcode->version); QRspec_getEccSpec(qrcode->version, num%4, spec); printf("DataLength: %d\n", QRspec_rsDataLength(spec)); printf("BlockNum1: %d\n", QRspec_rsBlockNum1(spec)); printf("BlockNum: %d\n", QRspec_rsBlockNum(spec)); printf("DataCodes1: %d\n", QRspec_rsDataCodes1(spec)); snprintf(buf, 256, "monkey-orig-%d.dat", num); fp = fopen(buf, "w"); fputs((char *)data, fp); fclose(fp); snprintf(buf, 256, "monkey-result-%d.dat", num); fp = fopen(buf, "w"); fputs((char *)qrdata->data, fp); fclose(fp); snprintf(buf, 256, "monkey-result-unmasked-%d.dat", num); fp = fopen(buf, "w"); frame = QRcode_unmask(qrcode); p = frame; for(y=0; y<qrcode->width; y++) { for(x=0; x<qrcode->width; x++) { fputc((*p&1)?'1':'0', fp); p++; } fputc('\n', fp); } fclose(fp); free(frame); snprintf(buf, 256, "monkey-orig-unmasked-%d.dat", num); fp = fopen(buf, "w"); input = QRinput_new2(0, num % 4); Split_splitStringToQRinput((char *)data, input, QR_MODE_8, num % 2); origcode = QRcode_encodeMask(input, -2); p = origcode->data; for(y=0; y<origcode->width; y++) { for(x=0; x<origcode->width; x++) { fputc((*p&1)?'1':'0', fp); p++; } fputc('\n', fp); } fclose(fp); QRcode_free(origcode); snprintf(buf, 256, "monkey-orig-bits-%d.dat", num); fp = fopen(buf, "w"); bstream = QRinput_mergeBitStream(input); c = 0; for(x=0; x<bstream->length; x++) { fputc((bstream->data[x]&1)?'1':'0', fp); if((x & 7) == 7) { fputc(' ', fp); c++; } if((x & 63) == 63) { fprintf(fp, "%d\n", c); } } fclose(fp); QRinput_free(input); BitStream_free(bstream); snprintf(buf, 256, "monkey-result-bits-%d.dat", num); fp = fopen(buf, "w"); p = QRcode_extractBits(qrcode, &y); c = 0; for(x=0; x<y; x++) { fputc((p[x]&1)?'1':'0', fp); if((x & 7) == 7) { fputc(' ', fp); c++; } if((x & 63) == 63) { fprintf(fp, "%d\n", c); } } fclose(fp); free(p); } QRdata_free(qrdata); QRcode_free(qrcode); }