]>
git.ipfire.org Git - pakfire.git/blob - tests/testsuite.h
1 /*#############################################################################
3 # Pakfire - The IPFire package management system #
4 # Copyright (C) 2017 Pakfire development team #
6 # This program is free software: you can redistribute it and/or modify #
7 # it under the terms of the GNU General Public License as published by #
8 # the Free Software Foundation, either version 3 of the License, or #
9 # (at your option) any later version. #
11 # This program is distributed in the hope that it will be useful, #
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of #
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
14 # GNU General Public License for more details. #
16 # You should have received a copy of the GNU General Public License #
17 # along with this program. If not, see <http://www.gnu.org/licenses/>. #
19 #############################################################################*/
21 #ifndef PAKFIRE_TESTSUITE_H
22 #define PAKFIRE_TESTSUITE_H
29 #include <pakfire/pakfire.h>
33 #define TEST_SRC_PATH ABS_TOP_SRCDIR "/tests/"
37 int (*func
)(const struct test
* t
);
38 struct pakfire
* pakfire
;
42 struct test tests
[MAX_TESTS
];
46 extern struct testsuite ts
;
48 int __testsuite_add_test(const char* name
, int (*func
)(const struct test
* t
));
51 #define _LOG(prefix, fmt, ...) fprintf(stderr, "TESTS: " prefix fmt, ## __VA_ARGS__);
52 #define LOG(fmt, ...) _LOG("", fmt, ## __VA_ARGS__);
53 #define LOG_WARN(fmt, ...) _LOG("WARN: ", fmt, ## __VA_ARGS__);
54 #define LOG_ERROR(fmt, ...) _LOG("ERROR: ", fmt, ## __VA_ARGS__);
56 #define testsuite_add_test(func) __testsuite_add_test(#func, func)
58 #define ASSERT(expr) \
61 LOG_ERROR("Failed assertion: " #expr " %s:%d %s\n", \
62 __FILE__, __LINE__, __PRETTY_FUNCTION__); \
67 #define ASSERT_NULL(expr) \
69 if (!((expr) == NULL)) { \
70 LOG_ERROR("Failed assertion: " #expr " == NULL %s:%d %s\n", \
71 __FILE__, __LINE__, __PRETTY_FUNCTION__); \
76 #define ASSERT_SUCCESS(expr) \
79 LOG_ERROR("Failed assertion: " #expr " %s:%d %s\n", \
80 __FILE__, __LINE__, __PRETTY_FUNCTION__); \
85 #define ASSERT_FAILURE(expr) \
88 LOG_ERROR("Failed assertion: " #expr " unexpectedly didn't fail in %s:%d %s\n", \
89 __FILE__, __LINE__, __PRETTY_FUNCTION__); \
94 #define ASSERT_TRUE(expr) \
97 LOG_ERROR("Failed assertion: " #expr " unexpectedly didn't return true in %s:%d: %m\n", \
98 __FILE__, __LINE__, __PRETTY_FUNCTION__); \
103 #define ASSERT_FALSE(expr) \
106 LOG_ERROR("Failed assertion: " #expr " unexpectedly didn't return false in %s:%d: %m\n", \
107 __FILE__, __LINE__, __PRETTY_FUNCTION__); \
112 #define ASSERT_ERRNO(expr, e) \
115 LOG_ERROR("Failed assertion: " #expr " unexpectedly didn't fail in %s:%d %s\n", \
116 __FILE__, __LINE__, __PRETTY_FUNCTION__); \
120 LOG_ERROR("Failed assertion: " #expr " failed with (%d - %s) " \
121 "but was expected to fail with (%d - %s) in %s:%d\n", \
122 errno, strerror(errno), e, strerror(e), __FILE__, __LINE__); \
127 #define ASSERT_STRING_EQUALS(value, string) \
130 LOG_ERROR("Failed assertion: " #value " is NULL, expected " #string " at %s:%d\n", \
131 __FILE__, __LINE__, __PRETTY_FUNCTION__); \
134 if (strcmp(string, value) != 0) { \
135 LOG_ERROR("Failed assertion: " #value " (%s) != " #string " %s:%d %s\n", \
136 value, __FILE__, __LINE__, __PRETTY_FUNCTION__); \
141 #define ASSERT_STRING_NOT_EQUALS(value1, value2) \
143 if (strcmp(value1, value2) == 0) { \
144 LOG_ERROR("Failed assertion: " #value1 " (%s) != " #value2 " (%s) %s:%d %s\n", \
145 value1, value2, __FILE__, __LINE__, __PRETTY_FUNCTION__); \
150 #define ASSERT_STRING_STARTSWITH(string, start) \
152 if (strncmp(string, start, strlen(start)) != 0) { \
153 LOG_ERROR("Failed assertion: " #string " does not start with " #start " %s:%d %s\n", \
154 __FILE__, __LINE__, __PRETTY_FUNCTION__); \
160 FILE* test_mktemp(char** path
);
161 char* test_mkdtemp();
163 #endif /* PAKFIRE_TESTSUITE_H */