abts.h 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /* Copyright 2000-2004 Ryan Bloom
  2. *
  3. * Licensed under the Apache License, Version 2.0 (the "License");
  4. * you may not use this file except in compliance with the License.
  5. * You may obtain a copy of the License at
  6. *
  7. * http://www.apache.org/licenses/LICENSE-2.0
  8. *
  9. * Unless required by applicable law or agreed to in writing, software
  10. * distributed under the License is distributed on an "AS IS" BASIS,
  11. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. * See the License for the specific language governing permissions and
  13. * limitations under the License.
  14. */
  15. #ifdef __cplusplus
  16. extern "C" {
  17. #endif
  18. #include <stdarg.h>
  19. #include <stdio.h>
  20. #include <stdlib.h>
  21. #include <string.h>
  22. #ifndef ABTS_H
  23. #define ABTS_H
  24. #ifndef FALSE
  25. #define FALSE 0
  26. #endif
  27. #ifndef TRUE
  28. #define TRUE 1
  29. #endif
  30. struct sub_suite {
  31. const char *name;
  32. int num_test;
  33. int failed;
  34. int not_run;
  35. int not_impl;
  36. struct sub_suite *next;
  37. };
  38. typedef struct sub_suite sub_suite;
  39. struct abts_suite {
  40. sub_suite *head;
  41. sub_suite *tail;
  42. };
  43. typedef struct abts_suite abts_suite;
  44. struct abts_case {
  45. int failed;
  46. sub_suite *suite;
  47. };
  48. typedef struct abts_case abts_case;
  49. typedef void (*test_func)(abts_case *tc, void *data);
  50. #define ADD_SUITE(suite) abts_add_suite(suite, __FILE__);
  51. abts_suite *abts_add_suite(abts_suite *suite, const char *suite_name);
  52. void abts_run_test(abts_suite *ts, test_func f, void *value);
  53. void abts_log_message(const char *fmt, ...);
  54. void abts_int_equal(abts_case *tc, const int expected, const int actual, int lineno);
  55. void abts_int_nequal(abts_case *tc, const int expected, const int actual, int lineno);
  56. void abts_str_equal(abts_case *tc, const char *expected, const char *actual, int lineno);
  57. void abts_str_nequal(abts_case *tc, const char *expected, const char *actual,
  58. size_t n, int lineno);
  59. void abts_ptr_notnull(abts_case *tc, const void *ptr, int lineno);
  60. void abts_ptr_equal(abts_case *tc, const void *expected, const void *actual, int lineno);
  61. void abts_true(abts_case *tc, int condition, int lineno);
  62. void abts_fail(abts_case *tc, const char *message, int lineno);
  63. void abts_not_impl(abts_case *tc, const char *message, int lineno);
  64. void abts_assert(abts_case *tc, const char *message, int condition, int lineno);
  65. /* Convenience macros. Ryan hates these! */
  66. #define ABTS_INT_EQUAL(a, b, c) abts_int_equal(a, b, c, __LINE__)
  67. #define ABTS_INT_NEQUAL(a, b, c) abts_int_nequal(a, b, c, __LINE__)
  68. #define ABTS_STR_EQUAL(a, b, c) abts_str_equal(a, b, c, __LINE__)
  69. #define ABTS_STR_NEQUAL(a, b, c, d) abts_str_nequal(a, b, c, d, __LINE__)
  70. #define ABTS_PTR_NOTNULL(a, b) abts_ptr_notnull(a, b, __LINE__)
  71. #define ABTS_PTR_EQUAL(a, b, c) abts_ptr_equal(a, b, c, __LINE__)
  72. #define ABTS_TRUE(a, b) abts_true(a, b, __LINE__);
  73. #define ABTS_FAIL(a, b) abts_fail(a, b, __LINE__);
  74. #define ABTS_NOT_IMPL(a, b) abts_not_impl(a, b, __LINE__);
  75. #define ABTS_ASSERT(a, b, c) abts_assert(a, b, c, __LINE__);
  76. abts_suite *run_tests(abts_suite *suite);
  77. abts_suite *run_tests1(abts_suite *suite);
  78. #endif
  79. #ifdef __cplusplus
  80. }
  81. #endif