/codebase/src-cpp/test/ng6/ddm/DDMSupportServicesTest.cpp

https://github.com/graeme-muller/portico · C++ · 238 lines · 106 code · 32 blank · 100 comment · 2 complexity · b57e514f821f31faa27e2831b6c85384 MD5 · raw file

  1. /*
  2. * Copyright 2008 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 "DDMSupportServicesTest.h"
  16. // Register test suite with the global repository
  17. CPPUNIT_TEST_SUITE_REGISTRATION( DDMSupportServicesTest );
  18. CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( DDMSupportServicesTest, "DDMSupportServicesTest" );
  19. CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( DDMSupportServicesTest, "ddm" );
  20. CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( DDMSupportServicesTest, "supportServices" );
  21. /////////////////////////////////////////////////////////////////////////////////////////////
  22. ////////////////////////////////// Constructors/Destructors /////////////////////////////////
  23. /////////////////////////////////////////////////////////////////////////////////////////////
  24. DDMSupportServicesTest::DDMSupportServicesTest()
  25. {
  26. this->defaultFederate = new TestNG6Federate( "defaultFederate" );
  27. }
  28. DDMSupportServicesTest::~DDMSupportServicesTest()
  29. {
  30. delete this->defaultFederate;
  31. }
  32. /////////////////////////////////////////////////////////////////////////////////////////////
  33. /////////////////////////////// Test Setup and Helper Methods ///////////////////////////////
  34. /////////////////////////////////////////////////////////////////////////////////////////////
  35. void DDMSupportServicesTest::setUp()
  36. {
  37. this->defaultFederate->quickCreate();
  38. this->defaultFederate->quickJoin();
  39. }
  40. void DDMSupportServicesTest::tearDown()
  41. {
  42. this->defaultFederate->quickResign();
  43. this->defaultFederate->quickDestroy();
  44. }
  45. ////////////////////////////////////////////////////////////////////////////////////////////
  46. /////////////////////////////////////// Test Methods ///////////////////////////////////////
  47. ////////////////////////////////////////////////////////////////////////////////////////////
  48. ///////////////////////////////////
  49. // TEST: (valid) testGetRegion() //
  50. ///////////////////////////////////
  51. // RTI::Region* getRegion( RTI::RegionToken token )
  52. // throw( RTI::FederateNotExecutionMember,
  53. // RTI::ConcurrentAccessAttempted,
  54. // RTI::RegionNotKnown,
  55. // RTI::RTIinternalError )
  56. void DDMSupportServicesTest::testGetRegion()
  57. {
  58. // register a region
  59. RTI::Region *region = defaultFederate->quickCreateTestRegion( 100, 150 );
  60. RTI::RegionToken token = defaultFederate->quickGetRegionToken( region );
  61. RTI::Region *otherRegion = NULL;
  62. // get the region for the token and make sure they are the same
  63. try
  64. {
  65. otherRegion = defaultFederate->rtiamb->getRegion( token );
  66. }
  67. catch( RTI::Exception &e )
  68. {
  69. delete region;
  70. failTest( "Fetching region for valid token: %s", e._reason );
  71. }
  72. if( otherRegion == NULL )
  73. {
  74. delete region;
  75. failTest( "Failed to fetch region, null found" );
  76. }
  77. // make sure the values are the same
  78. CPPUNIT_ASSERT_EQUAL( region->getSpaceHandle(), otherRegion->getSpaceHandle() );
  79. CPPUNIT_ASSERT_EQUAL( region->getNumberOfExtents(), otherRegion->getNumberOfExtents() );
  80. delete region;
  81. delete otherRegion;
  82. }
  83. ////////////////////////////////////////
  84. // TEST: (valid) testGetRegionToken() //
  85. ////////////////////////////////////////
  86. // RTI::RegionToken getRegionToken( RTI::Region *theRegion )
  87. // throw( RTI::FederateNotExecutionMember,
  88. // RTI::ConcurrentAccessAttempted,
  89. // RTI::RegionNotKnown,
  90. // RTI::RTIinternalError )
  91. void DDMSupportServicesTest::testGetRegionToken()
  92. {
  93. RTI::Region *region = defaultFederate->quickCreateTestRegion( 100, 150 );
  94. RTI::RegionToken token = defaultFederate->rtiamb->getRegionToken( region );
  95. RTI::Region *other = defaultFederate->rtiamb->getRegion( token );
  96. CPPUNIT_ASSERT_EQUAL( region->getNumberOfExtents(), other->getNumberOfExtents() );
  97. CPPUNIT_ASSERT_EQUAL( region->getSpaceHandle(), other->getSpaceHandle() );
  98. delete other;
  99. delete region;
  100. }
  101. ////////////////////////////////////////////////////////
  102. // TEST: (valid) testGetAttributeRoutingSpaceHandle() //
  103. ////////////////////////////////////////////////////////
  104. // RTI::SpaceHandle
  105. // getAttributeRoutingSpaceHandle( RTI::AttributeHandle theHandle,
  106. // RTI::ObjectClassHandle whichClass )
  107. // throw( RTI::ObjectClassNotDefined,
  108. // RTI::AttributeNotDefined,
  109. // RTI::FederateNotExecutionMember,
  110. // RTI::ConcurrentAccessAttempted,
  111. // RTI::RTIinternalError )
  112. void DDMSupportServicesTest::testGetAttributeRoutingSpaceHandle()
  113. {
  114. RTI::SpaceHandle expected = defaultFederate->quickSpaceHandle( "TestSpace" );
  115. RTI::ObjectClassHandle classHandle = defaultFederate->quickOCHandle( "ObjectRoot.A" );
  116. RTI::AttributeHandle attributeHandle = defaultFederate->quickACHandle( "ObjectRoot.A", "aa" );
  117. RTI::SpaceHandle actual =
  118. defaultFederate->rtiamb->getAttributeRoutingSpaceHandle( attributeHandle, classHandle );
  119. CPPUNIT_ASSERT_EQUAL( expected, actual );
  120. }
  121. ////////////////////////////////////////////
  122. // TEST: (valid) testGetDimensionHandle() //
  123. ////////////////////////////////////////////
  124. // RTI::DimensionHandle
  125. // getDimensionHandle( const char *theName, RTI::SpaceHandle whichSpace )
  126. // throw( RTI::SpaceNotDefined,
  127. // RTI::NameNotFound,
  128. // RTI::FederateNotExecutionMember,
  129. // RTI::ConcurrentAccessAttempted,
  130. // RTI::RTIinternalError )
  131. void DDMSupportServicesTest::testGetDimensionHandle()
  132. {
  133. RTI::SpaceHandle spaceHandle = defaultFederate->quickSpaceHandle( "TestSpace" );
  134. RTI::DimensionHandle dimensionHandle =
  135. defaultFederate->rtiamb->getDimensionHandle( "TestDimension", spaceHandle );
  136. CPPUNIT_ASSERT_EQUAL( (RTI::ULong)(spaceHandle+1), (RTI::ULong)dimensionHandle );
  137. }
  138. //////////////////////////////////////////
  139. // TEST: (valid) testGetDimensionName() //
  140. //////////////////////////////////////////
  141. // char*
  142. // getDimensionName( RTI::DimensionHandle theHandle, RTI::SpaceHandle whichSpace )
  143. // throw( RTI::SpaceNotDefined,
  144. // RTI::DimensionNotDefined,
  145. // RTI::FederateNotExecutionMember,
  146. // RTI::ConcurrentAccessAttempted,
  147. // RTI::RTIinternalError )
  148. void DDMSupportServicesTest::testGetDimensionName()
  149. {
  150. RTI::SpaceHandle spaceHandle = defaultFederate->quickSpaceHandle( "TestSpace" );
  151. RTI::DimensionHandle dimensionHandle =
  152. defaultFederate->quickDimensionHandle( "TestSpace", "TestDimension" );
  153. char *dimensionName = defaultFederate->rtiamb->getDimensionName( dimensionHandle, spaceHandle );
  154. int result = strcmp( "TestDimension", dimensionName );
  155. delete dimensionName;
  156. CPPUNIT_ASSERT_EQUAL( 0, result );
  157. }
  158. //////////////////////////////////////////////////////////
  159. // TEST: (valid) testGetInteractionRoutingSpaceHandle() //
  160. //////////////////////////////////////////////////////////
  161. // RTI::SpaceHandle
  162. // getInteractionRoutingSpaceHandle( RTI::InteractionClassHandle theHandle )
  163. // throw( RTI::InteractionClassNotDefined,
  164. // RTI::FederateNotExecutionMember,
  165. // RTI::ConcurrentAccessAttempted,
  166. // RTI::RTIinternalError )
  167. void DDMSupportServicesTest::testGetInteractionRoutingSpaceHandle()
  168. {
  169. RTI::SpaceHandle expected = defaultFederate->quickSpaceHandle( "TestSpace" );
  170. RTI::ObjectClassHandle classHandle = defaultFederate->quickICHandle( "InteractionRoot.X" );
  171. RTI::SpaceHandle actual = defaultFederate->rtiamb->getInteractionRoutingSpaceHandle( classHandle );
  172. CPPUNIT_ASSERT_EQUAL( expected, actual );
  173. }
  174. ///////////////////////////////////////////////
  175. // TEST: (valid) testGetRoutingSpaceHandle() //
  176. ///////////////////////////////////////////////
  177. // RTI::SpaceHandle getRoutingSpaceHandle( const char *theName )
  178. // throw( RTI::NameNotFound,
  179. // RTI::FederateNotExecutionMember,
  180. // RTI::ConcurrentAccessAttempted,
  181. // RTI::RTIinternalError )
  182. void DDMSupportServicesTest::testGetRoutingSpaceHandle()
  183. {
  184. // not really sure how to test this. just same as getSpaceName() until I figure something out
  185. RTI::SpaceHandle spaceHandle = defaultFederate->quickSpaceHandle( "TestSpace" );
  186. char *spaceName = defaultFederate->rtiamb->getRoutingSpaceName( spaceHandle );
  187. int result = strcmp( "TestSpace", spaceName );
  188. delete spaceName;
  189. CPPUNIT_ASSERT_EQUAL( 0, result );
  190. }
  191. /////////////////////////////////////////////
  192. // TEST: (valid) testGetRoutingSpaceName() //
  193. /////////////////////////////////////////////
  194. // char* getRoutingSpaceName( RTI::SpaceHandle theHandle )
  195. // throw( RTI::SpaceNotDefined,
  196. // RTI::FederateNotExecutionMember,
  197. // RTI::ConcurrentAccessAttempted,
  198. // RTI::RTIinternalError )
  199. void DDMSupportServicesTest::testGetRoutingSpaceName()
  200. {
  201. RTI::SpaceHandle spaceHandle = defaultFederate->quickSpaceHandle( "TestSpace" );
  202. char *spaceName = defaultFederate->rtiamb->getRoutingSpaceName( spaceHandle );
  203. int result = strcmp( "TestSpace", spaceName );
  204. delete spaceName;
  205. CPPUNIT_ASSERT_EQUAL( 0, result );
  206. }