コード例 #1
0
ファイル: test_qrencode.c プロジェクト: zapster/libqrencode
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();
}
コード例 #2
0
ファイル: qrencode.c プロジェクト: asmecher/libqrencode
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;
}
コード例 #3
0
ファイル: test_mask.c プロジェクト: 01org/irk_host_linux
void test_format(void)
{
	unsigned char *frame, *masked;
	int version, mask, width, dmask;
	QRecLevel level, dlevel;
	QRcode *code;
	int ret;

	testStart("Checking format info.");
	for(version=1; version<=QRSPEC_VERSION_MAX; version++) {
		frame = QRspec_newFrame(version);
		width = QRspec_getWidth(version);
		for(level=0; level<4; level++) {
			for(mask=0; mask<8; mask++) {
				masked = Mask_makeMask(width, frame, mask, level);
				code = QRcode_new(version, width, masked);
				ret = QRcode_decodeFormat(code, &dlevel, &dmask);
				assert_zero(ret, "Something wrong in format info.\n");
				assert_equal(dlevel, level, "Decoded level is wrong: %d, expected %d", dlevel, level);
				assert_equal(dmask, mask, "Decoded mask is wrong: %d, expected %d", dlevel, level);
				QRcode_free(code);
			}
		}
		free(frame);
	}
	testFinish();
}
コード例 #4
0
ファイル: test_qrspec.c プロジェクト: 937447974/libqrencode
/* This test is used to check positions of alignment pattern. See Appendix E
 * (pp.71) of JIS X0510:2004 and compare to the output. Before comment out
 * this test, change the value of the pattern marker's center dot from 0xa1
 * to 0xb1 (QRspec_putAlignmentMarker() : finder).
 */
void test_alignment(void)
{
	unsigned char *frame;
	int i, x, y, width, c;

	testStart("Checking alignment pattern.");
	for(i=2; i<=QRSPEC_VERSION_MAX; i++) {
		printf("%2d", i);
		frame = QRspec_newFrame(i);
		width = QRspec_getWidth(i);
		c = 0;
		for(x=0; x<width * width; x++) {
			if(frame[x] == 0xb1) {
				c++;
			}
		}
		printf("|%2d|   6", c);
		y = width - 7;
		for(x=0; x < width; x++) {
			if(frame[y * width + x] == 0xb1) {
				printf(", %3d", x);
			}
		}
		printf("\n");
		free(frame);
	}
	testFinish();
}
コード例 #5
0
ファイル: test_qrspec.c プロジェクト: 937447974/libqrencode
void test_newframe(void)
{
	unsigned char buf[QRSPEC_WIDTH_MAX * QRSPEC_WIDTH_MAX];
	int i, width;
	size_t len;
	FILE *fp;
	unsigned char *frame;
	QRcode *qrcode;
	unsigned int version;

	testStart("Checking newly created frame.");
	fp = fopen("frame", "rb");
	if(fp == NULL) {
		perror("Failed to open \"frame\":");
		abort();
	}
	for(i=1; i<=QRSPEC_VERSION_MAX; i++) {
		frame = QRspec_newFrame(i);
		width = QRspec_getWidth(i);
		len = fread(buf, 1, width * width, fp);
		if((int)len != width * width) {
			perror("Failed to read the pattern file:");
			abort();
		}
		assert_zero(memcmp(frame, buf, len), "frame pattern mismatch (version %d)\n", i);
		qrcode = QRcode_new(i, width, frame);
		version = QRcode_decodeVersion(qrcode);
		assert_equal(version, i, "Decoded version number is wrong: %d, expected %d.\n", version, i);
		QRcode_free(qrcode);
	}

	testFinish();
	fclose(fp);
}
コード例 #6
0
ファイル: test_qrencode.c プロジェクト: zapster/libqrencode
void print_filler(void)
{
	int width;
	int version = 7;
	unsigned char *frame;

	width = QRspec_getWidth(version);
	frame = FrameFiller_test(version);
	if(frame == NULL) abort();

	printFrame(width, frame);
	free(frame);
}
コード例 #7
0
ファイル: test_qrspec.c プロジェクト: 937447974/libqrencode
void print_newFrame(void)
{
	int width;
	int x, y;
	unsigned char *frame;

	frame = QRspec_newFrame(7);
	width = QRspec_getWidth(7);
	for(y=0; y<width; y++) {
		for(x=0; x<width; x++) {
			printf("%02x ", frame[y * width + x]);
		}
		printf("\n");
	}
	free(frame);
}
コード例 #8
0
ファイル: qrencode.c プロジェクト: keven123/KTV
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;
}
コード例 #9
0
ファイル: qrencode.c プロジェクト: asmecher/libqrencode
__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;
}
コード例 #10
0
ファイル: test_qrencode.c プロジェクト: zapster/libqrencode
void test_format(void)
{
	unsigned char *frame;
	unsigned int format;
	int width;
	int i;
	unsigned int decode;
	int blacks, b1 = 0, b2 = 0;

	testStart("Test format information(level L,mask 0)");
	width = QRspec_getWidth(1);
	frame = QRspec_newFrame(1);
	format = QRspec_getFormatInfo(1, QR_ECLEVEL_L);
	blacks = Mask_writeFormatInformation(width, frame, 1, QR_ECLEVEL_L);
	decode = 0;
	for(i=0; i<15; i++) {
		if((1<<i) & format) b2 += 2;
	}
	for(i=0; i<8; i++) {
		decode = decode << 1;
		decode |= frame[width * 8 + i + (i > 5)] & 1;
		if(decode & 1) b1++;
	}
	for(i=0; i<7; i++) {
		decode = decode << 1;
		decode |= frame[width * ((6 - i) + (i < 1)) + 8] & 1;
		if(decode & 1) b1++;
	}
	if(decode != format) {
		printf("Upper-left format information is invalid.\n");
		printf("%08x, %08x\n", format, decode);
		testEnd(1);
		return;
	}
	decode = 0;
	for(i=0; i<7; i++) {
		decode = decode << 1;
		decode |= frame[width * (width - 1 - i) + 8] & 1;
		if(decode & 1) b1++;
	}
	for(i=0; i<8; i++) {
		decode = decode << 1;
		decode |= frame[width * 8 + width - 8 + i] & 1;
		if(decode & 1) b1++;
	}
	if(decode != format) {
		printf("Bottom and right format information is invalid.\n");
		printf("%08x, %08x\n", format, decode);
		testEnd(1);
		return;
	}

	if(b2 != blacks || b1 != b2) {
		printf("Number of dark modules is incorrect.\n");
		printf("Return value: %d, dark modules in frame: %d, should be: %d\n", blacks, b1, b2);
		testEnd(1);
		return;
	}

	free(frame);

	testEnd(0);
}