Modify NormalizePath to work with boost 1.33.1, add regressions test

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@13297 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Lars Gullik Bjønnes 2006-03-05 18:11:11 +00:00
parent 3f103ffaa7
commit c0ce7ff659
7 changed files with 77 additions and 35 deletions

View File

@ -1,3 +1,8 @@
2006-03-05 Lars Gullik Bjønnes <larsbj@lyx.org>
* filetools.C (NormalizePath): Change to use boost::filesystem and
alter regex usage in preparation for boost 1.33.1.
2006-02-12 Jean-Marc Lasgouttes <lasgouttes@lyx.org> 2006-02-12 Jean-Marc Lasgouttes <lasgouttes@lyx.org>
* package.C.in (relative_system_support_dir): fix for win32 and * package.C.in (relative_system_support_dir): fix for win32 and

View File

@ -594,42 +594,16 @@ string const ExpandPath(string const & path)
// Also converts paths like /foo//bar ==> /foo/bar // Also converts paths like /foo//bar ==> /foo/bar
string const NormalizePath(string const & path) string const NormalizePath(string const & path)
{ {
string TempBase; // Normalize paths like /foo//bar ==> /foo/bar
string RTemp; static boost::regex regex("/{2,}");
string Temp; string const tmppath = boost::regex_merge(path, regex, "/");
if (os::is_absolute_path(path)) fs::path const npath = fs::path(tmppath, fs::no_check).normalize();
RTemp = path;
else
// Make implicit current directory explicit
RTemp = "./" + path;
// Normalise paths like /foo//bar ==> /foo/bar if (!npath.is_complete())
boost::RegEx regex("/{2,}"); return "./" + npath.string() + '/';
RTemp = regex.Merge(RTemp, "/");
while (!RTemp.empty()) { return npath.string() + '/';
// Split by next /
RTemp = split(RTemp, Temp, '/');
if (Temp == ".") {
TempBase = "./";
} else if (Temp == "..") {
// Remove one level of TempBase
string::difference_type i = TempBase.length() - 2;
while (i > 0 && TempBase[i] != '/')
--i;
if (i >= 0 && TempBase[i] == '/')
TempBase.erase(i + 1, string::npos);
else
TempBase = "../";
} else {
TempBase += Temp + '/';
}
}
// returns absolute path
return TempBase;
} }

View File

@ -1,3 +1,13 @@
2006-03-05 Lars Gullik Bjønnes <larsbj@lyx.org>
* Makefile.am: update for filetools test
* filetools.C: test prog
* regfiles/filetools: regression data
* test_filetools: new test driver
2005-02-25 Lars Gullik Bjønnes <larsbj@gullik.net> 2005-02-25 Lars Gullik Bjønnes <larsbj@gullik.net>
* Makefile.am (makeregfiles): rename from regfiles * Makefile.am (makeregfiles): rename from regfiles

View File

@ -1,15 +1,17 @@
include $(top_srcdir)/config/common.am include $(top_srcdir)/config/common.am
EXTRA_DIST = pch.h test_convert test_lstrings regfiles EXTRA_DIST = pch.h test_convert test_filetools test_lstrings regfiles
BUILT_SOURCES = $(PCH_FILE) BUILT_SOURCES = $(PCH_FILE)
TESTS = \ TESTS = \
test_convert \ test_convert \
test_filetools \
test_lstrings test_lstrings
check_PROGRAMS = \ check_PROGRAMS = \
convert \ convert \
filetools \
lstrings lstrings
AM_CPPFLAGS += $(BOOST_INCLUDES) AM_CPPFLAGS += $(BOOST_INCLUDES)
@ -19,6 +21,11 @@ convert_SOURCES = \
convert.C \ convert.C \
boost.C boost.C
filetools_LDADD = ../../debug.o ../libsupport.la $(BOOST_REGEX) $(BOOST_FILESYSTEM)
filetools_SOURCES = \
filetools.C \
boost.C
lstrings_LDADD = ../lstrings.o lstrings_LDADD = ../lstrings.o
lstrings_SOURCES = \ lstrings_SOURCES = \
lstrings.C \ lstrings.C \

30
src/support/tests/filetools.C Executable file
View File

@ -0,0 +1,30 @@
#include "../filetools.h"
#include <iostream>
using namespace lyx::support;
using namespace std;
string _(string const & str)
{
return str;
}
void test_NormalizePath()
{
cout << NormalizePath("foo/../bar") << endl;
cout << NormalizePath("foo/./bar") << endl;
cout << NormalizePath("./foo/../bar") << endl;
cout << NormalizePath("./foo/./bar") << endl;
cout << NormalizePath("/foo/../bar") << endl;
cout << NormalizePath("/foo/./bar") << endl;
cout << NormalizePath("foo//bar") << endl;
cout << NormalizePath("./foo//bar") << endl;
cout << NormalizePath("/foo//bar") << endl;
}
int main()
{
test_NormalizePath();
}

View File

@ -0,0 +1,9 @@
./bar/
./foo/bar/
./bar/
./foo/bar/
/bar/
/foo/bar/
./foo/bar/
./foo/bar/
/foo/bar/

View File

@ -0,0 +1,7 @@
#!/bin/bash
regfile=`cat ${srcdir}/regfiles/filetools`
output=`./filetools`
test "$regfile" = "$output"
exit $?