XtoolsCommon tests.

This commit is contained in:
Jief L 2020-05-01 00:43:44 +03:00
parent c903faa26a
commit 5ad1616d7f
7 changed files with 230 additions and 45 deletions

View File

@ -130,6 +130,14 @@
9A9AEB9B243F7B8400FBD7D8 /* unicode_conversions.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9A9AEB90243F7B5600FBD7D8 /* unicode_conversions.cpp */; };
9A9AEB9C243F7B8400FBD7D8 /* unicode_conversions.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9A9AEB90243F7B5600FBD7D8 /* unicode_conversions.cpp */; };
9A9D3B2324221563006D8CD9 /* printf_lite-test.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9A9D3B2124221563006D8CD9 /* printf_lite-test.cpp */; };
9A9EA7FE245AD97F0076EC02 /* XToolsCommon_test.h in Headers */ = {isa = PBXBuildFile; fileRef = 9A9EA7FC245AD97E0076EC02 /* XToolsCommon_test.h */; };
9A9EA7FF245AD97F0076EC02 /* XToolsCommon_test.h in Headers */ = {isa = PBXBuildFile; fileRef = 9A9EA7FC245AD97E0076EC02 /* XToolsCommon_test.h */; };
9A9EA800245AD97F0076EC02 /* XToolsCommon_test.h in Headers */ = {isa = PBXBuildFile; fileRef = 9A9EA7FC245AD97E0076EC02 /* XToolsCommon_test.h */; };
9A9EA801245AD97F0076EC02 /* XToolsCommon_test.h in Headers */ = {isa = PBXBuildFile; fileRef = 9A9EA7FC245AD97E0076EC02 /* XToolsCommon_test.h */; };
9A9EA806245AD9B30076EC02 /* XToolsCommon_test.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9A9EA7FD245AD97F0076EC02 /* XToolsCommon_test.cpp */; };
9A9EA807245AD9B30076EC02 /* XToolsCommon_test.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9A9EA7FD245AD97F0076EC02 /* XToolsCommon_test.cpp */; };
9A9EA808245AD9B40076EC02 /* XToolsCommon_test.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9A9EA7FD245AD97F0076EC02 /* XToolsCommon_test.cpp */; };
9A9EA80A245AD9E50076EC02 /* XToolsCommon_test.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9A9EA7FD245AD97F0076EC02 /* XToolsCommon_test.cpp */; };
9AC77FB924176C04005CDD5C /* XStringArray_test.h in Headers */ = {isa = PBXBuildFile; fileRef = 9AC77ECC24176C04005CDD5C /* XStringArray_test.h */; };
9AC77FBA24176C04005CDD5C /* XArray_tests.h in Headers */ = {isa = PBXBuildFile; fileRef = 9AC77ECD24176C04005CDD5C /* XArray_tests.h */; };
9AC77FBB24176C04005CDD5C /* XStringArray_test.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9AC77ECE24176C04005CDD5C /* XStringArray_test.cpp */; };
@ -890,6 +898,8 @@
9A9AEB93243F7B5600FBD7D8 /* unicode_conversions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = unicode_conversions.h; sourceTree = "<group>"; };
9A9AEB98243F7B7900FBD7D8 /* printf_lite-test.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "printf_lite-test.h"; sourceTree = "<group>"; };
9A9D3B2124221563006D8CD9 /* printf_lite-test.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = "printf_lite-test.cpp"; sourceTree = "<group>"; };
9A9EA7FC245AD97E0076EC02 /* XToolsCommon_test.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = XToolsCommon_test.h; sourceTree = "<group>"; };
9A9EA7FD245AD97F0076EC02 /* XToolsCommon_test.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = XToolsCommon_test.cpp; sourceTree = "<group>"; };
9AC77EC424176BF2005CDD5C /* libCloverX64.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libCloverX64.a; sourceTree = BUILT_PRODUCTS_DIR; };
9AC77ECC24176C04005CDD5C /* XStringArray_test.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = XStringArray_test.h; sourceTree = "<group>"; };
9AC77ECD24176C04005CDD5C /* XArray_tests.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = XArray_tests.h; sourceTree = "<group>"; };
@ -1170,6 +1180,8 @@
9AC77ECA24176C04005CDD5C /* cpp_unit_test */ = {
isa = PBXGroup;
children = (
9A9EA7FD245AD97F0076EC02 /* XToolsCommon_test.cpp */,
9A9EA7FC245AD97E0076EC02 /* XToolsCommon_test.h */,
9A9AEB98243F7B7900FBD7D8 /* printf_lite-test.h */,
9AC77ED424176C04005CDD5C /* all_tests.cpp */,
9AC77ED724176C04005CDD5C /* all_tests.h */,
@ -1491,6 +1503,7 @@
9AF41562242BABC700D2644C /* printlib-test-cpp_conf.h in Headers */,
9AC7808D24176C04005CDD5C /* XStringArray.h in Headers */,
9A105B7824483AE40006DE06 /* usbfix.h in Headers */,
9A9EA7FE245AD97F0076EC02 /* XToolsCommon_test.h in Headers */,
9A28CD33241BC0DF00F3D247 /* strcmp_test.h in Headers */,
9AC7802124176C04005CDD5C /* boot.h in Headers */,
9A7AEDE7245963BF003AAD04 /* XToolsCommon.h in Headers */,
@ -1600,6 +1613,7 @@
buildActionMask = 2147483647;
files = (
9ACFE64E24309AF80071CC93 /* abort.h in Headers */,
9A9EA801245AD97F0076EC02 /* XToolsCommon_test.h in Headers */,
9ACFE64F24309AF80071CC93 /* MSKEK.h in Headers */,
9ACFE65024309AF80071CC93 /* menu_items.h in Headers */,
9ACFE65124309AF80071CC93 /* XTheme.h in Headers */,
@ -1762,6 +1776,7 @@
9AF415D0242CD75C00D2644C /* Hibernate.h in Headers */,
9AF415D1242CD75C00D2644C /* strlen_test.h in Headers */,
9AF415D2242CD75C00D2644C /* XArray_tests.h in Headers */,
9A9EA7FF245AD97F0076EC02 /* XToolsCommon_test.h in Headers */,
9AF415D3242CD75C00D2644C /* Handle.h in Headers */,
9AF415D4242CD75C00D2644C /* XArray.h in Headers */,
9AF415D5242CD75C00D2644C /* MSPCADB.h in Headers */,
@ -1857,6 +1872,7 @@
9AF416AD242CDA5800D2644C /* Hibernate.h in Headers */,
9AF416AE242CDA5800D2644C /* strlen_test.h in Headers */,
9AF416AF242CDA5800D2644C /* XArray_tests.h in Headers */,
9A9EA800245AD97F0076EC02 /* XToolsCommon_test.h in Headers */,
9AF416B0242CDA5800D2644C /* Handle.h in Headers */,
9AF416B1242CDA5800D2644C /* XArray.h in Headers */,
9AF416B2242CDA5800D2644C /* MSPCADB.h in Headers */,
@ -2171,6 +2187,7 @@
9AC7805E24176C04005CDD5C /* common.cpp in Sources */,
9AC7804924176C04005CDD5C /* egemb_icons.cpp in Sources */,
9AC7801124176C04005CDD5C /* Edid.cpp in Sources */,
9A9EA80A245AD9E50076EC02 /* XToolsCommon_test.cpp in Sources */,
9AC7803A24176C04005CDD5C /* smbios.cpp in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
@ -2284,6 +2301,7 @@
9ACFE71F24309AF80071CC93 /* common.cpp in Sources */,
9ACFE72024309AF80071CC93 /* egemb_icons.cpp in Sources */,
9ACFE72124309AF80071CC93 /* Edid.cpp in Sources */,
9A9EA806245AD9B30076EC02 /* XToolsCommon_test.cpp in Sources */,
9ACFE72224309AF80071CC93 /* smbios.cpp in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
@ -2397,6 +2415,7 @@
9AF41655242CD75C00D2644C /* common.cpp in Sources */,
9AF41656242CD75C00D2644C /* egemb_icons.cpp in Sources */,
9AF41657242CD75C00D2644C /* Edid.cpp in Sources */,
9A9EA808245AD9B40076EC02 /* XToolsCommon_test.cpp in Sources */,
9AF41658242CD75C00D2644C /* smbios.cpp in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
@ -2510,6 +2529,7 @@
9AF41732242CDA5800D2644C /* common.cpp in Sources */,
9AF41733242CDA5800D2644C /* egemb_icons.cpp in Sources */,
9AF41734242CDA5800D2644C /* Edid.cpp in Sources */,
9A9EA807245AD9B30076EC02 /* XToolsCommon_test.cpp in Sources */,
9AF41735242CDA5800D2644C /* smbios.cpp in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;

View File

@ -85,6 +85,10 @@
9A9AEB8D243F73CE00FBD7D8 /* unicode_conversions.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9A9AEB8C243F73CE00FBD7D8 /* unicode_conversions.cpp */; };
9A9AEB8E243F752C00FBD7D8 /* unicode_conversions.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9A9AEB8C243F73CE00FBD7D8 /* unicode_conversions.cpp */; };
9A9AEB8F243F752C00FBD7D8 /* unicode_conversions.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9A9AEB8C243F73CE00FBD7D8 /* unicode_conversions.cpp */; };
9A9EA7F8245AAB310076EC02 /* XToolsCommon_test.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9A9EA7F7245AAB310076EC02 /* XToolsCommon_test.cpp */; };
9A9EA7F9245AAB310076EC02 /* XToolsCommon_test.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9A9EA7F7245AAB310076EC02 /* XToolsCommon_test.cpp */; };
9A9EA7FA245AAB310076EC02 /* XToolsCommon_test.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9A9EA7F7245AAB310076EC02 /* XToolsCommon_test.cpp */; };
9A9EA7FB245AAB310076EC02 /* XToolsCommon_test.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9A9EA7F7245AAB310076EC02 /* XToolsCommon_test.cpp */; };
9AA0458A2425F94D000D6970 /* printf_lite-test.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9AA045892425F94D000D6970 /* printf_lite-test.cpp */; };
9AA0458B2425F94D000D6970 /* printf_lite-test.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9AA045892425F94D000D6970 /* printf_lite-test.cpp */; };
9AA0458C2425F94D000D6970 /* printf_lite-test.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9AA045892425F94D000D6970 /* printf_lite-test.cpp */; };
@ -177,6 +181,8 @@
9A92234D2402FD9500483CBA /* Platform.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Platform.h; sourceTree = "<group>"; };
9A9AEB8B243F73CE00FBD7D8 /* unicode_conversions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = unicode_conversions.h; sourceTree = "<group>"; };
9A9AEB8C243F73CE00FBD7D8 /* unicode_conversions.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = unicode_conversions.cpp; sourceTree = "<group>"; };
9A9EA7F6245AAB310076EC02 /* XToolsCommon_test.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = XToolsCommon_test.h; sourceTree = "<group>"; };
9A9EA7F7245AAB310076EC02 /* XToolsCommon_test.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = XToolsCommon_test.cpp; sourceTree = "<group>"; };
9AA045732425D200000D6970 /* IO.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IO.h; sourceTree = "<group>"; };
9AA045742425D200000D6970 /* IO.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = IO.cpp; sourceTree = "<group>"; };
9AA045882425F94D000D6970 /* printf_lite-test.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "printf_lite-test.h"; sourceTree = "<group>"; };
@ -255,6 +261,8 @@
9A0B084C2402FE9B00E2B470 /* cpp_unit_test */ = {
isa = PBXGroup;
children = (
9A9EA7F7245AAB310076EC02 /* XToolsCommon_test.cpp */,
9A9EA7F6245AAB310076EC02 /* XToolsCommon_test.h */,
9A4FFA802451C88D0050B38B /* XString_test.cpp */,
9A4FFA7F2451C88C0050B38B /* XString_test.h */,
9A4185AF2439E4D500BEAFB8 /* LoadOptions_test.cpp */,
@ -500,6 +508,7 @@
9A28CD20241BB61B00F3D247 /* abort.cpp in Sources */,
9A4FFA842451C9740050B38B /* XString.cpp in Sources */,
9A4FFA822451C88D0050B38B /* XString_test.cpp in Sources */,
9A9EA7F9245AAB310076EC02 /* XToolsCommon_test.cpp in Sources */,
9A28CD23241BB61B00F3D247 /* strlen.cpp in Sources */,
9A28CD4C241F4CCE00F3D247 /* xcode_utf_fixed.cpp in Sources */,
9A0B08742403B08400E2B470 /* main.cpp in Sources */,
@ -528,6 +537,7 @@
9A2A7C6E24576CCE00422263 /* abort.cpp in Sources */,
9A2A7C6F24576CCE00422263 /* XString.cpp in Sources */,
9A2A7C7024576CCE00422263 /* XString_test.cpp in Sources */,
9A9EA7FB245AAB310076EC02 /* XToolsCommon_test.cpp in Sources */,
9A2A7C7124576CCE00422263 /* strlen.cpp in Sources */,
9A2A7C7224576CCE00422263 /* xcode_utf_fixed.cpp in Sources */,
9A2A7C7324576CCE00422263 /* main.cpp in Sources */,
@ -556,6 +566,7 @@
9A28CD21241BB61B00F3D247 /* abort.cpp in Sources */,
9A4FFA852451C9740050B38B /* XString.cpp in Sources */,
9A4FFA832451C88D0050B38B /* XString_test.cpp in Sources */,
9A9EA7FA245AAB310076EC02 /* XToolsCommon_test.cpp in Sources */,
9A28CD24241BB61B00F3D247 /* strlen.cpp in Sources */,
9A28CD4D241F4CCE00F3D247 /* xcode_utf_fixed.cpp in Sources */,
9A57C21B2418B9A00029A39F /* main.cpp in Sources */,
@ -584,6 +595,7 @@
9A4FFA7E2451C8330050B38B /* XString.cpp in Sources */,
9A4FFA812451C88D0050B38B /* XString_test.cpp in Sources */,
9A28CD22241BB61B00F3D247 /* strlen.cpp in Sources */,
9A9EA7F8245AAB310076EC02 /* XToolsCommon_test.cpp in Sources */,
9A28CD4B241F4CCE00F3D247 /* xcode_utf_fixed.cpp in Sources */,
9A9223312402FD1000483CBA /* main.cpp in Sources */,
9A28CD16241BACBB00F3D247 /* strlen_test.cpp in Sources */,

View File

@ -24,28 +24,32 @@ struct _xtools__true_type {
template <class _Tp>
struct _xtools__make_unsigned {};
template <> struct _xtools__make_unsigned< char> {typedef unsigned char type;};
template <> struct _xtools__make_unsigned< signed char> {typedef unsigned char type;};
template <> struct _xtools__make_unsigned<unsigned char> {typedef unsigned char type;};
template <> struct _xtools__make_unsigned< char16_t> {typedef char16_t type;};
template <> struct _xtools__make_unsigned< char32_t> {typedef char32_t type;};
template <> struct _xtools__make_unsigned< wchar_t> {typedef wchar_t type;};
template <> struct _xtools__make_unsigned< signed short> {typedef unsigned short type;};
template <> struct _xtools__make_unsigned<unsigned short> {typedef unsigned short type;};
template <> struct _xtools__make_unsigned< signed int> {typedef unsigned int type;};
template <> struct _xtools__make_unsigned<unsigned int> {typedef unsigned int type;};
template <> struct _xtools__make_unsigned< signed long> {typedef unsigned long type;};
template <> struct _xtools__make_unsigned<unsigned long> {typedef unsigned long type;};
template <> struct _xtools__make_unsigned< signed long long> {typedef unsigned long long type;};
template <> struct _xtools__make_unsigned< char> {typedef unsigned char type;};
template <> struct _xtools__make_unsigned< signed char> {typedef unsigned char type;};
template <> struct _xtools__make_unsigned< unsigned char> {typedef unsigned char type;};
template <> struct _xtools__make_unsigned< char16_t> {typedef char16_t type;};
template <> struct _xtools__make_unsigned< char32_t> {typedef char32_t type;};
#if WCHAR_MAX <= 0xFFFF
template <> struct _xtools__make_unsigned< wchar_t> {typedef char16_t type;};
#else
template <> struct _xtools__make_unsigned< wchar_t> {typedef char32_t type;};
#endif
template <> struct _xtools__make_unsigned< short> {typedef unsigned short type;};
template <> struct _xtools__make_unsigned< unsigned short> {typedef unsigned short type;};
template <> struct _xtools__make_unsigned< int> {typedef unsigned int type;};
template <> struct _xtools__make_unsigned< unsigned int> {typedef unsigned int type;};
template <> struct _xtools__make_unsigned< long> {typedef unsigned long type;};
template <> struct _xtools__make_unsigned< unsigned long> {typedef unsigned long type;};
template <> struct _xtools__make_unsigned< long long> {typedef unsigned long long type;};
template <> struct _xtools__make_unsigned<unsigned long long> {typedef unsigned long long type;};
// is_integral
template <class _Tp> struct _xtools__is_integral_st : public _xtools__false_type {};
//template <> struct _xtools__is_integral_st<bool> : public _xtools__true_type {};
template <> struct _xtools__is_integral_st<char> : public _xtools__true_type {};
template <> struct _xtools__is_integral_st<signed char> : public _xtools__true_type {};
template <> struct _xtools__is_integral_st<unsigned char> : public _xtools__true_type {};
//template <> struct _xtools__is_integral_st<char> : public _xtools__true_type {};
//template <> struct _xtools__is_integral_st<signed char> : public _xtools__true_type {};
//template <> struct _xtools__is_integral_st<unsigned char> : public _xtools__true_type {};
//template <> struct _xtools__is_integral_st<wchar_t> : public _xtools__true_type {};
template <> struct _xtools__is_integral_st<short> : public _xtools__true_type {};
template <> struct _xtools__is_integral_st<unsigned short> : public _xtools__true_type {};
@ -58,6 +62,11 @@ template <> struct _xtools__is_integral_st<unsigned long long> : public
// is_char
// Looks like I don't need to remove reference.
// This : template<typename O, enable_if(is_char(O))>
// void strcpy(O otherChar)
// is still enabled if parameter is a char&
template <class _Tp> struct _xtools__is_char_st : public _xtools__false_type {};
template <> struct _xtools__is_char_st<char> : public _xtools__true_type {};
template <> struct _xtools__is_char_st<signed char> : public _xtools__true_type {};
@ -93,6 +102,15 @@ template <> struct _xtools__is_char_st<wchar_t> : public
// typedef _Ty type;
// };
template< class T > struct _xtools__remove_ref { typedef T type; };
template< class T > struct _xtools__remove_ref<T&> { typedef T type; };
template< class T > struct _xtools__remove_const { typedef T type; };
template< class T > struct _xtools__remove_const<const T> { typedef T type; };
template< class T > struct _xtools__remove_const<const T&> { typedef T& type; };
template< class T > struct _xtools__remove_const<const T*> { typedef T* type; };
template< class T > struct _xtools__remove_const_ptr { typedef T type; };
template< class T > struct _xtools__remove_const_ptr<const T> { typedef T type; };
template< class T > struct _xtools__remove_const_ptr<T*> { typedef T type; };
@ -150,11 +168,14 @@ struct _xtools__has_type_member<T, _xtools__void_t<typename T::char_t>> : _xtool
#define remove_const(x) typename _xtools__remove_const<x>::type
#define unsigned_type(x) typename _xtools__make_unsigned<remove_const(x)>::type
#define remove_ref(x) typename _xtools__remove_ref<x>::type
#define remove_const_ptr(x) typename _xtools__remove_const_ptr<x>::type
#define unsigned_type(x) typename _xtools__make_unsigned<x>::type
#define is_integral(x) _xtools__is_integral_st<x>::value
#define is_char(x) _xtools__is_char_st<x>::value
#define is_char_ptr(x) _xtools__is_char_ptr_st<typename _xtools__remove_const_ptr<x>::type>::value
#define is_integral(x) _xtools__is_integral_st<remove_const(x)>::value
#define is_char(x) _xtools__is_char_st<remove_const(x)>::value
#define is_char_ptr(x) _xtools__is_char_ptr_st<typename _xtools__remove_const<x>::type>::value
#define enable_if_t(x) typename _xtools_enable_if_t<x>::type
#define enable_if(x) typename enable_if_type = typename _xtools_enable_if_t<x>::type

View File

@ -4,9 +4,9 @@
int nbTest = 0;
int nbTestFailed = 0;
bool displayOnlyFailed = true;
static int nbTest = 0;
static int nbTestFailed = 0;
static bool displayOnlyFailed = true;
#define STRINGIFY_(s) #s
@ -1486,7 +1486,6 @@ XStringClass xstr2 = initia__String.basename();
/***************************** *****************************/
#undef realloc
//
//#include <type_traits>
//#include <typeinfo>
@ -1515,24 +1514,12 @@ class C
int XString_tests()
{
#ifdef JIEF_DEBUG
// printf("XString16_tests -> Enter\n");
// printf("XString_tests -> Enter\n");
#endif
XString8 xs1 = "Test:"_XS8;
constexpr const LString8 ls1 = "foo"_XS8;
xs1 = ls1;
xs1 = ls1 + "bar";
XStringW xsw1 = L"world"_XSW;
XString8 xs2 = xs1 + "hel" + 'l' + L'o' + L" the " + xsw1;
XString8 xs3 = xs1;
LString8 a = "Hello"_XS8;
XStringW b = L"world"_XSW;
XString8 c = a + "foo"; // + 'o' + L'o' + b + L"bar";
//char c = 1;
//char c = 'a';
//int ii = sizeof(size_t);
//unsigned long long ull = 1;
//unsigned long long ll = 3;

View File

@ -0,0 +1,136 @@
#include <Platform.h>
#include "../cpp_foundation/XString.h"
#include "../cpp_foundation/unicode_conversions.h"
static int nbTest = 0;
static int nbTestFailed = 0;
//static bool displayOnlyFailed = true;
#define STRINGIFY_(s) #s
#define STRINGIFY(s) STRINGIFY_(s)
//#include <type_traits>
//#include <typeinfo>
//#include <iostream>
//#include <libgen.h>
class C
{
public:
typedef char char_t;
const char* data;
constexpr C() : data(0) { }
};
#define ASSERT_CONST_NONCONST(test, type, expectedResult) \
test(type, expectedResult) \
test(const type, expectedResult) \
#define ASSERT_ALL_INTEGRAL(test, expectedResult) \
ASSERT_CONST_NONCONST(test, short, expectedResult) \
ASSERT_CONST_NONCONST(test, short, expectedResult) \
ASSERT_CONST_NONCONST(test, int, expectedResult) \
ASSERT_CONST_NONCONST(test, unsigned int, expectedResult) \
ASSERT_CONST_NONCONST(test, long, expectedResult) \
ASSERT_CONST_NONCONST(test, unsigned long, expectedResult) \
ASSERT_CONST_NONCONST(test, long, expectedResult) \
ASSERT_CONST_NONCONST(test, unsigned long long, expectedResult) \
#define ASSERT_ALL_CHAR(test, expectedResult) \
ASSERT_CONST_NONCONST(test, char, expectedResult) \
ASSERT_CONST_NONCONST(test, signed char, expectedResult) \
ASSERT_CONST_NONCONST(test, unsigned char, expectedResult) \
ASSERT_CONST_NONCONST(test, char16_t, expectedResult) \
ASSERT_CONST_NONCONST(test, char32_t, expectedResult) \
ASSERT_CONST_NONCONST(test, wchar_t, expectedResult) \
#define ASSERT_ALL_PTR(test, type, expectedResult) \
ASSERT_CONST_NONCONST(test, type*, expectedResult) \
ASSERT_CONST_NONCONST(test, type[], expectedResult) \
ASSERT_CONST_NONCONST(test, type[10], expectedResult) \
#define ASSERT_ALL_CHAR_PTR(test, expectedResult) \
ASSERT_ALL_PTR(test, char, expectedResult) \
ASSERT_ALL_PTR(test, signed char, expectedResult) \
ASSERT_ALL_PTR(test, unsigned char, expectedResult) \
ASSERT_ALL_PTR(test, char16_t, expectedResult) \
ASSERT_ALL_PTR(test, char32_t, expectedResult) \
ASSERT_ALL_PTR(test, wchar_t, expectedResult) \
#define ASSERT_ALL_INTEGRAL_CHAR(test, expectedResult) \
ASSERT_ALL_INTEGRAL(test, expectedResult) \
ASSERT_ALL_CHAR(test, expectedResult) \
template <bool>
struct _xtools__is_unsigned_true_false : public _xtools__false_type {};
template <>
struct _xtools__is_unsigned_true_false<true> : public _xtools__true_type {};
template <>
struct _xtools__is_unsigned_true_false<false> : public _xtools__false_type {};
template <class _Tp>
struct _xtools__is_unsigned : public _xtools__is_unsigned_true_false< ( _Tp(0) < _Tp(-1) ) > {};
#define is_unsigned(x) _xtools__is_unsigned<x>::value
#define ASSERT_UNSIGNED_TYPE(type, expectedResult) \
static_assert(is_unsigned(unsigned_type(type)) == expectedResult, "unsigned_type " STRINGIFY(type) " failed");
#define ASSERT_SIZEOF_UNSIGNED_TYPE(type, expectedResult) \
static_assert(sizeof(unsigned_type(type)) == sizeof(type), "sizeof(unsigned_type(" STRINGIFY(type) ")) == sizeof(" STRINGIFY(type) ") failed");
#define ASSERT_IS_INTEGRAL(type, expectedResult) \
static_assert(is_integral(type) == expectedResult, "is_integral(" STRINGIFY(type) ") failed");
#define ASSERT_IS_CHAR(type, expectedResult) \
static_assert(is_char(type) == expectedResult, "is_char(" STRINGIFY(type) ") failed");
#define ASSERT_IS_CHAR_PTR(type, expectedResult) \
/*printf("is_char_ptr(%s)\n", STRINGIFY(type)); */ \
static_assert(is_char_ptr(type) == expectedResult, "is_char_ptr(" STRINGIFY(type) ") failed");
int XToolsCommon_tests()
{
#ifdef JIEF_DEBUG
// printf("XToolsCommon_tests -> Enter\n");
#endif
ASSERT_ALL_INTEGRAL_CHAR(ASSERT_UNSIGNED_TYPE, true)
ASSERT_ALL_INTEGRAL_CHAR(ASSERT_SIZEOF_UNSIGNED_TYPE, true) // expectedResult unused by ASSERT_SIZEOF_UNSIGNED_TYPE
ASSERT_ALL_INTEGRAL(ASSERT_IS_INTEGRAL, true)
ASSERT_ALL_CHAR(ASSERT_IS_INTEGRAL, false)
ASSERT_ALL_INTEGRAL(ASSERT_IS_CHAR, false)
ASSERT_ALL_CHAR(ASSERT_IS_CHAR, true)
ASSERT_ALL_CHAR_PTR(ASSERT_IS_CHAR_PTR, true)
#ifdef JIEF_DEBUG
if ( nbTestFailed == 0 ) printf("All %d tests succeeded.\n", nbTest);
else printf("%d tests succeeded out of %d.\n", nbTest-nbTestFailed, nbTest);
#endif
return nbTestFailed > 0;
}
//const char* p1 = "foo/bar"; // basename returns bar
//const char* p1 = "foo/"; // basename returns foo
//const char* p1 = "foo//"; // basename returns foo
//const char* p1 = "foo///"; // basename returns foo
//const char* p1 = ""; // basename returns "."
//const char* p1 = " foo/bar "; // basename returns "bar "
//const char* p1 = " foo "; // basename returns " foo "
//const char* p1 = " "; // basename returns " "
//const char* p2 = basename((char*)p1);

View File

@ -0,0 +1 @@
int XToolsCommon_tests();

View File

@ -13,6 +13,7 @@
#include "strlen_test.h"
#include "printf_lite-test.h"
#include "LoadOptions_test.h"
#include "XToolsCommon_test.h"
#if defined(JIEF_DEBUG) && defined(CLOVER_BUILD)
#include "poolprint-test.h"
@ -31,11 +32,18 @@ bool all_tests()
bool all_ok = true;
int ret;
ret = XString_tests();
// ret = XString_tests();
// if ( ret != 0 ) {
// printf("XString16_tests() failed at test %d\n", ret);
// all_ok = false;
// }
#if defined(JIEF_DEBUG)
ret = XToolsCommon_tests();
if ( ret != 0 ) {
printf("XString16_tests() failed at test %d\n", ret);
printf("printlib_tests() failed at test %d\n", ret);
all_ok = false;
}
#endif
//return ret;
// ret = XUINTN_tests();
// if ( ret != 0 ) {
@ -86,11 +94,11 @@ bool all_tests()
printf("XObjArray_tests() failed at test %d\n", ret);
all_ok = false;
}
// ret = XString_tests();
// if ( ret != 0 ) {
// printf("XString_tests() failed at test %d\n", ret);
// all_ok = false;
// }
ret = XString_tests();
if ( ret != 0 ) {
printf("XString_tests() failed at test %d\n", ret);
all_ok = false;
}
ret = XStringArray_tests();
if ( ret != 0 ) {
printf("XStringArray_tests() failed at test %d\n", ret);