test-numpack.c revision 7cb128dc4cae2a03a742f63ba7afee23c78e3af0
/* Copyright (c) 2013-2015 Dovecot authors, see the included COPYING file */
#include "test-lib.h"
#include "buffer.h"
#include "numpack.h"
#include <stdlib.h>
static struct test {
unsigned int output_size;
} enc_tests[] = {
{ 0xffffffff, { 0xff, 0xff, 0xff, 0xff, 0xf }, 5 },
{ 0, { 0 }, 1 },
{ 0x7f, { 0x7f }, 1 },
{ 0x80, { 0x80, 1 }, 2 },
{ 0x81, { 0x81, 1 }, 2 },
{ 0xdeadbeefcafe, { 0xfe, 0x95, 0xbf, 0xf7, 0xdb, 0xd5, 0x37 }, 7 },
{ 0xffffffffffffffff, { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 1 }, 10 },
{ 0xfffffffe, { 0xfe, 0xff, 0xff, 0xff, 0xf }, 5 },
};
static struct fail {
unsigned int input_size;
} dec_fails[] = {
{ { 0 }, 0 }, /* has no termination byte */
{ { 0x80 }, 1 }, /* ditto */
{ { 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80 }, 10 }, /* ditto*/
{ { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 2 }, 10 }, /* overflow */
{ { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f }, 11 }, /* ditto */
};
void test_numpack(void)
{
unsigned int i;
test_begin("numpack (good)");
for (i = 0; i < N_ELEMENTS(enc_tests); i++) {
buffer_set_used_size(buf, 0);
enc_tests[i].output_size) == 0,
i);
}
test_end();
test_begin("numpack (bad)");
for (i = 0; i < N_ELEMENTS(dec_fails); i++) {
}
test_end();
}