From 04837d784b0aa179c609f7c1f674f6b232f28f8e Mon Sep 17 00:00:00 2001
From: Francois Bleibel <fbleibel@gmail.com>
Date: Fri, 25 Jun 2010 14:20:00 +0900
Subject: [PATCH] Added two unit tests, removed a tool

---
 include/sot-core/feature-task.h               |  1 +
 include/sot-core/utils-windows.h              | 27 ++++++
 src/task/task-abstract.cpp                    |  1 +
 tools/CMakeLists.txt                          |  5 +-
 tools/sot/Makefile.in                         | 36 --------
 unitTesting/CMakeLists.txt                    | 15 +++-
 .../sot/test_solverSoth.cpp                   | 83 ++++++++++---------
 {tools => unitTesting}/sot/tsot.cpp           |  0
 8 files changed, 89 insertions(+), 79 deletions(-)
 create mode 100644 include/sot-core/utils-windows.h
 delete mode 100644 tools/sot/Makefile.in
 rename {tools => unitTesting}/sot/test_solverSoth.cpp (86%)
 rename {tools => unitTesting}/sot/tsot.cpp (100%)

diff --git a/include/sot-core/feature-task.h b/include/sot-core/feature-task.h
index 979f89d7..f567ccd7 100644
--- a/include/sot-core/feature-task.h
+++ b/include/sot-core/feature-task.h
@@ -49,6 +49,7 @@
 /* --------------------------------------------------------------------- */
 
 namespace sot {
+namespace dg = dynamicgraph;
 
 class SOTFEATURETASK_EXPORT FeatureTask 
 : public FeatureGeneric
diff --git a/include/sot-core/utils-windows.h b/include/sot-core/utils-windows.h
new file mode 100644
index 00000000..7a70dbaf
--- /dev/null
+++ b/include/sot-core/utils-windows.h
@@ -0,0 +1,27 @@
+/*
+ * utils-windows.h
+ *
+ *  Created on: Jun 25, 2010
+ *      Author: blue
+ */
+
+#ifndef UTILSWINDOWS_H_
+#define UTILSWINDOWS_H_
+
+#ifdef WIN32
+
+#include <sot-core/sot-core-api.h>
+
+#include < time.h >
+
+struct SOT_EXPORT timezone
+{
+  int  tz_minuteswest; /* minutes W of Greenwich */
+  int  tz_dsttime;     /* type of dst correction */
+};
+
+int SOT_EXPORT gettimeofday(struct timeval *tv, struct timezone *tz);
+
+#endif /*WIN32*/
+
+#endif /* UTILSWINDOWS_H_ */
diff --git a/src/task/task-abstract.cpp b/src/task/task-abstract.cpp
index daa6a445..a39f462c 100644
--- a/src/task/task-abstract.cpp
+++ b/src/task/task-abstract.cpp
@@ -28,6 +28,7 @@
 using namespace sot;
 using namespace dynamicgraph;
 
+
 /* --------------------------------------------------------------------- */
 /* --- CLASS ----------------------------------------------------------- */
 /* --------------------------------------------------------------------- */
diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt
index c6e574eb..0fd4e127 100644
--- a/tools/CMakeLists.txt
+++ b/tools/CMakeLists.txt
@@ -3,6 +3,9 @@
 # 
 
 ### tools
+
+#The sot-core plugin libraries that tools have to be linked against
+#There is currently no way to define separate libraries for separate tools.
 SET(TEST_LINK_LIBRARIES 
 	task
 	feature-visual-point
@@ -10,7 +13,7 @@ SET(TEST_LINK_LIBRARIES
 )
 
 SET(tools
-	sot/tsot
+	""
 )
 
 FOREACH(tool_name ${tools})
diff --git a/tools/sot/Makefile.in b/tools/sot/Makefile.in
deleted file mode 100644
index bb2f1fb8..00000000
--- a/tools/sot/Makefile.in
+++ /dev/null
@@ -1,36 +0,0 @@
-
-@build_mk@
-
-CXXFLAGS += $(INCLUDE)
-LDFLAGS += $(LIBPATH)
-LIBS += $(LIB) $(LIBS_FLAGS)
-
-MAINS		= tsot.cpp 
-LOCAL_DIR_BIN = $(PROJECT_TESTS_PATH)/bin
-
-tsot_OBJ     = 
-tsot_EXT_CLASS = sotTask sotFeatureVisualPoint sotGainAdaptative
-tsot_EXT_OBJ = $(tsot_EXT_CLASS:%=$(PROJECT_PLUGIN_PATH)/%.so)
-
-.DEFAULT: all
-all: install
-
-@directory_mk@
-
-@bin_mk@
-
-install: directory  $(LOCAL_DIR_BIN)_MKDIR $(PROGS_EXE) 
-
-$(VISP_LIBNAME):
-	cd $(VISP_DIR_SRC); $(MAKE)
-
-
-uninstall:
-	rm -f $(PROGS)
-	rm -f $(DEPFILES)
-	rm -rf $(LOCAL_DEP_PATH) $(LOCAL_OBJ_PATH)
-
-@clean_mk@
-
-@depend_mk@
-
diff --git a/unitTesting/CMakeLists.txt b/unitTesting/CMakeLists.txt
index e8317b8f..ec704265 100644
--- a/unitTesting/CMakeLists.txt
+++ b/unitTesting/CMakeLists.txt
@@ -2,12 +2,23 @@
 #  Copyright 
 # 
 
+#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 
+	task
+	feature-visual-point
+	gain-adaptative
+)
+
+#test paths and names (without .cpp extension)
 SET (tests
 	main
 	signal/test_signal
 	signal/test_depend
 	signal/test_ptr
-	signal/test_dep)
+	signal/test_dep
+	sot/tsot
+	sot/test_solverSoth)
 
 FOREACH(test ${tests})
 	GET_FILENAME_COMPONENT(EXECUTABLE_NAME ${test} NAME)
