From b4e0c0cda85ecd975877cc0d9a56eec1c306ae74 Mon Sep 17 00:00:00 2001
From: Francois Bleibel <fbleibel@gmail.com>
Date: Tue, 29 Jun 2010 17:21:15 +0900
Subject: [PATCH] Corrected a bug that stemmed from the renaming of
 GainAdaptive (thanks unit testing!) Added unit tests for filesystem and
 tracing.

---
 CMakeLists.txt                       |  4 +-
 unitTesting/CMakeLists.txt           | 12 +++++-
 unitTesting/factory/test_factory.cpp |  4 +-
 unitTesting/traces/files.cpp         | 43 +++++++++++++++++++++
 unitTesting/traces/traces.cpp        | 58 ++++++++++++++++++++++++++++
 5 files changed, 116 insertions(+), 5 deletions(-)
 create mode 100644 unitTesting/traces/files.cpp
 create mode 100644 unitTesting/traces/traces.cpp

diff --git a/CMakeLists.txt b/CMakeLists.txt
index cc17d7be..6833e19b 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -104,9 +104,9 @@ ENDIF(PACKAGE_REQUIREMENTS STREQUAL "")
 #
 # Boost
 #
-FIND_PACKAGE(Boost REQUIRED)
+FIND_PACKAGE(Boost COMPONENTS filesystem REQUIRED)
 include_directories(${Boost_INCLUDE_DIRS})
-set(LIBS ${LIBS} ${Boost_LIBRARIES})
+LINK_DIRECTORIES(${Boost_LIBRARY_DIRS})
 
 #
 # pkg-config file
diff --git a/unitTesting/CMakeLists.txt b/unitTesting/CMakeLists.txt
index 41cc0cff..40ec196f 100644
--- a/unitTesting/CMakeLists.txt
+++ b/unitTesting/CMakeLists.txt
@@ -13,6 +13,14 @@ SET(TEST_tsot_LIBS
 	gain-adaptive
 )
 
+SET(TEST_files_LIBS
+	${Boost_LIBRARIES}
+)
+
+SET(TEST_traces_LIBS
+	${CMAKE_INSTALL_PREFIX}/lib/plugin/tracer.so
+)
+
 #test paths and names (without .cpp extension)
 SET (tests
 	link
@@ -22,7 +30,9 @@ SET (tests
 	signal/test_dep
 	sot/tsot
 	sot/test_solverSoth
-	factory/test_factory)
+	factory/test_factory
+	traces/files
+	traces/traces)
 
 FOREACH(test ${tests})
 	GET_FILENAME_COMPONENT(EXECUTABLE_NAME ${test} NAME)
diff --git a/unitTesting/factory/test_factory.cpp b/unitTesting/factory/test_factory.cpp
index 6715b292..e6fc23a4 100644
--- a/unitTesting/factory/test_factory.cpp
+++ b/unitTesting/factory/test_factory.cpp
@@ -105,9 +105,9 @@ if( NULL==dlib )
 
 
 #ifndef WIN32
-	dlib = dlopen(PLUGIN_LIB_INSTALL_PATH "/gain-adaptative.so", RTLD_NOW);
+	dlib = dlopen(PLUGIN_LIB_INSTALL_PATH "/gain-adaptive.so", RTLD_NOW);
 #else
-	dlib = LoadLibrary (PLUGIN_LIB_INSTALL_PATH "/gain-adaptative.lib");
+	dlib = LoadLibrary (PLUGIN_LIB_INSTALL_PATH "/gain-adaptive.lib");
 #endif
   if( NULL==dlib ) 
     {
diff --git a/unitTesting/traces/files.cpp b/unitTesting/traces/files.cpp
new file mode 100644
index 00000000..c91e38a3
--- /dev/null
+++ b/unitTesting/traces/files.cpp
@@ -0,0 +1,43 @@
+/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+ * Copyright Projet JRL 2007
+ *+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+ *
+ * File:      test_flags.cc
+ * Project:   sot
+ * Author:    Nicolas Mansard
+ *
+ * Version control
+ * ===============
+ *
+ *  $Id$
+ *
+ * Description
+ * ============
+ *
+ *
+ * ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
+//#undef WITH_OPENHRP
+
+#include <iostream>
+#include <sot-core/debug.h>
+
+#include <boost/filesystem/path.hpp>
+#include <boost/filesystem/operations.hpp>
+
+using namespace std;
+
+int main()
+{
+  
+    boost::filesystem::create_directory( "foobar" );
+    ofstream file( "foobar/cheeze" );
+    file << "tastes good!\n";
+    file.close();
+    if ( !boost::filesystem::exists( "foobar/cheeze" ) )
+      std::cout << "Something is rotten in foobar\n";
+
+
+
+  return 0;
+}
+ 
diff --git a/unitTesting/traces/traces.cpp b/unitTesting/traces/traces.cpp
new file mode 100644
index 00000000..5b4005d0
--- /dev/null
+++ b/unitTesting/traces/traces.cpp
@@ -0,0 +1,58 @@
+/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+ * Copyright Projet JRL 2007
+ *+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+ *
+ * File:      test_traces.cpp
+ * Project:   sot
+ * Author:    Nicolas Mansard
+ *
+ * Version control
+ * ===============
+ *
+ *  $Id$
+ *
+ * Description
+ * ============
+ *
+ *
+ * ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
+
+#include <iostream>
+
+#include <sot-core/debug.h>
+#include <dynamic-graph/signal-base.h>
+#include <dynamic-graph/signal.h>
+#include <dynamic-graph/signal-time-dependent.h>
+#include <dynamic-graph/tracer.h>
+#include <MatrixAbstractLayer/boost.h>
+namespace ml = maal::boost;
+
+using namespace std;
+using namespace dynamicgraph;
+using namespace sot;
+
+double& f( double& res,const int& t ) { cout << "SIGM!"<<endl; return res; }
+
+int main()
+{
+  Signal<ml::Vector,int> sig1( "sig1" );
+  ml::Vector v1(2); v1.fill(1.1); sig1 = v1;
+
+  Signal<ml::Vector,int> sig2( "sig2" );
+  ml::Vector v2(4); v2.fill(2.); sig2 = v2;
+
+  Signal<ml::Vector,int> sig3( "sig3" );
+  ml::Vector v3(6); v3.fill(3.); sig3 = v3;
+
+  SignalTimeDependent<double,int> sigM( f,sotNOSIGNAL,"sigM" );
+  sigM.access(0);
+  
+  Tracer tracer( "trace" );
+  tracer.addSignalToTrace( sig1 );
+  tracer.openFiles( "/tmp/sot-core","tr_",".dat" );
+  
+  tracer.addSignalToTrace( sig2 );
+
+  return 0;
+}
+ 
-- 
GitLab