Esempio n. 1
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);
}
Esempio n. 2
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();
}
Esempio n. 3
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);
}
Esempio n. 4
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);
}
Esempio n. 5
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();
}
Esempio n. 6
0
static QRcode_List *QRcode_encodeInputToStructured(QRinput *input)
{
	QRinput_Struct *s;
	QRcode_List *codes;
	s = QRinput_splitQRinputToStruct(input);
	if(s == NULL) return NULL;
	codes = QRcode_encodeInputStructured(s);
	QRinput_Struct_free(s);
	return codes;
}
Esempio n. 7
0
void draw_structuredQRcodeFromQRinput(QRinput *stream)
{
	QRinput_Struct *s;

	QRinput_setVersion(stream, version);
	QRinput_setErrorCorrectionLevel(stream, level);
	s = QRinput_splitQRinputToStruct(stream);
	if(s != NULL) {
		draw_structuredQRcode(s);
		QRinput_Struct_free(s);
	} else {
		fprintf(stderr, "Input data is too large for this setting.\n");
	}
}
Esempio n. 8
0
void test_struct_split_invalidVersion(void)
{
	QRinput *input;
	QRinput_Struct *s;
	char *str;
	int errsv;

	testStart("Testing structured-append symbols. (invalid version 0)");
	str = (char *)malloc(128);
	memset(str, 'a', 128);
	input = QRinput_new2(0, QR_ECLEVEL_H);
	QRinput_append(input, QR_MODE_8, 128, (unsigned char *)str);
	s = QRinput_splitQRinputToStruct(input);
	errsv = errno;
	assert_null(s, "returns non-null.");
	assert_equal(errsv, ERANGE, "did not return ERANGE.");
	testFinish();
	if(s != NULL) QRinput_Struct_free(s);
	QRinput_free(input);
	free(str);
}
Esempio n. 9
0
void draw_structuredQRcodeFromText(int argc, char **argv)
{
	QRinput_Struct *s;
	QRinput *input;
	int i, ret;

	s = QRinput_Struct_new();
	if(s == NULL) {
		fprintf(stderr, "Failed to allocate memory.\n");
		exit(1);
	}
	for(i=0; i<argc; i++) {
		input = QRinput_new2(version, level);
		if(input == NULL) {
			fprintf(stderr, "Failed to allocate memory.\n");
			exit(1);
		}
		if(eightbit) {
			ret = QRinput_append(input, QR_MODE_8, strlen(argv[i]), (unsigned char *)argv[i]);
		} else {
			ret = Split_splitStringToQRinput(argv[i], input, hint, casesensitive);
		}
		if(ret < 0) {
			perror("Encoding the input string");
			exit(1);
		}
		ret = QRinput_Struct_appendInput(s, input);
		if(ret < 0) {
			perror("Encoding the input string");
			exit(1);
		}
	}
	ret = QRinput_Struct_insertStructuredAppendHeaders(s);
	if(ret < 0) {
		fprintf(stderr, "Too many inputs.\n");
	}

	draw_structuredQRcode(s);
	QRinput_Struct_free(s);
}
Esempio n. 10
0
void test_parity2(void)
{
	QRinput *input;
	QRinput_Struct *s;
	const char *text = "an example of four Structured Append symbols,";
	unsigned char p1, p2;
	int i, len;

	testStart("Testing parity calc.(split)");
	input = QRinput_new2(1, QR_ECLEVEL_L);
	QRinput_append(input, QR_MODE_8, strlen(text), (unsigned char *)text);
	s = QRinput_splitQRinputToStruct(input);
	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_free(input);
	QRinput_Struct_free(s);
}
Esempio n. 11
0
void test_splitentry3(void)
{
	QRinput *input;
	QRinput_Struct *s;
	QRinput_List *e00, *e01, *e10, *e11;
	QRinput_InputList *list;
	const char *str = "abcdefghijklmno";

	testStart("Testing QRinput_splitEntry. (does not split an entry)");
	/* version 1 symbol contains 152 bit (19 byte) data.
	 * 20 bits for a structured-append header, so 132 bits can be used.
	 * 15 bytes of 8-bit data is suitable for the symbol.
	 * (mode(4) + length(8) + data(120) == 132.)
	 */
	input = QRinput_new2(1, QR_ECLEVEL_L);
	QRinput_append(input, QR_MODE_8, strlen(str), (unsigned char *)str);
	QRinput_append(input, QR_MODE_8, strlen(str), (unsigned char *)str);
	s = QRinput_splitQRinputToStruct(input);
	list = s->head;
	e00 = list->input->head;
	e01 = e00->next;
	list = list->next;
	e10 = list->input->head;
	e11 = e00->next;
	
	assert_equal(e00->mode, QR_MODE_STRUCTURE, "Structure header is missing?");
	assert_equal(e01->mode, QR_MODE_8, "no data?!");
	assert_null(e01->next, "Input list is not terminated!\n");
	assert_equal(e10->mode, QR_MODE_STRUCTURE, "Structure header is missing?");
	assert_equal(e11->mode, QR_MODE_8, "no data?!");
	assert_null(e11->next, "Input list is not terminated!\n");

	QRinput_free(input);
	QRinput_Struct_free(s);
	testFinish();
}
Esempio n. 12
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);
}