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

@ -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);
}
};