test_block.c 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. /**
  2. * This is a test for block in si
  3. */
  4. #include "si_test.h"
  5. #include "si_block.h"
  6. TEST_FUNC(si_block) {
  7. char * s[] = { "Hello", "World", "This", "Is", "Me"};
  8. SiBlock * b = siblock_newempty(sizeof(char *));
  9. TEST_NOTNULL(b);
  10. TEST_INTEQ(siblock_elementsize(b), sizeof(char *));
  11. TEST_INTEQ(siblock_size(b), 0);
  12. TEST_NULL(siblock_getptr(b, 10));
  13. TEST_NULL(siblock_getptr(b, 1));
  14. TEST_NOTNULL(siblock_addptr(b, s[0]));
  15. TEST_NOTNULL(siblock_addptr(b, s[1]));
  16. TEST_INTEQ(siblock_size(b), 2);
  17. TEST_NOTNULL(siblock_getptr(b, 1));
  18. TEST_NOTNULL(siblock_getptr(b, 0));
  19. TEST_STREQ(((char *)siblock_getptr(b, 1)), s[1]);
  20. TEST_STREQ(((char *)siblock_getptr(b, 0)), s[0]);
  21. TEST_NOTNULL(siblock_setptr(b, 301, s[3]));
  22. TEST_NOTNULL(siblock_getptr(b, 301));
  23. TEST_INTEQ(siblock_size(b), 302);
  24. TEST_STREQ(((char **)siblock_getptr(b, 301)), s[3]);
  25. TEST_NOTNULL(siblock_setptr(b, 401, s[4]));
  26. TEST_INTEQ(siblock_size(b), 402);
  27. TEST_NOTNULL(siblock_getptr(b, 401));
  28. TEST_STREQ(((char **)siblock_getptr(b, 401)), s[4]);
  29. siblock_free(b);
  30. TEST_DONE();
  31. }
  32. int main(void) {
  33. TEST_INIT();
  34. TEST_RUN(si_block);
  35. TEST_REPORT();
  36. }