summaryrefslogtreecommitdiffstats
path: root/intl/locale/tests/gtest/TestLocaleServiceNegotiate.cpp
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
commit26a029d407be480d791972afb5975cf62c9360a6 (patch)
treef435a8308119effd964b339f76abb83a57c29483 /intl/locale/tests/gtest/TestLocaleServiceNegotiate.cpp
parentInitial commit. (diff)
downloadfirefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz
firefox-26a029d407be480d791972afb5975cf62c9360a6.zip
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'intl/locale/tests/gtest/TestLocaleServiceNegotiate.cpp')
-rw-r--r--intl/locale/tests/gtest/TestLocaleServiceNegotiate.cpp53
1 files changed, 53 insertions, 0 deletions
diff --git a/intl/locale/tests/gtest/TestLocaleServiceNegotiate.cpp b/intl/locale/tests/gtest/TestLocaleServiceNegotiate.cpp
new file mode 100644
index 0000000000..c428e81c8d
--- /dev/null
+++ b/intl/locale/tests/gtest/TestLocaleServiceNegotiate.cpp
@@ -0,0 +1,53 @@
+/* -*- 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/LocaleService.h"
+
+using namespace mozilla::intl;
+
+TEST(Intl_Locale_LocaleService, Negotiate)
+{
+ nsTArray<nsCString> requestedLocales;
+ nsTArray<nsCString> availableLocales;
+ nsTArray<nsCString> supportedLocales;
+ nsAutoCString defaultLocale("en-US");
+ int32_t strategy = LocaleService::kLangNegStrategyFiltering;
+
+ requestedLocales.AppendElement("sr"_ns);
+
+ availableLocales.AppendElement("sr-Cyrl"_ns);
+ availableLocales.AppendElement("sr-Latn"_ns);
+
+ LocaleService::GetInstance()->NegotiateLanguages(
+ requestedLocales, availableLocales, defaultLocale, strategy,
+ supportedLocales);
+
+ ASSERT_TRUE(supportedLocales.Length() == 2);
+ ASSERT_TRUE(supportedLocales[0].EqualsLiteral("sr-Cyrl"));
+ ASSERT_TRUE(supportedLocales[1].EqualsLiteral("en-US"));
+}
+
+TEST(Intl_Locale_LocaleService, UseLSDefaultLocale)
+{
+ nsTArray<nsCString> requestedLocales;
+ nsTArray<nsCString> availableLocales;
+ nsTArray<nsCString> supportedLocales;
+ nsAutoCString defaultLocale("en-US");
+ int32_t strategy = LocaleService::kLangNegStrategyLookup;
+
+ requestedLocales.AppendElement("sr"_ns);
+
+ availableLocales.AppendElement("de"_ns);
+
+ LocaleService::GetInstance()->NegotiateLanguages(
+ requestedLocales, availableLocales, defaultLocale, strategy,
+ supportedLocales);
+
+ nsAutoCString lsDefaultLocale;
+ LocaleService::GetInstance()->GetDefaultLocale(lsDefaultLocale);
+ ASSERT_TRUE(supportedLocales.Length() == 1);
+ ASSERT_TRUE(supportedLocales[0].Equals(lsDefaultLocale));
+}