1 /*
2 * Copyright (C) 2020 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 <vector>
20 #include <unicode/uloc.h>
21
is_enUS(const char * s)22 bool is_enUS(const char* s) {
23 return s != nullptr && std::strcmp("en_US", s) == 0;
24 }
25
TEST(Icu4cLocaleTest,test_uloc_getAvailable)26 TEST(Icu4cLocaleTest, test_uloc_getAvailable) {
27 int32_t count = uloc_countAvailable();
28 ASSERT_GT(uloc_countAvailable(), 0);
29
30 std::vector<const char*> locales(count);
31 for(int i = 0; i < count; i++) {
32 locales.push_back(uloc_getAvailable(i));
33 }
34
35 // On Android, uloc_getAvailable must contain en_US.
36 ASSERT_NE(locales.end(), std::find_if(locales.begin(), locales.end(), is_enUS));
37 }
38
TEST(Icu4cLocaleTest,test_uloc_getCountry)39 TEST(Icu4cLocaleTest, test_uloc_getCountry) {
40 char country[4];
41 UErrorCode error;
42 uloc_getCountry("en_US", country, sizeof(country), &error);
43 ASSERT_EQ(U_ZERO_ERROR, error);
44 EXPECT_STREQ("US", country);
45 }