js/src/jsapi-tests/testUTF8.cpp

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
     2  * vim: set ts=8 sts=4 et sw=4 tw=99:
     3  */
     4 /* This Source Code Form is subject to the terms of the Mozilla Public
     5  * License, v. 2.0. If a copy of the MPL was not distributed with this
     6  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     8 #include "jsapi.h"
     9 #include "jsstr.h"
    11 #include "js/CharacterEncoding.h"
    12 #include "jsapi-tests/tests.h"
    14 BEGIN_TEST(testUTF8_badUTF8)
    15 {
    16     static const char badUTF8[] = "...\xC0...";
    17     JSString *str = JS_NewStringCopyZ(cx, badUTF8);
    18     CHECK(str);
    19     const jschar *chars = JS_GetStringCharsZ(cx, str);
    20     CHECK(chars);
    21     CHECK(chars[3] == 0x00C0);
    22     return true;
    23 }
    24 END_TEST(testUTF8_badUTF8)
    26 BEGIN_TEST(testUTF8_bigUTF8)
    27 {
    28     static const char bigUTF8[] = "...\xFB\xBF\xBF\xBF\xBF...";
    29     JSString *str = JS_NewStringCopyZ(cx, bigUTF8);
    30     CHECK(str);
    31     const jschar *chars = JS_GetStringCharsZ(cx, str);
    32     CHECK(chars);
    33     CHECK(chars[3] == 0x00FB);
    34     return true;
    35 }
    36 END_TEST(testUTF8_bigUTF8)
    38 BEGIN_TEST(testUTF8_badSurrogate)
    39 {
    40     static const jschar badSurrogate[] = { 'A', 'B', 'C', 0xDEEE, 'D', 'E', 0 };
    41     JS::TwoByteChars tbchars(badSurrogate, js_strlen(badSurrogate));
    42     JS::Latin1CharsZ latin1 = JS::LossyTwoByteCharsToNewLatin1CharsZ(cx, tbchars);
    43     CHECK(latin1);
    44     CHECK(latin1[3] == 0x00EE);
    45     return true;
    46 }
    47 END_TEST(testUTF8_badSurrogate)

mercurial