1
0
forked from 0ad/0ad

Testing system for the i18n code, to make sure I don't break anything. (Now on CVS to make it less lonely.)

This was SVN commit r1145.
This commit is contained in:
Ykkrosh 2004-09-17 17:49:12 +00:00
parent ca862b8332
commit b1a5f53284
19 changed files with 2494 additions and 0 deletions

536
source/i18n/tests/CStr.cpp Executable file
View File

@ -0,0 +1,536 @@
#include "precompiled.h"
#ifndef CStr_CPP_FIRST
#define CStr_CPP_FIRST
//#include "Network/Serialization.h"
#include "types.h"
#include <cassert>
#define UNIDOUBLER_HEADER "CStr.cpp"
#include "UniDoubler.h"
#else
#include "CStr.h"
using namespace std;
#include <sstream>
CStr::CStr()
{
// Default Constructor
}
CStr::CStr(const CStr& Str)
{
// Copy Constructor
m_String = Str.m_String;
}
CStr::CStr(const TCHAR* String)
{
// Creates CStr from C-Style TCHAR string
m_String = String;
}
CStr::CStr(tstring String)
{
m_String = String;
}
#if !(defined(_MSC_VER) && defined(_UNICODE))
CStr::CStr(utf16string String)
{
m_String = tstring(String.begin(), String.end());
}
#endif
CStr::CStr(TCHAR Char)
{
// Creates CStr from a TCHAR
m_String = Char;
}
CStr::CStr(int Number)
{
std::tstringstream ss;
ss << Number;
ss >> m_String;
}
CStr::CStr(unsigned int Number)
{
std::tstringstream ss;
ss << Number;
ss >> m_String;
}
CStr::CStr(long Number)
{
std::tstringstream ss;
ss << Number;
ss >> m_String;
}
CStr::CStr(unsigned long Number)
{
std::tstringstream ss;
ss << Number;
ss >> m_String;
}
CStr::CStr(float Number)
{
std::tstringstream ss;
ss << Number;
ss >> m_String;
}
CStr::CStr(double Number)
{
std::tstringstream ss;
ss << Number;
ss >> m_String;
}
CStr::~CStr()
{
// Destructor
}
int CStr::ToInt() const
{
return _ttoi(m_String.c_str());
}
unsigned int CStr::ToUInt() const
{
return uint(_ttoi(m_String.c_str()));
}
long CStr::ToLong() const
{
return _ttol(m_String.c_str());
}
unsigned long CStr::ToULong() const
{
return ulong(_ttol(m_String.c_str()));
}
float CStr::ToFloat() const
{
return (float)_tstod(m_String.c_str(), NULL);
}
double CStr::ToDouble() const
{
return _tstod(m_String.c_str(), NULL);
}
//You can retrieve the substring within the string
CStr CStr::GetSubstring(size_t start, size_t len) const
{
return CStr( m_String.substr(start, len) );
}
//Search the string for another string
long CStr::Find(const CStr& Str) const
{
size_t Pos = m_String.find(Str.m_String, 0);
if (Pos != tstring::npos)
return (long)Pos;
return -1;
}
//Search the string for another string
long CStr::Find(const TCHAR &tchar) const
{
size_t Pos = m_String.find(tchar, 0);
if (Pos != tstring::npos)
return (long)Pos;
return -1;
}
//Search the string for another string
long CStr::Find(const int &start, const TCHAR &tchar) const
{
size_t Pos = m_String.find(tchar, start);
if (Pos != tstring::npos)
return (long)Pos;
return -1;
}
long CStr::ReverseFind(const CStr& Str) const
{
size_t Pos = m_String.rfind(Str.m_String, m_String.length() );
if (Pos != tstring::npos)
return (long)Pos;
return -1;
}
// Lowercase and uppercase
CStr CStr::LowerCase() const
{
tstring NewTString = m_String;
for (size_t i = 0; i < m_String.length(); i++)
NewTString[i] = (TCHAR)_totlower(m_String[i]);
return CStr(NewTString);
}
CStr CStr::UpperCase() const
{
tstring NewTString = m_String;
for (size_t i = 0; i < m_String.length(); i++)
NewTString[i] = (TCHAR)_totupper(m_String[i]);
return CStr(NewTString);
}
// Lazy versions
// code duplication because return by value overhead if they were merely an allias
CStr CStr::LCase() const
{
tstring NewTString = m_String;
for (size_t i = 0; i < m_String.length(); i++)
NewTString[i] = (TCHAR)_totlower(m_String[i]);
return CStr(NewTString);
}
CStr CStr::UCase() const
{
tstring NewTString = m_String;
for (size_t i = 0; i < m_String.length(); i++)
NewTString[i] = (TCHAR)_totupper(m_String[i]);
return CStr(NewTString);
}
//Retreive the substring of the first n characters
CStr CStr::Left(long len) const
{
return CStr( m_String.substr(0, len) );
}
//Retreive the substring of the last n characters
CStr CStr::Right(long len) const
{
return CStr( m_String.substr(m_String.length()-len, len) );
}
//Remove all occurences of some character or substring
void CStr::Remove(const CStr& Str)
{
size_t FoundAt = 0;
while (FoundAt != tstring::npos)
{
FoundAt = m_String.find(Str.m_String, 0);
if (FoundAt != tstring::npos)
m_String.erase(FoundAt, Str.m_String.length());
}
}
//Replace all occurences of some substring by another
void CStr::Replace(const CStr& ToReplace, const CStr& ReplaceWith)
{
size_t Pos = 0;
while (Pos != tstring::npos)
{
Pos = m_String.find(ToReplace.m_String, Pos);
if (Pos != tstring::npos)
{
m_String.erase(Pos, ToReplace.m_String.length());
m_String.insert(Pos, ReplaceWith.m_String);
Pos += ReplaceWith.m_String.length();
}
}
}
// returns a trimed string, removes whitespace from the left/right/both
CStr CStr::Trim(PS_TRIM_MODE Mode)
{
size_t Left = 0, Right = 0;
switch (Mode)
{
case PS_TRIM_LEFT:
{
for (Left = 0; Left < m_String.length(); Left++)
if (_istspace(m_String[Left]) == false)
break; // end found, trim 0 to Left-1 inclusive
} break;
case PS_TRIM_RIGHT:
{
Right = m_String.length();
while (Right--)
if (_istspace(m_String[Right]) == false)
break; // end found, trim len-1 to Right+1 inclusive
} break;
case PS_TRIM_BOTH:
{
for (Left = 0; Left < m_String.length(); Left++)
if (_istspace(m_String[Left]) == false)
break; // end found, trim 0 to Left-1 inclusive
Right = m_String.length();
while (Right--)
if (_istspace(m_String[Right]) == false)
break; // end found, trim len-1 to Right+1 inclusive
} break;
default:
debug_warn("CStr::Trim: invalid Mode");
}
return CStr( m_String.substr(Left, Right-Left+1) );
}
// Overload operations
CStr& CStr::operator=(const CStr& Str)
{
m_String = Str.m_String;
return *this;
}
CStr& CStr::operator=(const TCHAR* String)
{
m_String = String;
return *this;
}
CStr& CStr::operator=(TCHAR Char)
{
m_String = Char;
return *this;
}
CStr& CStr::operator=(int Number)
{
std::tstringstream ss;
ss << Number;
ss >> m_String;
return *this;
}
CStr& CStr::operator=(long Number)
{
std::tstringstream ss;
ss << Number;
ss >> m_String;
return *this;
}
CStr& CStr::operator=(unsigned int Number)
{
std::tstringstream ss;
ss << Number;
ss >> m_String;
return *this;
}
CStr& CStr::operator=(unsigned long Number)
{
std::tstringstream ss;
ss << Number;
ss >> m_String;
return *this;
}
CStr& CStr::operator=(float Number)
{
std::tstringstream ss;
ss << Number;
ss >> m_String;
return *this;
}
CStr& CStr::operator=(double Number)
{
std::tstringstream ss;
ss << Number;
ss >> m_String;
return *this;
}
bool CStr::operator==(const CStr& Str) const
{
return (m_String == Str.m_String);
}
bool CStr::operator!=(const CStr& Str) const
{
return (m_String != Str.m_String);
}
bool CStr::operator<(const CStr& Str) const
{
return (m_String < Str.m_String);
}
bool CStr::operator<=(const CStr& Str) const
{
return (m_String <= Str.m_String);
}
bool CStr::operator>(const CStr& Str) const
{
return (m_String > Str.m_String);
}
bool CStr::operator>=(const CStr& Str) const
{
return (m_String >= Str.m_String);
}
CStr& CStr::operator+=(const CStr& Str)
{
m_String += Str.m_String;
return *this;
}
CStr CStr::operator+(const CStr& Str)
{
CStr NewStr(*this);
NewStr.m_String += Str.m_String;
return NewStr;
}
CStr::operator const TCHAR*()
{
return m_String.c_str();
}
CStr::operator const TCHAR*() const
{
return m_String.c_str();
}
TCHAR &CStr::operator[](int n)
{
assert((size_t)n < m_String.length());
return m_String[n];
}
TCHAR &CStr::operator[](unsigned int n)
{
assert(n < m_String.length());
return m_String[n];
}
TCHAR &CStr::operator[](long n)
{
assert((size_t)n < m_String.length());
return m_String[n];
}
TCHAR &CStr::operator[](unsigned long n)
{
assert(n < m_String.length());
return m_String[n];
}
ostream &operator<<(ostream &os, CStr& Str)
{
os << (const TCHAR*)Str;
return os;
}
//size_t CStr::GetHashCode() const
//{
// return (size_t)fnv_hash64(m_String.data(), m_String.length());
// // janwas asks: do we care about the hash being 64 bits?
// // it is truncated here on 32-bit systems; why go 64 bit at all?
//}
//
//uint CStr::GetSerializedLength() const
//{
// return uint(m_String.length()*2 + 2);
//}
//
//#ifdef _UNICODE
///*
// CStrW is always serialized to/from UTF-16
//*/
//
//u8 *CStrW::Serialize(u8 *buffer) const
//{
// size_t length=m_String.length();
// size_t i=0;
// for (i=0;i<length;i++)
// *(u16 *)(buffer+i*2)=htons(m_String[i]);
// *(u16 *)(buffer+i*2)=0;
// return buffer+length*2+2;
//}
//
//const u8 *CStrW::Deserialize(const u8 *buffer, const u8 *bufferend)
//{
// const u16 *strend=(const u16 *)buffer;
// while ((const u8 *)strend < bufferend && *strend) strend++;
// if ((const u8 *)strend >= bufferend) return NULL;
//
// m_String.resize(strend-((const u16 *)buffer));
// size_t i=0;
// const u16 *ptr=(const u16 *)buffer;
// while (ptr<strend)
// m_String[i++]=(TCHAR)ntohs(*(ptr++));
//
// return (const u8 *)(strend+1);
//}
//#else
///*
// CStr8 is always serialized to/from ASCII (or whatever 8-bit codepage stored
// in the CStr)
//*/
//
//u8 *CStr8::Serialize(u8 *buffer) const
//{
// size_t length=m_String.length();
// size_t i=0;
// for (i=0;i<length;i++)
// buffer[i]=m_String[i];
// buffer[i]=0;
// return buffer+length+1;
//}
//
//const u8 *CStr8::Deserialize(const u8 *buffer, const u8 *bufferend)
//{
// const u8 *strend=buffer;
// while (strend < bufferend && *strend) strend++;
// if (strend >= bufferend) return NULL;
//
// m_String=std::string(buffer, strend);
//
// return strend+1;
//}
//#endif
#endif

