Fixed winchar tests

git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@6430 212acab6-be3b-0410-9dea-997c60f758d6
This commit is contained in:
anders_k 2014-01-22 09:54:21 +00:00
parent 069a18860a
commit 03405bcd96
10 changed files with 88 additions and 51 deletions

View file

@ -130,8 +130,6 @@ Macros and conversion functions for InstallOptions
!endif
!insertmacro INSTALLOPTIONS_WRITE "${FILE}" "Settings" "RTL" "$(^RTL)"
!verbose pop
!macroend
!macro INSTALLOPTIONS_EXTRACT_AS FILE FILENAME

View file

@ -3,15 +3,13 @@
; (c) brainsucker, 2002
; (r) BSForce
; Check for double includes
!verbose push 3
!ifndef SysFunc.NSH.Included
!define SysFunc.NSH.Included
!include "System.nsh"
!verbose 3 ; For WinMessages especially
!include "WinMessages.nsh"
!verbose 4
!include "WinMessages.nsh"
; ================= GetInstallerExeName implementation =================
@ -393,6 +391,5 @@ exit:
System::Store "P0 l"
FunctionEnd
!verbose 4
!endif
!endif
!verbose pop

View file

@ -3,12 +3,10 @@
; (c) brainsucker, 2002
; (r) BSForce
; Check for double includes
!verbose push 3
!ifndef System.NSH.Included
!define System.NSH.Included
!verbose 3
!include WinCore.nsh
; ------------- Functions --------------
@ -411,6 +409,5 @@ CheckCB_${CHKN}:
ExitCB_${CHKN}:
!macroend
!verbose 4
!endif
!endif
!verbose pop

View file

