test-array.c revision ba1a5db879b08d2fefcb42160af67853cdfe7687
/* Copyright (c) 2007-2017 Dovecot authors, see the included COPYING file */
#include "test-lib.h"
#include "array.h"
struct foo {
unsigned int a, b, c;
};
static void test_array_count(void)
{
test_begin("array count/empty");
test_end();
}
static void test_array_foreach(void)
{
unsigned int i;
test_begin("array foreach");
for (i = 0; i < 10; i++) {
}
test_assert(foo->a == i);
test_assert(foo->b == i);
test_assert(foo->c == i);
}
test_end();
}
static void test_array_foreach_elem_struct(void)
{
unsigned int i;
test_begin("array foreach_elem struct");
for (i = 0; i < 10; i++) {
}
i = 0;
test_assert_idx(foo.a == i, i);
test_assert_idx(foo.b == i, i);
test_assert_idx(foo.c == i, i);
i++;
}
test_end();
}
static void test_array_foreach_elem_string(void)
{
char *string;
const char *cstring;
int i;
test_begin("array foreach_elem ro/rw strings");
for (i = 0; i < 10; i++) {
}
i = 0;
i++;
}
i = 0;
i++;
}
test_end();
}
static void test_array_swap(void)
{
int i, j;
test_begin("array swap");
for (i = 1; i <= 3; i++) {
for (j = 1; j <= 2*i+1; j++) {
}
}
for (i = 0; i < 1000; i++)
/* Just want size 3, 5, and 7 in any order */
test_end();
}
{
0;
}
static void test_array_reverse(void)
{
unsigned int i, j;
test_begin("array reverse");
for (i = 0; i <= N_ELEMENTS(input); i++) {
for (j = 0; j < i; j++)
}
test_end();
test_begin("array_lsearch");
for (i = 0; i < N_ELEMENTS(input); i++) {
}
test_end();
}
{
: 0;
}
static int test_compare_ushort_fuzz(const unsigned short *c1, const unsigned short *c2, const int *pfuzz)
{
return 0;
return d;
}
static void test_array_cmp(void)
{
static const unsigned short deltas[] = {
0x8000, 0xc000, 0xfe00, 0xff00, 0xff80, 0xffc0, 0xfffe, 0xffff,
0, 1, 2, 64, 128, 256, 512, 16384, 32768
};
#define NELEMS 5u
unsigned int i;
int fuzz;
test_begin("array compare (ushort)");
for (i = 0; i < NELEMS; i++) {
}
fuzz = 0;
for (i = 0; i < 256; i++) {
if (fuzz < 0)
if (fuzz > 0) {
fuzz--;
}
fuzz = 0;
}
test_end();
}
{
}
static void test_array_cmp_str(void)
{
#define NELEMS 5u
unsigned int i;
test_begin("array compare (char*)");
for (i = 0; i < NELEMS; i++) {
}
for (i = 0; i < 2560; i++) {
char buf[12];
}
/* length differences being detected are tested in other tests */
test_end();
}
void test_array(void)
{
}
{
static const void *useless_ptr; /* persuade gcc to not optimise the tests */
switch(stage) {
case 0: {
test_begin("fatal_array");
/* allocation big enough, but memory not initialised */
test_expect_fatal_string("(array_idx_i): assertion failed: (idx * array->element_size < array->buffer->used)");
return FATAL_TEST_FAILURE;
}
case 1: {
/* actual out of range address requested */
test_expect_fatal_string("(array_idx_i): assertion failed: (idx * array->element_size < array->buffer->used)");
return FATAL_TEST_FAILURE;
}
case 2: {
/* can't copy different array sizes */
test_expect_fatal_string("(array_copy): assertion failed: (dest->element_size == src->element_size)");
return FATAL_TEST_FAILURE;
}
}
test_end();
/* Forces the compiler to check the value of useless_ptr, so that it
must call array_idx (which is marked as pure, and gcc was desperate
to optimise out. Of course, gcc is unaware stage is never UINT_MAX.*/
}