Import XStringWArray in Clover.

Added unit tests
This commit is contained in:
jief 2020-02-23 23:23:31 +03:00
parent 56ca2c3e67
commit 71e952401a
21 changed files with 459 additions and 105 deletions

View File

@ -0,0 +1,70 @@
//
// Platform.cpp
// cpp_tests
//
// Created by jief on 23.02.20.
// Copyright © 2020 JF Knudsen. All rights reserved.
//
#include "Platform.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <wchar.h>
void CpuDeadLoop(void)
{
}
void DebugLog(int DebugMode, const char *FormatString, ...)
{
va_list va;
va_start(va, FormatString);
vprintf(FormatString, va);
va_end(va);
}
void* AllocatePool(UINTN AllocationSize)
{
return malloc(AllocationSize);
}
void* ReallocatePool(UINTN OldSize, UINTN NewSize, void* OldBuffer)
{
if ( !OldBuffer ) return AllocatePool(NewSize);
return realloc(OldBuffer, NewSize);
}
void FreePool(const void* Buffer)
{
free((void*)Buffer);
}
void CopyMem(void *Destination, void *Source, UINTN Length)
{
memmove(Destination, Source, Length);
}
void PauseForKey(const wchar_t* msg)
{
printf("%ls", msg);
getchar();
}
int StrCmp(const wchar_t* FirstString, const wchar_t* SecondString)
{
return wcscmp(FirstString, SecondString);
}
int StrnCmp(const wchar_t* FirstString, const wchar_t* SecondString, UINTN Length)
{
return wcsncmp(FirstString, SecondString, Length);
}
int StrLen(const wchar_t* String)
{
return (int)wcslen(String);
}

View File

