void MulticastSocketTest::testReceiveWhileClosed() { syscommon::InetSocketAddress networkIface( INADDR_ANY, 3033 ); syscommon::InetSocketAddress multicastAddress( TEXT("226.0.1.3"), 3033 ); // Create the socket, and immediately close it syscommon::MulticastSocket receiver( networkIface ); receiver.close(); // Construct the send buffer and packet char receiveBuffer[1024]; syscommon::DatagramPacket receivePacket( receiveBuffer, 1024 ); // Attempting to receive should fail try { receiver.receive( receivePacket ); failTestMissingException( "SocketException", "receiving on a closed socket" ); } catch( syscommon::SocketException& ) { // SUCCESS! } catch( std::exception& e ) { failTestWrongException( "SocketException", e, "receiving on a closed socket" ); } }
//////////////////////////////////////////////////////////// // TEST: testCancelNegotiatedDivestWithUnownedAttribute() // //////////////////////////////////////////////////////////// void DivestOwnershipTest::testCancelNegotiatedDivestWithUnownedAttribute() { // start the transfer off, have it transferred but not confirmed to the default federate, // otherwise we'd get an error saying there was no outstanding request defaultFederate->quickNegotiatedRelease( theObject, 3, aa, ab, ac ); secondFederate->fedamb->waitForOwnershipOffered( theObject, 3, aa, ab, ac ); secondFederate->quickAcquireRequest( theObject, 3, aa, ab, ac ); defaultFederate->quickTick(); secondFederate->fedamb->waitForOwnershipAcquistion( theObject, 3, aa, ab, ac ); try { this->ahs = defaultFederate->populatedAHS( 3, aa, ab, ac ); defaultFederate->rtiamb->cancelNegotiatedAttributeOwnershipDivestiture( theObject, *ahs ); failTestMissingException( "AttributeNotOwned", "cancel negotiated ownership divest after exchange completed" ); } catch( RTI::AttributeNotOwned& ano ) { // success! } catch( RTI::Exception& e ) { failTestWrongException( "AttributeNotOwned", e, "cancel negotiated ownership divest after exchange completed" ); } }
//////////////////////////////////////////////// // TEST: testReflectTSOWithInvalidAttribute() // //////////////////////////////////////////////// void ReflectAttributesTest::testReflectTSOWithInvalidAttribute() { RTI::AttributeHandleValuePairSet *set = defaultFederate->createAHVPS( 2 ); set->add( aaHandle, "aa", 3 ); set->add( 10000000, "na", 3 ); try { RTIfedTime time = 10.0; defaultFederate->rtiamb->updateAttributeValues( theObject, *set, time, "NA" ); delete set; failTestMissingException( "AttributeNotDefined", "updating attributes with invalid attribute" ); } catch( RTI::AttributeNotDefined& attnd ) { // success delete set; } catch( RTI::Exception& e ) { delete set; failTestWrongException( "AttributeNotDefined", e, "updating attributes with invalid attribute" ); } }
///////////////////////////////////////////////////////// // TEST: testAssociateForUpdatedWithInvalidAttribute() // ///////////////////////////////////////////////////////// void AssociateRegionTest::testAssociateForUpdatedWithInvalidAttribute() { // create an ahs with an invalid handle RTI::AttributeHandleSet *ahs = defaultFederate->populatedAHS( 2, aaHandle, 100000000 ); // try and register using the dodgy set try { defaultFederate->rtiamb->associateRegionForUpdates( *senderRegion, theObject, *ahs ); delete ahs; failTestMissingException( "AttributeNotDefined", "associateForUpdates with invalid attribute" ); } catch( RTI::AttributeNotDefined &attnd ) { // success! delete ahs; } catch( RTI::Exception &e ) { delete ahs; failTestWrongException( "AttributeNotDefined", e, "associateForUpdates with invalid attribute" ); } }
//////////////////////////////////////////////////////// // TEST: testSendTSOInteractionWithInvalidParameter() // //////////////////////////////////////////////////////// void SendInteractionTest::testSendTSOInteractionWithInvalidParameter() { RTI::ParameterHandleValuePairSet *params = defaultFederate->createPHVPS( 2 ); params->add( xaHandle, "xa", 3 ); params->add( 10000000, "no", 3 ); try { RTIfedTime theTime = 10.0; defaultFederate->rtiamb->sendInteraction( yHandle, *params, theTime, "NA" ); delete params; failTestMissingException( "InteractionParameterNotDefined", "sending interaction with invalid param handle" ); } catch( RTI::InteractionParameterNotDefined &ipnd ) { // success! delete params; } catch( RTI::Exception &e ) { delete params; failTestWrongException( "InteractionParameterNotDefined", e, "sending interaction with invalid param handle" ); } }
///////////////////////////////////////////////// // TEST: testRODeleteObjectWithInvalidHandle() // ///////////////////////////////////////////////// void DeleteObjectTest::testRODeleteObjectWithInvalidHandle() { try { defaultFederate->rtiamb->deleteObjectInstance( 123, tag ); failTestMissingException( "ObjectNotKnown", "deleteing object that doesn't exist" ); } catch( RTI::ObjectNotKnown& onk ) { // success! } catch( RTI::Exception& e ) { failTestWrongException( "ObjectNotKnown", e, "deleteing object that doesn't exist" ); } }
//////////////////////////////////////////// // TEST: testReflectROWithUnknownObject() // //////////////////////////////////////////// void ReflectAttributesTest::testReflectROWithUnknownObject() { try { defaultFederate->rtiamb->updateAttributeValues( 100000, *ahvps, "NA" ); failTestMissingException( "ObjectNotKnown", "updating attributes for unknown object" ); } catch( RTI::ObjectNotKnown& onk ) { // success! } catch( RTI::Exception& e ) { failTestWrongException( "ObjectNotKnown", e, "updating attributes for unknown object" ); } }
////////////////////////////////////////////////////// // TEST: testAssociateForUpdatesWithUnknownObject() // ////////////////////////////////////////////////////// void AssociateRegionTest::testAssociateForUpdatesWithUnknownObject() { try { defaultFederate->rtiamb->associateRegionForUpdates( *senderRegion, 1000000, *allHandles ); failTestMissingException( "ObjectNotKnown", "associating for updates with unknown object" ); } catch( RTI::ObjectNotKnown &onk ) { // success! } catch( RTI::Exception &e ) { failTestWrongException( "ObjectNotKnown", e, "associating for updates with unknown object" ); } }
//////////////////////////////////////////////////////// // TEST: testUnassociateForUpdatesWithUnknownRegion() // //////////////////////////////////////////////////////// void AssociateRegionTest::testUnassociateForUpdatesWithUnknownRegion() { try { defaultFederate->rtiamb->unassociateRegionForUpdates( *federateARegion, theObject ); failTestMissingException( "RegionNotKnown", "unassociateForUpdates with unknown region" ); } catch( RTI::RegionNotKnown &rnk ) { // success! } catch( RTI::Exception &e ) { failTestWrongException( "RegionNotKnown", e, "unassociateForUpdates with unknown region" ); } }
//////////////////////////////////////////////////////////// // TEST: testRequestFederationSaveWhenRestoreInProgress() // //////////////////////////////////////////////////////////// void FederationSaveTest::testRequestFederationSaveWhenRestoreInProgress() { defaultFederate->quickRestoreInProgress( saveLabel, 2, defaultFederate, secondFederate ); try { defaultFederate->rtiamb->requestFederationSave( saveLabel ); failTestMissingException( "RestoreInProgress", "requesting save while restore in progress" ); } catch( RTI::RestoreInProgress& rip ) { // success } catch( RTI::Exception& e ) { failTestWrongException("RestoreInProgress", e, "requesting save while restore in progress"); } }
///////////////////////////////////////////////////////// // TEST: testRequestFederationSaveWhenSaveInProgress() // ///////////////////////////////////////////////////////// void FederationSaveTest::testRequestFederationSaveWhenSaveInProgress() { defaultFederate->quickSaveInProgress( saveLabel ); try { defaultFederate->rtiamb->requestFederationSave( "otherLabel" ); failTestMissingException( "SaveInProgress", "requesting save while save in progress" ); } catch( RTI::SaveInProgress& sip ) { // success! } catch( RTI::Exception& e ) { failTestWrongException( "SaveInProgress", e, "requesting save while save in progress" ); } }
/////////////////////////////////////////// // TEST: testGetHandleWithInvalidIndex() // /////////////////////////////////////////// void FederateHandleSetTest::testGetHandleWithInvalidIndex() { // Try getHandle on an array index that does not exist try { this->theSet->getHandle( 100 ); failTestMissingException( "ArrayIndexOutOfBounds", "getting handle with invalid index" ); } catch ( RTI::ArrayIndexOutOfBounds& aioob ) { // success } catch ( RTI::Exception& e ) { failTestWrongException( "ArrayIndexOutOfBounds", e, "getting handle with invalid index" ); } }
/////////////////////////////////////////////// // TEST: testTSODeleteObjectWithTimeInPast() // /////////////////////////////////////////////// void DeleteObjectTest::testTSODeleteObjectWithTimeInPast() { try { RTIfedTime theTime = 1.0; defaultFederate->rtiamb->deleteObjectInstance( theObject, theTime, tag ); failTestMissingException( "InvalidFederationTime", "deleteing object in the past" ); } catch( RTI::InvalidFederationTime& ift ) { // success! } catch( RTI::Exception& e ) { failTestWrongException( "InvalidFederationTime", e, "deleteing object in the past" ); } }
//////////////////////////////////////////////// // TEST: testGetValueLengthWithInvalidIndex() // //////////////////////////////////////////////// void AttributeHandleValuePairSetTest::testGetValueLengthWithInvalidIndex() { try { this->theSet->getHandle( 100 ); failTestMissingException( "ArrayIndexOutOfBounds", "getting value length with invalid index" ); } catch ( RTI::ArrayIndexOutOfBounds& aioob ) { // success } catch ( RTI::Exception& e ) { failTestWrongException( "ArrayIndexOutOfBounds", e, "getting value length with invalid index" ); } }
////////////////////////////////////////// // TEST: testGetValueWithInvalidIndex() // ////////////////////////////////////////// void AttributeHandleValuePairSetTest::testGetValueWithInvalidIndex() { try { char tempBuffer[8]; RTI::ULong tempSize; this->theSet->getValue( 100, tempBuffer, tempSize ); failTestMissingException( "ArrayIndexOutOfBounds", "getting value with invalid index" ); } catch ( RTI::ArrayIndexOutOfBounds& aioob ) { // success } catch ( RTI::Exception& e ) { failTestWrongException( "ArrayIndexOutOfBounds", e, "getting value with invalid index" ); } }
///////////////////////////////////////////////// // TEST: testGetValuePointerWithInvalidIndex() // ///////////////////////////////////////////////// void AttributeHandleValuePairSetTest::testGetValuePointerWithInvalidIndex() { // Try getValuePointer on an array index that does not exist try { RTI::ULong tempSize; this->theSet->getValuePointer( 100, tempSize ); failTestMissingException( "ArrayIndexOutOfBounds", "getValuePointer() with invalid index" ); } catch ( RTI::ArrayIndexOutOfBounds& aioob ) { // success } catch ( RTI::Exception& e ) { failTestWrongException( "ArrayIndexOutOfBounds", e, "getValuePointer() with invalid index" ); } }
/////////////////////////////////////////////////////////// // TEST: testSendROInteractionWithRegionThatIsNotValid() // /////////////////////////////////////////////////////////// void SendInteractionWithRegionTest::testSendROInteractionWithRegionThatIsNotValid() { try { defaultFederate->rtiamb->sendInteractionWithRegion( xHandle, *phvps, "NA", *otherRegion ); failTestMissingException( "InvalidRegionContext", "sending interaction with invalid region for interaction class" ); } catch( RTI::InvalidRegionContext &irc ) { // success! } catch( RTI::Exception &e ) { failTestWrongException( "InvalidRegionContext", e, "sending interaction with invalid region for interaction class" ); } }
/////////////////////////////////////////////////// // TEST: testSendROInteractionWhenNotPublished() // /////////////////////////////////////////////////// void SendInteractionTest::testSendROInteractionWhenNotPublished() { try { defaultFederate->rtiamb->sendInteraction( xHandle, *phvps, "NA" ); failTestMissingException( "InteractionClassNotPublished", "sending interaction of class we don't publish" ); } catch( RTI::InteractionClassNotPublished &icnp ) { // success! } catch( RTI::Exception &e ) { failTestWrongException( "InteractionClassNotPublished", e, "sending interaction of class we don't publish" ); } }
void MulticastSocketTest::testIfaceConstructorInvalid() { syscommon::InetSocketAddress networkIface( "meh.mclol", 3033 ); try { syscommon::MulticastSocket mcastSocket( networkIface ); failTestMissingException( "SocketException", "binding a socket to an invalid address" ); } catch( syscommon::SocketException& ) { } catch( std::exception& e ) { failTestWrongException( "SocketException", e, "binding a socket to an invalid address" ); } }
/////////////////////////////////////////////////// // TEST: testFederateSaveCompleteWhenNotJoined() // /////////////////////////////////////////////////// void FederationSaveTest::testFederateSaveCompleteWhenNotJoined() { defaultFederate->quickResign(); try { defaultFederate->rtiamb->federateSaveComplete(); failTestMissingException( "FederateNotExecutionMember","informing federate save complete" ); } catch( RTI::FederateNotExecutionMember& fnem ) { // success! } catch( RTI::Exception& e ) { failTestWrongException( "FederateNotExecutionMember", e, "informing federate save complete" ); } }
//////////////////////////////////////// // TEST: testRODeleteObjectNotOwned() // //////////////////////////////////////// void DeleteObjectTest::testRODeleteObjectNotOwned() { try { listenerFederate->rtiamb->deleteObjectInstance( theObject, tag ); failTestMissingException( "DeletePrivilegeNotHeld", "deleteing object that is owned by someone else" ); } catch( RTI::DeletePrivilegeNotHeld& dpnh ) { // success! } catch( RTI::Exception& e ) { failTestWrongException( "DeletePrivilegeNotHeld", e, "deleteing object that is owned by someone else" ); } }
//////////////////////////////////////////////// // TEST: testICUnsubscribeWhenNotSubscribed() // //////////////////////////////////////////////// void SubscribeInteractionTest::testICUnsubscribeWhenNotSubscribed() { try { listenerFederate->rtiamb->unsubscribeInteractionClass( xHandle ); failTestMissingException( "InteractionClassNotSubscribed", "unsubscribing from interaction class we don't subscribe to" ); } catch( RTI::InteractionClassNotSubscribed& icns ) { // success! } catch( RTI::Exception& e ) { failTestWrongException( "InteractionClassNotSubscribed", e, "unsubscribing from interaction class we don't subscribe to" ); } }
//////////////////////////////////////////////// // TEST: testICUnsubscribeWithInvalidHandle() // //////////////////////////////////////////////// void SubscribeInteractionTest::testICUnsubscribeWithInvalidHandle() { try { listenerFederate->rtiamb->unsubscribeInteractionClass( 10000000 ); failTestMissingException( "InteractionClassNotDefined", "unsubscribing from interaction class with invalid handle" ); } catch( RTI::InteractionClassNotDefined& icnd ) { // success! } catch( RTI::Exception& e ) { failTestWrongException( "InteractionClassNotDefined", e, "unsubscribing from interaction class with invalid handle" ); } }
/////////////////////////////////////////////////////////// // TEST: testFederateSaveNotCompletedWithoutActiveSave() // /////////////////////////////////////////////////////////// void FederationSaveTest::testFederateSaveNotCompletedWithoutActiveSave() { try { defaultFederate->rtiamb->federateSaveNotComplete(); failTestMissingException( "SaveNotInitiated", "informing federate save not complete without active save" ); } catch( RTI::SaveNotInitiated& sni ) { // success! } catch( RTI::Exception& e ) { failTestWrongException( "SaveNotInitiated", e, "informing federate save not complete without active save" ); } }
////////////////////////////////////////////////////////////////// // TEST: testFederationRestoreNotCompleteWithoutActiveRestore() // ////////////////////////////////////////////////////////////////// void FederationRestoreTest::testFederationRestoreNotCompleteWithoutActiveRestore() { try { defaultFederate->rtiamb->federateRestoreNotComplete(); failTestMissingException( "RestoreNotRequested", "informing federate restore not complete without active restore" ); } catch( RTI::RestoreNotRequested& rnr ) { // success! } catch( RTI::Exception& e ) { failTestWrongException( "RestoreNotRequested", e, "informing federate restore not complete without active restore" ); } }
/////////////////////////////////////////////////// // TEST: testSendROInteractionWithInvalidClass() // /////////////////////////////////////////////////// void SendInteractionTest::testSendROInteractionWithInvalidClass() { try { defaultFederate->rtiamb->sendInteraction( 10000000, *phvps, "NA" ); failTestMissingException( "InteractionClassNotDefined", "sending interaction with wrong class handle" ); } catch( RTI::InteractionClassNotDefined &icnd ) { // success! } catch( RTI::Exception &e ) { failTestWrongException( "InteractionClassNotDefined", e, "sending interaction with wrong class handle" ); } }
/////////////////////////////////////////////////////////// // TEST: testSendROInteractionWithRegionThatIsNotKnown() // /////////////////////////////////////////////////////////// void SendInteractionWithRegionTest::testSendROInteractionWithRegionThatIsNotKnown() { try { defaultFederate->rtiamb->sendInteractionWithRegion( xHandle, *phvps, "NA", *listenerRegion ); failTestMissingException( "RegionNotKnown", "sending interaction with region create in different federate" ); } catch( RTI::RegionNotKnown &rnk ) { // success! } catch( RTI::Exception &e ) { failTestWrongException( "RegionNotKnown", e, "sending interaction with region create in different federate" ); } }
////////////////////////////////////////////////////// // TEST: testRegisterSyncPointWithWhitespaceLabel() // ////////////////////////////////////////////////////// void RegisterSyncPointTest::testRegisterSyncPointWithWhitespaceLabel() { try { federateOne->rtiamb->registerFederationSynchronizationPoint( " ", tag ); failTestMissingException( "RTIinternalError", "registering sync point with whitespace label" ); } catch( RTI::RTIinternalError& rtie ) { // success! } catch( RTI::Exception &e ) { failTestWrongException( "RTIinternalError", e, "registering sync point with whitespace label" ); } }
////////////////////////////////////////////////////////// // TEST: testSendTSOInteractionWithTimeBelowLookahead() // ////////////////////////////////////////////////////////// void SendInteractionTest::testSendTSOInteractionWithTimeBelowLookahead() { try { RTIfedTime theTime = 3.0; defaultFederate->rtiamb->sendInteraction( yHandle, *phvps, theTime, "NA" ); failTestMissingException( "InvalidFederationTime", "sending interaction with time below lookahead" ); } catch( RTI::InvalidFederationTime &fnem ) { // success! } catch( RTI::Exception &e ) { failTestWrongException( "InvalidFederationTime", e, "sending interaction with time below lookahead" ); } }
//////////////////////////////////////////////////// // TEST: testRequestFederationSaveWhenNotJoined() // //////////////////////////////////////////////////// void FederationSaveTest::testRequestFederationSaveWhenNotJoined() { defaultFederate->quickResign(); try { defaultFederate->rtiamb->requestFederationSave( this->saveLabel ); failTestMissingException( "FederateNotExecutionMember", "requesting federation save when not joined" ); } catch( RTI::FederateNotExecutionMember& fnem ) { // success! } catch( RTI::Exception& e ) { failTestWrongException( "FederateNotExecutionMember", e, "requesting federation save when not joined" ); } }