test_bad.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /**
  2. * This is a test for bad in $package$
  3. */
  4. #include "si_test.h"
  5. #include "bad.h"
  6. TEST_FUNC(bad) {
  7. TEST_DONE();
  8. }
  9. TEST_FUNC(badchildtree) {
  10. int index;
  11. BadChildtree tnodes[32];
  12. BadChildtree * nodes[32];
  13. for(index = 0; index < 32; index ++) {
  14. badchildtree_initnull(tnodes + index);
  15. nodes[index] = tnodes + index;
  16. }
  17. badchildtree_appendchild(nodes[0], nodes[1]);
  18. badchildtree_appendchild(nodes[0], nodes[2]);
  19. badchildtree_appendchild(nodes[0], nodes[3]);
  20. badchildtree_appendchild(nodes[0], nodes[4]);
  21. badchildtree_appendchild(nodes[2], nodes[5]);
  22. badchildtree_appendchild(nodes[2], nodes[6]);
  23. badchildtree_appendchild(nodes[2], nodes[7]);
  24. badchildtree_appendchild(nodes[4], nodes[8]);
  25. badchildtree_appendchild(nodes[4], nodes[9]);
  26. badchildtree_appendchild(nodes[9], nodes[10]);
  27. badchildtree_appendchild(nodes[9], nodes[11]);
  28. badchildtree_printgraph(nodes[0], 0);
  29. TEST_DONE();
  30. }
  31. TEST_FUNC(badpar) {
  32. void * arr;
  33. size_t size = 123;
  34. arr = badpar_new(size);
  35. TEST_NOTNULL(arr);
  36. TEST_NOTNULL(badpar_put(arr, size, 17, "Hello"));
  37. TEST_NOTNULL(badpar_get(arr, size, 17));
  38. TEST_NULL(badpar_get(arr, size, 321));
  39. puts(badpar_get(arr, size, 17));
  40. TEST_NOTNULL(badpar_resize(&arr, &size, 100));
  41. TEST_NOTNULL(badpar_put(arr, size, 210, "World"));
  42. TEST_NOTNULL(badpar_get(arr, size, 210));
  43. puts(badpar_get(arr, size, 210));
  44. TEST_NULL(badpar_free(arr));
  45. TEST_DONE();
  46. }
  47. struct TestBadgar {
  48. int i;
  49. double d;
  50. char * cstr;
  51. };
  52. TEST_FUNC(badgar) {
  53. struct TestBadgar value1 = { 797, 3.2, "Hello Gar!" };
  54. struct TestBadgar value2 = { 204, 2.3, "World Far!" };
  55. struct TestBadgar * ptr;
  56. void * arr;
  57. size_t nmemb = 123;
  58. size_t size = sizeof(value1);
  59. arr = badgar_new(nmemb, size);
  60. TEST_NOTNULL(arr);
  61. TEST_NOTNULL(badgar_put(arr, nmemb, size, 17, &value1));
  62. ptr = badgar_get(arr, nmemb, size, 17);
  63. TEST_NOTNULL(ptr);
  64. TEST_NOTNULL(ptr->cstr);
  65. puts(ptr->cstr);
  66. TEST_NULL(badgar_get(arr, nmemb, size, 321));
  67. TEST_NOTNULL(badgar_resize(&(arr), &nmemb, size, 100));
  68. TEST_NOTNULL(badgar_put(arr, nmemb, size, 210, &value2));
  69. ptr = badgar_get(arr, nmemb, size, 210);
  70. TEST_NOTNULL(ptr);
  71. puts(ptr->cstr);
  72. TEST_NULL(badpar_free(arr));
  73. TEST_DONE();
  74. }
  75. int main(void) {
  76. TEST_INIT();
  77. TEST_RUN(bad);
  78. TEST_RUN(badchildtree);
  79. TEST_RUN(badpar);
  80. TEST_RUN(badgar);
  81. TEST_REPORT();
  82. }