Logo Search packages:      
Sourcecode: sofia-sip version File versions  Download package

tstdef.h File Reference
Include dependency graph for tstdef.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Defines

#define BEGIN()   BEGIN_(TSTFLAGS); { extern int tstdef_dummy
#define BEGIN_(flags)   if (flags & tst_verbatim) printf("%s: %s%sstarting\n", TSTNAME)
#define END()   (void) tstdef_dummy; } END_(TSTFLAGS)
#define END_(flags)
#define TEST(suite, expected)   TEST_(TSTFLAGS, suite, expected)
#define TEST0(suite)   TEST_1_(TSTFLAGS, suite)
#define TEST64(suite, expected)   TEST64_(TSTFLAGS, suite, expected)
#define TEST64_(flags, suite, expect)
#define TEST_(flags, suite, expect)
#define TEST_1(suite)   TEST_1_(TSTFLAGS, suite)
#define TEST_1_(flags, suite)
#define TEST_D(suite, expected)   TEST_D_(TSTFLAGS, suite, expected)
#define TEST_D_(flags, suite, expect)
#define TEST_FAILED(flags)
#define TEST_LOG(x)
#define TEST_M(suite, expected, len)   TEST_M_(TSTFLAGS, suite, expected, len)
#define TEST_M_(flags, suite, expect, len)
#define TEST_P(suite, expected)   TEST_P_(TSTFLAGS, suite, expected)
#define TEST_P_(flags, suite, expect)
#define TEST_S(suite, expected)   TEST_S_(TSTFLAGS, suite, expected)
#define TEST_S_(flags, suite, expect)
#define TEST_SIZE(suite, expected)   TEST_SIZE_(TSTFLAGS, suite, expected)
#define TEST_SIZE_(flags, suite, expect)
#define TEST_VOID(suite)   TEST_VOID_(TSTFLAGS, suite)
#define TEST_VOID_(flags, suite)
#define TSTNAME   name, "", ""

Enumerations

enum  { tst_verbatim = 1, tst_abort = 2, tst_log = 4 }

Detailed Description

Macros for unit tests

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.

Note:
There is no protection agains multiple inclusion.
Author:
Pekka Pessi <Pekka.Pessi@nokia.com>
Date:
Created: Wed Aug 22 13:53:24 2001 ppessi
Example Program

You should define the macro TSTFLAGS to a int variable possibly containing a flag tst_verbatim. As a convention, the int variable should be set when your test program is run with -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 <stdio.h>
 #include <limits.h>

 #include <sofia-sip/su.h>

 #define TSTFLAGS tstflags

 #include <stdlib.h>
 #include <sofia-sip/tstdef.h>

 static 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)
 {
   su_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)) != INVALID_SOCKET);

   // Check max bandwidth
   TEST_D(max_bandwidth(), DBL_MAX);

   END();
 }

Definition in file tstdef.h.


Generated by  Doxygen 1.6.0   Back to index