Exemple #1
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 #2
0
void test_encode_kanji(int num)
{
	QRcode *qrcode;
	QRdata *qrdata;
	int len, ret;

	len = fill8bitString();

	qrcode = QRcode_encodeString((char *)data, 0, num % 4, QR_MODE_8, 1);
	if(qrcode == NULL) {
		if(errno == ERANGE) return;
		perror("test_encdoe_kanji aborted at QRcode_encodeString():");
		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) {
		printf("#%d: data mismatched.\n", num);
	}
	QRdata_free(qrdata);
	QRcode_free(qrcode);
}
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();
}
void test_mqrencode(void)
{
	char *str = "MICROQR";
	char pattern[] = {
		"#######_#_#_#_#"
		"#_____#_#__####"
		"#_###_#_#_####_"
		"#_###_#_#__##_#"
		"#_###_#___#__##"
		"#_____#____#_#_"
		"#######__##_#_#"
		"_________#__#__"
		"#___#__####_#_#"
		"_#######_#_##_#"
		"##___#_#____#__"
		"_##_#_####____#"
		"#__###___#__##_"
		"_###_#_###_#_#_"
		"##____####_###_"
	};
	QRcode qrcode;
	QRdata *qrdata;
	unsigned char *frame;
	int i;

	testStart("Encoding test (MQR).");

	qrcode.width = 15;
	qrcode.version = 3;

	frame = MQRspec_newFrame(qrcode.version);
	for(i=0; i<225; i++) {
		frame[i] ^= (pattern[i] == '#')?1:0;
	}

	qrcode.data = frame;
	qrdata = QRcode_decodeMQR(&qrcode);
	assert_equal(qrdata->version, 3, "Format info decoder returns wrong version number: %d (%d expected)\n", qrdata->version, 3);
	assert_equal(qrdata->level, 1, "Format info decoder returns wrong level: %d (%d expected)\n", qrdata->level, 1);
	assert_zero(strcmp((char *)qrdata->data, str), "Decoded data (%s) mismatched (%s)\n", (char *)qrdata->data, str);

	QRdata_free(qrdata);
	free(frame);

	testFinish();
}
Exemple #5
0
void test_decodeLong(void)
{
	char *str = "12345678901234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ?????????????";
	QRcode *qrcode;
	QRdata *qrdata;

	testStart("Test code words (long, splitted).");
	qrcode = QRcode_encodeString(str, 0, QR_ECLEVEL_H, QR_MODE_8, 1);
	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 #6
0
void test_decodeSimple(void)
{
	char *str = "AC-42";
	QRcode *qrcode;
	QRdata *qrdata;

	testStart("Test code words.");
	qrcode = QRcode_encodeString(str, 1, QR_ECLEVEL_H, QR_MODE_8, 1);
	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: %d, expected %d.\n", qrdata->size, (int)strlen(str));
		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 #7
0
void test_decodeShortMQR(void)
{
	char str[]="55";
	QRcode *qrcode;
	QRdata *qrdata;
	int i;

	testStart("Test code words (MQR).");
	for(i=0; i<8; i++) {
		qrcode = QRcode_encodeStringMQR(str,
										MQRformat[i].version,
										MQRformat[i].level,
										QR_MODE_8, 1);
		qrdata = QRcode_decodeMQR(qrcode);

		assert_nonnull(qrdata, "Failed to decode.\n");
		assert_zero(strcmp((char *)qrdata->data, str), "Decoded data (%s) mismatched (%s)\n", (char *)qrdata->data, str);
		if(qrdata != NULL) QRdata_free(qrdata);
		if(qrcode != NULL) QRcode_free(qrcode);
	}

	testFinish();
}
Exemple #8
0
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);
}