/codebase/src-cpp/test/ng6/ownership/AcquireOwnershipTest.cpp

https://github.com/graeme-muller/portico · C++ · 935 lines · 634 code · 69 blank · 232 comment · 2 complexity · 7fd436306e9ac38e95460854ea25fa9d MD5 · raw file

  1. /*
  2. * Copyright 2009 The Portico Project
  3. *
  4. * This file is part of portico.
  5. *
  6. * portico is free software; you can redistribute it and/or modify
  7. * it under the terms of the Common Developer and Distribution License (CDDL)
  8. * as published by Sun Microsystems. For more information see the LICENSE file.
  9. *
  10. * Use of this software is strictly AT YOUR OWN RISK!!!
  11. * If something bad happens you do not have permission to come crying to me.
  12. * (that goes for your lawyer as well)
  13. *
  14. */
  15. #include "AcquireOwnershipTest.h"
  16. // Register test suite with the global repository
  17. CPPUNIT_TEST_SUITE_REGISTRATION( AcquireOwnershipTest );
  18. CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( AcquireOwnershipTest, "AcquireOwnershipTest" );
  19. CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( AcquireOwnershipTest, "ownershipManagement" );
  20. /////////////////////////////////////////////////////////////////////////////////////////////
  21. ////////////////////////////////// Constructors/Destructors /////////////////////////////////
  22. /////////////////////////////////////////////////////////////////////////////////////////////
  23. AcquireOwnershipTest::AcquireOwnershipTest()
  24. {
  25. this->defaultFederate = new TestNG6Federate( "defaultFederate" );
  26. this->secondFederate = new TestNG6Federate( "secondFederate" );
  27. this->ahs = NULL;
  28. this->tag = new char[8];
  29. strcpy( this->tag, "eltaggo" );
  30. }
  31. AcquireOwnershipTest::~AcquireOwnershipTest()
  32. {
  33. delete this->defaultFederate;
  34. delete this->secondFederate;
  35. delete this->tag;
  36. }
  37. /////////////////////////////////////////////////////////////////////////////////////////////
  38. /////////////////////////////// Test Setup and Helper Methods ///////////////////////////////
  39. /////////////////////////////////////////////////////////////////////////////////////////////
  40. void AcquireOwnershipTest::setUp()
  41. {
  42. this->defaultFederate->quickCreate();
  43. this->defaultFederate->quickJoin();
  44. this->secondFederate->quickJoin();
  45. // cache some handle information
  46. this->ahs = NULL;
  47. this->aa = defaultFederate->quickACHandle( "ObjectRoot.A", "aa" );
  48. this->ab = defaultFederate->quickACHandle( "ObjectRoot.A", "ab" );
  49. this->ac = defaultFederate->quickACHandle( "ObjectRoot.A", "ac" );
  50. this->ba = defaultFederate->quickACHandle( "ObjectRoot.A.B", "ba" );
  51. this->bb = defaultFederate->quickACHandle( "ObjectRoot.A.B", "bb" );
  52. this->bc = defaultFederate->quickACHandle( "ObjectRoot.A.B", "bc" );
  53. // publish and subscribe
  54. defaultFederate->quickPublish( "ObjectRoot.A.B", 3, "aa", "ab", "ac" );
  55. secondFederate->quickSubscribe( "ObjectRoot.A.B", 6, "aa", "ab", "ac", "ba", "bb", "bc" );
  56. secondFederate->quickPublish( "ObjectRoot.A.B", 6, "aa", "ab", "ac", "ba", "bb", "bc" );
  57. // register and discover the object
  58. this->theObject = defaultFederate->quickRegister( "ObjectRoot.A.B" );
  59. this->secondFederate->fedamb->waitForDiscovery( theObject );
  60. }
  61. void AcquireOwnershipTest::tearDown()
  62. {
  63. if( this->ahs != NULL )
  64. delete this->ahs;
  65. this->secondFederate->quickResign();
  66. this->defaultFederate->quickResign();
  67. this->defaultFederate->quickDestroy();
  68. }
  69. /////////////////////////////////////////////////////////////////////////////////////////////
  70. ///////////////////////////// Acquire If Available Test Methods /////////////////////////////
  71. /////////////////////////////////////////////////////////////////////////////////////////////
  72. // void attributeOwnershipAcquisitionIfAvailable(
  73. // ObjectHandle theObject,
  74. // const AttributeHandleSet& desiredAttributes ) // supplied C4
  75. // throw ( ObjectNotKnown,
  76. // ObjectClassNotPublished,
  77. // AttributeNotDefined,
  78. // AttributeNotPublished,
  79. // FederateOwnsAttributes,
  80. // AttributeAlreadyBeingAcquired,
  81. // FederateNotExecutionMember,
  82. // ConcurrentAccessAttempted,
  83. // SaveInProgress,
  84. // RestoreInProgress,
  85. // RTIinternalError );
  86. /////////////////////////////////////////////////////
  87. // TEST: (valid) testAcquireOwnershipIfAvailable() //
  88. /////////////////////////////////////////////////////
  89. void AcquireOwnershipTest::testAcquireOwnershipIfAvailable()
  90. {
  91. try
  92. {
  93. this->ahs = secondFederate->populatedAHS( 3, ba, bb, bc );
  94. secondFederate->rtiamb->attributeOwnershipAcquisitionIfAvailable( theObject, *ahs );
  95. }
  96. catch( RTI::Exception& e )
  97. {
  98. failTest( "Unexpected exception while requesting ownership acquire (available): %s",
  99. e._reason );
  100. }
  101. // wait for the acquisition notification
  102. secondFederate->fedamb->waitForOwnershipAcquistion( theObject, 3, ba, bb, bc );
  103. secondFederate->quickAssertOwnedBy( secondFederate->getFederateHandle(), theObject, 3, ba, bb, bc );
  104. secondFederate->quickAssertOwnedBy( defaultFederate->getFederateHandle(), theObject, 3, aa, ab, ac );
  105. // give the default federate some time to process callbacks before checking ownership
  106. defaultFederate->quickTick( 0.1, 1.0 );
  107. defaultFederate->quickAssertOwnedBy( secondFederate->getFederateHandle(), theObject, 3, ba, bb, bc );
  108. defaultFederate->quickAssertOwnedBy( defaultFederate->getFederateHandle(), theObject, 3, aa, ab, ac );
  109. }
  110. ////////////////////////////////////////////////////////////////////
  111. // TEST: (valid) testAcquireOwnershipIfAvailableWhenUnavailable() //
  112. ////////////////////////////////////////////////////////////////////
  113. void AcquireOwnershipTest::testAcquireOwnershipIfAvailableWhenUnavailable()
  114. {
  115. try
  116. {
  117. this->ahs = secondFederate->populatedAHS( 3, aa, ab, ac );
  118. secondFederate->rtiamb->attributeOwnershipAcquisitionIfAvailable( theObject, *ahs );
  119. }
  120. catch( RTI::Exception& e )
  121. {
  122. failTest( "Unexpected exception while requesting ownership acquire (available): %s",
  123. e._reason );
  124. }
  125. // wait for the acquisition notification
  126. secondFederate->fedamb->waitForOwnershipUnavailable( theObject, 3, aa, ab, ac );
  127. secondFederate->quickAssertOwnedBy( TestNG6Federate::OWNER_UNOWNED, theObject, 3, ba, bb, bc );
  128. secondFederate->quickAssertOwnedBy( defaultFederate->getFederateHandle(), theObject, 3, aa, ab, ac );
  129. // give the default federate some time to process callbacks before checking ownership
  130. defaultFederate->quickTick( 0.1, 1.0 );
  131. secondFederate->quickAssertOwnedBy( TestNG6Federate::OWNER_UNOWNED, theObject, 3, ba, bb, bc );
  132. defaultFederate->quickAssertOwnedBy( defaultFederate->getFederateHandle(), theObject, 3, aa, ab, ac );
  133. }
  134. //////////////////////////////////////////////////////////////
  135. // TEST: testAcquireOwnershipIfAvailableWithUnknownObject() //
  136. //////////////////////////////////////////////////////////////
  137. void AcquireOwnershipTest::testAcquireOwnershipIfAvailableWithUnknownObject()
  138. {
  139. // register a second object but one that isn't discovered by the second federate
  140. RTI::ObjectHandle secondObject = defaultFederate->quickRegister( "ObjectRoot.A.B" );
  141. try
  142. {
  143. this->ahs = secondFederate->populatedAHS( 3, ba, bb, bc );
  144. secondFederate->rtiamb->attributeOwnershipAcquisitionIfAvailable( secondObject, *ahs );
  145. failTestMissingException( "ObjectNotKnown",
  146. "requesting attribute ownership with unknown object" );
  147. }
  148. catch( RTI::ObjectNotKnown& onk )
  149. {
  150. // success!
  151. }
  152. catch( RTI::Exception& e )
  153. {
  154. failTestWrongException( "ObjectNotKnown",
  155. e,
  156. "requesting attribute ownership with unknown object" );
  157. }
  158. }
  159. //////////////////////////////////////////////////////////////
  160. // TEST: testAcquireOwnershipIfAvailableWithInvalidObject() //
  161. //////////////////////////////////////////////////////////////
  162. void AcquireOwnershipTest::testAcquireOwnershipIfAvailableWithInvalidObject()
  163. {
  164. try
  165. {
  166. this->ahs = secondFederate->populatedAHS( 3, ba, bb, bc );
  167. secondFederate->rtiamb->attributeOwnershipAcquisitionIfAvailable( 100000, *ahs );
  168. failTestMissingException( "ObjectNotKnown",
  169. "requesting attribute ownership with invalid object" );
  170. }
  171. catch( RTI::ObjectNotKnown& onk )
  172. {
  173. // success!
  174. }
  175. catch( RTI::Exception& e )
  176. {
  177. failTestWrongException( "ObjectNotKnown",
  178. e,
  179. "requesting attribute ownership with invalid object" );
  180. }
  181. }
  182. /////////////////////////////////////////////////////////////////
  183. // TEST: testAcquireOwnershipIfAvailableWithInvalidAttribute() //
  184. /////////////////////////////////////////////////////////////////
  185. void AcquireOwnershipTest::testAcquireOwnershipIfAvailableWithInvalidAttribute()
  186. {
  187. try
  188. {
  189. this->ahs = secondFederate->populatedAHS( 3, ba, bb, 1000000 );
  190. secondFederate->rtiamb->attributeOwnershipAcquisitionIfAvailable( theObject, *ahs );
  191. failTestMissingException( "AttributeNotDefined",
  192. "requesting attribute ownership with invalid attribute" );
  193. }
  194. catch( RTI::AttributeNotDefined& anotd )
  195. {
  196. // success!
  197. }
  198. catch( RTI::Exception& e )
  199. {
  200. failTestWrongException( "AttributeNotDefined",
  201. e,
  202. "requesting attribute ownership with invalid attribute" );
  203. }
  204. }
  205. /////////////////////////////////////////////////////////////////
  206. // TEST: testAcquireOwnershipIfAvailableWithUnpublishedClass() //
  207. /////////////////////////////////////////////////////////////////
  208. void AcquireOwnershipTest::testAcquireOwnershipIfAvailableWithUnpublishedClass()
  209. {
  210. // unpublish ObjectRoot.A.B
  211. secondFederate->quickUnpublishOC( "ObjectRoot.A.B" );
  212. try
  213. {
  214. this->ahs = secondFederate->populatedAHS( 3, ba, bb, bc );
  215. secondFederate->rtiamb->attributeOwnershipAcquisitionIfAvailable( theObject, *ahs );
  216. failTestMissingException( "ObjectClassNotPublished",
  217. "requesting attribute ownership with unpublished class" );
  218. }
  219. catch( RTI::ObjectClassNotPublished& ocnp )
  220. {
  221. // success!
  222. }
  223. catch( RTI::Exception& e )
  224. {
  225. failTestWrongException( "ObjectClassNotPublished",
  226. e,
  227. "requesting attribute ownership with unpublished class" );
  228. }
  229. }
  230. /////////////////////////////////////////////////////////////////////
  231. // TEST: testAcquireOwnershipIfAvailableWithUnpublishedAttribute() //
  232. /////////////////////////////////////////////////////////////////////
  233. void AcquireOwnershipTest::testAcquireOwnershipIfAvailableWithUnpublishedAttribute()
  234. {
  235. // republish ObjectRoot.A.B, but with different set, essentially unpublishing some atts
  236. secondFederate->quickPublish( "ObjectRoot.A.B", 4, "aa", "ab", "ac", "ba" );
  237. try
  238. {
  239. this->ahs = secondFederate->populatedAHS( 3, ba, bb, bc );
  240. secondFederate->rtiamb->attributeOwnershipAcquisitionIfAvailable( theObject, *ahs );
  241. failTestMissingException( "AttributeNotPublished",
  242. "requesting attribute ownership with unpublished attribute" );
  243. }
  244. catch( RTI::AttributeNotPublished& anp )
  245. {
  246. // success!
  247. }
  248. catch( RTI::Exception& e )
  249. {
  250. failTestWrongException( "AttributeNotPublished",
  251. e,
  252. "requesting attribute ownership with unpublished attribute" );
  253. }
  254. }
  255. //////////////////////////////////////////////////////////////////////
  256. // TEST: testAcquireOwnershipIfAvailableWithAlreadyOwnedAttribute() //
  257. //////////////////////////////////////////////////////////////////////
  258. void AcquireOwnershipTest::testAcquireOwnershipIfAvailableWithAlreadyOwnedAttribute()
  259. {
  260. // acquire the unowned attributes
  261. secondFederate->quickAcquireIfAvailableRequest( theObject, 3, ba, bb, bc );
  262. secondFederate->fedamb->waitForOwnershipAcquistion( theObject, 3, ba, bb, bc );
  263. // try and re-acquire the atts we now own
  264. try
  265. {
  266. this->ahs = secondFederate->populatedAHS( 3, ba, bb, bc );
  267. secondFederate->rtiamb->attributeOwnershipAcquisitionIfAvailable( theObject, *ahs );
  268. failTestMissingException( "FederateOwnsAttributes",
  269. "requesting attribute ownership with attributes we already own" );
  270. }
  271. catch( RTI::FederateOwnsAttributes& foa )
  272. {
  273. // success!
  274. }
  275. catch( RTI::Exception& e )
  276. {
  277. failTestWrongException( "FederateOwnsAttributes",
  278. e,
  279. "requesting attribute ownership with attributes we already own" );
  280. }
  281. }
  282. //////////////////////////////////////////////////////////
  283. // TEST: testAcquireOwnershipIfAvailableWhenNotJoined() //
  284. //////////////////////////////////////////////////////////
  285. void AcquireOwnershipTest::testAcquireOwnershipIfAvailableWhenNotJoined()
  286. {
  287. secondFederate->quickResign();
  288. try
  289. {
  290. this->ahs = secondFederate->populatedAHS( 3, ba, bb, bc );
  291. secondFederate->rtiamb->attributeOwnershipAcquisitionIfAvailable( theObject, *ahs );
  292. failTestMissingException( "FederateNotExecutionMember",
  293. "requesting attribute ownership when not joined" );
  294. }
  295. catch( RTI::FederateNotExecutionMember& fnem )
  296. {
  297. // success!
  298. }
  299. catch( RTI::Exception& e )
  300. {
  301. failTestWrongException( "FederateNotExecutionMember",
  302. e,
  303. "requesting attribute ownership when not joined" );
  304. }
  305. }
  306. ////////////////////////////////////////////////////////////////////////////////////////////
  307. /////////////////////////////// General Acquire Test Methods ///////////////////////////////
  308. ////////////////////////////////////////////////////////////////////////////////////////////
  309. //void attributeOwnershipAcquisition (
  310. // ObjectHandle theObject, // supplied C1
  311. // const AttributeHandleSet& desiredAttributes, // supplied C4
  312. // const char *theTag ) // supplied C4
  313. // throw ( ObjectNotKnown,
  314. // ObjectClassNotPublished,
  315. // AttributeNotDefined,
  316. // AttributeNotPublished,
  317. // FederateOwnsAttributes,
  318. // FederateNotExecutionMember,
  319. // ConcurrentAccessAttempted,
  320. // SaveInProgress,
  321. // RestoreInProgress,
  322. // RTIinternalError );
  323. /////////////////////////////////////////////////////
  324. // TEST: (valid) testAcquireOwnershipIfAvailable() //
  325. /////////////////////////////////////////////////////
  326. void AcquireOwnershipTest::testAcquireOwnership()
  327. {
  328. try
  329. {
  330. this->ahs = secondFederate->populatedAHS( 3, aa, ab, ac );
  331. secondFederate->rtiamb->attributeOwnershipAcquisition( theObject, *ahs, "NA" );
  332. }
  333. catch( RTI::Exception& e )
  334. {
  335. failTest( "Unexpected exception while requesting ownership acquire: %s", e._reason );
  336. }
  337. // wait for the acquisition notification
  338. defaultFederate->fedamb->waitForOwnershipRequest( theObject, 3, aa, ab, ac );
  339. }
  340. ///////////////////////////////////////////////////
  341. // TEST: testAcquireOwnershipWithUnknownObject() //
  342. ///////////////////////////////////////////////////
  343. void AcquireOwnershipTest::testAcquireOwnershipWithUnknownObject()
  344. {
  345. // register a second object but one that isn't discovered by the second federate
  346. RTI::ObjectHandle secondObject = defaultFederate->quickRegister( "ObjectRoot.A.B" );
  347. try
  348. {
  349. this->ahs = secondFederate->populatedAHS( 3, aa, ab, ac );
  350. secondFederate->rtiamb->attributeOwnershipAcquisition( secondObject, *ahs, "NA" );
  351. failTestMissingException( "ObjectNotKnown",
  352. "requesting attribute ownership with unknown object" );
  353. }
  354. catch( RTI::ObjectNotKnown& onk )
  355. {
  356. // success!
  357. }
  358. catch( RTI::Exception& e )
  359. {
  360. failTestWrongException( "ObjectNotKnown",
  361. e,
  362. "requesting attribute ownership with unknown object" );
  363. }
  364. }
  365. ///////////////////////////////////////////////////
  366. // TEST: testAcquireOwnershipWithInvalidObject() //
  367. ///////////////////////////////////////////////////
  368. void AcquireOwnershipTest::testAcquireOwnershipWithInvalidObject()
  369. {
  370. try
  371. {
  372. this->ahs = secondFederate->populatedAHS( 3, aa, ab, ac );
  373. secondFederate->rtiamb->attributeOwnershipAcquisition( 100000, *ahs, "NA" );
  374. failTestMissingException( "ObjectNotKnown",
  375. "requesting attribute ownership with invalid object" );
  376. }
  377. catch( RTI::ObjectNotKnown& onk )
  378. {
  379. // success!
  380. }
  381. catch( RTI::Exception& e )
  382. {
  383. failTestWrongException( "ObjectNotKnown",
  384. e,
  385. "requesting attribute ownership with invalid object" );
  386. }
  387. }
  388. //////////////////////////////////////////////////////
  389. // TEST: testAcquireOwnershipWithInvalidAttribute() //
  390. //////////////////////////////////////////////////////
  391. void AcquireOwnershipTest::testAcquireOwnershipWithInvalidAttribute()
  392. {
  393. try
  394. {
  395. this->ahs = secondFederate->populatedAHS( 3, aa, ab, 1000000 );
  396. secondFederate->rtiamb->attributeOwnershipAcquisition( theObject, *ahs, "NA" );
  397. failTestMissingException( "AttributeNotDefined",
  398. "requesting attribute ownership with invalid attribute" );
  399. }
  400. catch( RTI::AttributeNotDefined& anotd )
  401. {
  402. // success!
  403. }
  404. catch( RTI::Exception& e )
  405. {
  406. failTestWrongException( "AttributeNotDefined",
  407. e,
  408. "requesting attribute ownership with invalid attribute" );
  409. }
  410. }
  411. //////////////////////////////////////////////////////////
  412. // TEST: testAcquireOwnershipWithUnpublishedAttribute() //
  413. //////////////////////////////////////////////////////////
  414. void AcquireOwnershipTest::testAcquireOwnershipWithUnpublishedAttribute()
  415. {
  416. // republish ObjectRoot.A.B, but with different set, essentially unpublishing some atts
  417. secondFederate->quickPublish( "ObjectRoot.A.B", 4, "aa", "ab", "ac", "ba" );
  418. try
  419. {
  420. this->ahs = secondFederate->populatedAHS( 3, ba, bb, bc );
  421. secondFederate->rtiamb->attributeOwnershipAcquisition( theObject, *ahs, this->tag );
  422. failTestMissingException( "AttributeNotPublished",
  423. "requesting attribute ownership with unpublished attribute" );
  424. }
  425. catch( RTI::AttributeNotPublished& anp )
  426. {
  427. // success!
  428. }
  429. catch( RTI::Exception& e )
  430. {
  431. failTestWrongException( "AttributeNotPublished",
  432. e,
  433. "requesting attribute ownership with unpublished attribute" );
  434. }
  435. }
  436. //////////////////////////////////////////////////////
  437. // TEST: testAcquireOwnershipWithUnpublishedClass() //
  438. //////////////////////////////////////////////////////
  439. void AcquireOwnershipTest::testAcquireOwnershipWithUnpublishedClass()
  440. {
  441. // unpublish ObjectRoot.A.B
  442. secondFederate->quickUnpublishOC( "ObjectRoot.A.B" );
  443. try
  444. {
  445. this->ahs = secondFederate->populatedAHS( 3, ba, bb, bc );
  446. secondFederate->rtiamb->attributeOwnershipAcquisition( theObject, *ahs, this->tag );
  447. failTestMissingException( "ObjectClassNotPublished",
  448. "requesting attribute ownership with unpublished class" );
  449. }
  450. catch( RTI::ObjectClassNotPublished& ocnp )
  451. {
  452. // success!
  453. }
  454. catch( RTI::Exception& e )
  455. {
  456. failTestWrongException( "ObjectClassNotPublished",
  457. e,
  458. "requesting attribute ownership with unpublished class" );
  459. }
  460. }
  461. ///////////////////////////////////////////////////////////
  462. // TEST: testAcquireOwnershipWithAlreadyOwnedAttribute() //
  463. ///////////////////////////////////////////////////////////
  464. void AcquireOwnershipTest::testAcquireOwnershipWithAlreadyOwnedAttribute()
  465. {
  466. // acquire the unowned attributes
  467. secondFederate->quickAcquireIfAvailableRequest( theObject, 3, ba, bb, bc );
  468. secondFederate->fedamb->waitForOwnershipAcquistion( theObject, 3, ba, bb, bc );
  469. // try and re-acquire the atts we now own
  470. try
  471. {
  472. this->ahs = secondFederate->populatedAHS( 3, ba, bb, bc );
  473. secondFederate->rtiamb->attributeOwnershipAcquisition( theObject, *ahs, this->tag );
  474. failTestMissingException( "FederateOwnsAttributes",
  475. "requesting attribute ownership with attributes we already own" );
  476. }
  477. catch( RTI::FederateOwnsAttributes& foa )
  478. {
  479. // success!
  480. }
  481. catch( RTI::Exception& e )
  482. {
  483. failTestWrongException( "FederateOwnsAttributes",
  484. e,
  485. "requesting attribute ownership with attributes we already own" );
  486. }
  487. }
  488. ///////////////////////////////////////////////
  489. // TEST: testAcquireOwnershipWhenNotJoined() //
  490. ///////////////////////////////////////////////
  491. void AcquireOwnershipTest::testAcquireOwnershipWhenNotJoined()
  492. {
  493. secondFederate->quickResign();
  494. try
  495. {
  496. this->ahs = secondFederate->populatedAHS( 3, ba, bb, bc );
  497. secondFederate->rtiamb->attributeOwnershipAcquisition( theObject, *ahs, this->tag );
  498. failTestMissingException( "FederateNotExecutionMember",
  499. "requesting attribute ownership when not joined" );
  500. }
  501. catch( RTI::FederateNotExecutionMember& fnem )
  502. {
  503. // success!
  504. }
  505. catch( RTI::Exception& e )
  506. {
  507. failTestWrongException( "FederateNotExecutionMember",
  508. e,
  509. "requesting attribute ownership when not joined" );
  510. }
  511. }
  512. /////////////////////////////////////////////////////////////////////////////////////////////
  513. /////////////////////////////// Release Response Test Methods ///////////////////////////////
  514. /////////////////////////////////////////////////////////////////////////////////////////////
  515. // AttributeHandleSet* attributeOwnershipReleaseResponse( // returned C6
  516. // ObjectHandle theObject, // supplied C1
  517. // const AttributeHandleSet& theAttributes ) // supplied C4
  518. // throw ( ObjectNotKnown,
  519. // AttributeNotDefined,
  520. // AttributeNotOwned,
  521. // FederateWasNotAskedToReleaseAttribute,
  522. // FederateNotExecutionMember,
  523. // ConcurrentAccessAttempted,
  524. // SaveInProgress,
  525. // RestoreInProgress,
  526. // RTIinternalError );
  527. ///////////////////////////////////////////////////////
  528. // TEST: (valid) testAcquireOwnershipWhenNotJoined() //
  529. ///////////////////////////////////////////////////////
  530. void AcquireOwnershipTest::testReleaseResponse()
  531. {
  532. // request the release of attributes owned by the default federate
  533. secondFederate->quickAcquireRequest( theObject, 3, aa, ab, ac );
  534. defaultFederate->fedamb->waitForOwnershipRequest( theObject, 3, aa, ab, ac );
  535. // respond with a release response
  536. try
  537. {
  538. this->ahs = secondFederate->populatedAHS( 3, aa, ab, ac );
  539. defaultFederate->rtiamb->attributeOwnershipReleaseResponse( theObject, *ahs );
  540. }
  541. catch( RTI::Exception& e )
  542. {
  543. failTest( "Unexpected exception while releasing attributes via a release response: %s",
  544. e._reason );
  545. }
  546. // wait for them to be picked up in the second federate
  547. secondFederate->fedamb->waitForOwnershipAcquistion( theObject, 3, aa, ab, ac );
  548. secondFederate->quickAssertOwnedBy( secondFederate->getFederateHandle(), theObject, 3, aa, ab, ac );
  549. // give the default federate some time to process callbacks before checking ownership
  550. defaultFederate->quickTick( 0.1, 1.0 );
  551. defaultFederate->quickAssertOwnedBy( secondFederate->getFederateHandle(), theObject, 3, aa, ab, ac );
  552. }
  553. //////////////////////////////////////////////////
  554. // TEST: testReleaseResponseWithUnknownObject() //
  555. //////////////////////////////////////////////////
  556. void AcquireOwnershipTest::testReleaseResponseWithUnknownObject()
  557. {
  558. // register an object in the second federate that is not discovered by the first, and
  559. // thus is unknown to it
  560. RTI::ObjectHandle secondObject = secondFederate->quickRegister( "ObjectRoot.A.B" );
  561. try
  562. {
  563. this->ahs = defaultFederate->populatedAHS( 3, aa, ab, ac );
  564. defaultFederate->rtiamb->attributeOwnershipReleaseResponse( secondObject, *ahs );
  565. failTestMissingException( "ObjectNotKnown",
  566. "calling attribute release response with undiscovered object" );
  567. }
  568. catch( RTI::ObjectNotKnown& onk )
  569. {
  570. // success!
  571. }
  572. catch( RTI::Exception& e )
  573. {
  574. failTestWrongException( "ObjectNotKnown", e,
  575. "calling attribute release response with undiscovered object" );
  576. }
  577. }
  578. //////////////////////////////////////////////////
  579. // TEST: testReleaseResponseWithInvalidObject() //
  580. //////////////////////////////////////////////////
  581. void AcquireOwnershipTest::testReleaseResponseWithInvalidObject()
  582. {
  583. try
  584. {
  585. this->ahs = defaultFederate->populatedAHS( 3, aa, ab, ac );
  586. defaultFederate->rtiamb->attributeOwnershipReleaseResponse( 1000000, *ahs );
  587. failTestMissingException( "ObjectNotKnown",
  588. "calling attribute release response with invalid object handle" );
  589. }
  590. catch( RTI::ObjectNotKnown& onk )
  591. {
  592. // success!
  593. }
  594. catch( RTI::Exception& e )
  595. {
  596. failTestWrongException( "ObjectNotKnown", e,
  597. "calling attribute release response with invalid object handle" );
  598. }
  599. }
  600. /////////////////////////////////////////////////////
  601. // TEST: testReleaseResponseWithInvalidAttribute() //
  602. /////////////////////////////////////////////////////
  603. void AcquireOwnershipTest::testReleaseResponseWithInvalidAttribute()
  604. {
  605. try
  606. {
  607. this->ahs = defaultFederate->populatedAHS( 1, 100000 );
  608. defaultFederate->rtiamb->attributeOwnershipReleaseResponse( theObject, *ahs );
  609. failTestMissingException( "AttributeNotDefined",
  610. "calling attribute release response with undefined attribute" );
  611. }
  612. catch( RTI::AttributeNotDefined& anotd )
  613. {
  614. // success!
  615. }
  616. catch( RTI::Exception& e )
  617. {
  618. failTestWrongException( "AttributeNotDefined", e,
  619. "calling attribute release response with undefined attribute" );
  620. }
  621. }
  622. /////////////////////////////////////////////////////
  623. // TEST: testReleaseResponseWithUnownedAttribute() //
  624. /////////////////////////////////////////////////////
  625. void AcquireOwnershipTest::testReleaseResponseWithUnownedAttribute()
  626. {
  627. // create a second object, owned by the second federate so that we can play with it
  628. // we can't just use an attribute we don't publish (and thus don't own) because that'll
  629. // throw an AttributeNotPublished rather than the AttributeNotOwned we want
  630. RTI::ObjectHandle secondObject = secondFederate->quickRegister( "ObjectRoot.A.B" );
  631. defaultFederate->quickSubscribe( "ObjectRoot.A.B", 3, "aa", "ab", "ac" );
  632. defaultFederate->fedamb->waitForDiscovery( secondObject );
  633. try
  634. {
  635. this->ahs = defaultFederate->populatedAHS( 1, aa );
  636. defaultFederate->rtiamb->attributeOwnershipReleaseResponse( secondObject, *ahs );
  637. failTestMissingException( "AttributeNotOwned",
  638. "calling attribute release response with unowned attribute" );
  639. }
  640. catch( RTI::AttributeNotOwned& ano )
  641. {
  642. // success!
  643. }
  644. catch( RTI::Exception& e )
  645. {
  646. failTestWrongException( "AttributeNotOwned", e,
  647. "calling attribute release response with unowned attribute" );
  648. }
  649. }
  650. //////////////////////////////////////////////////////
  651. // TEST: testReleaseResponseWhenNotAskedToRelease() //
  652. //////////////////////////////////////////////////////
  653. void AcquireOwnershipTest::testReleaseResponseWhenNotAskedToRelease()
  654. {
  655. try
  656. {
  657. this->ahs = defaultFederate->populatedAHS( 3, aa, ab, ac );
  658. defaultFederate->rtiamb->attributeOwnershipReleaseResponse( theObject, *ahs );
  659. failTestMissingException( "FederateWasNotAskedToReleaseAttribute",
  660. "calling attribute release response with no outstanding request" );
  661. }
  662. catch( RTI::FederateWasNotAskedToReleaseAttribute& fwnatra )
  663. {
  664. // success!
  665. }
  666. catch( RTI::Exception& e )
  667. {
  668. failTestWrongException( "FederateWasNotAskedToReleaseAttribute", e,
  669. "calling attribute release response with no outstanding request" );
  670. }
  671. }
  672. //////////////////////////////////////////////
  673. // TEST: testReleaseResponseWhenNotJoined() //
  674. //////////////////////////////////////////////
  675. void AcquireOwnershipTest::testReleaseResponseWhenNotJoined()
  676. {
  677. defaultFederate->quickResign();
  678. try
  679. {
  680. this->ahs = defaultFederate->populatedAHS( 3, aa, ab, ac );
  681. defaultFederate->rtiamb->attributeOwnershipReleaseResponse( theObject, *ahs );
  682. failTestMissingException( "FederateNotExecutionMember",
  683. "calling attribute release response when not joined" );
  684. }
  685. catch( RTI::FederateNotExecutionMember& fnem )
  686. {
  687. // success!
  688. }
  689. catch( RTI::Exception& e )
  690. {
  691. failTestWrongException( "FederateNotExecutionMember", e,
  692. "calling attribute release response when not joined" );
  693. }
  694. }
  695. /////////////////////////////////////////////////////////////////////////////////////////////
  696. ////////////////////////////// Cancel Acquisition Test Methods //////////////////////////////
  697. /////////////////////////////////////////////////////////////////////////////////////////////
  698. // void cancelAttributeOwnershipAcquisition( ObjectHandle theObject, // supplied C1
  699. // const AttributeHandleSet& attributes ) // supplied C4
  700. // throw ( ObjectNotKnown,
  701. // AttributeNotDefined,
  702. // AttributeAlreadyOwned,
  703. // AttributeAcquisitionWasNotRequested,
  704. // FederateNotExecutionMember,
  705. // ConcurrentAccessAttempted,
  706. // SaveInProgress,
  707. // RestoreInProgress,
  708. // RTIinternalError );
  709. ////////////////////////////////////////////////////
  710. // TEST: (valid) testCancelOwnershipAcquisition() //
  711. ////////////////////////////////////////////////////
  712. void AcquireOwnershipTest::testCancelOwnershipAcquisition()
  713. {
  714. // request a transfer
  715. secondFederate->quickAcquireRequest( theObject, 3, aa, ab, ac );
  716. defaultFederate->fedamb->waitForOwnershipRequest( theObject, 3, aa, ab, ac );
  717. // cancel the transfer
  718. try
  719. {
  720. this->ahs = secondFederate->populatedAHS( 3, aa, ab, ac );
  721. secondFederate->rtiamb->cancelAttributeOwnershipAcquisition( theObject, *ahs );
  722. }
  723. catch( RTI::Exception& e )
  724. {
  725. failTest( "Unexpected exception while cancelling attribute ownership acquisition: %s",
  726. e._reason );
  727. }
  728. secondFederate->fedamb->waitForOwnershipCancelConfirmation( theObject, 3, aa, ab, ac );
  729. }
  730. /////////////////////////////////////////////////////////////
  731. // TEST: testCancelOwnershipAcquisitionWithInvalidObject() //
  732. /////////////////////////////////////////////////////////////
  733. void AcquireOwnershipTest::testCancelOwnershipAcquisitionWithInvalidObject()
  734. {
  735. try
  736. {
  737. this->ahs = secondFederate->populatedAHS( 3, aa, ab, ac );
  738. secondFederate->rtiamb->cancelAttributeOwnershipAcquisition( 1000000, *ahs );
  739. failTestMissingException( "ObjectNotKnown",
  740. "cancelling attribute acquisition with invalid object handle" );
  741. }
  742. catch( RTI::ObjectNotKnown& onk )
  743. {
  744. // success!
  745. }
  746. catch( RTI::Exception& e )
  747. {
  748. failTestWrongException( "ObjectNotKnown", e,
  749. "cancelling attribute acquisition with invalid object handle" );
  750. }
  751. }
  752. /////////////////////////////////////////////////////////////
  753. // TEST: testCancelOwnershipAcquisitionWithUnknownObject() //
  754. /////////////////////////////////////////////////////////////
  755. void AcquireOwnershipTest::testCancelOwnershipAcquisitionWithUnknownObject()
  756. {
  757. int secondObject = defaultFederate->quickRegister( "ObjectRoot.A.B" );
  758. try
  759. {
  760. this->ahs = secondFederate->populatedAHS( 3, aa, ab, ac );
  761. secondFederate->rtiamb->cancelAttributeOwnershipAcquisition( secondObject, *ahs );
  762. failTestMissingException( "ObjectNotKnown",
  763. "cancelling attribute acquisition with unknown object handle" );
  764. }
  765. catch( RTI::ObjectNotKnown& onk )
  766. {
  767. // success!
  768. }
  769. catch( RTI::Exception& e )
  770. {
  771. failTestWrongException( "ObjectNotKnown", e,
  772. "cancelling attribute acquisition with unknown object handle" );
  773. }
  774. }
  775. ////////////////////////////////////////////////////////////////
  776. // TEST: testCancelOwnershipAcquisitionWithInvalidAttribute() //
  777. ////////////////////////////////////////////////////////////////
  778. void AcquireOwnershipTest::testCancelOwnershipAcquisitionWithInvalidAttribute()
  779. {
  780. try
  781. {
  782. this->ahs = secondFederate->populatedAHS( 1, 100000 );
  783. secondFederate->rtiamb->cancelAttributeOwnershipAcquisition( theObject, *ahs );
  784. failTestMissingException( "AttributeNotDefined",
  785. "cancelling attribute acquisition with undefined attribute" );
  786. }
  787. catch( RTI::AttributeNotDefined& anotd )
  788. {
  789. // success!
  790. }
  791. catch( RTI::Exception& e )
  792. {
  793. failTestWrongException( "AttributeNotDefined", e,
  794. "cancelling attribute acquisition with undefined attribute" );
  795. }
  796. }
  797. //////////////////////////////////////////////////////////////////////////////
  798. // TEST: testCancelOwnershipAcquisitionWithOwnershipWhereAcquiredFinished() //
  799. //////////////////////////////////////////////////////////////////////////////
  800. void AcquireOwnershipTest::testCancelOwnershipAcquisitionWithOwnershipWhereAcquiredFinished()
  801. {
  802. secondFederate->quickAcquireRequest( theObject, 3, aa, ab, ac );
  803. defaultFederate->fedamb->waitForOwnershipRequest( theObject, 3, aa, ab, ac );
  804. defaultFederate->quickReleaseResponse( theObject, 3, aa, ab, ac );
  805. try
  806. {
  807. this->ahs = secondFederate->populatedAHS( 3, aa, ab, ac );
  808. secondFederate->rtiamb->cancelAttributeOwnershipAcquisition( theObject, *ahs );
  809. failTestMissingException( "AttributeAlreadyOwned",
  810. "cancelling attribute acquisition with completed transfer" );
  811. }
  812. catch( RTI::AttributeAlreadyOwned& aao )
  813. {
  814. // success!
  815. }
  816. catch( RTI::Exception& e )
  817. {
  818. failTestWrongException( "AttributeAlreadyOwned", e,
  819. "cancelling attribute acquisition with completed transfer" );
  820. }
  821. }
  822. /////////////////////////////////////////////////////////////////////
  823. // TEST: testCancelOwnershipAcquisitionWithUnrequestedAttributes() //
  824. /////////////////////////////////////////////////////////////////////
  825. void AcquireOwnershipTest::testCancelOwnershipAcquisitionWithUnrequestedAttributes()
  826. {
  827. try
  828. {
  829. this->ahs = secondFederate->populatedAHS( 3, aa, ab, ac );
  830. secondFederate->rtiamb->cancelAttributeOwnershipAcquisition( theObject, *ahs );
  831. failTestMissingException( "AttributeAcquisitionWasNotRequested",
  832. "cancelling attribute acquisition for unrequested attributes" );
  833. }
  834. catch( RTI::AttributeAcquisitionWasNotRequested& aao )
  835. {
  836. // success!
  837. }
  838. catch( RTI::Exception& e )
  839. {
  840. failTestWrongException( "AttributeAcquisitionWasNotRequested", e,
  841. "cancelling attribute acquisition for unrequested attributes" );
  842. }
  843. }
  844. /////////////////////////////////////////////////////////
  845. // TEST: testCancelOwnershipAcquisitionWhenNotJoined() //
  846. /////////////////////////////////////////////////////////
  847. void AcquireOwnershipTest::testCancelOwnershipAcquisitionWhenNotJoined()
  848. {
  849. secondFederate->quickResign();
  850. try
  851. {
  852. this->ahs = secondFederate->populatedAHS( 3, aa, ab, ac );
  853. secondFederate->rtiamb->cancelAttributeOwnershipAcquisition( theObject, *ahs );
  854. failTestMissingException( "FederateNotExecutionMember",
  855. "cancelling attribute acquisition when not joined" );
  856. }
  857. catch( RTI::FederateNotExecutionMember& fnem )
  858. {
  859. // success!
  860. }
  861. catch( RTI::Exception& e )
  862. {
  863. failTestWrongException( "FederateNotExecutionMember", e,
  864. "cancelling attribute acquisition when not joined" );
  865. }
  866. }