Home | History | Annotate | Download | only in unittest
      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 "ICUTestBase.h"
     20 #include <minikin/LineBreaker.h>
     21 #include <unicode/locid.h>
     22 
     23 namespace minikin {
     24 
     25 typedef ICUTestBase LineBreakerTest;
     26 
     27 TEST_F(LineBreakerTest, setLocales) {
     28     {
     29         LineBreaker lineBreaker;
     30         Hyphenator hyphenator;
     31         std::vector<Hyphenator*> hyphenators;
     32         hyphenators.push_back(&hyphenator);
     33         lineBreaker.setLocales("en-US", hyphenators);
     34         EXPECT_EQ(icu::Locale::getUS(), lineBreaker.mLocale);
     35         EXPECT_EQ(&hyphenator, lineBreaker.mHyphenator);
     36     }
     37     {
     38         LineBreaker lineBreaker;
     39         Hyphenator hyphenator1, hyphenator2;
     40         std::vector<Hyphenator*> hyphenators;
     41         hyphenators.push_back(&hyphenator1);
     42         hyphenators.push_back(&hyphenator2);
     43         lineBreaker.setLocales("fr-FR,en-US", hyphenators);
     44         EXPECT_EQ(icu::Locale::getFrance(), lineBreaker.mLocale);
     45         EXPECT_EQ(&hyphenator1, lineBreaker.mHyphenator);
     46     }
     47     {
     48         LineBreaker lineBreaker;
     49         std::vector<Hyphenator*> hyphenators;
     50         lineBreaker.setLocales("", hyphenators);
     51         EXPECT_EQ(icu::Locale::getRoot(), lineBreaker.mLocale);
     52         EXPECT_EQ(nullptr, lineBreaker.mHyphenator);
     53     }
     54     {
     55         LineBreaker lineBreaker;
     56         std::vector<Hyphenator*> hyphenators;
     57         Hyphenator hyphenator;
     58         hyphenators.push_back(&hyphenator);
     59         lineBreaker.setLocales("THISISABOGUSLANGUAGE", hyphenators);
     60         EXPECT_EQ(icu::Locale::getRoot(), lineBreaker.mLocale);
     61         EXPECT_EQ(nullptr, lineBreaker.mHyphenator);
     62     }
     63     {
     64         LineBreaker lineBreaker;
     65         Hyphenator hyphenator1, hyphenator2;
     66         std::vector<Hyphenator*> hyphenators;
     67         hyphenators.push_back(&hyphenator1);
     68         hyphenators.push_back(&hyphenator2);
     69         lineBreaker.setLocales("THISISABOGUSLANGUAGE,en-US", hyphenators);
     70         EXPECT_EQ(icu::Locale::getUS(), lineBreaker.mLocale);
     71         EXPECT_EQ(&hyphenator2, lineBreaker.mHyphenator);
     72     }
     73     {
     74         LineBreaker lineBreaker;
     75         Hyphenator hyphenator1, hyphenator2;
     76         std::vector<Hyphenator*> hyphenators;
     77         hyphenators.push_back(&hyphenator1);
     78         hyphenators.push_back(&hyphenator2);
     79         lineBreaker.setLocales("THISISABOGUSLANGUAGE,ANOTHERBOGUSLANGUAGE", hyphenators);
     80         EXPECT_EQ(icu::Locale::getRoot(), lineBreaker.mLocale);
     81         EXPECT_EQ(nullptr, lineBreaker.mHyphenator);
     82     }
     83 }
     84 
     85 }  // namespace minikin
     86