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
6 using namespace ::posixx::linux::tipc;
7 namespace tipc = ::posixx::linux::tipc;
9 BOOST_AUTO_TEST_CASE( linux_tipc_sockaddr_addr_test )
13 BOOST_CHECK_EQUAL( a.zone(), 1 );
14 BOOST_CHECK_EQUAL( a.cluster(), 2 );
15 BOOST_CHECK_EQUAL( a.node(), 3 );
18 BOOST_CHECK_EQUAL( a.zone(), 3 );
19 BOOST_CHECK_EQUAL( a.cluster(), 2 );
20 BOOST_CHECK_EQUAL( a.node(), 3 );
23 BOOST_CHECK_EQUAL( a.zone(), 3 );
24 BOOST_CHECK_EQUAL( a.cluster(), 1 );
25 BOOST_CHECK_EQUAL( a.node(), 3 );
28 BOOST_CHECK_EQUAL( a.zone(), 3 );
29 BOOST_CHECK_EQUAL( a.cluster(), 1 );
30 BOOST_CHECK_EQUAL( a.node(), 2 );
33 BOOST_CHECK_EQUAL( a, a2 );
35 addr a3(static_cast<uint32_t>(a2));
36 BOOST_CHECK_EQUAL( a3, a2 );
40 BOOST_AUTO_TEST_CASE( linux_tipc_sockaddr_const_addr_test )
43 const addr a(1, 2, 3);
44 BOOST_CHECK_EQUAL( a.zone(), 1 );
45 BOOST_CHECK_EQUAL( a.cluster(), 2 );
46 BOOST_CHECK_EQUAL( a.node(), 3 );
48 const addr a2(1, 2, 3);
49 BOOST_CHECK_EQUAL( a, a2 );
51 const addr a3(static_cast<uint32_t>(a2));
52 BOOST_CHECK_EQUAL( a3, a2 );
56 BOOST_AUTO_TEST_CASE( linux_tipc_sockaddr_portid_test )
59 portid id(55, addr(1, 2, 3));
60 BOOST_CHECK_EQUAL( id.ref, 55 );
61 BOOST_CHECK_EQUAL( id.node, addr(1, 2, 3) );
62 BOOST_CHECK_EQUAL( id.node_addr().zone(), 1 );
63 BOOST_CHECK_EQUAL( id.node_addr().cluster(), 2 );
64 BOOST_CHECK_EQUAL( id.node_addr().node(), 3 );
66 id.node_addr().zone(3);
67 BOOST_CHECK_EQUAL( id.node_addr().zone(), 3 );
68 BOOST_CHECK_EQUAL( id.node_addr().cluster(), 2 );
69 BOOST_CHECK_EQUAL( id.node_addr().node(), 3 );
71 portid id2(55, addr(3, 2, 3));
72 BOOST_CHECK_EQUAL( id, id2 );
75 BOOST_CHECK_EQUAL( id3, id2 );
79 BOOST_AUTO_TEST_CASE( linux_tipc_sockaddr_const_portid_test )
82 const portid id(55, addr(1, 2, 3));
83 BOOST_CHECK_EQUAL( id.ref, 55 );
84 BOOST_CHECK_EQUAL( id.node, addr(1, 2, 3) );
85 BOOST_CHECK_EQUAL( id.node_addr().zone(), 1 );
86 BOOST_CHECK_EQUAL( id.node_addr().cluster(), 2 );
87 BOOST_CHECK_EQUAL( id.node_addr().node(), 3 );
89 const portid id2(55, addr(1, 2, 3));
90 BOOST_CHECK_EQUAL( id, id2 );
93 BOOST_CHECK_EQUAL( id3, id2 );
97 BOOST_AUTO_TEST_CASE( linux_tipc_sockaddr_name_test )
101 BOOST_CHECK_EQUAL( n.type, 598 );
102 BOOST_CHECK_EQUAL( n.instance, 2937 );
105 BOOST_CHECK_EQUAL( n.type, 9834 );
106 BOOST_CHECK_EQUAL( n.instance, 2937 );
109 BOOST_CHECK_EQUAL( n.type, 9834 );
110 BOOST_CHECK_EQUAL( n.instance, 3324 );
113 BOOST_CHECK_EQUAL( n, n2 );
116 BOOST_CHECK_EQUAL( n3, n2 );
120 BOOST_AUTO_TEST_CASE( linux_tipc_sockaddr_const_name_test )
123 const name n(598, 2937);
124 BOOST_CHECK_EQUAL( n.type, 598 );
125 BOOST_CHECK_EQUAL( n.instance, 2937 );
127 const name n2(598, 2937);
128 BOOST_CHECK_EQUAL( n, n2 );
131 BOOST_CHECK_EQUAL( n3, n2 );
135 BOOST_AUTO_TEST_CASE( linux_tipc_sockaddr_nameseq_test )
138 nameseq n(598, 2937, 666);
139 BOOST_CHECK_EQUAL( n.type, 598 );
140 BOOST_CHECK_EQUAL( n.lower, 2937 );
141 BOOST_CHECK_EQUAL( n.upper, 666 );
144 BOOST_CHECK_EQUAL( n.type, 9834 );
145 BOOST_CHECK_EQUAL( n.lower, 2937 );
146 BOOST_CHECK_EQUAL( n.upper, 666 );
149 BOOST_CHECK_EQUAL( n.type, 9834 );
150 BOOST_CHECK_EQUAL( n.lower, 3324 );
151 BOOST_CHECK_EQUAL( n.upper, 666 );
154 BOOST_CHECK_EQUAL( n.type, 9834 );
155 BOOST_CHECK_EQUAL( n.lower, 3324 );
156 BOOST_CHECK_EQUAL( n.upper, 9999 );
158 nameseq n2(9834, 3324, 9999);
159 BOOST_CHECK_EQUAL( n, n2 );
162 BOOST_CHECK_EQUAL( n3, n2 );
164 nameseq n4(9834, 3324);
165 BOOST_CHECK_EQUAL( n4.type, 9834 );
166 BOOST_CHECK_EQUAL( n4.lower, 3324 );
167 BOOST_CHECK_EQUAL( n4.upper, 3324 );
171 BOOST_AUTO_TEST_CASE( linux_tipc_sockaddr_const_nameseq_test )
174 const nameseq n(598, 2937, 666);
175 BOOST_CHECK_EQUAL( n.type, 598 );
176 BOOST_CHECK_EQUAL( n.lower, 2937 );
177 BOOST_CHECK_EQUAL( n.upper, 666 );
179 const nameseq n2(598, 2937, 666);
180 BOOST_CHECK_EQUAL( n, n2 );
183 BOOST_CHECK_EQUAL( n3, n2 );
185 const nameseq n4(9834, 3324);
186 BOOST_CHECK_EQUAL( n4.type, 9834 );
187 BOOST_CHECK_EQUAL( n4.lower, 3324 );
188 BOOST_CHECK_EQUAL( n4.upper, 3324 );
192 BOOST_AUTO_TEST_CASE( linux_tipc_sockaddr_subscr_test )
195 subscr s(nameseq(999, 888), 12345, SUB_PORTS, "handle");
196 BOOST_CHECK_EQUAL( s.seq.type, 999 );
197 BOOST_CHECK_EQUAL( s.seq.lower, 888 );
198 BOOST_CHECK_EQUAL( s.seq.upper, 888 );
199 BOOST_CHECK_EQUAL( s.name_seq(), nameseq(999, 888) );
200 BOOST_CHECK_EQUAL( s.timeout, 12345 );
201 BOOST_CHECK_EQUAL( s.filter, SUB_PORTS );
202 BOOST_CHECK_EQUAL( s.usr_handle, "handle" );
204 s.name_seq().upper = 2888;
205 BOOST_CHECK_EQUAL( s.seq.type, 999 );
206 BOOST_CHECK_EQUAL( s.seq.lower, 888 );
207 BOOST_CHECK_EQUAL( s.seq.upper, 2888 );
208 BOOST_CHECK_EQUAL( s.name_seq(), nameseq(999, 888, 2888) );
209 BOOST_CHECK_EQUAL( s.timeout, 12345 );
210 BOOST_CHECK_EQUAL( s.filter, SUB_PORTS );
211 BOOST_CHECK_EQUAL( s.usr_handle, "handle" );
214 BOOST_CHECK_EQUAL( s.name_seq(), nameseq(999, 888, 2888) );
215 BOOST_CHECK_EQUAL( s.timeout, 9876 );
216 BOOST_CHECK_EQUAL( s.filter, SUB_PORTS );
217 BOOST_CHECK_EQUAL( s.usr_handle, "handle" );
219 s.filter = SUB_SERVICE;
220 BOOST_CHECK_EQUAL( s.name_seq(), nameseq(999, 888, 2888) );
221 BOOST_CHECK_EQUAL( s.timeout, 9876 );
222 BOOST_CHECK_EQUAL( s.filter, SUB_SERVICE );
223 BOOST_CHECK_EQUAL( s.usr_handle, "handle" );
226 BOOST_CHECK_EQUAL( s.name_seq(), nameseq(999, 888, 2888) );
227 BOOST_CHECK_EQUAL( s.timeout, 9876 );
228 BOOST_CHECK_EQUAL( s.filter, SUB_SERVICE );
229 BOOST_CHECK_EQUAL( s.usr_handle, "other" );
231 subscr s2(nameseq(999, 888, 2888), 9876, SUB_SERVICE, "other");
232 BOOST_CHECK_EQUAL( s, s2 );
235 BOOST_CHECK_EQUAL( s3, s2 );
237 subscr s4(nameseq(999, 888), 12345, SUB_PORTS);
238 BOOST_CHECK_EQUAL( s4.seq.type, 999 );
239 BOOST_CHECK_EQUAL( s4.seq.lower, 888 );
240 BOOST_CHECK_EQUAL( s4.seq.upper, 888 );
241 BOOST_CHECK_EQUAL( s4.name_seq(), nameseq(999, 888) );
242 BOOST_CHECK_EQUAL( s4.timeout, 12345 );
243 BOOST_CHECK_EQUAL( s4.filter, SUB_PORTS );
244 BOOST_CHECK_EQUAL( s4.usr_handle, "" );
248 BOOST_AUTO_TEST_CASE( linux_tipc_sockaddr_const_subscr_test )
251 const subscr s(nameseq(999, 888), 12345, SUB_PORTS, "handle");
252 BOOST_CHECK_EQUAL( s.seq.type, 999 );
253 BOOST_CHECK_EQUAL( s.seq.lower, 888 );
254 BOOST_CHECK_EQUAL( s.seq.upper, 888 );
255 BOOST_CHECK_EQUAL( s.name_seq(), nameseq(999, 888) );
256 BOOST_CHECK_EQUAL( s.timeout, 12345 );
257 BOOST_CHECK_EQUAL( s.filter, SUB_PORTS );
258 BOOST_CHECK_EQUAL( s.usr_handle, "handle" );
260 const subscr s2(nameseq(999, 888), 12345, SUB_PORTS, "handle");
261 BOOST_CHECK_EQUAL( s, s2 );
264 BOOST_CHECK_EQUAL( s3, s2 );
266 const subscr s4(nameseq(999, 888), 12345, SUB_PORTS);
267 BOOST_CHECK_EQUAL( s4.seq.type, 999 );
268 BOOST_CHECK_EQUAL( s4.seq.lower, 888 );
269 BOOST_CHECK_EQUAL( s4.seq.upper, 888 );
270 BOOST_CHECK_EQUAL( s4.name_seq(), nameseq(999, 888) );
271 BOOST_CHECK_EQUAL( s4.timeout, 12345 );
272 BOOST_CHECK_EQUAL( s4.filter, SUB_PORTS );
273 BOOST_CHECK_EQUAL( s4.usr_handle, "" );
277 BOOST_AUTO_TEST_CASE( linux_tipc_sockaddr_subscr_event_test )
283 e.found_upper = 1888;
285 e.port.node = addr(0, 2, 340);
290 e.s.filter = SUB_PORTS;
291 strcpy(e.s.usr_handle, "handle");
292 BOOST_CHECK_EQUAL( e.event, PUBLISHED );
293 BOOST_CHECK_EQUAL( e.found_lower, 888 );
294 BOOST_CHECK_EQUAL( e.found_upper, 1888 );
295 BOOST_CHECK_EQUAL( e.port.ref, 12345 );
296 BOOST_CHECK_EQUAL( e.port.node, 8532 );
297 BOOST_CHECK_EQUAL( e.port_id(), portid(12345, addr(0, 2, 340)) );
298 BOOST_CHECK_EQUAL( e.s.seq.type, 999 );
299 BOOST_CHECK_EQUAL( e.s.seq.lower, 888 );
300 BOOST_CHECK_EQUAL( e.s.seq.upper, 888 );
301 BOOST_CHECK_EQUAL( e.subscription().name_seq(), nameseq(999, 888) );
302 BOOST_CHECK_EQUAL( e.s.timeout, 12345 );
303 BOOST_CHECK_EQUAL( e.s.filter, SUB_PORTS );
304 BOOST_CHECK_EQUAL( e.s.usr_handle, "handle" );
306 e.port_id().node_addr().zone(1);
307 BOOST_CHECK_EQUAL( e.event, PUBLISHED );
308 BOOST_CHECK_EQUAL( e.found_lower, 888 );
309 BOOST_CHECK_EQUAL( e.found_upper, 1888 );
310 BOOST_CHECK_EQUAL( e.port.ref, 12345 );
311 BOOST_CHECK_EQUAL( e.port.node, 16785748 );
312 BOOST_CHECK_EQUAL( e.port_id(), portid(12345, addr(1, 2, 340)) );
313 BOOST_CHECK_EQUAL( e.s.seq.type, 999 );
314 BOOST_CHECK_EQUAL( e.s.seq.lower, 888 );
315 BOOST_CHECK_EQUAL( e.s.seq.upper, 888 );
316 BOOST_CHECK_EQUAL( e.subscription().name_seq(), nameseq(999, 888) );
317 BOOST_CHECK_EQUAL( e.s.timeout, 12345 );
318 BOOST_CHECK_EQUAL( e.s.filter, SUB_PORTS );
319 BOOST_CHECK_EQUAL( e.s.usr_handle, "handle" );
321 e.subscription().name_seq().upper = 1888;
322 BOOST_CHECK_EQUAL( e.event, PUBLISHED );
323 BOOST_CHECK_EQUAL( e.found_lower, 888 );
324 BOOST_CHECK_EQUAL( e.found_upper, 1888 );
325 BOOST_CHECK_EQUAL( e.port.ref, 12345 );
326 BOOST_CHECK_EQUAL( e.port.node, 16785748 );
327 BOOST_CHECK_EQUAL( e.port_id(), portid(12345, addr(1, 2, 340)) );
328 BOOST_CHECK_EQUAL( e.s.seq.type, 999 );
329 BOOST_CHECK_EQUAL( e.s.seq.lower, 888 );
330 BOOST_CHECK_EQUAL( e.s.seq.upper, 1888 );
331 BOOST_CHECK_EQUAL( e.subscription().name_seq(),
332 nameseq(999, 888, 1888) );
333 BOOST_CHECK_EQUAL( e.s.timeout, 12345 );
334 BOOST_CHECK_EQUAL( e.s.filter, SUB_PORTS );
335 BOOST_CHECK_EQUAL( e.s.usr_handle, "handle" );
337 e.subscription().handle("lala");
338 BOOST_CHECK_EQUAL( e.event, PUBLISHED );
339 BOOST_CHECK_EQUAL( e.found_lower, 888 );
340 BOOST_CHECK_EQUAL( e.found_upper, 1888 );
341 BOOST_CHECK_EQUAL( e.port.ref, 12345 );
342 BOOST_CHECK_EQUAL( e.port.node, 16785748 );
343 BOOST_CHECK_EQUAL( e.port_id(), portid(12345, addr(1, 2, 340)) );
344 BOOST_CHECK_EQUAL( e.s.seq.type, 999 );
345 BOOST_CHECK_EQUAL( e.s.seq.lower, 888 );
346 BOOST_CHECK_EQUAL( e.s.seq.upper, 1888 );
347 BOOST_CHECK_EQUAL( e.subscription().name_seq(),
348 nameseq(999, 888, 1888) );
349 BOOST_CHECK_EQUAL( e.s.timeout, 12345 );
350 BOOST_CHECK_EQUAL( e.s.filter, SUB_PORTS );
351 BOOST_CHECK_EQUAL( e.s.usr_handle, "lala" );
355 BOOST_AUTO_TEST_CASE( linux_tipc_sockaddr_const_event_test )
361 e.found_upper = 1888;
368 e.s.filter = SUB_PORTS;
369 strcpy(e.s.usr_handle, "handle");
370 const subscr_event& ee = e;
371 BOOST_CHECK_EQUAL( ee.event, PUBLISHED );
372 BOOST_CHECK_EQUAL( ee.found_lower, 888 );
373 BOOST_CHECK_EQUAL( ee.found_upper, 1888 );
374 BOOST_CHECK_EQUAL( ee.port.ref, 12345 );
375 BOOST_CHECK_EQUAL( ee.port.node, 8532 );
376 BOOST_CHECK_EQUAL( ee.port_id(), portid(12345, addr(0, 2, 340)) );
377 BOOST_CHECK_EQUAL( ee.s.seq.type, 999 );
378 BOOST_CHECK_EQUAL( ee.s.seq.lower, 888 );
379 BOOST_CHECK_EQUAL( ee.s.seq.upper, 888 );
380 BOOST_CHECK_EQUAL( ee.subscription().name_seq(), nameseq(999, 888) );
381 BOOST_CHECK_EQUAL( ee.s.timeout, 12345 );
382 BOOST_CHECK_EQUAL( ee.s.filter, SUB_PORTS );
383 BOOST_CHECK_EQUAL( ee.s.usr_handle, "handle" );
387 BOOST_AUTO_TEST_CASE( linux_tipc_sockaddr_testaddr_test )
389 BOOST_CHECK_EQUAL(test_address1.addr.name.name.type, PTYPE);
390 BOOST_CHECK_EQUAL(test_address1.addr.name.name.instance, INST1);
391 BOOST_CHECK_EQUAL(test_address2.addr.name.name.type, PTYPE);
392 BOOST_CHECK_EQUAL(test_address2.addr.name.name.instance, INST2);
395 BOOST_AUTO_TEST_CASE( linux_tipc_sockaddr_default_ctor_test )
398 BOOST_CHECK_EQUAL( sa.family, AF_TIPC );
399 BOOST_CHECK_EQUAL( sa.addrtype, 0 );
400 BOOST_CHECK_EQUAL( sa.scope, 0 );
401 BOOST_CHECK_EQUAL( sa.name_seq(), nameseq(0, 0, 0) );
402 BOOST_CHECK_EQUAL( sa.length(), sizeof(sockaddr_tipc) );
405 BOOST_AUTO_TEST_CASE( linux_tipc_sockaddr_id_ctor_test )
408 portid id(12313, addr(1, 1, 77));
409 tipc::sockaddr sp(id);
410 BOOST_CHECK_EQUAL( sp.family, AF_TIPC );
411 BOOST_CHECK_EQUAL( sp.addrtype, tipc::sockaddr::ID );
412 BOOST_CHECK_EQUAL( sp.type(), tipc::sockaddr::ID );
413 BOOST_CHECK_EQUAL( sp.scope, tipc::sockaddr::ZONE );
414 BOOST_CHECK_EQUAL( sp.port_id(), id );
415 BOOST_CHECK_EQUAL( sp.addr.id.ref, id.ref );
416 BOOST_CHECK_EQUAL( sp.addr.id.node, id.node );
418 sp.port_id().node_addr().zone(2);
419 BOOST_CHECK_EQUAL( sp.port_id(), portid(12313, addr(2, 1, 77)) );
421 BOOST_CHECK_EQUAL( sp, tipc::sockaddr(portid(12313, addr(2, 1, 77))) );
423 tipc::sockaddr sp2(id, tipc::sockaddr::NODE);
424 BOOST_CHECK_EQUAL( sp2.family, AF_TIPC );
425 BOOST_CHECK_EQUAL( sp2.addrtype, tipc::sockaddr::ID );
426 BOOST_CHECK_EQUAL( sp2.type(), tipc::sockaddr::ID );
427 BOOST_CHECK_EQUAL( sp2.scope, tipc::sockaddr::NODE );
428 BOOST_CHECK_EQUAL( sp2.port_id(), id );
429 BOOST_CHECK_EQUAL( sp2.addr.id.ref, id.ref );
430 BOOST_CHECK_EQUAL( sp2.addr.id.node, id.node );
434 BOOST_AUTO_TEST_CASE( linux_tipc_sockaddr_name_ctor_test )
438 tipc::sockaddr sn(n);
439 BOOST_CHECK_EQUAL( sn.family, AF_TIPC );
440 BOOST_CHECK_EQUAL( sn.addrtype, tipc::sockaddr::NAME );
441 BOOST_CHECK_EQUAL( sn.type(), tipc::sockaddr::NAME );
442 BOOST_CHECK_EQUAL( sn.scope, tipc::sockaddr::ZONE );
443 BOOST_CHECK_EQUAL( sn.port_name(), n );
444 BOOST_CHECK_EQUAL( sn.addr.name.name.type, n.type );
445 BOOST_CHECK_EQUAL( sn.addr.name.name.instance, n.instance );
446 BOOST_CHECK_EQUAL( sn.name_domain(), addr(0u) );
447 BOOST_CHECK_EQUAL( sn.addr.name.domain, 0u );
449 sn.port_name().type = 999;
450 BOOST_CHECK_EQUAL( sn.port_name(), name(999, 77) );
452 sn.name_domain().node(999);
453 BOOST_CHECK_EQUAL( sn.name_domain(), addr(0, 0, 999) );
455 BOOST_CHECK_EQUAL( sn, tipc::sockaddr(name(999, 77),
456 tipc::sockaddr::ZONE, addr(0, 0, 999)) );
460 BOOST_AUTO_TEST_CASE( linux_tipc_sockaddr_nameseq_ctor_test )
463 nameseq ns(12313, 77);
464 tipc::sockaddr sns(ns);
465 BOOST_CHECK_EQUAL( sns.family, AF_TIPC );
466 BOOST_CHECK_EQUAL( sns.addrtype, tipc::sockaddr::NAMESEQ );
467 BOOST_CHECK_EQUAL( sns.type(), tipc::sockaddr::NAMESEQ );
468 BOOST_CHECK_EQUAL( sns.scope, tipc::sockaddr::ZONE );
469 BOOST_CHECK_EQUAL( sns.name_seq(), ns );
470 BOOST_CHECK_EQUAL( sns.addr.nameseq.type, ns.type );
471 BOOST_CHECK_EQUAL( sns.addr.nameseq.lower, ns.lower );
472 BOOST_CHECK_EQUAL( sns.addr.nameseq.upper, ns.upper );
474 sns.name_seq().upper = 1999;
475 BOOST_CHECK_EQUAL( sns.name_seq(), nameseq(12313, 77, 1999) );
477 BOOST_CHECK_EQUAL( sns, tipc::sockaddr(nameseq(12313, 77, 1999)) );