Пример #1
0
extern unsigned char *FrameFiller_test(int version)
{
	int width;
	unsigned char *frame, *p;
	FrameFiller *filler;
	int i, length;

	width = QRspec_getWidth(version);
	frame = QRspec_newFrame(version);
	if(frame == NULL) return NULL;
	filler = FrameFiller_new(width, frame, 0);
	if(filler == NULL) {
		free(frame);
		return NULL;
	}
	length = QRspec_getDataLength(version, QR_ECLEVEL_L) * 8
	       + QRspec_getECCLength(version, QR_ECLEVEL_L) * 8
		   + QRspec_getRemainder(version);
	for(i=0; i<length; i++) {
		p = FrameFiller_next(filler);
		if(p == NULL) {
			free(filler);
			free(frame);
			return NULL;
		}
		*p = (unsigned char)(i & 0x7f) | 0x80;
	}
	free(filler);
	return frame;
}
Пример #2
0
void test_filler(void)
{
	unsigned char *frame;
	int i, j, w, e, length;

	testStart("Frame filler test");
	for(i=1; i<=QRSPEC_VERSION_MAX; i++) {
		length = QRspec_getDataLength(i, QR_ECLEVEL_L) * 8
		       + QRspec_getECCLength(i, QR_ECLEVEL_L) * 8
			   + QRspec_getRemainder(i);
		frame = FrameFiller_test(i);
		if(frame == NULL) {
			assert_nonnull(frame, "Something wrong in version %d\n", i);
		} else {
			w = QRspec_getWidth(i);
			e = 0;
			for(j=0; j<w*w; j++) {
				if(frame[j] == 0) e++;
			}
			assert_zero(e, "Not filled bit is found. (%d,%d)\n", j%w,j/w);
			e = w * (w - 9 - ((i > 6)?3:0));
			assert_equal(frame[e], (unsigned char)((length - 1) & 127) | 0x80,
			"Number of cell does not match.\n");
			free(frame);
		}
	}
	testFinish();
}
Пример #3
0
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);
}
Пример #4
0
unsigned char *FrameFiller_fillerTest(int version)
{
	int width, length;
	unsigned char *frame, *p;
	FrameFiller *filler;
	int i, j;
	unsigned char cl = 1;
	unsigned char ch = 0;

	width = QRspec_getWidth(version);
	frame = QRspec_newFrame(version);
	filler = FrameFiller_new(width, frame);
	length = QRspec_getDataLength(version, QR_ECLEVEL_L)
			+ QRspec_getECCLength(version, QR_ECLEVEL_L);

	for(i=0; i<length; i++) {
		for(j=0; j<8; j++) {
			p = FrameFiller_next(filler);
			*p = ch | cl;
			cl++;
			if(cl == 9) {
				cl = 1;
				ch += 0x10;
			}
		}
	}
	length = QRspec_getRemainder(version);
	for(i=0; i<length; i++) {
		p = FrameFiller_next(filler);
		*p = 0xa0;
	}
	p = FrameFiller_next(filler);
	free(filler);
	if(p != NULL) {
		return NULL;
	}

	return frame;
}
Пример #5
0
void QRspec_getEccSpec(int version, QRecLevel level, int spec[5])
{
	int b1, b2;
	int data, ecc;

	b1 = eccTable[version][level][0];
	b2 = eccTable[version][level][1];
	data = QRspec_getDataLength(version, level);
	ecc  = QRspec_getECCLength(version, level);

	if(b2 == 0) {
		spec[0] = b1;
		spec[1] = data / b1;
		spec[2] = ecc / b1;
		spec[3] = spec[4] = 0;
	} else {
		spec[0] = b1;
		spec[1] = data / (b1 + b2);
		spec[2] = ecc  / (b1 + b2);
		spec[3] = b2;
		spec[4] = spec[1] + 1;
	}
}
Пример #6
0
void test_split_structure(int num)
{
	QRinput *input;
	QRinput_Struct *s;
	QRcode_List *codes, *list;
	QRinput_InputList *il;
	int version;
	QRecLevel level;
	int c, i, ret;

	version = (int)drand(40) + 1;
	level = (QRecLevel)drand(4);

	fill8bitString();

	input = QRinput_new2(version, level);
	if(input == NULL) {
		perror("test_split_structure aborted at QRinput_new2():");
		return;
	}
	ret = Split_splitStringToQRinput((char *)data, input, QR_MODE_KANJI, 1);
	if(ret < 0) {
		perror("test_split_structure aborted at Split_splitStringToQRinput():");
		QRinput_free(input);
		return;
	}
	s = QRinput_splitQRinputToStruct(input);
	if(s == NULL) {
		if(errno != 0 && errno != ERANGE) {
			perror("test_split_structure aborted at QRinput_splitQRinputToStruct():");
		}
		QRinput_free(input);
		return;
	}
	il = s->head;
	i = 0;
	while(il != NULL) {
		if(il->input->version != version) {
			printf("Test: version %d, level %c\n", version, levelChar[level]);
			printf("wrong version number.\n");
			printQRinputInfo(il->input);
			exit(1);
		}
		i++;
		il = il->next;
	}
	codes = QRcode_encodeInputStructured(s);
	if(codes == NULL) {
		perror("test_split_structure aborted at QRcode_encodeInputStructured():");
		QRinput_free(input);
		QRinput_Struct_free(s);
		return;
	}
	list = codes;
	il = s->head;
	c = 0;
	while(list != NULL) {
		if(list->code->version != version) {
			printf("#%d: data mismatched.\n", num);
			printf("Test: version %d, level %c\n", version, levelChar[level]);
			printf("code #%d\n", c);
			printf("Version mismatch: %d should be %d\n", list->code->version, version);
			printf("max bits: %d\n", QRspec_getDataLength(version, level) * 8 - 20);
			printQRinputInfo(il->input);
			printQRinput(input);
			exit(1);
		}
		list = list->next;
		il = il->next;
		c++;
	}

	QRinput_free(input);
	QRinput_Struct_free(s);
	QRcode_List_free(codes);
}