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

https://github.com/graeme-muller/portico · C++ · 272 lines · 165 code · 28 blank · 79 comment · 0 complexity · 0379441f93ba9cfe64bb3ff3c52bf9dc 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 "QueryAttributeOwnershipTest.h"
  16. // Register test suite with the global repository
  17. CPPUNIT_TEST_SUITE_REGISTRATION( QueryAttributeOwnershipTest );
  18. CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( QueryAttributeOwnershipTest, "QueryAttributeOwnershipTest" );
  19. CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( QueryAttributeOwnershipTest, "ownershipManagement" );
  20. /////////////////////////////////////////////////////////////////////////////////////////////
  21. ////////////////////////////////// Constructors/Destructors /////////////////////////////////
  22. /////////////////////////////////////////////////////////////////////////////////////////////
  23. QueryAttributeOwnershipTest::QueryAttributeOwnershipTest()
  24. {
  25. this->defaultFederate = new TestNG6Federate( "defaultFederate" );
  26. this->secondFederate = new TestNG6Federate( "secondFederate" );
  27. }
  28. QueryAttributeOwnershipTest::~QueryAttributeOwnershipTest()
  29. {
  30. delete this->defaultFederate;
  31. delete this->secondFederate;
  32. }
  33. /////////////////////////////////////////////////////////////////////////////////////////////
  34. /////////////////////////////// Test Setup and Helper Methods ///////////////////////////////
  35. /////////////////////////////////////////////////////////////////////////////////////////////
  36. void QueryAttributeOwnershipTest::setUp()
  37. {
  38. this->defaultFederate->quickCreate();
  39. this->defaultFederate->quickJoin();
  40. this->secondFederate->quickJoin();
  41. // cache some handle information
  42. this->aa = defaultFederate->quickACHandle( "ObjectRoot.A", "aa" );
  43. this->ab = defaultFederate->quickACHandle( "ObjectRoot.A", "ab" );
  44. this->ac = defaultFederate->quickACHandle( "ObjectRoot.A", "ac" );
  45. this->ba = defaultFederate->quickACHandle( "ObjectRoot.A.B", "ba" );
  46. this->bb = defaultFederate->quickACHandle( "ObjectRoot.A.B", "bb" );
  47. this->bc = defaultFederate->quickACHandle( "ObjectRoot.A.B", "bc" );
  48. // publish and subscribe
  49. defaultFederate->quickPublish( "ObjectRoot.A.B", 3, "aa", "ab", "ac" );
  50. secondFederate->quickSubscribe( "ObjectRoot.A.B", 6, "aa", "ab", "ac", "ba", "bb", "bc" );
  51. secondFederate->quickPublish( "ObjectRoot.A.B", 6, "aa", "ab", "ac", "ba", "bb", "bc" );
  52. // register and discover the object
  53. this->theObject = defaultFederate->quickRegister( "ObjectRoot.A.B" );
  54. this->secondFederate->fedamb->waitForDiscovery( theObject );
  55. }
  56. void QueryAttributeOwnershipTest::tearDown()
  57. {
  58. this->secondFederate->quickResign();
  59. this->defaultFederate->quickResign();
  60. this->defaultFederate->quickDestroy();
  61. }
  62. /////////////////////////////////////////////////////////////////////////////////////////////
  63. /////////////////////////// Query Attribute Ownership Test Methods //////////////////////////
  64. /////////////////////////////////////////////////////////////////////////////////////////////
  65. // void queryAttributeOwnership( ObjectHandle theObject, // supplied C1
  66. // AttributeHandle theAttribute ) // supplied C1
  67. // throw ( ObjectNotKnown,
  68. // AttributeNotDefined,
  69. // FederateNotExecutionMember,
  70. // ConcurrentAccessAttempted,
  71. // SaveInProgress,
  72. // RestoreInProgress,
  73. // RTIinternalError );
  74. ////////////////////////////////////////////////////////////////////////
  75. // TEST: (valid) testQueryAttributeOwnershipAfterObjectRegistration() //
  76. ////////////////////////////////////////////////////////////////////////
  77. void QueryAttributeOwnershipTest::testQueryAttributeOwnershipAfterObjectRegistration()
  78. {
  79. // check ownership as it current stands
  80. // should be: defaultFederate=>{aa,ab,ac}, unowned=>{ba,bb,bc}
  81. int defaultHandle = defaultFederate->getFederateHandle();
  82. int secondHandle = secondFederate->getFederateHandle();
  83. defaultFederate->quickAssertOwnedBy( defaultHandle, theObject, 3, aa, ab, ac );
  84. defaultFederate->quickAssertOwnedBy( TestNG6Federate::OWNER_UNOWNED, theObject, 3, ba, bb, bc );
  85. secondFederate->quickAssertOwnedBy( defaultHandle, theObject, 3, aa, ab, ac );
  86. secondFederate->quickAssertOwnedBy( TestNG6Federate::OWNER_UNOWNED, theObject, 3, ba, bb, bc );
  87. // pick up some attributes in the second federate
  88. // should be: defaultFederate=>{aa,ab,ac}, secondFederate=>{ba,bb,bc}
  89. secondFederate->quickAcquireIfAvailableRequest( theObject, 3, ba, bb, bc );
  90. defaultFederate->quickTick( 0.1, 1.0 );
  91. defaultFederate->quickAssertOwnedBy( defaultHandle, theObject, 3, aa, ab, ac );
  92. defaultFederate->quickAssertOwnedBy( secondHandle, theObject, 3, ba, bb, bc );
  93. secondFederate->quickTick( 0.1, 1.0 );
  94. secondFederate->quickAssertOwnedBy( defaultHandle, theObject, 3, aa, ab, ac );
  95. secondFederate->quickAssertOwnedBy( secondHandle, theObject, 3, ba, bb, bc );
  96. }
  97. ///////////////////////////////////////////////////////////////////////
  98. // TEST: (valid) testQueryAttributeOwnershipAfterOwnershipTransfer() //
  99. ///////////////////////////////////////////////////////////////////////
  100. void QueryAttributeOwnershipTest::testQueryAttributeOwnershipAfterOwnershipTransfer()
  101. {
  102. // check ownership as it current stands
  103. // should be: defaultFederate=>{aa,ab,ac}, unowned=>{ba,bb,bc}
  104. int defaultHandle = defaultFederate->getFederateHandle();
  105. int secondHandle = secondFederate->getFederateHandle();
  106. defaultFederate->quickAssertOwnedBy( defaultHandle, theObject, 3, aa, ab, ac );
  107. defaultFederate->quickAssertOwnedBy( TestNG6Federate::OWNER_UNOWNED, theObject, 3, ba, bb, bc );
  108. secondFederate->quickAssertOwnedBy( defaultHandle, theObject, 3, aa, ab, ac );
  109. secondFederate->quickAssertOwnedBy( TestNG6Federate::OWNER_UNOWNED, theObject, 3, ba, bb, bc );
  110. // transfer aa and ab from defaultFederate to secondFederate
  111. secondFederate->quickAcquireRequest( theObject, 2, aa, ab );
  112. defaultFederate->fedamb->waitForOwnershipRequest( theObject, 2, aa, ab );
  113. defaultFederate->quickReleaseResponse( theObject, 2, aa, ab );
  114. secondFederate->fedamb->waitForOwnershipAcquistion( theObject, 2, aa, ab );
  115. // check to make sure new ownership is good
  116. defaultFederate->quickAssertOwnedBy( defaultHandle, theObject, 1, ac );
  117. defaultFederate->quickAssertOwnedBy( secondHandle, theObject, 2, aa, ab );
  118. defaultFederate->quickAssertOwnedBy( TestNG6Federate::OWNER_UNOWNED, theObject, 3, ba, bb, bc );
  119. secondFederate->quickAssertOwnedBy( defaultHandle, theObject, 1, ac );
  120. secondFederate->quickAssertOwnedBy( secondHandle, theObject, 2, aa, ab );
  121. secondFederate->quickAssertOwnedBy( TestNG6Federate::OWNER_UNOWNED, theObject, 3, ba, bb, bc );
  122. }
  123. /////////////////////////////////////////////////////////////////
  124. // TEST: (valid) testQueryAttributeOwnershipForMomAttributes() //
  125. /////////////////////////////////////////////////////////////////
  126. void QueryAttributeOwnershipTest::testQueryAttributeOwnershipForMomAttributes()
  127. {
  128. // get the handle for a mom attribute
  129. RTI::AttributeHandle federationNameHandle =
  130. defaultFederate->quickACHandle( "Manager.Federation", "FederationName" );
  131. // subscribe to a MOM class and wait for discovery
  132. defaultFederate->quickSubscribe( "Manager.Federation", 1, "FederationName" );
  133. defaultFederate->fedamb->waitForDiscovery( 0 /*mom federation object*/ );
  134. // check ownership of a MOM attribute
  135. defaultFederate->quickAssertOwnedBy( TestNG6Federate::OWNER_RTI,
  136. 0 /*mom federation object*/,
  137. 1,
  138. federationNameHandle );
  139. }
  140. //////////////////////////////////////////////////////////
  141. // TEST: testQueryAttributeOwnershipWithInvalidObject() //
  142. //////////////////////////////////////////////////////////
  143. void QueryAttributeOwnershipTest::testQueryAttributeOwnershipWithInvalidObject()
  144. {
  145. try
  146. {
  147. defaultFederate->rtiamb->queryAttributeOwnership( 100000, aa );
  148. failTestMissingException( "ObjectNotKnown", "query ownership with invalid object" );
  149. }
  150. catch( RTI::ObjectNotKnown& onk )
  151. {
  152. // success!
  153. }
  154. catch( RTI::Exception &e )
  155. {
  156. failTestWrongException( "ObjectNotKnown", e, "query ownership with invalid object" );
  157. }
  158. }
  159. //////////////////////////////////////////////////////////
  160. // TEST: testQueryAttributeOwnershipWithUnknownObject() //
  161. //////////////////////////////////////////////////////////
  162. void QueryAttributeOwnershipTest::testQueryAttributeOwnershipWithUnknownObject()
  163. {
  164. // register an object in the second federate, so we have a handle that is valid in the
  165. // federation, but don't have it discovered in the default federate, making it unknown
  166. RTI::ObjectHandle secondObject = secondFederate->quickRegister( "ObjectRoot.A.B" );
  167. try
  168. {
  169. defaultFederate->rtiamb->queryAttributeOwnership( secondObject, aa );
  170. failTestMissingException( "ObjectNotKnown", "query ownership with unknown object" );
  171. }
  172. catch( RTI::ObjectNotKnown& onk )
  173. {
  174. // success!
  175. }
  176. catch( RTI::Exception &e )
  177. {
  178. failTestWrongException( "ObjectNotKnown", e, "query ownership with unknown object" );
  179. }
  180. }
  181. ///////////////////////////////////////////////////////////////////
  182. // TEST: testQueryAttributeOwnershipWithWrongAttributeForClass() //
  183. ///////////////////////////////////////////////////////////////////
  184. void QueryAttributeOwnershipTest::testQueryAttributeOwnershipWithWrongAttributeForClass()
  185. {
  186. // register an object at ObjectRoot.A and then try and get ownership of attribute "ba"
  187. defaultFederate->quickPublish( "ObjectRoot.A", 3, "aa", "ab", "ac" );
  188. RTI::ObjectHandle secondObject = defaultFederate->quickRegister( "ObjectRoot.A" );
  189. try
  190. {
  191. defaultFederate->rtiamb->queryAttributeOwnership( secondObject, ba );
  192. failTestMissingException( "AttributeNotDefined",
  193. "query ownership with wrong attribute for class" );
  194. }
  195. catch( RTI::AttributeNotDefined& andef )
  196. {
  197. // success!
  198. }
  199. catch( RTI::Exception &e )
  200. {
  201. failTestWrongException( "AttributeNotDefined", e,
  202. "query ownership with wrong attribute for class" );
  203. }
  204. }
  205. /////////////////////////////////////////////////////////////
  206. // TEST: testQueryAttributeOwnershipWithInvalidAttribute() //
  207. /////////////////////////////////////////////////////////////
  208. void QueryAttributeOwnershipTest::testQueryAttributeOwnershipWithInvalidAttribute()
  209. {
  210. try
  211. {
  212. defaultFederate->rtiamb->queryAttributeOwnership( theObject, 10000 );
  213. failTestMissingException( "AttributeNotDefined", "query ownership with invalid attribute" );
  214. }
  215. catch( RTI::AttributeNotDefined& andef )
  216. {
  217. // success!
  218. }
  219. catch( RTI::Exception &e )
  220. {
  221. failTestWrongException( "AttributeNotDefined", e,
  222. "query ownership with wrong invalid attribute" );
  223. }
  224. }
  225. //////////////////////////////////////////////////////
  226. // TEST: testQueryAttributeOwnershipWhenNotJoined() //
  227. //////////////////////////////////////////////////////
  228. void QueryAttributeOwnershipTest::testQueryAttributeOwnershipWhenNotJoined()
  229. {
  230. defaultFederate->quickResign();
  231. try
  232. {
  233. defaultFederate->rtiamb->queryAttributeOwnership( theObject, aa );
  234. failTestMissingException( "FederateNotExecutionMember", "query ownership when not joined" );
  235. }
  236. catch( RTI::FederateNotExecutionMember& fnem )
  237. {
  238. // success!
  239. }
  240. catch( RTI::Exception &e )
  241. {
  242. failTestWrongException( "FederateNotExecutionMember", e, "query ownership when not joined" );
  243. }
  244. }