1 : /**
2 : * On Windows, a Unicode argument is passed as UTF-16 using ShellExecuteExW.
3 : * On other platforms, it is passed as UTF-8
4 : */
5 :
6 : static const int args_length = 4;
7 : #if defined(XP_WIN) && defined(_MSC_VER)
8 : #define _UNICODE
9 : #include <tchar.h>
10 : #include <stdio.h>
11 :
12 : static const _TCHAR* expected_utf16[args_length] = {
13 : // Latin-1
14 : L"M\xF8z\xEEll\xE5",
15 : // Cyrillic
16 : L"\x41C\x43E\x437\x438\x43B\x43B\x430",
17 : // Bengali
18 : L"\x9AE\x9CB\x99C\x9BF\x9B2\x9BE",
19 : // Cuneiform
20 : L"\xD808\xDE2C\xD808\xDF63\xD808\xDDB7"
21 : };
22 :
23 : int wmain(int argc, _TCHAR* argv[]) {
24 : printf("argc = %d\n", argc);
25 :
26 : if (argc != args_length + 1)
27 : return -1;
28 :
29 : for (int i = 1; i < argc; ++i) {
30 : printf("expected[%d]: ", i - 1);
31 : for (size_t j = 0; j < _tcslen(expected_utf16[i - 1]); ++j) {
32 : printf("%x ", *(expected_utf16[i - 1] + j));
33 : }
34 : printf("\n");
35 :
36 : printf("argv[%d]: ", i);
37 : for (size_t j = 0; j < _tcslen(argv[i]); ++j) {
38 : printf("%x ", *(argv[i] + j));
39 : }
40 : printf("\n");
41 :
42 : if (_tcscmp(expected_utf16[i - 1], argv[i])) {
43 : return i;
44 : }
45 : }
46 :
47 : return 0;
48 : }
49 : #else
50 : #include <string.h>
51 : #include <stdio.h>
52 :
53 : static const char* expected_utf8[args_length] = {
54 : // Latin-1
55 : "M\xC3\xB8z\xC3\xAEll\xC3\xA5",
56 : // Cyrillic
57 : "\xD0\x9C\xD0\xBE\xD0\xB7\xD0\xB8\xD0\xBB\xD0\xBB\xD0\xB0",
58 : // Bengali
59 : "\xE0\xA6\xAE\xE0\xA7\x8B\xE0\xA6\x9C\xE0\xA6\xBF\xE0\xA6\xB2\xE0\xA6\xBE",
60 : // Cuneiform
61 : "\xF0\x92\x88\xAC\xF0\x92\x8D\xA3\xF0\x92\x86\xB7"
62 : };
63 :
64 2 : int main(int argc, char* argv[]) {
65 2 : if (argc != args_length + 1)
66 0 : return -1;
67 :
68 10 : for (int i = 1; i < argc; ++i) {
69 8 : printf("argv[%d] = %s; expected = %s\n", i, argv[i], expected_utf8[i - 1]);
70 8 : if (strcmp(expected_utf8[i - 1], argv[i])) {
71 0 : return i;
72 : }
73 : }
74 :
75 2 : return 0;
76 : }
77 : #endif
|