Hash :
e72cf9ef
Author :
Date :
2014-08-05T15:43:17
main()'s arguments now correctly declared.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include "common.h"
#include "../qrinput.h"
#include "../qrencode_inner.h"
#include "../split.h"
#include "decoder.h"
#include "URI_testset.inc"
void encodeURLandPrint(char *url) {
QRinput *input;
BitStream *bstream;
input = QRinput_new2(0, QR_ECLEVEL_L);
Split_splitStringToQRinput(url, input, QR_MODE_8, 1);
bstream = BitStream_new();
QRinput_mergeBitStream(input, bstream);
printf("{%d,\"%s\"},\n", BitStream_size(bstream), url);
QRinput_free(input);
BitStream_free(bstream);
}
void print_currentBitLength() {
struct TestSet *ts = testset;
puts("struct TestSet {\n\tint expected_length;\n\tchar *url;\n};");
puts("\nstruct TestSet testset[] = {");
while(ts->url != NULL) {
encodeURLandPrint(ts->url);
ts++;
}
puts("{0,NULL}\n};");
}
int encodeURLandCompare(char *url, int expected_length) {
QRinput *input;
BitStream *bstream;
int ret = 0;
input = QRinput_new2(0, QR_ECLEVEL_L);
Split_splitStringToQRinput(url, input, QR_MODE_8, 1);
bstream = BitStream_new();
QRinput_mergeBitStream(input, bstream);
int length = BitStream_size(bstream);
if(length > expected_length) {
printf("The length of the encode stream is longer than expected: %d over %d\n", length, expected_length);
printQRinput(input);
ret = 1;
} else if(length < expected_length) {
printf("The length of the encode stream is shorter than expected: %d under %d\n", length, expected_length);
printQRinput(input);
ret = 1;
}
QRinput_free(input);
BitStream_free(bstream);
return ret;
}
void test_bitstream_length() {
struct TestSet *ts = testset;
int err = 0;
testStart("Split_URL test: compare bitstream length");
while(ts->url != NULL) {
err += encodeURLandCompare(ts->url, ts->expected_length);
ts++;
}
testEnd(err);
}
int main(int argc, char **argv)
{
test_bitstream_length();
report();
return 0;
}