72 lines
1.9 KiB
C
72 lines
1.9 KiB
C
|
|
/*
|
||
|
|
* KNOWN FAILING -- TODO.md section 2.1.2
|
||
|
|
*
|
||
|
|
* aksl_list_iterate runs a Floyd cycle check that leaves `slow` sitting at the
|
||
|
|
* list midpoint, and then starts the visiting loop from `slow` instead of from
|
||
|
|
* `list`. Every node before the midpoint -- including the head -- is never
|
||
|
|
* passed to the callback.
|
||
|
|
*
|
||
|
|
* The list here is built by hand rather than with aksl_list_append so that this
|
||
|
|
* test fails only for the iterate defect, not for the separate append defect in
|
||
|
|
* TODO.md 2.1.1.
|
||
|
|
*
|
||
|
|
* Registered in AKSL_KNOWN_FAILING_TESTS (WILL_FAIL). When iterate is fixed,
|
||
|
|
* CTest reports this as unexpectedly passing -- move it into AKSL_TESTS then.
|
||
|
|
*/
|
||
|
|
|
||
|
|
#include "aksl_capture.h"
|
||
|
|
|
||
|
|
#define CHAIN_LEN 3
|
||
|
|
|
||
|
|
typedef struct VisitLog
|
||
|
|
{
|
||
|
|
int count;
|
||
|
|
aksl_ListNode *seen[CHAIN_LEN];
|
||
|
|
} VisitLog;
|
||
|
|
|
||
|
|
static akerr_ErrorContext AKERR_NOIGNORE *record_visit(aksl_ListNode *node, void *data)
|
||
|
|
{
|
||
|
|
VisitLog *log = NULL;
|
||
|
|
|
||
|
|
PREPARE_ERROR(e);
|
||
|
|
FAIL_ZERO_RETURN(e, node, AKERR_NULLPOINTER, "node");
|
||
|
|
FAIL_ZERO_RETURN(e, data, AKERR_NULLPOINTER, "data");
|
||
|
|
log = (VisitLog *)data;
|
||
|
|
if ( log->count < CHAIN_LEN ) {
|
||
|
|
log->seen[log->count] = node;
|
||
|
|
}
|
||
|
|
log->count += 1;
|
||
|
|
SUCCEED_RETURN(e);
|
||
|
|
}
|
||
|
|
|
||
|
|
static int test_iterate_visits_every_node_from_the_head(void)
|
||
|
|
{
|
||
|
|
aksl_ListNode node[CHAIN_LEN];
|
||
|
|
VisitLog log;
|
||
|
|
int i = 0;
|
||
|
|
|
||
|
|
memset((void *)node, 0x00, sizeof(node));
|
||
|
|
memset((void *)&log, 0x00, sizeof(log));
|
||
|
|
|
||
|
|
for ( i = 1; i < CHAIN_LEN; i++ ) {
|
||
|
|
node[i - 1].next = &node[i];
|
||
|
|
node[i].prev = &node[i - 1];
|
||
|
|
}
|
||
|
|
|
||
|
|
AKSL_CHECK_OK(aksl_list_iterate(&node[0], &record_visit, &log));
|
||
|
|
AKSL_CHECK(log.count == CHAIN_LEN);
|
||
|
|
for ( i = 0; i < CHAIN_LEN; i++ ) {
|
||
|
|
AKSL_CHECK(log.seen[i] == &node[i]);
|
||
|
|
}
|
||
|
|
return 0;
|
||
|
|
}
|
||
|
|
|
||
|
|
int main(void)
|
||
|
|
{
|
||
|
|
int failures = 0;
|
||
|
|
|
||
|
|
akerr_init();
|
||
|
|
AKSL_RUN(failures, test_iterate_visits_every_node_from_the_head);
|
||
|
|
AKSL_REPORT(failures);
|
||
|
|
}
|