1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/xpcom/tests/TestUnicodeArguments.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,77 @@ 1.4 +/** 1.5 + * On Windows, a Unicode argument is passed as UTF-16 using ShellExecuteExW. 1.6 + * On other platforms, it is passed as UTF-8 1.7 + */ 1.8 + 1.9 +static const int args_length = 4; 1.10 +#if defined(XP_WIN) && defined(_MSC_VER) 1.11 +#define _UNICODE 1.12 +#include <tchar.h> 1.13 +#include <stdio.h> 1.14 + 1.15 +static const _TCHAR* expected_utf16[args_length] = { 1.16 + // Latin-1 1.17 + L"M\xF8z\xEEll\xE5", 1.18 + // Cyrillic 1.19 + L"\x41C\x43E\x437\x438\x43B\x43B\x430", 1.20 + // Bengali 1.21 + L"\x9AE\x9CB\x99C\x9BF\x9B2\x9BE", 1.22 + // Cuneiform 1.23 + L"\xD808\xDE2C\xD808\xDF63\xD808\xDDB7" 1.24 +}; 1.25 + 1.26 +int wmain(int argc, _TCHAR* argv[]) { 1.27 + printf("argc = %d\n", argc); 1.28 + 1.29 + if (argc != args_length + 1) 1.30 + return -1; 1.31 + 1.32 + for (int i = 1; i < argc; ++i) { 1.33 + printf("expected[%d]: ", i - 1); 1.34 + for (size_t j = 0; j < _tcslen(expected_utf16[i - 1]); ++j) { 1.35 + printf("%x ", *(expected_utf16[i - 1] + j)); 1.36 + } 1.37 + printf("\n"); 1.38 + 1.39 + printf("argv[%d]: ", i); 1.40 + for (size_t j = 0; j < _tcslen(argv[i]); ++j) { 1.41 + printf("%x ", *(argv[i] + j)); 1.42 + } 1.43 + printf("\n"); 1.44 + 1.45 + if (_tcscmp(expected_utf16[i - 1], argv[i])) { 1.46 + return i; 1.47 + } 1.48 + } 1.49 + 1.50 + return 0; 1.51 +} 1.52 +#else 1.53 +#include <string.h> 1.54 +#include <stdio.h> 1.55 + 1.56 +static const char* expected_utf8[args_length] = { 1.57 + // Latin-1 1.58 + "M\xC3\xB8z\xC3\xAEll\xC3\xA5", 1.59 + // Cyrillic 1.60 + "\xD0\x9C\xD0\xBE\xD0\xB7\xD0\xB8\xD0\xBB\xD0\xBB\xD0\xB0", 1.61 + // Bengali 1.62 + "\xE0\xA6\xAE\xE0\xA7\x8B\xE0\xA6\x9C\xE0\xA6\xBF\xE0\xA6\xB2\xE0\xA6\xBE", 1.63 + // Cuneiform 1.64 + "\xF0\x92\x88\xAC\xF0\x92\x8D\xA3\xF0\x92\x86\xB7" 1.65 +}; 1.66 + 1.67 +int main(int argc, char* argv[]) { 1.68 + if (argc != args_length + 1) 1.69 + return -1; 1.70 + 1.71 + for (int i = 1; i < argc; ++i) { 1.72 + printf("argv[%d] = %s; expected = %s\n", i, argv[i], expected_utf8[i - 1]); 1.73 + if (strcmp(expected_utf8[i - 1], argv[i])) { 1.74 + return i; 1.75 + } 1.76 + } 1.77 + 1.78 + return 0; 1.79 +} 1.80 +#endif