Revert "Use a variable on the stack to not have a temporary in the call"
[ACE_TAO.git] / ACE / tests / Multihomed_INET_Addr_Test_IPV6.cpp
blobef9fc882510d85049176c8c4dae989972cca20c4
1 //=============================================================================
2 /**
3 * @file Multihomed_INET_Addr_Test_IPV6.cpp
5 * Performs several tests on the Multihomed_ACE_INET_Addr class.
6 * It creates several IPv6 addresses and checks that the
7 * address formed by the class is valid.
9 * @author Edward Mulholland (emulholl@atl.lmco.com) Brian Buesker (bbuesker@qualcomm.com) - Added testing of ACE_Multihomed_INET_Addr class using IPv6 addresses based on Multihomed_INET_Addr_Test.
11 //=============================================================================
14 #include "test_config.h"
15 #include "ace/OS_NS_string.h"
16 #include "ace/Multihomed_INET_Addr.h"
17 #include "ace/Log_Msg.h"
18 #include "ace/OS_NS_arpa_inet.h"
20 int run_main (int argc, ACE_TCHAR *argv[])
22 ACE_UNUSED_ARG (argc);
23 ACE_UNUSED_ARG (argv);
25 ACE_START_TEST (ACE_TEXT ("Multihomed_INET_Addr_Test_IPV6"));
27 int status = 0; // Innocent until proven guilty
29 #if defined (ACE_HAS_IPV6)
30 // loop variables
31 size_t i, j;
32 sockaddr_in6 *pointer6;
34 const ACE_TCHAR *primary_ipv6 = ACE_TEXT("3ffe::123:4567:89ab:cdef");
36 const ACE_TCHAR *secondary_ipv6[] = {
37 ACE_IPV6_LOCALHOST,
38 ACE_TEXT("fe80::0123:4567:89ab:cdef"),
39 ACE_TEXT("fec0::0123:4567:89ab:cdef"),
40 ACE_TEXT("3ffe::1:0123:4567:89ab:cdef"),
41 ACE_TEXT("2002:3e02:5473::")
44 // The port will always be this
45 u_short port = 80;
47 // ... and as you can see, there are 5 of them
48 const size_t num_secondaries = 5;
50 // Test subject
51 ACE_Multihomed_INET_Addr addr;
53 // Array of INET_Addrs that will repeatedly be passed into the
54 // get_secondary_addresses accessor of Multihomed_INET_Addr
55 ACE_INET_Addr in_out[5];
57 // Array of INET_Addrs against which the above array will be tested.
58 ACE_INET_Addr stay_out[5];
60 // Array of sockaddrs that will repeatedly be passed into the
61 // get_addresses accessor of Multihomed_INET_Addr
62 const size_t num_sockaddrs = 6;
63 sockaddr_in6 in_out_sockaddr6[num_sockaddrs];
65 for (i = 0; i <= num_secondaries; ++i) {
66 /**** Test set (u_short, const char[], int, int, const char *([]), size_t) ****/
69 addr.set(port,
70 primary_ipv6,
72 AF_INET6,
73 secondary_ipv6,
74 i);
76 // Check the port number
77 if (addr.get_port_number() != port) {
78 ACE_ERROR ((LM_ERROR,
79 ACE_TEXT ("Failed second get_port_number check\n")
80 ACE_TEXT ("%d != %d\n"),
81 addr.get_port_number(),
82 port));
83 status = 1;
86 // Check the primary address
87 if (0 != ACE_OS::strcmp (ACE_TEXT_CHAR_TO_TCHAR(addr.get_host_addr()), primary_ipv6))
89 ACE_ERROR ((LM_ERROR,
90 ACE_TEXT ("%s failed get_host_addr() check\n")
91 ACE_TEXT ("%s != %s\n"),
92 primary_ipv6,
93 addr.get_host_addr (),
94 primary_ipv6));
95 status = 1;
98 // Check that the test subject reports the correct number of
99 // secondary addresses.
100 size_t returned_num_secondaries = addr.get_num_secondary_addresses();
101 if (returned_num_secondaries == i) {
102 // Initialize the stay_out array with the secondary addresses
103 for (j = 0; j < i; ++j) {
104 stay_out[j].set(port, secondary_ipv6[j]);
107 // Pass the in_out array to the accessor
108 addr.get_secondary_addresses(in_out, i);
110 // Check that the in_out array matches stay_out array
111 for (j = 0; j < i; ++j) {
112 if (in_out[j] != stay_out[j]) {
113 ACE_TCHAR in_out_string[100];
114 ACE_TCHAR stay_out_string[100];
116 in_out[j].addr_to_string(in_out_string, 100);
117 stay_out[j].addr_to_string(stay_out_string, 100);
119 ACE_ERROR ((LM_ERROR,
120 ACE_TEXT ("Failed get_secondary_addresses check\n")
121 ACE_TEXT ("%s != %s\n"),
122 in_out_string,
123 stay_out_string));
125 status = 1;
129 // Pass the in_out_sockaddr array to the accessor
130 addr.get_addresses(in_out_sockaddr6, i + 1);
132 // Check that the primary address in the in_out_sockaddr array
133 // matches the primary address reported by the superclass
134 if (ACE_OS::memcmp(in_out_sockaddr6, addr.get_addr(),
135 sizeof(sockaddr_in6))) {
136 ACE_ERROR ((LM_ERROR,
137 ACE_TEXT ("Failed second get_addresses check ")
138 ACE_TEXT ("(for primary address)\n")));
140 status = 1;
143 // Check that the secondary addresses in the in_out_sockaddr
144 // array match the stay_out array
145 for (j = 1, pointer6 = &in_out_sockaddr6[1];
146 j < i + 1;
147 ++j, ++pointer6) {
148 if (ACE_OS::memcmp(pointer6, stay_out[j-1].get_addr(),
149 sizeof(sockaddr_in6))) {
150 ACE_ERROR ((LM_ERROR,
151 ACE_TEXT ("Failed get_addresses check ")
152 ACE_TEXT ("(for secondary addresses)\n")));
154 status = 1;
157 } else {
158 ACE_ERROR ((LM_ERROR,
159 ACE_TEXT ("Failed get_num_secondary_addresses check\n")
160 ACE_TEXT ("%d != %d\n"),
161 returned_num_secondaries,
162 i));
163 status = 1;
166 #endif /* ACE_HAS_IPV6 */
168 ACE_END_TEST;
169 return status;