/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* vim: set ts=8 sts=2 et sw=2 tw=80: */ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
TEST(Encoding, GoodSurrogatePair)
{ // When this string is decoded, the surrogate pair is U+10302 and the rest of // the string is specified by indexes 2 onward. const char16_t goodPairData[] = {0xD800, 0xDF02, 0x65, 0x78, 0x0};
nsDependentString goodPair16(goodPairData);
// This takes a different code path from the above, so test it to make sure // the UTF-16 enumeration remains in sync with the UTF-8 enumeration.
nsDependentCString expected((constchar*)expected8);
EXPECT_EQ(0, CompareUTF8toUTF16(expected, goodPair16));
free(goodPair8);
}
TEST(Encoding, BackwardsSurrogatePair)
{ // When this string is decoded, the two surrogates are wrongly ordered and // must each be interpreted as U+FFFD. const char16_t backwardsPairData[] = {0xDDDD, 0xD863, 0x65, 0x78, 0x0};
nsDependentString backwardsPair16(backwardsPairData);
// This takes a different code path from the above, so test it to make sure // the UTF-16 enumeration remains in sync with the UTF-8 enumeration.
nsDependentCString expected((constchar*)expected8);
EXPECT_EQ(0, CompareUTF8toUTF16(expected, backwardsPair16));
free(backwardsPair8);
}
TEST(Encoding, MalformedUTF16OrphanHighSurrogate)
{ // When this string is decoded, the high surrogate should be replaced and the // rest of the string is specified by indexes 1 onward. const char16_t highSurrogateData[] = {0xD863, 0x74, 0x65, 0x78, 0x74, 0x0};
nsDependentString highSurrogate16(highSurrogateData);
// This takes a different code path from the above, so test it to make sure // the UTF-16 enumeration remains in sync with the UTF-8 enumeration.
nsDependentCString expected((constchar*)expected8);
EXPECT_EQ(0, CompareUTF8toUTF16(expected, highSurrogate16));
free(highSurrogate8);
}
TEST(Encoding, MalformedUTF16OrphanLowSurrogate)
{ // When this string is decoded, the low surrogate should be replaced and the // rest of the string is specified by indexes 1 onward. const char16_t lowSurrogateData[] = {0xDDDD, 0x74, 0x65, 0x78, 0x74, 0x0};
nsDependentString lowSurrogate16(lowSurrogateData);
// This takes a different code path from the above, so test it to make sure // the UTF-16 enumeration remains in sync with the UTF-8 enumeration.
nsDependentCString expected((constchar*)expected8);
EXPECT_EQ(0, CompareUTF8toUTF16(expected, lowSurrogate16));
free(lowSurrogate8);
}
¤ Dauer der Verarbeitung: 0.19 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.