@ -11,6 +11,7 @@ class CDialogTemplateTest : public CppUnit::TestFixture {
public:
void testCorrectness() {
const bool unicode_classes = false;
unsigned char original_dialog[184] = {
1, 0, 255, 255, 0, 0, 0, 0, 0, 0,
0, 0, 72, 4, 0, 64, 3, 0, 0, 0, 0,
@ -31,7 +32,7 @@ public:
0, 65, 0, 0, 0, 0, 0, 0, 0
};
CDialogTemplate dt(original_dialog, 1252);
CDialogTemplate dt(original_dialog, unicode_classes, 1252);
DWORD dwSize;
unsigned char *saved_dialog = dt.Save(dwSize);

View file

@ -2,6 +2,13 @@
#include <string.h> // for memset
#if _MSC_VER > 1200 // Hack to avoid extern "C" causing trouble with templates
#include <new>
#include <algorithm>
#include <iterator>
#include <memory>
#endif
#define EXEHEAD
#define NSIS_CONFIG_COMPRESSION_SUPPORT
@ -58,5 +65,5 @@ extern "C" {
}
DECOMPRESSOR(lzmaDecompressor, lzma_stream, lzmaInit, lzmaDecode, unsigned char);
DECOMPRESSOR(bzip2Decompressor, DState, BZ2_bzDecompressInit, BZ2_bzDecompress, char);
DECOMPRESSOR(bzip2Decompressor, DState, BZ2_bzDecompressInit, BZ2_bzDecompress, unsigned char);
DECOMPRESSOR(zlibDecompressor, z_stream, inflateReset, inflate, unsigned char);

View file

@ -1,7 +1,10 @@
#include <cppunit/extensions/HelperMacros.h>
#include "../dirreader.h"
#include "../tstring.h"
#include "tstring.h"
#ifndef TEXT
#define TEXT _T
#endif
using namespace std;

View file

@ -8,6 +8,10 @@
// macro for fixing endianity
#define _x(x) FIX_ENDIAN_INT16(WCHAR(x))
// BUGBUG: These tests currently run as Ansi, it would be better if it respected defenv['UNICODE']
// BUGBUG: WinWStrDupFromWC is unable to test WCToUTF16LEHlpr because it is behind #ifdef MAKENSIS
class WinCharTest : public CppUnit::TestFixture {
CPPUNIT_TEST_SUITE( WinCharTest );
@ -21,42 +25,49 @@ class WinCharTest : public CppUnit::TestFixture {
public:
void testFromTchar() {
WCHAR test[] = { _x('t'), _x('e'), _x('s'), _x('t'), 0 };
WCHAR *dyn = wcsdup_fromansi("test");
unsigned short test[] = { _x('t'), _x('e'), _x('s'), _x('t'), 0 };
WINWCHAR *dyn = WinWStrDupFromTChar(_T("test"));
CPPUNIT_ASSERT_EQUAL( 0, memcmp(test, dyn, 5) );
free(dyn);
dyn = WinWStrDupFromChar("test");
CPPUNIT_ASSERT_EQUAL( 0, memcmp(test, dyn, 5) );
free(dyn);
dyn = WinWStrDupFromWC(L"test");
CPPUNIT_ASSERT_EQUAL( 0, memcmp(test, dyn, 5) );
free(dyn);
}
void testStrCpy() {
WCHAR a[] = { _x('t'), _x('e'), _x('s'), _x('t'), 0 };
WCHAR b[5];
WINWCHAR a[] = { _x('t'), _x('e'), _x('s'), _x('t'), 0 };
WINWCHAR b[5];
CPPUNIT_ASSERT_EQUAL( (WCHAR*) b, (WCHAR*) wcscpy(b, a) );
CPPUNIT_ASSERT_EQUAL( 0, memcmp(a, b, 5) );
CPPUNIT_ASSERT_EQUAL( b, WinWStrCpy(b, a) );
CPPUNIT_ASSERT_EQUAL( 0, memcmp(a, b, 5 * sizeof(WINWCHAR)) );
}
void testStrNCpy() {
WCHAR a1[] = { _x('t'), _x('e'), _x('s'), _x('t'), 0 };
WCHAR b[5];
WINWCHAR a1[] = { _x('t'), _x('e'), _x('s'), _x('t'), 0 };
WINWCHAR b[5];
CPPUNIT_ASSERT_EQUAL( (WCHAR*) b, (WCHAR*) wcsncpy(b, a1, 5) );
CPPUNIT_ASSERT_EQUAL( 0, memcmp(a1, b, 5 * sizeof(WCHAR)) );
CPPUNIT_ASSERT_EQUAL( b, WinWStrNCpy(b, a1, 5) );
CPPUNIT_ASSERT_EQUAL( 0, memcmp(a1, b, 5 * sizeof(WINWCHAR)) );
WCHAR a2[] = { _x('t'), _x('e'), 0, 0, 0 };
WINWCHAR a2[] = { _x('t'), _x('e'), 0, 0, 0 };
CPPUNIT_ASSERT_EQUAL( (WCHAR*) b, (WCHAR*) wcsncpy(b, a2, 5) );
CPPUNIT_ASSERT_EQUAL( 0, memcmp(a2, b, 5 * sizeof(WCHAR)) );
CPPUNIT_ASSERT_EQUAL( b, WinWStrNCpy(b, a2, 5) );
CPPUNIT_ASSERT_EQUAL( 0, memcmp(a2, b, 5 * sizeof(WINWCHAR)) );
CPPUNIT_ASSERT_EQUAL( (WCHAR*) b, (WCHAR*) wcsncpy(b, a1, 2) );
CPPUNIT_ASSERT_EQUAL( 0, memcmp(a2, b, 5 * sizeof(WCHAR)) );
CPPUNIT_ASSERT_EQUAL( b, WinWStrNCpy(b, a1, 2) );
CPPUNIT_ASSERT_EQUAL( 0, memcmp(a2, b, 5 * sizeof(WINWCHAR)) );
}
void testStrLen() {
WCHAR test[] = { _x('t'), _x('e'), _x('s'), _x('t'), 0 };
WINWCHAR test[] = { _x('t'), _x('e'), _x('s'), _x('t'), 0 };
CPPUNIT_ASSERT_EQUAL( (size_t) 4, wcslen(test) );
CPPUNIT_ASSERT_EQUAL( (size_t) 4, WinWStrLen(test) );
}
static int simplifyNumber(int n) {
@ -69,16 +80,16 @@ public:
void testStrCmp() {
char a[] = "a";
WCHAR wa[] = { _x('a'), 0 };
WINWCHAR wa[] = { _x('a'), 0 };
char b[] = "b";
WCHAR wb[] = { _x('b'), 0 };
WINWCHAR wb[] = { _x('b'), 0 };
char empty[] = "";
WCHAR wempty[] = { 0 };
WINWCHAR wempty[] = { 0 };
#define TEST_STR_CMP(x, y) \
CPPUNIT_ASSERT_EQUAL(\
simplifyNumber(strcmp(x, y)), \
simplifyNumber(wcscmp(w##x, w##y)) \
simplifyNumber(WinWStrCmp(w##x, w##y)) \
)
TEST_STR_CMP(a, b);
@ -91,13 +102,13 @@ public:
}
void testStrDup() {
WCHAR a[] = { _x('a'), _x('b'), _x('c'), 0 };
WINWCHAR a[] = { _x('a'), _x('b'), _x('c'), 0 };
WCHAR *b = _wcsdup(a);
WINWCHAR *b = WinWStrDupFromWinWStr(a);
CPPUNIT_ASSERT_EQUAL( 0, wcscmp(a, b) );
CPPUNIT_ASSERT_EQUAL( 0, WinWStrCmp(a, b) );
delete [] b;
free(b);
}
};

View file

@ -942,7 +942,8 @@ int sane_system(const TCHAR *command)
fixedcmd += _T(" /C "), fixedcmd += prefix;
return RunChildProcessRedirected(fixedcmd.c_str(), command);
#else
tstring fixedcmd = prefix + _T("") + command;
tstring fixedcmd = prefix;
fixedcmd += _T(""), fixedcmd += command;
return _tsystem(fixedcmd.c_str());
#endif // ~_UNICODE
#else // !_WIN32

View file

@ -43,6 +43,21 @@ int WinWStrNICmpASCII(const WINWCHAR *a, const char *b, size_t n)
return diff;
}
WINWCHAR* WinWStrDupFromChar(const char *s, unsigned int cp)
{
size_t cch = MultiByteToWideChar(cp, 0, s, -1, 0, 0);
wchar_t *p = (wchar_t*) malloc(cch);
if (p)
{
MultiByteToWideChar(cp, 0, s, -1, p, cch);
#ifndef _WIN32
wchar_t *p2 = (wchar_t*) WinWStrDupFromWC(p);
free(p), p = p2;
#endif
}
return (WINWCHAR*) p;
}
#ifndef _WIN32
size_t WinWStrLen(const WINWCHAR *s)
{
@ -86,7 +101,7 @@ WINWCHAR* WinWStrDupFromWinWStr(const WINWCHAR *s)
return d;
}
WINWCHAR* WinWStrDupFromTChar(const TCHAR *s)
WINWCHAR* WinWStrDupFromWC(const wchar_t *s)
{
#ifdef MAKENSIS
WCToUTF16LEHlpr cnv;
@ -94,9 +109,9 @@ WINWCHAR* WinWStrDupFromTChar(const TCHAR *s)
return (WINWCHAR*) cnv.Detach();
#else
// NOTE: Anything outside the ASCII range will not convert correctly!
size_t cch = strlen(s);
size_t cch = wcslen(s);
WINWCHAR* p = (WINWCHAR*) malloc(++cch * 2);
if (p) for (size_t i = 0; i < cch; ++i) p[i] = s[i];
if (p) for (size_t i = 0; i < cch; ++i) p[i] = (unsigned char) s[i];
return p;
#endif
}

View file

@ -28,7 +28,7 @@ inline WINWCHAR* WinWStrCpy(WINWCHAR *d, const WINWCHAR *s) { return (WINWCHAR*)
inline WINWCHAR* WinWStrNCpy(WINWCHAR *d, const WINWCHAR *s, size_t n) { return (WINWCHAR*)wcsncpy((wchar_t*)d, (wchar_t*)s, n); }
inline int WinWStrCmp(const WINWCHAR *a, const WINWCHAR *b) { return wcscmp((wchar_t*)a, (wchar_t*)b); }
inline WINWCHAR* WinWStrDupFromWinWStr(const WINWCHAR *s) { return (WINWCHAR*)wcsdup((wchar_t*)s); }
inline WINWCHAR* WinWStrDupFromTChar(const wchar_t *s) { return WinWStrDupFromWinWStr((WINWCHAR*)s); }
inline WINWCHAR* WinWStrDupFromWC(const wchar_t *s) { return WinWStrDupFromWinWStr((WINWCHAR*)s); }
inline int WinWStrToInt(const WINWCHAR *s) { return _wtoi((wchar_t*)s); }
#else // !_WIN32
size_t WinWStrLen(const WINWCHAR *s);
@ -36,12 +36,19 @@ WINWCHAR* WinWStrCpy(WINWCHAR *d, const WINWCHAR *s);
WINWCHAR* WinWStrNCpy(WINWCHAR *d, const WINWCHAR *s, size_t n);
int WinWStrCmp(const WINWCHAR *a, const WINWCHAR *b);
WINWCHAR* WinWStrDupFromWinWStr(const WINWCHAR *s);
WINWCHAR* WinWStrDupFromTChar(const TCHAR *s);
WINWCHAR* WinWStrDupFromWC(const wchar_t *s);
int WinWStrToInt(const WINWCHAR *s);
#endif // ~_WIN32
WINWCHAR* WinWStrDupFromChar(const char *s, unsigned int cp);
inline WINWCHAR* WinWStrDupFromChar(const char *s) { return WinWStrDupFromChar(s, CP_ACP); }
#ifdef _UNICODE
inline WINWCHAR* WinWStrDupFromTChar(const TCHAR *s, unsigned int codepage) { return WinWStrDupFromTChar(s); }
inline WINWCHAR* WinWStrDupFromTChar(const wchar_t *s) { return WinWStrDupFromWC(s); }
inline WINWCHAR* WinWStrDupFromTChar(const wchar_t *s, unsigned int codepage) { return WinWStrDupFromTChar(s); }
#else
inline WINWCHAR* WinWStrDupFromTChar(const char *s, unsigned int cp) { return WinWStrDupFromChar(s, cp); }
inline WINWCHAR* WinWStrDupFromTChar(const char *s) { return WinWStrDupFromChar(s, CP_ACP); }
#endif
#endif // ~INC_NSIS_WINCHAR