2025-07-17 11:14:23 -07:00
|
|
|
/* Copyright (C) 2025 Wildfire Games.
|
2009-04-18 10:00:33 -07:00
|
|
|
*
|
2010-02-08 08:23:39 -08:00
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining
|
|
|
|
|
* a copy of this software and associated documentation files (the
|
|
|
|
|
* "Software"), to deal in the Software without restriction, including
|
|
|
|
|
* without limitation the rights to use, copy, modify, merge, publish,
|
|
|
|
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
|
|
|
|
* permit persons to whom the Software is furnished to do so, subject to
|
|
|
|
|
* the following conditions:
|
2016-11-23 03:18:37 -08:00
|
|
|
*
|
2010-02-08 08:23:39 -08:00
|
|
|
* The above copyright notice and this permission notice shall be included
|
|
|
|
|
* in all copies or substantial portions of the Software.
|
2016-11-23 03:18:37 -08:00
|
|
|
*
|
2010-02-08 08:23:39 -08:00
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
|
|
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
|
|
|
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
|
|
|
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
|
|
|
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
|
|
|
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
2009-04-18 10:00:33 -07:00
|
|
|
*/
|
|
|
|
|
|
2007-05-07 09:33:24 -07:00
|
|
|
#ifndef INCLUDED_SELF_TEST
|
|
|
|
|
#define INCLUDED_SELF_TEST
|
2006-04-23 16:14:18 -07:00
|
|
|
|
2024-09-13 04:27:42 -07:00
|
|
|
#include "lib/lib.h"
|
2011-03-23 07:43:35 -07:00
|
|
|
#include "lib/os_path.h"
|
2025-07-17 11:14:23 -07:00
|
|
|
#include "lib/self_test.h"
|
|
|
|
|
|
|
|
|
|
#include <cstddef>
|
|
|
|
|
#include <sstream>
|
|
|
|
|
#include <string>
|
|
|
|
|
#include <vector>
|
2006-06-08 12:03:43 -07:00
|
|
|
|
2006-08-22 14:38:53 -07:00
|
|
|
#define CXXTEST_HAVE_EH
|
|
|
|
|
#define CXXTEST_HAVE_STD
|
|
|
|
|
|
2006-11-11 20:02:36 -08:00
|
|
|
// If HAVE_STD wasn't defined at the point the ValueTraits header was included
|
|
|
|
|
// this header won't have been included and the default traits will be used for
|
|
|
|
|
// all variables... So fix that now ;-)
|
2025-08-12 11:29:24 -07:00
|
|
|
#include <cxxtest/GlobalFixture.h>
|
2006-11-11 20:02:36 -08:00
|
|
|
#include <cxxtest/StdValueTraits.h>
|
2006-06-08 12:03:43 -07:00
|
|
|
#include <cxxtest/TestSuite.h>
|
|
|
|
|
|
2016-01-13 14:39:09 -08:00
|
|
|
// TODO: The CStr and Vector code should not be in lib/
|
2006-12-09 06:39:52 -08:00
|
|
|
// Perform nice printing of CStr, based on std::string
|
|
|
|
|
#include "ps/CStr.h"
|
|
|
|
|
namespace CxxTest
|
|
|
|
|
{
|
|
|
|
|
CXXTEST_TEMPLATE_INSTANTIATION
|
|
|
|
|
class ValueTraits<const CStr8> : public ValueTraits<const CXXTEST_STD(string)>
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
ValueTraits( const CStr8 &s ) : ValueTraits<const CXXTEST_STD(string)>( s.c_str() ) {}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
CXXTEST_COPY_CONST_TRAITS( CStr8 );
|
|
|
|
|
|
|
|
|
|
CXXTEST_TEMPLATE_INSTANTIATION
|
|
|
|
|
class ValueTraits<const CStrW> : public ValueTraits<const CXXTEST_STD(wstring)>
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
ValueTraits( const CStrW &s ) : ValueTraits<const CXXTEST_STD(wstring)>( s.c_str() ) {}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
CXXTEST_COPY_CONST_TRAITS( CStrW );
|
|
|
|
|
}
|
|
|
|
|
|
2010-01-09 11:20:14 -08:00
|
|
|
// Perform nice printing of vectors
|
|
|
|
|
#include "maths/FixedVector3D.h"
|
2019-06-05 12:55:37 -07:00
|
|
|
#include "maths/Plane.h"
|
2010-01-09 11:20:14 -08:00
|
|
|
#include "maths/Vector3D.h"
|
2019-06-05 12:55:37 -07:00
|
|
|
|
2010-01-09 11:20:14 -08:00
|
|
|
namespace CxxTest
|
|
|
|
|
{
|
2019-06-05 12:55:37 -07:00
|
|
|
CXXTEST_TEMPLATE_INSTANTIATION
|
2010-01-09 11:20:14 -08:00
|
|
|
class ValueTraits<CFixedVector3D>
|
|
|
|
|
{
|
|
|
|
|
public:
|
2019-06-05 12:55:37 -07:00
|
|
|
ValueTraits(const CFixedVector3D& v)
|
2010-01-09 11:20:14 -08:00
|
|
|
{
|
|
|
|
|
std::stringstream s;
|
|
|
|
|
s << "[" << v.X.ToDouble() << ", " << v.Y.ToDouble() << ", " << v.Z.ToDouble() << "]";
|
2019-06-05 12:55:37 -07:00
|
|
|
m_StringRepr = s.str();
|
2010-01-09 11:20:14 -08:00
|
|
|
}
|
|
|
|
|
const char* asString() const
|
|
|
|
|
{
|
2019-06-05 12:55:37 -07:00
|
|
|
return m_StringRepr.c_str();
|
2010-01-09 11:20:14 -08:00
|
|
|
}
|
2019-06-05 12:55:37 -07:00
|
|
|
private:
|
|
|
|
|
std::string m_StringRepr;
|
2010-01-09 11:20:14 -08:00
|
|
|
};
|
|
|
|
|
|
2019-06-05 12:55:37 -07:00
|
|
|
CXXTEST_TEMPLATE_INSTANTIATION
|
2010-01-09 11:20:14 -08:00
|
|
|
class ValueTraits<CVector3D>
|
|
|
|
|
{
|
|
|
|
|
public:
|
2019-06-05 12:55:37 -07:00
|
|
|
ValueTraits(const CVector3D& v)
|
2010-01-09 11:20:14 -08:00
|
|
|
{
|
|
|
|
|
std::stringstream s;
|
|
|
|
|
s << "[" << v.X << ", " << v.Y << ", " << v.Z << "]";
|
2019-06-05 12:55:37 -07:00
|
|
|
m_StringRepr = s.str();
|
2010-01-09 11:20:14 -08:00
|
|
|
}
|
|
|
|
|
const char* asString() const
|
|
|
|
|
{
|
2019-06-05 12:55:37 -07:00
|
|
|
return m_StringRepr.c_str();
|
|
|
|
|
}
|
|
|
|
|
private:
|
|
|
|
|
std::string m_StringRepr;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
CXXTEST_TEMPLATE_INSTANTIATION
|
|
|
|
|
class ValueTraits<CPlane>
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
ValueTraits(const CPlane& p)
|
|
|
|
|
{
|
|
|
|
|
std::stringstream ss;
|
|
|
|
|
ss << "CPlane[";
|
|
|
|
|
ss << "Norm=" << TS_AS_STRING(p.m_Norm);
|
|
|
|
|
ss << ", Dist=" << TS_AS_STRING(p.m_Dist);
|
|
|
|
|
ss << "]";
|
|
|
|
|
m_StringRepr = ss.str();
|
2010-01-09 11:20:14 -08:00
|
|
|
}
|
2019-06-05 12:55:37 -07:00
|
|
|
const char* asString() const { return m_StringRepr.c_str(); }
|
|
|
|
|
private:
|
|
|
|
|
std::string m_StringRepr;
|
2010-01-09 11:20:14 -08:00
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2006-09-22 06:19:40 -07:00
|
|
|
#define TS_ASSERT_OK(expr) TS_ASSERT_EQUALS((expr), INFO::OK)
|
2010-01-10 11:29:27 -08:00
|
|
|
#define TSM_ASSERT_OK(m, expr) TSM_ASSERT_EQUALS(m, (expr), INFO::OK)
|
2006-08-22 14:38:53 -07:00
|
|
|
#define TS_ASSERT_STR_EQUALS(str1, str2) TS_ASSERT_EQUALS(std::string(str1), std::string(str2))
|
2010-01-10 11:29:27 -08:00
|
|
|
#define TSM_ASSERT_STR_EQUALS(m, str1, str2) TSM_ASSERT_EQUALS(m, std::string(str1), std::string(str2))
|
2006-11-07 13:03:13 -08:00
|
|
|
#define TS_ASSERT_WSTR_EQUALS(str1, str2) TS_ASSERT_EQUALS(std::wstring(str1), std::wstring(str2))
|
2010-01-10 11:29:27 -08:00
|
|
|
#define TSM_ASSERT_WSTR_EQUALS(m, str1, str2) TSM_ASSERT_EQUALS(m, std::wstring(str1), std::wstring(str2))
|
2011-03-23 14:15:22 -07:00
|
|
|
#define TS_ASSERT_PATH_EQUALS(path1, path2) TS_ASSERT_EQUALS((path1).string(), (path2).string())
|
|
|
|
|
#define TSM_ASSERT_PATH_EQUALS(m, path1, path2) TSM_ASSERT_EQUALS(m, (path1).string(), (path2).string())
|
2006-05-30 21:01:59 -07:00
|
|
|
|
2015-01-22 12:30:05 -08:00
|
|
|
bool ts_str_contains(const std::string& str1, const std::string& str2); // defined in test_setup.cpp
|
2009-11-03 13:46:35 -08:00
|
|
|
bool ts_str_contains(const std::wstring& str1, const std::wstring& str2); // defined in test_setup.cpp
|
2015-01-22 12:30:05 -08:00
|
|
|
#define TS_ASSERT_STR_CONTAINS(str1, str2) TSM_ASSERT(str1, ts_str_contains(str1, str2))
|
|
|
|
|
#define TS_ASSERT_STR_NOT_CONTAINS(str1, str2) TSM_ASSERT(str1, !ts_str_contains(str1, str2))
|
2010-01-09 11:20:14 -08:00
|
|
|
#define TS_ASSERT_WSTR_CONTAINS(str1, str2) TSM_ASSERT(str1, ts_str_contains(str1, str2))
|
|
|
|
|
#define TS_ASSERT_WSTR_NOT_CONTAINS(str1, str2) TSM_ASSERT(str1, !ts_str_contains(str1, str2))
|
2007-03-16 16:32:10 -07:00
|
|
|
|
2006-12-09 06:39:52 -08:00
|
|
|
template <typename T>
|
|
|
|
|
std::vector<T> ts_make_vector(T* start, size_t size_bytes)
|
|
|
|
|
{
|
|
|
|
|
return std::vector<T>(start, start+(size_bytes/sizeof(T)));
|
|
|
|
|
}
|
|
|
|
|
#define TS_ASSERT_VECTOR_EQUALS_ARRAY(vec1, array) TS_ASSERT_EQUALS(vec1, ts_make_vector((array), sizeof(array)))
|
2012-05-05 12:22:22 -07:00
|
|
|
#define TS_ASSERT_VECTOR_CONTAINS(vec1, element) TS_ASSERT(std::find((vec1).begin(), (vec1).end(), element) != (vec1).end());
|
2006-12-09 06:39:52 -08:00
|
|
|
|
2024-09-13 04:27:42 -07:00
|
|
|
#define TS_ASSERT_MATRIX_EQUALS_DELTA(m1, m2, size, epsilon) \
|
|
|
|
|
for (int j = 0; j < size; ++j) \
|
|
|
|
|
TS_ASSERT_DELTA(m1._data[j], m2._data[j], epsilon);
|
|
|
|
|
|
|
|
|
|
#define TS_ASSERT_MATRIX_DIFFERS_DELTA(m1, m2, size, epsilon) \
|
|
|
|
|
for (int j = 0; j < size; ++j) \
|
|
|
|
|
TS_ASSERT(!feq(m1._data[j], m2._data[j], epsilon));
|
|
|
|
|
|
2010-01-09 11:20:14 -08:00
|
|
|
class ScriptInterface;
|
|
|
|
|
// Script-based testing setup (defined in test_setup.cpp). Defines TS_* functions.
|
2017-08-23 17:32:42 -07:00
|
|
|
void ScriptTestSetup(const ScriptInterface&);
|
2010-01-09 11:20:14 -08:00
|
|
|
|
|
|
|
|
// Default game data directory
|
|
|
|
|
// (TODO: game-specific functions like this probably shouldn't be inside lib/, but it's useful
|
|
|
|
|
// here since lots of tests use it)
|
2011-03-23 06:36:20 -07:00
|
|
|
OsPath DataDir(); // defined in test_setup.cpp
|
2010-01-09 11:20:14 -08:00
|
|
|
|
2007-05-07 09:33:24 -07:00
|
|
|
#endif // #ifndef INCLUDED_SELF_TEST
|