DXR is a code search and navigation tool aimed at making sense of large projects. It supports full-text and regex searches as well as structural queries.

Mercurial (98275c66e600)

VCS Links

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 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(NS_LITERAL_CSTRING("sr"));

  availableLocales.AppendElement(NS_LITERAL_CSTRING("sr-Cyrl"));
  availableLocales.AppendElement(NS_LITERAL_CSTRING("sr-Latn"));

  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(NS_LITERAL_CSTRING("sr"));

  availableLocales.AppendElement(NS_LITERAL_CSTRING("de"));

  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));
}