@ -11,13 +11,13 @@
#if !defined(__XARRAY_H__)
#define __XARRAY_H__
//#include "../Platform/Platform.h" // for DebugLog
VOID EFIAPI DebugLog(IN INTN DebugMode, IN CONST CHAR8 *FormatString, ...); // To avoid include Platform just for this
extern "C" {
#include <Library/MemoryAllocationLib.h>
#include <Library/BaseMemoryLib.h>
#include <Library/BaseLib.h> // for CpuDeadLoop();
}
#include <Platform.h> // Only use angled for Platform, else, xcode project won't compile // for DebugLog
//VOID EFIAPI DebugLog(IN INTN DebugMode, IN CONST CHAR8 *FormatString, ...); // To avoid include Platform just for this
//extern "C" {
// #include <Library/MemoryAllocationLib.h>
// #include <Library/BaseMemoryLib.h>
// #include <Library/BaseLib.h> // for CpuDeadLoop();
//}
#include "XToolsCommon.h"
@ -118,7 +118,7 @@ xsize XArray<TYPE>::IdxOf(TYPE& e) const
template<class TYPE>
void XArray<TYPE>::Init()
{
m_data = NULL;
m_data = nullptr;
m_size = 0;
m_len = 0;
_GrowBy = XArrayGrowByDefault;
@ -277,7 +277,7 @@ template<class TYPE>
void XArray<TYPE>::RemoveAtIndex(xsize nIndex)
{
if ( nIndex < m_len ) {
if ( nIndex<m_len-1 ) Xmemcpy(&m_data[nIndex], &m_data[nIndex+1], (m_len-nIndex-1)*sizeof(TYPE));
if ( nIndex<m_len-1 ) Xmemmove(&m_data[nIndex], &m_data[nIndex+1], (m_len-nIndex-1)*sizeof(TYPE));
m_len -= 1;
return;
}

View File

@ -11,13 +11,13 @@
#if !defined(__XOBJARRAY_H__)
#define __XOBJARRAY_H__
//#include "../Platform/Platform.h" // for DebugLog
VOID EFIAPI DebugLog(IN INTN DebugMode, IN CONST CHAR8 *FormatString, ...); // To avoid include Platform just for this
extern "C" {
#include <Library/MemoryAllocationLib.h>
#include <Library/BaseMemoryLib.h>
#include <Library/BaseLib.h> // for CpuDeadLoop();
}
#include <Platform.h> // Only use angled for Platform, else, xcode project won't compile // for DebugLog
//VOID EFIAPI DebugLog(IN INTN DebugMode, IN CONST CHAR8 *FormatString, ...); // To avoid include Platform just for this
//extern "C" {
// #include <Library/MemoryAllocationLib.h>
// #include <Library/BaseMemoryLib.h>
// #include <Library/BaseLib.h> // for CpuDeadLoop();
//}
#include "XToolsCommon.h"
@ -137,7 +137,7 @@ class XObjArray : public XObjArrayNC<TYPE>
template<class TYPE>
void XObjArrayNC<TYPE>::Init()
{
_Data = NULL;
_Data = nullptr;
_Size = 0;
_Len = 0;
// THis was useful for realtime debugging with a debugger that do not recognise references.
@ -443,7 +443,7 @@ void XObjArrayNC<TYPE>::RemoveAtIndex(xsize nIndex)
TmpObject = (TYPE *)(_Data[nIndex].Object);
delete TmpObject;
}
if ( nIndex<XObjArrayNC<TYPE>::_Len-1 ) Xmemcpy(&_Data[nIndex], &_Data[nIndex+1], (_Len-nIndex-1)*sizeof(XObjArrayEntry<TYPE>));
if ( nIndex<XObjArrayNC<TYPE>::_Len-1 ) Xmemmove(&_Data[nIndex], &_Data[nIndex+1], (_Len-nIndex-1)*sizeof(XObjArrayEntry<TYPE>));
_Len -= 1;
return;
}

View File

@ -21,12 +21,12 @@
#include "XToolsCommon.h"
#include "XStringW.h"
extern "C" {
#include <Library/MemoryAllocationLib.h>
#include <Library/BaseMemoryLib.h>
}
#include "Platform/Platform.h"
#include "refit/IO.h"
//extern "C" {
// #include <Library/MemoryAllocationLib.h>
// #include <Library/BaseMemoryLib.h>
//}
#include <Platform.h>
//#include "refit/IO.h"
UINTN XStringWGrowByDefault = 1024;
const XStringW NullXStringW;
@ -132,7 +132,7 @@ void XStringW::StrnCpy(const wchar_t *buf, UINTN len)
{
if ( buf && *buf && len > 0 ) {
CheckSize(len, 0);
CopyMem(data(), buf, len*sizeof(wchar_t));
Xmemmove(data(), buf, len*sizeof(wchar_t));
}
SetLength(len); /* data()[len]=0 done in SetLength */
}
@ -154,7 +154,7 @@ void XStringW::StrnCat(const wchar_t *buf, UINTN len)
if ( buf && *buf && len > 0 ) {
NewLen = length()+len;
CheckSize(NewLen, 0);
CopyMem(data(length()), buf, len*sizeof(wchar_t));
Xmemmove(data(length()), buf, len*sizeof(wchar_t));
SetLength(NewLen); /* data()[NewLen]=0 done in SetLength */
}
}
@ -174,8 +174,8 @@ void XStringW::StrCat(const XStringW &uneXStringWW)
void XStringW::Delete(UINTN pos, UINTN count)
{
if ( pos < length() ) {
if ( count != MAX_UINTN && pos + count < length() ) {
CopyMem( data(pos), data(pos+count), (length()-pos-count)*sizeof(wchar_t)); // CopyMem handles overlapping memory move
if ( count != MAX_XSIZE && pos + count < length() ) {
Xmemmove( data(pos), data(pos+count), (length()-pos-count)*sizeof(wchar_t)); // Xmemmove handles overlapping memory move
SetLength(length()-count);/* data()[length()-count]=0 done in SetLength */
}else{
SetLength(pos);/* data()[pos]=0 done in SetLength */
@ -187,8 +187,8 @@ void XStringW::Insert(UINTN pos, const XStringW& Str)
{
if ( pos < length() ) {
CheckSize(length()+Str.length());
CopyMem(data(pos + Str.length()), data(pos), (length()-pos)*sizeof(wchar_t));
CopyMem(data(pos), Str.data(), Str.length()*sizeof(wchar_t));
Xmemmove(data(pos + Str.length()), data(pos), (length()-pos)*sizeof(wchar_t));
Xmemmove(data(pos), Str.data(), Str.length()*sizeof(wchar_t));
SetLength(length()+Str.length());
}else{
StrCat(Str);
@ -222,22 +222,22 @@ XStringW XStringW::SubStringReplace(wchar_t c1, wchar_t c2)
void XStringW::vSPrintf(const wchar_t *format, VA_LIST va)
{
POOL_PRINT spc;
PRINT_STATE ps;
ZeroMem(&spc, sizeof (spc));
spc.Str = data();
SetLength(0);
spc.Len = 0;
spc.Maxlen = m_size;
ZeroMem(&ps, sizeof (ps));
ps.Output = (IN EFI_STATUS (EFIAPI *)(VOID *context, CONST CHAR16 *str))_PoolPrint;
ps.Context = (void*)&spc;
ps.fmt.u.pw = format;
VA_COPY(ps.args, va);
_PPrint (&ps);
VA_END(ps.args);
// POOL_PRINT spc;
// PRINT_STATE ps;
//
// ZeroMem(&spc, sizeof (spc));
// spc.Str = data();
// SetLength(0);
// spc.Len = 0;
// spc.Maxlen = m_size;
// ZeroMem(&ps, sizeof (ps));
// ps.Output = (IN EFI_STATUS (EFIAPI *)(VOID *context, CONST CHAR16 *str))_PoolPrint;
// ps.Context = (void*)&spc;
// ps.fmt.u.pw = format;
//
// VA_COPY(ps.args, va);
// _PPrint (&ps);
// VA_END(ps.args);
}
void XStringW::SPrintf(const wchar_t *format, ...)
@ -252,14 +252,14 @@ void XStringW::SPrintf(const wchar_t *format, ...)
XStringW XStringW::basename() const
{
UINTN idx = RIdxOf(LPATH_SEPARATOR);
if ( idx == MAX_UINTN ) return NullXStringW;
if ( idx == MAX_XSIZE ) return NullXStringW;
return SubString(idx+1, length()-idx-1);
}
XStringW XStringW::dirname() const
{
UINTN idx = RIdxOf(LPATH_SEPARATOR);
if ( idx == MAX_UINTN ) return NullXStringW;
if ( idx == MAX_XSIZE ) return NullXStringW;
return SubString(0, idx);
}
@ -276,7 +276,7 @@ UINTN XStringW::IdxOf(wchar_t aChar, UINTN Pos) const
for ( Idx=Pos ; Idx<length() ; Idx+=1 ) {
if ( data()[Idx] == aChar ) return Idx;
}
return MAX_UINTN;
return MAX_XSIZE;
}
UINTN XStringW::IdxOf(const XStringW &S, UINTN Pos) const
@ -284,13 +284,13 @@ UINTN XStringW::IdxOf(const XStringW &S, UINTN Pos) const
UINTN i;
UINTN Idx;
if ( length() < S.length() ) return MAX_UINTN;
if ( length() < S.length() ) return MAX_XSIZE;
for ( Idx=Pos ; Idx<=length()-S.length() ; Idx+=1 ) {
i = 0;
while( i<S.length() && ( data()[Idx+i] - S[i] ) == 0 ) i += 1;
if ( i == S.length() ) return Idx;
}
return MAX_UINTN;
return MAX_XSIZE;
}
UINTN XStringW::RIdxOf(const wchar_t charToSearch, UINTN Pos) const
@ -298,11 +298,11 @@ UINTN XStringW::RIdxOf(const wchar_t charToSearch, UINTN Pos) const
UINTN Idx;
if ( Pos > length() ) Pos = length();
if ( Pos < 1 ) return MAX_UINTN;
if ( Pos < 1 ) return MAX_XSIZE;
for ( Idx=Pos ; Idx-- > 0 ; ) {
if ( m_data[Idx] == charToSearch ) return Idx;
}
return MAX_UINTN;
return MAX_XSIZE;
}
UINTN XStringW::RIdxOf(const XStringW &S, UINTN Pos) const
@ -310,16 +310,16 @@ UINTN XStringW::RIdxOf(const XStringW &S, UINTN Pos) const
UINTN i;
UINTN Idx;
if ( S.length() == 0 ) return MAX_UINTN;
if ( S.length() == 0 ) return MAX_XSIZE;
if ( Pos > length() ) Pos = length();
if ( Pos < S.length() ) return MAX_UINTN;
if ( Pos < S.length() ) return MAX_XSIZE;
Pos -= S.length();
for ( Idx=Pos+1 ; Idx-- > 0 ; ) {
i = 0;
while( i<S.length() && data()[Idx+i] == S[i] ) i += 1;
if ( i == S.length() ) return Idx;
}
return MAX_UINTN;
return MAX_XSIZE;
}

View File

@ -9,12 +9,13 @@
#if !defined(__XSTRINGW_H__)
#define __XSTRINGW_H__
//#include "XToolsCommon.h"
#include "XToolsCommon.h"
#include <Platform.h>
//#include "XConstStringW.h"
extern "C" {
#include <Library/BaseLib.h>
}
//extern "C" {
// #include <Library/BaseLib.h>
//}
#define LPATH_SEPARATOR L'\\'
@ -42,8 +43,8 @@ protected:
wchar_t *CheckSize(UINTN nNewSize, UINTN nGrowBy = XStringWGrowByDefault);
public:
const wchar_t *data(UINTN ui=0) const { return m_data+ui; }
wchar_t *data(UINTN ui=0) { return m_data+ui; }
const wchar_t *data(UINTN ui=0) const { return m_data+ui; } // do not multiply by sizeof(wchar_t), it's done by the compiler.
wchar_t *data(UINTN ui=0) { return m_data+ui; } // do not multiply by sizeof(wchar_t), it's done by the compiler.
wchar_t *dataWithSizeMin(UINTN pos, UINTN sizeMin, UINTN nGrowBy=XStringWGrowByDefault) { CheckSize(sizeMin, nGrowBy); return data(pos); }
UINTN length() const { return m_len; }
@ -102,8 +103,8 @@ public:
XStringW SubString(UINTN pos, UINTN count) const;
UINTN IdxOf(wchar_t c, UINTN Pos = 0) const;
UINTN IdxOf(const XStringW& S, UINTN Pos = 0) const;
UINTN RIdxOf(const wchar_t c, UINTN Pos = MAX_UINTN) const;
UINTN RIdxOf(const XStringW& S, UINTN Pos = MAX_UINTN) const;
UINTN RIdxOf(const wchar_t c, UINTN Pos = MAX_XSIZE) const;
UINTN RIdxOf(const XStringW& S, UINTN Pos = MAX_XSIZE) const;
void ToLower(bool FirstCharIsCap = false);
bool IsLetters() const;
@ -111,11 +112,11 @@ public:
bool IsDigits() const;
bool IsDigits(UINTN pos, UINTN count) const;
bool ExistIn(const XStringW &S) const { return IdxOf(S) != MAX_UINTN; }
bool ExistIn(const XStringW &S) const { return IdxOf(S) != MAX_XSIZE; }
void Replace(wchar_t c1, wchar_t c2);
XStringW SubStringReplace(wchar_t c1, wchar_t c2);
INTN Compare(const wchar_t* S) const { return StrCmp(data(), S) ; }
int Compare(const wchar_t* S) const { return StrCmp(data(), S) ; }
bool Equal(const wchar_t* S) const { return Compare(S) == 0; };
bool BeginingEqual(const wchar_t* S) const { return StrnCmp(data(), S, StrLen(S)); }

View File

@ -0,0 +1,140 @@
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
//
// STRINGS
//
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
#if !defined(__XSTRINGWS_CPP__)
#define __XSTRINGWS_CPP__
#include "XToolsCommon.h"
#include "XStringWArray.h"
#include <Platform.h>
const XStringWArray NullXStrings;
XStringWArray::XStringWArray() : XStringWArraySuper()
{
}
//-------------------------------------------------------------------------------------------------
//
//-------------------------------------------------------------------------------------------------
void XStringWArray::AddStrings(const wchar_t *Val1, ...)
{
VA_LIST va;
const wchar_t *p;
AddCopy(Val1);
VA_START(va, Val1);
p = VA_ARG(va, const wchar_t *);
while ( p != nullptr ) {
AddCopy(p);
p = VA_ARG(va, const wchar_t *);
}
VA_END(va);
}
XStringW XStringWArray::ConcatAll(XStringW Separator, XStringW Prefix, XStringW Suffix) const
{
xsize i;
XStringW s;
if ( Length() > 0 ) {
s = Prefix;
s += ElementAt(0);
for ( i=1 ; i<Length() ; i+=1 ) {
s += Separator;
s += ElementAt(i);
}
s += Suffix;
}
return s;
}
bool XStringWArray::Equal(const XStringWArray &aStrings) const
{
xsize ui;
if ( Length() != aStrings.Length() ) return false;
for ( ui=0 ; ui<Length() ; ui+=1 ) {
if ( ElementAt(ui) != aStrings[ui] ) return false;
}
return true;
}
bool XStringWArray::Same(const XStringWArray &aStrings) const
{
xsize i;
for ( i=0 ; i<Length() ; i+=1 ) {
if ( !aStrings.Contains(ElementAt(i)) ) return false;
}
for ( i=0 ; i<aStrings.Length() ; i+=1 ) {
if ( !Contains(aStrings.ElementAt(i)) ) return false;
}
return true;
}
bool XStringWArray::Contains(const XStringW &S) const
{
xsize i;
for ( i=0 ; i<Length() ; i+=1 ) {
if ( ElementAt(i) == S ) return true;
}
return false;
}
//-------------------------------------------------------------------------------------------------
// Add
//-------------------------------------------------------------------------------------------------
void XStringWArray::Add(const XStringWArray &aStrings)
{
xsize i;
for ( i=0 ; i<aStrings.Length() ; i+=1 ) {
AddCopy(aStrings[i]);
}
}
void XStringWArray::AddID(const XStringW &aString)
{
if ( !Contains(aString) ) AddCopy(aString);
}
void XStringWArray::AddID(const XStringWArray &aStrings)
{
xsize i;
for ( i=0 ; i<aStrings.Length() ; i+=1 ) {
if ( !Contains(aStrings[i]) ) AddCopy(aStrings[i]);
}
}
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
// Divers
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
XStringWArray Split(const XStringW &S, const XStringW &Separator)
{
XStringWArray Ss;
xsize idxB, idxE;
idxB = 0;
idxE = S.IdxOf(Separator, idxB);
while ( idxE != MAX_XSIZE ) {
Ss.AddCopy(SubString(S, idxB, idxE-idxB));
idxB = idxE + Separator.length();
idxE = S.IdxOf(Separator, idxB);
}
if ( idxB < S.length() ) Ss.AddCopy(SubString(S, idxB, S.length()-idxB));
return Ss;
}
#endif

View File

@ -0,0 +1,53 @@
//*************************************************************************************************
//*************************************************************************************************
//
// STRINGS
//
//*************************************************************************************************
//*************************************************************************************************
#if !defined(__XSTRINGWARRAY_H__)
#define __XSTRINGWARRAY_H__
#include "XToolsCommon.h"
#include "XObjArray.h"
#include "XStringW.h"
#define XStringWArraySuper XObjArray<XStringW>
class XStringWArray : public XStringWArraySuper
{
public:
XStringWArray();
void SetNull() { Empty(); }
bool IsNull() const { return Length() == 0 ; }
bool NotNull() const { return Length() > 0 ; }
XStringW ConcatAll(XStringW Separator = L", ", XStringW Prefix = L"", XStringW Suffix = L"") const;
bool Equal(const XStringWArray &aStrings) const;
bool operator ==(const XStringWArray &aXStrings) const { return Equal(aXStrings); }
bool operator !=(const XStringWArray& aXStrings) const { return !Equal(aXStrings); }
bool Contains(const XStringW &S) const;
bool Same(const XStringWArray &aStrings) const;
// Add
void AddStrings(const wchar_t *Val1, ...);
void AddNoNull(const XStringW &aString) { if ( aString.NotNull() ) AddCopy(aString); }
void AddEvenNull(const XStringW &aString) { AddCopy(aString); }
void Add(const XStringW &aString) { AddCopy(aString); }
void Add(const XStringWArray &aStrings);
void AddID(const XStringW &aString); /* ignore Duplicate */
void AddID(const XStringWArray &aStrings); /* ignore Duplicate */
};
extern const XStringWArray NullXStringws;
XStringWArray Split(const XStringW &S, const XStringW &Separator = L", ");
#endif

View File

@ -1,6 +1,8 @@
#ifndef __XTOOLSCOMMON_H__
#define __XTOOLSCOMMON_H__
#include <Platform.h>
#define xsize UINTN
#define MAX_XSIZE MAX_UINTN
@ -15,5 +17,5 @@ extern xsize XBufferGrowByDefault;
#define Xalloc(AllocationSize) AllocatePool(AllocationSize)
#define Xrealloc(OldSize, NewSize, OldBuffer) ReallocatePool(OldSize, NewSize, OldBuffer)
#define Xfree(Buffer) FreePool(Buffer)
#define Xmemcpy(dest,source,count) CopyMem(dest, (void*)(source), count)
#define Xmemmove(dest,source,count) CopyMem(dest, (void*)(source), count) // that has to handle overlapping memory (prefer memmove to memcpy).
#endif

View File

@ -1,6 +1,6 @@
#include "../cpp_foundation/XArray.h"
#include "../Platform/Platform.h"
#include <Platform.h> // Only use angled for Platform, else, xcode project won't compile
int XArray_tests()
{

View File

@ -1,6 +1,6 @@
#include "../cpp_foundation/XObjArray.h"
#include "../Platform/Platform.h"
#include <Platform.h> // Only use angled for Platform, else, xcode project won't compile
class TestObjInt
{

View File

@ -0,0 +1,67 @@
#include "../cpp_foundation/XStringWArray.h"
int XStringWArray_tests()
{
#ifdef JIEF_DEBUG
DebugLog(2, "XStringWArray_tests -> Enter\n");
#endif
XStringWArray array1;
if ( !array1.IsNull() ) return 1;
array1.Add(L"1");
if ( array1.IsNull() ) return 2;
array1.Add(L"2");
if ( array1[0] != L"1" ) return 3;
if ( array1[1] != L"2" ) return 4;
if ( !array1.Contains(L"2") ) return 5;
// Test == and !=
{
XStringWArray array1bis;
array1bis.Add(L"1");
array1bis.Add(L"2");
if ( !(array1 == array1bis) ) return 10;
if ( array1 != array1bis ) return 11;
}
// Test concat and Split
{
XStringW c = array1.ConcatAll(L", ", L"^", L"$");
if ( c != L"^1, 2$" ) return 1;
// Split doesn't handle prefix and suffix yet.
c = array1.ConcatAll(L", ");
XStringWArray array1bis = Split(c);
if ( array1 != array1bis ) return 20;
}
XStringWArray array2;
array2.Add(L"2");
array2.Add(L"1");
if ( array2[0] != L"2" ) return 30;
if ( array2[1] != L"1" ) return 31;
if ( array1 == array2 ) return 40; // Array != because order is different
if ( !array1.Same(array2) ) return 41; // Arrays are the same
array1.AddNoNull(L"3");
if ( array1.Length() != 3 ) return 50;
array1.AddNoNull(L"");
if ( array1.Length() != 3 ) return 51;
array1.AddEvenNull(XStringW());
if ( array1.Length() != 4 ) return 52;
array1.AddID(L"2");
if ( array1.Length() != 4 ) return 53;
return 0;
}

View File

@ -0,0 +1,2 @@
int XStringWArray_tests();

View File

@ -1,35 +1,35 @@
#ifdef DEBUG_CLOVER
DBG("g_str = %s\n", g_str.data());
DBG("g_str2 = %s\n", g_str2.data());
extern XStringW global_str1;
DBG("global_str1 = %s\n", global_str1.data());
extern XStringW global_str2;
DBG("global_str2 = %s\n", global_str2.data());
#include "../cpp_foundation/XStringW.h"
#include "global1.h"
#include "global2.h"
int XStringW_tests()
{
// XStringW str(L"local str value");
// DBG("str = %s\n", str.data());
// str.StrCat(L" appended text");
// DBG("str = %s, len=%d\n", str.data(), str.length());
//
// XStringW str2(str);
// DBG("str2 = %s\n", str2.data());
// str2.StrnCpy(str.data(), 2);
// DBG("str2 = %s\n", str2.data());
// str2.StrnCat(L"2ndtext", 2);
// DBG("str2 = %s\n", str2.data());
// str2.Insert(1, str);
// DBG("str2 = %s\n", str2.data());
// str2 += L"3rdtext";
// DBG("str2 = %s\n", str2.data());
//
// XStringW* str3 = new XStringW();
// *str3 = L"str3data";
// DBG("str3 = %s\n", str3->data());
// delete str3;
}
//
destruct_globals_objects(NULL); // That should be done just before quitting clover module. Now, it's just for test.
DBG("press");
PauseForKey(L"press");
#ifdef JIEF_DEBUG
DebugLog(2, "XStringW_tests -> Enter\n");
#endif
if ( global_str1 != L"global_str1" ) return 1;
if ( global_str2 != L"global_str2" ) return 1;
{
XStringW str(L"1");
if ( str != L"1" ) return 1;
str.StrCat(L"2");
if ( str != L"12" ) return 1;
XStringW str2;
if ( str2.NotNull() ) return 10;
str2.StrnCpy(str.data(), 2);
if ( str2 != L"12" ) return 11;
str2.StrnCat(L"345", 2);
if ( str2 != L"1234" ) return 12;
str2.Insert(1, str);
if ( str2 != L"112234" ) return 13;
str2 += L"6";
if ( str2 != L"1122346" ) return 14;
}
return 0;
}

View File

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

View File

@ -4,8 +4,10 @@
#include "XArray_tests.h"
#include "XObjArray_tests.h"
#include "XStringWArray_test.h"
#include "XStringW_test.h"
#include "../Platform/Platform.h"
#include <Platform.h> // Only use angled for Platform, else, xcode project won't compile
bool all_tests()
{
@ -22,9 +24,19 @@ bool all_tests()
DebugLog(2, "XObjArray_tests() failed at test %d\n", ret);
all_ok = false;
}
ret = XStringW_tests();
if ( ret != 0 ) {
DebugLog(2, "XStringW_tests() failed at test %d\n", ret);
all_ok = false;
}
ret = XStringWArray_tests();
if ( ret != 0 ) {
DebugLog(2, "XStringWArray_tests() failed at test %d\n", ret);
all_ok = false;
}
if ( !all_ok ) {
DebugLog(2, "A test failed, module %d, test %d \n");
DebugLog(2, "A test failed\n");
PauseForKey(L"press");
}else{
#ifdef JIEF_DEBUG

View File

@ -0,0 +1,3 @@
#include "../cpp_foundation/XStringW.h"
extern XStringW global_str1;

View File

@ -0,0 +1,3 @@
#include "../cpp_foundation/XStringW.h"
extern XStringW global_str2;

View File

@ -1,6 +1,6 @@
#include "../Platform/Platform.h"
#include <Platform.h> // Only use angled for Platform, else, xcode project won't compile
extern "C" {
/*

View File

@ -1,5 +1,5 @@
#include "../Platform/Platform.h"
#include <Platform.h> // Only use angled for Platform, else, xcode project won't compile
CONST CHAR16 *
EFIAPI