249
source/i18n/tests/CStr.h Executable file
View File

@ -0,0 +1,249 @@
// Hacked version to minimise dependencies
/*
CStr.h
by Caecus
Caecus@0ad.wildfiregames.com
Overview:
Contains CStr class which is a versatile class for making string use easy.
Basic functionality implemented via STL string, so performance is limited
based on the STL implementation we use.
Example:
CStr MyString = _T("Hello, World.");
int MyNum = 126;
MyString += _T(" I'm the number ") += CStr(MyNumber);
// Prints "Hello, World. I'm the number 126"
_tcout << (LPCTSTR)MyString << endl;
MyString = _("2341");
MyNum = MyString.ToInt();
// Prints "2341"
_tcout << MyNum << endl;
More Info:
http://wildfiregames.com/0ad/codepit/TDD/CStr.html
*/
// history:
// 19 May 04, Mark Thompson (mot20@cam.ac.uk / mark@wildfiregames.com)
// 2004-06-18 janwas: replaced conversion buffer with stringstream
#ifndef CSTR_H_FIRST
#define CSTR_H_FIRST
enum PS_TRIM_MODE {PS_TRIM_LEFT, PS_TRIM_RIGHT, PS_TRIM_BOTH};
#ifndef IN_UNIDOUBLER
#define UNIDOUBLER_HEADER "CStr.h"
#include "UniDoubler.h"
#endif
#endif
#if !defined(CSTR_H) || defined(IN_UNIDOUBLER)
#define CSTR_H
//#include "Prometheus.h"
#include <string> // Used for basic string functionality
#include <iostream>
#include "utf16string.h"
//#include "Network/Serialization.h"
#include <cstdlib>
#ifdef _UNICODE
#define tstring wstring
#define tstringstream wstringstream
#define _tcout wcout
#define _tstod wcstod
#define TCHAR wchar_t
#define _ttoi(a) wcstol(a, NULL, 0)
#define _ttol(a) wcstol(a, NULL, 0)
#define _T(t) L ## t
#define _istspace iswspace
#define _tsnprintf swprintf
#define _totlower towlower
#define _totupper towupper
#else
#define tstringstream stringstream
#define tstring string
#define _tcout cout
#define _tstod strtod
#define _ttoi atoi
#define _ttol atol
#define TCHAR char
#define _T(t) t
#define _istspace isspace
#define _tsnprintf snprintf
#define _totlower tolower
#define _totupper toupper
#endif
// CStr class, the mother of all strings
class CStr//: public ISerializable
{
#ifdef _UNICODE
friend class CStr8;
#endif
public:
// CONSTRUCTORS
CStr(); // Default constructor
CStr(const CStr& Str); // Copy Constructor
// Transparent CStrW/8 conversion. Note that CStr8 will provide both
// definitions since CStrW is defined first - would otherwise result in a
// circular dependency
#ifndef _UNICODE
inline CStr8(const CStrW &wideStr):
m_String(wideStr.m_String.begin(), wideStr.m_String.end())
{}
inline operator CStrW ()
{
return CStrW(std::wstring(m_String.begin(), m_String.end()));
}
#endif
CStr(std::tstring String); // Creates CStr from C++ string
#if !(defined(_MSC_VER) && defined(_UNICODE))
CStr(utf16string String); // Creates CStr from UTF16 string, potentially losing data in UTF16->ASCII conversions
#endif
CStr(const TCHAR* String); // Creates CStr from C-Style TCHAR string
CStr(TCHAR Char); // Creates CStr from a TCHAR
CStr(int Number); // Creates CStr from a int
CStr(unsigned int Number); // Creates CStr from a uint
CStr(long Number); // Creates CStr from a long
CStr(unsigned long Number); // Creates CStr from a ulong
CStr(float Number); // Creates CStr from a float
CStr(double Number); // Creates CStr from a double
~CStr(); // Destructor
// Conversions
int ToInt() const;
unsigned int ToUInt() const;
long ToLong() const;
unsigned long ToULong() const;
float ToFloat() const;
double ToDouble() const;
size_t Length() const {return m_String.length();}
// Retrieves the substring within the string
CStr GetSubstring(size_t start, size_t len) const;
//Search the string for another string
long Find(const CStr& Str) const;
//Search the string for another string
long Find(const TCHAR &tchar) const;
//Search the string for another string
long Find(const int &start, const TCHAR &tchar) const;
//You can also do a "ReverseFind"- i.e. search starting from the end
long ReverseFind(const CStr& Str) const;
// Lowercase and uppercase
CStr LowerCase() const;
CStr UpperCase() const;
// Lazy funcs
CStr LCase() const;
CStr UCase() const;
// Retreive the substring of the first n characters
CStr Left(long len) const;
// Retreive the substring of the last n characters
CStr Right(long len) const;
//Remove all occurences of some character or substring
void Remove(const CStr& Str);
//Replace all occurences of some substring by another
void Replace(const CStr& StrToReplace, const CStr& ReplaceWith);
// Returns a trimed string, removes whitespace from the left/right/both
CStr Trim(PS_TRIM_MODE Mode);
// Overload operations
CStr& operator=(const CStr& Str);
CStr& operator=(const TCHAR* String);
CStr& operator=(TCHAR Char);
CStr& operator=(int Number);
CStr& operator=(long Number);
CStr& operator=(unsigned int Number);
CStr& operator=(unsigned long Number);
CStr& operator=(float Number);
CStr& operator=(double Number);
bool operator==(const CStr& Str) const;
bool operator!=(const CStr& Str) const;
bool operator<(const CStr& Str) const;
bool operator<=(const CStr& Str) const;
bool operator>(const CStr& Str) const;
bool operator>=(const CStr& Str) const;
CStr& operator+=(const CStr& Str);
CStr operator+(const CStr& Str);
operator const TCHAR*();
operator const TCHAR*() const; // Gee, I've added this, Maybe the one above should be removed?
TCHAR &operator[](int n);
TCHAR &operator[](unsigned int n);
TCHAR &operator[](long n);
TCHAR &operator[](unsigned long n);
inline const TCHAR *c_str() const
{ return m_String.c_str(); }
inline utf16string utf16() const
{ return utf16string(m_String.begin(), m_String.end()); }
size_t GetHashCode() const;
// Serialization functions
// virtual uint GetSerializedLength() const;
// virtual u8 *Serialize(u8 *buffer) const;
// virtual const u8 *Deserialize(const u8 *buffer, const u8 *bufferend);
protected:
std::tstring m_String;
};
class CStr_hash_compare
{
public:
static const size_t bucket_size = 1;
static const size_t min_buckets = 16;
size_t operator()( const CStr& Key ) const
{
return( Key.GetHashCode() );
}
bool operator()( const CStr& _Key1, const CStr& _Key2 ) const
{
return( _Key1 < _Key2 );
}
};
// overloaded operator for ostreams
std::ostream &operator<<(std::ostream &os, CStr& Str);
#endif
// Hacks to make VAssist happy:
#ifdef PLEASE_DO_NOT_EVER_DEFINE_THIS
class CStrW : public CStr;
class CStr8 : public CStr;
#endif

265
source/i18n/tests/Errors.cpp Executable file
View File

