xpcom/tests/TestUnicodeArguments.cpp

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

     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  */
     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>
    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 };
    23 int wmain(int argc, _TCHAR* argv[]) {
    24   printf("argc = %d\n", argc);
    26   if (argc != args_length + 1)
    27     return -1;
    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");
    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");
    42     if (_tcscmp(expected_utf16[i - 1], argv[i])) {
    43       return i;
    44     }
    45   }
    47   return 0;
    48 }
    49 #else
    50 #include <string.h>
    51 #include <stdio.h>
    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 };
    64 int main(int argc, char* argv[]) {
    65   if (argc != args_length + 1)
    66     return -1;
    68   for (int i = 1; i < argc; ++i) {
    69     printf("argv[%d] = %s; expected = %s\n", i, argv[i], expected_utf8[i - 1]);
    70     if (strcmp(expected_utf8[i - 1], argv[i])) {
    71       return i;
    72     }
    73   }
    75   return 0;
    76 }
    77 #endif

mercurial