1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/js/src/jsapi-tests/testUTF8.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,47 @@ 1.4 +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- 1.5 + * vim: set ts=8 sts=4 et sw=4 tw=99: 1.6 + */ 1.7 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.8 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.9 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.10 + 1.11 +#include "jsapi.h" 1.12 +#include "jsstr.h" 1.13 + 1.14 +#include "js/CharacterEncoding.h" 1.15 +#include "jsapi-tests/tests.h" 1.16 + 1.17 +BEGIN_TEST(testUTF8_badUTF8) 1.18 +{ 1.19 + static const char badUTF8[] = "...\xC0..."; 1.20 + JSString *str = JS_NewStringCopyZ(cx, badUTF8); 1.21 + CHECK(str); 1.22 + const jschar *chars = JS_GetStringCharsZ(cx, str); 1.23 + CHECK(chars); 1.24 + CHECK(chars[3] == 0x00C0); 1.25 + return true; 1.26 +} 1.27 +END_TEST(testUTF8_badUTF8) 1.28 + 1.29 +BEGIN_TEST(testUTF8_bigUTF8) 1.30 +{ 1.31 + static const char bigUTF8[] = "...\xFB\xBF\xBF\xBF\xBF..."; 1.32 + JSString *str = JS_NewStringCopyZ(cx, bigUTF8); 1.33 + CHECK(str); 1.34 + const jschar *chars = JS_GetStringCharsZ(cx, str); 1.35 + CHECK(chars); 1.36 + CHECK(chars[3] == 0x00FB); 1.37 + return true; 1.38 +} 1.39 +END_TEST(testUTF8_bigUTF8) 1.40 + 1.41 +BEGIN_TEST(testUTF8_badSurrogate) 1.42 +{ 1.43 + static const jschar badSurrogate[] = { 'A', 'B', 'C', 0xDEEE, 'D', 'E', 0 }; 1.44 + JS::TwoByteChars tbchars(badSurrogate, js_strlen(badSurrogate)); 1.45 + JS::Latin1CharsZ latin1 = JS::LossyTwoByteCharsToNewLatin1CharsZ(cx, tbchars); 1.46 + CHECK(latin1); 1.47 + CHECK(latin1[3] == 0x00EE); 1.48 + return true; 1.49 +} 1.50 +END_TEST(testUTF8_badSurrogate)