@@ -47,6 +58,8 @@ FOREACH(test ${tests})
 		dl)
 	ENDIF(UNIX)
 	
+	TARGET_LINK_LIBRARIES(${EXECUTABLE_NAME} ${TEST_${EXECUTABLE_NAME}_LIBS})
+	
 	ADD_TEST(${test} ${EXECUTABLE_NAME})
 
 ENDFOREACH(test)
diff --git a/tools/sot/test_solverSoth.cpp b/unitTesting/sot/test_solverSoth.cpp
similarity index 86%
rename from tools/sot/test_solverSoth.cpp
rename to unitTesting/sot/test_solverSoth.cpp
index 95403d9f..ed0179df 100644
--- a/tools/sot/test_solverSoth.cpp
+++ b/unitTesting/sot/test_solverSoth.cpp
@@ -1,8 +1,7 @@
 //#define VP_DEBUG
 #define VP_DEBUG_MODE 45
-#include <sot/sotDebug.h>
-
-#include <sot/sotSolverHierarchicalInequalities.h>
+#include <sot-core/debug.h>
+#include <sot-core/solver-hierarchical-inequalities.h>
 #include <fstream>
 
 
@@ -11,11 +10,13 @@
 #else /*WIN32*/
 // When including Winsock2.h, the MAL must be included first
 //#include <MatrixAbstractLayer/boost.h>
-#  include <sot/sotUtilsWindows.h>
+#  include <sot-core/utils-windows.h>
 #  include <Winsock2.h>
 #endif /*WIN32*/
 //#define WITH_CHRONO
 
+using namespace sot;
+
 /* ---------------------------------------------------------- */
 /* ---------------------------------------------------------- */
 /* ---------------------------------------------------------- */
@@ -27,26 +28,26 @@ void parseTest( const std::string filename )
   std::string bs;
 
   bubMatrix Rh;
-  sotSolverHierarchicalInequalities::ConstraintList constraintH;
+  SolverHierarchicalInequalities::ConstraintList constraintH;
   std::vector<bubMatrix> Jes;
   std::vector<bubVector> ees;
   std::vector<bubMatrix> Jis;
   std::vector<bubVector> eiInfs;
   std::vector<bubVector> eiSups;
-  std::vector<sotConstraintMem::BoundSideVector> bounds;
+  std::vector<ConstraintMem::BoundSideVector> bounds;
 
   int nJ;
   int me,mi;
   bubMatrix Je,Ji;
   bubVector ee,eiInf,eiSup;
-  sotConstraintMem::BoundSideVector eiBoundSide;
+  ConstraintMem::BoundSideVector eiBoundSide;
 
   off >> bs; if(bs!="variable") { cerr << "!! '" << bs << "'" << endl; return; }
   off >> bs; if(bs!="size") { cerr << "!! '" << bs << "'" << endl; return; }
   off >> nJ;
 
   sotRotationComposedInExtenso Qh(nJ);
