summaryrefslogtreecommitdiffstats
path: root/intl/gtest
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 14:29:10 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 14:29:10 +0000
commit2aa4a82499d4becd2284cdb482213d541b8804dd (patch)
treeb80bf8bf13c3766139fbacc530efd0dd9d54394c /intl/gtest
parentInitial commit. (diff)
downloadfirefox-2aa4a82499d4becd2284cdb482213d541b8804dd.tar.xz
firefox-2aa4a82499d4becd2284cdb482213d541b8804dd.zip
Adding upstream version 86.0.1.upstream/86.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'intl/gtest')
-rw-r--r--intl/gtest/TestEncoding.cpp64
-rw-r--r--intl/gtest/moz.build13
2 files changed, 77 insertions, 0 deletions
diff --git a/intl/gtest/TestEncoding.cpp b/intl/gtest/TestEncoding.cpp
new file mode 100644
index 0000000000..e6be8e56ee
--- /dev/null
+++ b/intl/gtest/TestEncoding.cpp
@@ -0,0 +1,64 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+
+#include "gtest/gtest.h"
+
+#include "mozilla/Encoding.h"
+#include <type_traits>
+
+#define ENCODING_TEST(name) TEST(EncodingTest, name)
+
+using namespace mozilla;
+
+static_assert(std::is_standard_layout<NotNull<const Encoding*>>::value,
+ "NotNull<const Encoding*> must be a standard layout type.");
+
+// These tests mainly test that the C++ interface seems to
+// reach the Rust code. More thorough testing of the back
+// end is done in Rust.
+
+ENCODING_TEST(ForLabel) {
+ nsAutoCString label(" uTf-8 ");
+ ASSERT_EQ(Encoding::ForLabel(label), UTF_8_ENCODING);
+ label.AssignLiteral(" cseucpkdfmTjapanese ");
+ ASSERT_EQ(Encoding::ForLabel(label), EUC_JP_ENCODING);
+}
+
+ENCODING_TEST(ForBOM) {
+ nsAutoCString data("\xEF\xBB\xBF\x61");
+ const Encoding* encoding;
+ size_t bomLength;
+ Tie(encoding, bomLength) = Encoding::ForBOM(data);
+ ASSERT_EQ(encoding, UTF_8_ENCODING);
+ ASSERT_EQ(bomLength, 3U);
+ data.AssignLiteral("\xFF\xFE");
+ Tie(encoding, bomLength) = Encoding::ForBOM(data);
+ ASSERT_EQ(encoding, UTF_16LE_ENCODING);
+ ASSERT_EQ(bomLength, 2U);
+ data.AssignLiteral("\xFE\xFF");
+ Tie(encoding, bomLength) = Encoding::ForBOM(data);
+ ASSERT_EQ(encoding, UTF_16BE_ENCODING);
+ ASSERT_EQ(bomLength, 2U);
+ data.AssignLiteral("\xEF\xBB");
+ Tie(encoding, bomLength) = Encoding::ForBOM(data);
+ ASSERT_EQ(encoding, nullptr);
+ ASSERT_EQ(bomLength, 0U);
+}
+
+ENCODING_TEST(Name) {
+ nsAutoCString name;
+ UTF_8_ENCODING->Name(name);
+ ASSERT_TRUE(name.EqualsLiteral("UTF-8"));
+ GBK_ENCODING->Name(name);
+ ASSERT_TRUE(name.EqualsLiteral("GBK"));
+}
+
+ENCODING_TEST(CanEncodeEverything) {
+ ASSERT_TRUE(UTF_8_ENCODING->CanEncodeEverything());
+ ASSERT_FALSE(GB18030_ENCODING->CanEncodeEverything());
+}
+
+ENCODING_TEST(IsAsciiCompatible) {
+ ASSERT_TRUE(UTF_8_ENCODING->IsAsciiCompatible());
+ ASSERT_FALSE(ISO_2022_JP_ENCODING->IsAsciiCompatible());
+}
diff --git a/intl/gtest/moz.build b/intl/gtest/moz.build
new file mode 100644
index 0000000000..80d897ad03
--- /dev/null
+++ b/intl/gtest/moz.build
@@ -0,0 +1,13 @@
+# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
+# vim: set filetype=python:
+# 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/.
+
+UNIFIED_SOURCES += []
+
+# skip the test on windows10-aarch64 due to perma-crash - bug 1544961
+if not (CONFIG["OS_TARGET"] == "WINNT" and CONFIG["CPU_ARCH"] == "aarch64"):
+ UNIFIED_SOURCES += ["TestEncoding.cpp"]
+
+FINAL_LIBRARY = "xul-gtest"