1 /* 2 * Copyright (C) 2017 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #include <gtest/gtest.h> 18 19 #include "minikin/Hyphenator.h" 20 21 #include "GreedyLineBreaker.h" 22 #include "LocaleListCache.h" 23 #include "MinikinInternal.h" 24 25 namespace minikin { 26 namespace { 27 28 const LocaleList& getLocaleList(const std::string& localeStr) { 29 return LocaleListCache::getById(LocaleListCache::getId(localeStr)); 30 } 31 32 TEST(LocaleListTest, basicTest) { 33 std::string langTag = "en-US"; 34 EXPECT_EQ(1U, getLocaleList(langTag).size()); 35 EXPECT_EQ("en-Latn-US", getLocaleList(langTag)[0].getString()); 36 37 langTag = "en-US,fr-FR"; 38 EXPECT_EQ(2U, getLocaleList(langTag).size()); 39 EXPECT_EQ("en-Latn-US", getLocaleList(langTag)[0].getString()); 40 EXPECT_EQ("fr-Latn-FR", getLocaleList(langTag)[1].getString()); 41 42 langTag = "en-US,en-US,fr-FR"; 43 EXPECT_EQ(2U, getLocaleList(langTag).size()); 44 EXPECT_EQ("en-Latn-US", getLocaleList(langTag)[0].getString()); 45 EXPECT_EQ("fr-Latn-FR", getLocaleList(langTag)[1].getString()); 46 47 EXPECT_EQ(0U, getLocaleList("").size()); 48 } 49 50 TEST(LocaleListTest, bogusLanguageTest) { 51 std::string langTag = "en-US,THISISBOGUSLANGUAGE"; 52 EXPECT_EQ(1U, getLocaleList(langTag).size()); 53 EXPECT_EQ("en-Latn-US", getLocaleList(langTag)[0].getString()); 54 55 langTag = "THISISBOGUSLANGUAGE,en-US"; 56 EXPECT_EQ(1U, getLocaleList(langTag).size()); 57 EXPECT_EQ("en-Latn-US", getLocaleList(langTag)[0].getString()); 58 59 langTag = "THISISBOGUSLANGUAGE,THISISANOTHERBOGUSLANGUAGE"; 60 EXPECT_EQ(0U, getLocaleList(langTag).size()); 61 } 62 63 } // namespace 64 } // namespace minikin 65