@ -0,0 +1,265 @@
// Auto-generated by errorlist.pl - do not edit.
#include "precompiled.h"
#include "Errors.h"
class PSERROR_CVFSFile : public PSERROR {};
class PSERROR_Error : public PSERROR {};
class PSERROR_GUI : public PSERROR {};
class PSERROR_Game : public PSERROR {};
class PSERROR_I18n : public PSERROR {};
class PSERROR_Renderer : public PSERROR {};
class PSERROR_Scripting : public PSERROR {};
class PSERROR_System : public PSERROR {};
class PSERROR_Xeromyces : public PSERROR {};
class PSERROR_Game_World : public PSERROR_Game {};
class PSERROR_I18n_Script : public PSERROR_I18n {};
class PSERROR_Scripting_DefineType : public PSERROR_Scripting {};
class PSERROR_Scripting_LoadFile : public PSERROR_Scripting {};
class PSERROR_CVFSFile_AlreadyLoaded : public PSERROR_CVFSFile { public: PSERROR_CVFSFile_AlreadyLoaded(); };
class PSERROR_CVFSFile_InvalidBufferAccess : public PSERROR_CVFSFile { public: PSERROR_CVFSFile_InvalidBufferAccess(); };
class PSERROR_CVFSFile_LoadFailed : public PSERROR_CVFSFile { public: PSERROR_CVFSFile_LoadFailed(); };
class PSERROR_Error_InvalidError : public PSERROR_Error { public: PSERROR_Error_InvalidError(); };
class PSERROR_GUI_JSOpenFailed : public PSERROR_GUI { public: PSERROR_GUI_JSOpenFailed(); };
class PSERROR_Game_World_MapLoadFailed : public PSERROR_Game_World { public: PSERROR_Game_World_MapLoadFailed(); };
class PSERROR_I18n_Script_SetupFailed : public PSERROR_I18n_Script { public: PSERROR_I18n_Script_SetupFailed(); };
class PSERROR_Renderer_VBOFailed : public PSERROR_Renderer { public: PSERROR_Renderer_VBOFailed(); };
class PSERROR_Scripting_CallFunctionFailed : public PSERROR_Scripting { public: PSERROR_Scripting_CallFunctionFailed(); };
class PSERROR_Scripting_ContextCreationFailed : public PSERROR_Scripting { public: PSERROR_Scripting_ContextCreationFailed(); };
class PSERROR_Scripting_ConversionFailed : public PSERROR_Scripting { public: PSERROR_Scripting_ConversionFailed(); };
class PSERROR_Scripting_CreateObjectFailed : public PSERROR_Scripting { public: PSERROR_Scripting_CreateObjectFailed(); };
class PSERROR_Scripting_DefineConstantFailed : public PSERROR_Scripting { public: PSERROR_Scripting_DefineConstantFailed(); };
class PSERROR_Scripting_DefineType_AlreadyExists : public PSERROR_Scripting_DefineType { public: PSERROR_Scripting_DefineType_AlreadyExists(); };
class PSERROR_Scripting_DefineType_CreationFailed : public PSERROR_Scripting_DefineType { public: PSERROR_Scripting_DefineType_CreationFailed(); };
class PSERROR_Scripting_GlobalObjectCreationFailed : public PSERROR_Scripting { public: PSERROR_Scripting_GlobalObjectCreationFailed(); };
class PSERROR_Scripting_LoadFile_EvalErrors : public PSERROR_Scripting_LoadFile { public: PSERROR_Scripting_LoadFile_EvalErrors(); };
class PSERROR_Scripting_LoadFile_OpenFailed : public PSERROR_Scripting_LoadFile { public: PSERROR_Scripting_LoadFile_OpenFailed(); };
class PSERROR_Scripting_NativeFunctionSetupFailed : public PSERROR_Scripting { public: PSERROR_Scripting_NativeFunctionSetupFailed(); };
class PSERROR_Scripting_RegisterFunctionFailed : public PSERROR_Scripting { public: PSERROR_Scripting_RegisterFunctionFailed(); };
class PSERROR_Scripting_RuntimeCreationFailed : public PSERROR_Scripting { public: PSERROR_Scripting_RuntimeCreationFailed(); };
class PSERROR_Scripting_StandardClassSetupFailed : public PSERROR_Scripting { public: PSERROR_Scripting_StandardClassSetupFailed(); };
class PSERROR_Scripting_TypeDoesNotExist : public PSERROR_Scripting { public: PSERROR_Scripting_TypeDoesNotExist(); };
class PSERROR_System_RequiredExtensionsMissing : public PSERROR_System { public: PSERROR_System_RequiredExtensionsMissing(); };
class PSERROR_System_SDLInitFailed : public PSERROR_System { public: PSERROR_System_SDLInitFailed(); };
class PSERROR_System_VmodeFailed : public PSERROR_System { public: PSERROR_System_VmodeFailed(); };
class PSERROR_Xeromyces_XMLOpenFailed : public PSERROR_Xeromyces { public: PSERROR_Xeromyces_XMLOpenFailed(); };
class PSERROR_Xeromyces_XMLParseError : public PSERROR_Xeromyces { public: PSERROR_Xeromyces_XMLParseError(); };
extern const PSRETURN PSRETURN_CVFSFile_AlreadyLoaded = 0x01000001;
extern const PSRETURN PSRETURN_CVFSFile_InvalidBufferAccess = 0x01000002;
extern const PSRETURN PSRETURN_CVFSFile_LoadFailed = 0x01000003;
extern const PSRETURN PSRETURN_Error_InvalidError = 0x02000001;
extern const PSRETURN PSRETURN_GUI_JSOpenFailed = 0x03000001;
extern const PSRETURN PSRETURN_Game_World_MapLoadFailed = 0x04040001;
extern const PSRETURN PSRETURN_I18n_Script_SetupFailed = 0x05030001;
extern const PSRETURN PSRETURN_Renderer_VBOFailed = 0x06000001;
extern const PSRETURN PSRETURN_Scripting_DefineType_AlreadyExists = 0x07010001;
extern const PSRETURN PSRETURN_Scripting_DefineType_CreationFailed = 0x07010002;
extern const PSRETURN PSRETURN_Scripting_LoadFile_EvalErrors = 0x07020001;
extern const PSRETURN PSRETURN_Scripting_LoadFile_OpenFailed = 0x07020002;
extern const PSRETURN PSRETURN_Scripting_CallFunctionFailed = 0x07000001;
extern const PSRETURN PSRETURN_Scripting_ContextCreationFailed = 0x07000002;
extern const PSRETURN PSRETURN_Scripting_ConversionFailed = 0x07000003;
extern const PSRETURN PSRETURN_Scripting_CreateObjectFailed = 0x07000004;
extern const PSRETURN PSRETURN_Scripting_DefineConstantFailed = 0x07000005;
extern const PSRETURN PSRETURN_Scripting_GlobalObjectCreationFailed = 0x07000006;
extern const PSRETURN PSRETURN_Scripting_NativeFunctionSetupFailed = 0x07000007;
extern const PSRETURN PSRETURN_Scripting_RegisterFunctionFailed = 0x07000008;
extern const PSRETURN PSRETURN_Scripting_RuntimeCreationFailed = 0x07000009;
extern const PSRETURN PSRETURN_Scripting_StandardClassSetupFailed = 0x0700000a;
extern const PSRETURN PSRETURN_Scripting_TypeDoesNotExist = 0x0700000b;
extern const PSRETURN PSRETURN_System_RequiredExtensionsMissing = 0x08000001;
extern const PSRETURN PSRETURN_System_SDLInitFailed = 0x08000002;
extern const PSRETURN PSRETURN_System_VmodeFailed = 0x08000003;
extern const PSRETURN PSRETURN_Xeromyces_XMLOpenFailed = 0x09000001;
extern const PSRETURN PSRETURN_Xeromyces_XMLParseError = 0x09000002;
extern const PSRETURN MASK__PSRETURN_CVFSFile = 0xff000000;
extern const PSRETURN CODE__PSRETURN_CVFSFile = 0x01000000;
extern const PSRETURN MASK__PSRETURN_Error = 0xff000000;
extern const PSRETURN CODE__PSRETURN_Error = 0x02000000;
extern const PSRETURN MASK__PSRETURN_GUI = 0xff000000;
extern const PSRETURN CODE__PSRETURN_GUI = 0x03000000;
extern const PSRETURN MASK__PSRETURN_Game = 0xff000000;
extern const PSRETURN CODE__PSRETURN_Game = 0x04000000;
extern const PSRETURN MASK__PSRETURN_I18n = 0xff000000;
extern const PSRETURN CODE__PSRETURN_I18n = 0x05000000;
extern const PSRETURN MASK__PSRETURN_Renderer = 0xff000000;
extern const PSRETURN CODE__PSRETURN_Renderer = 0x06000000;
extern const PSRETURN MASK__PSRETURN_Scripting = 0xff000000;
extern const PSRETURN CODE__PSRETURN_Scripting = 0x07000000;
extern const PSRETURN MASK__PSRETURN_System = 0xff000000;
extern const PSRETURN CODE__PSRETURN_System = 0x08000000;
extern const PSRETURN MASK__PSRETURN_Xeromyces = 0xff000000;
extern const PSRETURN CODE__PSRETURN_Xeromyces = 0x09000000;
extern const PSRETURN MASK__PSRETURN_Game_World = 0xffff0000;
extern const PSRETURN CODE__PSRETURN_Game_World = 0x04040000;
extern const PSRETURN MASK__PSRETURN_I18n_Script = 0xffff0000;
extern const PSRETURN CODE__PSRETURN_I18n_Script = 0x05030000;
extern const PSRETURN MASK__PSRETURN_Scripting_DefineType = 0xffff0000;
extern const PSRETURN CODE__PSRETURN_Scripting_DefineType = 0x07010000;
extern const PSRETURN MASK__PSRETURN_Scripting_LoadFile = 0xffff0000;
extern const PSRETURN CODE__PSRETURN_Scripting_LoadFile = 0x07020000;
extern const PSRETURN MASK__PSRETURN_CVFSFile_AlreadyLoaded = 0xffffffff;
extern const PSRETURN CODE__PSRETURN_CVFSFile_AlreadyLoaded = 0x01000001;
extern const PSRETURN MASK__PSRETURN_CVFSFile_InvalidBufferAccess = 0xffffffff;
extern const PSRETURN CODE__PSRETURN_CVFSFile_InvalidBufferAccess = 0x01000002;
extern const PSRETURN MASK__PSRETURN_CVFSFile_LoadFailed = 0xffffffff;
extern const PSRETURN CODE__PSRETURN_CVFSFile_LoadFailed = 0x01000003;
extern const PSRETURN MASK__PSRETURN_Error_InvalidError = 0xffffffff;
extern const PSRETURN CODE__PSRETURN_Error_InvalidError = 0x02000001;
extern const PSRETURN MASK__PSRETURN_GUI_JSOpenFailed = 0xffffffff;
extern const PSRETURN CODE__PSRETURN_GUI_JSOpenFailed = 0x03000001;
extern const PSRETURN MASK__PSRETURN_Game_World_MapLoadFailed = 0xffffffff;
extern const PSRETURN CODE__PSRETURN_Game_World_MapLoadFailed = 0x04040001;
extern const PSRETURN MASK__PSRETURN_I18n_Script_SetupFailed = 0xffffffff;
extern const PSRETURN CODE__PSRETURN_I18n_Script_SetupFailed = 0x05030001;
extern const PSRETURN MASK__PSRETURN_Renderer_VBOFailed = 0xffffffff;
extern const PSRETURN CODE__PSRETURN_Renderer_VBOFailed = 0x06000001;
extern const PSRETURN MASK__PSRETURN_Scripting_DefineType_AlreadyExists = 0xffffffff;
extern const PSRETURN CODE__PSRETURN_Scripting_DefineType_AlreadyExists = 0x07010001;
extern const PSRETURN MASK__PSRETURN_Scripting_DefineType_CreationFailed = 0xffffffff;
extern const PSRETURN CODE__PSRETURN_Scripting_DefineType_CreationFailed = 0x07010002;
extern const PSRETURN MASK__PSRETURN_Scripting_LoadFile_EvalErrors = 0xffffffff;
extern const PSRETURN CODE__PSRETURN_Scripting_LoadFile_EvalErrors = 0x07020001;
extern const PSRETURN MASK__PSRETURN_Scripting_LoadFile_OpenFailed = 0xffffffff;
extern const PSRETURN CODE__PSRETURN_Scripting_LoadFile_OpenFailed = 0x07020002;
extern const PSRETURN MASK__PSRETURN_Scripting_CallFunctionFailed = 0xffffffff;
extern const PSRETURN CODE__PSRETURN_Scripting_CallFunctionFailed = 0x07000001;
extern const PSRETURN MASK__PSRETURN_Scripting_ContextCreationFailed = 0xffffffff;
extern const PSRETURN CODE__PSRETURN_Scripting_ContextCreationFailed = 0x07000002;
extern const PSRETURN MASK__PSRETURN_Scripting_ConversionFailed = 0xffffffff;
extern const PSRETURN CODE__PSRETURN_Scripting_ConversionFailed = 0x07000003;
extern const PSRETURN MASK__PSRETURN_Scripting_CreateObjectFailed = 0xffffffff;
extern const PSRETURN CODE__PSRETURN_Scripting_CreateObjectFailed = 0x07000004;
extern const PSRETURN MASK__PSRETURN_Scripting_DefineConstantFailed = 0xffffffff;
extern const PSRETURN CODE__PSRETURN_Scripting_DefineConstantFailed = 0x07000005;
extern const PSRETURN MASK__PSRETURN_Scripting_GlobalObjectCreationFailed = 0xffffffff;
extern const PSRETURN CODE__PSRETURN_Scripting_GlobalObjectCreationFailed = 0x07000006;
extern const PSRETURN MASK__PSRETURN_Scripting_NativeFunctionSetupFailed = 0xffffffff;
extern const PSRETURN CODE__PSRETURN_Scripting_NativeFunctionSetupFailed = 0x07000007;
extern const PSRETURN MASK__PSRETURN_Scripting_RegisterFunctionFailed = 0xffffffff;
extern const PSRETURN CODE__PSRETURN_Scripting_RegisterFunctionFailed = 0x07000008;
extern const PSRETURN MASK__PSRETURN_Scripting_RuntimeCreationFailed = 0xffffffff;
extern const PSRETURN CODE__PSRETURN_Scripting_RuntimeCreationFailed = 0x07000009;
extern const PSRETURN MASK__PSRETURN_Scripting_StandardClassSetupFailed = 0xffffffff;
extern const PSRETURN CODE__PSRETURN_Scripting_StandardClassSetupFailed = 0x0700000a;
extern const PSRETURN MASK__PSRETURN_Scripting_TypeDoesNotExist = 0xffffffff;
extern const PSRETURN CODE__PSRETURN_Scripting_TypeDoesNotExist = 0x0700000b;
extern const PSRETURN MASK__PSRETURN_System_RequiredExtensionsMissing = 0xffffffff;
extern const PSRETURN CODE__PSRETURN_System_RequiredExtensionsMissing = 0x08000001;
extern const PSRETURN MASK__PSRETURN_System_SDLInitFailed = 0xffffffff;
extern const PSRETURN CODE__PSRETURN_System_SDLInitFailed = 0x08000002;
extern const PSRETURN MASK__PSRETURN_System_VmodeFailed = 0xffffffff;
extern const PSRETURN CODE__PSRETURN_System_VmodeFailed = 0x08000003;
extern const PSRETURN MASK__PSRETURN_Xeromyces_XMLOpenFailed = 0xffffffff;
extern const PSRETURN CODE__PSRETURN_Xeromyces_XMLOpenFailed = 0x09000001;
extern const PSRETURN MASK__PSRETURN_Xeromyces_XMLParseError = 0xffffffff;
extern const PSRETURN CODE__PSRETURN_Xeromyces_XMLParseError = 0x09000002;
PSERROR_CVFSFile_AlreadyLoaded::PSERROR_CVFSFile_AlreadyLoaded() { magic=0x45725221; code=0x01000001; }
PSERROR_CVFSFile_InvalidBufferAccess::PSERROR_CVFSFile_InvalidBufferAccess() { magic=0x45725221; code=0x01000002; }
PSERROR_CVFSFile_LoadFailed::PSERROR_CVFSFile_LoadFailed() { magic=0x45725221; code=0x01000003; }
PSERROR_Error_InvalidError::PSERROR_Error_InvalidError() { magic=0x45725221; code=0x02000001; }
PSERROR_GUI_JSOpenFailed::PSERROR_GUI_JSOpenFailed() { magic=0x45725221; code=0x03000001; }
PSERROR_Game_World_MapLoadFailed::PSERROR_Game_World_MapLoadFailed() { magic=0x45725221; code=0x04040001; }
PSERROR_I18n_Script_SetupFailed::PSERROR_I18n_Script_SetupFailed() { magic=0x45725221; code=0x05030001; }
PSERROR_Renderer_VBOFailed::PSERROR_Renderer_VBOFailed() { magic=0x45725221; code=0x06000001; }
PSERROR_Scripting_DefineType_AlreadyExists::PSERROR_Scripting_DefineType_AlreadyExists() { magic=0x45725221; code=0x07010001; }
PSERROR_Scripting_DefineType_CreationFailed::PSERROR_Scripting_DefineType_CreationFailed() { magic=0x45725221; code=0x07010002; }
PSERROR_Scripting_LoadFile_EvalErrors::PSERROR_Scripting_LoadFile_EvalErrors() { magic=0x45725221; code=0x07020001; }
PSERROR_Scripting_LoadFile_OpenFailed::PSERROR_Scripting_LoadFile_OpenFailed() { magic=0x45725221; code=0x07020002; }
PSERROR_Scripting_CallFunctionFailed::PSERROR_Scripting_CallFunctionFailed() { magic=0x45725221; code=0x07000001; }
PSERROR_Scripting_ContextCreationFailed::PSERROR_Scripting_ContextCreationFailed() { magic=0x45725221; code=0x07000002; }
PSERROR_Scripting_ConversionFailed::PSERROR_Scripting_ConversionFailed() { magic=0x45725221; code=0x07000003; }
PSERROR_Scripting_CreateObjectFailed::PSERROR_Scripting_CreateObjectFailed() { magic=0x45725221; code=0x07000004; }
PSERROR_Scripting_DefineConstantFailed::PSERROR_Scripting_DefineConstantFailed() { magic=0x45725221; code=0x07000005; }
PSERROR_Scripting_GlobalObjectCreationFailed::PSERROR_Scripting_GlobalObjectCreationFailed() { magic=0x45725221; code=0x07000006; }
PSERROR_Scripting_NativeFunctionSetupFailed::PSERROR_Scripting_NativeFunctionSetupFailed() { magic=0x45725221; code=0x07000007; }
PSERROR_Scripting_RegisterFunctionFailed::PSERROR_Scripting_RegisterFunctionFailed() { magic=0x45725221; code=0x07000008; }
PSERROR_Scripting_RuntimeCreationFailed::PSERROR_Scripting_RuntimeCreationFailed() { magic=0x45725221; code=0x07000009; }
PSERROR_Scripting_StandardClassSetupFailed::PSERROR_Scripting_StandardClassSetupFailed() { magic=0x45725221; code=0x0700000a; }
PSERROR_Scripting_TypeDoesNotExist::PSERROR_Scripting_TypeDoesNotExist() { magic=0x45725221; code=0x0700000b; }
PSERROR_System_RequiredExtensionsMissing::PSERROR_System_RequiredExtensionsMissing() { magic=0x45725221; code=0x08000001; }
PSERROR_System_SDLInitFailed::PSERROR_System_SDLInitFailed() { magic=0x45725221; code=0x08000002; }
PSERROR_System_VmodeFailed::PSERROR_System_VmodeFailed() { magic=0x45725221; code=0x08000003; }
PSERROR_Xeromyces_XMLOpenFailed::PSERROR_Xeromyces_XMLOpenFailed() { magic=0x45725221; code=0x09000001; }
PSERROR_Xeromyces_XMLParseError::PSERROR_Xeromyces_XMLParseError() { magic=0x45725221; code=0x09000002; }
const wchar_t* GetErrorString(PSRETURN code)
{
switch (code)
{
case 0x01000001: return L"CVFSFile_AlreadyLoaded";
case 0x01000002: return L"CVFSFile_InvalidBufferAccess";
case 0x01000003: return L"CVFSFile_LoadFailed";
case 0x02000001: return L"Error_InvalidError";
case 0x03000001: return L"GUI_JSOpenFailed";
case 0x04040001: return L"Game_World_MapLoadFailed";
case 0x05030001: return L"I18n_Script_SetupFailed";
case 0x06000001: return L"Renderer_VBOFailed";
case 0x07010001: return L"Scripting_DefineType_AlreadyExists";
case 0x07010002: return L"Scripting_DefineType_CreationFailed";
case 0x07020001: return L"Scripting_LoadFile_EvalErrors";
case 0x07020002: return L"Scripting_LoadFile_OpenFailed";
case 0x07000001: return L"Scripting_CallFunctionFailed";
case 0x07000002: return L"Scripting_ContextCreationFailed";
case 0x07000003: return L"Scripting_ConversionFailed";
case 0x07000004: return L"Scripting_CreateObjectFailed";
case 0x07000005: return L"Scripting_DefineConstantFailed";
case 0x07000006: return L"Scripting_GlobalObjectCreationFailed";
case 0x07000007: return L"Scripting_NativeFunctionSetupFailed";
case 0x07000008: return L"Scripting_RegisterFunctionFailed";
case 0x07000009: return L"Scripting_RuntimeCreationFailed";
case 0x0700000a: return L"Scripting_StandardClassSetupFailed";
case 0x0700000b: return L"Scripting_TypeDoesNotExist";
case 0x08000001: return L"System_RequiredExtensionsMissing";
case 0x08000002: return L"System_SDLInitFailed";
case 0x08000003: return L"System_VmodeFailed";
case 0x09000001: return L"Xeromyces_XMLOpenFailed";
case 0x09000002: return L"Xeromyces_XMLParseError";
default: return L"Unrecognised error";
}
}
void ThrowError(PSRETURN code)
{
switch (code) // Use 'break' in case someone tries to continue from the exception
{
case 0x01000001: throw PSERROR_CVFSFile_AlreadyLoaded(); break;
case 0x01000002: throw PSERROR_CVFSFile_InvalidBufferAccess(); break;
case 0x01000003: throw PSERROR_CVFSFile_LoadFailed(); break;
case 0x02000001: throw PSERROR_Error_InvalidError(); break;
case 0x03000001: throw PSERROR_GUI_JSOpenFailed(); break;
case 0x04040001: throw PSERROR_Game_World_MapLoadFailed(); break;
case 0x05030001: throw PSERROR_I18n_Script_SetupFailed(); break;
case 0x06000001: throw PSERROR_Renderer_VBOFailed(); break;
case 0x07010001: throw PSERROR_Scripting_DefineType_AlreadyExists(); break;
case 0x07010002: throw PSERROR_Scripting_DefineType_CreationFailed(); break;
case 0x07020001: throw PSERROR_Scripting_LoadFile_EvalErrors(); break;
case 0x07020002: throw PSERROR_Scripting_LoadFile_OpenFailed(); break;
case 0x07000001: throw PSERROR_Scripting_CallFunctionFailed(); break;
case 0x07000002: throw PSERROR_Scripting_ContextCreationFailed(); break;
case 0x07000003: throw PSERROR_Scripting_ConversionFailed(); break;
case 0x07000004: throw PSERROR_Scripting_CreateObjectFailed(); break;
case 0x07000005: throw PSERROR_Scripting_DefineConstantFailed(); break;
case 0x07000006: throw PSERROR_Scripting_GlobalObjectCreationFailed(); break;
case 0x07000007: throw PSERROR_Scripting_NativeFunctionSetupFailed(); break;
case 0x07000008: throw PSERROR_Scripting_RegisterFunctionFailed(); break;
case 0x07000009: throw PSERROR_Scripting_RuntimeCreationFailed(); break;
case 0x0700000a: throw PSERROR_Scripting_StandardClassSetupFailed(); break;
case 0x0700000b: throw PSERROR_Scripting_TypeDoesNotExist(); break;
case 0x08000001: throw PSERROR_System_RequiredExtensionsMissing(); break;
case 0x08000002: throw PSERROR_System_SDLInitFailed(); break;
case 0x08000003: throw PSERROR_System_VmodeFailed(); break;
case 0x09000001: throw PSERROR_Xeromyces_XMLOpenFailed(); break;
case 0x09000002: throw PSERROR_Xeromyces_XMLParseError(); break;
default: throw PSERROR_Error_InvalidError(); // Hmm...
}
}

