lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame^] | 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 |
|
| 16 | #ifndef __TEST_ABTS_H__
|
| 17 | #define __TEST_ABTS_H__
|
| 18 |
|
| 19 | #ifdef __cplusplus
|
| 20 | extern "C" {
|
| 21 | #endif
|
| 22 |
|
| 23 | #include <stdarg.h>
|
| 24 | #include <stdio.h>
|
| 25 | #include <stdlib.h>
|
| 26 | #include <string.h>
|
| 27 |
|
| 28 | #ifndef ABTS_H
|
| 29 | #define ABTS_H
|
| 30 |
|
| 31 | #ifndef FALSE
|
| 32 | #define FALSE 0
|
| 33 | #endif
|
| 34 | #ifndef TRUE
|
| 35 | #define TRUE 1
|
| 36 | #endif
|
| 37 |
|
| 38 | struct sub_suite {
|
| 39 | const char *name;
|
| 40 | int num_test;
|
| 41 | int failed;
|
| 42 | int not_run;
|
| 43 | int not_impl;
|
| 44 | struct sub_suite *next;
|
| 45 | };
|
| 46 | typedef struct sub_suite sub_suite;
|
| 47 |
|
| 48 | struct abts_suite {
|
| 49 | sub_suite *head;
|
| 50 | sub_suite *tail;
|
| 51 | };
|
| 52 | typedef struct abts_suite abts_suite;
|
| 53 |
|
| 54 | struct abts_case {
|
| 55 | int failed;
|
| 56 | sub_suite *suite;
|
| 57 | };
|
| 58 | typedef struct abts_case abts_case;
|
| 59 |
|
| 60 | typedef void (*test_func)(abts_case *tc, void *data);
|
| 61 |
|
| 62 | #define ADD_SUITE(suite) abts_add_suite(suite, __FILE__);
|
| 63 |
|
| 64 | abts_suite *abts_add_suite(abts_suite *suite, const char *suite_name);
|
| 65 | void abts_run_test(abts_suite *ts, test_func f, void *value);
|
| 66 | void abts_log_message(const char *fmt, ...);
|
| 67 |
|
| 68 | void abts_int_equal(abts_case *tc, const int expected, const int actual, int lineno);
|
| 69 | void abts_int_nequal(abts_case *tc, const int expected, const int actual, int lineno);
|
| 70 | void abts_str_equal(abts_case *tc, const char *expected, const char *actual, int lineno);
|
| 71 | void abts_str_notequal(abts_case *tc, const char *expected, const char *actual, int lineno);
|
| 72 | void abts_str_nequal(abts_case *tc, const char *expected, const char *actual,
|
| 73 | size_t n, int lineno);
|
| 74 | void abts_ptr_notnull(abts_case *tc, const void *ptr, int lineno);
|
| 75 | void abts_ptr_equal(abts_case *tc, const void *expected, const void *actual, int lineno);
|
| 76 | void abts_true(abts_case *tc, int condition, int lineno);
|
| 77 | void abts_fail(abts_case *tc, const char *message, int lineno);
|
| 78 | void abts_not_impl(abts_case *tc, const char *message, int lineno);
|
| 79 | void abts_assert(abts_case *tc, const char *message, int condition, int lineno);
|
| 80 |
|
| 81 | /* Convenience macros. Ryan hates these! */
|
| 82 | #define ABTS_INT_EQUAL(a, b, c) abts_int_equal(a, b, c, __LINE__)
|
| 83 | #define ABTS_INT_NEQUAL(a, b, c) abts_int_nequal(a, b, c, __LINE__)
|
| 84 | #define ABTS_STR_EQUAL(a, b, c) abts_str_equal(a, b, c, __LINE__)
|
| 85 | #define ABTS_STR_NOTEQUAL(a, b, c) abts_str_notequal(a, b, c, __LINE__)
|
| 86 | #define ABTS_STR_NEQUAL(a, b, c, d) abts_str_nequal(a, b, c, d, __LINE__)
|
| 87 | #define ABTS_PTR_NOTNULL(a, b) abts_ptr_notnull(a, b, __LINE__)
|
| 88 | #define ABTS_PTR_NULL(a, b) abts_ptr_equal(a, NULL, b, __LINE__)
|
| 89 | #define ABTS_PTR_EQUAL(a, b, c) abts_ptr_equal(a, b, c, __LINE__)
|
| 90 | #define ABTS_TRUE(a, b) abts_true(a, b, __LINE__);
|
| 91 | #define ABTS_FAIL(a, b) abts_fail(a, b, __LINE__);
|
| 92 | #define ABTS_NOT_IMPL(a, b) abts_not_impl(a, b, __LINE__);
|
| 93 | #define ABTS_ASSERT(a, b, c) abts_assert(a, b, c, __LINE__);
|
| 94 |
|
| 95 | abts_suite *run_tests(abts_suite *suite);
|
| 96 | abts_suite *run_tests1(abts_suite *suite);
|
| 97 |
|
| 98 |
|
| 99 | #define ASSERT_NULL(x) ABTS_PTR_NULL(tc, x)
|
| 100 | #define ASSERT_NOTNULL(x) ABTS_PTR_NOTNULL(tc, x)
|
| 101 | #define ASSERT_TRUE(x) ABTS_TRUE(tc, x)
|
| 102 | #define ASSERT_FALSE(x) ABTS_TRUE(tc, !x)
|
| 103 |
|
| 104 | #define ASSERT_STR_EQ(a,b) ABTS_STR_EQUAL(tc, a,b)
|
| 105 | #define ASSERT_STR_NEQ(a,b) ABTS_STR_NOTEQUAL(tc, a,b)
|
| 106 |
|
| 107 |
|
| 108 | #endif
|
| 109 |
|
| 110 | #ifdef __cplusplus
|
| 111 | }
|
| 112 | #endif
|
| 113 |
|
| 114 | #endif
|
| 115 |
|
| 116 |
|