int empty = fifo_is_empty(f);
ck_assert_int_eq(empty, 1);
// Check we can't add NULL to the fifo int success = fifo_add_item(f, NULL);
ck_assert_int_eq(success, 0);
// Check we can't remove anything from an empty fifo void *vp = fifo_remove_item(f);
ck_assert_ptr_eq(vp, NULL);
// Add some static strings to the FIFO constchar **s; unsignedint n = 0; for (s = &strings[0] ; *s != NULL; ++s)
{
fifo_add_item(f, (void *)*s);
++n;
}
// Add some dynamically allocated strings to the FIFO constchar **s; unsignedint n = 0; for (s = &strings[0] ; *s != NULL; ++s)
{ int ok = fifo_add_item(f, (void *)strdup(*s));
ck_assert_int_eq(ok, 1);
++n;
}
// Delete the fifo, freeing the allocated strings. Check free() is called // the expected number of times. int c = 0;
fifo_delete(f, &c);
ck_assert_int_eq(c, n);
}
END_TEST
// Fill the fifo with dynamically allocated strings int i; for (i = 0; i < LARGE_TEST_SIZE; ++i)
{ int ok = fifo_add_item(f, (void *)strdup("test item"));
ck_assert_int_eq(ok, 1);
}
// Clear the fifo, checking free is called the expected number of times int c = 0;
fifo_clear(f, &c);
ck_assert_int_eq(c, LARGE_TEST_SIZE);
int empty = fifo_is_empty(f);
ck_assert_int_eq(empty, 1);
// Finally delete the fifo, checking free is not called this time
c = 0;
fifo_delete(f, &c);
ck_assert_int_eq(c, 0);
}
END_TEST
// Fill the fifo with dynamically allocated strings int i; for (i = 0; i < LARGE_TEST_SIZE; ++i)
{
g_snprintf(buff, sizeof(buff), "%d", i); int ok = fifo_add_item(f, (void *)strdup(buff));
ck_assert_int_eq(ok, 1);
}
// Extract all the strings from the fifo, making sure they're // as expected for (i = 0; i < LARGE_TEST_SIZE; ++i)
{
g_snprintf(buff, sizeof(buff), "%d", i); char *s = fifo_remove_item(f);
ck_assert_ptr_ne(s, NULL);
ck_assert_str_eq(s, buff);
free(s);
}
int empty = fifo_is_empty(f);
ck_assert_int_eq(empty, 1);
int c = 0;
fifo_delete(f, &c);
ck_assert_int_eq(c, 0);
}
END_TEST
/******************************************************************************/
Suite *
make_suite_test_fifo(void)
{
Suite *s;
TCase *tc_simple;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.