-  std::deque<sotSolverHierarchicalInequalities*> solvers;
+  std::deque<SolverHierarchicalInequalities*> solvers;
 
   for( unsigned int level=0;;++level )
     {
@@ -75,19 +76,19 @@ void parseTest( const std::string filename )
             for( int j=0;j<nJ;++j )
               off >> Ji(i,j);
             std::string number;
-            eiBoundSide[i] = sotConstraintMem::BOUND_VOID;
+            eiBoundSide[i] = ConstraintMem::BOUND_VOID;
             off>>number;
             if( number!="X" )
               {
-                eiBoundSide[i] = (sotConstraintMem::BoundSideType)
-                  (eiBoundSide[i]|sotConstraintMem::BOUND_INF);
+                eiBoundSide[i] = (ConstraintMem::BoundSideType)
+                  (eiBoundSide[i]|ConstraintMem::BOUND_INF);
                 eiInf(i) = atof(number.c_str());
               } else { eiInf(i) = 1e-66; }
             off>>number;
             if( number!="X" )
               {
-                eiBoundSide[i] = (sotConstraintMem::BoundSideType)
-                  (eiBoundSide[i]|sotConstraintMem::BOUND_SUP);
+                eiBoundSide[i] = (ConstraintMem::BoundSideType)
+                  (eiBoundSide[i]|ConstraintMem::BOUND_SUP);
                 eiSup(i) = atof(number.c_str());
               } else { eiSup(i) = 1e-66; }
           }
@@ -113,13 +114,13 @@ void parseTest( const std::string filename )
       bounds.push_back(eiBoundSide);
 
       sotDEBUG(1) << "--- Level " << level << std::endl;
-      sotSolverHierarchicalInequalities * solver
-        = new sotSolverHierarchicalInequalities(nJ,Qh,Rh,constraintH);
+      SolverHierarchicalInequalities * solver
+        = new SolverHierarchicalInequalities(nJ,Qh,Rh,constraintH);
       solver->initConstraintSize(Je.size1()+Ji.size1());
       if( solvers.size()==0 ) solver->setInitialConditionVoid();
       else
         {
-          sotSolverHierarchicalInequalities * solverPrec
+          SolverHierarchicalInequalities * solverPrec
             = solvers.back();
           solver->setInitialCondition( solverPrec->u0,solverPrec->rankh );
         }
