2008-03-19 12:29:14 +01:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2008 Patrick Ohly
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef INCL_SYNCEVOLUTION_UTIL
|
|
|
|
# define INCL_SYNCEVOLUTION_UTIL
|
|
|
|
|
2008-03-25 22:54:05 +01:00
|
|
|
#include <base/test.h>
|
|
|
|
|
2008-07-06 22:26:23 +02:00
|
|
|
#include <boost/algorithm/string/case_conv.hpp>
|
2008-07-11 22:25:02 +02:00
|
|
|
#include <boost/algorithm/string/predicate.hpp>
|
2008-07-06 22:26:23 +02:00
|
|
|
|
2008-03-28 23:31:21 +01:00
|
|
|
#include <vector>
|
2008-03-19 12:29:14 +01:00
|
|
|
#include <sstream>
|
2008-03-19 15:35:22 +01:00
|
|
|
#include <string>
|
2008-07-11 22:25:02 +02:00
|
|
|
#include <utility>
|
2008-03-19 12:29:14 +01:00
|
|
|
using namespace std;
|
|
|
|
|
2008-07-11 22:25:02 +02:00
|
|
|
/** case-insensitive less than for assoziative containers */
|
2008-07-06 22:26:23 +02:00
|
|
|
template <class T> class Nocase : public std::binary_function<T, T, bool> {
|
|
|
|
public:
|
2008-07-11 22:25:02 +02:00
|
|
|
bool operator()(const T &x, const T &y) const { return boost::ilexicographical_compare(x, y); }
|
2008-07-06 22:26:23 +02:00
|
|
|
};
|
|
|
|
|
2008-07-11 22:25:02 +02:00
|
|
|
/** case-insensitive equals */
|
|
|
|
template <class T> class Iequals : public std::binary_function<T, T, bool> {
|
|
|
|
public:
|
|
|
|
bool operator()(const T &x, const T &y) const { return boost::iequals(x, y); }
|
|
|
|
};
|
|
|
|
|
|
|
|
/** shorthand, primarily useful for BOOST_FOREACH macro */
|
|
|
|
typedef pair<string, string> StringPair;
|
|
|
|
|
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 /
|
|
|
|
*/
|
2008-03-28 23:31:21 +01:00
|
|
|
string normalizePath(const string &path);
|
2008-03-19 15:35:22 +01:00
|
|
|
|
2008-03-28 23:31:21 +01:00
|
|
|
/** ensure that m_path is writable, otherwise throw error */
|
|
|
|
void mkdir_p(const string &path);
|
|
|
|
|
|
|
|
/** remove a complete directory hierarchy; invoking on non-existant directory is okay */
|
|
|
|
void rm_r(const string &path);
|
|
|
|
|
2008-03-29 15:16:34 +01:00
|
|
|
/** true if the path refers to a directory */
|
|
|
|
bool isDir(const string &path);
|
|
|
|
|
2008-03-30 20:02:32 +02:00
|
|
|
/**
|
|
|
|
* This is a simplified implementation of a class representing and calculating
|
|
|
|
* UUIDs v4 inspired from RFC 4122. We do not use cryptographic pseudo-random
|
|
|
|
* numbers, instead we rely on rand/srand.
|
|
|
|
*
|
|
|
|
* We initialize the random generation with the system time given by time(), but
|
|
|
|
* only once.
|
|
|
|
*
|
|
|
|
* Instantiating this class will generate a new unique UUID, available afterwards
|
|
|
|
* in the base string class.
|
|
|
|
*/
|
|
|
|
class UUID : public string {
|
|
|
|
public:
|
|
|
|
UUID();
|
|
|
|
};
|
|
|
|
|
2008-03-28 23:31:21 +01:00
|
|
|
/**
|
|
|
|
* A C++ wrapper around readir() which provides the names of all
|
|
|
|
* directory entries, excluding . and ..
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
class ReadDir {
|
|
|
|
public:
|
|
|
|
ReadDir(const string &path);
|
|
|
|
|
|
|
|
typedef vector<string>::const_iterator const_iterator;
|
|
|
|
typedef vector<string>::iterator iterator;
|
|
|
|
iterator begin() { return m_entries.begin(); }
|
|
|
|
iterator end() { return m_entries.end(); }
|
|
|
|
const_iterator begin() const { return m_entries.begin(); }
|
|
|
|
const_iterator end() const { return m_entries.end(); }
|
|
|
|
|
|
|
|
private:
|
|
|
|
string m_path;
|
|
|
|
vector<string> m_entries;
|
|
|
|
};
|
2008-03-19 15:35:22 +01:00
|
|
|
|
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
|