Apply clang-format
This commit is contained in:
parent
53ff69130c
commit
db46948f2f
|
@ -98,9 +98,9 @@ void startConsole()
|
|||
* \brief Convert command line arguments to UTF-8.
|
||||
* \remarks Only available on Windows (on other platforms we can assume passed arguments are already UTF-8 encoded).
|
||||
*/
|
||||
pair<vector<unique_ptr<char[]> >, vector<char *> > convertArgsToUtf8()
|
||||
pair<vector<unique_ptr<char[]>>, vector<char *>> convertArgsToUtf8()
|
||||
{
|
||||
pair<vector<unique_ptr<char[]> >, vector<char *> > res;
|
||||
pair<vector<unique_ptr<char[]>>, vector<char *>> res;
|
||||
int argc;
|
||||
|
||||
LPWSTR *argv_w = CommandLineToArgvW(GetCommandLineW(), &argc);
|
||||
|
|
|
@ -21,7 +21,7 @@ bool CPP_UTILITIES_EXPORT confirmPrompt(const char *message, Response defaultRes
|
|||
|
||||
#ifdef PLATFORM_WINDOWS
|
||||
void CPP_UTILITIES_EXPORT startConsole();
|
||||
std::pair<std::vector<std::unique_ptr<char[]> >, std::vector<char *> > CPP_UTILITIES_EXPORT convertArgsToUtf8();
|
||||
std::pair<std::vector<std::unique_ptr<char[]>>, std::vector<char *>> CPP_UTILITIES_EXPORT convertArgsToUtf8();
|
||||
#define CMD_UTILS_START_CONSOLE ::ApplicationUtilities::startConsole();
|
||||
#define CMD_UTILS_CONVERT_ARGS_TO_UTF8 \
|
||||
auto utf8Args = ::ApplicationUtilities::convertArgsToUtf8(); \
|
||||
|
|
|
@ -12,30 +12,30 @@ namespace ConversionUtilities {
|
|||
/// \cond
|
||||
namespace Helper {
|
||||
|
||||
template <class StringType, Traits::EnableIf<std::is_class<StringType> >...> std::size_t computeTupleElementSize(const StringType *str)
|
||||
template <class StringType, Traits::EnableIf<std::is_class<StringType>>...> std::size_t computeTupleElementSize(const StringType *str)
|
||||
{
|
||||
return str->size();
|
||||
}
|
||||
|
||||
template <class StringType, Traits::EnableIf<std::is_class<StringType> >...> std::size_t computeTupleElementSize(const StringType &str)
|
||||
template <class StringType, Traits::EnableIf<std::is_class<StringType>>...> std::size_t computeTupleElementSize(const StringType &str)
|
||||
{
|
||||
return str.size();
|
||||
}
|
||||
|
||||
template <class StringType, class CharType, Traits::EnableIf<std::is_same<typename StringType::value_type, CharType> >...>
|
||||
template <class StringType, class CharType, Traits::EnableIf<std::is_same<typename StringType::value_type, CharType>>...>
|
||||
std::size_t computeTupleElementSize(const CharType *str)
|
||||
{
|
||||
return std::char_traits<CharType>::length(str);
|
||||
}
|
||||
|
||||
template <class StringType, class CharType, Traits::EnableIf<std::is_same<typename StringType::value_type, CharType> >...>
|
||||
template <class StringType, class CharType, Traits::EnableIf<std::is_same<typename StringType::value_type, CharType>>...>
|
||||
constexpr std::size_t computeTupleElementSize(CharType)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
template <class StringType, typename IntegralType, Traits::EnableIf<Traits::Not<std::is_same<typename StringType::value_type, IntegralType> >,
|
||||
std::is_integral<IntegralType>, std::is_unsigned<IntegralType> >...>
|
||||
template <class StringType, typename IntegralType, Traits::EnableIf<Traits::Not<std::is_same<typename StringType::value_type, IntegralType>>,
|
||||
std::is_integral<IntegralType>, std::is_unsigned<IntegralType>>...>
|
||||
std::size_t computeTupleElementSize(IntegralType number, typename StringType::value_type base = 10)
|
||||
{
|
||||
std::size_t size = 0;
|
||||
|
@ -44,8 +44,8 @@ std::size_t computeTupleElementSize(IntegralType number, typename StringType::va
|
|||
return size;
|
||||
}
|
||||
|
||||
template <class StringType, typename IntegralType, Traits::EnableIf<Traits::Not<std::is_same<typename StringType::value_type, IntegralType> >,
|
||||
std::is_integral<IntegralType>, std::is_signed<IntegralType> >...>
|
||||
template <class StringType, typename IntegralType, Traits::EnableIf<Traits::Not<std::is_same<typename StringType::value_type, IntegralType>>,
|
||||
std::is_integral<IntegralType>, std::is_signed<IntegralType>>...>
|
||||
std::size_t computeTupleElementSize(IntegralType number, typename StringType::value_type base = 10)
|
||||
{
|
||||
std::size_t size = number < 0 ? 1 : 0;
|
||||
|
@ -54,30 +54,30 @@ std::size_t computeTupleElementSize(IntegralType number, typename StringType::va
|
|||
return size;
|
||||
}
|
||||
|
||||
template <class StringType, Traits::EnableIf<std::is_class<StringType> >...> void append(StringType &target, const StringType *str)
|
||||
template <class StringType, Traits::EnableIf<std::is_class<StringType>>...> void append(StringType &target, const StringType *str)
|
||||
{
|
||||
target.append(*str);
|
||||
}
|
||||
|
||||
template <class StringType, Traits::EnableIf<std::is_class<StringType> >...> void append(StringType &target, const StringType &str)
|
||||
template <class StringType, Traits::EnableIf<std::is_class<StringType>>...> void append(StringType &target, const StringType &str)
|
||||
{
|
||||
target.append(str);
|
||||
}
|
||||
|
||||
template <class StringType, class CharType, Traits::EnableIf<std::is_same<typename StringType::value_type, CharType> >...>
|
||||
template <class StringType, class CharType, Traits::EnableIf<std::is_same<typename StringType::value_type, CharType>>...>
|
||||
void append(StringType &target, const CharType *str)
|
||||
{
|
||||
target.append(str);
|
||||
}
|
||||
|
||||
template <class StringType, class CharType, Traits::EnableIf<std::is_same<typename StringType::value_type, CharType> >...>
|
||||
template <class StringType, class CharType, Traits::EnableIf<std::is_same<typename StringType::value_type, CharType>>...>
|
||||
void append(StringType &target, CharType c)
|
||||
{
|
||||
target += c;
|
||||
}
|
||||
|
||||
template <class StringType, typename IntegralType, Traits::EnableIf<Traits::Not<std::is_same<typename StringType::value_type, IntegralType> >,
|
||||
std::is_integral<IntegralType>, std::is_unsigned<IntegralType> >...>
|
||||
template <class StringType, typename IntegralType, Traits::EnableIf<Traits::Not<std::is_same<typename StringType::value_type, IntegralType>>,
|
||||
std::is_integral<IntegralType>, std::is_unsigned<IntegralType>>...>
|
||||
void append(StringType &target, IntegralType number, typename StringType::value_type base = 10)
|
||||
{
|
||||
const auto start = target.begin() + target.size();
|
||||
|
@ -87,8 +87,8 @@ void append(StringType &target, IntegralType number, typename StringType::value_
|
|||
} while (number);
|
||||
}
|
||||
|
||||
template <class StringType, typename IntegralType, Traits::EnableIf<Traits::Not<std::is_same<typename StringType::value_type, IntegralType> >,
|
||||
std::is_integral<IntegralType>, std::is_signed<IntegralType> >...>
|
||||
template <class StringType, typename IntegralType, Traits::EnableIf<Traits::Not<std::is_same<typename StringType::value_type, IntegralType>>,
|
||||
std::is_integral<IntegralType>, std::is_signed<IntegralType>>...>
|
||||
void append(StringType &target, IntegralType number, typename StringType::value_type base = 10)
|
||||
{
|
||||
if (number < 0) {
|
||||
|
@ -164,7 +164,7 @@ template <class Tuple> constexpr auto operator%(const Tuple &lhs, const char *rh
|
|||
/*!
|
||||
* \brief Allows construction of string-tuples via %-operator, eg. string1 % "string2" % string3.
|
||||
*/
|
||||
template <class Tuple, typename IntegralType, Traits::EnableIf<std::is_integral<IntegralType> >...>
|
||||
template <class Tuple, typename IntegralType, Traits::EnableIf<std::is_integral<IntegralType>>...>
|
||||
constexpr auto operator%(const Tuple &lhs, IntegralType rhs) -> decltype(std::tuple_cat(lhs, std::make_tuple(rhs)))
|
||||
{
|
||||
return std::tuple_cat(lhs, std::make_tuple(rhs));
|
||||
|
@ -219,7 +219,7 @@ constexpr auto operator%(char lhs, const std::string &rhs) -> decltype(std::make
|
|||
* printVelocity("velocity: " % numberToString(velocityExample) % " km/h (" % numberToString(velocityExample / 3.6) + " m/s)"));
|
||||
* ```
|
||||
*/
|
||||
template <class Tuple, Traits::EnableIf<Traits::IsSpecializationOf<Tuple, std::tuple> >...>
|
||||
template <class Tuple, Traits::EnableIf<Traits::IsSpecializationOf<Tuple, std::tuple>>...>
|
||||
inline std::string operator+(const Tuple &lhs, const std::string &rhs)
|
||||
{
|
||||
return tupleToString(std::tuple_cat(lhs, std::make_tuple(&rhs)));
|
||||
|
@ -234,7 +234,7 @@ inline std::string operator+(const Tuple &lhs, const std::string &rhs)
|
|||
* printVelocity("velocity: " % numberToString(velocityExample) % " km/h (" % numberToString(velocityExample / 3.6) + " m/s)"));
|
||||
* ```
|
||||
*/
|
||||
template <class Tuple, Traits::EnableIf<Traits::IsSpecializationOf<Tuple, std::tuple> >...>
|
||||
template <class Tuple, Traits::EnableIf<Traits::IsSpecializationOf<Tuple, std::tuple>>...>
|
||||
inline std::string operator+(const Tuple &lhs, const char *rhs)
|
||||
{
|
||||
return tupleToString(std::tuple_cat(lhs, std::make_tuple(rhs)));
|
||||
|
@ -249,7 +249,7 @@ inline std::string operator+(const Tuple &lhs, const char *rhs)
|
|||
* printVelocity("velocity: " % numberToString(velocityExample) % " km/h (" % numberToString(velocityExample / 3.6) + " m/s)"));
|
||||
* ```
|
||||
*/
|
||||
template <class Tuple, typename IntegralType, Traits::EnableIf<Traits::IsSpecializationOf<Tuple, std::tuple>, std::is_integral<IntegralType> >...>
|
||||
template <class Tuple, typename IntegralType, Traits::EnableIf<Traits::IsSpecializationOf<Tuple, std::tuple>, std::is_integral<IntegralType>>...>
|
||||
inline std::string operator+(const Tuple &lhs, IntegralType rhs)
|
||||
{
|
||||
return tupleToString(std::tuple_cat(lhs, std::make_tuple(rhs)));
|
||||
|
|
|
@ -61,7 +61,7 @@ CPP_UTILITIES_EXPORT void truncateString(std::string &str, char terminationChar
|
|||
* \tparam Container The STL-container used to provide the \a strings.
|
||||
* \returns Returns the joined string.
|
||||
*/
|
||||
template <class Container = std::initializer_list<std::string> >
|
||||
template <class Container = std::initializer_list<std::string>>
|
||||
typename Container::value_type joinStrings(const Container &strings,
|
||||
const typename Container::value_type &delimiter = typename Container::value_type(), bool omitEmpty = false,
|
||||
const typename Container::value_type &leftClosure = typename Container::value_type(),
|
||||
|
@ -112,7 +112,7 @@ enum class EmptyPartsTreat {
|
|||
* \tparam Container The STL-container used to return the parts.
|
||||
* \returns Returns the parts.
|
||||
*/
|
||||
template <class Container = std::list<std::string> >
|
||||
template <class Container = std::list<std::string>>
|
||||
Container splitString(const typename Container::value_type &string, const typename Container::value_type &delimiter,
|
||||
EmptyPartsTreat emptyPartsRole = EmptyPartsTreat::Keep, int maxParts = -1)
|
||||
{
|
||||
|
@ -250,7 +250,7 @@ template <typename CharType> CharType digitToChar(CharType digit)
|
|||
* \sa stringToNumber()
|
||||
*/
|
||||
template <typename IntegralType, class StringType = std::string,
|
||||
Traits::EnableIf<std::is_integral<IntegralType>, Traits::Not<std::is_signed<IntegralType> > >...>
|
||||
Traits::EnableIf<std::is_integral<IntegralType>, Traits::Not<std::is_signed<IntegralType>>>...>
|
||||
StringType numberToString(IntegralType number, typename StringType::value_type base = 10)
|
||||
{
|
||||
std::size_t resSize = 0;
|
||||
|
@ -271,7 +271,7 @@ StringType numberToString(IntegralType number, typename StringType::value_type b
|
|||
* \tparam StringType The string type (should be an instantiation of the basic_string class template).
|
||||
* \sa stringToNumber()
|
||||
*/
|
||||
template <typename IntegralType, class StringType = std::string, Traits::EnableIf<std::is_integral<IntegralType>, std::is_signed<IntegralType> >...>
|
||||
template <typename IntegralType, class StringType = std::string, Traits::EnableIf<std::is_integral<IntegralType>, std::is_signed<IntegralType>>...>
|
||||
StringType numberToString(IntegralType number, typename StringType::value_type base = 10)
|
||||
{
|
||||
const bool negative = number < 0;
|
||||
|
@ -303,7 +303,7 @@ StringType numberToString(IntegralType number, typename StringType::value_type b
|
|||
* \a base and types).
|
||||
* \sa stringToNumber()
|
||||
*/
|
||||
template <typename FloatingType, class StringType = std::string, Traits::EnableIf<std::is_floating_point<FloatingType> >...>
|
||||
template <typename FloatingType, class StringType = std::string, Traits::EnableIf<std::is_floating_point<FloatingType>>...>
|
||||
StringType numberToString(FloatingType number, typename StringType::value_type base = 10)
|
||||
{
|
||||
std::basic_stringstream<typename StringType::value_type> ss;
|
||||
|
@ -340,7 +340,7 @@ template <typename CharType> CharType charToDigit(CharType character, CharType b
|
|||
* \throws A ConversionException will be thrown if the provided \a string is not a valid number.
|
||||
* \sa numberToString()
|
||||
*/
|
||||
template <typename IntegralType, class StringType, Traits::EnableIf<std::is_integral<IntegralType>, Traits::Not<std::is_signed<IntegralType> > >...>
|
||||
template <typename IntegralType, class StringType, Traits::EnableIf<std::is_integral<IntegralType>, Traits::Not<std::is_signed<IntegralType>>>...>
|
||||
IntegralType stringToNumber(const StringType &string, typename StringType::value_type base = 10)
|
||||
{
|
||||
IntegralType result = 0;
|
||||
|
@ -361,7 +361,7 @@ IntegralType stringToNumber(const StringType &string, typename StringType::value
|
|||
* \throws A ConversionException will be thrown if the provided \a string is not a valid number.
|
||||
* \sa numberToString()
|
||||
*/
|
||||
template <typename IntegralType, class StringType, Traits::EnableIf<std::is_integral<IntegralType>, std::is_signed<IntegralType> >...>
|
||||
template <typename IntegralType, class StringType, Traits::EnableIf<std::is_integral<IntegralType>, std::is_signed<IntegralType>>...>
|
||||
IntegralType stringToNumber(const StringType &string, typename StringType::value_type base = 10)
|
||||
{
|
||||
auto i = string.begin();
|
||||
|
@ -393,7 +393,7 @@ IntegralType stringToNumber(const StringType &string, typename StringType::value
|
|||
* \a base and types).
|
||||
* \sa numberToString()
|
||||
*/
|
||||
template <typename FloatingType, class StringType, Traits::EnableIf<std::is_floating_point<FloatingType> >...>
|
||||
template <typename FloatingType, class StringType, Traits::EnableIf<std::is_floating_point<FloatingType>>...>
|
||||
FloatingType stringToNumber(const StringType &string, typename StringType::value_type base = 10)
|
||||
{
|
||||
std::basic_stringstream<typename StringType::value_type> ss;
|
||||
|
@ -413,7 +413,7 @@ FloatingType stringToNumber(const StringType &string, typename StringType::value
|
|||
* \throws A ConversionException will be thrown if the provided \a string is not a valid number.
|
||||
* \sa numberToString()
|
||||
*/
|
||||
template <typename IntegralType, class CharType, Traits::EnableIf<std::is_integral<IntegralType>, Traits::Not<std::is_signed<IntegralType> > >...>
|
||||
template <typename IntegralType, class CharType, Traits::EnableIf<std::is_integral<IntegralType>, Traits::Not<std::is_signed<IntegralType>>>...>
|
||||
IntegralType stringToNumber(const CharType *string, unsigned char base = 10)
|
||||
{
|
||||
IntegralType result = 0;
|
||||
|
@ -434,7 +434,7 @@ IntegralType stringToNumber(const CharType *string, unsigned char base = 10)
|
|||
* \throws A ConversionException will be thrown if the provided \a string is not a valid number.
|
||||
* \sa numberToString()
|
||||
*/
|
||||
template <typename IntegralType, class CharType, Traits::EnableIf<std::is_integral<IntegralType>, std::is_signed<IntegralType> >...>
|
||||
template <typename IntegralType, class CharType, Traits::EnableIf<std::is_integral<IntegralType>, std::is_signed<IntegralType>>...>
|
||||
IntegralType stringToNumber(const CharType *string, unsigned char base = 10)
|
||||
{
|
||||
if (!*string) {
|
||||
|
|
|
@ -15,15 +15,15 @@ namespace ConversionUtilities {
|
|||
* \brief Converts a std::string to a wide string using the specified locale.
|
||||
* \deprecated Might be removed in future release because not used anymore. Use iconv based string converion functions instead.
|
||||
*/
|
||||
template <class E, class T = std::char_traits<E>, class A = std::allocator<E> >
|
||||
class CPP_UTILITIES_EXPORT Widen : public std::unary_function<const std::string &, std::basic_string<E, T, A> > {
|
||||
template <class E, class T = std::char_traits<E>, class A = std::allocator<E>>
|
||||
class CPP_UTILITIES_EXPORT Widen : public std::unary_function<const std::string &, std::basic_string<E, T, A>> {
|
||||
public:
|
||||
/*!
|
||||
* \brief Constructs a new instance with the specified \a locale.
|
||||
*/
|
||||
Widen(const std::locale &locale = std::locale())
|
||||
: m_loc(locale)
|
||||
, m_pctype(&std::use_facet<std::ctype<E> >(locale))
|
||||
, m_pctype(&std::use_facet<std::ctype<E>>(locale))
|
||||
{
|
||||
}
|
||||
|
||||
|
|
10
io/inifile.h
10
io/inifile.h
|
@ -13,13 +13,13 @@ class CPP_UTILITIES_EXPORT IniFile {
|
|||
public:
|
||||
IniFile();
|
||||
|
||||
std::vector<std::pair<std::string, std::multimap<std::string, std::string> > > &data();
|
||||
const std::vector<std::pair<std::string, std::multimap<std::string, std::string> > > &data() const;
|
||||
std::vector<std::pair<std::string, std::multimap<std::string, std::string>>> &data();
|
||||
const std::vector<std::pair<std::string, std::multimap<std::string, std::string>>> &data() const;
|
||||
void parse(std::istream &inputStream);
|
||||
void make(std::ostream &outputStream);
|
||||
|
||||
private:
|
||||
std::vector<std::pair<std::string, std::multimap<std::string, std::string> > > m_data;
|
||||
std::vector<std::pair<std::string, std::multimap<std::string, std::string>>> m_data;
|
||||
};
|
||||
|
||||
/*!
|
||||
|
@ -35,7 +35,7 @@ inline IniFile::IniFile()
|
|||
* - The returned pairs represent the [scope names] and the contained "key = value"-pairs.
|
||||
* - The data might be modified and then saved using the make() method.
|
||||
*/
|
||||
inline std::vector<std::pair<std::string, std::multimap<std::string, std::string> > > &IniFile::data()
|
||||
inline std::vector<std::pair<std::string, std::multimap<std::string, std::string>>> &IniFile::data()
|
||||
{
|
||||
return m_data;
|
||||
}
|
||||
|
@ -44,7 +44,7 @@ inline std::vector<std::pair<std::string, std::multimap<std::string, std::string
|
|||
* \brief Returns the data of the file.
|
||||
* \remarks The returned pairs represent the [scope names] and the contained "key = value"-pairs.
|
||||
*/
|
||||
inline const std::vector<std::pair<std::string, std::multimap<std::string, std::string> > > &IniFile::data() const
|
||||
inline const std::vector<std::pair<std::string, std::multimap<std::string, std::string>>> &IniFile::data() const
|
||||
{
|
||||
return m_data;
|
||||
}
|
||||
|
|
|
@ -58,7 +58,7 @@ void NativeFileStream::open(const string &path, ios_base::openmode flags)
|
|||
if (fd == -1) {
|
||||
::IoUtilities::throwIoFailure("_wopen failed");
|
||||
}
|
||||
m_filebuf = make_unique<__gnu_cxx::stdio_filebuf<char> >(fd, flags);
|
||||
m_filebuf = make_unique<__gnu_cxx::stdio_filebuf<char>>(fd, flags);
|
||||
rdbuf(m_filebuf.get());
|
||||
}
|
||||
|
||||
|
|
|
@ -30,7 +30,7 @@ public:
|
|||
void close();
|
||||
|
||||
private:
|
||||
std::unique_ptr<__gnu_cxx::stdio_filebuf<char> > m_filebuf;
|
||||
std::unique_ptr<__gnu_cxx::stdio_filebuf<char>> m_filebuf;
|
||||
std::__c_file m_cfile;
|
||||
};
|
||||
|
||||
|
|
|
@ -21,12 +21,12 @@ template <typename T> using Not = Bool<!T::value>;
|
|||
|
||||
template <typename... T> struct Any : Bool<false> {
|
||||
};
|
||||
template <typename Head, typename... Tail> struct Any<Head, Tail...> : Conditional<Head, Bool<true>, Any<Tail...> > {
|
||||
template <typename Head, typename... Tail> struct Any<Head, Tail...> : Conditional<Head, Bool<true>, Any<Tail...>> {
|
||||
};
|
||||
|
||||
template <typename... T> struct All : Bool<true> {
|
||||
};
|
||||
template <typename Head, typename... Tail> struct All<Head, Tail...> : Conditional<Head, All<Tail...>, Bool<false> > {
|
||||
template <typename Head, typename... Tail> struct All<Head, Tail...> : Conditional<Head, All<Tail...>, Bool<false>> {
|
||||
};
|
||||
|
||||
template <typename... Condition> using EnableIf = typename std::enable_if<All<Condition...>::value, Detail::Enabler>::type;
|
||||
|
|
|
@ -11,11 +11,11 @@
|
|||
|
||||
#include "resources/config.h"
|
||||
|
||||
#include <cppunit/extensions/HelperMacros.h>
|
||||
#include <cppunit/TestFixture.h>
|
||||
#include <cppunit/extensions/HelperMacros.h>
|
||||
|
||||
#include <cstring>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
|
||||
using namespace std;
|
||||
using namespace ApplicationUtilities;
|
||||
|
@ -26,8 +26,7 @@ using namespace CPPUNIT_NS;
|
|||
/*!
|
||||
* \brief The ArgumentParserTests class tests the ArgumentParser and Argument classes.
|
||||
*/
|
||||
class ArgumentParserTests : public TestFixture
|
||||
{
|
||||
class ArgumentParserTests : public TestFixture {
|
||||
CPPUNIT_TEST_SUITE(ArgumentParserTests);
|
||||
CPPUNIT_TEST(testArgument);
|
||||
CPPUNIT_TEST(testParsing);
|
||||
|
@ -51,10 +50,12 @@ private:
|
|||
CPPUNIT_TEST_SUITE_REGISTRATION(ArgumentParserTests);
|
||||
|
||||
void ArgumentParserTests::setUp()
|
||||
{}
|
||||
{
|
||||
}
|
||||
|
||||
void ArgumentParserTests::tearDown()
|
||||
{}
|
||||
{
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Tests the behaviour of the argument class.
|
||||
|
@ -71,7 +72,7 @@ void ArgumentParserTests::testArgument()
|
|||
CPPUNIT_ASSERT(!subArg.conflictsWithArgument());
|
||||
CPPUNIT_ASSERT(!argument.firstValue());
|
||||
argument.setEnvironmentVariable("PATH");
|
||||
if(getenv("PATH")) {
|
||||
if (getenv("PATH")) {
|
||||
CPPUNIT_ASSERT(argument.firstValue());
|
||||
CPPUNIT_ASSERT(!strcmp(argument.firstValue(), getenv("PATH")));
|
||||
} else {
|
||||
|
@ -92,14 +93,14 @@ void ArgumentParserTests::testParsing()
|
|||
Argument verboseArg("verbose", 'v', "be verbose");
|
||||
verboseArg.setCombinable(true);
|
||||
Argument fileArg("file", 'f', "specifies the path of the file to be opened");
|
||||
fileArg.setValueNames({"path"});
|
||||
fileArg.setValueNames({ "path" });
|
||||
fileArg.setRequiredValueCount(1);
|
||||
fileArg.setEnvironmentVariable("PATH");
|
||||
Argument filesArg("files", 'f', "specifies the path of the file(s) to be opened");
|
||||
filesArg.setValueNames({"path 1", "path 2"});
|
||||
filesArg.setValueNames({ "path 1", "path 2" });
|
||||
filesArg.setRequiredValueCount(-1);
|
||||
Argument outputFileArg("output-file", 'o', "specifies the path of the output file");
|
||||
outputFileArg.setValueNames({"path"});
|
||||
outputFileArg.setValueNames({ "path" });
|
||||
outputFileArg.setRequiredValueCount(1);
|
||||
outputFileArg.setRequired(true);
|
||||
outputFileArg.setCombinable(true);
|
||||
|
@ -107,23 +108,23 @@ void ArgumentParserTests::testParsing()
|
|||
Argument displayFileInfoArg("display-file-info", 'i', "displays general file information");
|
||||
Argument notAlbumArg("album", 'a', "should not be confused with album value");
|
||||
displayFileInfoArg.setDenotesOperation(true);
|
||||
displayFileInfoArg.setSubArguments({&fileArg, &verboseArg, ¬AlbumArg});
|
||||
displayFileInfoArg.setSubArguments({ &fileArg, &verboseArg, ¬AlbumArg });
|
||||
Argument fieldsArg("fields", '\0', "specifies the fields");
|
||||
fieldsArg.setRequiredValueCount(-1);
|
||||
fieldsArg.setValueNames({"title", "album", "artist", "trackpos"});
|
||||
fieldsArg.setValueNames({ "title", "album", "artist", "trackpos" });
|
||||
fieldsArg.setImplicit(true);
|
||||
Argument displayTagInfoArg("get", 'p', "displays the values of all specified tag fields (displays all fields if none specified)");
|
||||
displayTagInfoArg.setDenotesOperation(true);
|
||||
displayTagInfoArg.setSubArguments({&fieldsArg, &filesArg, &verboseArg, ¬AlbumArg});
|
||||
parser.setMainArguments({&qtConfigArgs.qtWidgetsGuiArg(), &printFieldNamesArg, &displayTagInfoArg, &displayFileInfoArg, &helpArg});
|
||||
displayTagInfoArg.setSubArguments({ &fieldsArg, &filesArg, &verboseArg, ¬AlbumArg });
|
||||
parser.setMainArguments({ &qtConfigArgs.qtWidgetsGuiArg(), &printFieldNamesArg, &displayTagInfoArg, &displayFileInfoArg, &helpArg });
|
||||
|
||||
// error about uncombinable arguments
|
||||
const char *argv[] = {"tageditor", "get", "album", "title", "diskpos", "-f", "somefile"};
|
||||
const char *argv[] = { "tageditor", "get", "album", "title", "diskpos", "-f", "somefile" };
|
||||
// try to parse, this should fail
|
||||
try {
|
||||
parser.parseArgs(7, argv);
|
||||
CPPUNIT_FAIL("Exception expected.");
|
||||
} catch(const Failure &e) {
|
||||
} catch (const Failure &e) {
|
||||
CPPUNIT_ASSERT(!strcmp(e.what(), "The argument \"files\" can not be combined with \"fields\"."));
|
||||
}
|
||||
|
||||
|
@ -144,7 +145,7 @@ void ArgumentParserTests::testParsing()
|
|||
CPPUNIT_ASSERT_THROW(displayTagInfoArg.values().at(3), out_of_range);
|
||||
|
||||
// skip empty args
|
||||
const char *argv2[] = {"tageditor", "", "-p", "album", "title", "diskpos", "", "--files", "somefile"};
|
||||
const char *argv2[] = { "tageditor", "", "-p", "album", "title", "diskpos", "", "--files", "somefile" };
|
||||
// reparse the args
|
||||
parser.resetArgs();
|
||||
parser.parseArgs(9, argv2);
|
||||
|
@ -163,12 +164,12 @@ void ArgumentParserTests::testParsing()
|
|||
CPPUNIT_ASSERT(!strcmp(filesArg.values().at(0), "somefile"));
|
||||
|
||||
// error about unknown argument: forget get/-p
|
||||
const char *argv3[] = {"tageditor", "album", "title", "diskpos", "--files", "somefile"};
|
||||
const char *argv3[] = { "tageditor", "album", "title", "diskpos", "--files", "somefile" };
|
||||
try {
|
||||
parser.resetArgs();
|
||||
parser.parseArgs(6, argv3);
|
||||
CPPUNIT_FAIL("Exception expected.");
|
||||
} catch(const Failure &e) {
|
||||
} catch (const Failure &e) {
|
||||
CPPUNIT_ASSERT_EQUAL("The specified argument \"album\" is unknown."s, string(e.what()));
|
||||
}
|
||||
|
||||
|
@ -180,7 +181,7 @@ void ArgumentParserTests::testParsing()
|
|||
parser.resetArgs();
|
||||
try {
|
||||
parser.parseArgs(6, argv3);
|
||||
} catch(...) {
|
||||
} catch (...) {
|
||||
cerr.rdbuf(regularCerrBuffer);
|
||||
throw;
|
||||
}
|
||||
|
@ -190,7 +191,7 @@ void ArgumentParserTests::testParsing()
|
|||
"The specified argument \"diskpos\" is unknown and will be ignored.\n"s
|
||||
"The specified argument \"--files\" is unknown and will be ignored.\n"s
|
||||
"The specified argument \"somefile\" is unknown and will be ignored.\n"s,
|
||||
buffer.str());
|
||||
buffer.str());
|
||||
// none of the arguments should be present now
|
||||
CPPUNIT_ASSERT(!qtConfigArgs.qtWidgetsGuiArg().isPresent());
|
||||
CPPUNIT_ASSERT(!displayFileInfoArg.isPresent());
|
||||
|
@ -199,7 +200,7 @@ void ArgumentParserTests::testParsing()
|
|||
CPPUNIT_ASSERT(!filesArg.isPresent());
|
||||
|
||||
// combined abbreviations like "-vf"
|
||||
const char *argv4[] = {"tageditor", "-i", "-vf", "test"};
|
||||
const char *argv4[] = { "tageditor", "-i", "-vf", "test" };
|
||||
parser.setUnknownArgumentBehavior(UnknownArgumentBehavior::Fail);
|
||||
parser.resetArgs();
|
||||
parser.parseArgs(4, argv4);
|
||||
|
@ -217,7 +218,7 @@ void ArgumentParserTests::testParsing()
|
|||
try {
|
||||
parser.parseArgs(4, argv4);
|
||||
CPPUNIT_FAIL("Exception expected.");
|
||||
} catch(const Failure &e) {
|
||||
} catch (const Failure &e) {
|
||||
CPPUNIT_ASSERT(!qtConfigArgs.qtWidgetsGuiArg().isPresent());
|
||||
CPPUNIT_ASSERT(!strcmp(e.what(), "The argument \"verbose\" mustn't be specified more than 1 time."));
|
||||
}
|
||||
|
@ -235,19 +236,19 @@ void ArgumentParserTests::testParsing()
|
|||
CPPUNIT_ASSERT(!qtConfigArgs.qtWidgetsGuiArg().isPresent());
|
||||
|
||||
// contraint checking: error about missing mandatory argument
|
||||
const char *argv5[] = {"tageditor", "-i", "-f", "test"};
|
||||
const char *argv5[] = { "tageditor", "-i", "-f", "test" };
|
||||
displayFileInfoArg.reset(), fileArg.reset(), verboseArg.reset();
|
||||
try {
|
||||
parser.parseArgs(4, argv5);
|
||||
CPPUNIT_FAIL("Exception expected.");
|
||||
} catch(const Failure &e) {
|
||||
} catch (const Failure &e) {
|
||||
CPPUNIT_ASSERT(!qtConfigArgs.qtWidgetsGuiArg().isPresent());
|
||||
CPPUNIT_ASSERT(!strcmp(e.what(), "The argument \"verbose\" must be specified at least 1 time."));
|
||||
}
|
||||
verboseArg.setRequired(false);
|
||||
|
||||
// combined abbreviation with nesting "-pf"
|
||||
const char *argv10[] = {"tageditor", "-pf", "test"};
|
||||
const char *argv10[] = { "tageditor", "-pf", "test" };
|
||||
parser.resetArgs();
|
||||
parser.parseArgs(3, argv10);
|
||||
CPPUNIT_ASSERT(displayTagInfoArg.isPresent());
|
||||
|
@ -259,24 +260,24 @@ void ArgumentParserTests::testParsing()
|
|||
CPPUNIT_ASSERT(!qtConfigArgs.qtWidgetsGuiArg().isPresent());
|
||||
|
||||
// constraint checking: no complains about missing -i
|
||||
const char *argv6[] = {"tageditor", "-g"};
|
||||
const char *argv6[] = { "tageditor", "-g" };
|
||||
parser.resetArgs();
|
||||
parser.parseArgs(2, argv6);
|
||||
CPPUNIT_ASSERT(qtConfigArgs.qtWidgetsGuiArg().isPresent());
|
||||
|
||||
// constraint checking: dependend arguments (-f requires -i or -p)
|
||||
const char *argv7[] = {"tageditor", "-f", "test"};
|
||||
const char *argv7[] = { "tageditor", "-f", "test" };
|
||||
parser.resetArgs();
|
||||
try {
|
||||
parser.parseArgs(3, argv7);
|
||||
CPPUNIT_FAIL("Exception expected.");
|
||||
} catch(const Failure &e) {
|
||||
} catch (const Failure &e) {
|
||||
CPPUNIT_ASSERT(!qtConfigArgs.qtWidgetsGuiArg().isPresent());
|
||||
CPPUNIT_ASSERT_EQUAL("The specified argument \"-f\" is unknown."s, string(e.what()));
|
||||
}
|
||||
|
||||
// equation sign syntax
|
||||
const char *argv11[] = {"tageditor", "-if=test"};
|
||||
const char *argv11[] = { "tageditor", "-if=test" };
|
||||
parser.resetArgs();
|
||||
parser.parseArgs(2, argv11);
|
||||
CPPUNIT_ASSERT(!filesArg.isPresent());
|
||||
|
@ -285,7 +286,7 @@ void ArgumentParserTests::testParsing()
|
|||
CPPUNIT_ASSERT(!strcmp(fileArg.values(0).front(), "test"));
|
||||
|
||||
// specifying value directly after abbreviation
|
||||
const char *argv12[] = {"tageditor", "-iftest"};
|
||||
const char *argv12[] = { "tageditor", "-iftest" };
|
||||
parser.resetArgs();
|
||||
parser.parseArgs(2, argv12);
|
||||
CPPUNIT_ASSERT(!filesArg.isPresent());
|
||||
|
@ -294,7 +295,7 @@ void ArgumentParserTests::testParsing()
|
|||
CPPUNIT_ASSERT(!strcmp(fileArg.values(0).front(), "test"));
|
||||
|
||||
// default argument
|
||||
const char *argv8[] = {"tageditor"};
|
||||
const char *argv8[] = { "tageditor" };
|
||||
parser.resetArgs();
|
||||
parser.parseArgs(1, argv8);
|
||||
CPPUNIT_ASSERT(qtConfigArgs.qtWidgetsGuiArg().isPresent());
|
||||
|
@ -303,7 +304,7 @@ void ArgumentParserTests::testParsing()
|
|||
CPPUNIT_ASSERT(!displayTagInfoArg.isPresent());
|
||||
CPPUNIT_ASSERT(!filesArg.isPresent());
|
||||
CPPUNIT_ASSERT(!fileArg.isPresent());
|
||||
if(getenv("PATH")) {
|
||||
if (getenv("PATH")) {
|
||||
CPPUNIT_ASSERT(fileArg.firstValue());
|
||||
CPPUNIT_ASSERT(!strcmp(fileArg.firstValue(), getenv("PATH")));
|
||||
} else {
|
||||
|
@ -311,7 +312,7 @@ void ArgumentParserTests::testParsing()
|
|||
}
|
||||
|
||||
// constraint checking: required value count with sufficient number of provided parameters
|
||||
const char *argv13[] = {"tageditor", "get", "--fields", "album=test", "title", "diskpos", "--files", "somefile"};
|
||||
const char *argv13[] = { "tageditor", "get", "--fields", "album=test", "title", "diskpos", "--files", "somefile" };
|
||||
verboseArg.setRequired(false);
|
||||
parser.resetArgs();
|
||||
parser.parseArgs(8, argv13);
|
||||
|
@ -330,19 +331,20 @@ void ArgumentParserTests::testParsing()
|
|||
CPPUNIT_ASSERT(!notAlbumArg.isPresent());
|
||||
|
||||
// constraint checking: required value count with insufficient number of provided parameters
|
||||
const char *argv9[] = {"tageditor", "-p", "album", "title", "diskpos"};
|
||||
const char *argv9[] = { "tageditor", "-p", "album", "title", "diskpos" };
|
||||
fieldsArg.setRequiredValueCount(4);
|
||||
parser.resetArgs();
|
||||
try {
|
||||
parser.parseArgs(5, argv9);
|
||||
CPPUNIT_FAIL("Exception expected.");
|
||||
} catch(const Failure &e) {
|
||||
} catch (const Failure &e) {
|
||||
CPPUNIT_ASSERT(!qtConfigArgs.qtWidgetsGuiArg().isPresent());
|
||||
CPPUNIT_ASSERT(!strcmp(e.what(), "Not all parameter for argument \"fields\" provided. You have to provide the following parameter: title album artist trackpos"));
|
||||
CPPUNIT_ASSERT(!strcmp(e.what(),
|
||||
"Not all parameter for argument \"fields\" provided. You have to provide the following parameter: title album artist trackpos"));
|
||||
}
|
||||
|
||||
// nested operations
|
||||
const char *argv14[] = {"tageditor", "get", "fields", "album=test", "-f", "somefile"};
|
||||
const char *argv14[] = { "tageditor", "get", "fields", "album=test", "-f", "somefile" };
|
||||
parser.resetArgs();
|
||||
fieldsArg.setRequiredValueCount(-1);
|
||||
fieldsArg.setDenotesOperation(true);
|
||||
|
@ -369,7 +371,7 @@ void ArgumentParserTests::testCallbacks()
|
|||
ArgumentParser parser;
|
||||
Argument callbackArg("with-callback", 't', "callback test");
|
||||
callbackArg.setRequiredValueCount(2);
|
||||
callbackArg.setCallback([] (const ArgumentOccurrence &occurrence) {
|
||||
callbackArg.setCallback([](const ArgumentOccurrence &occurrence) {
|
||||
CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(0), occurrence.index);
|
||||
CPPUNIT_ASSERT(occurrence.path.empty());
|
||||
CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(2), occurrence.values.size());
|
||||
|
@ -379,19 +381,19 @@ void ArgumentParserTests::testCallbacks()
|
|||
});
|
||||
Argument noCallbackArg("no-callback", 'l', "callback test");
|
||||
noCallbackArg.setRequiredValueCount(2);
|
||||
parser.setMainArguments({&callbackArg, &noCallbackArg});
|
||||
parser.setMainArguments({ &callbackArg, &noCallbackArg });
|
||||
|
||||
// test whether callback is invoked when argument with callback is specified
|
||||
const char *argv[] = {"test", "-t", "val1", "val2"};
|
||||
const char *argv[] = { "test", "-t", "val1", "val2" };
|
||||
try {
|
||||
parser.parseArgs(4, argv);
|
||||
} catch(int i) {
|
||||
} catch (int i) {
|
||||
CPPUNIT_ASSERT_EQUAL(i, 42);
|
||||
}
|
||||
|
||||
// test whether callback is not invoked when argument with callback is not specified
|
||||
callbackArg.reset();
|
||||
const char *argv2[] = {"test", "-l", "val1", "val2"};
|
||||
const char *argv2[] = { "test", "-l", "val1", "val2" };
|
||||
parser.parseArgs(4, argv2);
|
||||
}
|
||||
|
||||
|
@ -411,10 +413,10 @@ void ArgumentParserTests::testBashCompletion()
|
|||
filesArg.setCombinable(true);
|
||||
Argument nestedSubArg("nested-sub", '\0', "nested sub arg");
|
||||
Argument subArg("sub", '\0', "sub arg");
|
||||
subArg.setSubArguments({&nestedSubArg});
|
||||
subArg.setSubArguments({ &nestedSubArg });
|
||||
Argument displayFileInfoArg("display-file-info", 'i', "displays general file information");
|
||||
displayFileInfoArg.setDenotesOperation(true);
|
||||
displayFileInfoArg.setSubArguments({&filesArg, &verboseArg, &subArg});
|
||||
displayFileInfoArg.setSubArguments({ &filesArg, &verboseArg, &subArg });
|
||||
Argument fieldsArg("fields", '\0', "specifies the fields");
|
||||
fieldsArg.setRequiredValueCount(-1);
|
||||
fieldsArg.setPreDefinedCompletionValues("title album artist trackpos");
|
||||
|
@ -425,11 +427,11 @@ void ArgumentParserTests::testBashCompletion()
|
|||
valuesArg.setImplicit(true);
|
||||
valuesArg.setValueCompletionBehavior(ValueCompletionBehavior::PreDefinedValues | ValueCompletionBehavior::AppendEquationSign);
|
||||
Argument getArg("get", 'g', "gets tag values");
|
||||
getArg.setSubArguments({&fieldsArg, &filesArg});
|
||||
getArg.setSubArguments({ &fieldsArg, &filesArg });
|
||||
Argument setArg("set", 's', "sets tag values");
|
||||
setArg.setSubArguments({&valuesArg, &filesArg});
|
||||
setArg.setSubArguments({ &valuesArg, &filesArg });
|
||||
|
||||
parser.setMainArguments({&helpArg, &displayFileInfoArg, &getArg, &setArg});
|
||||
parser.setMainArguments({ &helpArg, &displayFileInfoArg, &getArg, &setArg });
|
||||
|
||||
// redirect cout to custom buffer
|
||||
stringstream buffer;
|
||||
|
@ -437,7 +439,7 @@ void ArgumentParserTests::testBashCompletion()
|
|||
|
||||
try {
|
||||
// fail due to operation flags not set
|
||||
const char *const argv1[] = {"se"};
|
||||
const char *const argv1[] = { "se" };
|
||||
ArgumentReader reader(parser, argv1, argv1 + 1, true);
|
||||
reader.read();
|
||||
parser.printBashCompletion(1, argv1, 0, reader);
|
||||
|
@ -454,7 +456,7 @@ void ArgumentParserTests::testBashCompletion()
|
|||
CPPUNIT_ASSERT_EQUAL("COMPREPLY=('set' )\n"s, buffer.str());
|
||||
|
||||
// argument at current cursor position already specified -> the completion should just return the argument
|
||||
const char *const argv2[] = {"set"};
|
||||
const char *const argv2[] = { "set" };
|
||||
buffer.str(string());
|
||||
cout.rdbuf(buffer.rdbuf());
|
||||
parser.resetArgs();
|
||||
|
@ -493,7 +495,7 @@ void ArgumentParserTests::testBashCompletion()
|
|||
CPPUNIT_ASSERT_EQUAL("COMPREPLY=('display-file-info' 'get' 'set' '--help' )\n"s, buffer.str());
|
||||
|
||||
// pre-defined values
|
||||
const char *const argv3[] = {"get", "--fields"};
|
||||
const char *const argv3[] = { "get", "--fields" };
|
||||
buffer.str(string());
|
||||
cout.rdbuf(buffer.rdbuf());
|
||||
parser.resetArgs();
|
||||
|
@ -503,7 +505,7 @@ void ArgumentParserTests::testBashCompletion()
|
|||
CPPUNIT_ASSERT_EQUAL("COMPREPLY=('title' 'album' 'artist' 'trackpos' '--files' )\n"s, buffer.str());
|
||||
|
||||
// pre-defined values with equation sign, one letter already present
|
||||
const char *const argv4[] = {"set", "--values", "a"};
|
||||
const char *const argv4[] = { "set", "--values", "a" };
|
||||
buffer.str(string());
|
||||
cout.rdbuf(buffer.rdbuf());
|
||||
parser.resetArgs();
|
||||
|
@ -518,7 +520,7 @@ void ArgumentParserTests::testBashCompletion()
|
|||
string mkvFilePath = TestUtilities::testFilePath("test 'with quote'.mkv");
|
||||
mkvFilePath.resize(mkvFilePath.size() - 17);
|
||||
TestUtilities::testFilePath("t.aac");
|
||||
const char *const argv5[] = {"get", "--files", iniFilePath.c_str()};
|
||||
const char *const argv5[] = { "get", "--files", iniFilePath.c_str() };
|
||||
buffer.str(string());
|
||||
cout.rdbuf(buffer.rdbuf());
|
||||
parser.resetArgs();
|
||||
|
@ -527,14 +529,16 @@ void ArgumentParserTests::testBashCompletion()
|
|||
cout.rdbuf(regularCoutBuffer);
|
||||
// order for file names is not specified
|
||||
const string res(buffer.str());
|
||||
if(res.find(".mkv") < res.find(".ini")) {
|
||||
CPPUNIT_ASSERT_EQUAL("COMPREPLY=('" % mkvFilePath % " '\"'\"'with quote'\"'\"'.mkv' '" % iniFilePath + ".ini' ); compopt -o filenames\n", buffer.str());
|
||||
if (res.find(".mkv") < res.find(".ini")) {
|
||||
CPPUNIT_ASSERT_EQUAL(
|
||||
"COMPREPLY=('" % mkvFilePath % " '\"'\"'with quote'\"'\"'.mkv' '" % iniFilePath + ".ini' ); compopt -o filenames\n", buffer.str());
|
||||
} else {
|
||||
CPPUNIT_ASSERT_EQUAL("COMPREPLY=('" % iniFilePath % ".ini' '" % mkvFilePath + " '\"'\"'with quote'\"'\"'.mkv' ); compopt -o filenames\n", buffer.str());
|
||||
CPPUNIT_ASSERT_EQUAL(
|
||||
"COMPREPLY=('" % iniFilePath % ".ini' '" % mkvFilePath + " '\"'\"'with quote'\"'\"'.mkv' ); compopt -o filenames\n", buffer.str());
|
||||
}
|
||||
|
||||
// sub arguments
|
||||
const char *const argv6[] = {"set", "--"};
|
||||
const char *const argv6[] = { "set", "--" };
|
||||
buffer.str(string());
|
||||
cout.rdbuf(buffer.rdbuf());
|
||||
parser.resetArgs();
|
||||
|
@ -544,7 +548,7 @@ void ArgumentParserTests::testBashCompletion()
|
|||
CPPUNIT_ASSERT_EQUAL("COMPREPLY=('--files' '--values' )\n"s, buffer.str());
|
||||
|
||||
// nested sub arguments
|
||||
const char *const argv7[] = {"-i", "--sub", "--"};
|
||||
const char *const argv7[] = { "-i", "--sub", "--" };
|
||||
buffer.str(string());
|
||||
cout.rdbuf(buffer.rdbuf());
|
||||
parser.resetArgs();
|
||||
|
@ -554,7 +558,7 @@ void ArgumentParserTests::testBashCompletion()
|
|||
CPPUNIT_ASSERT_EQUAL("COMPREPLY=('--files' '--nested-sub' '--verbose' )\n"s, buffer.str());
|
||||
|
||||
// started pre-defined values with equation sign, one letter already present, last value matches
|
||||
const char *const argv8[] = {"set", "--values", "t"};
|
||||
const char *const argv8[] = { "set", "--values", "t" };
|
||||
buffer.str(string());
|
||||
cout.rdbuf(buffer.rdbuf());
|
||||
parser.resetArgs();
|
||||
|
@ -564,7 +568,7 @@ void ArgumentParserTests::testBashCompletion()
|
|||
CPPUNIT_ASSERT_EQUAL("COMPREPLY=('title=' 'trackpos=' ); compopt -o nospace\n"s, buffer.str());
|
||||
|
||||
// combined abbreviations
|
||||
const char *const argv9[] = {"-gf"};
|
||||
const char *const argv9[] = { "-gf" };
|
||||
buffer.str(string());
|
||||
cout.rdbuf(buffer.rdbuf());
|
||||
parser.resetArgs();
|
||||
|
@ -581,7 +585,7 @@ void ArgumentParserTests::testBashCompletion()
|
|||
cout.rdbuf(regularCoutBuffer);
|
||||
CPPUNIT_ASSERT_EQUAL(static_cast<string::size_type>(0), buffer.str().find("COMPREPLY=('--fields' "));
|
||||
|
||||
} catch(...) {
|
||||
} catch (...) {
|
||||
cout.rdbuf(regularCoutBuffer);
|
||||
throw;
|
||||
}
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
#include "../chrono/datetime.h"
|
||||
#include "../chrono/timespan.h"
|
||||
#include "../chrono/period.h"
|
||||
#include "../chrono/format.h"
|
||||
#include "../chrono/period.h"
|
||||
#include "../chrono/timespan.h"
|
||||
#include "../conversion/conversionexception.h"
|
||||
|
||||
#include <cppunit/extensions/HelperMacros.h>
|
||||
#include <cppunit/TestFixture.h>
|
||||
#include <cppunit/extensions/HelperMacros.h>
|
||||
|
||||
#include <iostream>
|
||||
|
||||
|
@ -18,8 +18,7 @@ using namespace CPPUNIT_NS;
|
|||
/*!
|
||||
* \brief The ChronoTests class tests classes and methods of the ChronoUtilities namespace.
|
||||
*/
|
||||
class ChronoTests : public TestFixture
|
||||
{
|
||||
class ChronoTests : public TestFixture {
|
||||
CPPUNIT_TEST_SUITE(ChronoTests);
|
||||
CPPUNIT_TEST(testDateTime);
|
||||
CPPUNIT_TEST(testTimeSpan);
|
||||
|
@ -28,8 +27,12 @@ class ChronoTests : public TestFixture
|
|||
CPPUNIT_TEST_SUITE_END();
|
||||
|
||||
public:
|
||||
void setUp() {}
|
||||
void tearDown() {}
|
||||
void setUp()
|
||||
{
|
||||
}
|
||||
void tearDown()
|
||||
{
|
||||
}
|
||||
|
||||
void testDateTime();
|
||||
void testTimeSpan();
|
||||
|
@ -74,7 +77,7 @@ void ChronoTests::testDateTime()
|
|||
const auto test3 = DateTime::fromIsoString("2016-08-29T21:32:31.125+02:00");
|
||||
CPPUNIT_ASSERT_EQUAL("2016-08-29T21:32:31.125+02:00"s, test3.first.toIsoString(test3.second));
|
||||
|
||||
// test now() and exactNow() (or at least whether both behave the same)
|
||||
// test now() and exactNow() (or at least whether both behave the same)
|
||||
#if defined(PLATFORM_UNIX)
|
||||
const auto delta = DateTime::gmtNow() - DateTime::exactGmtNow();
|
||||
CPPUNIT_ASSERT(delta < TimeSpan::fromSeconds(2) && delta > TimeSpan::fromSeconds(-2));
|
||||
|
|
|
@ -1,15 +1,15 @@
|
|||
#include "../conversion/binaryconversion.h"
|
||||
#include "../conversion/stringconversion.h"
|
||||
#include "../conversion/stringbuilder.h"
|
||||
#include "../conversion/stringconversion.h"
|
||||
#include "../tests/testutils.h"
|
||||
|
||||
#include <cppunit/extensions/HelperMacros.h>
|
||||
#include <cppunit/TestFixture.h>
|
||||
#include <cppunit/extensions/HelperMacros.h>
|
||||
|
||||
#include <random>
|
||||
#include <sstream>
|
||||
#include <functional>
|
||||
#include <initializer_list>
|
||||
#include <random>
|
||||
#include <sstream>
|
||||
|
||||
using namespace std;
|
||||
using namespace ConversionUtilities;
|
||||
|
@ -20,8 +20,7 @@ using namespace CPPUNIT_NS;
|
|||
/*!
|
||||
* \brief The ConversionTests class tests classes and methods of the ConversionUtilities namespace.
|
||||
*/
|
||||
class ConversionTests : public TestFixture
|
||||
{
|
||||
class ConversionTests : public TestFixture {
|
||||
CPPUNIT_TEST_SUITE(ConversionTests);
|
||||
CPPUNIT_TEST(testEndianness);
|
||||
CPPUNIT_TEST(testBinaryConversions);
|
||||
|
@ -34,8 +33,12 @@ class ConversionTests : public TestFixture
|
|||
public:
|
||||
ConversionTests();
|
||||
|
||||
void setUp() {}
|
||||
void tearDown() {}
|
||||
void setUp()
|
||||
{
|
||||
}
|
||||
void tearDown()
|
||||
{
|
||||
}
|
||||
|
||||
void testEndianness();
|
||||
void testBinaryConversions();
|
||||
|
@ -45,8 +48,8 @@ public:
|
|||
void testStringBuilder();
|
||||
|
||||
private:
|
||||
template<typename intType>
|
||||
void testConversion(const char *message, function<void (intType, char *)> vice, function<intType (const char *)> verca, intType min, intType max);
|
||||
template <typename intType>
|
||||
void testConversion(const char *message, function<void(intType, char *)> vice, function<intType(const char *)> verca, intType min, intType max);
|
||||
|
||||
char m_buff[8];
|
||||
random_device m_randomDevice;
|
||||
|
@ -55,10 +58,11 @@ private:
|
|||
|
||||
CPPUNIT_TEST_SUITE_REGISTRATION(ConversionTests);
|
||||
|
||||
ConversionTests::ConversionTests() :
|
||||
m_randomDevice(),
|
||||
m_randomEngine(m_randomDevice())
|
||||
{}
|
||||
ConversionTests::ConversionTests()
|
||||
: m_randomDevice()
|
||||
, m_randomEngine(m_randomDevice())
|
||||
{
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Tests whether macros for endianness are correct.
|
||||
|
@ -68,7 +72,7 @@ void ConversionTests::testEndianness()
|
|||
union {
|
||||
uint32_t integer;
|
||||
char characters[4];
|
||||
} test = {0x01020304};
|
||||
} test = { 0x01020304 };
|
||||
#if defined(CONVERSION_UTILITIES_BYTE_ORDER_BIG_ENDIAN)
|
||||
// test whether macro definitions are consistent
|
||||
CPPUNIT_ASSERT(CONVERSION_UTILITIES_IS_BYTE_ORDER_BIG_ENDIAN == true);
|
||||
|
@ -86,8 +90,9 @@ void ConversionTests::testEndianness()
|
|||
#endif
|
||||
}
|
||||
|
||||
template<typename intType>
|
||||
void ConversionTests::testConversion(const char *message, function<void (intType, char *)> vice, function<intType (const char *)> versa, intType min, intType max)
|
||||
template <typename intType>
|
||||
void ConversionTests::testConversion(
|
||||
const char *message, function<void(intType, char *)> vice, function<intType(const char *)> versa, intType min, intType max)
|
||||
{
|
||||
const intType random = uniform_int_distribution<intType>(min, max)(m_randomEngine);
|
||||
stringstream msg;
|
||||
|
@ -96,35 +101,20 @@ void ConversionTests::testConversion(const char *message, function<void (intType
|
|||
CPPUNIT_ASSERT_MESSAGE(msg.str(), versa(m_buff) == random);
|
||||
}
|
||||
|
||||
#define TEST_TYPE(endianness, function) \
|
||||
decltype(endianness::function(m_buff))
|
||||
#define TEST_TYPE(endianness, function) decltype(endianness::function(m_buff))
|
||||
|
||||
#define TEST_CONVERSION(function, endianness) \
|
||||
testConversion<TEST_TYPE(endianness, function)>( \
|
||||
"testing " #function, \
|
||||
static_cast<void(*)(TEST_TYPE(endianness, function), char *)>(&endianness::getBytes), \
|
||||
endianness::function, \
|
||||
numeric_limits<TEST_TYPE(endianness, function)>::min(), \
|
||||
numeric_limits<TEST_TYPE(endianness, function)>::max() \
|
||||
)
|
||||
#define TEST_CONVERSION(function, endianness) \
|
||||
testConversion<TEST_TYPE(endianness, function)>("testing " #function, \
|
||||
static_cast<void (*)(TEST_TYPE(endianness, function), char *)>(&endianness::getBytes), endianness::function, \
|
||||
numeric_limits<TEST_TYPE(endianness, function)>::min(), numeric_limits<TEST_TYPE(endianness, function)>::max())
|
||||
|
||||
#define TEST_BE_CONVERSION(function) \
|
||||
TEST_CONVERSION( \
|
||||
function, BE \
|
||||
)
|
||||
#define TEST_BE_CONVERSION(function) TEST_CONVERSION(function, BE)
|
||||
|
||||
#define TEST_LE_CONVERSION(function) \
|
||||
TEST_CONVERSION( \
|
||||
function, LE \
|
||||
)
|
||||
#define TEST_LE_CONVERSION(function) TEST_CONVERSION(function, LE)
|
||||
|
||||
#define TEST_CUSTOM_CONVERSION(vice, versa, endianness, min, max) \
|
||||
testConversion<TEST_TYPE(endianness, versa)>( \
|
||||
"testing " #versa, \
|
||||
static_cast<void(*)(TEST_TYPE(endianness, versa), char *)>(&endianness::vice), \
|
||||
endianness::versa, \
|
||||
min, max \
|
||||
)
|
||||
#define TEST_CUSTOM_CONVERSION(vice, versa, endianness, min, max) \
|
||||
testConversion<TEST_TYPE(endianness, versa)>( \
|
||||
"testing " #versa, static_cast<void (*)(TEST_TYPE(endianness, versa), char *)>(&endianness::vice), endianness::versa, min, max)
|
||||
|
||||
/*!
|
||||
* \brief Tests most important binary conversions.
|
||||
|
@ -135,7 +125,7 @@ void ConversionTests::testConversion(const char *message, function<void (intType
|
|||
void ConversionTests::testBinaryConversions()
|
||||
{
|
||||
// test to...() / getBytes() with random numbers
|
||||
for(byte b = 1; b < 100; ++b) {
|
||||
for (byte b = 1; b < 100; ++b) {
|
||||
TEST_BE_CONVERSION(toUInt16);
|
||||
TEST_BE_CONVERSION(toUInt32);
|
||||
TEST_BE_CONVERSION(toUInt64);
|
||||
|
@ -173,17 +163,17 @@ void assertEqual(const char *message, const byte *expectedValues, size_t expecte
|
|||
// check whether contents match
|
||||
auto *end = expectedValues + expectedSize;
|
||||
auto *i = reinterpret_cast<byte *>(actualValues.first.get());
|
||||
for(; expectedValues != end; ++expectedValues, ++i) {
|
||||
for (; expectedValues != end; ++expectedValues, ++i) {
|
||||
CPPUNIT_ASSERT_EQUAL_MESSAGE(message, asHexNumber(*expectedValues), asHexNumber(*i));
|
||||
}
|
||||
}
|
||||
|
||||
#if CONVERSION_UTILITIES_IS_BYTE_ORDER_LITTLE_ENDIAN == true
|
||||
# define LE_STR_FOR_ENDIANNESS(name) name ## LE ## String
|
||||
# define BE_STR_FOR_ENDIANNESS(name) name ## BE ## String
|
||||
#define LE_STR_FOR_ENDIANNESS(name) name##LE##String
|
||||
#define BE_STR_FOR_ENDIANNESS(name) name##BE##String
|
||||
#elif CONVERSION_UTILITIES_IS_BYTE_ORDER_BIG_ENDIAN == true
|
||||
# define LE_STR_FOR_ENDIANNESS(name) name ## BE ## String
|
||||
# define BE_STR_FOR_ENDIANNESS(name) name ## LE ## String
|
||||
#define LE_STR_FOR_ENDIANNESS(name) name##BE##String
|
||||
#define BE_STR_FOR_ENDIANNESS(name) name##LE##String
|
||||
#endif
|
||||
|
||||
/*!
|
||||
|
@ -202,28 +192,34 @@ void assertEqual(const char *message, const byte *expectedValues, size_t expecte
|
|||
void ConversionTests::testStringEncodingConversions()
|
||||
{
|
||||
// define test string "ABCD" for the different encodings
|
||||
const byte simpleString[] = {'A', 'B', 'C', 'D'};
|
||||
const uint16 simpleUtf16LEString[] = {0x0041, 0x0042, 0x0043, 0x0044};
|
||||
const uint16 simpleUtf16BEString[] = {0x4100, 0x4200, 0x4300, 0x4400};
|
||||
const byte simpleString[] = { 'A', 'B', 'C', 'D' };
|
||||
const uint16 simpleUtf16LEString[] = { 0x0041, 0x0042, 0x0043, 0x0044 };
|
||||
const uint16 simpleUtf16BEString[] = { 0x4100, 0x4200, 0x4300, 0x4400 };
|
||||
// define test string "ABÖCD" for the different encodings
|
||||
const byte latin1String[] = {'A', 'B', 0xD6, 'C', 'D'};
|
||||
const byte utf8String[] = {'A', 'B', 0xC3, 0x96, 'C', 'D'};
|
||||
const uint16 utf16LEString[] = {0x0041, 0x0042, 0x00D6, 0x0043, 0x0044};
|
||||
const uint16 utf16BEString[] = {0x4100, 0x4200, 0xD600, 0x4300, 0x4400};
|
||||
const byte latin1String[] = { 'A', 'B', 0xD6, 'C', 'D' };
|
||||
const byte utf8String[] = { 'A', 'B', 0xC3, 0x96, 'C', 'D' };
|
||||
const uint16 utf16LEString[] = { 0x0041, 0x0042, 0x00D6, 0x0043, 0x0044 };
|
||||
const uint16 utf16BEString[] = { 0x4100, 0x4200, 0xD600, 0x4300, 0x4400 };
|
||||
// test conversion to UTF-8
|
||||
assertEqual("Latin-1 to UTF-8 (simple)", simpleString, 4, convertLatin1ToUtf8(reinterpret_cast<const char *>(simpleString), 4));
|
||||
assertEqual("Latin-1 to UTF-8", utf8String, 6, convertLatin1ToUtf8(reinterpret_cast<const char *>(latin1String), 5));
|
||||
assertEqual("UTF-16LE to UTF-8 (simple)", simpleString, 4, convertUtf16LEToUtf8(reinterpret_cast<const char *>(LE_STR_FOR_ENDIANNESS(simpleUtf16)), 8));
|
||||
assertEqual(
|
||||
"UTF-16LE to UTF-8 (simple)", simpleString, 4, convertUtf16LEToUtf8(reinterpret_cast<const char *>(LE_STR_FOR_ENDIANNESS(simpleUtf16)), 8));
|
||||
assertEqual("UTF-16LE to UTF-8", utf8String, 6, convertUtf16LEToUtf8(reinterpret_cast<const char *>(LE_STR_FOR_ENDIANNESS(utf16)), 10));
|
||||
assertEqual("UTF-16BE to UTF-8 (simple)", simpleString, 4, convertUtf16BEToUtf8(reinterpret_cast<const char *>(BE_STR_FOR_ENDIANNESS(simpleUtf16)), 8));
|
||||
assertEqual(
|
||||
"UTF-16BE to UTF-8 (simple)", simpleString, 4, convertUtf16BEToUtf8(reinterpret_cast<const char *>(BE_STR_FOR_ENDIANNESS(simpleUtf16)), 8));
|
||||
assertEqual("UTF-16BE to UTF-8", utf8String, 6, convertUtf16BEToUtf8(reinterpret_cast<const char *>(BE_STR_FOR_ENDIANNESS(utf16)), 10));
|
||||
// test conversion from UTF-8
|
||||
assertEqual("UTF-8 to Latin-1 (simple)", simpleString, 4, convertUtf8ToLatin1(reinterpret_cast<const char *>(simpleString), 4));
|
||||
assertEqual("UTF-8 to Latin-1", latin1String, 5, convertUtf8ToLatin1(reinterpret_cast<const char *>(utf8String), 6));
|
||||
assertEqual("UTF-8 to UFT-16LE (simple)", reinterpret_cast<const byte *>(LE_STR_FOR_ENDIANNESS(simpleUtf16)), 8, convertUtf8ToUtf16LE(reinterpret_cast<const char *>(simpleString), 4));
|
||||
assertEqual("UTF-8 to UFT-16LE", reinterpret_cast<const byte *>(LE_STR_FOR_ENDIANNESS(utf16)), 10, convertUtf8ToUtf16LE(reinterpret_cast<const char *>(utf8String), 6));
|
||||
assertEqual("UTF-8 to UFT-16BE (simple)", reinterpret_cast<const byte *>(BE_STR_FOR_ENDIANNESS(simpleUtf16)), 8, convertUtf8ToUtf16BE(reinterpret_cast<const char *>(simpleString), 4));
|
||||
assertEqual("UTF-8 to UFT-16BE", reinterpret_cast<const byte *>(BE_STR_FOR_ENDIANNESS(utf16)), 10, convertUtf8ToUtf16BE(reinterpret_cast<const char *>(utf8String), 6));
|
||||
assertEqual("UTF-8 to UFT-16LE (simple)", reinterpret_cast<const byte *>(LE_STR_FOR_ENDIANNESS(simpleUtf16)), 8,
|
||||
convertUtf8ToUtf16LE(reinterpret_cast<const char *>(simpleString), 4));
|
||||
assertEqual("UTF-8 to UFT-16LE", reinterpret_cast<const byte *>(LE_STR_FOR_ENDIANNESS(utf16)), 10,
|
||||
convertUtf8ToUtf16LE(reinterpret_cast<const char *>(utf8String), 6));
|
||||
assertEqual("UTF-8 to UFT-16BE (simple)", reinterpret_cast<const byte *>(BE_STR_FOR_ENDIANNESS(simpleUtf16)), 8,
|
||||
convertUtf8ToUtf16BE(reinterpret_cast<const char *>(simpleString), 4));
|
||||
assertEqual("UTF-8 to UFT-16BE", reinterpret_cast<const byte *>(BE_STR_FOR_ENDIANNESS(utf16)), 10,
|
||||
convertUtf8ToUtf16BE(reinterpret_cast<const char *>(utf8String), 6));
|
||||
}
|
||||
|
||||
/*!
|
||||
|
@ -236,16 +232,16 @@ void ConversionTests::testStringConversions()
|
|||
CPPUNIT_ASSERT_EQUAL(string("0"), numberToString<signed int>(0));
|
||||
uniform_int_distribution<int64> randomDistSigned(numeric_limits<int64>::min());
|
||||
uniform_int_distribution<uint64> randomDistUnsigned(0);
|
||||
for(byte b = 1; b < 100; ++b) {
|
||||
for (byte b = 1; b < 100; ++b) {
|
||||
auto signedRandom = randomDistSigned(m_randomEngine);
|
||||
auto unsignedRandom = randomDistUnsigned(m_randomEngine);
|
||||
for(const auto base : initializer_list<byte>{2, 8, 10, 16}) {
|
||||
for (const auto base : initializer_list<byte>{ 2, 8, 10, 16 }) {
|
||||
auto resultString = stringToNumber<uint64, string>(numberToString<uint64, string>(unsignedRandom, base), base);
|
||||
auto resultWideString = stringToNumber<uint64, wstring>(numberToString<uint64, wstring>(unsignedRandom, base), base);
|
||||
CPPUNIT_ASSERT_EQUAL(unsignedRandom, resultString);
|
||||
CPPUNIT_ASSERT_EQUAL(unsignedRandom, resultWideString);
|
||||
}
|
||||
for(const auto base : initializer_list<byte>{10}) {
|
||||
for (const auto base : initializer_list<byte>{ 10 }) {
|
||||
auto resultString = stringToNumber<int64, string>(numberToString<int64, string>(signedRandom, base), base);
|
||||
auto resultWideString = stringToNumber<int64, wstring>(numberToString<int64, wstring>(signedRandom, base), base);
|
||||
CPPUNIT_ASSERT_EQUAL(signedRandom, resultString);
|
||||
|
@ -265,13 +261,13 @@ void ConversionTests::testStringConversions()
|
|||
CPPUNIT_ASSERT(interpretIntegerAsString<uint32>(0x54455354) == "TEST");
|
||||
|
||||
// splitString() / joinStrings()
|
||||
string splitJoinTest = joinStrings(splitString<vector<string> >(",a,,ab,ABC,s"s, ","s, EmptyPartsTreat::Keep), " "s, false, "("s, ")"s);
|
||||
string splitJoinTest = joinStrings(splitString<vector<string>>(",a,,ab,ABC,s"s, ","s, EmptyPartsTreat::Keep), " "s, false, "("s, ")"s);
|
||||
CPPUNIT_ASSERT_EQUAL("() (a) () (ab) (ABC) (s)"s, splitJoinTest);
|
||||
splitJoinTest = joinStrings(splitString<vector<string> >(",a,,ab,ABC,s"s, ","s, EmptyPartsTreat::Keep), " "s, true, "("s, ")"s);
|
||||
splitJoinTest = joinStrings(splitString<vector<string>>(",a,,ab,ABC,s"s, ","s, EmptyPartsTreat::Keep), " "s, true, "("s, ")"s);
|
||||
CPPUNIT_ASSERT_EQUAL("(a) (ab) (ABC) (s)"s, splitJoinTest);
|
||||
splitJoinTest = joinStrings(splitString<vector<string> >(",a,,ab,ABC,s"s, ","s, EmptyPartsTreat::Omit), " "s, false, "("s, ")"s);
|
||||
splitJoinTest = joinStrings(splitString<vector<string>>(",a,,ab,ABC,s"s, ","s, EmptyPartsTreat::Omit), " "s, false, "("s, ")"s);
|
||||
CPPUNIT_ASSERT_EQUAL("(a) (ab) (ABC) (s)"s, splitJoinTest);
|
||||
splitJoinTest = joinStrings(splitString<vector<string> >(",a,,ab,ABC,s"s, ","s, EmptyPartsTreat::Merge), " "s, false, "("s, ")"s);
|
||||
splitJoinTest = joinStrings(splitString<vector<string>>(",a,,ab,ABC,s"s, ","s, EmptyPartsTreat::Merge), " "s, false, "("s, ")"s);
|
||||
CPPUNIT_ASSERT_EQUAL("(a,ab) (ABC) (s)"s, splitJoinTest);
|
||||
|
||||
// findAndReplace()
|
||||
|
@ -284,19 +280,19 @@ void ConversionTests::testStringConversions()
|
|||
CPPUNIT_ASSERT(startsWith<string>(findReplaceTest, "findOr"));
|
||||
|
||||
// containsSubstrings()
|
||||
CPPUNIT_ASSERT(containsSubstrings<string>("this string contains foo and bar", {"foo", "bar"}));
|
||||
CPPUNIT_ASSERT(!containsSubstrings<string>("this string contains foo and bar", {"bar", "foo"}));
|
||||
CPPUNIT_ASSERT(containsSubstrings<string>("this string contains foo and bar", { "foo", "bar" }));
|
||||
CPPUNIT_ASSERT(!containsSubstrings<string>("this string contains foo and bar", { "bar", "foo" }));
|
||||
|
||||
// encodeBase64() / decodeBase64() with random data
|
||||
uniform_int_distribution<byte> randomDistChar;
|
||||
byte originalBase64Data[4047];
|
||||
for(byte &c : originalBase64Data) {
|
||||
for (byte &c : originalBase64Data) {
|
||||
c = randomDistChar(m_randomEngine);
|
||||
}
|
||||
const auto encodedBase64Data = encodeBase64(originalBase64Data, sizeof(originalBase64Data));
|
||||
auto decodedBase64Data = decodeBase64(encodedBase64Data.data(), encodedBase64Data.size());
|
||||
CPPUNIT_ASSERT(decodedBase64Data.second == sizeof(originalBase64Data));
|
||||
for(unsigned int i = 0; i < sizeof(originalBase64Data); ++i) {
|
||||
for (unsigned int i = 0; i < sizeof(originalBase64Data); ++i) {
|
||||
CPPUNIT_ASSERT(decodedBase64Data.first[i] == originalBase64Data[i]);
|
||||
}
|
||||
}
|
||||
|
@ -315,8 +311,11 @@ void ConversionTests::testStringBuilder()
|
|||
CPPUNIT_ASSERT_EQUAL(string("v2.3.0"), argsToString("v2.", 3, '.', 0));
|
||||
|
||||
// construction of string-tuple and final conversion to string works
|
||||
CPPUNIT_ASSERT_EQUAL_MESSAGE("result can be passed to any function taking a std::string"s, "123456789"s, functionTakingString("12" % string("34") % '5' % 67 + "89"));
|
||||
CPPUNIT_ASSERT_EQUAL_MESSAGE(
|
||||
"result can be passed to any function taking a std::string"s, "123456789"s, functionTakingString("12" % string("34") % '5' % 67 + "89"));
|
||||
constexpr double velocityExample = 27.0;
|
||||
CPPUNIT_ASSERT_EQUAL_MESSAGE("real-word example"s, "velocity: 27 km/h (7.5 m/s)"s, functionTakingString("velocity: " % numberToString(velocityExample) % " km/h (" % numberToString(velocityExample / 3.6) + " m/s)"));
|
||||
CPPUNIT_ASSERT_EQUAL_MESSAGE("regular + operator still works (no problems with ambiguity)"s, "regular + still works"s, "regular"s + " + still works");
|
||||
CPPUNIT_ASSERT_EQUAL_MESSAGE("real-word example"s, "velocity: 27 km/h (7.5 m/s)"s,
|
||||
functionTakingString("velocity: " % numberToString(velocityExample) % " km/h (" % numberToString(velocityExample / 3.6) + " m/s)"));
|
||||
CPPUNIT_ASSERT_EQUAL_MESSAGE(
|
||||
"regular + operator still works (no problems with ambiguity)"s, "regular + still works"s, "regular"s + " + still works");
|
||||
}
|
||||
|
|
|
@ -3,17 +3,17 @@
|
|||
#include "../io/binaryreader.h"
|
||||
#include "../io/binarywriter.h"
|
||||
#include "../io/bitreader.h"
|
||||
#include "../io/path.h"
|
||||
#include "../io/inifile.h"
|
||||
#include "../io/copy.h"
|
||||
#include "../io/catchiofailure.h"
|
||||
#include "../io/copy.h"
|
||||
#include "../io/inifile.h"
|
||||
#include "../io/path.h"
|
||||
|
||||
#include <cppunit/extensions/HelperMacros.h>
|
||||
#include <cppunit/TestFixture.h>
|
||||
#include <cppunit/extensions/HelperMacros.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
#include <algorithm>
|
||||
|
||||
using namespace std;
|
||||
using namespace IoUtilities;
|
||||
|
@ -23,8 +23,7 @@ using namespace CPPUNIT_NS;
|
|||
/*!
|
||||
* \brief The IoTests class tests classes and methods of the IoUtilities namespace.
|
||||
*/
|
||||
class IoTests : public TestFixture
|
||||
{
|
||||
class IoTests : public TestFixture {
|
||||
CPPUNIT_TEST_SUITE(IoTests);
|
||||
CPPUNIT_TEST(testFailure);
|
||||
CPPUNIT_TEST(testBinaryReader);
|
||||
|
@ -51,10 +50,12 @@ public:
|
|||
CPPUNIT_TEST_SUITE_REGISTRATION(IoTests);
|
||||
|
||||
void IoTests::setUp()
|
||||
{}
|
||||
{
|
||||
}
|
||||
|
||||
void IoTests::tearDown()
|
||||
{}
|
||||
{
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Tests for GCC Bug 66145.
|
||||
|
@ -77,7 +78,7 @@ void IoTests::testFailure()
|
|||
fstream stream;
|
||||
stream.exceptions(ios_base::failbit | ios_base::badbit);
|
||||
stream.open("path/to/file/which/does/not/exist", ios_base::in);
|
||||
} catch(...) {
|
||||
} catch (...) {
|
||||
catchIoFailure();
|
||||
}
|
||||
}
|
||||
|
@ -160,9 +161,9 @@ void IoTests::testBinaryWriter()
|
|||
writer.writeUInt64BE(0x0102030405060708u);
|
||||
|
||||
// test written values
|
||||
for(char c : testData) {
|
||||
for (char c : testData) {
|
||||
CPPUNIT_ASSERT(c == static_cast<char>(testFile.get()));
|
||||
if(testFile.tellg() >= 58) {
|
||||
if (testFile.tellg() >= 58) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -193,7 +194,7 @@ void IoTests::testBinaryWriter()
|
|||
writer.writeTerminatedString("def");
|
||||
|
||||
// test written values
|
||||
for(char c : testData) {
|
||||
for (char c : testData) {
|
||||
CPPUNIT_ASSERT(c == static_cast<char>(testFile.get()));
|
||||
}
|
||||
}
|
||||
|
@ -203,7 +204,7 @@ void IoTests::testBinaryWriter()
|
|||
*/
|
||||
void IoTests::testBitReader()
|
||||
{
|
||||
const byte testData[] = {0x81, 0x90, 0x3C, 0x44, 0x28, 0x00, 0x44, 0x10, 0x20};
|
||||
const byte testData[] = { 0x81, 0x90, 0x3C, 0x44, 0x28, 0x00, 0x44, 0x10, 0x20 };
|
||||
BitReader reader(reinterpret_cast<const char *>(testData), sizeof(testData));
|
||||
CPPUNIT_ASSERT(reader.readBit() == 1);
|
||||
reader.skipBits(6);
|
||||
|
@ -218,10 +219,9 @@ void IoTests::testBitReader()
|
|||
CPPUNIT_ASSERT(reader.readBit() == 0);
|
||||
try {
|
||||
reader.readBit();
|
||||
} catch(...) {
|
||||
} catch (...) {
|
||||
catchIoFailure();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*!
|
||||
|
@ -312,7 +312,7 @@ void IoTests::testCopy()
|
|||
|
||||
// test
|
||||
testFile.seekg(0);
|
||||
for(byte i = 0; i < 50; ++i) {
|
||||
for (byte i = 0; i < 50; ++i) {
|
||||
CPPUNIT_ASSERT(testFile.get() == outputStream.get());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -188,7 +188,7 @@ string TestApplication::workingCopyPathMode(const string &name, WorkingCopyMode
|
|||
}
|
||||
|
||||
// ensure subdirectory exists
|
||||
const auto parts = splitString<vector<string> >(name, string("/"), EmptyPartsTreat::Omit);
|
||||
const auto parts = splitString<vector<string>>(name, string("/"), EmptyPartsTreat::Omit);
|
||||
if (!parts.empty()) {
|
||||
string currentLevel = m_workingDir;
|
||||
for (auto i = parts.cbegin(), end = parts.end() - 1; i != end; ++i) {
|
||||
|
|
Loading…
Reference in New Issue