test_list.c 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #include <stdio.h>
  2. #include <stddef.h>
  3. #include "si_test.h"
  4. #include "si_list.h"
  5. void * cursor_search(SiCursor * cursor, void * extra) {
  6. char * data = (char *) sicursor_data(cursor);
  7. char * tofind = (char *) extra;
  8. if (strcmp(data, tofind) == 0) return tofind;
  9. return NULL;
  10. }
  11. void * walker_search(void * value, void * key, void * list, void * extra) {
  12. char * data = (char *) value;
  13. char * tofind = (char *) extra;
  14. printf("%s %s\n", data, tofind);
  15. if (strcmp(data, tofind) == 0) return tofind;
  16. return NULL;
  17. }
  18. TEST_FUNC(silist) {
  19. char * aid;
  20. char * s[] = { "Hello", "World", "This", "Is", "Me"};
  21. SiList * list = silist_new(s[0]);
  22. TEST_NOTNULL(list);
  23. TEST_NOTNULL(silist_add(list, s[1]));
  24. TEST_NOTNULL(silist_add(list, s[2]));
  25. TEST_NOTNULL(silist_add(list, s[3]));
  26. TEST_NOTNULL(silist_add(list, s[4]));
  27. TEST_NOTNULL(silist_last(list));
  28. TEST_STREQ(silist_data(silist_last(list)), s[4]);
  29. aid = (char *) silist_walk(list, walker_search, "Is");
  30. TEST_NOTNULL(aid);
  31. TEST_STREQ(aid, "Is");
  32. /*
  33. {
  34. SiCursor * index = silist_cursor(list);
  35. int okindex = 0;
  36. TEST_NOTNULL(index);
  37. while(index) {
  38. TEST_INTEQ(okindex, sicursor_index(index));
  39. puts((char *)sicursor_data(index));
  40. index = sicursor_next(index);
  41. okindex++;
  42. }
  43. }
  44. {
  45. char * res =
  46. (char *) sicursor_each(silist_cursor(list), cursor_search, "Me");
  47. TEST_NOTNULL(res);
  48. TEST_STREQ(res, "Me");
  49. }
  50. */
  51. silist_free(list);
  52. TEST_DONE();
  53. }
  54. int main(void) {
  55. TEST_INIT();
  56. TEST_RUN(silist);
  57. TEST_REPORT();
  58. }