39
source/i18n/tests/Errors.h Executable file
View File

@ -0,0 +1,39 @@
#ifndef _ERRORS_H_
#define _ERRORS_H_
#include "types.h"
typedef u32 PSRETURN;
class PSERROR
{
public:
int magic; // = 0x45725221, so the exception handler can recognise
// that it's a PSERROR and not some other random object.
PSRETURN code; // unique (but arbitrary) code, for translation tables etc
};
#define ERROR_GROUP(a) class PSERROR_##a : public PSERROR {}; \
extern const PSRETURN MASK__PSRETURN_##a; \
extern const PSRETURN CODE__PSRETURN_##a
#define ERROR_SUBGROUP(a,b) class PSERROR_##a##_##b : public PSERROR_##a {}; \
extern const PSRETURN MASK__PSRETURN_##a##_##b; \
extern const PSRETURN CODE__PSRETURN_##a##_##b
#define ERROR_TYPE(a,b) class PSERROR_##a##_##b : public PSERROR_##a { public: PSERROR_##a##_##b(); }; \
extern const PSRETURN MASK__PSRETURN_##a##_##b; \
extern const PSRETURN CODE__PSRETURN_##a##_##b; \
extern const PSRETURN PSRETURN_##a##_##b
#define ERROR_IS(a, b) ( ((a) & MASK__PSRETURN_##b) == CODE__PSRETURN_##b )
const PSRETURN PSRETURN_OK = 0;
const PSRETURN MASK__PSRETURN_OK = 0xffffffff;
const PSRETURN CODE__PSRETURN_OK = 0;
const wchar_t* GetErrorString(PSRETURN code);
void ThrowError(PSRETURN code);
#endif

