mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-14 13:55:43 +00:00
Backed out 2 changesets (bug 1126301) on a CLOSED TREE because the test was apparently busted on some platforms
Backed out changeset 4aecd46afeb1 (bug 1126301) Backed out changeset c61a87a20888 (bug 1126301) --HG-- rename : xpcom/tests/gtest/TestUTF.cpp => xpcom/tests/TestUTF.cpp
This commit is contained in:
parent
f27da06422
commit
39a6fe9c60
189
xpcom/tests/TestUTF.cpp
Normal file
189
xpcom/tests/TestUTF.cpp
Normal file
@ -0,0 +1,189 @@
|
||||
/* 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/. */
|
||||
|
||||
#include "mozilla/ArrayUtils.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "nsString.h"
|
||||
#include "nsStringBuffer.h"
|
||||
#include "nsReadableUtils.h"
|
||||
#include "UTFStrings.h"
|
||||
#include "nsUnicharUtils.h"
|
||||
#include "mozilla/HashFunctions.h"
|
||||
|
||||
using namespace mozilla;
|
||||
|
||||
namespace TestUTF {
|
||||
|
||||
bool
|
||||
test_valid()
|
||||
{
|
||||
for (unsigned int i = 0; i < ArrayLength(ValidStrings); ++i) {
|
||||
nsDependentCString str8(ValidStrings[i].m8);
|
||||
nsDependentString str16(ValidStrings[i].m16);
|
||||
|
||||
if (!NS_ConvertUTF16toUTF8(str16).Equals(str8))
|
||||
return false;
|
||||
|
||||
if (!NS_ConvertUTF8toUTF16(str8).Equals(str16))
|
||||
return false;
|
||||
|
||||
nsCString tmp8("string ");
|
||||
AppendUTF16toUTF8(str16, tmp8);
|
||||
if (!tmp8.Equals(NS_LITERAL_CSTRING("string ") + str8))
|
||||
return false;
|
||||
|
||||
nsString tmp16(NS_LITERAL_STRING("string "));
|
||||
AppendUTF8toUTF16(str8, tmp16);
|
||||
if (!tmp16.Equals(NS_LITERAL_STRING("string ") + str16))
|
||||
return false;
|
||||
|
||||
if (CompareUTF8toUTF16(str8, str16) != 0)
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
test_invalid16()
|
||||
{
|
||||
for (unsigned int i = 0; i < ArrayLength(Invalid16Strings); ++i) {
|
||||
nsDependentString str16(Invalid16Strings[i].m16);
|
||||
nsDependentCString str8(Invalid16Strings[i].m8);
|
||||
|
||||
if (!NS_ConvertUTF16toUTF8(str16).Equals(str8))
|
||||
return false;
|
||||
|
||||
nsCString tmp8("string ");
|
||||
AppendUTF16toUTF8(str16, tmp8);
|
||||
if (!tmp8.Equals(NS_LITERAL_CSTRING("string ") + str8))
|
||||
return false;
|
||||
|
||||
if (CompareUTF8toUTF16(str8, str16) != 0)
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
test_invalid8()
|
||||
{
|
||||
for (unsigned int i = 0; i < ArrayLength(Invalid8Strings); ++i) {
|
||||
nsDependentString str16(Invalid8Strings[i].m16);
|
||||
nsDependentCString str8(Invalid8Strings[i].m8);
|
||||
|
||||
if (!NS_ConvertUTF8toUTF16(str8).Equals(str16))
|
||||
return false;
|
||||
|
||||
nsString tmp16(NS_LITERAL_STRING("string "));
|
||||
AppendUTF8toUTF16(str8, tmp16);
|
||||
if (!tmp16.Equals(NS_LITERAL_STRING("string ") + str16))
|
||||
return false;
|
||||
|
||||
if (CompareUTF8toUTF16(str8, str16) != 0)
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
test_malformed8()
|
||||
{
|
||||
// Don't run this test in debug builds as that intentionally asserts.
|
||||
#ifndef DEBUG
|
||||
for (unsigned int i = 0; i < ArrayLength(Malformed8Strings); ++i) {
|
||||
nsDependentCString str8(Malformed8Strings[i]);
|
||||
|
||||
if (!NS_ConvertUTF8toUTF16(str8).IsEmpty())
|
||||
return false;
|
||||
|
||||
nsString tmp16(NS_LITERAL_STRING("string"));
|
||||
AppendUTF8toUTF16(str8, tmp16);
|
||||
if (!tmp16.EqualsLiteral("string"))
|
||||
return false;
|
||||
|
||||
if (CompareUTF8toUTF16(str8, EmptyString()) == 0)
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
test_hashas16()
|
||||
{
|
||||
for (unsigned int i = 0; i < ArrayLength(ValidStrings); ++i) {
|
||||
nsDependentCString str8(ValidStrings[i].m8);
|
||||
bool err;
|
||||
if (HashString(ValidStrings[i].m16) !=
|
||||
HashUTF8AsUTF16(str8.get(), str8.Length(), &err) ||
|
||||
err)
|
||||
return false;
|
||||
}
|
||||
|
||||
for (unsigned int i = 0; i < ArrayLength(Invalid8Strings); ++i) {
|
||||
nsDependentCString str8(Invalid8Strings[i].m8);
|
||||
bool err;
|
||||
if (HashString(Invalid8Strings[i].m16) !=
|
||||
HashUTF8AsUTF16(str8.get(), str8.Length(), &err) ||
|
||||
err)
|
||||
return false;
|
||||
}
|
||||
|
||||
// Don't run this test in debug builds as that intentionally asserts.
|
||||
#ifndef DEBUG
|
||||
for (unsigned int i = 0; i < ArrayLength(Malformed8Strings); ++i) {
|
||||
nsDependentCString str8(Malformed8Strings[i]);
|
||||
bool err;
|
||||
if (HashUTF8AsUTF16(str8.get(), str8.Length(), &err) != 0 ||
|
||||
!err)
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
typedef bool (*TestFunc)();
|
||||
|
||||
static const struct Test
|
||||
{
|
||||
const char* name;
|
||||
TestFunc func;
|
||||
}
|
||||
tests[] =
|
||||
{
|
||||
{ "test_valid", test_valid },
|
||||
{ "test_invalid16", test_invalid16 },
|
||||
{ "test_invalid8", test_invalid8 },
|
||||
{ "test_malformed8", test_malformed8 },
|
||||
{ "test_hashas16", test_hashas16 },
|
||||
{ nullptr, nullptr }
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
using namespace TestUTF;
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int count = 1;
|
||||
if (argc > 1)
|
||||
count = atoi(argv[1]);
|
||||
|
||||
while (count--)
|
||||
{
|
||||
for (const Test* t = tests; t->name != nullptr; ++t)
|
||||
{
|
||||
printf("%25s : %s\n", t->name, t->func() ? "SUCCESS" : "FAILURE <--");
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
@ -1,123 +0,0 @@
|
||||
/* 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/. */
|
||||
|
||||
#include "mozilla/ArrayUtils.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "nsString.h"
|
||||
#include "nsStringBuffer.h"
|
||||
#include "nsReadableUtils.h"
|
||||
#include "UTFStrings.h"
|
||||
#include "nsUnicharUtils.h"
|
||||
#include "mozilla/HashFunctions.h"
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
using namespace mozilla;
|
||||
|
||||
namespace TestUTF {
|
||||
|
||||
TEST(UTF, Valid)
|
||||
{
|
||||
for (unsigned int i = 0; i < ArrayLength(ValidStrings); ++i) {
|
||||
nsDependentCString str8(ValidStrings[i].m8);
|
||||
nsDependentString str16(ValidStrings[i].m16);
|
||||
|
||||
EXPECT_TRUE(NS_ConvertUTF16toUTF8(str16).Equals(str8));
|
||||
|
||||
EXPECT_TRUE(NS_ConvertUTF8toUTF16(str8).Equals(str16));
|
||||
|
||||
nsCString tmp8("string ");
|
||||
AppendUTF16toUTF8(str16, tmp8);
|
||||
EXPECT_TRUE(tmp8.Equals(NS_LITERAL_CSTRING("string ") + str8));
|
||||
|
||||
nsString tmp16(NS_LITERAL_STRING("string "));
|
||||
AppendUTF8toUTF16(str8, tmp16);
|
||||
EXPECT_TRUE(tmp16.Equals(NS_LITERAL_STRING("string ") + str16));
|
||||
|
||||
EXPECT_EQ(CompareUTF8toUTF16(str8, str16), 0);
|
||||
}
|
||||
}
|
||||
|
||||
TEST(UTF, Invalid16)
|
||||
{
|
||||
for (unsigned int i = 0; i < ArrayLength(Invalid16Strings); ++i) {
|
||||
nsDependentString str16(Invalid16Strings[i].m16);
|
||||
nsDependentCString str8(Invalid16Strings[i].m8);
|
||||
|
||||
EXPECT_TRUE(NS_ConvertUTF16toUTF8(str16).Equals(str8));
|
||||
|
||||
nsCString tmp8("string ");
|
||||
AppendUTF16toUTF8(str16, tmp8);
|
||||
EXPECT_TRUE(tmp8.Equals(NS_LITERAL_CSTRING("string ") + str8));
|
||||
|
||||
EXPECT_EQ(CompareUTF8toUTF16(str8, str16), 0);
|
||||
}
|
||||
}
|
||||
|
||||
TEST(UTF, Invalid8)
|
||||
{
|
||||
for (unsigned int i = 0; i < ArrayLength(Invalid8Strings); ++i) {
|
||||
nsDependentString str16(Invalid8Strings[i].m16);
|
||||
nsDependentCString str8(Invalid8Strings[i].m8);
|
||||
|
||||
EXPECT_TRUE(NS_ConvertUTF8toUTF16(str8).Equals(str16));
|
||||
|
||||
nsString tmp16(NS_LITERAL_STRING("string "));
|
||||
AppendUTF8toUTF16(str8, tmp16);
|
||||
EXPECT_TRUE(tmp16.Equals(NS_LITERAL_STRING("string ") + str16));
|
||||
|
||||
EXPECT_EQ(CompareUTF8toUTF16(str8, str16), 0);
|
||||
}
|
||||
}
|
||||
|
||||
TEST(UTF, Malformed8)
|
||||
{
|
||||
// Don't run this test in debug builds as that intentionally asserts.
|
||||
#ifndef DEBUG
|
||||
for (unsigned int i = 0; i < ArrayLength(Malformed8Strings); ++i) {
|
||||
nsDependentCString str8(Malformed8Strings[i]);
|
||||
|
||||
EXPECT_TRUE(NS_ConvertUTF8toUTF16(str8).IsEmpty());
|
||||
|
||||
nsString tmp16(NS_LITERAL_STRING("string"));
|
||||
AppendUTF8toUTF16(str8, tmp16);
|
||||
EXPECT_TRUE(tmp16.EqualsLiteral("string"));
|
||||
|
||||
EXPECT_NE(CompareUTF8toUTF16(str8, EmptyString()), 0);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
TEST(UTF, Hash16)
|
||||
{
|
||||
for (unsigned int i = 0; i < ArrayLength(ValidStrings); ++i) {
|
||||
nsDependentCString str8(ValidStrings[i].m8);
|
||||
bool err;
|
||||
EXPECT_EQ(HashString(ValidStrings[i].m16),
|
||||
HashUTF8AsUTF16(str8.get(), str8.Length(), &err));
|
||||
EXPECT_FALSE(err);
|
||||
}
|
||||
|
||||
for (unsigned int i = 0; i < ArrayLength(Invalid8Strings); ++i) {
|
||||
nsDependentCString str8(Invalid8Strings[i].m8);
|
||||
bool err;
|
||||
EXPECT_EQ(HashString(Invalid8Strings[i].m16),
|
||||
HashUTF8AsUTF16(str8.get(), str8.Length(), &err));
|
||||
EXPECT_FALSE(err);
|
||||
}
|
||||
|
||||
// Don't run this test in debug builds as that intentionally asserts.
|
||||
#ifndef DEBUG
|
||||
for (unsigned int i = 0; i < ArrayLength(Malformed8Strings); ++i) {
|
||||
nsDependentCString str8(Malformed8Strings[i]);
|
||||
bool err;
|
||||
EXPECT_EQ(HashUTF8AsUTF16(str8.get(), str8.Length(), &err), 0u);
|
||||
EXPECT_FALSE(err);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
}
|
@ -17,7 +17,6 @@ UNIFIED_SOURCES += [
|
||||
'TestSynchronization.cpp',
|
||||
'TestThreadPool.cpp',
|
||||
'TestTimeStamp.cpp',
|
||||
'TestUTF.cpp',
|
||||
]
|
||||
|
||||
FINAL_LIBRARY = 'xul-gtest'
|
||||
|
@ -82,6 +82,7 @@ if CONFIG['MOZ_MEMORY']:
|
||||
#CPP_UNIT_TESTS += [
|
||||
# 'TestThreads',
|
||||
# 'TestXPIDLString',
|
||||
# 'TestUTF',
|
||||
#]
|
||||
|
||||
# FIXME: bug 577500 TestStaticAtoms fails when run in dist/bin
|
||||
|
Loading…
Reference in New Issue
Block a user