Branch
Hash :
f8ceb0d2
Author :
Date :
2020-08-28T18:38:00
All test programs are now TAP-ready.
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 90 91 92
#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"
#if 0
static 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("{%zu,\"%s\"},\n", BitStream_size(bstream), url);
QRinput_free(input);
BitStream_free(bstream);
}
static 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};");
}
#endif
static int encodeURLandCompare(char *url, size_t 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);
size_t length = BitStream_size(bstream);
if(length > expected_length) {
printf("The length of the encode stream is longer than expected: %zu over %zu\n", length, expected_length);
printQRinput(input);
ret = 1;
} else if(length < expected_length) {
printf("The length of the encode stream is shorter than expected: %zu under %zu\n", length, expected_length);
printQRinput(input);
ret = 1;
}
QRinput_free(input);
BitStream_free(bstream);
return ret;
}
static 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 tests = 1;
testInit(tests);
test_bitstream_length();
testReport(tests);
return 0;
}