This source file includes following definitions.
- TEST
- TEST
#include "components/language_usage_metrics/language_usage_metrics.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace language_usage_metrics {
TEST(LanguageUsageMetricsTest, ParseAcceptLanguages) {
std::set<int> language_set;
std::set<int>::const_iterator it;
const int ENGLISH = 25966;
const int SPANISH = 25971;
const int JAPANESE = 27233;
LanguageUsageMetrics::ParseAcceptLanguages("ja", &language_set);
EXPECT_EQ(1U, language_set.size());
EXPECT_EQ(JAPANESE, *language_set.begin());
LanguageUsageMetrics::ParseAcceptLanguages(std::string(), &language_set);
EXPECT_EQ(0U, language_set.size());
LanguageUsageMetrics::ParseAcceptLanguages("ja-JP", &language_set);
EXPECT_EQ(1U, language_set.size());
EXPECT_EQ(JAPANESE, *language_set.begin());
LanguageUsageMetrics::ParseAcceptLanguages("Ja-jP", &language_set);
EXPECT_EQ(1U, language_set.size());
EXPECT_EQ(JAPANESE, *language_set.begin());
LanguageUsageMetrics::ParseAcceptLanguages("ja_JP", &language_set);
EXPECT_EQ(1U, language_set.size());
EXPECT_EQ(JAPANESE, *language_set.begin());
LanguageUsageMetrics::ParseAcceptLanguages("ja-JP,ja", &language_set);
EXPECT_EQ(1U, language_set.size());
EXPECT_EQ(JAPANESE, *language_set.begin());
LanguageUsageMetrics::ParseAcceptLanguages("en,ja", &language_set);
EXPECT_EQ(2U, language_set.size());
it = language_set.begin();
EXPECT_EQ(ENGLISH, *it);
EXPECT_EQ(JAPANESE, *++it);
LanguageUsageMetrics::ParseAcceptLanguages("ja-JP,en,es,ja,en-US",
&language_set);
EXPECT_EQ(3U, language_set.size());
it = language_set.begin();
EXPECT_EQ(ENGLISH, *it);
EXPECT_EQ(SPANISH, *++it);
EXPECT_EQ(JAPANESE, *++it);
LanguageUsageMetrics::ParseAcceptLanguages(",", &language_set);
EXPECT_EQ(0U, language_set.size());
LanguageUsageMetrics::ParseAcceptLanguages("ja,", &language_set);
EXPECT_EQ(1U, language_set.size());
EXPECT_EQ(JAPANESE, *language_set.begin());
LanguageUsageMetrics::ParseAcceptLanguages(",es", &language_set);
EXPECT_EQ(1U, language_set.size());
EXPECT_EQ(SPANISH, *language_set.begin());
LanguageUsageMetrics::ParseAcceptLanguages("1234,en", &language_set);
EXPECT_EQ(1U, language_set.size());
it = language_set.begin();
EXPECT_EQ(ENGLISH, *it);
}
TEST(LanguageUsageMetricsTest, ToLanguageCode) {
const int SPANISH = 25971;
const int JAPANESE = 27233;
EXPECT_EQ(JAPANESE, LanguageUsageMetrics::ToLanguageCode("ja"));
EXPECT_EQ(SPANISH, LanguageUsageMetrics::ToLanguageCode("Es"));
EXPECT_EQ(JAPANESE, LanguageUsageMetrics::ToLanguageCode("ja-JP"));
EXPECT_EQ(0, LanguageUsageMetrics::ToLanguageCode(std::string()));
EXPECT_EQ(0, LanguageUsageMetrics::ToLanguageCode("1234"));
EXPECT_EQ(30840, LanguageUsageMetrics::ToLanguageCode("xx"));
}
}