test-array.c revision cca8abdc46f329a236efcffc6b82ac15e7331ba0
/* Copyright (c) 2007-2015 Dovecot authors, see the included COPYING file */
#include "test-lib.h"
#include "array.h"
#include <stdlib.h> /* rand() */
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_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[] = {
-32768, -16384, -512, -256, -128, -64, -2, -1,
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 */
return FATAL_TEST_FAILURE;
} break;
case 1: {
/* actual out of range address requested */
return FATAL_TEST_FAILURE;
} break;
case 2: {
return FATAL_TEST_FAILURE;
} break;
}
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 -1.*/
}