Skip to content

Commit

Permalink
[skiplist] Inline testing.
Browse files Browse the repository at this point in the history
Add a loop to create a skip list to allow manual checking.
  • Loading branch information
Chris Wilson committed Nov 16, 2008
1 parent e44c1f2 commit 032be98
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,12 @@ TESTS += check-link$(EXEEXT)
endif

EXTRA_DIST += $(TESTS_SH) check-has-hidden-symbols.c
check_PROGRAMS += check-link
check_PROGRAMS += check-link check-skiplist
check_link_LDADD = libcairo.la

check_skiplist_SOURCES = cairo-skiplist.c
check_skiplist_CPPFLAGS = -DMAIN $(AM_CPPFLAGS)

check: headers-standalone

PREPROCESS_ARGS = $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS)
Expand Down
36 changes: 36 additions & 0 deletions src/cairo-skiplist.c
Original file line number Diff line number Diff line change
Expand Up @@ -305,3 +305,39 @@ _cairo_skip_list_delete_given (cairo_skip_list_t *list, skip_elt_t *given)
list->max_level--;
free_elt (list, elt);
}

#if MAIN
typedef struct {
int n;
skip_elt_t elt;
} test_elt_t;

static int
test_cmp (void *list, void *A, void *B)
{
const test_elt_t *a = A, *b = B;
return a->n - b->n;
}

int
main (void)
{
cairo_skip_list_t list;
test_elt_t elt;
int n;

_cairo_skip_list_init (&list, test_cmp, sizeof (test_elt_t));
for (n = 0; n < 10000000; n++) {
void *elt_and_data;
elt.n = n;
elt_and_data = _cairo_skip_list_insert (&list, &elt, TRUE);
assert (elt_and_data != NULL);
}
_cairo_skip_list_fini (&list);

return 0;
}

/* required supporting stubs */
cairo_status_t _cairo_error (cairo_status_t status) { return status; }
#endif

0 comments on commit 032be98

Please sign in to comment.