Skip to content

Commit

Permalink
Merge pull request twitter#4 from twitter/cc_array-test-1
Browse files Browse the repository at this point in the history
Create basic cc_array test
  • Loading branch information
Yao Yue committed Nov 11, 2015
2 parents ca13b1b + 7bcca7b commit dc6caae
Showing 1 changed file with 51 additions and 2 deletions.
53 changes: 51 additions & 2 deletions test/array/check_array.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,67 @@
#define SUITE_NAME "array"
#define DEBUG_LOG SUITE_NAME ".log"

#define ARRAY_MAX_NELEM_DELTA 8

/*
* utilities
*/
static void
test_setup(void)
{
array_setup(ARRAY_MAX_NELEM_DELTA);
}

static void
test_reset(void)
test_teardown(void)
{
array_teardown();
}

static void
test_teardown(void)
test_reset(void)
{
test_teardown();
test_setup();
}

START_TEST(test_create_push_pop_destroy)
{
#define NALLOC 4
#define SIZE 8
struct array *arr;
uint64_t *el;

test_reset();

ck_assert_int_eq(array_create(&arr, NALLOC, SIZE), CC_OK);
ck_assert_ptr_ne(arr, NULL);

el = array_push(arr);
*el = 1;

el = array_push(arr);
*el = 2;

el = array_push(arr);
*el = 3;

el = array_pop(arr);
ck_assert_int_eq(*el, 3);

el = array_pop(arr);
ck_assert_int_eq(*el, 2);

el = array_pop(arr);
ck_assert_int_eq(*el, 1);

array_destroy(&arr);
ck_assert_ptr_eq(arr, NULL);
#undef NALLOC
#undef SIZE
}
END_TEST

/*
* test suite
*/
Expand All @@ -34,6 +77,12 @@ array_suite(void)
{
Suite *s = suite_create(SUITE_NAME);

/* basic requests */
TCase *tc_array = tcase_create("cc_array test");
suite_add_tcase(s, tc_array);

tcase_add_test(tc_array, test_create_push_pop_destroy);

return s;
}
/**************
Expand Down

0 comments on commit dc6caae

Please sign in to comment.