2020-03-12 15:40:38 +01:00
|
|
|
#include <Platform.h>
|
|
|
|
#include "../cpp_foundation/XString.h"
|
|
|
|
#include "../cpp_foundation/utf8Conversion.h"
|
|
|
|
#include "global_test.h"
|
|
|
|
|
|
|
|
|
|
|
|
//#include <wchar.h>
|
|
|
|
|
|
|
|
|
|
|
|
int XString_tests()
|
|
|
|
{
|
|
|
|
|
|
|
|
#ifdef JIEF_DEBUG
|
|
|
|
// DebugLog(2, "XStringW_tests -> Enter\n");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if ( global_str1 != "global_str1" ) return 1;
|
|
|
|
if ( global_str2 != "global_str2" ) return 2;
|
|
|
|
|
2020-03-21 14:12:26 +01:00
|
|
|
// Check default ctor
|
|
|
|
{
|
|
|
|
XString str;
|
|
|
|
if (str.length() != 0) return 3;
|
|
|
|
if (str.c_str() == NULL) return 4;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check ctor with value (or check takeValueFrom while we are waiting to put back ctor(const char*)
|
2020-03-12 15:40:38 +01:00
|
|
|
#ifdef XSTRINGW_HAS_CTOR_LITTERAL
|
2020-03-21 14:12:26 +01:00
|
|
|
{
|
|
|
|
{
|
|
|
|
XString str("");
|
2020-03-26 13:59:20 +01:00
|
|
|
if ( str != "" ) return 100;
|
|
|
|
}
|
|
|
|
{
|
|
|
|
XString str("1");
|
|
|
|
if ( str != "1" ) return 101;
|
2020-03-21 14:12:26 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
{
|
|
|
|
XString str;
|
|
|
|
str.takeValueFrom("");
|
2020-03-26 13:59:20 +01:00
|
|
|
if (str.length() != 0) return 110;
|
2020-03-21 14:12:26 +01:00
|
|
|
str.takeValueFrom("1");
|
2020-03-26 13:59:20 +01:00
|
|
|
if ( str != "1" ) return 111;
|
2020-03-21 14:12:26 +01:00
|
|
|
str.StrCat("2");
|
2020-03-26 13:59:20 +01:00
|
|
|
if ( str != "12" ) return 112;
|
2020-03-21 14:12:26 +01:00
|
|
|
}
|
2020-03-12 15:40:38 +01:00
|
|
|
#endif
|
|
|
|
|
2020-03-26 13:59:20 +01:00
|
|
|
// check [] operator
|
|
|
|
{
|
|
|
|
XString str;
|
|
|
|
str.takeValueFrom("01234567890123456789");
|
|
|
|
char c;
|
|
|
|
c = str[(char)1];
|
|
|
|
if ( c != '1' ) return 201;
|
|
|
|
c = str[(unsigned char)2];
|
|
|
|
if ( c != '2' ) return 202;
|
|
|
|
c = str[(short)3];
|
|
|
|
if ( c != '3' ) return 203;
|
|
|
|
c = str[(unsigned short)4];
|
|
|
|
if ( c != '4' ) return 204;
|
|
|
|
c = str[(int)5];
|
|
|
|
if ( c != '5' ) return 205;
|
|
|
|
c = str[(unsigned int)6];
|
|
|
|
if ( c != '6' ) return 206;
|
|
|
|
c = str[(long)7];
|
|
|
|
if ( c != '7' ) return 207;
|
|
|
|
c = str[(unsigned long)8];
|
|
|
|
if ( c != '8' ) return 208;
|
|
|
|
c = str[(long long)9];
|
|
|
|
if ( c != '9' ) return 209;
|
|
|
|
c = str[(unsigned long long)10];
|
|
|
|
if ( c != '0' ) return 210;
|
|
|
|
}
|
|
|
|
|
2020-03-21 14:12:26 +01:00
|
|
|
// Check StrCat. TODO more test, and test StrnCat
|
|
|
|
{
|
|
|
|
XString str;
|
|
|
|
str.takeValueFrom("1");
|
|
|
|
str.StrCat("2");
|
2020-03-26 13:59:20 +01:00
|
|
|
if ( str != "12" ) return 50;
|
2020-03-21 14:12:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// check takeValueFrom from utf8 string
|
2020-03-12 15:40:38 +01:00
|
|
|
XString str;
|
2020-03-21 14:12:26 +01:00
|
|
|
str.takeValueFrom("Ň"); // this is a UTF8 string 2 bytes long
|
2020-03-26 13:59:20 +01:00
|
|
|
if (str != "Ň") return 80; // utf8 litteral are converted to an XStringW if ctor is available.
|
2020-03-21 14:12:26 +01:00
|
|
|
str.takeValueFrom("𐌾"); // this is a UTF8 string 4 bytes long
|
2020-03-26 13:59:20 +01:00
|
|
|
if ( str != "𐌾" ) return 81;
|
2020-03-21 14:12:26 +01:00
|
|
|
str.takeValueFrom("𐌾"); // this is a UTF16 or UTF32 string (depending of -fshort-wchar)
|
2020-03-26 13:59:20 +01:00
|
|
|
if ( str != "𐌾" ) return 82;
|
2020-03-21 14:12:26 +01:00
|
|
|
|
|
|
|
// check takeValueFrom from UTF16 or 32 string
|
|
|
|
str.takeValueFrom(L"Ň"); // this is a UTF8 string 2 bytes long
|
2020-03-26 13:59:20 +01:00
|
|
|
if (str != "Ň") return 83; // utf8 litteral are converted to an XStringW if ctor is available.
|
2020-03-21 14:12:26 +01:00
|
|
|
str.takeValueFrom(L"𐌾"); // this is a UTF8 string 4 bytes long
|
2020-03-26 13:59:20 +01:00
|
|
|
if ( str != "𐌾" ) return 84;
|
2020-03-21 14:12:26 +01:00
|
|
|
str.takeValueFrom(L"𐌾"); // this is a UTF16 or UTF32 string (depending of -fshort-wchar)
|
2020-03-26 13:59:20 +01:00
|
|
|
if ( str != "𐌾" ) return 85;
|
2020-03-21 14:12:26 +01:00
|
|
|
|
|
|
|
// Quick check of StrnCpy,StrnCat,Insert,+=
|
2020-03-12 15:40:38 +01:00
|
|
|
str.takeValueFrom("12");
|
|
|
|
XString str2;
|
2020-03-21 14:12:26 +01:00
|
|
|
if ( !str2.isEmpty() ) return 100;
|
2020-03-12 15:40:38 +01:00
|
|
|
str2.StrnCpy(str.data(), 2);
|
2020-03-21 14:12:26 +01:00
|
|
|
if ( str2 != "12" ) return 101;
|
2020-03-12 15:40:38 +01:00
|
|
|
str2.StrnCat("345", 2);
|
2020-03-21 14:12:26 +01:00
|
|
|
if ( str2 != "1234" ) return 102;
|
2020-03-12 15:40:38 +01:00
|
|
|
str2.Insert(1, str);
|
2020-03-21 14:12:26 +01:00
|
|
|
if ( str2 != "112234" ) return 103;
|
2020-03-12 15:40:38 +01:00
|
|
|
str2 += "6";
|
2020-03-21 14:12:26 +01:00
|
|
|
if ( str2 != "1122346" ) return 104;
|
|
|
|
// Check Insert at beginning and end
|
|
|
|
str2.takeValueFrom("123");
|
|
|
|
str2.Insert(0, XString().takeValueFrom("x"));
|
|
|
|
if ( str2 != "x123" ) return 105;
|
|
|
|
str2.Insert(4, XString().takeValueFrom("y"));
|
|
|
|
if ( str2 != "x123y" ) return 106;
|
2020-03-12 15:40:38 +01:00
|
|
|
|
|
|
|
//wchar_t c2 = L'Ň';
|
|
|
|
//printf("1=%lc\n", c2);
|
|
|
|
//const char* s1 = "𐌾";
|
2020-03-26 13:59:20 +01:00
|
|
|
// Check SPrintf
|
2020-03-21 14:12:26 +01:00
|
|
|
str2.SPrintf("%c", 'a'); // single UTF8 ascii char
|
|
|
|
if ( str2 != "a" ) return 200;
|
|
|
|
#ifndef _MSC_VER
|
|
|
|
str2.SPrintf("%lc", L'Ň'); // single UTF16(32) char. (2 bytes in total if UTF16)
|
|
|
|
if ( str2 != "Ň" ) return 202;
|
|
|
|
#endif
|
|
|
|
str2.SPrintf("%s", "Ň"); // this is a UTF8 string 2 bytes long
|
|
|
|
if (str2 != "Ň") return 203; // utf8 litteral are converted to an XStringW if ctor is available.
|
|
|
|
str2.SPrintf("%ls", L"Ň"); // this is a UTF8 string 2 bytes long
|
|
|
|
if (str2 != "Ň") return 204; // utf8 litteral are converted to an XStringW if ctor is available.
|
2020-03-12 15:40:38 +01:00
|
|
|
#if __WCHAR_MAX__ > 0xFFFFu
|
|
|
|
str2.SPrintf("%lc", L'𐌾'); // L'𐌾' // this char cannot convert to an UTF16 char. So it doesn't compile with -fshort-wchar
|
2020-03-21 14:12:26 +01:00
|
|
|
if ( str2 != "𐌾" ) return 205;
|
2020-03-12 15:40:38 +01:00
|
|
|
#endif
|
|
|
|
|
2020-03-12 18:45:28 +01:00
|
|
|
/* Stil doesn't work as VS doesn't encode correctly litteral */
|
|
|
|
#ifndef _MSC_VER
|
|
|
|
|
|
|
|
// int i1 = sizeof(wchar_t);
|
|
|
|
// int i2 = sizeof(char16_t);
|
|
|
|
// const wchar_t* ls = L"Выход";
|
|
|
|
// const char16_t* us = u"Выход";
|
|
|
|
// const char32_t* Us = U"Выход";
|
2020-03-21 14:12:26 +01:00
|
|
|
XString str3;
|
|
|
|
str3.takeValueFrom(L"Выход");
|
|
|
|
if ( str3 != "Выход" ) return 500;
|
2020-03-12 18:45:28 +01:00
|
|
|
#endif
|
2020-03-25 19:32:44 +01:00
|
|
|
//MsgLog("Test MsgLog ascii=%ls ucs-2=%ls\n", "a string", L"ascii char in ucs-2 string\n");
|
|
|
|
//MsgLog("Test MsgLog ascii=%ls ucs-2=%ls\n", "a string", "ascii char in ucs-2 string\n");
|
|
|
|
//MsgLog("Test MsgLog ascii=%ls ucs-2=%ls\n", "a string", "ascii char in ucs-2 string\n");
|
2020-03-21 14:12:26 +01:00
|
|
|
//
|
2020-03-25 19:32:44 +01:00
|
|
|
//MsgLog("Test MsgLog ascii=%ls ucs-2=%ls\n", "a string", L"Выход из подменю, обновление главного меню\n");
|
|
|
|
//MsgLog("Test MsgLog ascii=%ls ucs-2=%ls\n", "a string", "Выход из подменю, обновление главного меню\n");
|
|
|
|
//MsgLog("Test MsgLog ascii=%ls ucs-2=%ls\n", "a string", "Выход из подменю, обновление главного меню\n");
|
2020-03-21 14:12:26 +01:00
|
|
|
//
|
2020-03-25 19:32:44 +01:00
|
|
|
//DBG("Test ascii=%ls ucs-2=%ls\n", "a string", L"Выход из подменю, обновление главного меню\n");
|
|
|
|
//DBG("Test ascii=%ls ucs-2=%ls\n", "a string", "Выход из подменю, обновление главного меню\n");
|
|
|
|
//DBG("Test ascii=%ls ucs-2=%ls\n", "a string", "Выход из подменю, обновление главного меню\n");
|
2020-03-12 15:40:38 +01:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|