Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/intl/locale/tests/gtest/TestLocaleServiceNegotiate.cpp
Line
Count
Source (jump to first uncovered line)
1
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
/* This Source Code Form is subject to the terms of the Mozilla Public
3
 * License, v. 2.0. If a copy of the MPL was not distributed with this
4
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5
6
#include "gtest/gtest.h"
7
#include "mozilla/intl/LocaleService.h"
8
#include "mozilla/Services.h"
9
#include "nsIToolkitChromeRegistry.h"
10
11
using namespace mozilla::intl;
12
13
0
TEST(Intl_Locale_LocaleService, Negotiate) {
14
0
  nsTArray<nsCString> requestedLocales;
15
0
  nsTArray<nsCString> availableLocales;
16
0
  nsTArray<nsCString> supportedLocales;
17
0
  nsAutoCString defaultLocale("en-US");
18
0
  int32_t strategy =
19
0
    LocaleService::kLangNegStrategyFiltering;
20
0
21
0
  requestedLocales.AppendElement(NS_LITERAL_CSTRING("sr"));
22
0
23
0
  availableLocales.AppendElement(NS_LITERAL_CSTRING("sr-Cyrl"));
24
0
  availableLocales.AppendElement(NS_LITERAL_CSTRING("sr-Latn"));
25
0
26
0
  LocaleService::GetInstance()->NegotiateLanguages(
27
0
      requestedLocales, availableLocales, defaultLocale, strategy, supportedLocales);
28
0
29
0
  ASSERT_TRUE(supportedLocales.Length() == 2);
30
0
  ASSERT_TRUE(supportedLocales[0].EqualsLiteral("sr-Cyrl"));
31
0
  ASSERT_TRUE(supportedLocales[1].EqualsLiteral("en-US"));
32
0
}
33
34
0
TEST(Intl_Locale_LocaleService, UseLSDefaultLocale) {
35
0
  nsTArray<nsCString> requestedLocales;
36
0
  nsTArray<nsCString> availableLocales;
37
0
  nsTArray<nsCString> supportedLocales;
38
0
  nsAutoCString defaultLocale("");
39
0
  int32_t strategy =
40
0
    LocaleService::kLangNegStrategyLookup;
41
0
42
0
  requestedLocales.AppendElement(NS_LITERAL_CSTRING("sr"));
43
0
44
0
  availableLocales.AppendElement(NS_LITERAL_CSTRING("de"));
45
0
46
0
  LocaleService::GetInstance()->NegotiateLanguages(
47
0
      requestedLocales, availableLocales, defaultLocale, strategy, supportedLocales);
48
0
49
0
  nsAutoCString lsDefaultLocale;
50
0
  LocaleService::GetInstance()->GetDefaultLocale(lsDefaultLocale);
51
0
  ASSERT_TRUE(supportedLocales.Length() == 1);
52
0
  ASSERT_TRUE(supportedLocales[0].Equals(lsDefaultLocale));
53
0
}