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_null_free(void) { testStart("Testing free NULL pointers"); assert_nothing(QRcode_free(NULL), "Check QRcode_free(NULL).\n"); assert_nothing(QRcode_List_free(NULL), "Check QRcode_List_free(NULL).\n"); assert_nothing(QRraw_free(NULL), "Check QRraw_free(NULL).\n"); testFinish(); }
__STATIC QRRawCode *QRraw_new(QRinput *input) { QRRawCode *raw; int spec[5], ret; raw = (QRRawCode *)malloc(sizeof(QRRawCode)); if(raw == NULL) return NULL; raw->datacode = QRinput_getByteStream(input); if(raw->datacode == NULL) { free(raw); return NULL; } QRspec_getEccSpec(input->version, input->level, spec); raw->version = input->version; raw->b1 = QRspec_rsBlockNum1(spec); raw->dataLength = QRspec_rsDataLength(spec); raw->eccLength = QRspec_rsEccLength(spec); raw->ecccode = (unsigned char *)malloc(raw->eccLength); if(raw->ecccode == NULL) { free(raw->datacode); free(raw); return NULL; } raw->blocks = QRspec_rsBlockNum(spec); raw->rsblock = (RSblock *)calloc(raw->blocks, sizeof(RSblock)); if(raw->rsblock == NULL) { QRraw_free(raw); return NULL; } ret = RSblock_init(raw->rsblock, spec, raw->datacode, raw->ecccode); if(ret < 0) { QRraw_free(raw); return NULL; } raw->count = 0; return raw; }
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); }
/* See pp. 73 of JIS X0510:2004 */ void test_rscodeexample(void) { QRinput *stream; QRRawCode *code; static const char str[9] = "01234567"; static unsigned char correct[26] = { 0x10, 0x20, 0x0c, 0x56, 0x61, 0x80, 0xec, 0x11, 0xec, 0x11, 0xec, 0x11, 0xec, 0x11, 0xec, 0x11, 0xa5, 0x24, 0xd4, 0xc1, 0xed, 0x36, 0xc7, 0x87, 0x2c, 0x55}; testStart("RS ecc test"); stream = QRinput_new(); QRinput_append(stream, QR_MODE_NUM, 8, (unsigned char *)str); QRinput_setErrorCorrectionLevel(stream, QR_ECLEVEL_M); code = QRraw_new(stream); testEnd(memcmp(correct + 16, code->rsblock[0].ecc, 10)); QRinput_free(stream); QRraw_free(code); }
void test_qrraw_new(void) { int i; QRinput *stream; char num[9] = "01234567"; QRRawCode *raw; testStart("Test QRRaw_new()"); stream = QRinput_new(); QRinput_setVersion(stream, 10); QRinput_setErrorCorrectionLevel(stream, QR_ECLEVEL_Q); QRinput_append(stream, QR_MODE_NUM, 8, (unsigned char *)num); raw = QRraw_new(stream); assert_nonnull(raw, "Failed QRraw_new().\n"); assert_zero(raw->count, "QRraw.count = %d != 0\n", raw->count); assert_equal(raw->version, 10, "QRraw.version was not as expected. (%d)\n", raw->version); assert_equal(raw->dataLength, 19 * 6 + 20 * 2, "QRraw.dataLength was not as expected.\n"); assert_equal(raw->eccLength, 24 * 8, "QRraw.eccLength was not as expected.\n"); assert_equal(raw->b1, 6, "QRraw.b1 was not as expected.\n"); assert_equal(raw->blocks, 8, "QRraw.blocks was not as expected.\n"); for(i=0; i<raw->b1; i++) { assert_equal(raw->rsblock[i].dataLength, 19, "QRraw.rsblock[].dataLength was not as expected.\n"); } for(i=raw->b1; i<raw->blocks; i++) { assert_equal(raw->rsblock[i].dataLength, 20, "QRraw.rsblock[].dataLength was not as expected.\n"); } for(i=0; i<raw->blocks; i++) { assert_equal(raw->rsblock[i].eccLength, 24, "QRraw.rsblock[].eccLength was not as expected.\n"); } QRinput_free(stream); QRraw_free(raw); testFinish(); }
__STATIC QRcode *QRcode_encodeMask(QRinput *input, int mask) { int width, version; QRRawCode *raw; unsigned char *frame, *masked, *p, code, bit; FrameFiller *filler; int i, j; QRcode *qrcode = NULL; if(input->mqr) { errno = EINVAL; return NULL; } if(input->version < 0 || input->version > QRSPEC_VERSION_MAX) { errno = EINVAL; return NULL; } if(input->level > QR_ECLEVEL_H) { errno = EINVAL; return NULL; } raw = QRraw_new(input); if(raw == NULL) return NULL; version = raw->version; width = QRspec_getWidth(version); frame = QRspec_newFrame(version); if(frame == NULL) { QRraw_free(raw); return NULL; } filler = FrameFiller_new(width, frame, 0); if(filler == NULL) { QRraw_free(raw); free(frame); return NULL; } /* inteleaved data and ecc codes */ for(i=0; i<raw->dataLength + raw->eccLength; i++) { code = QRraw_getCode(raw); bit = 0x80; for(j=0; j<8; j++) { p = FrameFiller_next(filler); if(p == NULL) goto EXIT; *p = 0x02 | ((bit & code) != 0); bit = bit >> 1; } } QRraw_free(raw); raw = NULL; /* remainder bits */ j = QRspec_getRemainder(version); for(i=0; i<j; i++) { p = FrameFiller_next(filler); if(p == NULL) goto EXIT; *p = 0x02; } /* masking */ if(mask == -2) { // just for debug purpose masked = (unsigned char *)malloc(width * width); memcpy(masked, frame, width * width); } else if(mask < 0) { masked = Mask_mask(width, frame, input->level); } else { masked = Mask_makeMask(width, frame, mask, input->level); } if(masked == NULL) { goto EXIT; } qrcode = QRcode_new(version, width, masked); EXIT: QRraw_free(raw); free(filler); free(frame); return qrcode; }