ACE+TAO-7_0_8
[ACE_TAO.git] / ACE / tests / Multihomed_INET_Addr_Test_IPV6.cpp
blobbab97e3c0321c9f86f1fee3a6ed0a305885c438b
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) {
68 /**** Test set (u_short, const char[], int, int, const char *([]), size_t) ****/
71 addr.set(port,
72 primary_ipv6,
74 AF_INET6,
75 secondary_ipv6,
76 i);
78 // Check the port number
79 if (addr.get_port_number() != port) {
80 ACE_ERROR ((LM_ERROR,
81 ACE_TEXT ("Failed second get_port_number check\n")
82 ACE_TEXT ("%d != %d\n"),
83 addr.get_port_number(),
84 port));
85 status = 1;
88 // Check the primary address
89 if (0 != ACE_OS::strcmp (ACE_TEXT_CHAR_TO_TCHAR(addr.get_host_addr()), primary_ipv6))
91 ACE_ERROR ((LM_ERROR,
92 ACE_TEXT ("%s failed get_host_addr() check\n")
93 ACE_TEXT ("%s != %s\n"),
94 primary_ipv6,
95 addr.get_host_addr (),
96 primary_ipv6));
97 status = 1;
100 // Check that the test subject reports the correct number of
101 // secondary addresses.
102 size_t returned_num_secondaries = addr.get_num_secondary_addresses();
103 if (returned_num_secondaries == i) {
105 // Initialize the stay_out array with the secondary addresses
106 for (j = 0; j < i; ++j) {
107 stay_out[j].set(port, secondary_ipv6[j]);
110 // Pass the in_out array to the accessor
111 addr.get_secondary_addresses(in_out, i);
113 // Check that the in_out array matches stay_out array
114 for (j = 0; j < i; ++j) {
116 if (in_out[j] != stay_out[j]) {
118 ACE_TCHAR in_out_string[100];
119 ACE_TCHAR stay_out_string[100];
121 in_out[j].addr_to_string(in_out_string, 100);
122 stay_out[j].addr_to_string(stay_out_string, 100);
124 ACE_ERROR ((LM_ERROR,
125 ACE_TEXT ("Failed get_secondary_addresses check\n")
126 ACE_TEXT ("%s != %s\n"),
127 in_out_string,
128 stay_out_string));
130 status = 1;
134 // Pass the in_out_sockaddr array to the accessor
135 addr.get_addresses(in_out_sockaddr6, i + 1);
137 // Check that the primary address in the in_out_sockaddr array
138 // matches the primary address reported by the superclass
139 if (ACE_OS::memcmp(in_out_sockaddr6, addr.get_addr(),
140 sizeof(sockaddr_in6))) {
142 ACE_ERROR ((LM_ERROR,
143 ACE_TEXT ("Failed second get_addresses check ")
144 ACE_TEXT ("(for primary address)\n")));
146 status = 1;
150 // Check that the secondary addresses in the in_out_sockaddr
151 // array match the stay_out array
152 for (j = 1, pointer6 = &in_out_sockaddr6[1];
153 j < i + 1;
154 ++j, ++pointer6) {
156 if (ACE_OS::memcmp(pointer6, stay_out[j-1].get_addr(),
157 sizeof(sockaddr_in6))) {
159 ACE_ERROR ((LM_ERROR,
160 ACE_TEXT ("Failed get_addresses check ")
161 ACE_TEXT ("(for secondary addresses)\n")));
163 status = 1;
166 } else {
168 ACE_ERROR ((LM_ERROR,
169 ACE_TEXT ("Failed get_num_secondary_addresses check\n")
170 ACE_TEXT ("%d != %d\n"),
171 returned_num_secondaries,
172 i));
173 status = 1;
176 #endif /* ACE_HAS_IPV6 */
178 ACE_END_TEST;
179 return status;