list_test.c revision a734c64bff58bda2fa48c2795453e092167b0ff7
/*
* Copyright (C) 2011 Michael Brown <mbrown@fensystems.co.uk>.
*
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/** @file
*
* List function tests
*
*/
/* Forcibly enable assertions for list_check() */
#include <assert.h>
#include <string.h>
#include <stdio.h>
/** A list test structure */
struct list_test {
/** List element */
/** Label */
char label;
};
/** List test elements */
static struct list_test list_tests[] = {
{ .label = '0' },
{ .label = '1' },
{ .label = '2' },
{ .label = '3' },
{ .label = '4' },
{ .label = '5' },
{ .label = '6' },
{ .label = '7' },
{ .label = '8' },
{ .label = '9' },
};
/** Test list */
/**
* Check list contents are as expected
*
* @v list Test list
* @v expected Expected contents
* @v ok List contents are as expected
*/
const char *expected ) {
size_t num_entries = 0;
/* Determine size of list */
num_entries++;
{
char *tmp;
/* Build up list content string */
*tmp = '\0';
/* Sanity check reversed list */
*tmp = '\0';
printf ( "FAILURE: list reversal mismatch (forward "
"\"%s\", reverse \"%s\")\n",
return 0;
}
/* Compare against expected content */
return 1;
} else {
printf ( "FAILURE: expected \"%s\", got \"%s\"\n",
return 0;
}
}
}
/**
* Report list test result
*
* @v list Test list
* @v expected Expected contents
*/
} while ( 0 )
/**
* Report list iteration test result
*
* @v macro Iterator macro
* @v expected Expected contents
* @v pos Iterator
* @v ... Arguments to iterator macro
*/
list ); \
} \
} while ( 0 )
/**
* Report list entry iteration test result
*
* @v macro Iterator macro
* @v expected Expected contents
* @v pos Iterator
* @v ... Arguments to iterator macro
*/
} \
} while ( 0 )
/**
* Perform list self-test
*
*/
static void list_test_exec ( void ) {
struct list_head target_list;
/* Test initialiser and list_empty() */
/* Test list_add(), list_add_tail() and list_del() */
INIT_LIST_HEAD ( list );
/* Test list_is_singular() */
INIT_LIST_HEAD ( list );
/* Test list_is_last() */
INIT_LIST_HEAD ( list );
/* Test list_cut_position() - empty list */
INIT_LIST_HEAD ( list );
INIT_LIST_HEAD ( target );
/* Test list_cut_position() - singular list, move nothing */
INIT_LIST_HEAD ( list );
INIT_LIST_HEAD ( target );
/* Test list_cut_position() - singular list, move singular entry */
INIT_LIST_HEAD ( list );
INIT_LIST_HEAD ( target );
/* Test list_cut_position() - multi-entry list, move nothing */
INIT_LIST_HEAD ( list );
INIT_LIST_HEAD ( target );
/* Test list_cut_position() - multi-entry list, move some */
INIT_LIST_HEAD ( list );
INIT_LIST_HEAD ( target );
/* Test list_cut_position() - multi-entry list, move everything */
INIT_LIST_HEAD ( list );
INIT_LIST_HEAD ( target );
/* Test list_splice() - empty list */
INIT_LIST_HEAD ( list );
INIT_LIST_HEAD ( target );
/* Test list_splice() - both lists empty */
INIT_LIST_HEAD ( list );
INIT_LIST_HEAD ( target );
/* Test list_splice() - source list empty */
INIT_LIST_HEAD ( list );
INIT_LIST_HEAD ( target );
/* Test list_splice() - destination list empty */
INIT_LIST_HEAD ( list );
INIT_LIST_HEAD ( target );
/* Test list_splice() - both lists non-empty */
INIT_LIST_HEAD ( list );
INIT_LIST_HEAD ( target );
/* Test list_splice_tail() - both lists empty */
INIT_LIST_HEAD ( list );
INIT_LIST_HEAD ( target );
/* Test list_splice_tail() - source list empty */
INIT_LIST_HEAD ( list );
INIT_LIST_HEAD ( target );
/* Test list_splice_tail() - destination list empty */
INIT_LIST_HEAD ( list );
INIT_LIST_HEAD ( target );
/* Test list_splice_tail() - both lists non-empty */
INIT_LIST_HEAD ( list );
INIT_LIST_HEAD ( target );
/* Test list_splice_init() */
INIT_LIST_HEAD ( list );
INIT_LIST_HEAD ( target );
/* Test list_splice_tail_init() */
INIT_LIST_HEAD ( list );
INIT_LIST_HEAD ( target );
/* Test list_entry() */
== &list_tests[3] );
/* Test list_first_entry() and list_last_entry() */
INIT_LIST_HEAD ( list );
== &list_tests[9] );
== &list_tests[6] );
== &list_tests[5] );
== &list_tests[6] );
== &list_tests[5] );
== &list_tests[5] );
/* Test list_for_each() */
INIT_LIST_HEAD ( list );
/* Test list_for_each_entry() and list_for_each_entry_reverse() */
INIT_LIST_HEAD ( list );
/* Test list_for_each_entry_safe() */
INIT_LIST_HEAD ( list );
{
char *expected = "241";
expected++;
}
}
/* Test list_for_each_entry_continue() and
* list_for_each_entry_continue_reverse()
*/
INIT_LIST_HEAD ( list );
/* Test list_contains() and list_contains_entry() */
INIT_LIST_HEAD ( list );
/* Test list_check_contains_entry() */
INIT_LIST_HEAD ( list );
}
/** List self-test */
.name = "list",
.exec = list_test_exec,
};