The macros defined here can be used by unit test programs. When a test fails, the TEST macros print the offending file name and line number. They use format that is accepted by Emacs and other fine editors so you can directly go to the source code of the failed test with next-error.
-v
or --verbatim
command line option. If the (TSTFLAGS & tst_verbatim) is true, the test macros log the test before executing it and the result of successful tests, too.You should typedef longlong to integer type at least 64 bit wide before including <sofia-sip/tstdef.h>, too.
As an example, we provide a test program making sure that inet_ntop() and inet_pton() behave as expected and that we can create UDP/IPv4 sockets with su library:
#include "config.h" #include <su.h> #include <stdio.h> #include <limits.h> #define TSTFLAGS tstflags int tstflags = 0; void usage(void) { fprintf(stderr, "usage: %s [-v|--verbatim]\n", name); exit(2); } static int socket_test(void); int main(int argc, char *argv[]) { int retval = 0, i; for (i = 1; argv[i]; i++) { if (strcmp(argv[i], "-v") == 0 || strcmp(argv[i], "--verbatim") == 0) tstflags |= tst_verbatim; else usage(); } retval |= socket_test(); fflush(stdout); return retval; } double max_bandwidth() int socket_test(void) { socket_t s; char buf[64]; unsigned long localhost = htonl(0x7f000001); unsigned long addr; BEGIN(); // Check inet_ntop() return value (Tests equality of integral values) TEST(inet_ntop(AF_INET, &localhost, buf, sizeof buf), buf); // Check inet_ntop() result (Tests equality of strings) TEST_S(buf, "127.0.0.1"); // Check inet_pton() argument validation (Tests equality of ints) TEST(inet_pton(0, buf, &addr), -1); // Check inet_pton() return value (Tests for true value (non-zero)) TEST_1(inet_pton(AF_INET, buf, &addr) > 0); // Check inet_pton() result (Tests equality of memory areas) TEST_M(&addr, &localhost, sizeof(addr)); // Test to create UDP socket (Test for true value) TEST_1((s = su_socket(AF_INET, SOCK_DGRAM, 0)) != SOCKET_ERROR); // Check max bandwidth TEST_D(max_bandwidth(), DBL_MAX); END(); }
#include <sofia-sip/su_types.h>
Include dependency graph for tstdef.h:
Go to the source code of this file.
Defines | |
#define | BEGIN() |
Begin a test function. | |
#define | END() |
End a test function. | |
#define | TEST0(suite) |
Test that suite returns a nonzero value. | |
#define | TEST_1(suite) |
Test that suite returns a nonzero value. | |
#define | TEST_VOID(suite) |
Test a void suite. | |
#define | TEST(suite, expected) |
Test that suite is equal to expected. | |
#define | TEST64(suite, expected) |
Test that 64-bit suite is equal to expect. | |
#define | TEST_D(suite, expected) |
Test that suite is same double as expected. | |
#define | TEST_S(suite, expected) |
Test that suite is same string as expected. | |
#define | TEST_M(suite, expected, len) |
Test that suite is results as identical memory as expected. | |
Enumerations | |
enum | { tst_verbatim } |
#define TEST0 | ( | suite | ) |