Initial community commit
This commit is contained in:
parent
537bcbc862
commit
fc06254474
16440 changed files with 4239995 additions and 2 deletions
32
Src/external_dependencies/openmpt-trunk/test/TestTools.h
Normal file
32
Src/external_dependencies/openmpt-trunk/test/TestTools.h
Normal file
|
@ -0,0 +1,32 @@
|
|||
/*
|
||||
* TestTools.h
|
||||
* -----------
|
||||
* Purpose: Unit test framework.
|
||||
* Notes :
|
||||
* Authors: OpenMPT Devs
|
||||
* The OpenMPT source code is released under the BSD license. Read LICENSE for more details.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "openmpt/all/BuildSettings.hpp"
|
||||
|
||||
#include "TestToolsTracker.h"
|
||||
#include "TestToolsLib.h"
|
||||
|
||||
#include "../common/mptPathString.h"
|
||||
|
||||
OPENMPT_NAMESPACE_BEGIN
|
||||
|
||||
#ifdef ENABLE_TESTS
|
||||
|
||||
namespace Test
|
||||
{
|
||||
|
||||
mpt::PathString GetPathPrefix();
|
||||
|
||||
} // namespace Test
|
||||
|
||||
OPENMPT_NAMESPACE_END
|
||||
|
||||
#endif
|
309
Src/external_dependencies/openmpt-trunk/test/TestToolsLib.cpp
Normal file
309
Src/external_dependencies/openmpt-trunk/test/TestToolsLib.cpp
Normal file
|
@ -0,0 +1,309 @@
|
|||
/*
|
||||
* TestToolsLib.cpp
|
||||
* ----------------
|
||||
* Purpose: Unit test framework for libopenmpt.
|
||||
* Notes : Currently somewhat unreadable :/
|
||||
* Authors: OpenMPT Devs
|
||||
* The OpenMPT source code is released under the BSD license. Read LICENSE for more details.
|
||||
*/
|
||||
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "TestToolsLib.h"
|
||||
|
||||
|
||||
#ifdef ENABLE_TESTS
|
||||
#ifndef MODPLUG_TRACKER
|
||||
|
||||
|
||||
#include <exception>
|
||||
#include <iostream>
|
||||
|
||||
#include <cstdlib>
|
||||
|
||||
|
||||
OPENMPT_NAMESPACE_BEGIN
|
||||
|
||||
|
||||
namespace Test {
|
||||
|
||||
|
||||
|
||||
void mpt_test_reporter::case_run(const mpt::source_location& loc)
|
||||
{
|
||||
#if !MPT_OS_DJGPP
|
||||
std::cout << "TEST..: " << MPT_AFORMAT("{}({}):")(loc.file_name() ? loc.file_name() : "", loc.line()) << ": " << std::endl;
|
||||
#else
|
||||
MPT_UNUSED(loc);
|
||||
#endif
|
||||
}
|
||||
|
||||
void mpt_test_reporter::case_run(const mpt::source_location& loc, const char* text_e)
|
||||
{
|
||||
#if !MPT_OS_DJGPP
|
||||
std::cout << "TEST..: " << MPT_AFORMAT("{}({}): {}")(loc.file_name() ? loc.file_name() : "", loc.line(), text_e) << ": " << std::endl;
|
||||
#else
|
||||
MPT_UNUSED(loc);
|
||||
MPT_UNUSED(text_e);
|
||||
#endif
|
||||
}
|
||||
|
||||
void mpt_test_reporter::case_run(const mpt::source_location& loc, const char* text_ex, const char* text_e)
|
||||
{
|
||||
if(text_ex)
|
||||
{
|
||||
#if !MPT_OS_DJGPP
|
||||
std::cout << "TEST..: " << MPT_AFORMAT("{}({}): {} throws {}")(loc.file_name() ? loc.file_name() : "", loc.line(), text_e, text_ex) << ": " << std::endl;
|
||||
#else
|
||||
MPT_UNUSED(loc);
|
||||
MPT_UNUSED(text_ex);
|
||||
MPT_UNUSED(text_e);
|
||||
#endif
|
||||
} else
|
||||
{
|
||||
#if !MPT_OS_DJGPP
|
||||
std::cout << "TEST..: " << MPT_AFORMAT("{}({}): {} throws")(loc.file_name() ? loc.file_name() : "", loc.line(), text_e) << ": " << std::endl;
|
||||
#else
|
||||
MPT_UNUSED(loc);
|
||||
MPT_UNUSED(text_ex);
|
||||
MPT_UNUSED(text_e);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
void mpt_test_reporter::case_run(const mpt::source_location& loc, const char* text_a, const char* text_cmp, const char* text_b)
|
||||
{
|
||||
#if !MPT_OS_DJGPP
|
||||
std::cout << "TEST..: " << MPT_AFORMAT("{}({}): {} {} {}")(loc.file_name() ? loc.file_name() : "", loc.line(), text_a, text_cmp, text_b) << ": " << std::endl;
|
||||
#else
|
||||
MPT_UNUSED(loc);
|
||||
MPT_UNUSED(text_a);
|
||||
MPT_UNUSED(text_cmp);
|
||||
MPT_UNUSED(text_b);
|
||||
#endif
|
||||
}
|
||||
|
||||
void mpt_test_reporter::case_result(const mpt::source_location& loc, const mpt::test::result& result)
|
||||
{
|
||||
MPT_UNUSED(loc);
|
||||
if(std::holds_alternative<mpt::test::result_success>(result.info))
|
||||
{
|
||||
#if !MPT_OS_DJGPP
|
||||
std::cout << "RESULT: PASS" << std::endl;
|
||||
#endif
|
||||
} else if(std::holds_alternative<mpt::test::result_failure>(result.info))
|
||||
{
|
||||
fail_count++;
|
||||
std::cout << "RESULT: FAIL" << std::endl;
|
||||
std::cout.flush();
|
||||
std::cerr << "FAIL: " << "FAILURE: " << std::get<mpt::test::result_failure>(result.info).text << std::endl;
|
||||
std::cerr.flush();
|
||||
} else if(std::holds_alternative<mpt::test::result_unexpected_exception>(result.info))
|
||||
{
|
||||
fail_count++;
|
||||
std::cout << "RESULT: FAIL" << std::endl;
|
||||
std::cout.flush();
|
||||
std::cerr << "FAIL: " << "UNEXPECTED EXCEPTION: " << std::get<mpt::test::result_unexpected_exception>(result.info).text << std::endl;
|
||||
std::cerr.flush();
|
||||
} else
|
||||
{
|
||||
fail_count++;
|
||||
std::cout << "RESULT: FAIL" << std::endl;
|
||||
std::cout.flush();
|
||||
std::cerr << "FAIL: " << "UNKOWN" << std::endl;
|
||||
std::cerr.flush();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
int fail_count = 0;
|
||||
|
||||
|
||||
static std::string remove_newlines(std::string str)
|
||||
{
|
||||
return mpt::replace(mpt::replace(str, std::string("\n"), std::string(" ")), std::string("\r"), std::string(" "));
|
||||
}
|
||||
|
||||
|
||||
Testcase::Testcase(Fatality fatality, Verbosity verbosity, const char * const desc, const mpt::source_location &loc)
|
||||
: fatality(fatality)
|
||||
, verbosity(verbosity)
|
||||
, desc(desc)
|
||||
, loc(loc)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
std::string Testcase::AsString() const
|
||||
{
|
||||
return MPT_AFORMAT("{}({}): {}")(loc.file_name() ? loc.file_name() : "", loc.line(), remove_newlines(desc));
|
||||
}
|
||||
|
||||
|
||||
void Testcase::ShowStart() const
|
||||
{
|
||||
switch(verbosity)
|
||||
{
|
||||
case VerbosityQuiet:
|
||||
break;
|
||||
case VerbosityNormal:
|
||||
#if !MPT_OS_DJGPP
|
||||
std::cout << "TEST..: " << AsString() << ": " << std::endl;
|
||||
#endif
|
||||
break;
|
||||
case VerbosityVerbose:
|
||||
#if !MPT_OS_DJGPP
|
||||
std::cout << "TEST..: " << AsString() << ": " << std::endl;
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Testcase::ShowProgress(const char * text) const
|
||||
{
|
||||
switch(verbosity)
|
||||
{
|
||||
case VerbosityQuiet:
|
||||
break;
|
||||
case VerbosityNormal:
|
||||
break;
|
||||
case VerbosityVerbose:
|
||||
#if !MPT_OS_DJGPP
|
||||
std::cout << "TEST..: " << AsString() << ": " << text << std::endl;
|
||||
#else
|
||||
MPT_UNUSED_VARIABLE(text);
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Testcase::ShowPass() const
|
||||
{
|
||||
switch(verbosity)
|
||||
{
|
||||
case VerbosityQuiet:
|
||||
break;
|
||||
case VerbosityNormal:
|
||||
#if !MPT_OS_DJGPP
|
||||
std::cout << "RESULT: PASS" << std::endl;
|
||||
#endif
|
||||
break;
|
||||
case VerbosityVerbose:
|
||||
#if !MPT_OS_DJGPP
|
||||
std::cout << "PASS..: " << AsString() << std::endl;
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Testcase::ShowFail(bool exception, const char * const text) const
|
||||
{
|
||||
switch(verbosity)
|
||||
{
|
||||
case VerbosityQuiet:
|
||||
break;
|
||||
case VerbosityNormal:
|
||||
std::cout << "RESULT: FAIL" << std::endl;
|
||||
break;
|
||||
case VerbosityVerbose:
|
||||
std::cout << "FAIL..: " << AsString() << std::endl;
|
||||
break;
|
||||
}
|
||||
std::cout.flush();
|
||||
if(!exception)
|
||||
{
|
||||
if(!text || (text && std::string(text).empty()))
|
||||
{
|
||||
std::cerr << "FAIL: " << AsString() << std::endl;
|
||||
} else
|
||||
{
|
||||
std::cerr << "FAIL: " << AsString() << " : " << text << std::endl;
|
||||
}
|
||||
} else
|
||||
{
|
||||
if(!text || (text && std::string(text).empty()))
|
||||
{
|
||||
std::cerr << "FAIL: " << AsString() << " EXCEPTION!" << std::endl;
|
||||
} else
|
||||
{
|
||||
std::cerr << "FAIL: " << AsString() << " EXCEPTION: " << text << std::endl;
|
||||
}
|
||||
}
|
||||
std::cerr.flush();
|
||||
}
|
||||
|
||||
|
||||
void Testcase::ReportPassed()
|
||||
{
|
||||
ShowPass();
|
||||
}
|
||||
|
||||
|
||||
void Testcase::ReportFailed()
|
||||
{
|
||||
fail_count++;
|
||||
ReportException();
|
||||
}
|
||||
|
||||
|
||||
void Testcase::ReportException()
|
||||
{
|
||||
try
|
||||
{
|
||||
throw; // get the exception
|
||||
} catch(TestFailed & e)
|
||||
{
|
||||
ShowFail(false, e.values.c_str());
|
||||
if(fatality == FatalityStop)
|
||||
{
|
||||
throw; // rethrow
|
||||
}
|
||||
} catch(std::exception & e)
|
||||
{
|
||||
ShowFail(true, e.what());
|
||||
throw; // rethrow
|
||||
} catch(...)
|
||||
{
|
||||
ShowFail(true);
|
||||
throw; // rethrow
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} // namespace Test
|
||||
|
||||
|
||||
#if defined(MPT_ASSERT_HANDLER_NEEDED)
|
||||
|
||||
MPT_NOINLINE void AssertHandler(const mpt::source_location &loc, const char *expr, const char *msg)
|
||||
{
|
||||
Test::fail_count++;
|
||||
if(msg)
|
||||
{
|
||||
mpt::log::GlobalLogger().SendLogMessage(loc, LogError, "ASSERT",
|
||||
U_("ASSERTION FAILED: ") + mpt::ToUnicode(mpt::Charset::ASCII, msg) + U_(" (") + mpt::ToUnicode(mpt::Charset::ASCII, expr) + U_(")")
|
||||
);
|
||||
} else
|
||||
{
|
||||
mpt::log::GlobalLogger().SendLogMessage(loc, LogError, "ASSERT",
|
||||
U_("ASSERTION FAILED: ") + mpt::ToUnicode(mpt::Charset::ASCII, expr)
|
||||
);
|
||||
}
|
||||
#if defined(MPT_BUILD_FATAL_ASSERTS)
|
||||
std::abort();
|
||||
#endif // MPT_BUILD_FATAL_ASSERTS
|
||||
}
|
||||
|
||||
#endif // MPT_ASSERT_HANDLER_NEEDED
|
||||
|
||||
|
||||
OPENMPT_NAMESPACE_END
|
||||
|
||||
|
||||
#endif // !MODPLUG_TRACKER
|
||||
#endif // ENABLE_TESTS
|
362
Src/external_dependencies/openmpt-trunk/test/TestToolsLib.h
Normal file
362
Src/external_dependencies/openmpt-trunk/test/TestToolsLib.h
Normal file
|
@ -0,0 +1,362 @@
|
|||
/*
|
||||
* TestToolsLib.h
|
||||
* --------------
|
||||
* Purpose: Unit test framework for libopenmpt.
|
||||
* Notes : This is more complex than the OpenMPT version because we cannot
|
||||
* rely on a debugger and have to deal with exceptions ourselves.
|
||||
* Authors: OpenMPT Devs
|
||||
* The OpenMPT source code is released under the BSD license. Read LICENSE for more details.
|
||||
*/
|
||||
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "openmpt/all/BuildSettings.hpp"
|
||||
|
||||
|
||||
#ifdef ENABLE_TESTS
|
||||
#ifndef MODPLUG_TRACKER
|
||||
|
||||
|
||||
//#define MPT_TEST_CXX11
|
||||
|
||||
|
||||
#include "mpt/test/test.hpp"
|
||||
|
||||
#include <type_traits>
|
||||
|
||||
#include "mpt/base/bit.hpp"
|
||||
#include "openmpt/base/FlagSet.hpp"
|
||||
#include "../soundlib/Snd_defs.h"
|
||||
|
||||
|
||||
OPENMPT_NAMESPACE_BEGIN
|
||||
|
||||
|
||||
namespace Test {
|
||||
|
||||
|
||||
|
||||
class mpt_test_reporter
|
||||
: public mpt::test::silent_reporter
|
||||
{
|
||||
public:
|
||||
mpt_test_reporter() = default;
|
||||
~mpt_test_reporter() override = default;
|
||||
public:
|
||||
void case_run(const mpt::source_location & loc) override;
|
||||
void case_run(const mpt::source_location & loc, const char * text_e) override;
|
||||
void case_run(const mpt::source_location & loc, const char * text_ex, const char * text_e) override;
|
||||
void case_run(const mpt::source_location & loc, const char * text_a, const char * text_cmp, const char * text_b) override;
|
||||
void case_result(const mpt::source_location & loc, const mpt::test::result & result) override;
|
||||
};
|
||||
|
||||
|
||||
|
||||
extern int fail_count;
|
||||
|
||||
|
||||
enum Verbosity
|
||||
{
|
||||
VerbosityQuiet,
|
||||
VerbosityNormal,
|
||||
VerbosityVerbose,
|
||||
};
|
||||
|
||||
enum Fatality
|
||||
{
|
||||
FatalityContinue,
|
||||
FatalityStop
|
||||
};
|
||||
|
||||
|
||||
struct TestFailed
|
||||
{
|
||||
std::string values;
|
||||
TestFailed(const std::string &values) : values(values) { }
|
||||
TestFailed() { }
|
||||
};
|
||||
|
||||
} // namespace Test
|
||||
|
||||
template<typename T>
|
||||
struct ToStringHelper
|
||||
{
|
||||
std::string operator () (const T &x)
|
||||
{
|
||||
return mpt::afmt::val(x);
|
||||
}
|
||||
};
|
||||
|
||||
#ifdef MPT_TEST_CXX11
|
||||
|
||||
template<>
|
||||
struct ToStringHelper<mpt::endian>
|
||||
{
|
||||
std::string operator () (const mpt::endian &x)
|
||||
{
|
||||
if(x == mpt::endian::big) return "big";
|
||||
if(x == mpt::endian::little) return "little";
|
||||
return "unknown";
|
||||
}
|
||||
};
|
||||
|
||||
template<typename enum_t, typename store_t>
|
||||
struct ToStringHelper<FlagSet<enum_t, store_t> >
|
||||
{
|
||||
std::string operator () (const FlagSet<enum_t, store_t> &x)
|
||||
{
|
||||
return mpt::afmt::val(x.GetRaw());
|
||||
}
|
||||
};
|
||||
|
||||
template<typename enum_t>
|
||||
struct ToStringHelper<enum_value_type<enum_t> >
|
||||
{
|
||||
std::string operator () (const enum_value_type<enum_t> &x)
|
||||
{
|
||||
return mpt::afmt::val(x.as_bits());
|
||||
}
|
||||
};
|
||||
|
||||
template<typename Ta, typename Tb>
|
||||
struct ToStringHelper<std::pair<Ta, Tb> >
|
||||
{
|
||||
std::string operator () (const std::pair<Ta, Tb> &x)
|
||||
{
|
||||
return std::string("{") + mpt::afmt::val(x.first) + std::string(",") + mpt::afmt::val(x.second) + std::string("}");
|
||||
}
|
||||
};
|
||||
|
||||
template<std::size_t FRACT, typename T>
|
||||
struct ToStringHelper<FPInt<FRACT, T> >
|
||||
{
|
||||
std::string operator () (const FPInt<FRACT, T> &x)
|
||||
{
|
||||
return std::string("FPInt<") + mpt::afmt::val(FRACT) + std::string(",") + mpt::afmt::val(typeid(T).name()) + std::string(">{") + mpt::afmt::val(x.GetInt()) + std::string(".") + mpt::afmt::val(x.GetFract()) + std::string("}");
|
||||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
struct ToStringHelper<SamplePosition>
|
||||
{
|
||||
std::string operator () (const SamplePosition &x)
|
||||
{
|
||||
return mpt::afmt::val(x.GetInt()) + std::string(".") + std::string("0x") + mpt::afmt::hex0<8>(x.GetFract());
|
||||
}
|
||||
};
|
||||
|
||||
#endif // MPT_TEST_CXX11
|
||||
|
||||
|
||||
namespace Test {
|
||||
|
||||
class Testcase
|
||||
{
|
||||
|
||||
private:
|
||||
|
||||
Fatality const fatality;
|
||||
Verbosity const verbosity;
|
||||
const char * const desc;
|
||||
mpt::source_location const loc;
|
||||
|
||||
public:
|
||||
|
||||
Testcase(Fatality fatality, Verbosity verbosity, const char * const desc, const mpt::source_location &loc);
|
||||
|
||||
public:
|
||||
|
||||
std::string AsString() const;
|
||||
|
||||
void ShowStart() const;
|
||||
void ShowProgress(const char * text) const;
|
||||
void ShowPass() const;
|
||||
void ShowFail(bool exception = false, const char * const text = nullptr) const;
|
||||
|
||||
void ReportPassed();
|
||||
void ReportFailed();
|
||||
|
||||
void ReportException();
|
||||
|
||||
private:
|
||||
|
||||
template <typename Tx, typename Ty>
|
||||
inline bool IsEqual(const Tx &x, const Ty &y, std::false_type, std::false_type)
|
||||
{
|
||||
return (x == y);
|
||||
}
|
||||
|
||||
template <typename Tx, typename Ty>
|
||||
inline bool IsEqual(const Tx &x, const Ty &y, std::false_type, std::true_type)
|
||||
{
|
||||
return (x == y);
|
||||
}
|
||||
|
||||
template <typename Tx, typename Ty>
|
||||
inline bool IsEqual(const Tx &x, const Ty &y, std::true_type, std::false_type)
|
||||
{
|
||||
return (x == y);
|
||||
}
|
||||
|
||||
template <typename Tx, typename Ty>
|
||||
inline bool IsEqual(const Tx &x, const Ty &y, std::true_type /* is_integer */, std::true_type /* is_integer */ )
|
||||
{
|
||||
// Avoid signed-unsigned-comparison warnings and test equivalence in case of either type conversion direction.
|
||||
return ((x == static_cast<Tx>(y)) && (static_cast<Ty>(x) == y));
|
||||
}
|
||||
|
||||
template <typename Tx, typename Ty, typename Teps>
|
||||
inline bool IsEqualEpsilon(const Tx &x, const Ty &y, const Teps &eps)
|
||||
{
|
||||
return std::abs(x - y) <= eps;
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
#ifdef MPT_TEST_CXX11
|
||||
|
||||
private:
|
||||
|
||||
template <typename Tx, typename Ty>
|
||||
MPT_NOINLINE void TypeCompareHelper(const Tx &x, const Ty &y)
|
||||
{
|
||||
if(!IsEqual(x, y, std::is_integral<Tx>(), std::is_integral<Ty>()))
|
||||
{
|
||||
throw TestFailed(MPT_AFORMAT("{} != {}")(ToStringHelper<Tx>()(x), ToStringHelper<Ty>()(y)));
|
||||
//throw TestFailed();
|
||||
}
|
||||
}
|
||||
|
||||
template <typename Tx, typename Ty, typename Teps>
|
||||
MPT_NOINLINE void TypeCompareHelper(const Tx &x, const Ty &y, const Teps &eps)
|
||||
{
|
||||
if(!IsEqualEpsilon(x, y, eps))
|
||||
{
|
||||
throw TestFailed(MPT_AFORMAT("{} != {}")(ToStringHelper<Tx>()(x), ToStringHelper<Ty>()(y)));
|
||||
//throw TestFailed();
|
||||
}
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
template <typename Tfx, typename Tfy>
|
||||
MPT_NOINLINE void operator () (const Tfx &fx, const Tfy &fy)
|
||||
{
|
||||
ShowStart();
|
||||
try
|
||||
{
|
||||
ShowProgress("Calculate x ...");
|
||||
const auto x = fx();
|
||||
ShowProgress("Calculate y ...");
|
||||
const auto y = fy();
|
||||
ShowProgress("Compare ...");
|
||||
TypeCompareHelper(x, y);
|
||||
ReportPassed();
|
||||
} catch(...)
|
||||
{
|
||||
ReportFailed();
|
||||
}
|
||||
}
|
||||
|
||||
template <typename Tfx, typename Tfy, typename Teps>
|
||||
MPT_NOINLINE void operator () (const Tfx &fx, const Tfy &fy, const Teps &eps)
|
||||
{
|
||||
ShowStart();
|
||||
try
|
||||
{
|
||||
ShowProgress("Calculate x ...");
|
||||
const auto x = fx();
|
||||
ShowProgress("Calculate y ...");
|
||||
const auto y = fy();
|
||||
ShowProgress("Compare ...");
|
||||
TypeCompareHelper(x, y, eps);
|
||||
ReportPassed();
|
||||
} catch(...)
|
||||
{
|
||||
ReportFailed();
|
||||
}
|
||||
}
|
||||
|
||||
#define VERIFY_EQUAL(x,y) Test::Testcase(Test::FatalityContinue, Test::VerbosityNormal, #x " == " #y , MPT_SOURCE_LOCATION_CURRENT() )( [&](){return (x) ;}, [&](){return (y) ;} )
|
||||
#define VERIFY_EQUAL_NONCONT(x,y) Test::Testcase(Test::FatalityStop , Test::VerbosityNormal, #x " == " #y , MPT_SOURCE_LOCATION_CURRENT() )( [&](){return (x) ;}, [&](){return (y) ;} )
|
||||
#define VERIFY_EQUAL_QUIET_NONCONT(x,y) Test::Testcase(Test::FatalityStop , Test::VerbosityQuiet , #x " == " #y , MPT_SOURCE_LOCATION_CURRENT() )( [&](){return (x) ;}, [&](){return (y) ;} )
|
||||
|
||||
#define VERIFY_EQUAL_EPS(x,y,eps) Test::Testcase(Test::FatalityContinue, Test::VerbosityNormal, #x " == " #y , MPT_SOURCE_LOCATION_CURRENT() )( [&](){return (x) ;}, [&](){return (y) ;}, (eps) )
|
||||
|
||||
#else
|
||||
|
||||
public:
|
||||
|
||||
template <typename Tx, typename Ty>
|
||||
MPT_NOINLINE void operator () (const Tx &x, const Ty &y)
|
||||
{
|
||||
ShowStart();
|
||||
try
|
||||
{
|
||||
if(!IsEqual(x, y, std::is_integral<Tx>(), std::is_integral<Ty>()))
|
||||
{
|
||||
//throw TestFailed(MPT_AFORMAT("{} != {}")(x, y));
|
||||
throw TestFailed();
|
||||
}
|
||||
ReportPassed();
|
||||
} catch(...)
|
||||
{
|
||||
ReportFailed();
|
||||
}
|
||||
}
|
||||
|
||||
template <typename Tx, typename Ty, typename Teps>
|
||||
MPT_NOINLINE void operator () (const Tx &x, const Ty &y, const Teps &eps)
|
||||
{
|
||||
ShowStart();
|
||||
try
|
||||
{
|
||||
if(!IsEqualEpsilon(x, y, eps))
|
||||
{
|
||||
//throw TestFailed(MPT_AFORMAT("{} != {}")(x, y));
|
||||
throw TestFailed();
|
||||
}
|
||||
ReportPassed();
|
||||
} catch(...)
|
||||
{
|
||||
ReportFailed();
|
||||
}
|
||||
}
|
||||
|
||||
#define VERIFY_EQUAL(x,y) Test::Testcase(Test::FatalityContinue, Test::VerbosityNormal, #x " == " #y , MPT_SOURCE_LOCATION_CURRENT() )( (x) , (y) )
|
||||
#define VERIFY_EQUAL_NONCONT(x,y) Test::Testcase(Test::FatalityStop , Test::VerbosityNormal, #x " == " #y , MPT_SOURCE_LOCATION_CURRENT() )( (x) , (y) )
|
||||
#define VERIFY_EQUAL_QUIET_NONCONT(x,y) Test::Testcase(Test::FatalityStop , Test::VerbosityQuiet , #x " == " #y , MPT_SOURCE_LOCATION_CURRENT() )( (x) , (y) )
|
||||
|
||||
#define VERIFY_EQUAL_EPS(x,y,eps) Test::Testcase(Test::FatalityContinue, Test::VerbosityNormal, #x " == " #y , MPT_SOURCE_LOCATION_CURRENT() )( (x) , (y), (eps) )
|
||||
|
||||
#endif
|
||||
|
||||
};
|
||||
|
||||
|
||||
#define DO_TEST(func) \
|
||||
do { \
|
||||
Test::Testcase test(Test::FatalityStop, Test::VerbosityVerbose, #func , MPT_SOURCE_LOCATION_CURRENT() ); \
|
||||
try { \
|
||||
test.ShowStart(); \
|
||||
fail_count = 0; \
|
||||
func(); \
|
||||
if(fail_count > 0) { \
|
||||
throw Test::TestFailed(); \
|
||||
} \
|
||||
test.ReportPassed(); \
|
||||
} catch(...) { \
|
||||
test.ReportException(); \
|
||||
} \
|
||||
} while(0)
|
||||
|
||||
|
||||
} // namespace Test
|
||||
|
||||
|
||||
OPENMPT_NAMESPACE_END
|
||||
|
||||
|
||||
#endif // !MODPLUG_TRACKER
|
||||
#endif // ENABLE_TESTS
|
|
@ -0,0 +1,92 @@
|
|||
/*
|
||||
* TestToolsTracker.h
|
||||
* ------------------
|
||||
* Purpose: Unit test framework for OpenMPT.
|
||||
* Notes : Really basic functionality that relies on a debugger that catches
|
||||
* exceptions and breaks right at the spot where it gets thrown.
|
||||
* Authors: OpenMPT Devs
|
||||
* The OpenMPT source code is released under the BSD license. Read LICENSE for more details.
|
||||
*/
|
||||
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "openmpt/all/BuildSettings.hpp"
|
||||
|
||||
|
||||
#ifdef ENABLE_TESTS
|
||||
#ifdef MODPLUG_TRACKER
|
||||
|
||||
|
||||
#include "mpt/test/test.hpp"
|
||||
|
||||
|
||||
OPENMPT_NAMESPACE_BEGIN
|
||||
|
||||
|
||||
namespace Test {
|
||||
|
||||
|
||||
#if MPT_COMPILER_MSVC
|
||||
// With MSVC, break directly using __debugbreak intrinsic instead of calling DebugBreak which breaks one stackframe deeper than we want
|
||||
#define MyDebugBreak() __debugbreak()
|
||||
#else
|
||||
#define MyDebugBreak() DebugBreak()
|
||||
#endif
|
||||
|
||||
|
||||
class mpt_test_reporter
|
||||
: public mpt::test::silent_reporter
|
||||
{
|
||||
public:
|
||||
mpt_test_reporter() = default;
|
||||
~mpt_test_reporter() override = default;
|
||||
public:
|
||||
inline void immediate_breakpoint() override {
|
||||
MyDebugBreak();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// Verify that given parameters are 'equal'. Break directly into the debugger if not.
|
||||
// The exact meaning of equality is based on operator== of the compared types.
|
||||
#define VERIFY_EQUAL(x,y) \
|
||||
do { \
|
||||
if(!((x) == (y))) { \
|
||||
MyDebugBreak(); \
|
||||
} \
|
||||
} while(0) \
|
||||
/**/
|
||||
|
||||
// Like VERIFY_EQUAL, only differs for libopenmpt
|
||||
#define VERIFY_EQUAL_NONCONT VERIFY_EQUAL
|
||||
|
||||
// Like VERIFY_EQUAL, only differs for libopenmpt
|
||||
#define VERIFY_EQUAL_QUIET_NONCONT VERIFY_EQUAL
|
||||
|
||||
#define VERIFY_EQUAL_EPS(x,y,eps) \
|
||||
do { \
|
||||
if(std::abs((x) - (y)) > (eps)) { \
|
||||
MyDebugBreak(); \
|
||||
} \
|
||||
} while(0) \
|
||||
/**/
|
||||
|
||||
|
||||
#define DO_TEST(func) \
|
||||
do { \
|
||||
if(IsDebuggerPresent()) { \
|
||||
func(); \
|
||||
} \
|
||||
} while(0) \
|
||||
/**/
|
||||
|
||||
|
||||
} // namespace Test
|
||||
|
||||
|
||||
OPENMPT_NAMESPACE_END
|
||||
|
||||
|
||||
#endif // MODPLUG_TRACKER
|
||||
#endif // ENABLE_TESTS
|
|
@ -0,0 +1,13 @@
|
|||
|
||||
#include "stdafx.h"
|
||||
|
||||
#ifdef ENABLE_TESTS
|
||||
|
||||
#include "mpt/base/tests/tests_base_arithmetic_shift.hpp"
|
||||
#include "mpt/base/tests/tests_base_bit.hpp"
|
||||
#include "mpt/base/tests/tests_base_math.hpp"
|
||||
#include "mpt/base/tests/tests_base_saturate_cast.hpp"
|
||||
#include "mpt/base/tests/tests_base_saturate_round.hpp"
|
||||
#include "mpt/base/tests/tests_base_wrapping_divide.hpp"
|
||||
|
||||
#endif
|
|
@ -0,0 +1,8 @@
|
|||
|
||||
#include "stdafx.h"
|
||||
|
||||
#ifdef ENABLE_TESTS
|
||||
|
||||
#include "mpt/binary/tests/tests_binary.hpp"
|
||||
|
||||
#endif
|
|
@ -0,0 +1,8 @@
|
|||
|
||||
#include "stdafx.h"
|
||||
|
||||
#ifdef ENABLE_TESTS
|
||||
|
||||
#include "mpt/crc/tests/tests_crc.hpp"
|
||||
|
||||
#endif
|
|
@ -0,0 +1,10 @@
|
|||
|
||||
#include "stdafx.h"
|
||||
|
||||
#ifdef ENABLE_TESTS
|
||||
|
||||
#ifdef MODPLUG_TRACKER
|
||||
#include "mpt/crypto/tests/tests_crypto.hpp"
|
||||
#endif // MODPLUG_TRACKER
|
||||
|
||||
#endif
|
|
@ -0,0 +1,9 @@
|
|||
|
||||
#include "stdafx.h"
|
||||
|
||||
#ifdef ENABLE_TESTS
|
||||
|
||||
#include "mpt/endian/tests/tests_endian_floatingpoint.hpp"
|
||||
#include "mpt/endian/tests/tests_endian_integer.hpp"
|
||||
|
||||
#endif
|
|
@ -0,0 +1,9 @@
|
|||
|
||||
#include "stdafx.h"
|
||||
|
||||
#ifdef ENABLE_TESTS
|
||||
|
||||
#include "mpt/format/tests/tests_format_message.hpp"
|
||||
#include "mpt/format/tests/tests_format_simple.hpp"
|
||||
|
||||
#endif
|
|
@ -0,0 +1,8 @@
|
|||
|
||||
#include "stdafx.h"
|
||||
|
||||
#ifdef ENABLE_TESTS
|
||||
|
||||
#include "mpt/io/tests/tests_io.hpp"
|
||||
|
||||
#endif
|
|
@ -0,0 +1,8 @@
|
|||
|
||||
#include "stdafx.h"
|
||||
|
||||
#ifdef ENABLE_TESTS
|
||||
|
||||
#include "mpt/parse/tests/tests_parse.hpp"
|
||||
|
||||
#endif
|
|
@ -0,0 +1,8 @@
|
|||
|
||||
#include "stdafx.h"
|
||||
|
||||
#ifdef ENABLE_TESTS
|
||||
|
||||
#include "mpt/random/tests/tests_random.hpp"
|
||||
|
||||
#endif
|
|
@ -0,0 +1,9 @@
|
|||
|
||||
#include "stdafx.h"
|
||||
|
||||
#ifdef ENABLE_TESTS
|
||||
|
||||
#include "mpt/string/tests/tests_string_buffer.hpp"
|
||||
#include "mpt/string/tests/tests_string_utility.hpp"
|
||||
|
||||
#endif
|
|
@ -0,0 +1,8 @@
|
|||
|
||||
#include "stdafx.h"
|
||||
|
||||
#ifdef ENABLE_TESTS
|
||||
|
||||
#include "mpt/string_transcode/tests/tests_string_transcode.hpp"
|
||||
|
||||
#endif
|
|
@ -0,0 +1,8 @@
|
|||
|
||||
#include "stdafx.h"
|
||||
|
||||
#ifdef ENABLE_TESTS
|
||||
|
||||
#include "mpt/uuid/tests/tests_uuid.hpp"
|
||||
|
||||
#endif
|
|
@ -0,0 +1,10 @@
|
|||
|
||||
#include "stdafx.h"
|
||||
|
||||
#ifdef ENABLE_TESTS
|
||||
|
||||
#ifdef MODPLUG_TRACKER
|
||||
#include "mpt/uuid_namespace/tests/tests_uuid_namespace.hpp"
|
||||
#endif // MODPLUG_TRACKER
|
||||
|
||||
#endif
|
3859
Src/external_dependencies/openmpt-trunk/test/test.cpp
Normal file
3859
Src/external_dependencies/openmpt-trunk/test/test.cpp
Normal file
File diff suppressed because it is too large
Load diff
BIN
Src/external_dependencies/openmpt-trunk/test/test.flac
Normal file
BIN
Src/external_dependencies/openmpt-trunk/test/test.flac
Normal file
Binary file not shown.
24
Src/external_dependencies/openmpt-trunk/test/test.h
Normal file
24
Src/external_dependencies/openmpt-trunk/test/test.h
Normal file
|
@ -0,0 +1,24 @@
|
|||
/*
|
||||
* test.h
|
||||
* ------
|
||||
* Purpose: Unit tests for OpenMPT.
|
||||
* Notes : We need FAAAAAAAR more unit tests!
|
||||
* Authors: Olivier Lapicque
|
||||
* OpenMPT Devs
|
||||
* The OpenMPT source code is released under the BSD license. Read LICENSE for more details.
|
||||
*/
|
||||
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "openmpt/all/BuildSettings.hpp"
|
||||
|
||||
OPENMPT_NAMESPACE_BEGIN
|
||||
|
||||
namespace Test {
|
||||
|
||||
void DoTests();
|
||||
|
||||
} // namespace Test
|
||||
|
||||
OPENMPT_NAMESPACE_END
|
BIN
Src/external_dependencies/openmpt-trunk/test/test.mod
Normal file
BIN
Src/external_dependencies/openmpt-trunk/test/test.mod
Normal file
Binary file not shown.
BIN
Src/external_dependencies/openmpt-trunk/test/test.mptm
Normal file
BIN
Src/external_dependencies/openmpt-trunk/test/test.mptm
Normal file
Binary file not shown.
BIN
Src/external_dependencies/openmpt-trunk/test/test.s3m
Normal file
BIN
Src/external_dependencies/openmpt-trunk/test/test.s3m
Normal file
Binary file not shown.
BIN
Src/external_dependencies/openmpt-trunk/test/test.xm
Normal file
BIN
Src/external_dependencies/openmpt-trunk/test/test.xm
Normal file
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue