blob: 15632cd50d3f80d0ccbb5e93b893ff56c7747482 [file] [log] [blame]
/*
* Copyright (C) 2020 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <gtest/gtest.h>
#include <vector>
#include <unicode/uloc.h>
bool is_enUS(const char* s) {
return s != nullptr && std::strcmp("en_US", s) == 0;
}
TEST(Icu4cLocaleTest, test_uloc_getAvailable) {
int32_t count = uloc_countAvailable();
ASSERT_GT(uloc_countAvailable(), 0);
std::vector<const char*> locales(count);
for(int i = 0; i < count; i++) {
locales.push_back(uloc_getAvailable(i));
}
// On Android, uloc_getAvailable must contain en_US.
ASSERT_NE(locales.end(), std::find_if(locales.begin(), locales.end(), is_enUS));
}
TEST(Icu4cLocaleTest, test_uloc_getCountry) {
char country[4];
UErrorCode error;
uloc_getCountry("en_US", country, sizeof(country), &error);
ASSERT_EQ(U_ZERO_ERROR, error);
EXPECT_STREQ("US", country);
}