Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/intl/locale/tests/gtest/TestOSPreferences.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/ArrayUtils.h"
8
#include "mozilla/intl/OSPreferences.h"
9
10
using namespace mozilla::intl;
11
12
/**
13
 * We test that on all platforms we test against (irrelevant of the tier),
14
 * we will be able to retrieve at least a single locale out of the system.
15
 *
16
 * In theory, that may not be true, but if we encounter such platform we should
17
 * decide how to handle this and special case and this test should make
18
 * it not happen without us noticing.
19
 */
20
0
TEST(Intl_Locale_OSPreferences, GetSystemLocales) {
21
0
  nsTArray<nsCString> systemLocales;
22
0
  ASSERT_TRUE(NS_SUCCEEDED(OSPreferences::GetInstance()->GetSystemLocales(systemLocales)));
23
0
24
0
  ASSERT_FALSE(systemLocales.IsEmpty());
25
0
}
26
27
/**
28
 * We test that on all platforms we test against (irrelevant of the tier),
29
 * we will be able to retrieve at least a single locale out of the system.
30
 *
31
 * In theory, that may not be true, but if we encounter such platform we should
32
 * decide how to handle this and special case and this test should make
33
 * it not happen without us noticing.
34
 */
35
0
TEST(Intl_Locale_OSPreferences, GetRegionalPrefsLocales) {
36
0
  nsTArray<nsCString> rgLocales;
37
0
  ASSERT_TRUE(NS_SUCCEEDED(OSPreferences::GetInstance()->GetRegionalPrefsLocales(rgLocales)));
38
0
39
0
  ASSERT_FALSE(rgLocales.IsEmpty());
40
0
}
41
42
/**
43
 * We test that on all platforms we test against,
44
 * we will be able to retrieve a date and time pattern.
45
 *
46
 * This may come back empty on platforms where we don't have platforms
47
 * bindings for, so effectively, we're testing for crashes. We should
48
 * never crash.
49
 */
50
0
TEST(Intl_Locale_OSPreferences, GetDateTimePattern) {
51
0
  nsAutoString pattern;
52
0
  OSPreferences* osprefs = OSPreferences::GetInstance();
53
0
54
0
  struct Test {
55
0
    int dateStyle;
56
0
    int timeStyle;
57
0
    const char* locale;
58
0
  };
59
0
  Test tests[] = {
60
0
    { 0, 0, "" },
61
0
    { 1, 0, "pl" },
62
0
    { 2, 0, "de-DE" },
63
0
    { 3, 0, "fr" },
64
0
    { 4, 0, "ar" },
65
0
66
0
    { 0, 1, "" },
67
0
    { 0, 2, "it" },
68
0
    { 0, 3, "" },
69
0
    { 0, 4, "ru" },
70
0
71
0
    { 4, 1, "" },
72
0
    { 3, 2, "cs" },
73
0
    { 2, 3, "" },
74
0
    { 1, 4, "ja" }
75
0
  };
76
0
77
0
  for (unsigned i = 0; i < mozilla::ArrayLength(tests); i++) {
78
0
    const Test& t = tests[i];
79
0
    nsAutoString pattern;
80
0
    if (NS_SUCCEEDED(osprefs->GetDateTimePattern(t.dateStyle, t.timeStyle,
81
0
                                                 nsDependentCString(t.locale),
82
0
                                                 pattern))) {
83
0
      ASSERT_TRUE((t.dateStyle == 0 && t.timeStyle == 0) || !pattern.IsEmpty());
84
0
    }
85
0
  }
86
0
87
0
  ASSERT_TRUE(1);
88
0
}