Revision: 6889 http://playerstage.svn.sourceforge.net/playerstage/?rev=6889&view=rev Author: jeremy_asher Date: 2008-07-18 20:58:47 +0000 (Fri, 18 Jul 2008)
Log Message: ----------- libstageplugin: updates to testing framework, using CppUnit Modified Paths: -------------- code/stage/trunk/libstageplugin/CMakeLists.txt code/stage/trunk/libstageplugin/test/CMakeLists.txt code/stage/trunk/libstageplugin/test/lsp_test.cc Added Paths: ----------- code/stage/trunk/libstageplugin/test/lsp_test_laser.cc code/stage/trunk/libstageplugin/test/lsp_test_laser.hh Modified: code/stage/trunk/libstageplugin/CMakeLists.txt =================================================================== --- code/stage/trunk/libstageplugin/CMakeLists.txt 2008-07-18 18:18:17 UTC (rev 6888) +++ code/stage/trunk/libstageplugin/CMakeLists.txt 2008-07-18 20:58:47 UTC (rev 6889) @@ -3,8 +3,7 @@ link_directories( ${PLAYER_LIBDIR} ) include_directories( ${PLAYER_INCLUDE_DIRS}) -add_library( stageplugin MODULE - p_driver.h +set( stagepluginSrcs p_driver.h p_driver.cc p_blobfinder.cc p_simulation.cc @@ -16,6 +15,8 @@ stg_time.cc ) +add_library( stageplugin MODULE ${stagepluginSrcs} ) + # p_graphics3d.cc @@ -24,7 +25,7 @@ ${PLAYER_LIBRARIES} playerutils ${OPENGL_LIBRARIES} - + ) IF (BUILD_LSPTEST) Modified: code/stage/trunk/libstageplugin/test/CMakeLists.txt =================================================================== --- code/stage/trunk/libstageplugin/test/CMakeLists.txt 2008-07-18 18:18:17 UTC (rev 6888) +++ code/stage/trunk/libstageplugin/test/CMakeLists.txt 2008-07-18 20:58:47 UTC (rev 6889) @@ -1,10 +1,24 @@ MESSAGE( STATUS "Building Player plugin tests" ) pkg_search_module( PLAYERC REQUIRED playerc ) +pkg_search_module( CPPUNIT REQUIRED cppunit ) +include_directories( + ${CPPUNIT_INCLUDE_PATH} +) + +link_directories( + ${CPPUNIT_LIBRARY_DIRS} +) + SET( lspTestSrcs lsp_test.cc + lsp_test_laser.cc + lsp_test_laser.hh ) add_executable( lsp_test ${lspTestSrcs} ) -target_link_libraries( lsp_test PLAYERC ) +target_link_libraries( lsp_test + ${PLAYERC_LIBRARIES} + ${CPPUNIT_LIBRARIES} +) Modified: code/stage/trunk/libstageplugin/test/lsp_test.cc =================================================================== --- code/stage/trunk/libstageplugin/test/lsp_test.cc 2008-07-18 18:18:17 UTC (rev 6888) +++ code/stage/trunk/libstageplugin/test/lsp_test.cc 2008-07-18 20:58:47 UTC (rev 6889) @@ -1,42 +1,32 @@ -#include <stdio.h> +#include <cppunit/BriefTestProgressListener.h> +#include <cppunit/CompilerOutputter.h> +#include <cppunit/extensions/TestFactoryRegistry.h> +#include <cppunit/TestResult.h> +#include <cppunit/TestResultCollector.h> +#include <cppunit/TestRunner.h> -#include <libplayerc/playerc.h> - -int main(int argc, const char **argv) +int main( int argc, char* argv[] ) { - int i; - playerc_client_t *client; - playerc_position2d_t *position2d; - // Create a client and connect it to the server. - client = playerc_client_create(NULL, "localhost", 6665); - if (0 != playerc_client_connect(client)) - return -1; + // Create the event manager and test controller + CPPUNIT_NS::TestResult controller; - // Create and subscribe to a position2d device. - position2d = playerc_position2d_create(client, 0); - if (playerc_position2d_subscribe(position2d, PLAYER_OPEN_MODE)) - return -1; + // Add a listener that colllects test result + CPPUNIT_NS::TestResultCollector result; + controller.addListener( &result ); - // Make the robot spin! - if (0 != playerc_position2d_set_cmd_vel(position2d, 0, 0, DTOR(40.0), 1)) - return -1; + // Add a listener that print dots as test run. + CPPUNIT_NS::BriefTestProgressListener progress; + controller.addListener( &progress ); - for (i = 0; i < 200; i++) - { - // Wait for new data from server - playerc_client_read(client); - - // Print current robot pose - printf("position2d : %f %f %f\n", - position2d->px, position2d->py, position2d->pa); - } + // Add the top suite to the test runner + CPPUNIT_NS::TestRunner runner; + runner.addTest( CPPUNIT_NS::TestFactoryRegistry::getRegistry().makeTest() ); + runner.run( controller ); - // Shutdown - playerc_position2d_unsubscribe(position2d); - playerc_position2d_destroy(position2d); - playerc_client_disconnect(client); - playerc_client_destroy(client); + // Print test in a compiler compatible format. + CPPUNIT_NS::CompilerOutputter outputter( &result, CPPUNIT_NS::stdCOut() ); + outputter.write(); - return 0; + return result.wasSuccessful() ? 0 : 1; } Added: code/stage/trunk/libstageplugin/test/lsp_test_laser.cc =================================================================== --- code/stage/trunk/libstageplugin/test/lsp_test_laser.cc (rev 0) +++ code/stage/trunk/libstageplugin/test/lsp_test_laser.cc 2008-07-18 20:58:47 UTC (rev 6889) @@ -0,0 +1,51 @@ +#include "lsp_test_laser.hh" + + + +void LSPLaserTest::setUp() { + client = playerc_client_create( NULL, "localhost", 6665 ); + +// int connectError = playerc_client_connect( client ); + CPPUNIT_ASSERT( playerc_client_connect( client ) == 0 ); + + laserProxy = playerc_laser_create( client, 0 ); + + CPPUNIT_ASSERT( playerc_laser_subscribe( laserProxy, PLAYER_OPEN_MODE ) == 0 ); +} + + +void LSPLaserTest::tearDown() { + CPPUNIT_ASSERT( playerc_laser_unsubscribe( laserProxy ) == 0 ); + playerc_laser_destroy( laserProxy ); + + CPPUNIT_ASSERT( playerc_client_disconnect( client ) == 0 ); + playerc_client_destroy( client ); +} + +void LSPLaserTest::testConfig() { + const double DELTA = 0.01; + + double min = -M_PI/2; + double max = +M_PI/2; + double res = 100; + double range_res = 1; + unsigned char intensity = 1; + double freq = 10; + + CPPUNIT_ASSERT( playerc_laser_set_config( laserProxy, min, max, res, range_res, intensity, freq ) == 0 ); + + double min2, max2, res2, range_res2, freq2; + unsigned char intensity2 = 1; + CPPUNIT_ASSERT( playerc_laser_get_config( laserProxy, &min2, &max2, &res2, &range_res2, &intensity2, &freq2 ) == 0 ); + + CPPUNIT_ASSERT_DOUBLES_EQUAL( min2, min, DELTA ); + CPPUNIT_ASSERT_DOUBLES_EQUAL( max2, max, DELTA ); + CPPUNIT_ASSERT_DOUBLES_EQUAL( res2, res, DELTA ); + CPPUNIT_ASSERT_DOUBLES_EQUAL( range_res2, range_res, DELTA ); + CPPUNIT_ASSERT_DOUBLES_EQUAL( freq2, freq, DELTA ); + CPPUNIT_ASSERT( intensity == intensity2 ); +} + +void LSPLaserTest::testData() { + +} \ No newline at end of file Added: code/stage/trunk/libstageplugin/test/lsp_test_laser.hh =================================================================== --- code/stage/trunk/libstageplugin/test/lsp_test_laser.hh (rev 0) +++ code/stage/trunk/libstageplugin/test/lsp_test_laser.hh 2008-07-18 20:58:47 UTC (rev 6889) @@ -0,0 +1,28 @@ +#ifndef _LSP_LASER_TEST_H_ +#define _LSP_LASER_TEST_H_ + +#include <cppunit/extensions/HelperMacros.h> +#include <libplayerc/playerc.h> + +class LSPLaserTest : public CPPUNIT_NS::TestFixture +{ + CPPUNIT_TEST_SUITE( LSPLaserTest ); + CPPUNIT_TEST( testConfig ); + CPPUNIT_TEST( testData ); + CPPUNIT_TEST_SUITE_END(); + +protected: + playerc_laser_t* laserProxy; + playerc_client_t* client; + + void testConfig(); + void testData(); + +public: + void setUp(); + void tearDown(); +}; + +CPPUNIT_TEST_SUITE_REGISTRATION( LSPLaserTest ); + +#endif \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ------------------------------------------------------------------------- This SF.Net email is sponsored by the Moblin Your Move Developer's challenge Build the coolest Linux based applications with Moblin SDK & win great prizes Grand prize is a trip for two to an Open Source event anywhere in the world http://moblin-contest.org/redirect.php?banner_id=100&url=/ _______________________________________________ Playerstage-commit mailing list Playerstage-commit@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/playerstage-commit