static void compareRS(unsigned char data[])
{
	int i, j;
	RS *rs;
	int spec[5];
	int dl, el;
	unsigned char ecc_expected[256], ecc_rscodec[256];

	for(i = 1; i <= QRSPEC_VERSION_MAX; i++) {
		for(j = QR_ECLEVEL_L; j <= QR_ECLEVEL_H; j++) {
			QRspec_getEccSpec(i, (QRecLevel)j, spec);
			dl = QRspec_rsDataCodes1(spec);
			el = QRspec_rsEccCodes1(spec);
			rs = init_rs(8, 0x11d, 0, 1, el, 255 - dl - el);
			RSECC_encode(dl, el, data, ecc_rscodec);
			encode_rs_char(rs, data, ecc_expected);
			assert_zero(memcmp(ecc_expected, ecc_rscodec, el), "Invalid ECC found: length %d.\n", el);
			free_rs_char(rs);

			dl = QRspec_rsDataCodes2(spec);
			el = QRspec_rsEccCodes2(spec);
			if(dl != 0) {
				rs = init_rs(8, 0x11d, 0, 1, el, 255 - dl - el);
				RSECC_encode(dl, el, data, ecc_rscodec);
				encode_rs_char(rs, data, ecc_expected);
				assert_zero(memcmp(ecc_expected, ecc_rscodec, el), "Invalid ECC found: length %d.\n", el);
				free_rs_char(rs);
			}
		}
	}
}
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();
}
Example #3
0
int test_main(int argc, char *const argv[]) {
    int r;
    const char *env_dir = TOKU_TEST_FILENAME;
    const char *db_filename = "ftcxx_cursor_test";
    parse_args(argc, argv);

    char rm_cmd[strlen(env_dir) + strlen("rm -rf ") + 1];
    snprintf(rm_cmd, sizeof(rm_cmd), "rm -rf %s", env_dir);
    r = system(rm_cmd);
    assert_zero(r);

    r = toku_os_mkdir(env_dir, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
    assert_zero(r);

    int env_open_flags = DB_CREATE | DB_PRIVATE | DB_INIT_MPOOL | DB_INIT_TXN | DB_INIT_LOCK | DB_INIT_LOG;
    ftcxx::DBEnv env = ftcxx::DBEnvBuilder()
        .set_default_bt_compare(uint_dbt_cmp)
        .open(env_dir, env_open_flags, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);

    ftcxx::DBTxn create_txn(env);
    ftcxx::DB db = ftcxx::DBBuilder()
        .open(env, create_txn, db_filename, NULL, DB_BTREE, DB_CREATE, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
    create_txn.commit();

    run_test(env, db);

    return 0;
}
Example #4
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);
}
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);
}
Example #6
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);
}
Example #7
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();
}
Example #8
0
void map (MapperIn *mapper_input, MapperOut *mapper_output) {
  int i, j, k;

  MapperChunkOut* out = &mapper_output->output[0];

  //Only one reducer.
  assert_zero(NUM_REDUCERS-1);

  //Zero out output
  for(i = 0; i < NUM_VARS; i++){
    out->sum_x[i] = 0;
    for(j = 0; j < NUM_VARS; j++){
      out->sum_x_times_y[i][j] = 0;
    }
  }

  //Iterate over data, computing sums
  for(i = 0; i < NUM_DATAPOINTS_PER_MAPPER; i++){
    for(j = 0; j < NUM_VARS; j++){
      out->sum_x[j] += mapper_input->data[i][j];
      for(k = 0; k < NUM_VARS; k++){
	out->sum_x_times_y[j][k] += mapper_input->data[i][j] * mapper_input->data[i][k];
      }
    }
  }
}
Example #9
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();
}
Example #10
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();
}
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);
}
Example #12
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();
}
Example #13
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();
}
Example #14
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();
}
Example #15
0
void test_append(void)
{
	BitStream *bs1, *bs2;
	char c1[] = "00";
	char c2[] = "0011";
	char c3[] = "01111111111111111";
	char c4[] = "001101111111111111111";
	char c5[] = "0011011111111111111111111111111111";
	int ret;

	testStart("Append two BitStreams");

	bs1 = BitStream_new();
	bs2 = BitStream_new();
	ret = BitStream_appendNum(bs1, 1, 0);
	ret = BitStream_appendNum(bs2, 1, 0);

	ret = BitStream_append(bs1, bs2);
	assert_zero(ret, "Failed to append.");
	assert_zero(cmpBin(c1, bs1), "Internal data is incorrect.");

	ret = BitStream_appendNum(bs1, 2, 3);
	assert_zero(ret, "Failed to append.");
	assert_zero(cmpBin(c2, bs1), "Internal data is incorrect.");

	ret = BitStream_appendNum(bs2, 16, 65535);
	assert_zero(ret, "Failed to append.");
	assert_zero(cmpBin(c3, bs2), "Internal data is incorrect.");

	ret = BitStream_append(bs1, bs2);
	assert_zero(ret, "Failed to append.");
	assert_zero(cmpBin(c4, bs1), "Internal data is incorrect.");

	ret = BitStream_appendNum(bs1, 13, 16383);
	assert_zero(ret, "Failed to append.");
	assert_zero(cmpBin(c5, bs1), "Internal data is incorrect.");

	testFinish();

	BitStream_free(bs1);
	BitStream_free(bs2);
}
Example #16
0
void test_insertStructuredAppendHeader(void)
{
	QRinput *stream;
	char correct[] = "0011000011111010010101000000000101000001";
	BitStream *bstream;
	int ret;

	testStart("Insert a structured-append header");
	stream = QRinput_new();
	QRinput_append(stream, QR_MODE_8, 1, (unsigned char *)"A");
	ret = QRinput_insertStructuredAppendHeader(stream, 16, 1, 0xa5);
	assert_zero(ret, "QRinput_insertStructuredAppendHeader() returns nonzero.\n");
	bstream = QRinput_mergeBitStream(stream);
	assert_nonnull(bstream->data, "Bstream->data is null.");
	assert_zero(cmpBin(correct, bstream), "bitstream is wrong.");
	testFinish();

	QRinput_free(stream);
	BitStream_free(bstream);
}
Example #17
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();
}
Example #18
0
void test_appendNum(void)
{
	BitStream *bstream;
	char correct[] = "10001010 11111111 11111111 00010010001101000101011001111000";

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

	BitStream_appendNum(bstream,  8, 0x0000008a);
	assert_zero(ncmpBin(correct, bstream, 8), "Internal data is incorrect.\n");

	BitStream_appendNum(bstream, 16, 0x0000ffff);
	assert_zero(ncmpBin(correct, bstream, 24), "Internal data is incorrect.\n");

	BitStream_appendNum(bstream, 32, 0x12345678);

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

	BitStream_free(bstream);
}
Example #19
0
static void fill(const ftcxx::DBEnv &env, const ftcxx::DB &db) {
    ftcxx::DBTxn txn(env);

    ftcxx::Slice val(1<<10);
    memset(val.mutable_data(), 'x', val.size());
    for (uint32_t i = 0; i < N; ++i) {
        int r = db.put(txn, ftcxx::Slice::slice_of(i), val);
        assert_zero(r);
    }

    txn.commit();
}
void test_textMQR(void)
{
	int version = 3;
	QRecLevel level = QR_ECLEVEL_M;
	char *str = "MICROQR";
	char *correct = {"01 0111 01111110000 01000110111 10001010010 011011 0000000 0000 11101100 0000"};
	int ret;

	testStart("Text encoding (Micro QR)");
	ret = encodeAndCheckBStream(1, version, level, QR_MODE_AN, str, correct);
	assert_zero(ret, "AlphaNumeric string '%s' incorrectly encoded.\n", str);
	testFinish();
}
Example #21
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);
}
Example #22
0
void test_calcRunLength(void)
{
	int width = 5;
	unsigned char frame[width * width];
	int runLength[width + 1];
	int i, j;
	int length;
	static unsigned char pattern[6][5] = {
		{0, 1, 0, 1, 0},
		{1, 0, 1, 0, 1},
		{0, 0, 0, 0, 0},
		{1, 1, 1, 1, 1},
		{0, 0, 1, 1, 1},
		{1, 1, 0, 0, 0}
	};
	static int expected[6][7] = {
		{ 1, 1, 1, 1, 1, 0, 5},
		{-1, 1, 1, 1, 1, 1, 6},
		{ 5, 0, 0, 0, 0, 0, 1},
		{-1, 5, 0, 0, 0, 0, 2},
		{ 2, 3, 0, 0, 0, 0, 2},
		{-1, 2, 3, 0, 0, 0, 3}
	};

	testStart("Test runlength calc function");
	for(i=0; i<6; i++) {
		length = Mask_calcRunLength(width, pattern[i], 0, runLength);
		assert_equal(expected[i][6], length, "Length incorrect: %d, expected %d.\n", length, expected[i][6]);
		assert_zero(memcmp(runLength, expected[i], sizeof(int) * expected[i][6]), "Run length does not match: pattern %d, horizontal access.\n", i);
		for(j=0; j<width; j++) {
			frame[j * width] = pattern[i][j];
		}
		length = Mask_calcRunLength(width, frame, 1, runLength);
		assert_equal(expected[i][6], length, "Length incorrect: %d, expected %d.\n", length, expected[i][6]);
		assert_zero(memcmp(runLength, expected[i], sizeof(int) * expected[i][6]), "Run length does not match: pattern %d, vertical access.\n", i);
	}
	testFinish();
}
void test_paddingMQR(void)
{
	char *dataM1[] = {"65", "513", "5139", "51365"};
	char *correctM1[] = {"01010000010000000000",
						 "01110000000010000000",
						 "10010000000011001000",
						 "10110000000011000001"};
	char *dataM2[] = {"513513", "51351365"};
	char *correctM2[] = {"0 0110 1000000001 1000000001 0000000",
						 "0 1000 1000000001 1000000001 1000001"};
	int i, ret;

	testStart("Padding bit check of MQR. (only 0 padding)");
	for(i=0; i<4; i++) {
		ret = encodeAndCheckBStream(1, 1, QR_ECLEVEL_L, QR_MODE_NUM, dataM1[i], correctM1[i]);
		assert_zero(ret, "Number %s incorrectly encoded.\n", dataM1[i]);
	}
	for(i=0; i<2; i++) {
		ret = encodeAndCheckBStream(1, 2, QR_ECLEVEL_M, QR_MODE_NUM, dataM2[i], correctM2[i]);
		assert_zero(ret, "Number %s incorrectly encoded.\n", dataM2[i]);
	}
	testFinish();
}
Example #24
0
void test_newWithBits(void)
{
	BitStream *bstream;
	unsigned char data[4] = {0, 1, 0, 1};

	testStart("New with bits");

	bstream = BitStream_newWithBits(4, data);
	assert_equal(bstream->length, 4, "Internal bit length is incorrect.\n");
	assert_equal(bstream->datasize, 4, "Internal buffer size is incorrect.\n");
	assert_zero(cmpBin("0101", bstream), "Internal data is incorrect.\n");

	testFinish();
}
void test_ECIinvalid(void)
{
	QRinput *stream;
	int ret;

	testStart("Appending invalid ECI header");
	stream = QRinput_new();
	ret = QRinput_appendECIheader(stream, 999999);
	assert_zero(ret, "Valid ECI header rejected.");
	ret = QRinput_appendECIheader(stream, 1000000);
	assert_nonzero(ret, "Invalid ECI header accepted.");
	QRinput_free(stream);
	testFinish();
}
Example #26
0
void test_mqrraw_new(void)
{
	QRinput *stream;
	char *num = "01234";
	unsigned char datacode[] = {0xa0, 0x62, 0x02};
	MQRRawCode *raw;

	testStart("Test MQRRaw_new()");
	stream = QRinput_newMQR(1, QR_ECLEVEL_L);
	QRinput_append(stream, QR_MODE_NUM, 5, (unsigned char *)num);

	raw = MQRraw_new(stream);
	assert_nonnull(raw, "Failed MQRraw_new().\n");
	assert_zero(raw->count, "MQRraw.count = %d != 0\n", raw->count);
	assert_equal(raw->version, 1, "MQRraw.version was not as expected. (%d)\n", raw->version);
	assert_equal(raw->dataLength, 3, "MQRraw.dataLength was not as expected.\n");
	assert_equal(raw->eccLength, 2, "MQRraw.eccLength was not as expected.\n");
	assert_zero(memcmp(raw->datacode, datacode, 3), "Datacode doesn't match.\n");


	QRinput_free(stream);
	MQRraw_free(raw);
	testFinish();
}
Example #27
0
void test_apiversion(void)
{
	int major_version, minor_version, micro_version;
	char *str, *str2;

	testStart("API Version check");
	QRcode_APIVersion(&major_version, &minor_version, &micro_version);
	assert_equal(major_version, MAJOR_VERSION, "Major version number mismatched: %d (%d expected)\n", major_version, MAJOR_VERSION);
	assert_equal(minor_version, MINOR_VERSION, "Minor version number mismatched: %d (%d expected)\n", minor_version, MINOR_VERSION);
	assert_equal(micro_version, MICRO_VERSION, "Micro version number mismatched: %d (%d expected)\n", micro_version, MICRO_VERSION);
	str = QRcode_APIVersionString();
	str2 = QRcode_APIVersionString();
	assert_zero(strcmp(VERSION, str), "Version string mismatched: %s (%s expected)\n", str, VERSION);
	assert_equal(str, str2, "Version strings are not identical.");
	testFinish();
}
Example #28
0
void test_newFrame(void)
{
	int width, i, y;
	unsigned char *frame;

	testStart("Test empty frames");
	for(i=1; i<MQRSPEC_VERSION_MAX; i++) {
		frame = MQRspec_newFrame(i);
		width = MQRspec_getWidth(i);
		for(y=0; y<width; y++) {
			assert_zero(memcmp(&frame[y * width], &v4frame[y * MQRSPEC_WIDTH_MAX], width), "Mismatch found in version %d, line %d.\n", i, y);
		}
		free(frame);
	}
	testFinish();
}
Example #29
0
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();
}
Example #30
0
void test_formatInfo(void)
{
	QRcode *qrcode;
	QRecLevel level;
	int mask;
	int ret;

	testStart("Test format info in QR code.");
	qrcode = QRcode_encodeString("AC-42", 1, QR_ECLEVEL_H, QR_MODE_8, 1);
	ret = QRcode_decodeFormat(qrcode, &level, &mask);
	assert_zero(ret, "Failed to decode.\n");
	assert_equal(level, QR_ECLEVEL_H, "Decoded format is wrong.\n");

	if(qrcode != NULL) QRcode_free(qrcode);

	testFinish();
}