View File

@ -0,0 +1,53 @@
#include "precompiled.h"
#include "StringConvert.h"
#include <assert.h>
#include "jsapi.h"
#if SDL_BYTE_ORDER == SDL_BIG_ENDIAN
#define ucs2le_to_wchart(ptr) (wchar_t)( (u16) ((u8*)ptr)[0] | (u16) ( ((u8*)ptr)[1] << 8) )
#else
#define ucs2le_to_wchart(ptr) (wchar_t)(*ptr);
#endif
JSString* StringConvert::wstring_to_jsstring(JSContext* cx, const std::wstring& str)
{
size_t len = str.length();
jschar* data = (jschar*)JS_malloc(cx, len*sizeof(jschar));
if (!data)
return NULL;
for (size_t i=0; i<len; ++i)
data[i] = str[i];
return JS_NewUCString(cx, data, len);
}
JSString* StringConvert::wchars_to_jsstring(JSContext* cx, const wchar_t* chars)
{
size_t len = wcslen(chars);
jschar* data = (jschar*)JS_malloc(cx, len*sizeof(jschar));
if (!data)
return NULL;
for (size_t i=0; i<len; ++i)
data[i] = chars[i];
return JS_NewUCString(cx, data, len);
}
void StringConvert::jschars_to_wstring(const jschar* chars, size_t len, std::wstring& result)
{
assert(result.empty());
result.reserve(len);
for (size_t i = 0; i < len; ++i)
result += chars[i];
}
void StringConvert::ucs2le_to_wstring(const char* start, const char* end, std::wstring& result)
{
assert(result.empty());
result.reserve(end-start);
for (const char* pos = start; pos < end; pos += 2)
result += ucs2le_to_wchart(pos);
}

View File

@ -0,0 +1,19 @@
typedef unsigned short jschar;
typedef unsigned short ucs2char;
struct JSString;
struct JSContext;
#include <string>
namespace StringConvert
{
// A random collection of conversion functions:
JSString* wstring_to_jsstring(JSContext* cx, const std::wstring& str);
JSString* wchars_to_jsstring(JSContext* cx, const wchar_t* chars);
void jschars_to_wstring(const jschar* chars, size_t len, std::wstring& result);
void ucs2le_to_wstring(const char* start, const char* end, std::wstring& result);
}

43
source/i18n/tests/UniDoubler.h Executable file
View File

@ -0,0 +1,43 @@
// Make sure we have the argument (UNIDOUBLER_HEADER), and that we're not
// called from within another unidoubler execution (now that's just asking for
// trouble)
#if defined(UNIDOUBLER_HEADER) && !defined(IN_UNIDOUBLER)
#define IN_UNIDOUBLER
#define _UNICODE
#undef CStr
#undef CStr_hash_compare
#define CStr CStrW
// Compat for old code. *Deprecated* CStrW isn't 16-bit - it is "wide"
#define CStr16 CStrW
#define CStr_hash_compare CStrW_hash_compare
#include UNIDOUBLER_HEADER
// Undef all the Conversion Macros
#undef tstring
#undef tstringstream
#undef _tcout
#undef _tstod
#undef _ttoi
#undef _ttol
#undef TCHAR
#undef _T
#undef _istspace
#undef _tsnprintf
#undef _totlower
#undef _totupper
// Now include the 8-bit version under the name CStr8
#undef _UNICODE
#undef CStr
#undef CStr_hash_compare
#define CStr CStr8
#define CStr_hash_compare CStr8_hash_compare
#include UNIDOUBLER_HEADER
#undef IN_UNIDOUBLER
#undef UNIDOUBLER_HEADER
#endif

16
source/i18n/tests/comp.txt Executable file
View File

@ -0,0 +1,16 @@
BufferVariable.cpp
BufferVariable.h
CLocale.cpp
CLocale.h
Common.h
Interface.cpp
Interface.h
ScriptInterface.cpp
ScriptInterface.h
StrImmutable.h
StringBuffer.cpp
#StringBuffer.h
TranslatedString.cpp
TranslatedString.h
#TSComponent.cpp
TSComponent.h

View File

@ -0,0 +1,6 @@
del Coverage\*.dyn
Coverage\tests
cd Coverage
profmerge
codecov -comp ../comp.txt -ccolor #f6f6ff -mname "Philip Taylor" -maddr excors@gmail.com
start CODE_COVERAGE.HTML

View File

@ -0,0 +1,24 @@
#ifndef SYSDEP_H__
#define SYSDEP_H__
// STL_HASH_MAP, STL_HASH_MULTIMAP
#ifdef __GNUC__
// GCC
# include <ext/hash_map>
# define STL_HASH_MAP __gnu_cxx::hash_map
# define STL_HASH_MULTIMAP __gnu_cxx::hash_multimap
#else // !__GNUC__
# include <hash_map>
# if defined(_MSC_VER) && (_MSC_VER >= 1300)
// VC7 or above
# define STL_HASH_MAP stdext::hash_map
# define STL_HASH_MULTIMAP stdext::hash_multimap
# else
// VC6 and anything else (most likely name)
# define STL_HASH_MAP std::hash_map
# define STL_HASH_MULTIMAP std::hash_multimap
# endif // defined(_MSC_VER) && (_MSC_VER >= 1300)
#endif // !__GNUC__
#endif // #ifndef SYSDEP_H__

35
source/i18n/tests/precompiled.h Executable file
View File

@ -0,0 +1,35 @@
#ifndef NDEBUG
#include <vector>
#include <hash_map>
#include <string>
#include <sstream>
#include <map>
/*
#include <crtdbg.h>
#define new new(_NORMAL_BLOCK ,__FILE__, __LINE__)
#define malloc(s) _malloc_dbg(s, _NORMAL_BLOCK, __FILE__, __LINE__)
#define calloc(c, s) _calloc_dbg(c, s, _NORMAL_BLOCK, __FILE__, __LINE__)
#define realloc(p, s) _realloc_dbg(p, s, _NORMAL_BLOCK, __FILE__, __LINE__)
#define _expand(p, s) _expand_dbg(p, s, _NORMAL_BLOCK, __FILE__, __LINE__)
#define free(p) _free_dbg(p, _NORMAL_BLOCK)
*/
#endif
// Random stuff:
#define SDL_LIL_ENDIAN 1234
#define SDL_BIG_ENDIAN 4321
#define SDL_BYTE_ORDER SDL_LIL_ENDIAN
#define cassert(x) extern char cassert__##__LINE__ [x]
#define debug_warn(x) assert(0&&x)
#define XP_WIN
#include "Errors.h"
#include <stdio.h>
#define swprintf _snwprintf

14
source/i18n/tests/ps/CLogger.h Executable file
View File

@ -0,0 +1,14 @@
enum {
ERROR,
WARNING,
};
#include <stdarg.h>
static void LOG(int level, const char* cat, const char* fmt, ...)
{
va_list va;
va_start(va, fmt);
vprintf(fmt, va);
printf("\n");
}

165
source/i18n/tests/test.cpp Executable file
View File

