From 3edf8e7d6f8ee15c3014dfa3b33ec50ad88d3112 Mon Sep 17 00:00:00 2001 From: Francois Bleibel <fbleibel@gmail.com> Date: Fri, 25 Jun 2010 18:32:45 +0900 Subject: [PATCH] Added new test test_factory --- unitTesting/CMakeLists.txt | 8 +- unitTesting/factory/test_factory.cpp | 154 +++++++++++++++++++++++++++ unitTesting/{main.cpp => link.cpp} | 0 unitTesting/test-paths.h.cmake | 5 + 4 files changed, 165 insertions(+), 2 deletions(-) create mode 100644 unitTesting/factory/test_factory.cpp rename unitTesting/{main.cpp => link.cpp} (100%) create mode 100644 unitTesting/test-paths.h.cmake diff --git a/unitTesting/CMakeLists.txt b/unitTesting/CMakeLists.txt index ec704265..b789b96c 100644 --- a/unitTesting/CMakeLists.txt +++ b/unitTesting/CMakeLists.txt @@ -2,6 +2,9 @@ # Copyright # +CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/test-paths.h.cmake + ${CMAKE_CURRENT_SOURCE_DIR}/test-paths.h) + #The sot-core plugin libraries that tests have to be linked against #the name of the variable for test EXECUTABLE_NAME is TEST_${EXECUTABLE_NAME}_LIBS SET(TEST_tsot_LIBS @@ -12,13 +15,14 @@ SET(TEST_tsot_LIBS #test paths and names (without .cpp extension) SET (tests - main + link signal/test_signal signal/test_depend signal/test_ptr signal/test_dep sot/tsot - sot/test_solverSoth) + sot/test_solverSoth + factory/test_factory) FOREACH(test ${tests}) GET_FILENAME_COMPONENT(EXECUTABLE_NAME ${test} NAME) diff --git a/unitTesting/factory/test_factory.cpp b/unitTesting/factory/test_factory.cpp new file mode 100644 index 00000000..64b6fdff --- /dev/null +++ b/unitTesting/factory/test_factory.cpp @@ -0,0 +1,154 @@ +/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + * Copyright Projet JRL-JAPAN, Tsukuba, 2007 + *+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + * + * File: test_factory.cc + * Project: SOT + * Author: Nicolas Mansard + * + * Version control + * =============== + * + * $Id$ + * + * Description + * ============ + * + * + * ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ + +/* -------------------------------------------------------------------------- */ +/* --- INCLUDES ------------------------------------------------------------- */ +/* -------------------------------------------------------------------------- */ + + +#include <string> +#include <iostream> + +#include <sot-core/factory.h> +#include <dynamic-graph/entity.h> +#include "../test-paths.h" +#include <sot-core/feature-visual-point.h> +#include <sot-core/exception-feature.h> +#include <sot-core/debug.h> +using namespace std; +using namespace sot; +using namespace dg; + +#ifdef WIN32 +#include <Windows.h> +#else +#include <dlfcn.h> +#endif + +#ifdef WIN32 + typedef HMODULE sotPluginKey; +#else + typedef void* sotPluginKey; +#endif + +class TestFeature + :public FeatureAbstract +{ +public: + TestFeature( void ) : FeatureAbstract("") {} + virtual ~TestFeature( void ) {} + virtual unsigned int& getDimension( unsigned int& res,int time ) {return res;} + + virtual ml::Vector& computeError( ml::Vector& res,int time ) {return res;} + virtual ml::Matrix& computeJacobian( ml::Matrix& res,int time ) {return res;} + virtual ml::Vector& computeActivation( ml::Vector& res,int time ) {return res;} +}; + + +int main() +{ + + sotDEBUG(0) << "# In {"<<endl; +// Entity test(""); +// ExceptionFeature t2(ExceptionFeature::BAD_INIT); +// ExceptionSignal t4(ExceptionSignal::COPY_NOT_INITIALIZED); +// Flags t3; +// TestFeature t5; + +#ifndef WIN32 + sotPluginKey dlib = dlopen(PLUGIN_LIB_INSTALL_PATH "feature-visual-point.so", RTLD_NOW); +#else + sotPluginKey dlib = LoadLibrary (PLUGIN_LIB_INSTALL_PATH "lib/plugin/feature-visual-point.lib"); +#endif +if( NULL==dlib ) + { + cerr << " Error dl"<<endl; +#ifndef WIN32 + cerr << dlerror() <<endl; +#else + // Retrieve the system error message for the last-error code + LPTSTR pszMessage; + DWORD dwLastError = GetLastError(); + FormatMessage( + FORMAT_MESSAGE_ALLOCATE_BUFFER | + FORMAT_MESSAGE_FROM_SYSTEM | + FORMAT_MESSAGE_IGNORE_INSERTS, + NULL, + dwLastError, + MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), + (LPTSTR)&pszMessage, + 0, NULL ); + + + cerr << pszMessage <<endl; + LocalFree(pszMessage); +#endif + + exit(1); + } + + +#ifndef WIN32 + dlib = dlopen(PLUGIN_LIB_INSTALL_PATH "lib/plugin/gain-adaptative.so", RTLD_NOW); +#else + dlib = LoadLibrary (PLUGIN_LIB_INSTALL_PATH "lib/plugin/gain-adaptative.lib"); +#endif + if( NULL==dlib ) + { + cerr << " Error dl"<<endl; +#ifndef WIN32 + cerr << dlerror() <<endl; +#else + // Retrieve the system error message for the last-error code + LPTSTR pszMessage; + DWORD dwLastError = GetLastError(); + FormatMessage( + FORMAT_MESSAGE_ALLOCATE_BUFFER | + FORMAT_MESSAGE_FROM_SYSTEM | + FORMAT_MESSAGE_IGNORE_INSERTS, + NULL, + dwLastError, + MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), + (LPTSTR)&pszMessage, + 0, NULL ); + + + cerr << pszMessage <<endl; + LocalFree(pszMessage); +#endif + exit(1); + } + + Entity* gain = g_factory.newEntity("GainAdaptative","Gain"); + FeatureAbstract* point = sotFactory.newFeature("FeatureVisualPoint","DynamicTest."); + + try { + gain->display(cout); cout << endl; + cout <<gain->getClassName(); cout << endl; + + point->display(cout); cout << endl; + cout <<point->getClassName(); cout << endl; + } + catch ( ExceptionSignal e ) { + cout << "Exception caught! " << e << endl; + } + + sotDEBUG(0) << "# Out }"<<endl; +} + diff --git a/unitTesting/main.cpp b/unitTesting/link.cpp similarity index 100% rename from unitTesting/main.cpp rename to unitTesting/link.cpp diff --git a/unitTesting/test-paths.h.cmake b/unitTesting/test-paths.h.cmake new file mode 100644 index 00000000..6cd128b2 --- /dev/null +++ b/unitTesting/test-paths.h.cmake @@ -0,0 +1,5 @@ +#ifndef TEST_PATHS_H + +#define PLUGIN_LIB_INSTALL_PATH "${CMAKE_INSTALL_PREFIX}/lib/plugin" + +#endif -- GitLab