test_tmatrix.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /**
  2. * This is a test for tmatrix in tmatrix.h
  3. */
  4. #include "si_test.h"
  5. /* Get Tmatrix interface, generate for integer type */
  6. #define TEMPLATE_T int
  7. #define TEMPLATE_NAME Intmat
  8. #define TEMPLATE_PREFIX intmat_
  9. #include "tmatrix.h"
  10. /* Get implementation for integer type. */
  11. #define TEMPLATE_IMPLEMENT
  12. #define TEMPLATE_T int
  13. #define TEMPLATE_NAME Intmat
  14. #define TEMPLATE_PREFIX intmat_
  15. #include "tmatrix.h"
  16. #undef TEMPLATE_T
  17. #undef TEMPLATE_NAME
  18. #undef TEMPLATE_PREFIX
  19. #undef TEMPLATE_IMPLEMENT
  20. /* Get Tmatrix interface generate for pointer type */
  21. #define TEMPLATE_T void*
  22. #define TEMPLATE_NAME Ptrmat
  23. #define TEMPLATE_PREFIX ptrmat_
  24. #include "tmatrix.h"
  25. /* Get implementation for pointer type. */
  26. #define TEMPLATE_IMPLEMENT
  27. #define TEMPLATE_T void*
  28. #define TEMPLATE_NAME Ptrmat
  29. #define TEMPLATE_PREFIX ptrmat_
  30. #include "tmatrix.h"
  31. #undef TEMPLATE_T
  32. #undef TEMPLATE_NAME
  33. #undef TEMPLATE_PREFIX
  34. #undef TEMPLATE_IMPLEMENT
  35. TEST_FUNC(tmatrix_int) {
  36. Intmat matrix_struct;
  37. Intmat * matrix = &matrix_struct;
  38. int get;
  39. TEST_NOTNULL(intmat_init(matrix, 5, 7));
  40. TEST_FALSE(intmat_put(matrix, 3, 4, 123));
  41. TEST_FALSE(intmat_put(matrix, 0, 0, 654));
  42. TEST_TRUE(intmat_put(matrix, 5, 4, 321));
  43. TEST_TRUE(intmat_put(matrix, 1, 7, 321));
  44. TEST_TRUE(intmat_put(matrix, 10, 20, 456));
  45. TEST_INTEQ(123, intmat_getraw(matrix, 3, 4));
  46. TEST_INTEQ(654, intmat_getraw(matrix, 0, 0));
  47. TEST_FALSE(intmat_get(matrix, 3, 4, &get));
  48. TEST_INTEQ(123, get);
  49. TEST_FALSE(intmat_get(matrix, 0, 0, &get));
  50. TEST_INTEQ(654, get);
  51. TEST_TRUE(intmat_get(matrix, 5, 4, &get));
  52. TEST_TRUE(intmat_get(matrix, 1, 7, &get));
  53. TEST_TRUE(intmat_get(matrix, 10, 20, &get));
  54. TEST_NULL(intmat_free(matrix));
  55. TEST_DONE();
  56. }
  57. TEST_FUNC(tmatrix_ptr) {
  58. Ptrmat matrix_struct;
  59. Ptrmat * matrix = &matrix_struct;
  60. int i1 = 123;
  61. int i2 = 234;
  62. int i3 = 354;
  63. int i4 = 456;
  64. void * get;
  65. void * p1 = &i1;
  66. void * p2 = &i2;
  67. void * p3 = &i3;
  68. void * p4 = &i4;
  69. TEST_NOTNULL(ptrmat_init(matrix, 5, 7));
  70. TEST_FALSE(ptrmat_put(matrix, 3, 4, p1));
  71. TEST_FALSE(ptrmat_put(matrix, 0, 0, p2));
  72. TEST_TRUE(ptrmat_put(matrix, 5, 4, p3));
  73. TEST_TRUE(ptrmat_put(matrix, 1, 7, p3));
  74. TEST_TRUE(ptrmat_put(matrix, 10, 20, p4));
  75. TEST_PTREQ(p1, ptrmat_getraw(matrix, 3, 4));
  76. TEST_PTREQ(p2, ptrmat_getraw(matrix, 0, 0));
  77. TEST_FALSE(ptrmat_get(matrix, 3, 4, &get));
  78. TEST_PTREQ(p1, get);
  79. TEST_FALSE(ptrmat_get(matrix, 0, 0, &get));
  80. TEST_PTREQ(p2, get);
  81. TEST_TRUE(ptrmat_get(matrix, 5, 4, &get));
  82. TEST_TRUE(ptrmat_get(matrix, 1, 7, &get));
  83. TEST_TRUE(ptrmat_get(matrix, 10, 20, &get));
  84. TEST_NULL(ptrmat_free(matrix));
  85. TEST_DONE();
  86. }
  87. int main(void) {
  88. TEST_INIT();
  89. TEST_RUN(tmatrix_int);
  90. TEST_RUN(tmatrix_ptr);
  91. TEST_REPORT();
  92. }