diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /intl/l10n/test/gtest/TestLocalization.cpp | |
parent | Initial commit. (diff) | |
download | firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'intl/l10n/test/gtest/TestLocalization.cpp')
-rw-r--r-- | intl/l10n/test/gtest/TestLocalization.cpp | 118 |
1 files changed, 118 insertions, 0 deletions
diff --git a/intl/l10n/test/gtest/TestLocalization.cpp b/intl/l10n/test/gtest/TestLocalization.cpp new file mode 100644 index 0000000000..804c228c98 --- /dev/null +++ b/intl/l10n/test/gtest/TestLocalization.cpp @@ -0,0 +1,118 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* 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 "gtest/gtest.h" +#include "mozilla/intl/Localization.h" + +using namespace mozilla; +using namespace mozilla::dom; +using namespace mozilla::intl; + +TEST(Intl_Localization, FormatValueSyncMissing) +{ + nsTArray<nsCString> resIds = { + "toolkit/global/handlerDialog.ftl"_ns, + }; + RefPtr<Localization> l10n = Localization::Create(resIds, true); + + auto l10nId = "non-existing-l10n-id"_ns; + IgnoredErrorResult rv; + nsAutoCString result; + + l10n->FormatValueSync(l10nId, {}, result, rv); + ASSERT_FALSE(rv.Failed()); + ASSERT_TRUE(result.IsEmpty()); +} + +TEST(Intl_Localization, FormatValueSync) +{ + nsTArray<nsCString> resIds = { + "toolkit/global/handlerDialog.ftl"_ns, + }; + RefPtr<Localization> l10n = Localization::Create(resIds, true); + + auto l10nId = "permission-dialog-unset-description"_ns; + IgnoredErrorResult rv; + nsAutoCString result; + + l10n->FormatValueSync(l10nId, {}, result, rv); + ASSERT_FALSE(rv.Failed()); + ASSERT_FALSE(result.IsEmpty()); +} + +TEST(Intl_Localization, FormatValueSyncWithArgs) +{ + nsTArray<nsCString> resIds = { + "toolkit/global/handlerDialog.ftl"_ns, + }; + RefPtr<Localization> l10n = Localization::Create(resIds, true); + + auto l10nId = "permission-dialog-description"_ns; + + auto l10nArgs = dom::Optional<intl::L10nArgs>(); + l10nArgs.Construct(); + + auto dirArg = l10nArgs.Value().Entries().AppendElement(); + dirArg->mKey = "scheme"_ns; + dirArg->mValue.SetValue().SetAsUTF8String().Assign("Foo"_ns); + + IgnoredErrorResult rv; + nsAutoCString result; + + l10n->FormatValueSync(l10nId, l10nArgs, result, rv); + ASSERT_FALSE(rv.Failed()); + ASSERT_TRUE(result.Find("Foo"_ns) > -1); +} + +TEST(Intl_Localization, FormatMessagesSync) +{ + nsTArray<nsCString> resIds = { + "toolkit/global/handlerDialog.ftl"_ns, + }; + RefPtr<Localization> l10n = Localization::Create(resIds, true); + + dom::Sequence<dom::OwningUTF8StringOrL10nIdArgs> l10nIds; + auto* l10nId = l10nIds.AppendElement(fallible); + ASSERT_TRUE(l10nId); + l10nId->SetAsUTF8String().Assign("permission-dialog-unset-description"_ns); + + IgnoredErrorResult rv; + nsTArray<dom::Nullable<dom::L10nMessage>> result; + + l10n->FormatMessagesSync(l10nIds, result, rv); + ASSERT_FALSE(rv.Failed()); + ASSERT_FALSE(result.IsEmpty()); +} + +TEST(Intl_Localization, FormatMessagesSyncWithArgs) +{ + nsTArray<nsCString> resIds = { + "toolkit/global/handlerDialog.ftl"_ns, + }; + RefPtr<Localization> l10n = Localization::Create(resIds, true); + + dom::Sequence<dom::OwningUTF8StringOrL10nIdArgs> l10nIds; + L10nIdArgs& key0 = l10nIds.AppendElement(fallible)->SetAsL10nIdArgs(); + key0.mId.Assign("permission-dialog-description"_ns); + auto arg = key0.mArgs.SetValue().Entries().AppendElement(); + arg->mKey = "scheme"_ns; + arg->mValue.SetValue().SetAsUTF8String().Assign("Foo"_ns); + + L10nIdArgs& key1 = l10nIds.AppendElement(fallible)->SetAsL10nIdArgs(); + key1.mId.Assign("chooser-window"_ns); + + IgnoredErrorResult rv; + nsTArray<dom::Nullable<dom::L10nMessage>> result; + + l10n->FormatMessagesSync(l10nIds, result, rv); + ASSERT_FALSE(rv.Failed()); + ASSERT_TRUE(result.Length() == 2); + ASSERT_TRUE(result.ElementAt(0).Value().mValue.Find("Foo"_ns) > -1); + + auto fmtAttr = result.ElementAt(1).Value().mAttributes.Value(); + ASSERT_TRUE(fmtAttr.Length() == 2); + ASSERT_FALSE(fmtAttr.ElementAt(0).mName.IsEmpty()); + ASSERT_FALSE(fmtAttr.ElementAt(0).mValue.IsEmpty()); +} |