Thread: [Opal-commits] opal/src BlueprintInstance.cpp,1.4,1.5 BlueprintInstance.h,1.4,1.5 testBlueprint.cpp,
Status: Inactive
Brought to you by:
tylerstreeter
|
From: Olex <ole...@us...> - 2005-12-12 00:35:21
|
Update of /cvsroot/opal/opal/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26526/src Modified Files: BlueprintInstance.cpp BlueprintInstance.h testBlueprint.cpp testJoint.cpp testopal.cpp testsolid.cpp Log Message: Enhancing BlueprintInstance. Added new unit tests. Index: testBlueprint.cpp =================================================================== RCS file: /cvsroot/opal/opal/src/testBlueprint.cpp,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** testBlueprint.cpp 11 Dec 2005 04:43:05 -0000 1.2 --- testBlueprint.cpp 12 Dec 2005 00:35:13 -0000 1.3 *************** *** 38,41 **** --- 38,58 ---- namespace testBlueprint { + QT_TEST( manual_addition_solid ) + { + // solidmap seems to be corrups sometimes, let's test this + Simulator * sim = createSimulator(); + Solid * s = sim->createSolid(); + s->setName( "baba" ); + BlueprintInstance * b = new BlueprintInstance(); + b->internal_addSolid( s ); + + QT_CHECK_EQUAL( b->getSolid( "baba" ), s ); + QT_CHECK_EQUAL( b->getSolid( 0 ), s ); + + delete b; + + sim->destroy(); + } + QT_TEST( create_and_delete ) { *************** *** 58,69 **** { // Instantiate the Blueprint. ! BlueprintInstance instance; ! sim->instantiateBlueprint( instance, bp ); QT_CHECK_EQUAL( sim->getNumSolids(), 1 ); ! unsigned int nsolids = instance.getNumSolids(); for ( unsigned int i = 0; i < nsolids; ++i ) { ! sim->destroySolid( instance.getSolid( i ) ); } } --- 75,89 ---- { // Instantiate the Blueprint. ! BlueprintInstance * instance = new BlueprintInstance(); ! sim->instantiateBlueprint( *instance, bp ); QT_CHECK_EQUAL( sim->getNumSolids(), 1 ); ! unsigned int nsolids = instance->getNumSolids(); for ( unsigned int i = 0; i < nsolids; ++i ) { ! Solid * tobedetached = instance->getSolid( i ); ! sim->destroySolid( instance->detachSolid( tobedetached->getName() ) ); } + + delete instance; } Index: testopal.cpp =================================================================== RCS file: /cvsroot/opal/opal/src/testopal.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** testopal.cpp 6 Nov 2005 17:41:20 -0000 1.1 --- testopal.cpp 12 Dec 2005 00:35:13 -0000 1.2 *************** *** 28,35 **** --- 28,44 ---- // system headers + #include <iostream> #include <quicktest.h> + #include <string> + + using namespace std; int main( int argc, char* argv[] ) { QT_RUN_TESTS; + + cout << "Type any letter and then Enter to quit." << endl; + + string temp; + cin >> temp; } Index: testJoint.cpp =================================================================== RCS file: /cvsroot/opal/opal/src/testJoint.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** testJoint.cpp 10 Dec 2005 22:41:06 -0000 1.1 --- testJoint.cpp 12 Dec 2005 00:35:13 -0000 1.2 *************** *** 38,41 **** --- 38,58 ---- namespace testJoint { + QT_TEST( setContacts ) + { + Simulator * sim = createSimulator(); + Joint * j = sim->createJoint(); + JointData data; + data.contactsEnabled = false; + + j->init( data ); + QT_CHECK_EQUAL( j->areContactsEnabled(), false ); + + data.contactsEnabled = true; + j->init( data ); + QT_CHECK_EQUAL( j->areContactsEnabled(), true ); + + sim->destroy(); + } + QT_TEST( break_settings ) { Index: testsolid.cpp =================================================================== RCS file: /cvsroot/opal/opal/src/testsolid.cpp,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** testsolid.cpp 10 Dec 2005 22:41:06 -0000 1.8 --- testsolid.cpp 12 Dec 2005 00:35:13 -0000 1.9 *************** *** 250,252 **** --- 250,338 ---- f.sim->simulate( 1 ); } + + class TwoSolidFixture + { + public: + TwoSolidFixture() + { + sim = createSimulator(); + s0 = sim->createSolid(); + s1 = sim->createSolid(); + } + + ~TwoSolidFixture() + { + sim->destroy(); + } + + Simulator * sim; + Solid * s0; + Solid * s1; + }; + + class MockCollision : public CollisionEventHandler + { + public: + MockCollision() + { + calls = 0; + } + + void OPAL_CALL handleCollisionEvent( const CollisionEvent & e ) + { + ++calls; + } + + int calls; + }; + + QT_TEST( same_contact_group_no_collision ) + { + TwoSolidFixture f; + { + SphereShapeData data; + data.radius = 1; + data.contactGroup = 1; + f.s0->addShape( data ); + f.s1->addShape( data ); + } + MockCollision * c = new MockCollision( ); + f.s0->setCollisionEventHandler( c ); + f.s1->setCollisionEventHandler( c ); + + f.s0->setPosition( 0, 0, 0 ); + f.s1->setPosition( 0, 0, 0 ); + + f.sim->setupContactGroups( 1, 1, false ); + + c->calls = 0; + f.sim->simulate( 1 ); + + QT_CHECK_EQUAL( c->calls, 0 ); + } + + QT_TEST( same_contact_group_with_collision ) + { + TwoSolidFixture f; + { + SphereShapeData data; + data.radius = 1; + data.contactGroup = 1; + f.s0->addShape( data ); + f.s1->addShape( data ); + } + MockCollision * c = new MockCollision( ); + f.s0->setCollisionEventHandler( c ); + f.s1->setCollisionEventHandler( c ); + + f.s0->setPosition( 0, 0, 0 ); + f.s1->setPosition( 0, 0, 0 ); + + f.sim->setupContactGroups( 1, 1, true ); + + c->calls = 0; + f.sim->simulate( 1 ); + + QT_CHECK_GREATER( c->calls, 0 ); + } } Index: BlueprintInstance.h =================================================================== RCS file: /cvsroot/opal/opal/src/BlueprintInstance.h,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** BlueprintInstance.h 31 Mar 2005 08:47:02 -0000 1.4 --- BlueprintInstance.h 12 Dec 2005 00:35:13 -0000 1.5 *************** *** 94,97 **** --- 94,118 ---- OPAL_DECL virtual Sensor* OPAL_CALL getSensor(unsigned int i)const; + //! Removes but does not delete the solid. + /*! + * @note make sure i is in the range of solid list + */ + OPAL_DECL virtual Solid * OPAL_CALL detachSolid( unsigned int i ); + + /// Detachs a Joint by index and returns its pointer. + OPAL_DECL virtual Joint* OPAL_CALL detachJoint(unsigned int i); + + /// Detachs a Motor by index and returns its pointer. + OPAL_DECL virtual Motor* OPAL_CALL detachMotor(unsigned int i); + + /// Detachs a Sensor by index and returns its pointer. + OPAL_DECL virtual Sensor* OPAL_CALL detachSensor(unsigned int i); + + //! Removes but does not delete the solid. + /*! + * @note make sure solid is stored here + */ + OPAL_DECL virtual Solid * OPAL_CALL detachSolid( const std::string & name ); + /// Adds a new Solid pointer to the list. If the pointer is /// non-NULL and the object's name is not an empty string, this Index: BlueprintInstance.cpp =================================================================== RCS file: /cvsroot/opal/opal/src/BlueprintInstance.cpp,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** BlueprintInstance.cpp 31 Mar 2005 08:47:02 -0000 1.4 --- BlueprintInstance.cpp 12 Dec 2005 00:35:13 -0000 1.5 *************** *** 26,30 **** --- 26,33 ---- *************************************************************************/ + // class headers #include "BlueprintInstance.h" + + // project headers #include "Solid.h" #include "Joint.h" *************** *** 32,39 **** --- 35,49 ---- #include "Sensor.h" + // system headers + #include <map> + #include <vector> + + using namespace std; + namespace opal { BlueprintInstance::BlueprintInstance() { + // nothing to do } *************** *** 51,57 **** } ! Solid* BlueprintInstance::getSolid(const std::string& name)const { ! std::map<std::string, Solid*>::const_iterator iter = mSolidMap.find(name); if (mSolidMap.end() == iter) --- 61,156 ---- } ! Solid * BlueprintInstance::detachSolid(unsigned int i) { ! assert( i < mSolidList.size() ); ! Solid * detached = mSolidList[i]; ! ! // detach from list ! mSolidList.erase( mSolidList.begin() + i ); ! ! // detach from map ! map<string, Solid*>::iterator iter = ! mSolidMap.find( detached->getName() ); ! mSolidMap.erase( iter ); ! ! return detached; ! } ! ! Joint * BlueprintInstance::detachJoint(unsigned int i) ! { ! assert( i < mJointList.size() ); ! Joint * detached = mJointList[i]; ! ! // detach from list ! mJointList.erase( mJointList.begin() + i ); ! ! // detach from map ! map<string, Joint*>::iterator iter = ! mJointMap.find( detached->getName() ); ! mJointMap.erase( iter ); ! ! return detached; ! } ! ! Sensor * BlueprintInstance::detachSensor(unsigned int i) ! { ! assert( i < mSensorList.size() ); ! Sensor * detached = mSensorList[i]; ! ! // detach from list ! mSensorList.erase( mSensorList.begin() + i ); ! ! // detach from map ! map<string, Sensor*>::iterator iter = ! mSensorMap.find( detached->getName() ); ! mSensorMap.erase( iter ); ! ! return detached; ! } ! ! Motor * BlueprintInstance::detachMotor(unsigned int i) ! { ! assert( i < mMotorList.size() ); ! Motor * detached = mMotorList[i]; ! ! // detach from list ! mMotorList.erase( mMotorList.begin() + i ); ! ! // detach from map ! map<string, Motor*>::iterator iter = ! mMotorMap.find( detached->getName() ); ! mMotorMap.erase( iter ); ! ! return detached; ! } ! ! Solid * BlueprintInstance::detachSolid( const string & name ) ! { ! map<string, Solid*>::iterator iter = ! mSolidMap.find( name ); ! Solid * detached = iter->second; ! ! // detach from list ! vector<Solid *>::iterator listIter; ! for ( listIter = mSolidList.begin(); ! listIter != mSolidList.end(); ! ++listIter ) ! { ! if ( ( *listIter )->getName() == name ) ! { ! mSolidList.erase( listIter ); ! break; ! } ! } ! ! // detach from map ! mSolidMap.erase( iter ); ! ! return detached; ! } ! ! Solid* BlueprintInstance::getSolid(const string& name)const ! { ! map<string, Solid*>::const_iterator iter = mSolidMap.find(name); if (mSolidMap.end() == iter) *************** *** 65,71 **** } ! Joint* BlueprintInstance::getJoint(const std::string& name)const { ! std::map<std::string, Joint*>::const_iterator iter = mJointMap.find(name); if (mJointMap.end() == iter) --- 164,170 ---- } ! Joint* BlueprintInstance::getJoint(const string& name)const { ! map<string, Joint*>::const_iterator iter = mJointMap.find(name); if (mJointMap.end() == iter) *************** *** 79,85 **** } ! Motor* BlueprintInstance::getMotor(const std::string& name)const { ! std::map<std::string, Motor*>::const_iterator iter = mMotorMap.find(name); if (mMotorMap.end() == iter) --- 178,184 ---- } ! Motor* BlueprintInstance::getMotor(const string& name)const { ! map<string, Motor*>::const_iterator iter = mMotorMap.find(name); if (mMotorMap.end() == iter) *************** *** 93,99 **** } ! Sensor* BlueprintInstance::getSensor(const std::string& name)const { ! std::map<std::string, Sensor*>::const_iterator iter = mSensorMap.find(name); if (mSensorMap.end() == iter) --- 192,198 ---- } ! Sensor* BlueprintInstance::getSensor(const string& name)const { ! map<string, Sensor*>::const_iterator iter = mSensorMap.find(name); if (mSensorMap.end() == iter) *************** *** 156,160 **** } ! std::string name = s->getName(); if (name.empty()) --- 255,259 ---- } ! string name = s->getName(); if (name.empty()) *************** *** 175,179 **** } ! std::string name = j->getName(); if (name.empty()) --- 274,278 ---- } ! string name = j->getName(); if (name.empty()) *************** *** 194,198 **** } ! std::string name = m->getName(); if (name.empty()) --- 293,297 ---- } ! string name = m->getName(); if (name.empty()) *************** *** 213,217 **** } ! std::string name = s->getName(); if (name.empty()) --- 312,316 ---- } ! string name = s->getName(); if (name.empty()) |