diff options
| author | manuel <manuel@mausz.at> | 2020-10-19 00:52:24 +0200 |
|---|---|---|
| committer | manuel <manuel@mausz.at> | 2020-10-19 00:52:24 +0200 |
| commit | be933ef2241d79558f91796cc5b3a161f72ebf9c (patch) | |
| tree | fe3ab2f130e20c99001f2d7a81d610c78c96a3f4 /xbmc/utils/test/TestLocale.cpp | |
| parent | 5f8335c1e49ce108ef3481863833c98efa00411b (diff) | |
| download | kodi-pvr-build-be933ef2241d79558f91796cc5b3a161f72ebf9c.tar.gz kodi-pvr-build-be933ef2241d79558f91796cc5b3a161f72ebf9c.tar.bz2 kodi-pvr-build-be933ef2241d79558f91796cc5b3a161f72ebf9c.zip | |
sync with upstream
Diffstat (limited to 'xbmc/utils/test/TestLocale.cpp')
| -rw-r--r-- | xbmc/utils/test/TestLocale.cpp | 272 |
1 files changed, 272 insertions, 0 deletions
diff --git a/xbmc/utils/test/TestLocale.cpp b/xbmc/utils/test/TestLocale.cpp new file mode 100644 index 0000000..f5193ed --- /dev/null +++ b/xbmc/utils/test/TestLocale.cpp | |||
| @@ -0,0 +1,272 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (C) 2015-2018 Team Kodi | ||
| 3 | * This file is part of Kodi - https://kodi.tv | ||
| 4 | * | ||
| 5 | * SPDX-License-Identifier: GPL-2.0-or-later | ||
| 6 | * See LICENSES/README.md for more information. | ||
| 7 | */ | ||
| 8 | |||
| 9 | #include "utils/Locale.h" | ||
| 10 | #include "utils/StringUtils.h" | ||
| 11 | |||
| 12 | #include <gtest/gtest.h> | ||
| 13 | |||
| 14 | static const std::string TerritorySeparator = "_"; | ||
| 15 | static const std::string CodesetSeparator = "."; | ||
| 16 | static const std::string ModifierSeparator = "@"; | ||
| 17 | |||
| 18 | static const std::string LanguageCodeEnglish = "en"; | ||
| 19 | static const std::string TerritoryCodeBritain = "GB"; | ||
| 20 | static const std::string CodesetUtf8 = "UTF-8"; | ||
| 21 | static const std::string ModifierLatin = "latin"; | ||
| 22 | |||
| 23 | TEST(TestLocale, DefaultLocale) | ||
| 24 | { | ||
| 25 | CLocale locale; | ||
| 26 | ASSERT_FALSE(locale.IsValid()); | ||
| 27 | ASSERT_STREQ("", locale.GetLanguageCode().c_str()); | ||
| 28 | ASSERT_STREQ("", locale.GetTerritoryCode().c_str()); | ||
| 29 | ASSERT_STREQ("", locale.GetCodeset().c_str()); | ||
| 30 | ASSERT_STREQ("", locale.GetModifier().c_str()); | ||
| 31 | ASSERT_STREQ("", locale.ToString().c_str()); | ||
| 32 | } | ||
| 33 | |||
| 34 | TEST(TestLocale, LanguageLocale) | ||
| 35 | { | ||
| 36 | CLocale locale(LanguageCodeEnglish); | ||
| 37 | ASSERT_TRUE(locale.IsValid()); | ||
| 38 | ASSERT_STREQ(LanguageCodeEnglish.c_str(), locale.GetLanguageCode().c_str()); | ||
| 39 | ASSERT_STREQ("", locale.GetTerritoryCode().c_str()); | ||
| 40 | ASSERT_STREQ("", locale.GetCodeset().c_str()); | ||
| 41 | ASSERT_STREQ("", locale.GetModifier().c_str()); | ||
| 42 | ASSERT_STREQ(LanguageCodeEnglish.c_str(), locale.ToString().c_str()); | ||
| 43 | ASSERT_STREQ(LanguageCodeEnglish.c_str(), locale.ToStringLC().c_str()); | ||
| 44 | ASSERT_STREQ(LanguageCodeEnglish.c_str(), locale.ToShortString().c_str()); | ||
| 45 | ASSERT_STREQ(LanguageCodeEnglish.c_str(), locale.ToShortStringLC().c_str()); | ||
| 46 | } | ||
| 47 | |||
| 48 | TEST(TestLocale, LanguageTerritoryLocale) | ||
| 49 | { | ||
| 50 | const std::string strLocale = LanguageCodeEnglish + TerritorySeparator + TerritoryCodeBritain; | ||
| 51 | std::string strLocaleLC = strLocale; | ||
| 52 | StringUtils::ToLower(strLocaleLC); | ||
| 53 | |||
| 54 | CLocale locale(LanguageCodeEnglish, TerritoryCodeBritain); | ||
| 55 | ASSERT_TRUE(locale.IsValid()); | ||
| 56 | ASSERT_STREQ(LanguageCodeEnglish.c_str(), locale.GetLanguageCode().c_str()); | ||
| 57 | ASSERT_STREQ(TerritoryCodeBritain.c_str(), locale.GetTerritoryCode().c_str()); | ||
| 58 | ASSERT_STREQ("", locale.GetCodeset().c_str()); | ||
| 59 | ASSERT_STREQ("", locale.GetModifier().c_str()); | ||
| 60 | ASSERT_STREQ(strLocale.c_str(), locale.ToString().c_str()); | ||
| 61 | ASSERT_STREQ(strLocaleLC.c_str(), locale.ToStringLC().c_str()); | ||
| 62 | ASSERT_STREQ(strLocale.c_str(), locale.ToShortString().c_str()); | ||
| 63 | ASSERT_STREQ(strLocaleLC.c_str(), locale.ToShortStringLC().c_str()); | ||
| 64 | } | ||
| 65 | |||
| 66 | TEST(TestLocale, LanguageCodesetLocale) | ||
| 67 | { | ||
| 68 | const std::string strLocale = LanguageCodeEnglish + CodesetSeparator + CodesetUtf8; | ||
| 69 | std::string strLocaleLC = strLocale; | ||
| 70 | StringUtils::ToLower(strLocaleLC); | ||
| 71 | |||
| 72 | CLocale locale(LanguageCodeEnglish, "", CodesetUtf8); | ||
| 73 | ASSERT_TRUE(locale.IsValid()); | ||
| 74 | ASSERT_STREQ(LanguageCodeEnglish.c_str(), locale.GetLanguageCode().c_str()); | ||
| 75 | ASSERT_STREQ("", locale.GetTerritoryCode().c_str()); | ||
| 76 | ASSERT_STREQ(CodesetUtf8.c_str(), locale.GetCodeset().c_str()); | ||
| 77 | ASSERT_STREQ("", locale.GetModifier().c_str()); | ||
| 78 | ASSERT_STREQ(strLocale.c_str(), locale.ToString().c_str()); | ||
| 79 | ASSERT_STREQ(strLocaleLC.c_str(), locale.ToStringLC().c_str()); | ||
| 80 | ASSERT_STREQ(LanguageCodeEnglish.c_str(), locale.ToShortString().c_str()); | ||
| 81 | ASSERT_STREQ(LanguageCodeEnglish.c_str(), locale.ToShortStringLC().c_str()); | ||
| 82 | } | ||
| 83 | |||
| 84 | TEST(TestLocale, LanguageModifierLocale) | ||
| 85 | { | ||
| 86 | const std::string strLocale = LanguageCodeEnglish + ModifierSeparator + ModifierLatin; | ||
| 87 | std::string strLocaleLC = strLocale; | ||
| 88 | StringUtils::ToLower(strLocaleLC); | ||
| 89 | |||
| 90 | CLocale locale(LanguageCodeEnglish, "", "", ModifierLatin); | ||
| 91 | ASSERT_TRUE(locale.IsValid()); | ||
| 92 | ASSERT_STREQ(LanguageCodeEnglish.c_str(), locale.GetLanguageCode().c_str()); | ||
| 93 | ASSERT_STREQ("", locale.GetTerritoryCode().c_str()); | ||
| 94 | ASSERT_STREQ("", locale.GetCodeset().c_str()); | ||
| 95 | ASSERT_STREQ(ModifierLatin.c_str(), locale.GetModifier().c_str()); | ||
| 96 | ASSERT_STREQ(strLocale.c_str(), locale.ToString().c_str()); | ||
| 97 | ASSERT_STREQ(strLocaleLC.c_str(), locale.ToStringLC().c_str()); | ||
| 98 | ASSERT_STREQ(LanguageCodeEnglish.c_str(), locale.ToShortString().c_str()); | ||
| 99 | ASSERT_STREQ(LanguageCodeEnglish.c_str(), locale.ToShortStringLC().c_str()); | ||
| 100 | } | ||
| 101 | |||
| 102 | TEST(TestLocale, LanguageTerritoryCodesetLocale) | ||
| 103 | { | ||
| 104 | const std::string strLocaleShort = LanguageCodeEnglish + TerritorySeparator + TerritoryCodeBritain; | ||
| 105 | std::string strLocaleShortLC = strLocaleShort; | ||
| 106 | StringUtils::ToLower(strLocaleShortLC); | ||
| 107 | const std::string strLocale = strLocaleShort + CodesetSeparator + CodesetUtf8; | ||
| 108 | std::string strLocaleLC = strLocale; | ||
| 109 | StringUtils::ToLower(strLocaleLC); | ||
| 110 | |||
| 111 | CLocale locale(LanguageCodeEnglish, TerritoryCodeBritain, CodesetUtf8); | ||
| 112 | ASSERT_TRUE(locale.IsValid()); | ||
| 113 | ASSERT_STREQ(LanguageCodeEnglish.c_str(), locale.GetLanguageCode().c_str()); | ||
| 114 | ASSERT_STREQ(TerritoryCodeBritain.c_str(), locale.GetTerritoryCode().c_str()); | ||
| 115 | ASSERT_STREQ(CodesetUtf8.c_str(), locale.GetCodeset().c_str()); | ||
| 116 | ASSERT_STREQ("", locale.GetModifier().c_str()); | ||
| 117 | ASSERT_STREQ(strLocale.c_str(), locale.ToString().c_str()); | ||
| 118 | ASSERT_STREQ(strLocaleLC.c_str(), locale.ToStringLC().c_str()); | ||
| 119 | ASSERT_STREQ(strLocaleShort.c_str(), locale.ToShortString().c_str()); | ||
| 120 | ASSERT_STREQ(strLocaleShortLC.c_str(), locale.ToShortStringLC().c_str()); | ||
| 121 | } | ||
| 122 | |||
| 123 | TEST(TestLocale, LanguageTerritoryModifierLocale) | ||
| 124 | { | ||
| 125 | const std::string strLocaleShort = LanguageCodeEnglish + TerritorySeparator + TerritoryCodeBritain; | ||
| 126 | std::string strLocaleShortLC = strLocaleShort; | ||
| 127 | StringUtils::ToLower(strLocaleShortLC); | ||
| 128 | const std::string strLocale = strLocaleShort + ModifierSeparator + ModifierLatin; | ||
| 129 | std::string strLocaleLC = strLocale; | ||
| 130 | StringUtils::ToLower(strLocaleLC); | ||
| 131 | |||
| 132 | CLocale locale(LanguageCodeEnglish, TerritoryCodeBritain, "", ModifierLatin); | ||
| 133 | ASSERT_TRUE(locale.IsValid()); | ||
| 134 | ASSERT_STREQ(LanguageCodeEnglish.c_str(), locale.GetLanguageCode().c_str()); | ||
| 135 | ASSERT_STREQ(TerritoryCodeBritain.c_str(), locale.GetTerritoryCode().c_str()); | ||
| 136 | ASSERT_STREQ("", locale.GetCodeset().c_str()); | ||
| 137 | ASSERT_STREQ(ModifierLatin.c_str(), locale.GetModifier().c_str()); | ||
| 138 | ASSERT_STREQ(strLocale.c_str(), locale.ToString().c_str()); | ||
| 139 | ASSERT_STREQ(strLocaleLC.c_str(), locale.ToStringLC().c_str()); | ||
| 140 | ASSERT_STREQ(strLocaleShort.c_str(), locale.ToShortString().c_str()); | ||
| 141 | ASSERT_STREQ(strLocaleShortLC.c_str(), locale.ToShortStringLC().c_str()); | ||
| 142 | } | ||
| 143 | |||
| 144 | TEST(TestLocale, LanguageTerritoryCodesetModifierLocale) | ||
| 145 | { | ||
| 146 | const std::string strLocaleShort = LanguageCodeEnglish + TerritorySeparator + TerritoryCodeBritain; | ||
| 147 | std::string strLocaleShortLC = strLocaleShort; | ||
| 148 | StringUtils::ToLower(strLocaleShortLC); | ||
| 149 | const std::string strLocale = strLocaleShort + CodesetSeparator + CodesetUtf8 + ModifierSeparator + ModifierLatin; | ||
| 150 | std::string strLocaleLC = strLocale; | ||
| 151 | StringUtils::ToLower(strLocaleLC); | ||
| 152 | |||
| 153 | CLocale locale(LanguageCodeEnglish, TerritoryCodeBritain, CodesetUtf8, ModifierLatin); | ||
| 154 | ASSERT_TRUE(locale.IsValid()); | ||
| 155 | ASSERT_STREQ(LanguageCodeEnglish.c_str(), locale.GetLanguageCode().c_str()); | ||
| 156 | ASSERT_STREQ(TerritoryCodeBritain.c_str(), locale.GetTerritoryCode().c_str()); | ||
| 157 | ASSERT_STREQ(CodesetUtf8.c_str(), locale.GetCodeset().c_str()); | ||
| 158 | ASSERT_STREQ(ModifierLatin.c_str(), locale.GetModifier().c_str()); | ||
| 159 | ASSERT_STREQ(strLocale.c_str(), locale.ToString().c_str()); | ||
| 160 | ASSERT_STREQ(strLocaleLC.c_str(), locale.ToStringLC().c_str()); | ||
| 161 | ASSERT_STREQ(strLocaleShort.c_str(), locale.ToShortString().c_str()); | ||
| 162 | ASSERT_STREQ(strLocaleShortLC.c_str(), locale.ToShortStringLC().c_str()); | ||
| 163 | } | ||
| 164 | |||
| 165 | TEST(TestLocale, FullStringLocale) | ||
| 166 | { | ||
| 167 | const std::string strLocaleShort = LanguageCodeEnglish + TerritorySeparator + TerritoryCodeBritain; | ||
| 168 | std::string strLocaleShortLC = strLocaleShort; | ||
| 169 | StringUtils::ToLower(strLocaleShortLC); | ||
| 170 | const std::string strLocale = strLocaleShort + CodesetSeparator + CodesetUtf8 + ModifierSeparator + ModifierLatin; | ||
| 171 | std::string strLocaleLC = strLocale; | ||
| 172 | StringUtils::ToLower(strLocaleLC); | ||
| 173 | |||
| 174 | CLocale locale(strLocale); | ||
| 175 | ASSERT_TRUE(locale.IsValid()); | ||
| 176 | ASSERT_STREQ(LanguageCodeEnglish.c_str(), locale.GetLanguageCode().c_str()); | ||
| 177 | ASSERT_STREQ(TerritoryCodeBritain.c_str(), locale.GetTerritoryCode().c_str()); | ||
| 178 | ASSERT_STREQ(CodesetUtf8.c_str(), locale.GetCodeset().c_str()); | ||
| 179 | ASSERT_STREQ(ModifierLatin.c_str(), locale.GetModifier().c_str()); | ||
| 180 | ASSERT_STREQ(strLocale.c_str(), locale.ToString().c_str()); | ||
| 181 | ASSERT_STREQ(strLocaleLC.c_str(), locale.ToStringLC().c_str()); | ||
| 182 | ASSERT_STREQ(strLocaleShort.c_str(), locale.ToShortString().c_str()); | ||
| 183 | ASSERT_STREQ(strLocaleShortLC.c_str(), locale.ToShortStringLC().c_str()); | ||
| 184 | } | ||
| 185 | |||
| 186 | TEST(TestLocale, FromString) | ||
| 187 | { | ||
| 188 | std::string strLocale = ""; | ||
| 189 | CLocale locale = CLocale::FromString(strLocale); | ||
| 190 | ASSERT_FALSE(locale.IsValid()); | ||
| 191 | ASSERT_STREQ(strLocale.c_str(), locale.ToString().c_str()); | ||
| 192 | |||
| 193 | strLocale = LanguageCodeEnglish; | ||
| 194 | locale = CLocale::FromString(strLocale); | ||
| 195 | ASSERT_TRUE(locale.IsValid()); | ||
| 196 | ASSERT_STREQ(strLocale.c_str(), locale.ToString().c_str()); | ||
| 197 | |||
| 198 | strLocale = LanguageCodeEnglish + TerritorySeparator + TerritoryCodeBritain; | ||
| 199 | locale = CLocale::FromString(strLocale); | ||
| 200 | ASSERT_TRUE(locale.IsValid()); | ||
| 201 | ASSERT_STREQ(strLocale.c_str(), locale.ToString().c_str()); | ||
| 202 | |||
| 203 | strLocale = LanguageCodeEnglish + CodesetSeparator + CodesetUtf8; | ||
| 204 | locale = CLocale::FromString(strLocale); | ||
| 205 | ASSERT_TRUE(locale.IsValid()); | ||
| 206 | ASSERT_STREQ(strLocale.c_str(), locale.ToString().c_str()); | ||
| 207 | |||
| 208 | strLocale = LanguageCodeEnglish + ModifierSeparator + ModifierLatin; | ||
| 209 | locale = CLocale::FromString(strLocale); | ||
| 210 | ASSERT_TRUE(locale.IsValid()); | ||
| 211 | ASSERT_STREQ(strLocale.c_str(), locale.ToString().c_str()); | ||
| 212 | |||
| 213 | strLocale = LanguageCodeEnglish + TerritorySeparator + TerritoryCodeBritain + CodesetSeparator + CodesetUtf8; | ||
| 214 | locale = CLocale::FromString(strLocale); | ||
| 215 | ASSERT_TRUE(locale.IsValid()); | ||
| 216 | ASSERT_STREQ(strLocale.c_str(), locale.ToString().c_str()); | ||
| 217 | |||
| 218 | strLocale = LanguageCodeEnglish + TerritorySeparator + TerritoryCodeBritain + ModifierSeparator + ModifierLatin; | ||
| 219 | locale = CLocale::FromString(strLocale); | ||
| 220 | ASSERT_TRUE(locale.IsValid()); | ||
| 221 | ASSERT_STREQ(strLocale.c_str(), locale.ToString().c_str()); | ||
| 222 | |||
| 223 | strLocale = LanguageCodeEnglish + TerritorySeparator + TerritoryCodeBritain + CodesetSeparator + CodesetUtf8 + ModifierSeparator + ModifierLatin; | ||
| 224 | locale = CLocale::FromString(strLocale); | ||
| 225 | ASSERT_TRUE(locale.IsValid()); | ||
| 226 | ASSERT_STREQ(strLocale.c_str(), locale.ToString().c_str()); | ||
| 227 | } | ||
| 228 | |||
| 229 | TEST(TestLocale, EmptyLocale) | ||
| 230 | { | ||
| 231 | ASSERT_FALSE(CLocale::Empty.IsValid()); | ||
| 232 | ASSERT_STREQ("", CLocale::Empty.GetLanguageCode().c_str()); | ||
| 233 | ASSERT_STREQ("", CLocale::Empty.GetTerritoryCode().c_str()); | ||
| 234 | ASSERT_STREQ("", CLocale::Empty.GetCodeset().c_str()); | ||
| 235 | ASSERT_STREQ("", CLocale::Empty.GetModifier().c_str()); | ||
| 236 | ASSERT_STREQ("", CLocale::Empty.ToString().c_str()); | ||
| 237 | } | ||
| 238 | |||
| 239 | TEST(TestLocale, Equals) | ||
| 240 | { | ||
| 241 | std::string strLocale = ""; | ||
| 242 | CLocale locale; | ||
| 243 | ASSERT_TRUE(locale.Equals(strLocale)); | ||
| 244 | |||
| 245 | locale = CLocale(LanguageCodeEnglish); | ||
| 246 | strLocale = LanguageCodeEnglish; | ||
| 247 | ASSERT_TRUE(locale.Equals(strLocale)); | ||
| 248 | |||
| 249 | locale = CLocale(LanguageCodeEnglish, TerritoryCodeBritain); | ||
| 250 | strLocale = LanguageCodeEnglish + TerritorySeparator + TerritoryCodeBritain; | ||
| 251 | ASSERT_TRUE(locale.Equals(strLocale)); | ||
| 252 | |||
| 253 | locale = CLocale(LanguageCodeEnglish, "", CodesetUtf8); | ||
| 254 | strLocale = LanguageCodeEnglish + CodesetSeparator + CodesetUtf8; | ||
| 255 | ASSERT_TRUE(locale.Equals(strLocale)); | ||
| 256 | |||
| 257 | locale = CLocale(LanguageCodeEnglish, "", "", ModifierLatin); | ||
| 258 | strLocale = LanguageCodeEnglish + ModifierSeparator + ModifierLatin; | ||
| 259 | ASSERT_TRUE(locale.Equals(strLocale)); | ||
| 260 | |||
| 261 | locale = CLocale(LanguageCodeEnglish, TerritoryCodeBritain, CodesetUtf8); | ||
| 262 | strLocale = LanguageCodeEnglish + TerritorySeparator + TerritoryCodeBritain + CodesetSeparator + CodesetUtf8; | ||
| 263 | ASSERT_TRUE(locale.Equals(strLocale)); | ||
| 264 | |||
| 265 | locale = CLocale(LanguageCodeEnglish, TerritoryCodeBritain, "", ModifierLatin); | ||
| 266 | strLocale = LanguageCodeEnglish + TerritorySeparator + TerritoryCodeBritain + ModifierSeparator + ModifierLatin; | ||
| 267 | ASSERT_TRUE(locale.Equals(strLocale)); | ||
| 268 | |||
| 269 | locale = CLocale(LanguageCodeEnglish, TerritoryCodeBritain, CodesetUtf8, ModifierLatin); | ||
| 270 | strLocale = LanguageCodeEnglish + TerritorySeparator + TerritoryCodeBritain + CodesetSeparator + CodesetUtf8 + ModifierSeparator + ModifierLatin; | ||
| 271 | ASSERT_TRUE(locale.Equals(strLocale)); | ||
| 272 | } | ||
