switch to using boost::filesystem
[mussa.git] / alg / test / test_mussa.cpp
index 852d2fd0aa98bb80f67d95d3ebbf2d7de9255ba8..04886a0a1fd5675438d807576e481fc03ae60e90 100644 (file)
@@ -1,4 +1,6 @@
 #include <boost/test/auto_unit_test.hpp>
+#include <boost/filesystem/operations.hpp>
+namespace fs = boost::filesystem;
 
 #include <string>
 #include <sstream>
@@ -75,22 +77,21 @@ BOOST_AUTO_TEST_CASE ( empty_mussa_set_threshold )
   m.nway();
 }
 
-#include <unistd.h>
 BOOST_AUTO_TEST_CASE( mussa_load_mupa )
 {
+  fs::path mupa_path(EXAMPLE_DIR);
+  mupa_path /= "mck3test.mupa";
+
   Mussa m1;
-  chdir( "examples" );
-  m1.load_mupa_file( "mck3test.mupa" );
+  m1.load_mupa_file( mupa_path );
   m1.analyze(0, 0);
   BOOST_CHECK_EQUAL( m1.get_name(), std::string("mck3test") );
   BOOST_CHECK( m1.size() > 0 );
 
   Mussa m2;
-  std::string saved_analysis_path("mck3test_w30_t20");
-  m2.load( saved_analysis_path  );
-  chdir( ".." );
-
-  BOOST_CHECK_EQUAL( m2.get_name(), saved_analysis_path );
+  fs::path result_path = fs::initial_path() / "mck3test_w30_t20";
+  m2.load( result_path );
+  BOOST_CHECK_EQUAL( m2.get_name(), result_path.leaf() );
   BOOST_CHECK_EQUAL( m1.size(), m2.size() );
 
 }
@@ -98,14 +99,8 @@ BOOST_AUTO_TEST_CASE( mussa_load_mupa )
 BOOST_AUTO_TEST_CASE( mussa_load_full_path )
 {
   Mussa m1;
-  chdir( "examples" );
-  const int bufsize = 1024;
-  char path_buf[bufsize];
-  getcwd(path_buf, bufsize);
-  std::string path(path_buf);
-  chdir( ".." );
-  path += "/mck3test.mupa";
-  m1.load_mupa_file( path );
+  fs::path full_path(fs::path(EXAMPLE_DIR) / "mck3test.mupa");
+  m1.load_mupa_file( full_path );
   m1.analyze(0, 0);
 
   BOOST_CHECK( m1.size() > 0);
@@ -115,18 +110,13 @@ BOOST_AUTO_TEST_CASE( mussa_load_full_path )
 
 BOOST_AUTO_TEST_CASE( mussa_load_analysis )
 {
+  fs::path example_dir(EXAMPLE_DIR);
   Mussa m1;
-  chdir( "examples" );
-  const int bufsize = 1024;
-  char path_buf[bufsize];
-  getcwd(path_buf, bufsize);
-  std::string base_path(path_buf);
-  chdir( ".." );
-  m1.load_mupa_file( base_path + "/mck3test.mupa" );
+  m1.load_mupa_file( example_dir / "mck3test.mupa" );
   m1.analyze(0, 0);
 
   Mussa m2;
-  m2.load(base_path + "/mck3test_w30_t20");
+  m2.load( example_dir / "mck3test_w30_t20");
 
   BOOST_CHECK_EQUAL( m1.size(), m2.size() );
   BOOST_CHECK_EQUAL( m1.get_window(), m2.get_window() );