}
locale_t newlocale(int category_mask, const char* locale_name, locale_t /*base*/) {
- // Is 'category_mask' valid?
- if ((category_mask & ~LC_ALL_MASK) != 0) {
+ // Are 'category_mask' and 'locale_name' valid?
+ if ((category_mask & ~LC_ALL_MASK) != 0 || locale_name == NULL) {
errno = EINVAL;
return NULL;
}
EXPECT_EQ(ENOENT, errno); // POSIX specified, not an implementation detail!
}
-TEST(locale, newlocale) {
+TEST(locale, newlocale_invalid_category_mask) {
errno = 0;
EXPECT_EQ(0, newlocale(1 << 20, "C", 0));
EXPECT_EQ(EINVAL, errno);
+}
- locale_t l = newlocale(LC_ALL, "C", 0);
- ASSERT_TRUE(l != NULL);
- freelocale(l);
+TEST(locale, newlocale_NULL_locale_name) {
+ errno = 0;
+ EXPECT_EQ(0, newlocale(LC_ALL, NULL, 0));
+ EXPECT_EQ(EINVAL, errno);
+}
+TEST(locale, newlocale_bad_locale_name) {
errno = 0;
EXPECT_EQ(0, newlocale(LC_ALL, "this-is-not-a-locale", 0));
EXPECT_EQ(ENOENT, errno); // POSIX specified, not an implementation detail!
}
+TEST(locale, newlocale) {
+ locale_t l = newlocale(LC_ALL, "C", 0);
+ ASSERT_TRUE(l != NULL);
+ freelocale(l);
+}
+
TEST(locale, duplocale) {
locale_t cloned_global = duplocale(LC_GLOBAL_LOCALE);
ASSERT_TRUE(cloned_global != NULL);