2008-03-19 12:29:14 +01:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2008 Patrick Ohly
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef INCL_SYNCEVOLUTION_UTIL
|
|
|
|
# define INCL_SYNCEVOLUTION_UTIL
|
|
|
|
|
2008-03-25 22:54:05 +01:00
|
|
|
#include <base/test.h>
|
|
|
|
|
2008-03-19 12:29:14 +01:00
|
|
|
#include <sstream>
|
2008-03-19 15:35:22 +01:00
|
|
|
#include <string>
|
2008-03-19 12:29:14 +01:00
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
template<class T> string join(const string &sep, T begin, T end)
|
|
|
|
{
|
|
|
|
stringstream res;
|
|
|
|
|
|
|
|
if (begin != end) {
|
|
|
|
res << *begin;
|
|
|
|
++begin;
|
|
|
|
while (begin != end) {
|
|
|
|
res << sep;
|
|
|
|
res << *begin;
|
|
|
|
++begin;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return res.str();
|
|
|
|
}
|
|
|
|
|
2008-03-19 15:35:22 +01:00
|
|
|
/**
|
|
|
|
* remove multiple slashes in a row and dots directly after a slash if not followed by filename,
|
|
|
|
* remove trailing /
|
|
|
|
*/
|
|
|
|
inline string normalizePath(const string &path) {
|
|
|
|
string res;
|
|
|
|
|
|
|
|
res.reserve(path.size());
|
|
|
|
size_t index = 0;
|
|
|
|
while (index < path.size()) {
|
|
|
|
char curr = path[index];
|
|
|
|
res += curr;
|
|
|
|
index++;
|
|
|
|
if (curr == '/') {
|
|
|
|
while (index < path.size() &&
|
|
|
|
(path[index] == '/' ||
|
|
|
|
(path[index] == '.' &&
|
|
|
|
index + 1 < path.size() &&
|
|
|
|
(path[index + 1] == '.' ||
|
|
|
|
path[index + 1] == '/')))) {
|
|
|
|
index++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!res.empty() && res[res.size() - 1] == '/') {
|
|
|
|
res.resize(res.size() - 1);
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2008-03-25 22:54:05 +01:00
|
|
|
/**
|
|
|
|
* Using this macro ensures that tests, even if defined in
|
|
|
|
* object files which are not normally linked into the test
|
|
|
|
* binary, are included in the test suite under the group
|
|
|
|
* "SyncEvolution".
|
|
|
|
*/
|
|
|
|
#define SYNCEVOLUTION_TEST_SUITE_REGISTRATION( ATestFixtureType ) \
|
|
|
|
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( ATestFixtureType, "SyncEvolution" ); \
|
|
|
|
extern "C" { int funambolAutoRegisterRegistry ## ATestFixtureType = 12345; }
|
|
|
|
|
2008-03-19 15:35:22 +01:00
|
|
|
|
2008-03-19 12:29:14 +01:00
|
|
|
#endif // INCL_SYNCEVOLUTION_UTIL
|