@@ -152,11 +153,11 @@ void parseTest( const std::string filename )
         {
           gettimeofday(&t0,NULL);
           sotDEBUG(1) << "--- Level " << level << std::endl;
-          sotSolverHierarchicalInequalities * solver = solvers[level];
+          SolverHierarchicalInequalities * solver = solvers[level];
           if( level==0 ) solver->setInitialConditionVoid();
           else
             {
-              sotSolverHierarchicalInequalities * solverPrec = solvers[level-1];
+              SolverHierarchicalInequalities * solverPrec = solvers[level-1];
               solver->setInitialCondition( solverPrec->u0,solverPrec->rankh );
             }
 
@@ -202,7 +203,7 @@ void parseTest( const std::string filename )
 /* ---------------------------------------------------------- */
 void deparse( std::vector<bubMatrix> Jes,std::vector<bubVector> ees,
               std::vector<bubMatrix> Jis,std::vector<bubVector> eiInfs,
-              std::vector<bubVector> eiSups,std::vector<sotConstraintMem::BoundSideVector> bounds )
+              std::vector<bubVector> eiSups,std::vector<ConstraintMem::BoundSideVector> bounds )
 {
   using namespace std;
   cout << "variable size " << Jes[0].size2() << endl;
@@ -214,7 +215,7 @@ void deparse( std::vector<bubMatrix> Jes,std::vector<bubVector> ees,
       bubVector & ee = ees[i];
       bubVector & eiInf = eiInfs[i];
       bubVector & eiSup = eiSups[i];
-      sotConstraintMem::BoundSideVector & boundSide = bounds[i];
+      ConstraintMem::BoundSideVector & boundSide = bounds[i];
 
       cout <<  endl << endl << "level" << endl << endl << "equalities " << ee.size() << endl;
       if(ee.size()>0)
@@ -228,21 +229,21 @@ void deparse( std::vector<bubMatrix> Jes,std::vector<bubVector> ees,
       unsigned int nbIneq = 0;
       for( unsigned int i=0;i<boundSide.size();++i )
         {
-          if( boundSide[i]&sotConstraintMem::BOUND_INF ) nbIneq++;
-          if( boundSide[i]&sotConstraintMem::BOUND_SUP ) nbIneq++;
+          if( boundSide[i]&ConstraintMem::BOUND_INF ) nbIneq++;
+          if( boundSide[i]&ConstraintMem::BOUND_SUP ) nbIneq++;
         }
 
       cout << endl << "inequalities " << nbIneq << endl;
       if(eiInf.size()>0)
         for( unsigned int i=0;i<eiInf.size();++i )
           {
-            if( boundSide[i]&sotConstraintMem::BOUND_INF )
+            if( boundSide[i]&ConstraintMem::BOUND_INF )
               {
                 for( unsigned int j=0;j<Ji.size2();++j )
                   cout << -Ji(i,j) << " ";
                 cout << "\t" << " X " <<  -eiInf(i) << endl;
               }
-            if( boundSide[i]&sotConstraintMem::BOUND_SUP )
+            if( boundSide[i]&ConstraintMem::BOUND_SUP )
               {
                 for( unsigned int j=0;j<Ji.size2();++j )
                   cout << Ji(i,j) << " ";
@@ -264,7 +265,7 @@ void convertDoubleToSingle( const std::string filename )
   int me,mi;
   bubMatrix Je,Ji;
   bubVector ee,eiInf,eiSup;
-  sotConstraintMem::BoundSideVector eiBoundSide;
+  ConstraintMem::BoundSideVector eiBoundSide;
 
   off >> bs; if(bs!="variable") { cerr << "!! '" << bs << "'" << endl; return; }
   off >> bs; if(bs!="size") { cerr << "!! '" << bs << "'" << endl; return; }
@@ -276,7 +277,7 @@ void convertDoubleToSingle( const std::string filename )
   std::vector<bubMatrix> Jis;
   std::vector<bubVector> eiInfs;
   std::vector<bubVector> eiSups;
-  std::vector<sotConstraintMem::BoundSideVector> bounds;
+  std::vector<ConstraintMem::BoundSideVector> bounds;
 
   for( unsigned int level=0;;++level )
     {
@@ -303,17 +304,17 @@ void convertDoubleToSingle( const std::string filename )
             for( int j=0;j<nJ;++j )
               off >> Ji(i,j);
             std::string number;
-            eiBoundSide[i] = sotConstraintMem::BOUND_VOID;
+            eiBoundSide[i] = ConstraintMem::BOUND_VOID;
             off>>number; // std::cout << "toto '" << number << "'" << std::endl;
             if( number!="X" )
               {
-                eiBoundSide[i] = (sotConstraintMem::BoundSideType)(eiBoundSide[i]|sotConstraintMem::BOUND_INF);
+                eiBoundSide[i] = (ConstraintMem::BoundSideType)(eiBoundSide[i]|ConstraintMem::BOUND_INF);
                 eiInf(i) = atof(number.c_str());
               } else { eiInf(i) = 1e-66; }
             off>>number;
             if( number!="X" )
               {
-                eiBoundSide[i] = (sotConstraintMem::BoundSideType)(eiBoundSide[i]|sotConstraintMem::BOUND_SUP);
+                eiBoundSide[i] = (ConstraintMem::BoundSideType)(eiBoundSide[i]|ConstraintMem::BOUND_SUP);
                 eiSup(i) = atof(number.c_str());
               } else { eiSup(i) = 1e-66; }
           }
@@ -334,14 +335,14 @@ void convertDoubleToSingle( const std::string filename )
 /* ---------------------------------------------------------- */
 /* ---------------------------------------------------------- */
 /* ---------------------------------------------------------- */
-void randBound( sotConstraintMem::BoundSideVector& M,const unsigned int row)
+void randBound( ConstraintMem::BoundSideVector& M,const unsigned int row)
 {
   M.resize(row);
   for( unsigned int i=0;i<row;++i )
     {
       double c = ((rand()+0.0)/RAND_MAX*2)-1.;
-      if( c<0 ) M[i] = sotConstraintMem::BOUND_INF;
-      else M[i] = sotConstraintMem::BOUND_SUP;
+      if( c<0 ) M[i] = ConstraintMem::BOUND_INF;
+      else M[i] = ConstraintMem::BOUND_SUP;
     }
 }
 
@@ -349,7 +350,7 @@ void randTest( const unsigned int nJ,const bool enableSolve[]  )
 {
   bubVector eiInf0(nJ),ee0(1),eiSup0(nJ);
   bubMatrix Ji0(nJ,nJ),Je0(1,nJ);
-  sotConstraintMem::BoundSideVector bound0(nJ,sotConstraintMem::BOUND_INF);
+  ConstraintMem::BoundSideVector bound0(nJ,ConstraintMem::BOUND_INF);
   Ji0.assign( bub::identity_matrix<double>(nJ));
   eiInf0.assign( bub::zero_vector<double>(nJ));
   Je0.assign( bub::zero_matrix<double>(1,nJ));
@@ -358,7 +359,7 @@ void randTest( const unsigned int nJ,const bool enableSolve[]  )
 
   bubVector ee1,eiInf1,eiSup1;
   bubMatrix Je1,Ji1;
-  sotConstraintMem::BoundSideVector bound1;
+  ConstraintMem::BoundSideVector bound1;
   randVector(ee1,3); sotDEBUG(15) << "ee1 = " << (MATLAB)ee1 << std::endl;
   randVector(eiInf1,3); sotDEBUG(15) << "eiInf1 = " << (MATLAB)eiInf1 << std::endl;
   randVector(eiSup1,3); sotDEBUG(15) << "eiSup1 = " << (MATLAB)eiSup1 << std::endl;
@@ -375,7 +376,7 @@ void randTest( const unsigned int nJ,const bool enableSolve[]  )
 
   bubVector ee2,eiInf2,eiSup2;
   bubMatrix Je2,Ji2;
-  sotConstraintMem::BoundSideVector bound2;
+  ConstraintMem::BoundSideVector bound2;
   randVector(ee2,3); sotDEBUG(15) << "ee2 = " << (MATLAB)ee2 << std::endl;
   randVector(eiInf2,3); sotDEBUG(15) << "eiInf2 = " << (MATLAB)eiInf2 << std::endl;
   randVector(eiSup2,3); sotDEBUG(15) << "eiSup2 = " << (MATLAB)eiSup2 << std::endl;
@@ -385,7 +386,7 @@ void randTest( const unsigned int nJ,const bool enableSolve[]  )
 
   bubVector ee3,eiInf3,eiSup3;
   bubMatrix Je3,Ji3;
-  sotConstraintMem::BoundSideVector bound3;
+  ConstraintMem::BoundSideVector bound3;
   randVector(ee3,3); sotDEBUG(15) << "ee3 = " << (MATLAB)ee3 << std::endl;
   randVector(eiInf3,3); sotDEBUG(15) << "eiInf3 = " << (MATLAB)eiInf3 << std::endl;
   randVector(eiSup3,3); sotDEBUG(15) << "eiSup3 = " << (MATLAB)eiSup3 << std::endl;
@@ -395,7 +396,7 @@ void randTest( const unsigned int nJ,const bool enableSolve[]  )
 
   bubVector ee4(nJ),eiInf4(1),eiSup4(1);
   bubMatrix Je4(nJ,nJ),Ji4(1,nJ);
-  sotConstraintMem::BoundSideVector bound4(1,sotConstraintMem::BOUND_INF);
+  ConstraintMem::BoundSideVector bound4(1,ConstraintMem::BOUND_INF);
   Je4.assign( bub::identity_matrix<double>(nJ));
   ee4.assign( bub::zero_vector<double>(nJ));
   Ji4.assign( bub::zero_matrix<double>(1,nJ));
@@ -408,7 +409,7 @@ void randTest( const unsigned int nJ,const bool enableSolve[]  )
   std::vector<bubMatrix> Jis;
   std::vector<bubVector> eiInfs;
   std::vector<bubVector> eiSups;
-  std::vector<sotConstraintMem::BoundSideVector> bounds;
+  std::vector<ConstraintMem::BoundSideVector> bounds;
 
   if(enableSolve[0])
     {
@@ -460,8 +461,8 @@ void randTest( const unsigned int nJ,const bool enableSolve[]  )
 
   sotRotationComposedInExtenso Qh(nJ);
   bubMatrix Rh;
-  sotSolverHierarchicalInequalities::ConstraintList constraintH;
-  sotSolverHierarchicalInequalities solver(nJ,Qh,Rh,constraintH);
+  SolverHierarchicalInequalities::ConstraintList constraintH;
+  SolverHierarchicalInequalities solver(nJ,Qh,Rh,constraintH);
   solver.initConstraintSize((40+6+6+6+40)+2);
 
 
@@ -504,7 +505,7 @@ int main( void )
   for(int i=0;i<10;++i)
 #endif
 #endif
-      parseTest("/home/nmansard/src/StackOfTasks/tests/sot/t.txt");
+      parseTest("/home/nmansard/src/StackOfTasks/tests//t.txt");
 //   bool enable [5] ={ 1,1,0,0,0};
 //   randTest(9,enable );
 }
diff --git a/tools/sot/tsot.cpp b/unitTesting/sot/tsot.cpp
similarity index 100%
rename from tools/sot/tsot.cpp
rename to unitTesting/sot/tsot.cpp
-- 
GitLab