Apache Portable Runtime Utility Library
|
00001 /* Licensed to the Apache Software Foundation (ASF) under one or more 00002 * contributor license agreements. See the NOTICE file distributed with 00003 * this work for additional information regarding copyright ownership. 00004 * The ASF licenses this file to You under the Apache License, Version 2.0 00005 * (the "License"); you may not use this file except in compliance with 00006 * the License. You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 00017 #ifdef __cplusplus 00018 extern "C" { 00019 #endif 00020 00021 #include <stdarg.h> 00022 #include <stdio.h> 00023 #include <stdlib.h> 00024 #include <string.h> 00025 00026 #ifdef WIN32 00027 #include <io.h> 00028 #else 00029 #include <unistd.h> 00030 #endif 00031 00032 #ifndef ABTS_H 00033 #define ABTS_H 00034 00035 #ifndef FALSE 00036 #define FALSE 0 00037 #endif 00038 #ifndef TRUE 00039 #define TRUE 1 00040 #endif 00041 00042 struct sub_suite { 00043 const char *name; 00044 int num_test; 00045 int failed; 00046 int not_run; 00047 int not_impl; 00048 struct sub_suite *next; 00049 }; 00050 typedef struct sub_suite sub_suite; 00051 00052 struct abts_suite { 00053 sub_suite *head; 00054 sub_suite *tail; 00055 }; 00056 typedef struct abts_suite abts_suite; 00057 00058 struct abts_case { 00059 int failed; 00060 sub_suite *suite; 00061 }; 00062 typedef struct abts_case abts_case; 00063 00064 typedef void (*test_func)(abts_case *tc, void *data); 00065 00066 #define ADD_SUITE(suite) abts_add_suite(suite, __FILE__); 00067 00068 abts_suite *abts_add_suite(abts_suite *suite, const char *suite_name); 00069 void abts_run_test(abts_suite *ts, test_func f, void *value); 00070 void abts_log_message(const char *fmt, ...); 00071 00072 void abts_int_equal(abts_case *tc, const int expected, const int actual, int lineno); 00073 void abts_int_nequal(abts_case *tc, const int expected, const int actual, int lineno); 00074 void abts_str_equal(abts_case *tc, const char *expected, const char *actual, int lineno); 00075 void abts_str_nequal(abts_case *tc, const char *expected, const char *actual, 00076 size_t n, int lineno); 00077 void abts_ptr_notnull(abts_case *tc, const void *ptr, int lineno); 00078 void abts_ptr_equal(abts_case *tc, const void *expected, const void *actual, int lineno); 00079 void abts_true(abts_case *tc, int condition, int lineno); 00080 void abts_fail(abts_case *tc, const char *message, int lineno); 00081 void abts_not_impl(abts_case *tc, const char *message, int lineno); 00082 void abts_assert(abts_case *tc, const char *message, int condition, int lineno); 00083 00084 /* Convenience macros. Ryan hates these! */ 00085 #define ABTS_INT_EQUAL(a, b, c) abts_int_equal(a, b, c, __LINE__) 00086 #define ABTS_INT_NEQUAL(a, b, c) abts_int_nequal(a, b, c, __LINE__) 00087 #define ABTS_STR_EQUAL(a, b, c) abts_str_equal(a, b, c, __LINE__) 00088 #define ABTS_STR_NEQUAL(a, b, c, d) abts_str_nequal(a, b, c, d, __LINE__) 00089 #define ABTS_PTR_NOTNULL(a, b) abts_ptr_notnull(a, b, __LINE__) 00090 #define ABTS_PTR_EQUAL(a, b, c) abts_ptr_equal(a, b, c, __LINE__) 00091 #define ABTS_TRUE(a, b) abts_true(a, b, __LINE__); 00092 #define ABTS_FAIL(a, b) abts_fail(a, b, __LINE__); 00093 #define ABTS_NOT_IMPL(a, b) abts_not_impl(a, b, __LINE__); 00094 #define ABTS_ASSERT(a, b, c) abts_assert(a, b, c, __LINE__); 00095 00096 #endif 00097 00098 #ifdef __cplusplus 00099 } 00100 #endif 00101