From 14fcfbe1a840b6613e325eb1aaa2b868beb121d7 Mon Sep 17 00:00:00 2001 From: kichik Date: Sun, 5 Oct 2014 21:52:03 +0000 Subject: [PATCH] fixed bug #1098 so test-code works on ubuntu now git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@6545 212acab6-be3b-0410-9dea-997c60f758d6 --- Source/Tests/decompress.cpp | 2 ++ Source/Tests/winchar.cpp | 17 ++++++++++++----- Source/util.cpp | 3 ++- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/Source/Tests/decompress.cpp b/Source/Tests/decompress.cpp index dae46f52..3083ac04 100644 --- a/Source/Tests/decompress.cpp +++ b/Source/Tests/decompress.cpp @@ -12,6 +12,8 @@ #define EXEHEAD #define NSIS_CONFIG_COMPRESSION_SUPPORT +#include "../Platform.h" + extern "C" { #define NSIS_COMPRESS_USE_BZIP2 #include "../bzip2/bzlib.h" diff --git a/Source/Tests/winchar.cpp b/Source/Tests/winchar.cpp index d3516aa4..6fdb3bce 100644 --- a/Source/Tests/winchar.cpp +++ b/Source/Tests/winchar.cpp @@ -1,5 +1,6 @@ // Reviewed for Unicode support by Jim Park -- 08/13/2007 #include +#include "../util.h" #include "../winchar.h" #include @@ -12,6 +13,8 @@ // BUGBUG: WinWStrDupFromWC is unable to test WCToUTF16LEHlpr because it is behind #ifdef MAKENSIS +// TODO write equal() for WINWCHAR -- http://subcommanderblog.wordpress.com/2009/01/10/cppunit_assert_equal-and-custom-data-types/ + class WinCharTest : public CppUnit::TestFixture { CPPUNIT_TEST_SUITE( WinCharTest ); @@ -24,8 +27,12 @@ class WinCharTest : public CppUnit::TestFixture { CPPUNIT_TEST_SUITE_END(); public: + void setUp() { + NSISRT_Initialize(); + } + void testFromTchar() { - unsigned short test[] = { _x('t'), _x('e'), _x('s'), _x('t'), 0 }; + WINWCHAR test[] = { _x('t'), _x('e'), _x('s'), _x('t'), 0 }; WINWCHAR *dyn = WinWStrDupFromTChar(_T("test")); CPPUNIT_ASSERT_EQUAL( 0, memcmp(test, dyn, 5) ); @@ -44,7 +51,7 @@ public: WINWCHAR a[] = { _x('t'), _x('e'), _x('s'), _x('t'), 0 }; WINWCHAR b[5]; - CPPUNIT_ASSERT_EQUAL( b, WinWStrCpy(b, a) ); + CPPUNIT_ASSERT( !WinWStrCmp(b, WinWStrCpy(b, a)) ); CPPUNIT_ASSERT_EQUAL( 0, memcmp(a, b, 5 * sizeof(WINWCHAR)) ); } @@ -52,15 +59,15 @@ public: WINWCHAR a1[] = { _x('t'), _x('e'), _x('s'), _x('t'), 0 }; WINWCHAR b[5]; - CPPUNIT_ASSERT_EQUAL( b, WinWStrNCpy(b, a1, 5) ); + CPPUNIT_ASSERT( !WinWStrCmp(b, WinWStrNCpy(b, a1, 5)) ); CPPUNIT_ASSERT_EQUAL( 0, memcmp(a1, b, 5 * sizeof(WINWCHAR)) ); WINWCHAR a2[] = { _x('t'), _x('e'), 0, 0, 0 }; - CPPUNIT_ASSERT_EQUAL( b, WinWStrNCpy(b, a2, 5) ); + CPPUNIT_ASSERT( !WinWStrCmp(b, WinWStrNCpy(b, a2, 5)) ); CPPUNIT_ASSERT_EQUAL( 0, memcmp(a2, b, 5 * sizeof(WINWCHAR)) ); - CPPUNIT_ASSERT_EQUAL( b, WinWStrNCpy(b, a1, 2) ); + CPPUNIT_ASSERT( !WinWStrCmp(b, WinWStrNCpy(b, a1, 2)) ); CPPUNIT_ASSERT_EQUAL( 0, memcmp(a2, b, 5 * sizeof(WINWCHAR)) ); } diff --git a/Source/util.cpp b/Source/util.cpp index 461b9e4b..467d30ca 100644 --- a/Source/util.cpp +++ b/Source/util.cpp @@ -196,7 +196,7 @@ int wsprintf(TCHAR *s, const TCHAR *format, ...) { return res; } -static char g_nrt_iconv_narrowlocbuf[50], *g_nrt_iconv_narrowloc; +static char g_nrt_iconv_narrowlocbuf[50], *g_nrt_iconv_narrowloc = 0; #define setlocale_ACP(cat) setlocale((cat), "") #define iconv_ACP g_nrt_iconv_narrowloc #define setlocale_OEM(cat) NSISRT_setlocale_wincp((cat), 1252) @@ -453,6 +453,7 @@ bool nsis_iconv_reallociconv(iconv_t CD, char**In, size_t*cbInLeft, char**Mem, s const unsigned short CODEPAGESTR_MAXLEN = 50; // Should be plenty void create_code_page_string(TCHAR *buf, size_t len, UINT code_page) { + if (!g_nrt_iconv_narrowloc) NSISRT_Initialize(); // For winchar.cpp unit test switch(code_page) { case CP_ACP: _sntprintf(buf, len, _T("%") NPRINs, iconv_ACP); return;