@ -0,0 +1,165 @@
#include "precompiled.h"
#include <stdio.h>
#include <assert.h>
#include <time.h>
#include "Interface.h"
#include "jsapi.h"
I18n::CLocale_interface* g_CurrentLocale;
#define translate(x) g_CurrentLocale->Translate(x)
std::string readfile(const char* fn)
{
std::string t;
FILE* f = fopen(fn, "rb");
assert(f);
size_t c;
char buf[1024];
while (0 != (c = fread(buf, 1, sizeof(buf), f)))
t += std::string(buf, buf+c);
fclose(f);
return t;
}
void errrep(JSContext* cx, const char* msg, JSErrorReport* err)
{
printf("Error: %s\n", msg);
}
int main()
{
JSRuntime* rt = JS_NewRuntime(1024*1024);
assert(rt);
JSContext* cx = JS_NewContext(rt, 8192);
assert(cx);
JSClass clas =
{
"global", 0,
JS_PropertyStub, JS_PropertyStub,
JS_PropertyStub, JS_PropertyStub,
JS_EnumerateStub, JS_ResolveStub,
JS_ConvertStub, JS_FinalizeStub
};
JSObject* glob = JS_NewObject(cx, &clas, NULL, NULL);
JSBool builtins = JS_InitStandardClasses(cx, glob);
assert(builtins);
JS_SetErrorReporter(cx, errrep);
#ifndef NDEBUG
// _CrtSetDbgFlag( _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG) | _CRTDBG_LEAK_CHECK_DF);
//_CrtSetDbgFlag( _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG) | _CRTDBG_CHECK_ALWAYS_DF | _CRTDBG_DELAY_FREE_MEM_DF);
//CrtSetBreakAlloc(1450);
#endif
g_CurrentLocale = I18n::NewLocale(cx, glob);
if (!g_CurrentLocale)
return 1;
extern void test();
test();
#if 0
std::string lang = readfile("e:\\0ad\\cvs\\binaries\\data\\mods\\official\\language\\test\\phrases.lng");
std::string funcs = readfile("e:\\0ad\\cvs\\binaries\\data\\mods\\official\\language\\test\\functions.js");
std::string words = readfile("e:\\0ad\\cvs\\binaries\\data\\mods\\official\\language\\test\\nouns.wrd");
std::string words2 = readfile("e:\\0ad\\cvs\\binaries\\data\\mods\\official\\language\\test\\nouns2.wrd");
g_CurrentLocale->LoadFunctions(funcs.c_str(), funcs.size(), "functions.txt");
g_CurrentLocale->LoadStrings(lang.c_str());
g_CurrentLocale->LoadDictionary(words.c_str());
g_CurrentLocale->LoadDictionary(words2.c_str());
I18n::Str s;
// const char* script = " translate('Hello $name!', i18n.Noun('apple')) ";
const char* script = " translate('Testing things $num of $object', 3/1.5, i18n.Noun('banana')) ";
jsval rval;
if (JS_EvaluateScript(cx, glob, script, (int)strlen(script), "test", 1, &rval) != JS_TRUE)
assert(! "Eval failed");
//assert(JSVAL_IS_STRING(rval));
//s = JS_GetStringChars(JSVAL_TO_STRING(rval));
s = JS_GetStringChars(JS_ValueToString(cx, rval));
printf("%ls\n", s.c_str());
#if 0
s = translate(L"Hello $name!") << I18n::Name("banana");
printf("%ls\n", s.c_str());
s = translate(L"Hello $name!") << I18n::Name("banana");
printf("%ls\n", s.c_str());
s = translate(L"Testing things $num of $object") << 1 << I18n::Name("banana");
printf("%ls\n", s.c_str());
s = translate(L"Testing things $num of $object") << 1234 << I18n::Name("banana");
printf("%ls\n", s.c_str());
s = translate(L"Testing things $num of $object") << 12345 << I18n::Name("apple");
printf("%ls\n", s.c_str());
s = translate(L"Testing things $num of $object") << 123456 << I18n::Name("orange");
printf("%ls\n", s.c_str());
s = translate(L"Testing things $num of $object") << 1234567 << I18n::Name("cheese");
printf("%ls\n", s.c_str());
s = translate(L"Hello $name!") << I18n::Name("Philip");
printf("%ls\n", s.c_str());
s = translate(L"Hello $name!") << I18n::Name("Philip2");
printf("%ls\n", s.c_str());
// s = translate(L"Also hi to $you$me etc") << I18n::DateShort(time(NULL)) << -1;
// printf("%ls\n", s.c_str());
// s = translate(L"Hello $name!") << I18n::DateShort(time(NULL));
//char* y = "you";
//s = translate(L"Hello $name!") << y;
// printf("%ls\n", s.c_str());
s = translate(L"Your $colour cheese-monster eats $num biscuits") << I18n::Name("blue") << 15;
printf("%ls\n", s.c_str());
#endif
// Performance test: (it should go at a few hundred thousand per second)
#if 0
clock_t t = clock();
int limit = 1000000;
for (int i=0; i<limit; ++i)
{
/*
I18n::Str s1 = translate(L"Hello world 1");
I18n::Str s2 = translate(L"Hello world 2");
I18n::Str s3 = translate(L"Hello world 3");
I18n::Str s4 = translate(L"Hello world 4");
// I18n::Str s1 = translate(L"Hello $name!") << L"Philip";
// I18n::Str s2 = translate(L"Your $colour cheese-monster eats $num biscuits") << "blue" << 15;
//I18n::Str s3 = translate(L"Hello2 $name!") << L"Philip";
//I18n::Str s4 = translate(L"Your2 $colour cheese-monster eats $num biscuits") << "blue" << 15;
// I18n::Str s3 = translate(L"Hello $name!") << 1234;
// I18n::Str s4 = translate(L"Your $colour cheese-monster eats $num biscuits") << 10000 << 15;
/*/
I18n::Str s1 = translate(L"Testing things $num $obj") << 1234.0 << I18n::Name("cheese bananas");
//I18n::Str s2 = translate(L"Testing things $num") << 124;
//I18n::Str s3 = translate(L"Testing things $num") << 1231234;
//I18n::Str s4 = translate(L"Testing things $num") << 1243456;
//*/
}
t = clock() - t;
printf("\nTook %f secs (%f/sec)\n", (float)t/(float)CLOCKS_PER_SEC, (float)limit/((float)t/(float)CLOCKS_PER_SEC));
#endif
#endif
delete g_CurrentLocale;
JS_DestroyContext(cx);
JS_DestroyRuntime(rt);
JS_ShutDown();
getchar();
}

229
source/i18n/tests/tests.cpp Executable file
View File

