]> git.llucax.com Git - software/posixx.git/blob - test/socket/unix/common.hpp
Improve handling of CFLAGS and LDFLAGS make variables
[software/posixx.git] / test / socket / unix / common.hpp
1 #ifndef TEST_SOCKET_UNIX_COMMON_HPP_
2 #define TEST_SOCKET_UNIX_COMMON_HPP_
3
4 #include <posixx/socket/unix.hpp> // posixx::socket::unix
5 #include <boost/test/unit_test.hpp> // unit testing stuff
6 #include <ostream> // std::ostream
7 #include <unistd.h> // unlink
8 #include <sys/stat.h> // struct stat
9
10 #define PATH "/tmp/posixx_socket_unix_test"
11 #define PATH1 PATH "1"
12 #define PATH2 PATH "2"
13
14 static inline
15 std::ostream& operator << (std::ostream& os,
16                 const posixx::socket::unix::sockaddr& sa) throw()
17 {
18         return os << "unix::sockaddr(family=" << sa.sun_family
19                 << ", path=" << sa.sun_path << ")";
20 }
21
22 static inline
23 void clean_test_address(posixx::socket::unix::socket& socket,
24                 const posixx::socket::unix::sockaddr& addr)
25 {
26         // remove the socket file, if exists
27         struct stat st;
28         if (stat(addr.sun_path, &st) == 0)
29                 BOOST_REQUIRE_EQUAL(unlink(addr.sun_path), 0);
30 }
31
32 static posixx::socket::unix::sockaddr test_address1(PATH1);
33 static posixx::socket::unix::sockaddr test_address2(PATH2);
34
35 #endif // TEST_SOCKET_UNIX_COMMON_HPP_