Bug 1852740: add tests for the `fetchpriority` attribute in Link headers. r=necko...
[gecko.git] / js / src / jsapi-tests / testUTF8.cpp
blob599bab357e9d500996a76bb2ba978e9635c9b89e
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:
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 "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);
16 CHECK(str);
17 char16_t ch;
18 if (!JS_GetStringCharAt(cx, str, 3, &ch)) {
19 return false;
21 CHECK(ch == 0x00C0);
22 return true;
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);
29 CHECK(str);
30 char16_t ch;
31 if (!JS_GetStringCharAt(cx, str, 3, &ch)) {
32 return false;
34 CHECK(ch == 0x00FB);
35 return true;
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);
43 CHECK(latin1);
44 CHECK(latin1[3] == 0x00EE);
45 return true;
47 END_TEST(testUTF8_badSurrogate)