[Opal-commits] opal/src testAccelerationSensor.cpp,NONE,1.1 Makefile.am,1.1,1.2 Makefile.in,1.1,1.2
Status: Inactive
Brought to you by:
tylerstreeter
|
From: Olex <ole...@us...> - 2005-11-13 18:51:36
|
Update of /cvsroot/opal/opal/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22008/src Modified Files: Makefile.am Makefile.in testsolid.cpp Added Files: testAccelerationSensor.cpp Log Message: Added Solid and AccelerationSensor unit tests. Cosmetic modifications to QuickTest header. Index: Makefile.in =================================================================== RCS file: /cvsroot/opal/opal/src/Makefile.in,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** Makefile.in 6 Nov 2005 17:41:20 -0000 1.1 --- Makefile.in 13 Nov 2005 18:51:20 -0000 1.2 *************** *** 65,69 **** binPROGRAMS_INSTALL = $(INSTALL_PROGRAM) PROGRAMS = $(bin_PROGRAMS) ! am_test_opal_OBJECTS = testopal.$(OBJEXT) testsolid.$(OBJEXT) test_opal_OBJECTS = $(am_test_opal_OBJECTS) test_opal_DEPENDENCIES = \ --- 65,70 ---- binPROGRAMS_INSTALL = $(INSTALL_PROGRAM) PROGRAMS = $(bin_PROGRAMS) ! am_test_opal_OBJECTS = testopal.$(OBJEXT) testsolid.$(OBJEXT) \ ! testAccelerationSensor.$(OBJEXT) test_opal_OBJECTS = $(am_test_opal_OBJECTS) test_opal_DEPENDENCIES = \ *************** *** 206,210 **** VolumeSensor.cpp ! test_opal_SOURCES = testopal.cpp testsolid.cpp test_opal_LDADD = $(top_builddir)/src/external/tinyxml/libtinyxml.a \ $(top_builddir)/src/ODE/libodeimpl.a $(top_builddir)/src/libopalode.a -lode --- 207,211 ---- VolumeSensor.cpp ! test_opal_SOURCES = testopal.cpp testsolid.cpp testAccelerationSensor.cpp test_opal_LDADD = $(top_builddir)/src/external/tinyxml/libtinyxml.a \ $(top_builddir)/src/ODE/libodeimpl.a $(top_builddir)/src/libopalode.a -lode *************** *** 309,312 **** --- 310,314 ---- @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ThrusterMotor.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/VolumeSensor.Po@am__quote@ + @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/testAccelerationSensor.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/testopal.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/testsolid.Po@am__quote@ Index: testsolid.cpp =================================================================== RCS file: /cvsroot/opal/opal/src/testsolid.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** testsolid.cpp 6 Nov 2005 17:41:20 -0000 1.1 --- testsolid.cpp 13 Nov 2005 18:51:20 -0000 1.2 *************** *** 37,56 **** namespace testSolid { ! struct SolidFixture { ! SolidFixture() ! { ! sim = createSimulator(); ! s = sim->createSolid(); ! } ! ~SolidFixture() ! { ! sim->destroySolid( s ); ! sim->destroy(); ! } ! Simulator * sim; ! Solid * s; }; --- 37,58 ---- namespace testSolid { ! class SolidFixture { ! public: ! SolidFixture() ! { ! sim = createSimulator(); ! sim->setGravity( Vec3r( 0, -9.81, 0 ) ); ! s = sim->createSolid(); ! } ! ~SolidFixture() ! { ! sim->destroySolid( s ); ! sim->destroy(); ! } ! Simulator * sim; ! Solid * s; }; *************** *** 58,63 **** { SolidFixture f; - QT_CHECK( f.sim != NULL ); QT_CHECK( f.s != NULL ); } } --- 60,204 ---- { SolidFixture f; QT_CHECK( f.s != NULL ); } + + QT_TEST( testNaming ) + { + SolidFixture f; + f.s->setName( "baba" ); + QT_CHECK_EQUAL( "baba", f.s->getName() ); + } + + class SolidBoxFixture : public SolidFixture + { + public: + SolidBoxFixture() : SolidFixture() + { + BoxShapeData data; + data.dimensions = Vec3r( 1, 1, 1 ); + data.material.density = 1; + s->addShape( data ); + } + }; + + QT_TEST( testEnablingTrue ) + { + SolidBoxFixture f; + + f.s->setEnabled( true ); + Point3r p = f.s->getPosition(); + + f.sim->simulate( 1 ); + + QT_CHECK_LESS( f.s->getPosition() [ 1 ], p[ 1 ] ); + } + + QT_TEST( testEnablingFalse ) + { + SolidBoxFixture f; + + f.s->setEnabled( false ); + Point3r p = f.s->getPosition(); + + f.sim->simulate( 1 ); + + QT_CHECK_CLOSE( f.s->getPosition() [ 1 ], p[ 1 ], 0.001 ); + } + + QT_TEST( testStaticTrue ) + { + SolidBoxFixture f; + + f.s->setStatic( true ); + Point3r p = f.s->getPosition(); + + f.sim->simulate( 1 ); + + QT_CHECK_CLOSE( f.s->getPosition() [ 1 ], p[ 1 ], 0.001 ); + } + + QT_TEST( testStaticFalse ) + { + SolidBoxFixture f; + + f.s->setStatic( false ); + Point3r p = f.s->getPosition(); + + f.sim->simulate( 1 ); + + QT_CHECK_LESS( f.s->getPosition() [ 1 ], p[ 1 ] ); + } + + QT_TEST( testSleepingTrue ) + { + SolidBoxFixture f; + + f.s->setSleeping( true ); + Point3r p = f.s->getPosition(); + + f.sim->simulate( 1 ); + + QT_CHECK_CLOSE( f.s->getPosition() [ 1 ], p[ 1 ], 0.001 ); + } + + QT_TEST( testSleepingFalse ) + { + SolidBoxFixture f; + + f.s->setSleeping( false ); + Point3r p = f.s->getPosition(); + + f.sim->simulate( 1 ); + + QT_CHECK_LESS( f.s->getPosition() [ 1 ], p[ 1 ] ); + } + + QT_TEST( testAddingForce ) + { + SolidBoxFixture f; + + Force force; + force.type = GLOBAL_FORCE; + force.vec = Vec3r( 0, 200, 0 ); + force.duration = 0.1; + f.s->addForce( force ); + + Point3r p = f.s->getPosition(); + + f.sim->simulate( 1 ); + + QT_CHECK_GREATER( f.s->getPosition() [ 1 ], p[ 1 ] ); + } + + QT_TEST( testZeroForces ) + { + SolidBoxFixture f; + + Force force; + force.type = GLOBAL_FORCE; + force.vec = Vec3r( 0, 200, 0 ); + force.duration = 0.1; + f.s->addForce( force ); + + f.s->zeroForces(); + + Point3r p = f.s->getPosition(); + + f.sim->simulate( 1 ); + + QT_CHECK_LESS( f.s->getPosition() [ 1 ], p[ 1 ] ); + } + + QT_TEST( testRotationViaIdentity ) + { + SolidBoxFixture f; + + Matrix44r m; + m.makeIdentity(); + + f.s->setTransform( m ); + Matrix44r current = f.s->getTransform(); + + QT_CHECK_EQUAL( current, m ); + } } Index: Makefile.am =================================================================== RCS file: /cvsroot/opal/opal/src/Makefile.am,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** Makefile.am 6 Nov 2005 17:41:20 -0000 1.1 --- Makefile.am 13 Nov 2005 18:51:20 -0000 1.2 *************** *** 15,19 **** VolumeSensor.cpp bin_PROGRAMS = test_opal ! test_opal_SOURCES = testopal.cpp testsolid.cpp test_opal_LDADD = $(top_builddir)/src/external/tinyxml/libtinyxml.a \ $(top_builddir)/src/ODE/libodeimpl.a $(top_builddir)/src/libopalode.a -lode --- 15,19 ---- VolumeSensor.cpp bin_PROGRAMS = test_opal ! test_opal_SOURCES = testopal.cpp testsolid.cpp testAccelerationSensor.cpp test_opal_LDADD = $(top_builddir)/src/external/tinyxml/libtinyxml.a \ $(top_builddir)/src/ODE/libodeimpl.a $(top_builddir)/src/libopalode.a -lode --- NEW FILE: testAccelerationSensor.cpp --- /************************************************************************* * * * Open Physics Abstraction Layer * * Copyright (C) 2004-2005 * * Alan Fischer ala...@gm... * * Andres Reinot an...@re... * * Tyler Streeter tyl...@gm... * * Oleksandr Lozitskiy mr....@gm... * * All rights reserved. * * Web: opal.sourceforge.net * * * * This library is free software; you can redistribute it and/or * * modify it under the terms of EITHER: * * (1) The GNU Lesser General Public License as published by the Free * * Software Foundation; either version 2.1 of the License, or (at * * your option) any later version. The text of the GNU Lesser * * General Public License is included with this library in the * * file license-LGPL.txt. * * (2) The BSD-style license that is included with this library in * * the file license-BSD.txt. * * * * This library is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the files * * license-LGPL.txt and license-BSD.txt for more details. * * * *************************************************************************/ // system headers #include <quicktest.h> // project headers #include "opal.h" using namespace opal; namespace testAccelerationSensor { class Fixture { public: Fixture() { sim = createSimulator(); sim->setGravity( Vec3r( 0, -9.81, 0 ) ); s = sim->createSolid(); sensor = sim->createAccelerationSensor(); } ~Fixture() { sim->destroySensor( sensor ); sim->destroySolid( s ); sim->destroy(); } Simulator * sim; Solid * s; AccelerationSensor * sensor; }; QT_TEST( testCreation ) { Fixture f; QT_CHECK( f.sensor != NULL ); } QT_TEST( testNaming ) { Fixture f; f.sensor->setName( "baba" ); QT_CHECK_EQUAL( "baba", f.sensor->getName() ); } class SetupFixture : public Fixture { public: SetupFixture() { AccelerationSensorData data; data.solid = s; sensor->init( data ); } }; QT_TEST( testAcceleration ) { SetupFixture f; f.sim->simulate( 1 ); QT_CHECK( f.sensor->getGlobalLinearAccel() [ 1 ] < 0 ); } QT_TEST( testDisabled ) { SetupFixture f; f.sensor->setEnabled( false ); f.sim->simulate( 1 ); QT_CHECK_CLOSE( f.sensor->getGlobalLinearAccel() [ 1 ] , 0, 0.001 ); } } |