xpcom/tests/TestTextFormatter.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.

michael@0 1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 #include <nsTextFormatter.h>
michael@0 7 #include <nsStringGlue.h>
michael@0 8 #include <stdio.h>
michael@0 9
michael@0 10 int main()
michael@0 11 {
michael@0 12 int test_ok = true;
michael@0 13
michael@0 14 nsAutoString fmt(NS_LITERAL_STRING("%3$s %4$S %1$d %2$d %2$d %3$s"));
michael@0 15 char utf8[] = "Hello";
michael@0 16 char16_t ucs2[]={'W', 'o', 'r', 'l', 'd', 0x4e00, 0xAc00, 0xFF45, 0x0103, 0x00};
michael@0 17 int d=3;
michael@0 18
michael@0 19 char16_t buf[256];
michael@0 20 nsTextFormatter::snprintf(buf, 256, fmt.get(), d, 333, utf8, ucs2);
michael@0 21 nsAutoString out(buf);
michael@0 22 if(strcmp("Hello World", NS_LossyConvertUTF16toASCII(out).get()))
michael@0 23 test_ok = false;
michael@0 24
michael@0 25 const char16_t *uout = out.get();
michael@0 26 const char16_t expected[] = {0x48, 0x65, 0x6C, 0x6C, 0x6F, 0x20,
michael@0 27 0x57, 0x6F, 0x72, 0x6C, 0x64, 0x4E00,
michael@0 28 0xAC00, 0xFF45, 0x0103, 0x20, 0x33,
michael@0 29 0x20, 0x33, 0x33, 0x33, 0x20, 0x33,
michael@0 30 0x33, 0x33, 0x20, 0x48, 0x65, 0x6C,
michael@0 31 0x6C, 0x6F};
michael@0 32 for(uint32_t i=0;i<out.Length();i++) {
michael@0 33 if(uout[i] != expected[i]) {
michael@0 34 test_ok = false;
michael@0 35 break;
michael@0 36 }
michael@0 37 }
michael@0 38 printf(test_ok? "nsTextFormatter: OK\n": "nsTextFormatter: FAIL\n");
michael@0 39 }
michael@0 40

mercurial