Exemple #1
0
void test_fillerMQR(void)
{
	unsigned char *frame;
	int i, j, w, e, length;

	testStart("Micro QR Code Frame filler test");
	for(i=1; i<=MQRSPEC_VERSION_MAX; i++) {
		length = MQRspec_getDataLengthBit(i, QR_ECLEVEL_L)
		       + MQRspec_getECCLength(i, QR_ECLEVEL_L) * 8;
		frame = FrameFiller_testMQR(i);
		if(frame == NULL) {
			assert_nonnull(frame, "Something wrong in version %d\n", i);
		} else {
			w = MQRspec_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);
			if(i & 1) {
				e = w * 9 + 1;
			} else {
				e = w * (w - 1) + 1;
			}
			assert_equal(frame[e], (unsigned char)((length - 1) & 127) | 0x80,
			"Number of cell does not match in version %d.\n", i);
			free(frame);
		}
	}
	testFinish();
}
Exemple #2
0
void test_struct_insertStructuredAppendHeaders(void)
{
	QRinput *input;
	QRinput_Struct *s;
	QRinput_InputList *p;
	int i;

	testStart("Insert structured-append headers to a QRinput_Struct.");
	s = QRinput_Struct_new();
	for(i=0; i<10; i++) {
		input = QRinput_new();
		QRinput_append(input, QR_MODE_8, 1, (unsigned char *)"A");
		QRinput_Struct_appendInput(s, input);
	}
	QRinput_Struct_insertStructuredAppendHeaders(s);
	p = s->head;
	i = 1;
	while(p != NULL) {
		assert_equal(p->input->head->mode, QR_MODE_STRUCTURE, "a structured-append header is not inserted.");
		assert_equal(p->input->head->data[0], 10, "size of the structured-header is wrong: #%d, %d should be %d\n", i, p->input->head->data[0], 10);
		assert_equal(p->input->head->data[1], i, "index of the structured-header is wrong: #%d, %d should be %d\n", i, p->input->head->data[1], i);
		assert_equal(p->input->head->data[2], 0, "parity of the structured-header is wrong: #%d\n", i);
		p = p->next;
		i++;
	}
	testFinish();
	QRinput_Struct_free(s);
}
void test_encodeECI(void)
{
	QRinput *input;
	BitStream *bstream;
	unsigned char str[] = {0xa1, 0xa2, 0xa3, 0xa4, 0xa5};
	char *correct = "0111 00001001 0100 00000101 10100001 10100010 10100011 10100100 10100101";
	int ret;

	testStart("Encoding characters with ECI header.");
	input = QRinput_new();
	ret = QRinput_appendECIheader(input, 9);
	assert_zero(ret, "Valid ECI header rejected.\n");

	ret = QRinput_append(input, QR_MODE_8, 5, str);
	assert_zero(ret, "Failed to append characters.\n");
	bstream = BitStream_new();
	QRinput_mergeBitStream(input, bstream);
	assert_nonnull(bstream, "Failed to merge.\n");
	if(bstream != NULL) {
		ret = ncmpBin(correct, bstream, 64);
		assert_zero(ret, "Encodation of ECI header was invalid.\n");
		BitStream_free(bstream);
	}
	QRinput_free(input);
	testFinish();
}
Exemple #4
0
void test_toByte_4bitpadding(void)
{
	BitStream *bstream;
	unsigned char *result;

	testStart("Convert to a byte array");

	bstream = BitStream_new();
	BitStream_appendNum(bstream, 4, 0xb);
	result = BitStream_toByte(bstream);
	assert_equal(result[0], 0xb0, "incorrect paddings\n");
	BitStream_free(bstream);
	free(result);

	bstream = BitStream_new();
	BitStream_appendNum(bstream, 12, 0x335);
	result = BitStream_toByte(bstream);
	assert_equal(result[0], 0x33, "incorrect paddings\n");
	assert_equal(result[1], 0x50, "incorrect paddings\n");
	BitStream_free(bstream);
	free(result);

	testFinish();

}
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(1, QR_ECLEVEL_L);
	QRinput_append(input, QR_MODE_8, 17, (unsigned char *)data);
	bstream = BitStream_new();
	QRinput_getBitStream(input, bstream);
	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);
}
Exemple #6
0
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();
}
Exemple #7
0
void test_maskEvaluation(void)
{
	static const int w = 11;
	unsigned char pattern[w*w];
	int i, score;

	memset(pattern, 0, w*w);

	testStart("Test mask evaluation");
	score = MMask_evaluateSymbol(w, pattern);
	assert_equal(score, 0, "Mask score caluculation is incorrect. (score=%d (%d expected)\n", score, 0);

	for(i=0; i<w; i++) {
		pattern[(w-1) * w + i] = 1;
	}
	score = MMask_evaluateSymbol(w, pattern);
	assert_equal(score, 16 + w - 1, "Mask score caluculation is incorrect. (score=%d) (%d expected)\n", score, 16 + w - 1);

	for(i=0; i<w; i++) {
		pattern[(w-1) * w + i] = 0;
		pattern[i * w + w - 1] = 1;
	}
	score = MMask_evaluateSymbol(w, pattern);
	assert_equal(score, 16 + w - 1, "Mask score caluculation is incorrect. (score=%d) (%d expected)\n", score, 16 + w - 1);

	for(i=0; i<w; i++) {
		pattern[(w-1) * w + i] = 1;
		pattern[i * w + w - 1] = 1;
	}
	score = MMask_evaluateSymbol(w, pattern);
	assert_equal(score, 16 * (w - 1) + w - 1, "Mask score caluculation is incorrect. (score=%d) (%d expected)\n", score, 16 * (w - 1) + w - 1);

	testFinish();
}
Exemple #8
0
/* 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();
}
Exemple #9
0
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);
}
Exemple #10
0
void test_oddBitCalcMQR(void)
{
	/* test issue #25 (odd bits calculation bug) */
	/* test pattern contributed by vlad417 */
	TestString tests[] = {
		{"46194", 1, QR_ECLEVEL_L, QR_MODE_8, 1},
		{"WBA5Y47YPQQ", 3, QR_ECLEVEL_L, QR_MODE_8, 1}
	};
	QRcode *qrcode;
	QRdata *qrdata;
	int i;

	testStart("Odd bits calculation bug checking (MQR).");

	for(i=0; i<_countof(tests); i++) {
		qrcode = QRcode_encodeStringMQR(tests[i].str,
										tests[i].version,
										tests[i].level,
										tests[i].hint,
										tests[i].casesensitive);
		assert_nonnull(qrcode, "Failed to encode: %s\n", tests[i].str);
		if(qrcode == NULL) continue;
		qrdata = QRcode_decodeMQR(qrcode);
		assert_nonnull(qrdata, "Failed to decode.\n");
		assert_zero(strcmp((char *)qrdata->data, tests[i].str), "Decoded data (%s) mismatched (%s)\n", (char *)qrdata->data, tests[i].str);
		if(qrdata != NULL) QRdata_free(qrdata);
		QRcode_free(qrcode);
	}

	testFinish();
}
Exemple #11
0
void test_parity(void)
{
	QRinput *input;
	QRinput_Struct *s;
	const char *text = "an example of four Structured Append symbols,";
	const char *str[4] = {
		"an example ",
		"of four Str",
		"uctured Appe",
		"nd symbols,"};
	unsigned char p1, p2;
	int i, len;

	testStart("Testing parity calc.");
	s = QRinput_Struct_new();
	for(i=0; i<4; i++) {
		input = QRinput_new2(1, QR_ECLEVEL_M);
		QRinput_append(input, QR_MODE_8, strlen(str[i]), (unsigned char *)str[i]);
		QRinput_Struct_appendInput(s, input);
	}
	QRinput_Struct_insertStructuredAppendHeaders(s);
	p1 = s->parity;

	p2 = 0;
	len = strlen(text);
	for(i=0; i<len; i++) {
		p2 ^= text[i];
	}
	assert_equal(p1, p2, "Parity numbers didn't match. (%02x should be %02x).\n", p1, p2);
	testFinish();
	QRinput_Struct_free(s);
}
Exemple #12
0
void test_null_free(void)
{
	testStart("Testing free NULL pointers");
	assert_nothing(QRinput_free(NULL), "Check QRinput_free(NULL).\n");
	assert_nothing(QRinput_Struct_free(NULL), "Check QRinput_Struct_free(NULL).\n");
	testFinish();
}
Exemple #13
0
void test_struct_listop(void)
{
	QRinput_Struct *s;
	QRinput *inputs[5];
	QRinput_InputList *l;
	int i, ret;

	testStart("QRinput_Struct list operation test.");
	s = QRinput_Struct_new();
	QRinput_Struct_setParity(s, 10);
	assert_nonnull(s, "QRinput_Struct_new() failed.");
	assert_equal(s->parity, 10, "QRinput_Struct_setParity() failed.");

	for(i=0; i<5; i++) {
		inputs[i] = QRinput_new();
		QRinput_append(inputs[i], QR_MODE_AN, 5, (unsigned char *)"ABCDE");
		ret = QRinput_Struct_appendInput(s, inputs[i]);
	}
	assert_equal(ret, 5, "QRinput_Struct_appendInput() returns wrong num?");
	assert_equal(s->size, 5, "QRiput_Struct.size counts wrong number.");

	l = s->head;
	i = 0;
	while(l != NULL) {
		assert_equal(l->input, inputs[i], "QRinput_Struct input list order would be wrong?");
		l = l->next;
		i++;
	}

	QRinput_Struct_free(s);
	testFinish();
}
Exemple #14
0
void test_appendBytes(void)
{
	BitStream *bstream;
	unsigned char data[8];
	char correct[] = "10001010111111111111111100010010001101000101011001111000";

	testStart("Append Bytes");
	bstream = BitStream_new();

	data[0] = 0x8a;
	BitStream_appendBytes(bstream,  1, data);
	assert_zero(ncmpBin(correct, bstream, 8), "Internal data is incorrect.");

	data[0] = 0xff;
	data[1] = 0xff;
	BitStream_appendBytes(bstream, 2, data);
	assert_zero(ncmpBin(correct, bstream, 24), "Internal data is incorrect.\n");

	data[0] = 0x12;
	data[1] = 0x34;
	data[2] = 0x56;
	data[3] = 0x78;
	BitStream_appendBytes(bstream, 4, data);

	assert_zero(cmpBin(correct, bstream), "Internal data is incorrect.\n");
	testFinish();

	BitStream_free(bstream);
}
Exemple #15
0
void test_decodeVeryLong(void)
{
	char str[4000];
	int i;
	QRcode *qrcode;
	QRdata *qrdata;

	testStart("Test code words (very long string).");

	for(i=0; i<3999; i++) {
		str[i] = decodeAnTable[(int)drand(45)];
	}
	str[3999] = '\0';

	qrcode = QRcode_encodeString(str, 0, QR_ECLEVEL_L, QR_MODE_8, 0);
	qrdata = QRcode_decode(qrcode);

	assert_nonnull(qrdata, "Failed to decode.\n");
	if(qrdata != NULL) {
		assert_equal(strlen(str), qrdata->size, "Lengths of input/output mismatched.\n");
		assert_zero(strncmp(str, (char *)(qrdata->data), qrdata->size), "Decoded data %s is different from the original %s\n", qrdata->data, str);
	}
	if(qrdata != NULL) QRdata_free(qrdata);
	if(qrcode != NULL) QRcode_free(qrcode);

	testFinish();
}
Exemple #16
0
void test_encodeTooLongMQR(void)
{
	QRcode *code;
	char *data[] = {"012345", "ABC0EFG", "0123456789", "0123456789ABCDEFG"};

	testStart("Encode too large data for MQR.");

	code = QRcode_encodeStringMQR(data[0], 1, QR_ECLEVEL_L, QR_MODE_8, 0);
	assert_null(code, "6 byte length numeric string was accepted to version 1.\n");
	assert_equal(errno, ERANGE, "errno != ERANGE\n");
	code = QRcode_encodeStringMQR(data[1], 2, QR_ECLEVEL_L, QR_MODE_8, 0);
	assert_null(code, "7 byte length alphanumeric string was accepted to version 2.\n");
	assert_equal(errno, ERANGE, "errno != ERANGE\n");
	code = QRcode_encodeString8bitMQR(data[2], 3, QR_ECLEVEL_L);
	assert_null(code, "9 byte length 8bit string was accepted to version 3.\n");
	assert_equal(errno, ERANGE, "errno != ERANGE\n");
	code = QRcode_encodeString8bitMQR(data[3], 4, QR_ECLEVEL_L);
	assert_null(code, "16 byte length 8bit string was accepted to version 4.\n");
	assert_equal(errno, ERANGE, "errno != ERANGE\n");
	testFinish();

	if(code != NULL) {
		printQRcode(code);
		QRcode_free(code);
	}
}
Exemple #17
0
void test_struct_split_example(void)
{
	QRinput *input;
	QRinput_Struct *s;
	QRinput_InputList *e;
	QRinput_List *l;
	const char *str[4] = { "an example ", "of four Str", "uctured Appe", "nd symbols,"};
	int i;
	BitStream *bstream;

	testStart("Testing the example of structured-append symbols");
	s = QRinput_Struct_new();
	for(i=0; i<4; i++) {
		input = QRinput_new2(1, QR_ECLEVEL_M);
		QRinput_append(input, QR_MODE_8, strlen(str[i]), (unsigned char *)str[i]);
		QRinput_Struct_appendInput(s, input);
	}
	QRinput_Struct_insertStructuredAppendHeaders(s);
	e = s->head;
	i = 0;
	while(e != NULL) {
		bstream = QRinput_mergeBitStream(e->input);
		BitStream_free(bstream);
		l = e->input->head->next;
		assert_equal(l->mode, QR_MODE_8, "#%d: wrong mode (%d).\n", i, l->mode);
		assert_equal(e->input->level, QR_ECLEVEL_M, "#%d: wrong level (%d).\n", i, e->input->level);

		e = e->next;
		i++;
	}
	testFinish();
	QRinput_Struct_free(s);
}
Exemple #18
0
void test_struct_semilong(void)
{
	QRcode_List *codes, *list;
	const char *str = "asdfasdfasdfasdfasdfASDFASDASDFASDFAsdfasdfasdfasdASDFASDFADSADadsfasdf";
	int num, size;

	testStart("Testing semi-long structured-append symbols");
	codes = QRcode_encodeString8bitStructured(str, 1, QR_ECLEVEL_L);
	list = codes;
	num = 0;
	while(list != NULL) {
		num++;
		assert_equal(list->code->version, 1, "version number is %d (1 expected)\n", list->code->version);
		list = list->next;
	}
	size = QRcode_List_size(codes);
	assert_equal(num, size, "QRcode_List_size returns wrong size?");
	QRcode_List_free(codes);

	codes = QRcode_encodeStringStructured(str, 1, QR_ECLEVEL_L, QR_MODE_8, 1);
	list = codes;
	num = 0;
	while(list != NULL) {
		num++;
		assert_equal(list->code->version, 1, "version number is %d (1 expected)\n", list->code->version);
		list = list->next;
	}
	size = QRcode_List_size(codes);
	assert_equal(num, size, "QRcode_List_size returns wrong size?");
	QRcode_List_free(codes);

	testFinish();
}
Exemple #19
0
void test_splitentry2(void)
{
	QRinput *i1, *i2;
	QRinput_List *e;
	const char *str = "abcdefghij";
	int size1, size2, i;
	unsigned char *d1, *d2;

	testStart("Testing QRinput_splitEntry. (next != NULL)");
	i1 = QRinput_new();
	QRinput_append(i1, QR_MODE_8, strlen(str), (unsigned char *)str);
	QRinput_append(i1, QR_MODE_8, strlen(str), (unsigned char *)str);

	i2 = QRinput_dup(i1);
	e = i2->head;

	e = i2->head;
	QRinput_splitEntry(e, 4);

	size1 = size2 = 0;
	e = i1->head;
	while(e != NULL) {
		size1 += e->size;
		e = e->next;
	}
	e = i2->head;
	while(e != NULL) {
		size2 += e->size;
		e = e->next;
	}

	d1 = (unsigned char *)malloc(size1);
	e = i1->head;
	i = 0;
	while(e != NULL) {
		memcpy(&d1[i], e->data, e->size);
		i += e->size;
		e = e->next;
	}
	d2 = (unsigned char *)malloc(size2);
	e = i2->head;
	i = 0;
	while(e != NULL) {
		memcpy(&d2[i], e->data, e->size);
		i += e->size;
		e = e->next;
	}

	assert_equal(size1, size2, "sizes are different. (%d:%d)\n", size1, size2);
	assert_equal(i2->head->size, 4, "split failed (first half)");
	assert_equal(i2->head->next->size, 6, "split failed(second half)");
	assert_zero(memcmp(d1, d2, size1), "strings are different.");
	QRinput_free(i1);
	QRinput_free(i2);
	free(d1);
	free(d2);

	testFinish();
}
Exemple #20
0
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();
}
void test_padding2(void)
{
	QRinput *input;
	BitStream *bstream;
	int i, size, ret;
	char data[] = "0123456789ABCDeF";
	char correct[153];
	unsigned char c;

	testStart("Padding bit check. (1 or 2 padding bytes)");

	/* 16 byte data (4 bit terminator and 1 byte padding) */
	memset(correct, 0, 153);
	memcpy(correct, "010000010000", 12);
	for(size=0; size<16; size++) {
		c = 0x80;
		for(i=0; i<8; i++) {
			correct[size * 8 + i + 12] = (data[size]&c)?'1':'0';
			c = c >> 1;
		}
	}
	memcpy(correct + 140, "000011101100", 12);

	input = QRinput_new2(1, QR_ECLEVEL_L);
	QRinput_append(input, QR_MODE_8, 16, (unsigned char *)data);
	bstream = BitStream_new();
	QRinput_getBitStream(input, bstream);
	size = BitStream_size(bstream);
	assert_equal(size, 152, "16byte: # of bit is incorrect (%d != 152).\n", size);
	ret = ncmpBin(correct, bstream, 152);
	assert_zero(ret, "Padding bits incorrect.\n");
	printBstream(bstream);

	QRinput_free(input);
	BitStream_free(bstream);

	/* 15 byte data (4 bit terminator and 2 byte paddings) */

	memcpy(correct, "010000001111", 12);
	memcpy(correct + 132, "00001110110000010001", 20);

	input = QRinput_new2(1, QR_ECLEVEL_L);
	QRinput_append(input, QR_MODE_8, 15, (unsigned char *)data);
	bstream = BitStream_new();
	QRinput_getBitStream(input, bstream);
	size = BitStream_size(bstream);
	assert_equal(size, 152, "15byte: # of bit is incorrect (%d != 152).\n", size);
	ret = ncmpBin(correct, bstream, 152);
	assert_zero(ret, "Padding bits incorrect.\n");
	printBstream(bstream);

	testFinish();

	QRinput_free(input);
	BitStream_free(bstream);
}
Exemple #22
0
void test_masks(void)
{
	int i;

	testStart("Mask pattern checks");
	for(i=0; i<4; i++) {
		assert_zero(test_mask(i), "Mask pattern %d incorrect.\n", i);
	}
	testFinish();
}
Exemple #23
0
void test_encodeNull(void)
{
	QRcode *qrcode;

	testStart("Test encode NULL.");
	qrcode = QRcode_encodeString(NULL, 0, QR_ECLEVEL_H, QR_MODE_8, 0);
	assert_null(qrcode, "QRcode_encodeString() returned something.\n");
	testFinish();
	if(qrcode != NULL) QRcode_free(qrcode);
}
Exemple #24
0
void test_encodeEmpty8(void)
{
	QRcode *qrcode;

	testStart("Test encode an empty string.");
	qrcode = QRcode_encodeString8bit("", 0, QR_ECLEVEL_H);
	assert_null(qrcode, "QRcode_encodeString8bit() returned something.\n");
	testFinish();
	if(qrcode != NULL) QRcode_free(qrcode);
}
Exemple #25
0
int main(int argc, char** argv) {
    testStart();
	
    testFSMatcher();
	testInstanceOf();
	testRandomString();
	testCloner();
    // Add your own test method
    
    return testFinish();
}
void test_newframe_invalid(void)
{
	unsigned char *frame;

	testStart("Checking MQRspec_newFrame with invalid version.");
	frame = MQRspec_newFrame(0);
	assert_null(frame, "MQRspec_newFrame(0) returns non-NULL.");
	frame = MQRspec_newFrame(MQRSPEC_VERSION_MAX+1);
	assert_null(frame, "MQRspec_newFrame(0) returns non-NULL.");
	testFinish();
}
Exemple #27
0
void test_encodeLongData(void)
{
	QRinput *stream;
	unsigned char data[7090];
	int maxlength[4][4] = {{7089,5596,3993,3057},
						   {4296,3391,2420,1852},
						   {2953,2331,1663,1273},
						   {1817*2,1435*2,1024*2, 784*2}};
	int i, l, len, ret;
	QRcode *qrcode;

	testStart("Encoding long data.");

	for(i=QR_MODE_NUM; i<=QR_MODE_KANJI; i++) {
		if(i != QR_MODE_KANJI) {
			memset(data, '0', maxlength[i][0] + 1);
		} else {
			for(l=0; l<=maxlength[i][0]/2+1; l++) {
				data[l*2] = 0x93; data[l*2+1] = 0x5f;
			}
		}
		for(l=QR_ECLEVEL_L; l<=QR_ECLEVEL_H; l++) {
			stream = QRinput_new2(0, l);
			ret = QRinput_append(stream, i, maxlength[i][l], data);
			assert_zero(ret, "Failed to add %d-byte %s to a QRinput\n", maxlength[i][l], modeStr[i]);
			qrcode = QRcode_encodeInput(stream);
			assert_nonnull(qrcode, "(QRcode_encodeInput) failed to encode %d-byte %s in level %d.\n", maxlength[i][l], modeStr[i], l);
			if(qrcode != NULL) {
				QRcode_free(qrcode);
			}
			QRinput_free(stream);

			stream = QRinput_new2(0, l);
			len = maxlength[i][l];
			if(i == QR_MODE_KANJI) {
				len += 2;
			} else {
				len += 1;
			}
			ret = QRinput_append(stream, i, len, data);
			if(ret == 0) {
				qrcode = QRcode_encodeInput(stream);
				assert_null(qrcode, "(QRcode_encodeInput) incorrectly succeeded to encode %d-byte %s in level %d.\n", len, modeStr[i], l);
				if(qrcode != NULL) {
					printf("version: %d\n", qrcode->version);
					QRcode_free(qrcode);
				}
			}
			QRinput_free(stream);
		}
	}

	testFinish();
}
Exemple #28
0
void test_lengthOfCode_kanji(void)
{
	int i, bytes;
	unsigned char str[4]= {0x93, 0x5f,0xe4, 0xaa};

	testStart("Checking length of code (kanji)");
	for(i=2; i<=4; i+=2) {
		bytes = check_lengthOfCode(QR_MODE_KANJI, (char *)str, i, 1);
		assert_equal(i, bytes, "lengthOfCode failed. (QR_MODE_KANJI, version:1, size:%d)\n", i);
	}
	testFinish();
}
Exemple #29
0
void test_null(void)
{
	BitStream *bstream;

	testStart("Empty stream");
	bstream = BitStream_new();
	assert_zero(BitStream_size(bstream), "Size of empty BitStream is not 0.\n");
	assert_null(BitStream_toByte(bstream), "BitStream_toByte returned non-NULL.\n");
	assert_nothing(BitStream_free(NULL), "Checking BitStream_free(NULL).\n");
	testFinish();

	BitStream_free(bstream);
}
Exemple #30
0
void test_newWithBits_size0(void)
{
	BitStream *bstream;

	testStart("New with bits (size = 0)");

	bstream = BitStream_newWithBits(0, NULL);
	assert_equal(bstream->length, 0, "Internal bit length is incorrect.\n");
	assert_nonzero(bstream->datasize, "Internal buffer size is incorrect.\n");
	assert_nonnull(bstream->data, "Internal buffer not allocated.\n");

	testFinish();
}