1 /* 2 * Copyright (C) 2015 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/FontFamily.h> 20 21 #include "FontLanguageListCache.h" 22 #include "ICUTestBase.h" 23 #include "MinikinInternal.h" 24 25 namespace android { 26 27 typedef ICUTestBase FontLanguageListCacheTest; 28 29 TEST_F(FontLanguageListCacheTest, getId) { 30 EXPECT_NE(0UL, FontStyle::registerLanguageList("en")); 31 EXPECT_NE(0UL, FontStyle::registerLanguageList("jp")); 32 EXPECT_NE(0UL, FontStyle::registerLanguageList("en,zh-Hans")); 33 34 AutoMutex _l(gMinikinLock); 35 EXPECT_EQ(0UL, FontLanguageListCache::getId("")); 36 37 EXPECT_EQ(FontLanguageListCache::getId("en"), FontLanguageListCache::getId("en")); 38 EXPECT_NE(FontLanguageListCache::getId("en"), FontLanguageListCache::getId("jp")); 39 40 EXPECT_EQ(FontLanguageListCache::getId("en,zh-Hans"), 41 FontLanguageListCache::getId("en,zh-Hans")); 42 EXPECT_NE(FontLanguageListCache::getId("en,zh-Hans"), 43 FontLanguageListCache::getId("zh-Hans,en")); 44 EXPECT_NE(FontLanguageListCache::getId("en,zh-Hans"), 45 FontLanguageListCache::getId("jp")); 46 EXPECT_NE(FontLanguageListCache::getId("en,zh-Hans"), 47 FontLanguageListCache::getId("en")); 48 EXPECT_NE(FontLanguageListCache::getId("en,zh-Hans"), 49 FontLanguageListCache::getId("en,zh-Hant")); 50 } 51 52 TEST_F(FontLanguageListCacheTest, getById) { 53 AutoMutex _l(gMinikinLock); 54 uint32_t enLangId = FontLanguageListCache::getId("en"); 55 uint32_t jpLangId = FontLanguageListCache::getId("jp"); 56 FontLanguage english = FontLanguageListCache::getById(enLangId)[0]; 57 FontLanguage japanese = FontLanguageListCache::getById(jpLangId)[0]; 58 59 const FontLanguages& defLangs = FontLanguageListCache::getById(0); 60 EXPECT_TRUE(defLangs.empty()); 61 62 const FontLanguages& langs = FontLanguageListCache::getById(FontLanguageListCache::getId("en")); 63 ASSERT_EQ(1UL, langs.size()); 64 EXPECT_EQ(english, langs[0]); 65 66 const FontLanguages& langs2 = 67 FontLanguageListCache::getById(FontLanguageListCache::getId("en,jp")); 68 ASSERT_EQ(2UL, langs2.size()); 69 EXPECT_EQ(english, langs2[0]); 70 EXPECT_EQ(japanese, langs2[1]); 71 } 72 73 } // android 74