test_str.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /**
  2. * This is a test for str in $package$
  3. */
  4. #include "si_test.h"
  5. #include "str.h"
  6. TEST_FUNC(str) {
  7. /** Test the cstr_simplematch function */
  8. TEST_ASSERT(cstr_simplematch("$a", 'x'));
  9. TEST_ASSERT(cstr_simplematch("$a", '0'));
  10. TEST_ASSERT(cstr_simplematch("$A", 'x'));
  11. TEST_ASSERT(!cstr_simplematch("$A", '0'));
  12. TEST_ASSERT(cstr_simplematch(".", '\n'));
  13. TEST_ASSERT(cstr_simplematch("@\n\r", '\n'));
  14. TEST_ASSERT(!cstr_simplematch("!@\r\n", '\n'));
  15. TEST_ASSERT(!cstr_simplematch("", '\n'));
  16. TEST_ASSERT(!cstr_simplematch(NULL, '\n'));
  17. TEST_ASSERT(cstr_simplematch("@0123456789", '5'));
  18. TEST_ASSERT(!cstr_simplematch("@0123456789", ' '));
  19. TEST_DONE();
  20. }
  21. TEST_FUNC(strlist) {
  22. int index;
  23. USTR * ustr;
  24. USTRListNode * node;
  25. char * data[] = { "one", "two", "three", "four" };
  26. char * zero = "zero";
  27. USTRList list;
  28. /** Test the cstr_simplematch function */
  29. TEST_NOTNULL(ustrlist_init(&list));
  30. for(index = 0; index < 4; index ++) {
  31. TEST_NOTNULL(ustrlist_addcstr(&list, data[index]));
  32. }
  33. TEST_NOTNULL(ustrlist_shiftcstr(&list, zero));
  34. for(node = ustrlist_head(&list); node; node = ustrlistnode_next(node)) {
  35. printf("%s\n", ustr_c(ustrlistnode_ustr(node)));
  36. }
  37. TEST_NOTNULL(ustrlist_droplast(&list));
  38. for(node = ustrlist_head(&list); node; node = ustrlistnode_next(node)) {
  39. printf("%s\n", ustr_c(ustrlistnode_ustr(node)));
  40. }
  41. ustr = ustrlist_joinwithcstr(&list, " , ");
  42. printf("%s\n", ustr_c(ustr));
  43. TEST_NOTNULL(ustrlist_shiftustr(&list, ustr));
  44. ustr_free(ustr);
  45. for(node = ustrlist_head(&list); node; node = ustrlistnode_next(node)) {
  46. printf("%s\n", ustr_c(ustrlistnode_ustr(node)));
  47. }
  48. TEST_NOTNULL(ustrlist_done(&list));
  49. TEST_DONE();
  50. }
  51. int main(void) {
  52. TEST_INIT();
  53. TEST_RUN(str);
  54. TEST_RUN(strlist);
  55. TEST_REPORT();
  56. }