Commit a6b50921 authored by Francois Bleibel's avatar Francois Bleibel
Browse files

Added two unit tests.

Shell (ok)
Factory (currently needs sotGainAdaptive to compile, will change to another entity soon)
parent 66516bf8
......@@ -105,6 +105,7 @@ INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/dynamic-graph.pc
ADD_SUBDIRECTORY(src)
ADD_SUBDIRECTORY(include)
ADD_SUBDIRECTORY(unitTesting)
#
# Documentation produced by doxygen
#
......
#
# Copyright
#
SET(EXECUTABLE_NAME test_shell)
ADD_DEFINITIONS(-DDEBUG=2)
ADD_EXECUTABLE(${EXECUTABLE_NAME}
test_shell.cpp)
INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include)
link_directories(${LIBRARY_OUTPUT_PATH})
TARGET_LINK_LIBRARIES(${EXECUTABLE_NAME}
dynamicGraph
dl)
#NOTE on test_factory:
# test can only be compiled IF sotGainAdaptive has been compiled first
SET(EXECUTABLE_NAME test_factory)
ADD_DEFINITIONS(-DDEBUG=2)
ADD_EXECUTABLE(${EXECUTABLE_NAME}
test_factory.cpp)
INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include)
link_directories(${LIBRARY_OUTPUT_PATH})
TARGET_LINK_LIBRARIES(${EXECUTABLE_NAME}
dynamicGraph
dl)
\ No newline at end of file
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
* 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 <cstdlib>
#include <dynamic-graph/factory.h>
#include <dynamic-graph/entity.h>
#include <dynamic-graph/debug.h>
using namespace std;
using namespace dynamicgraph;
#ifdef WIN32
#include <Windows.h>
#else
#include <dlfcn.h>
#endif
#ifdef WIN32
typedef HMODULE sotPluginKey;
#else
typedef void* sotPluginKey;
#endif
int main()
{
dgDEBUG(0) << "# In {"<<endl;
// Entity test("");
// sotExceptionFeature t2(sotExceptionFeature::BAD_INIT);
// sotExceptionSignal t4(sotExceptionSignal::COPY_NOT_INITIALIZED);
// sotFlags t3;
// TestFeature t5;
#ifndef WIN32
sotPluginKey dlib = dlopen("lib/plugin/sotFeatureVisualPoint.so", RTLD_NOW);
#else
sotPluginKey dlib = LoadLibrary ( "lib/plugin/sotFeatureVisualPoint.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(0);
}
#ifndef WIN32
dlib = dlopen("lib/plugin/sotGainAdaptative.so", RTLD_NOW);
#else
dlib = LoadLibrary ("lib/plugin/sotGainAdaptative.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(0);
}
Entity* gain = factory.newEntity("GainAdaptative","Gain");
gain->display(cout); cout << endl;
cout <<gain->getClassName(); cout << endl;
dgDEBUG(0) << "# Out }"<<endl;
}
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
* Copyright Projet JRL-JAPAN, Tsukuba, 2007
*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
*
* File: test_shell.cc
* Project: SOT
* Author: Nicolas Mansard
*
* Version control
* ===============
*
* $Id$
*
* Description
* ============
*
*
* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
/* -------------------------------------------------------------------------- */
/* --- INCLUDES ------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
#include <dynamic-graph/entity.h>
#include <dynamic-graph/plugin-loader.h>
#include <dynamic-graph/interpreter.h>
#include <dynamic-graph/debug.h>
#include <sstream>
using namespace std;
using namespace dynamicgraph;
extern std::ofstream debugfile;
int main( int argc,char** argv )
{
dgDEBUGIN(15);
dgDEBUG(5) << " Loading..." << endl;
PluginLoader pl;
Shell.referencePluginLoader( &pl );
int fileIdx;
try
{
for( fileIdx=1;fileIdx<argc;++fileIdx )
{
std::istringstream script( argv[fileIdx] );
cout << "Run "<< argv[fileIdx] << endl;
Shell.cmd( "run",script,cout );
}
}
catch( ExceptionAbstract& e )
{
cout << "!! In file <" << argv[fileIdx] << "> : " << e <<endl;
}
catch ( const char* str ) {
cout << "!! In file <" << argv[fileIdx] << "> : "
<< "Unknown exception " << str << endl;
}
catch( ... ){ dgDEBUG(5) << "!! Unknown! " <<endl ; }
while(1)
{
try
{
dgDEBUG(5) << "Run shell." << endl;
Shell.shell(cin,cout);
dgDEBUG(5) << "Shell over." << endl;
if( cin.eof() ) break;
}
catch( ExceptionAbstract& e )
{
cout << "!! " << e <<endl;
}
catch( ... ){ dgDEBUG(5) << "!! Unknown! " <<endl ; }
}
dgDEBUGOUT(15);
return 0;
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment