2012-07-17 14:45:55 +08:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
|
#include <config.h>
|
|
|
|
|
#endif
|
|
|
|
|
|
2004-11-11 21:18:33 +00:00
|
|
|
#include <stdio.h>
|
2012-07-17 14:45:55 +08:00
|
|
|
#include <check.h>
|
2004-11-11 21:18:33 +00:00
|
|
|
|
2006-06-19 21:53:48 +00:00
|
|
|
#include <pulse/xmalloc.h>
|
2008-05-15 23:34:41 +00:00
|
|
|
|
2006-06-19 21:53:48 +00:00
|
|
|
#include <pulsecore/strlist.h>
|
2012-07-17 14:45:55 +08:00
|
|
|
#include <pulsecore/core-util.h>
|
2004-11-11 21:18:33 +00:00
|
|
|
|
2012-07-17 14:45:55 +08:00
|
|
|
START_TEST (strlist_test) {
|
2004-11-11 21:18:33 +00:00
|
|
|
char *t, *u;
|
2006-01-11 01:17:39 +00:00
|
|
|
pa_strlist *l = NULL;
|
2004-11-11 21:18:33 +00:00
|
|
|
|
|
|
|
|
l = pa_strlist_prepend(l, "e");
|
|
|
|
|
l = pa_strlist_prepend(l, "d");
|
|
|
|
|
l = pa_strlist_prepend(l, "c");
|
|
|
|
|
l = pa_strlist_prepend(l, "b");
|
|
|
|
|
l = pa_strlist_prepend(l, "a");
|
|
|
|
|
|
|
|
|
|
t = pa_strlist_tostring(l);
|
|
|
|
|
pa_strlist_free(l);
|
2007-01-04 13:43:45 +00:00
|
|
|
|
2004-11-11 21:18:33 +00:00
|
|
|
fprintf(stderr, "1: %s\n", t);
|
2012-07-17 14:45:55 +08:00
|
|
|
fail_unless(pa_streq(t, "a b c d e"));
|
2004-11-11 21:18:33 +00:00
|
|
|
|
|
|
|
|
l = pa_strlist_parse(t);
|
|
|
|
|
pa_xfree(t);
|
|
|
|
|
|
|
|
|
|
t = pa_strlist_tostring(l);
|
|
|
|
|
fprintf(stderr, "2: %s\n", t);
|
2012-07-17 14:45:55 +08:00
|
|
|
fail_unless(pa_streq(t, "a b c d e"));
|
2004-11-11 21:18:33 +00:00
|
|
|
pa_xfree(t);
|
|
|
|
|
|
|
|
|
|
l = pa_strlist_pop(l, &u);
|
|
|
|
|
fprintf(stderr, "3: %s\n", u);
|
2012-07-17 14:45:55 +08:00
|
|
|
fail_unless(pa_streq(u, "a"));
|
2004-11-11 21:18:33 +00:00
|
|
|
pa_xfree(u);
|
2007-01-04 13:43:45 +00:00
|
|
|
|
2004-11-11 21:18:33 +00:00
|
|
|
l = pa_strlist_remove(l, "c");
|
2007-01-04 13:43:45 +00:00
|
|
|
|
2004-11-11 21:18:33 +00:00
|
|
|
t = pa_strlist_tostring(l);
|
|
|
|
|
fprintf(stderr, "4: %s\n", t);
|
2012-07-17 14:45:55 +08:00
|
|
|
fail_unless(pa_streq(t, "b d e"));
|
2004-11-11 21:18:33 +00:00
|
|
|
pa_xfree(t);
|
|
|
|
|
|
|
|
|
|
pa_strlist_free(l);
|
2012-07-17 14:45:55 +08:00
|
|
|
}
|
|
|
|
|
END_TEST
|
|
|
|
|
|
|
|
|
|
int main(int argc, char *argv[]) {
|
|
|
|
|
int failed = 0;
|
|
|
|
|
Suite *s;
|
|
|
|
|
TCase *tc;
|
|
|
|
|
SRunner *sr;
|
|
|
|
|
|
|
|
|
|
s = suite_create("StrList");
|
|
|
|
|
tc = tcase_create("strlist");
|
|
|
|
|
tcase_add_test(tc, strlist_test);
|
|
|
|
|
suite_add_tcase(s, tc);
|
|
|
|
|
|
|
|
|
|
sr = srunner_create(s);
|
|
|
|
|
srunner_run_all(sr, CK_NORMAL);
|
|
|
|
|
failed = srunner_ntests_failed(sr);
|
|
|
|
|
srunner_free(sr);
|
2004-11-21 16:27:51 +00:00
|
|
|
|
2012-07-17 14:45:55 +08:00
|
|
|
return (failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
|
2004-11-11 21:18:33 +00:00
|
|
|
}
|