diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index cec7345..d41b865 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -193,41 +193,81 @@ endif () # -# test_exchndl +# test_exchndl_static_unicode # include_directories ( ${CMAKE_CURRENT_SOURCE_DIR}/apps ) -add_executable (test_exchndl_static - test_exchndl_static.cpp +add_executable (test_exchndl_static_unicode + test_exchndl_static_unicode.cpp ) -add_dependencies (test_exchndl_static exchndl_implib) -target_link_libraries (test_exchndl_static ${EXCHNDL_IMPLIB} shlwapi) -add_dependencies (check test_exchndl_static) +add_dependencies (test_exchndl_static_unicode exchndl_implib) +target_link_libraries (test_exchndl_static_unicode ${EXCHNDL_IMPLIB} shlwapi) +add_dependencies (check test_exchndl_static_unicode) add_test ( - NAME test_exchndl_static - COMMAND test_exchndl_static + NAME test_exchndl_static_unicode + COMMAND test_exchndl_static_unicode WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ) # -# test_exchndl +# test_exchndl_static_ansi # include_directories ( ${CMAKE_CURRENT_SOURCE_DIR}/apps ) -add_executable (test_exchndl_dynamic - test_exchndl_dynamic.cpp +add_executable (test_exchndl_static_ansi + test_exchndl_static_ansi.cpp ) -target_link_libraries (test_exchndl_dynamic shlwapi) -add_dependencies (test_exchndl_dynamic exchndl) -add_dependencies (check test_exchndl_dynamic) +add_dependencies (test_exchndl_static_ansi exchndl_implib) +target_link_libraries (test_exchndl_static_ansi ${EXCHNDL_IMPLIB} shlwapi) +add_dependencies (check test_exchndl_static_ansi) add_test ( - NAME test_exchndl_dynamic - COMMAND test_exchndl_dynamic + NAME test_exchndl_static_ansi + COMMAND test_exchndl_static_ansi + WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} +) + + +# +# test_exchndl_dynamic_unicode +# + +include_directories ( + ${CMAKE_CURRENT_SOURCE_DIR}/apps +) +add_executable (test_exchndl_dynamic_unicode + test_exchndl_dynamic_unicode.cpp +) +target_link_libraries (test_exchndl_dynamic_unicode shlwapi) +add_dependencies (test_exchndl_dynamic_unicode exchndl) +add_dependencies (check test_exchndl_dynamic_unicode) +add_test ( + NAME test_exchndl_dynamic_unicode + COMMAND test_exchndl_dynamic_unicode + WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} +) + + +# +# test_exchndl_dynamic_ansi +# + +include_directories ( + ${CMAKE_CURRENT_SOURCE_DIR}/apps +) +add_executable (test_exchndl_dynamic_ansi + test_exchndl_dynamic_ansi.cpp +) +target_link_libraries (test_exchndl_dynamic_ansi shlwapi) +add_dependencies (test_exchndl_dynamic_ansi exchndl) +add_dependencies (check test_exchndl_dynamic_ansi) +add_test ( + NAME test_exchndl_dynamic_ansi + COMMAND test_exchndl_dynamic_ansi WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ) diff --git a/tests/apps/macros.h b/tests/apps/macros.h index b4ec945..93a15b1 100644 --- a/tests/apps/macros.h +++ b/tests/apps/macros.h @@ -42,3 +42,10 @@ #else #error Unsupported compiler #endif + + +// Define WFILE as a wide-character variant of __FILE__ +// See https://stackoverflow.com/a/14421702/1708371 +#define WIDE2(x) L##x +#define WIDE1(x) WIDE2(x) +#define WFILE WIDE1(__FILE__) diff --git a/tests/test_exchndl.h b/tests/test_exchndl.h index 37e8258..4233c4c 100644 --- a/tests/test_exchndl.h +++ b/tests/test_exchndl.h @@ -79,9 +79,16 @@ main(int argc, char **argv) { bool ok; +#if !TEST_UNICODE const char *szReport = PROG_NAME ".RPT"; DeleteFileA(szReport); +#else + // Add additional unicode wide characters to the name to test this behavior + const WCHAR *szReport = PROG_NAME L"_ぬるぽ.RPT"; + + DeleteFileW(szReport); +#endif // !TEST_UNICODE g_prevExceptionFilter = SetUnhandledExceptionFilter(topLevelExceptionHandler); @@ -89,8 +96,13 @@ main(int argc, char **argv) ExcHndlInit(); +#if !TEST_UNICODE ok = ExcHndlSetLogFileNameA(szReport); test_line(ok, "ExcHndlSetLogFileNameA(\"%s\")", szReport); +#else + ok = ExcHndlSetLogFileNameW(szReport); + test_line(ok, "ExcHndlSetLogFileNameW(\"%S\")", szReport); +#endif // !TEST_UNICODE #else @@ -102,9 +114,10 @@ main(int argc, char **argv) test_exit(); } +#if !TEST_UNICODE test_line(!GetProcAddress(hModule, "ExcHndlSetLogFileNameA@4"), "!GetProcAddress(\"ExcHndlSetLogFileNameA@4\")"); - typedef BOOL (APIENTRY * PFN_SETLOGFILENAMEA)(const char *szLogFileName); + typedef BOOL (APIENTRY * PFN_SETLOGFILENAMEA)(const char *pszLogFileName); PFN_SETLOGFILENAMEA pfnSetLogFileNameA = (PFN_SETLOGFILENAMEA)GetProcAddress(hModule, "ExcHndlSetLogFileNameA"); ok = pfnSetLogFileNameA != NULL; test_line(ok, "GetProcAddress(\"ExcHndlSetLogFileNameA\")"); @@ -115,14 +128,34 @@ main(int argc, char **argv) ok = pfnSetLogFileNameA(szReport); test_line(ok, "ExcHndlSetLogFileNameA(\"%s\")", szReport); +#else + test_line(!GetProcAddress(hModule, "ExcHndlSetLogFileNameW@5"), "!GetProcAddress(\"ExcHndlSetLogFileNameW@5\")"); -#endif + typedef BOOL (APIENTRY * PFN_SETLOGFILENAMEW)(const WCHAR *pszLogFileName); + PFN_SETLOGFILENAMEW pfnSetLogFileNameW = (PFN_SETLOGFILENAMEW)GetProcAddress(hModule, "ExcHndlSetLogFileNameW"); + ok = pfnSetLogFileNameW != NULL; + test_line(ok, "GetProcAddress(\"ExcHndlSetLogFileNameW\")"); + if (!ok) { + test_diagnostic_last_error(); + test_exit(); + } + + ok = pfnSetLogFileNameW(szReport); + test_line(ok, "ExcHndlSetLogFileNameW(\"%S\")", szReport); +#endif // !TEST_UNICODE + +#endif // !DYNAMIC _snprintf(g_szExceptionFunctionPattern, sizeof g_szExceptionFunctionPattern, " %s!%s+0x", PROG_NAME ".exe", __FUNCTION__); if (!setjmp(g_JmpBuf) ) { +#if !TEST_UNICODE _snprintf(g_szExceptionLinePattern, sizeof g_szExceptionLinePattern, "%s @ %u]", PathFindFileNameA(__FILE__), __LINE__); *((volatile int *)0) = 0; LINE_BARRIER +#else + _snprintf(g_szExceptionLinePattern, sizeof g_szExceptionLinePattern, "%S @ %u]", + PathFindFileNameW(WFILE), __LINE__); *((volatile int *)0) = 0; LINE_BARRIER +#endif // !TEST_UNICODE test_line(false, "longjmp"); exit(1); } else { test_line(true, "longjmp"); @@ -131,9 +164,15 @@ main(int argc, char **argv) normalizePath(g_szExceptionFunctionPattern); normalizePath(g_szExceptionLinePattern); +#if !TEST_UNICODE FILE *fp = fopen(szReport, "rt"); ok = fp != NULL; test_line(ok, "fopen(\"%s\")", szReport); +#else + FILE *fp = _wfopen(szReport, L"rt"); + ok = fp != NULL; + test_line(ok, "_wfopen(\"%S\")", szReport); +#endif // !TEST_UNICODE if (ok) { const unsigned nPatterns = _countof(g_szPatterns); bool found[nPatterns]; diff --git a/tests/test_exchndl_dynamic.cpp b/tests/test_exchndl_dynamic_ansi.cpp similarity index 91% rename from tests/test_exchndl_dynamic.cpp rename to tests/test_exchndl_dynamic_ansi.cpp index 5539059..ffdf2c9 100644 --- a/tests/test_exchndl_dynamic.cpp +++ b/tests/test_exchndl_dynamic_ansi.cpp @@ -17,7 +17,8 @@ */ -#define PROG_NAME "test_exchndl_dynamic" +#define PROG_NAME "test_exchndl_dynamic_ansi" #define DYNAMIC 1 +#define TEST_UNICODE 0 #include "test_exchndl.h" diff --git a/tests/test_exchndl_dynamic_unicode.cpp b/tests/test_exchndl_dynamic_unicode.cpp new file mode 100644 index 0000000..8ab5542 --- /dev/null +++ b/tests/test_exchndl_dynamic_unicode.cpp @@ -0,0 +1,24 @@ +/* + * Copyright 2015 Jose Fonseca + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + + +#define PROG_NAME "test_exchndl_dynamic_unicode" +#define DYNAMIC 1 +#define TEST_UNICODE 1 + +#include "test_exchndl.h" diff --git a/tests/test_exchndl_static.cpp b/tests/test_exchndl_static_ansi.cpp similarity index 92% rename from tests/test_exchndl_static.cpp rename to tests/test_exchndl_static_ansi.cpp index 298559a..b0069b5 100644 --- a/tests/test_exchndl_static.cpp +++ b/tests/test_exchndl_static_ansi.cpp @@ -17,7 +17,8 @@ */ -#define PROG_NAME "test_exchndl_static" +#define PROG_NAME "test_exchndl_static_ansi" #define DYNAMIC 0 +#define TEST_UNICODE 0 #include "test_exchndl.h" diff --git a/tests/test_exchndl_static_unicode.cpp b/tests/test_exchndl_static_unicode.cpp new file mode 100644 index 0000000..98a7980 --- /dev/null +++ b/tests/test_exchndl_static_unicode.cpp @@ -0,0 +1,24 @@ +/* + * Copyright 2015 Jose Fonseca + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + + +#define PROG_NAME "test_exchndl_static_unicode" +#define DYNAMIC 0 +#define TEST_UNICODE 1 + +#include "test_exchndl.h"