@ -0,0 +1,229 @@
#include "precompiled.h"
#include "Interface.h"
#define FILE_PATH "..\\..\\..\\binaries\\data\\mods\\official\\language\\test\\"
extern I18n::CLocale_interface* g_CurrentLocale;
#define translate(x) g_CurrentLocale->Translate(x)
extern std::string readfile(const char* fn);
#include <stdarg.h>
typedef char CHAR;
typedef const CHAR *LPCSTR;
extern "C" {
__declspec(dllimport) void __stdcall
OutputDebugStringA(LPCSTR lpOutputString);
}
/*
WINBASEAPI
VOID
WINAPI
OutputDebugStringA(
IN LPCSTR lpOutputString
);
*/
void test_assert(bool test, const char* file, int line, const char* fmt, ...)
{
if (! test)
{
char msg[256];
va_list v;
va_start(v, fmt);
vsprintf(msg, fmt, v);
char err[256];
sprintf(err, "%s(%d) : TEST FAILED : %s\n", file, line, msg);
OutputDebugStringA(err);
printf("%s", err);
}
}
#ifndef I18NDEBUG
#error Please compile with I18NDEBUG debug
#endif
namespace I18n { extern bool g_UsedCache; }
#define TEST_EQ_NOCACHE(answer, str, param) \
{ \
I18n::Str s = translate(L##str) param; \
test_assert(s == L##answer, __FILE__, __LINE__, "Unexpected output: %ls", s.c_str()); \
test_assert(!I18n::g_UsedCache, __FILE__, __LINE__, "Unexpectedly used cache"); \
}
#define TEST_EQ_CACHED(answer, str, param) \
{ \
I18n::Str s = translate(L##str) param; \
test_assert(s == L##answer, __FILE__, __LINE__, "Unexpected output: %ls", s.c_str()); \
test_assert(I18n::g_UsedCache, __FILE__, __LINE__, "Failed to use cache"); \
}
void test()
{
// Untranslated strings. Simple strings.
TEST_EQ_NOCACHE(
"Hello world",
"Hello world",
);
// Reporting of an invalid number of parameters.
TEST_EQ_NOCACHE(
"(translation error)",
"Hello world", << 1
);
// Untranslated strings with variables. Int variables.
TEST_EQ_NOCACHE(
"Hello world 1",
"Hello world $n", << 1
);
// Parsing of untranslated strings. Int variables.
TEST_EQ_NOCACHE(
"Hello world 1 23$4!",
"Hello world $a $bee$cee$$$bee!", << 1 << 2 << 3 << 4
);
// PROBLEM: Duplicated variables aren't handled correctly (or at all).
// Make sure they're never used in the identifier strings.
// Caching with ints.
TEST_EQ_CACHED(
"Hello world 1",
"Hello world $n", << 1
);
// Double variables.
TEST_EQ_NOCACHE(
"Hello world 1.500000",
"Hello world $n", << 1.5
);
// Caching with doubles.
TEST_EQ_CACHED(
"Hello world 1.500000",
"Hello world $n", << 1.5
);
/*
// More caching with doubles.
int num[2] = { -1, 0x3ff00000 }; // slightly endian-dependent
TEST_EQ_NOCACHE(
"Hello world 1.000001",
"Hello world $n", << *(double*)&num;
);
num[1] = 0xbff00000;
TEST_EQ_NOCACHE(
"Hello world -1.000001",
"Hello world $n", << *(double*)&num;
);
num[0] = -2;
TEST_EQ_NOCACHE(
"Hello world -1.000001",
"Hello world $n", << *(double*)&num;
);
*/
// Float variables.
TEST_EQ_NOCACHE(
"Hello world 2.500000",
"Hello world $n", << 2.5f
);
// Caching with floats.
TEST_EQ_CACHED(
"Hello world 2.500000",
"Hello world $n", << 2.5f
);
// Handling nouns (no noun table loaded).
TEST_EQ_NOCACHE(
"Hello world cheese",
"Hello world $n", << I18n::Noun("cheese")
);
g_CurrentLocale->LoadDictionary(readfile(FILE_PATH "nouns2.wrd").c_str());
// Handling nouns (not in noun table).
TEST_EQ_NOCACHE(
"Hello world pumpkin",
"Hello world $n", << I18n::Noun("pumpkin")
);
// Handling nouns (from noun table but missing singular).
TEST_EQ_NOCACHE(
"Hello world apple",
"Hello world $n", << I18n::Noun("apple")
);
g_CurrentLocale->UnloadDictionaries();
g_CurrentLocale->LoadDictionary(readfile(FILE_PATH "nouns.wrd").c_str());
// Name variables.
TEST_EQ_NOCACHE(
"Hello world banana",
"Hello world $n", << I18n::Name("banana")
);
// Raw string variables. Caching names / raw strings.
TEST_EQ_CACHED(
"Hello world banana",
"Hello world $n", << I18n::Raw("banana")
);
// Handling nouns (from noun table).
TEST_EQ_NOCACHE(
"Hello world BANANA",
"Hello world $n", << I18n::Noun("banana")
);
// Caching nouns.
TEST_EQ_CACHED(
"Hello world BANANA",
"Hello world $n", << I18n::Noun("banana")
);
std::string funcs = readfile(FILE_PATH "functions.js");
g_CurrentLocale->LoadFunctions(funcs.c_str(), funcs.size(), "functions.txt");
g_CurrentLocale->LoadStrings(readfile(FILE_PATH "phrases.lng").c_str());
// Functions with strings, doubles, ints, variable ints, and variable strings.
TEST_EQ_NOCACHE(
"1.2345+67890=67891.2345. An armadillo buys a platypus for 14.99 (platypus! 14.990000!)",
"Test $obj ($$$amnt)", << I18n::Noun("platypus") << 14.99
);
// Noun lookups in JS functions.
TEST_EQ_NOCACHE(
"There are (1 BANANA) here",
"Testing things $num of $object", << 1 << I18n::Noun("banana")
);
// More noun lookups in JS functions.
TEST_EQ_NOCACHE(
"There are (2 bananas) here",
"Testing things $num of $object", << 2 << I18n::Noun("banana")
);
// Noun lookups in JS functions, despite being Raw. (JS only sees strings).
TEST_EQ_NOCACHE(
"There are (2.5 bananas) here",
"Testing things $num of $object", << 2.5 << I18n::Raw("banana")
);
// Noun lookup failures in JS functions.
TEST_EQ_NOCACHE(
"There are (-3.5 orangutan) here",
"Testing things $num of $object", << -3.5 << I18n::Raw("orangutan")
);
// TODO: Tests for the JS interface.
}

327
source/i18n/tests/tests.icproj Executable file
View File

@ -0,0 +1,327 @@
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Intel C++ Project"
Version="7.1"
Name="tests"
VCNestedProjectGUID="{1D6A376C-DA9E-4E03-83A7-16784F356633}"
VCNestedProjectFileName="tests.vcproj">
<Configurations>
<Configuration
Name="Debug|Win32">
<IntelOptions
CompilerName="1"/>
<Tool
Name="VCCLCompilerTool">
<IntelOptions
Optimization="0"
MinimalRebuild="1"
BasicRuntimeChecks="3"
RuntimeLibrary="5"/>
</Tool>
</Configuration>
<Configuration
Name="Release|Win32">
<IntelOptions
CompilerName="1"/>
<Tool
Name="VCCLCompilerTool">
<IntelOptions
RuntimeLibrary="4"/>
</Tool>
</Configuration>
<Configuration
Name="Coverage|Win32">
<Tool
Name="VCCLCompilerTool">
<IntelOptions
PGOPhase="2"
Optimization="0"
MinimalRebuild="1"
BasicRuntimeChecks="0"
RuntimeLibrary="5"/>
</Tool>
</Configuration>
</Configurations>
<Files>
<File
RelativePath=".\CStr.cpp">
<FileConfiguration
Name="Debug|Win32"/>
<FileConfiguration
Name="Release|Win32"/>
<FileConfiguration
Name="Coverage|Win32"/>
</File>
<File
RelativePath=".\CStr.h">
<FileConfiguration
Name="Debug|Win32"/>
<FileConfiguration
Name="Release|Win32"/>
<FileConfiguration
Name="Coverage|Win32"/>
</File>
<File
RelativePath=".\Errors.cpp">
<FileConfiguration
Name="Debug|Win32"/>
<FileConfiguration
Name="Release|Win32"/>
<FileConfiguration
Name="Coverage|Win32"/>
</File>
<File
RelativePath=".\Errors.h">
<FileConfiguration
Name="Debug|Win32"/>
<FileConfiguration
Name="Release|Win32"/>
<FileConfiguration
Name="Coverage|Win32"/>
</File>
<File
RelativePath=".\precompiled.h">
<FileConfiguration
Name="Debug|Win32"/>
<FileConfiguration
Name="Release|Win32"/>
<FileConfiguration
Name="Coverage|Win32"/>
</File>
<File
RelativePath=".\StringConvert.cpp">
<FileConfiguration
Name="Debug|Win32"/>
<FileConfiguration
Name="Release|Win32"/>
<FileConfiguration
Name="Coverage|Win32"/>
</File>
<File
RelativePath=".\StringConvert.h">
<FileConfiguration
Name="Debug|Win32"/>
<FileConfiguration
Name="Release|Win32"/>
<FileConfiguration
Name="Coverage|Win32"/>
</File>
<File
RelativePath=".\test.cpp">
<FileConfiguration
Name="Debug|Win32"/>
<FileConfiguration
Name="Release|Win32"/>
<FileConfiguration
Name="Coverage|Win32"/>
</File>
<File
RelativePath=".\tests.cpp">
<FileConfiguration
Name="Debug|Win32"/>
<FileConfiguration
Name="Release|Win32"/>
<FileConfiguration
Name="Coverage|Win32"/>
</File>
<File
RelativePath=".\types.h">
<FileConfiguration
Name="Debug|Win32"/>
<FileConfiguration
Name="Release|Win32"/>
<FileConfiguration
Name="Coverage|Win32"/>
</File>
<File
RelativePath=".\UniDoubler.h">
<FileConfiguration
Name="Debug|Win32"/>
<FileConfiguration
Name="Release|Win32"/>
<FileConfiguration
Name="Coverage|Win32"/>
</File>
<File
RelativePath=".\utf16string.h">
<FileConfiguration
Name="Debug|Win32"/>
<FileConfiguration
Name="Release|Win32"/>
<FileConfiguration
Name="Coverage|Win32"/>
</File>
<File
RelativePath="..\BufferVariable.cpp">
<FileConfiguration
Name="Debug|Win32"/>
<FileConfiguration
Name="Release|Win32"/>
<FileConfiguration
Name="Coverage|Win32"/>
</File>
<File
RelativePath="..\BufferVariable.h">
<FileConfiguration
Name="Debug|Win32"/>
<FileConfiguration
Name="Release|Win32"/>
<FileConfiguration
Name="Coverage|Win32"/>
</File>
<File
RelativePath="..\CLocale.cpp">
<FileConfiguration
Name="Debug|Win32"/>
<FileConfiguration
Name="Release|Win32"/>
<FileConfiguration
Name="Coverage|Win32"/>
</File>
<File
RelativePath="..\CLocale.h">
<FileConfiguration
Name="Debug|Win32"/>
<FileConfiguration
Name="Release|Win32"/>
<FileConfiguration
Name="Coverage|Win32"/>
</File>
<File
RelativePath="..\Common.h">
<FileConfiguration
Name="Debug|Win32"/>
<FileConfiguration
Name="Release|Win32"/>
<FileConfiguration
Name="Coverage|Win32"/>
</File>
<File
RelativePath="..\DataTypes.h">
<FileConfiguration
Name="Debug|Win32"/>
<FileConfiguration
Name="Release|Win32"/>
<FileConfiguration
Name="Coverage|Win32"/>
</File>
<File
RelativePath="..\Interface.cpp">
<FileConfiguration
Name="Debug|Win32"/>
<FileConfiguration
Name="Release|Win32"/>
<FileConfiguration
Name="Coverage|Win32"/>
</File>
<File
RelativePath="..\Interface.h">
<FileConfiguration
Name="Debug|Win32"/>
<FileConfiguration
Name="Release|Win32"/>
<FileConfiguration
Name="Coverage|Win32"/>
</File>
<File
RelativePath="..\ScriptInterface.cpp">
<FileConfiguration
Name="Debug|Win32"/>
<FileConfiguration
Name="Release|Win32"/>
<FileConfiguration
Name="Coverage|Win32"/>
</File>
<File
RelativePath="..\ScriptInterface.h">
<FileConfiguration
Name="Debug|Win32"/>
<FileConfiguration
Name="Release|Win32"/>
<FileConfiguration
Name="Coverage|Win32"/>
</File>
<File
RelativePath="..\StrImmutable.h">
<FileConfiguration
Name="Debug|Win32"/>
<FileConfiguration
Name="Release|Win32"/>
<FileConfiguration
Name="Coverage|Win32"/>
</File>
<File
RelativePath="..\StringBuffer.cpp">
<FileConfiguration
Name="Debug|Win32"/>
<FileConfiguration
Name="Release|Win32"/>
<FileConfiguration
Name="Coverage|Win32"/>
</File>
<File
RelativePath="..\StringBuffer.h">
<FileConfiguration
Name="Debug|Win32"/>
<FileConfiguration
Name="Release|Win32"/>
<FileConfiguration
Name="Coverage|Win32"/>
</File>
<File
RelativePath="..\TranslatedString.cpp">
<FileConfiguration
Name="Debug|Win32"/>
<FileConfiguration
Name="Release|Win32"/>
<FileConfiguration
Name="Coverage|Win32"/>
</File>
<File
RelativePath="..\TranslatedString.h">
<FileConfiguration
Name="Debug|Win32"/>
<FileConfiguration
Name="Release|Win32"/>
<FileConfiguration
Name="Coverage|Win32"/>
</File>
<File
RelativePath="..\TSComponent.cpp">
<FileConfiguration
Name="Debug|Win32"/>
<FileConfiguration
Name="Release|Win32"/>
<FileConfiguration
Name="Coverage|Win32"/>
</File>
<File
RelativePath="..\TSComponent.h">
<FileConfiguration
Name="Debug|Win32"/>
<FileConfiguration
Name="Release|Win32"/>
<FileConfiguration
Name="Coverage|Win32"/>
</File>
<File
RelativePath=".\lib\sysdep\sysdep.h">
<FileConfiguration
Name="Debug|Win32"/>
<FileConfiguration
Name="Release|Win32"/>
<FileConfiguration
Name="Coverage|Win32"/>
</File>
<File
RelativePath=".\ps\CLogger.h">
<FileConfiguration
Name="Debug|Win32"/>
<FileConfiguration
Name="Release|Win32"/>
<FileConfiguration
Name="Coverage|Win32"/>
</File>
</Files>
</VisualStudioProject>

29
source/i18n/tests/tests.sln Executable file
View File

@ -0,0 +1,29 @@
Microsoft Visual Studio Solution File, Format Version 8.00
Project("{EAF909A5-FA59-4C3D-9431-0FCC20D5BCF9}") = "tests", "tests.icproj", "{9B3CF673-0EF8-4385-8AFE-456CD309D91A}"
ProjectSection(ProjectDependencies) = postProject
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfiguration) = preSolution
Coverage = Coverage
Debug = Debug
Release = Release
EndGlobalSection
GlobalSection(ProjectConfiguration) = postSolution
{9B3CF673-0EF8-4385-8AFE-456CD309D91A}.Coverage.ActiveCfg = Coverage|Win32
{9B3CF673-0EF8-4385-8AFE-456CD309D91A}.Coverage.Build.0 = Coverage|Win32
{9B3CF673-0EF8-4385-8AFE-456CD309D91A}.Debug.ActiveCfg = Debug|Win32
{9B3CF673-0EF8-4385-8AFE-456CD309D91A}.Debug.Build.0 = Debug|Win32
{9B3CF673-0EF8-4385-8AFE-456CD309D91A}.Release.ActiveCfg = Release|Win32
{9B3CF673-0EF8-4385-8AFE-456CD309D91A}.Release.Build.0 = Release|Win32
{1D6A376C-DA9E-4E03-83A7-16784F356633}.Coverage.ActiveCfg = Coverage|Win32
{1D6A376C-DA9E-4E03-83A7-16784F356633}.Debug.ActiveCfg = Debug|Win32
{1D6A376C-DA9E-4E03-83A7-16784F356633}.Debug.Build.0 = Debug|Win32
{1D6A376C-DA9E-4E03-83A7-16784F356633}.Release.ActiveCfg = Release|Win32
{1D6A376C-DA9E-4E03-83A7-16784F356633}.Release.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
EndGlobalSection
GlobalSection(ExtensibilityAddIns) = postSolution
EndGlobalSection
EndGlobal

297
source/i18n/tests/tests.vcproj Executable file
View File

@ -0,0 +1,297 @@
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="7.10"
Name="tests"
ProjectGUID="{1D6A376C-DA9E-4E03-83A7-16784F356633}"
RootNamespace="tests"
Keyword="Win32Proj">
<Platforms>
<Platform
Name="Win32"/>
</Platforms>
<Configurations>
<Configuration
Name="Debug|Win32"
OutputDirectory="Debug"
IntermediateDirectory="Debug"
ConfigurationType="1"
CharacterSet="2">
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="E:\0ad\libs\include;E:\0ad\cvs\source\i18n;E:\0ad\cvs\source\i18n\tests"
PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
MinimalRebuild="TRUE"
BasicRuntimeChecks="3"
RuntimeLibrary="5"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="TRUE"
DebugInformationFormat="4"/>
<Tool
Name="VCCustomBuildTool"/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="kernel32.lib js32d.lib"
OutputFile="$(OutDir)/tests.exe"
LinkIncremental="2"
AdditionalLibraryDirectories="E:\0ad\libs\lib"
GenerateDebugInformation="TRUE"
ProgramDatabaseFile="$(OutDir)/tests.pdb"
SubSystem="1"
TargetMachine="1"/>
<Tool
Name="VCMIDLTool"/>
<Tool
Name="VCPostBuildEventTool"/>
<Tool
Name="VCPreBuildEventTool"/>
<Tool
Name="VCPreLinkEventTool"/>
<Tool
Name="VCResourceCompilerTool"/>
<Tool
Name="VCWebServiceProxyGeneratorTool"/>
<Tool
Name="VCXMLDataGeneratorTool"/>
<Tool
Name="VCWebDeploymentTool"/>
<Tool
Name="VCManagedWrapperGeneratorTool"/>
<Tool
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
</Configuration>
<Configuration
Name="Release|Win32"
OutputDirectory="Release"
IntermediateDirectory="Release"
ConfigurationType="1"
CharacterSet="2">
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories="E:\0ad\libs\include;E:\0ad\cvs\source\i18n;E:\0ad\cvs\source\i18n\tests"
PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
RuntimeLibrary="4"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="TRUE"
DebugInformationFormat="3"/>
<Tool
Name="VCCustomBuildTool"/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="kernel32.lib js32.lib"
OutputFile="$(OutDir)/tests.exe"
LinkIncremental="1"
AdditionalLibraryDirectories="E:\0ad\libs\lib"
GenerateDebugInformation="TRUE"
SubSystem="1"
OptimizeReferences="2"
EnableCOMDATFolding="2"
TargetMachine="1"/>
<Tool
Name="VCMIDLTool"/>
<Tool
Name="VCPostBuildEventTool"/>
<Tool
Name="VCPreBuildEventTool"/>
<Tool
Name="VCPreLinkEventTool"/>
<Tool
Name="VCResourceCompilerTool"/>
<Tool
Name="VCWebServiceProxyGeneratorTool"/>
<Tool
Name="VCXMLDataGeneratorTool"/>
<Tool
Name="VCWebDeploymentTool"/>
<Tool
Name="VCManagedWrapperGeneratorTool"/>
<Tool
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
</Configuration>
<Configuration
Name="Coverage|Win32"
OutputDirectory="$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="2">
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="E:\0ad\libs\include;E:\0ad\cvs\source\i18n;E:\0ad\cvs\source\i18n\tests"
PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE;I18NDEBUG"
MinimalRebuild="TRUE"
BasicRuntimeChecks="0"
RuntimeLibrary="5"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="TRUE"
DebugInformationFormat="3"/>
<Tool
Name="VCCustomBuildTool"/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="kernel32.lib js32d.lib"
OutputFile="$(OutDir)/tests.exe"
LinkIncremental="2"
SuppressStartupBanner="TRUE"
AdditionalLibraryDirectories="E:\0ad\libs\lib"
GenerateDebugInformation="TRUE"
ProgramDatabaseFile="$(OutDir)/tests.pdb"
SubSystem="1"
TargetMachine="1"/>
<Tool
Name="VCMIDLTool"/>
<Tool
Name="VCPostBuildEventTool"/>
<Tool
Name="VCPreBuildEventTool"/>
<Tool
Name="VCPreLinkEventTool"/>
<Tool
Name="VCResourceCompilerTool"/>
<Tool
Name="VCWebServiceProxyGeneratorTool"/>
<Tool
Name="VCXMLDataGeneratorTool"/>
<Tool
Name="VCWebDeploymentTool"/>
<Tool
Name="VCManagedWrapperGeneratorTool"/>
<Tool
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<Filter
Name="Source Files"
Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm;asmx"
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}">
<File
RelativePath=".\CStr.cpp">
</File>
<File
RelativePath=".\CStr.h">
</File>
<File
RelativePath=".\Errors.cpp">
</File>
<File
RelativePath=".\Errors.h">
</File>
<File
RelativePath=".\precompiled.h">
</File>
<File
RelativePath=".\StringConvert.cpp">
</File>
<File
RelativePath=".\StringConvert.h">
</File>
<File
RelativePath=".\test.cpp">
</File>
<File
RelativePath=".\tests.cpp">
</File>
<File
RelativePath=".\types.h">
</File>
<File
RelativePath=".\UniDoubler.h">
</File>
<File
RelativePath=".\utf16string.h">
</File>
<Filter
Name="i18n"
Filter="">
<File
RelativePath="..\BufferVariable.cpp">
</File>
<File
RelativePath="..\BufferVariable.h">
</File>
<File
RelativePath="..\CLocale.cpp">
</File>
<File
RelativePath="..\CLocale.h">
</File>
<File
RelativePath="..\Common.h">
</File>
<File
RelativePath="..\DataTypes.h">
</File>
<File
RelativePath="..\Interface.cpp">
</File>
<File
RelativePath="..\Interface.h">
</File>
<File
RelativePath="..\ScriptInterface.cpp">
</File>
<File
RelativePath="..\ScriptInterface.h">
</File>
<File
RelativePath="..\StrImmutable.h">
</File>
<File
RelativePath="..\StringBuffer.cpp">
</File>
<File
RelativePath="..\StringBuffer.h">
</File>
<File
RelativePath="..\TranslatedString.cpp">
</File>
<File
RelativePath="..\TranslatedString.h">
</File>
<File
RelativePath="..\TSComponent.cpp">
</File>
<File
RelativePath="..\TSComponent.h">
</File>
</Filter>
<Filter
Name="lib"
Filter="">
<Filter
Name="sysdep"
Filter="">
<File
RelativePath=".\lib\sysdep\sysdep.h">
</File>
</Filter>
</Filter>
<Filter
Name="ps"
Filter="">
<File
RelativePath=".\ps\CLogger.h">
</File>
</Filter>
</Filter>
<Filter
Name="Header Files"
Filter="h;hpp;hxx;hm;inl;inc;xsd"
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}">
</Filter>
<Filter
Name="Resource Files"
Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx"
UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}">
</Filter>
</Files>
<Globals>
</Globals>
</VisualStudioProject>

