summaryrefslogtreecommitdiff
path: root/libs
diff options
context:
space:
mode:
authorTim Mayberry <mojofunk@gmail.com>2014-12-02 20:40:50 +0700
committerTim Mayberry <mojofunk@gmail.com>2014-12-03 17:44:48 +0700
commit0ec85a4164e87de632db42a4769a9d20443ccb98 (patch)
tree943ca48a353ab56b7ef315f5c78724ca83883d31 /libs
parentdd976d8c7aece4c82b6abcc632f7ec002adeb8d6 (diff)
Fix running libpbd unit tests when $TOP(in test scripts) is set as relative path
Add test for PBD::canonical_path that was used to track down silly mistake in test code
Diffstat (limited to 'libs')
-rw-r--r--libs/pbd/test/filesystem_test.cc34
-rw-r--r--libs/pbd/test/filesystem_test.h2
2 files changed, 36 insertions, 0 deletions
diff --git a/libs/pbd/test/filesystem_test.cc b/libs/pbd/test/filesystem_test.cc
index 781e2bdafe..28ba11329b 100644
--- a/libs/pbd/test/filesystem_test.cc
+++ b/libs/pbd/test/filesystem_test.cc
@@ -10,6 +10,7 @@
#include <glibmm/fileutils.h>
#include "pbd/file_utils.h"
+#include "pbd/pathexpand.h"
#include "test_common.h"
@@ -23,6 +24,8 @@ FilesystemTest::testPathIsWithin ()
{
#ifndef PLATFORM_WINDOWS
string output_path = test_output_directory ("testPathIsWithin");
+ string orig_path = Glib::get_current_dir ();
+
CPPUNIT_ASSERT (g_chdir (output_path.c_str()) == 0);
CPPUNIT_ASSERT (g_mkdir_with_parents ("foo/bar/baz", 0755) == 0);
@@ -45,6 +48,7 @@ FilesystemTest::testPathIsWithin ()
CPPUNIT_ASSERT (PBD::path_is_within ("foo/bar", "foo/bar"));
CPPUNIT_ASSERT (PBD::path_is_within ("foo/jim/baz", "frobozz") == false);
+ CPPUNIT_ASSERT (g_chdir (orig_path.c_str()) == 0);
#endif
}
@@ -205,3 +209,33 @@ FilesystemTest::testRemoveDirectory ()
CPPUNIT_ASSERT (files_in_output_dir.size () == 0);
}
+
+void
+FilesystemTest::testCanonicalPath ()
+{
+#ifndef PLATFORM_WINDOWS
+ string top_dir = test_output_directory ("testCanonicalPath");
+ string orig_path = Glib::get_current_dir ();
+
+ CPPUNIT_ASSERT (g_chdir (top_dir.c_str()) == 0);
+
+ string pwd = Glib::get_current_dir ();
+
+ CPPUNIT_ASSERT (!pwd.empty());
+ CPPUNIT_ASSERT (pwd == top_dir);
+
+ CPPUNIT_ASSERT (g_mkdir ("gtk2_ardour", 0755) == 0);
+ CPPUNIT_ASSERT (g_mkdir_with_parents ("libs/pbd/test", 0755) == 0);
+
+ const char* relative_path = "./gtk2_ardour/../libs/pbd/test";
+ string canonical_path = PBD::canonical_path (relative_path);
+ // no expansion expected in this case
+ string expanded_path = PBD::path_expand (relative_path);
+ string expected_path = top_dir + string("/libs/pbd/test");
+
+ CPPUNIT_ASSERT (canonical_path == expected_path);
+ CPPUNIT_ASSERT (expanded_path == expected_path);
+
+ CPPUNIT_ASSERT (g_chdir (orig_path.c_str()) == 0);
+#endif
+}
diff --git a/libs/pbd/test/filesystem_test.h b/libs/pbd/test/filesystem_test.h
index 45d55a673a..180149dd36 100644
--- a/libs/pbd/test/filesystem_test.h
+++ b/libs/pbd/test/filesystem_test.h
@@ -10,6 +10,7 @@ class FilesystemTest : public CppUnit::TestFixture
CPPUNIT_TEST (testFindFilesMatchingPattern);
CPPUNIT_TEST (testClearDirectory);
CPPUNIT_TEST (testRemoveDirectory);
+ CPPUNIT_TEST (testCanonicalPath);
CPPUNIT_TEST_SUITE_END ();
public:
@@ -19,5 +20,6 @@ public:
void testFindFilesMatchingPattern ();
void testClearDirectory ();
void testRemoveDirectory ();
+ void testCanonicalPath ();
};