2 #include "common.hpp" // PTYPE, INST{1,2}, test_address{1,2}
3 #include <posixx/linux/tipc.hpp> // posixx::linux::tipc
4 #include <boost/test/unit_test.hpp> // unit testing stuff
7 using namespace ::posixx::linux::tipc;
8 namespace tipc = ::posixx::linux::tipc;
10 BOOST_AUTO_TEST_CASE( linux_tipc_sockaddr_addr_test )
14 BOOST_CHECK_EQUAL( a.zone(), 1 );
15 BOOST_CHECK_EQUAL( a.cluster(), 2 );
16 BOOST_CHECK_EQUAL( a.node(), 3 );
19 BOOST_CHECK_EQUAL( a.zone(), 3 );
20 BOOST_CHECK_EQUAL( a.cluster(), 2 );
21 BOOST_CHECK_EQUAL( a.node(), 3 );
24 BOOST_CHECK_EQUAL( a.zone(), 3 );
25 BOOST_CHECK_EQUAL( a.cluster(), 1 );
26 BOOST_CHECK_EQUAL( a.node(), 3 );
29 BOOST_CHECK_EQUAL( a.zone(), 3 );
30 BOOST_CHECK_EQUAL( a.cluster(), 1 );
31 BOOST_CHECK_EQUAL( a.node(), 2 );
34 BOOST_CHECK_EQUAL( a, a2 );
36 addr a3(static_cast<uint32_t>(a2));
37 BOOST_CHECK_EQUAL( a3, a2 );
41 BOOST_AUTO_TEST_CASE( linux_tipc_sockaddr_const_addr_test )
44 const addr a(1, 2, 3);
45 BOOST_CHECK_EQUAL( a.zone(), 1 );
46 BOOST_CHECK_EQUAL( a.cluster(), 2 );
47 BOOST_CHECK_EQUAL( a.node(), 3 );
49 const addr a2(1, 2, 3);
50 BOOST_CHECK_EQUAL( a, a2 );
52 const addr a3(static_cast<uint32_t>(a2));
53 BOOST_CHECK_EQUAL( a3, a2 );
57 BOOST_AUTO_TEST_CASE( linux_tipc_sockaddr_portid_test )
60 portid id(55, addr(1, 2, 3));
61 BOOST_CHECK_EQUAL( id.ref, 55 );
62 BOOST_CHECK_EQUAL( id.node, addr(1, 2, 3) );
63 BOOST_CHECK_EQUAL( id.node_addr().zone(), 1 );
64 BOOST_CHECK_EQUAL( id.node_addr().cluster(), 2 );
65 BOOST_CHECK_EQUAL( id.node_addr().node(), 3 );
67 id.node_addr().zone(3);
68 BOOST_CHECK_EQUAL( id.node_addr().zone(), 3 );
69 BOOST_CHECK_EQUAL( id.node_addr().cluster(), 2 );
70 BOOST_CHECK_EQUAL( id.node_addr().node(), 3 );
72 portid id2(55, addr(3, 2, 3));
73 BOOST_CHECK_EQUAL( id, id2 );
76 BOOST_CHECK_EQUAL( id3, id2 );
80 BOOST_AUTO_TEST_CASE( linux_tipc_sockaddr_const_portid_test )
83 const portid id(55, addr(1, 2, 3));
84 BOOST_CHECK_EQUAL( id.ref, 55 );
85 BOOST_CHECK_EQUAL( id.node, addr(1, 2, 3) );
86 BOOST_CHECK_EQUAL( id.node_addr().zone(), 1 );
87 BOOST_CHECK_EQUAL( id.node_addr().cluster(), 2 );
88 BOOST_CHECK_EQUAL( id.node_addr().node(), 3 );
90 const portid id2(55, addr(1, 2, 3));
91 BOOST_CHECK_EQUAL( id, id2 );
94 BOOST_CHECK_EQUAL( id3, id2 );
98 BOOST_AUTO_TEST_CASE( linux_tipc_sockaddr_name_test )
102 BOOST_CHECK_EQUAL( n.type, 598 );
103 BOOST_CHECK_EQUAL( n.instance, 2937 );
106 BOOST_CHECK_EQUAL( n.type, 9834 );
107 BOOST_CHECK_EQUAL( n.instance, 2937 );
110 BOOST_CHECK_EQUAL( n.type, 9834 );
111 BOOST_CHECK_EQUAL( n.instance, 3324 );
114 BOOST_CHECK_EQUAL( n, n2 );
117 BOOST_CHECK_EQUAL( n3, n2 );
121 BOOST_AUTO_TEST_CASE( linux_tipc_sockaddr_const_name_test )
124 const name n(598, 2937);
125 BOOST_CHECK_EQUAL( n.type, 598 );
126 BOOST_CHECK_EQUAL( n.instance, 2937 );
128 const name n2(598, 2937);
129 BOOST_CHECK_EQUAL( n, n2 );
132 BOOST_CHECK_EQUAL( n3, n2 );
136 BOOST_AUTO_TEST_CASE( linux_tipc_sockaddr_nameseq_test )
139 nameseq n(598, 2937, 666);
140 BOOST_CHECK_EQUAL( n.type, 598 );
141 BOOST_CHECK_EQUAL( n.lower, 2937 );
142 BOOST_CHECK_EQUAL( n.upper, 666 );
145 BOOST_CHECK_EQUAL( n.type, 9834 );
146 BOOST_CHECK_EQUAL( n.lower, 2937 );
147 BOOST_CHECK_EQUAL( n.upper, 666 );
150 BOOST_CHECK_EQUAL( n.type, 9834 );
151 BOOST_CHECK_EQUAL( n.lower, 3324 );
152 BOOST_CHECK_EQUAL( n.upper, 666 );
155 BOOST_CHECK_EQUAL( n.type, 9834 );
156 BOOST_CHECK_EQUAL( n.lower, 3324 );
157 BOOST_CHECK_EQUAL( n.upper, 9999 );
159 nameseq n2(9834, 3324, 9999);
160 BOOST_CHECK_EQUAL( n, n2 );
163 BOOST_CHECK_EQUAL( n3, n2 );
165 nameseq n4(9834, 3324);
166 BOOST_CHECK_EQUAL( n4.type, 9834 );
167 BOOST_CHECK_EQUAL( n4.lower, 3324 );
168 BOOST_CHECK_EQUAL( n4.upper, 3324 );
172 BOOST_AUTO_TEST_CASE( linux_tipc_sockaddr_const_nameseq_test )
175 const nameseq n(598, 2937, 666);
176 BOOST_CHECK_EQUAL( n.type, 598 );
177 BOOST_CHECK_EQUAL( n.lower, 2937 );
178 BOOST_CHECK_EQUAL( n.upper, 666 );
180 const nameseq n2(598, 2937, 666);
181 BOOST_CHECK_EQUAL( n, n2 );
184 BOOST_CHECK_EQUAL( n3, n2 );
186 const nameseq n4(9834, 3324);
187 BOOST_CHECK_EQUAL( n4.type, 9834 );
188 BOOST_CHECK_EQUAL( n4.lower, 3324 );
189 BOOST_CHECK_EQUAL( n4.upper, 3324 );
193 BOOST_AUTO_TEST_CASE( linux_tipc_sockaddr_subscr_test )
196 subscr s(nameseq(999, 888), 12345, SUB_PORTS, "handle");
197 BOOST_CHECK_EQUAL( s.seq.type, 999 );
198 BOOST_CHECK_EQUAL( s.seq.lower, 888 );
199 BOOST_CHECK_EQUAL( s.seq.upper, 888 );
200 BOOST_CHECK_EQUAL( s.name_seq(), nameseq(999, 888) );
201 BOOST_CHECK_EQUAL( s.timeout, 12345 );
202 BOOST_CHECK_EQUAL( s.filter, SUB_PORTS );
203 BOOST_CHECK_EQUAL( s.usr_handle, "handle" );
205 s.name_seq().upper = 2888;
206 BOOST_CHECK_EQUAL( s.seq.type, 999 );
207 BOOST_CHECK_EQUAL( s.seq.lower, 888 );
208 BOOST_CHECK_EQUAL( s.seq.upper, 2888 );
209 BOOST_CHECK_EQUAL( s.name_seq(), nameseq(999, 888, 2888) );
210 BOOST_CHECK_EQUAL( s.timeout, 12345 );
211 BOOST_CHECK_EQUAL( s.filter, SUB_PORTS );
212 BOOST_CHECK_EQUAL( s.usr_handle, "handle" );
215 BOOST_CHECK_EQUAL( s.name_seq(), nameseq(999, 888, 2888) );
216 BOOST_CHECK_EQUAL( s.timeout, 9876 );
217 BOOST_CHECK_EQUAL( s.filter, SUB_PORTS );
218 BOOST_CHECK_EQUAL( s.usr_handle, "handle" );
220 s.filter = SUB_SERVICE;
221 BOOST_CHECK_EQUAL( s.name_seq(), nameseq(999, 888, 2888) );
222 BOOST_CHECK_EQUAL( s.timeout, 9876 );
223 BOOST_CHECK_EQUAL( s.filter, SUB_SERVICE );
224 BOOST_CHECK_EQUAL( s.usr_handle, "handle" );
227 BOOST_CHECK_EQUAL( s.name_seq(), nameseq(999, 888, 2888) );
228 BOOST_CHECK_EQUAL( s.timeout, 9876 );
229 BOOST_CHECK_EQUAL( s.filter, SUB_SERVICE );
230 BOOST_CHECK_EQUAL( s.usr_handle, "other" );
232 subscr s2(nameseq(999, 888, 2888), 9876, SUB_SERVICE, "other");
233 BOOST_CHECK_EQUAL( s, s2 );
236 BOOST_CHECK_EQUAL( s3, s2 );
238 subscr s4(nameseq(999, 888), 12345, SUB_PORTS);
239 BOOST_CHECK_EQUAL( s4.seq.type, 999 );
240 BOOST_CHECK_EQUAL( s4.seq.lower, 888 );
241 BOOST_CHECK_EQUAL( s4.seq.upper, 888 );
242 BOOST_CHECK_EQUAL( s4.name_seq(), nameseq(999, 888) );
243 BOOST_CHECK_EQUAL( s4.timeout, 12345 );
244 BOOST_CHECK_EQUAL( s4.filter, SUB_PORTS );
245 BOOST_CHECK_EQUAL( s4.usr_handle, "" );
249 BOOST_AUTO_TEST_CASE( linux_tipc_sockaddr_const_subscr_test )
252 const subscr s(nameseq(999, 888), 12345, SUB_PORTS, "handle");
253 BOOST_CHECK_EQUAL( s.seq.type, 999 );
254 BOOST_CHECK_EQUAL( s.seq.lower, 888 );
255 BOOST_CHECK_EQUAL( s.seq.upper, 888 );
256 BOOST_CHECK_EQUAL( s.name_seq(), nameseq(999, 888) );
257 BOOST_CHECK_EQUAL( s.timeout, 12345 );
258 BOOST_CHECK_EQUAL( s.filter, SUB_PORTS );
259 BOOST_CHECK_EQUAL( s.usr_handle, "handle" );
261 const subscr s2(nameseq(999, 888), 12345, SUB_PORTS, "handle");
262 BOOST_CHECK_EQUAL( s, s2 );
265 BOOST_CHECK_EQUAL( s3, s2 );
267 const subscr s4(nameseq(999, 888), 12345, SUB_PORTS);
268 BOOST_CHECK_EQUAL( s4.seq.type, 999 );
269 BOOST_CHECK_EQUAL( s4.seq.lower, 888 );
270 BOOST_CHECK_EQUAL( s4.seq.upper, 888 );
271 BOOST_CHECK_EQUAL( s4.name_seq(), nameseq(999, 888) );
272 BOOST_CHECK_EQUAL( s4.timeout, 12345 );
273 BOOST_CHECK_EQUAL( s4.filter, SUB_PORTS );
274 BOOST_CHECK_EQUAL( s4.usr_handle, "" );
278 BOOST_AUTO_TEST_CASE( linux_tipc_sockaddr_subscr_event_test )
284 e.found_upper = 1888;
286 e.port.node = addr(0, 2, 340);
291 e.s.filter = SUB_PORTS;
292 strcpy(e.s.usr_handle, "handle");
293 BOOST_CHECK_EQUAL( e.event, PUBLISHED );
294 BOOST_CHECK_EQUAL( e.found_lower, 888 );
295 BOOST_CHECK_EQUAL( e.found_upper, 1888 );
296 BOOST_CHECK_EQUAL( e.port.ref, 12345 );
297 BOOST_CHECK_EQUAL( e.port.node, 8532 );
298 BOOST_CHECK_EQUAL( e.port_id(), portid(12345, addr(0, 2, 340)) );
299 BOOST_CHECK_EQUAL( e.s.seq.type, 999 );
300 BOOST_CHECK_EQUAL( e.s.seq.lower, 888 );
301 BOOST_CHECK_EQUAL( e.s.seq.upper, 888 );
302 BOOST_CHECK_EQUAL( e.subscription().name_seq(), nameseq(999, 888) );
303 BOOST_CHECK_EQUAL( e.s.timeout, 12345 );
304 BOOST_CHECK_EQUAL( e.s.filter, SUB_PORTS );
305 BOOST_CHECK_EQUAL( e.s.usr_handle, "handle" );
307 e.port_id().node_addr().zone(1);
308 BOOST_CHECK_EQUAL( e.event, PUBLISHED );
309 BOOST_CHECK_EQUAL( e.found_lower, 888 );
310 BOOST_CHECK_EQUAL( e.found_upper, 1888 );
311 BOOST_CHECK_EQUAL( e.port.ref, 12345 );
312 BOOST_CHECK_EQUAL( e.port.node, 16785748 );
313 BOOST_CHECK_EQUAL( e.port_id(), portid(12345, addr(1, 2, 340)) );
314 BOOST_CHECK_EQUAL( e.s.seq.type, 999 );
315 BOOST_CHECK_EQUAL( e.s.seq.lower, 888 );
316 BOOST_CHECK_EQUAL( e.s.seq.upper, 888 );
317 BOOST_CHECK_EQUAL( e.subscription().name_seq(), nameseq(999, 888) );
318 BOOST_CHECK_EQUAL( e.s.timeout, 12345 );
319 BOOST_CHECK_EQUAL( e.s.filter, SUB_PORTS );
320 BOOST_CHECK_EQUAL( e.s.usr_handle, "handle" );
322 e.subscription().name_seq().upper = 1888;
323 BOOST_CHECK_EQUAL( e.event, PUBLISHED );
324 BOOST_CHECK_EQUAL( e.found_lower, 888 );
325 BOOST_CHECK_EQUAL( e.found_upper, 1888 );
326 BOOST_CHECK_EQUAL( e.port.ref, 12345 );
327 BOOST_CHECK_EQUAL( e.port.node, 16785748 );
328 BOOST_CHECK_EQUAL( e.port_id(), portid(12345, addr(1, 2, 340)) );
329 BOOST_CHECK_EQUAL( e.s.seq.type, 999 );
330 BOOST_CHECK_EQUAL( e.s.seq.lower, 888 );
331 BOOST_CHECK_EQUAL( e.s.seq.upper, 1888 );
332 BOOST_CHECK_EQUAL( e.subscription().name_seq(),
333 nameseq(999, 888, 1888) );
334 BOOST_CHECK_EQUAL( e.s.timeout, 12345 );
335 BOOST_CHECK_EQUAL( e.s.filter, SUB_PORTS );
336 BOOST_CHECK_EQUAL( e.s.usr_handle, "handle" );
338 e.subscription().handle("lala");
339 BOOST_CHECK_EQUAL( e.event, PUBLISHED );
340 BOOST_CHECK_EQUAL( e.found_lower, 888 );
341 BOOST_CHECK_EQUAL( e.found_upper, 1888 );
342 BOOST_CHECK_EQUAL( e.port.ref, 12345 );
343 BOOST_CHECK_EQUAL( e.port.node, 16785748 );
344 BOOST_CHECK_EQUAL( e.port_id(), portid(12345, addr(1, 2, 340)) );
345 BOOST_CHECK_EQUAL( e.s.seq.type, 999 );
346 BOOST_CHECK_EQUAL( e.s.seq.lower, 888 );
347 BOOST_CHECK_EQUAL( e.s.seq.upper, 1888 );
348 BOOST_CHECK_EQUAL( e.subscription().name_seq(),
349 nameseq(999, 888, 1888) );
350 BOOST_CHECK_EQUAL( e.s.timeout, 12345 );
351 BOOST_CHECK_EQUAL( e.s.filter, SUB_PORTS );
352 BOOST_CHECK_EQUAL( e.s.usr_handle, "lala" );
356 BOOST_AUTO_TEST_CASE( linux_tipc_sockaddr_const_event_test )
362 e.found_upper = 1888;
369 e.s.filter = SUB_PORTS;
370 strcpy(e.s.usr_handle, "handle");
371 const subscr_event& ee = e;
372 BOOST_CHECK_EQUAL( ee.event, PUBLISHED );
373 BOOST_CHECK_EQUAL( ee.found_lower, 888 );
374 BOOST_CHECK_EQUAL( ee.found_upper, 1888 );
375 BOOST_CHECK_EQUAL( ee.port.ref, 12345 );
376 BOOST_CHECK_EQUAL( ee.port.node, 8532 );
377 BOOST_CHECK_EQUAL( ee.port_id(), portid(12345, addr(0, 2, 340)) );
378 BOOST_CHECK_EQUAL( ee.s.seq.type, 999 );
379 BOOST_CHECK_EQUAL( ee.s.seq.lower, 888 );
380 BOOST_CHECK_EQUAL( ee.s.seq.upper, 888 );
381 BOOST_CHECK_EQUAL( ee.subscription().name_seq(), nameseq(999, 888) );
382 BOOST_CHECK_EQUAL( ee.s.timeout, 12345 );
383 BOOST_CHECK_EQUAL( ee.s.filter, SUB_PORTS );
384 BOOST_CHECK_EQUAL( ee.s.usr_handle, "handle" );
388 BOOST_AUTO_TEST_CASE( linux_tipc_sockaddr_testaddr_test )
390 BOOST_CHECK_EQUAL(test_address1.addr.name.name.type, PTYPE);
391 BOOST_CHECK_EQUAL(test_address1.addr.name.name.instance, INST1);
392 BOOST_CHECK_EQUAL(test_address2.addr.name.name.type, PTYPE);
393 BOOST_CHECK_EQUAL(test_address2.addr.name.name.instance, INST2);
396 BOOST_AUTO_TEST_CASE( linux_tipc_sockaddr_default_ctor_test )
399 BOOST_CHECK_EQUAL( sa.family, AF_TIPC );
400 BOOST_CHECK_EQUAL( sa.addrtype, 0 );
401 BOOST_CHECK_EQUAL( sa.scope, 0 );
402 BOOST_CHECK_EQUAL( sa.name_seq(), nameseq(0, 0, 0) );
403 BOOST_CHECK_EQUAL( sa.length(), sizeof(sockaddr_tipc) );
406 BOOST_AUTO_TEST_CASE( linux_tipc_sockaddr_id_ctor_test )
409 portid id(12313, addr(1, 1, 77));
410 tipc::sockaddr sp(id);
411 BOOST_CHECK_EQUAL( sp.family, AF_TIPC );
412 BOOST_CHECK_EQUAL( sp.addrtype, ID );
413 BOOST_CHECK_EQUAL( sp.type(), ID );
414 BOOST_CHECK_EQUAL( sp.scope, ZONE );
415 BOOST_CHECK_EQUAL( sp.port_id(), id );
416 BOOST_CHECK_EQUAL( sp.addr.id.ref, id.ref );
417 BOOST_CHECK_EQUAL( sp.addr.id.node, id.node );
419 sp.port_id().node_addr().zone(2);
420 BOOST_CHECK_EQUAL( sp.port_id(), portid(12313, addr(2, 1, 77)) );
422 BOOST_CHECK_EQUAL( sp, tipc::sockaddr(portid(12313, addr(2, 1, 77))) );
424 tipc::sockaddr sp2(id, NODE);
425 BOOST_CHECK_EQUAL( sp2.family, AF_TIPC );
426 BOOST_CHECK_EQUAL( sp2.addrtype, ID );
427 BOOST_CHECK_EQUAL( sp2.type(), ID );
428 BOOST_CHECK_EQUAL( sp2.scope, NODE );
429 BOOST_CHECK_EQUAL( sp2.port_id(), id );
430 BOOST_CHECK_EQUAL( sp2.addr.id.ref, id.ref );
431 BOOST_CHECK_EQUAL( sp2.addr.id.node, id.node );
435 BOOST_AUTO_TEST_CASE( linux_tipc_sockaddr_name_ctor_test )
439 tipc::sockaddr sn(n);
440 BOOST_CHECK_EQUAL( sn.family, AF_TIPC );
441 BOOST_CHECK_EQUAL( sn.addrtype, NAME );
442 BOOST_CHECK_EQUAL( sn.type(), NAME );
443 BOOST_CHECK_EQUAL( sn.scope, ZONE );
444 BOOST_CHECK_EQUAL( sn.port_name(), n );
445 BOOST_CHECK_EQUAL( sn.addr.name.name.type, n.type );
446 BOOST_CHECK_EQUAL( sn.addr.name.name.instance, n.instance );
447 BOOST_CHECK_EQUAL( sn.name_domain(), addr(0u) );
448 BOOST_CHECK_EQUAL( sn.addr.name.domain, 0u );
450 sn.port_name().type = 999;
451 BOOST_CHECK_EQUAL( sn.port_name(), name(999, 77) );
453 sn.name_domain().node(999);
454 BOOST_CHECK_EQUAL( sn.name_domain(), addr(0, 0, 999) );
456 BOOST_CHECK_EQUAL( sn, tipc::sockaddr(name(999, 77), ZONE,
461 BOOST_AUTO_TEST_CASE( linux_tipc_sockaddr_nameseq_ctor_test )
464 nameseq ns(12313, 77);
465 tipc::sockaddr sns(ns);
466 BOOST_CHECK_EQUAL( sns.family, AF_TIPC );
467 BOOST_CHECK_EQUAL( sns.addrtype, NAMESEQ );
468 BOOST_CHECK_EQUAL( sns.type(), NAMESEQ );
469 BOOST_CHECK_EQUAL( sns.scope, ZONE );
470 BOOST_CHECK_EQUAL( sns.name_seq(), ns );
471 BOOST_CHECK_EQUAL( sns.addr.nameseq.type, ns.type );
472 BOOST_CHECK_EQUAL( sns.addr.nameseq.lower, ns.lower );
473 BOOST_CHECK_EQUAL( sns.addr.nameseq.upper, ns.upper );
475 sns.name_seq().upper = 1999;
476 BOOST_CHECK_EQUAL( sns.name_seq(), nameseq(12313, 77, 1999) );
478 BOOST_CHECK_EQUAL( sns, tipc::sockaddr(nameseq(12313, 77, 1999)) );