43
source/i18n/tests/types.h Executable file
View File

@ -0,0 +1,43 @@
// Hacked version to minimise dependencies
// convenience type (shorter defs than stdint uintN_t)
#ifndef __TYPES_H__
#define __TYPES_H__
//#include "posix.h"
typedef unsigned int uint32_t;
typedef unsigned short uint16_t;
typedef unsigned char uint8_t;
typedef unsigned short wchar_t;
// defines instead of typedefs so we can #undef conflicting decls
// Workaround: GCC won't parse constructor-casts with multi-word types, while
// visual studio will. Define uint/long to a namespaced one-word typedef.
typedef unsigned long PS_ulong;
typedef unsigned int PS_uint;
#define ulong PS_ulong
#define uint PS_uint
#define i8 int8_t
#define i16 int16_t
#define i32 int32_t
#define i64 int64_t
#define u8 uint8_t
#define u16 uint16_t
#define u32 uint32_t
#define u64 uint64_t
// the standard only guarantees 16 bits.
// we use this for memory offsets and ranges, so it better be big enough.
#ifdef SIZE_MAX // nested #if to avoid ICC warning if not defined
# if SIZE_MAX < 32
# error "check size_t and SIZE_MAX - too small?"
# endif
#endif
#endif // #ifndef __TYPES_H__

105
source/i18n/tests/utf16string.h Executable file
View File

@ -0,0 +1,105 @@
/*
A basic_string derivative that works with uint16_t as its underlying char
type.
*/
#ifndef utf16string_H
#define utf16string_H
// On Windows, wchar_t is typedef'ed to unsigned short, which conflicts
// with uint16_t (which is also an unsigned short), so just use std::wstring
#ifdef _MSC_VER
typedef wchar_t utf16_t;
typedef std::wstring utf16string;
typedef std::wstringstream utf16stringstream;
// On Linux, wchar_t is 32-bit, so define a new version of it
#else
#include <string>
#include "types.h"
typedef uint16_t utf16_t;
typedef std::basic_string<utf16_t> utf16string;
typedef std::basic_stringstream<utf16_t> utf16stringstream;
namespace std {
template<>
struct char_traits<utf16_t>
{
typedef utf16_t char_type;
typedef int int_type;
typedef streampos pos_type;
typedef streamoff off_type;
typedef mbstate_t state_type;
static void assign(char_type& c1, const char_type& c2)
{ c1 = c2; }
static bool eq(const char_type& c1, const char_type& c2)
{ return c1 == c2; }
static bool lt(const char_type& c1, const char_type& c2)
{ return c1 < c2; }
static int compare(const char_type* s1, const char_type* s2, size_t n)
{
return memcmp(s1, s2, n*sizeof(char_type));
}
static size_t length(const char_type* s)
{
const char_type* end=s;
while (*end) end++;
return end-s;
}
static const char_type* find(const char_type* s, size_t n, const char_type& a)
{
size_t i;
for (i=0;i<n;i++)
{
if (s[i] == a) return s+i;
}
return NULL;
}
static char_type* move(char_type* s1, const char_type* s2, size_t n)
{
return (char_type *)memmove(s1, s2, n*sizeof(char_type));
}
static char_type* copy(char_type* s1, const char_type* s2, size_t n)
{
return (char_type *)memcpy(s1, s2, n*sizeof(char_type));
}
static char_type* assign(char_type* s, size_t n, char_type a)
{
while (n--)
{
s[n]=a;
}
return s;
}
static char_type to_char_type(const int_type& c)
{ return (char_type)c; }
static int_type to_int_type(const char_type& c)
{ return (int_type)c; }
static bool eq_int_type(const int_type& c1, const int_type& c2)
{ return c1 == c2; }
static int_type eof()
{ return -1; }
static int_type not_eof(const int_type& c)
{ return (c == -1) ? 0 : c; }
};
}
#endif // #ifdef _MSC_VER / #else
#endif