1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 * vim: set ts=8 sts=2 et sw=2 tw=80:
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 "mozilla/Range.h"
10 #include "js/CharacterEncoding.h"
11 #include "jsapi-tests/tests.h"
13 BEGIN_TEST(testUTF8_badUTF8
) {
14 static const char badUTF8
[] = "...\xC0...";
15 JSString
* str
= JS_NewStringCopyZ(cx
, badUTF8
);
18 if (!JS_GetStringCharAt(cx
, str
, 3, &ch
)) {
24 END_TEST(testUTF8_badUTF8
)
26 BEGIN_TEST(testUTF8_bigUTF8
) {
27 static const char bigUTF8
[] = "...\xFB\xBF\xBF\xBF\xBF...";
28 JSString
* str
= JS_NewStringCopyZ(cx
, bigUTF8
);
31 if (!JS_GetStringCharAt(cx
, str
, 3, &ch
)) {
37 END_TEST(testUTF8_bigUTF8
)
39 BEGIN_TEST(testUTF8_badSurrogate
) {
40 static const char16_t badSurrogate
[] = {'A', 'B', 'C', 0xDEEE, 'D', 'E', 0};
41 mozilla::Range
<const char16_t
> tbchars(badSurrogate
, js_strlen(badSurrogate
));
42 JS::Latin1CharsZ latin1
= JS::LossyTwoByteCharsToNewLatin1CharsZ(cx
, tbchars
);
44 CHECK(latin1
[3] == 0x00EE);
47 END_TEST(testUTF8_badSurrogate
)