Revert "Use a variable on the stack to not have a temporary in the call"
[ACE_TAO.git] / ACE / tests / UNIX_Addr_Test.cpp
blob14c76a7ff0c9a578ee61fe1b10fab69ec5270829
1 /**
2 * @file UNIX_Addr_Test.cpp
3 * @brief Performs serveral tests on ACE_UNIX_Addr class.
4 * @author Like Ma <likemartinma@gmail.com>
5 */
6 #include "test_config.h"
7 #include "ace/OS_NS_string.h"
8 #include "ace/UNIX_Addr.h"
9 #include "ace/Log_Msg.h"
10 #include "ace/OS_NS_unistd.h"
12 int run_main (int, ACE_TCHAR *[])
14 ACE_START_TEST (ACE_TEXT ("UNIX_Addr_Test"));
16 #if !defined (ACE_LACKS_UNIX_DOMAIN_SOCKETS)
17 // Default ctor and empty path.
18 ACE_UNIX_Addr addr;
19 ACE_UNIX_Addr empty("");
20 ACE_TEST_ASSERT (addr == empty);
21 ACE_TEST_ASSERT (addr.get_type () == AF_UNIX);
22 ACE_TEST_ASSERT (addr.get_size () == empty.get_size ());
23 ACE_TEST_ASSERT (addr.hash () == empty.hash ());
24 ACE_TEST_ASSERT (*addr.get_path_name () == '\0');
25 ACE_TEST_ASSERT (*empty.get_path_name () == '\0');
27 ACE_TCHAR buf[MAXPATHLEN];
28 ACE_TEST_ASSERT (addr.addr_to_string (buf, sizeof (buf)) == 0);
29 ACE_TEST_ASSERT (*buf == '\0');
31 // Set longer path by ACE_UNIX_Addr::set
32 int origin = addr.get_size ();
33 const char* path = "/tmp/ace.test";
34 addr.set (path);
35 ACE_TEST_ASSERT (addr.get_size () > origin);
36 ACE_TEST_ASSERT (addr.addr_to_string (buf, sizeof (buf)) == 0);
37 ACE_TEST_ASSERT (strcmp(path, ACE_TEXT_ALWAYS_CHAR(buf)) == 0);
38 ACE_TEST_ASSERT (strcmp(path, addr.get_path_name ()) == 0);
40 // Set longer path by ACE_UNIX_Addr::string_to_addr
41 origin = addr.get_size ();
42 path = "/tmp/unix_addr_test";
43 addr.string_to_addr (path);
44 ACE_TEST_ASSERT (addr.get_size () > origin);
45 ACE_TEST_ASSERT (addr.addr_to_string (buf, sizeof (buf)) == 0);
46 ACE_TEST_ASSERT (strcmp(path, ACE_TEXT_ALWAYS_CHAR(buf)) == 0);
47 ACE_TEST_ASSERT (strcmp(path, addr.get_path_name ()) == 0);
49 // Set shorter path by ACE_UNIX_Addr::string_to_addr
50 origin = addr.get_size ();
51 path = "/tmp/test";
52 addr.string_to_addr (path);
53 ACE_TEST_ASSERT (addr.get_size () < origin);
54 ACE_TEST_ASSERT (addr.addr_to_string (buf, sizeof (buf)) == 0);
55 ACE_TEST_ASSERT (strcmp(path, ACE_TEXT_ALWAYS_CHAR(buf)) == 0);
56 ACE_TEST_ASSERT (strcmp(path, addr.get_path_name ()) == 0);
57 #endif // ! ACE_LACKS_UNIX_DOMAIN_SOCKETS
59 ACE_END_TEST;
61 return 0;
63 // vim: set ts=2 sw=2 sts=2 et: