Loading...
--- Libc/Libc-1725.40.4/tests/collate.c
+++ Libc/Libc-1583.60.2/tests/collate.c
@@ -1,13 +1,8 @@
-#include <sys/param.h>
-
#include <TargetConditionals.h>
#include <errno.h>
#include <limits.h>
#include <locale.h>
-#include <regex.h>
-#include <stdbool.h>
#include <stdlib.h>
-#include <unistd.h>
#include <xlocale.h>
#include <darwintest.h>
@@ -15,6 +10,8 @@
void __collate_lookup_l(const __darwin_wchar_t *, int *, int *, int *,
locale_t);
void __collate_lookup(const unsigned char *, int *, int *, int *);
+
+#define CHARS_WITHOUT_ENTRIES "\xdf"
/*
* in C or POSIX locales
@@ -84,8 +81,9 @@
__collate_lookup(str, &len, &prim, &sec);
T_ASSERT_EQ_INT(len, (c == '\0' ? 0 : 1), "Only read one character");
str[1] = '\0';
- if (prim == 0 || prim == -1) {
- T_EXPECT_EQ(sec, prim, "0x%x has no secondary weight", c);
+ if (strstr(CHARS_WITHOUT_ENTRIES, str)) {
+ T_EXPECT_EQ(prim, -1, "0x%x is not present in the table", c);
+ T_EXPECT_EQ(sec, -1, "0x%x is not present in the table", c);
} else {
T_EXPECT_GT(prim, 0, "0x%x Has primary weight", c);
T_EXPECT_GT(sec, 0, "0x%x Has secondary weight", c);
@@ -119,8 +117,9 @@
str[0] = c;
__collate_lookup(str, &len, &prim, &sec);
T_ASSERT_EQ_INT(len, 1, "Only read one character");
- if (prim == 0 || prim == -1) {
- T_EXPECT_EQ(sec, prim, "0x%x has no secondary weight", c);
+ if (strstr(CHARS_WITHOUT_ENTRIES, (const char *)str)) {
+ T_EXPECT_EQ(prim, -1, "0x%x is not present in the table", c);
+ T_EXPECT_GT(sec, -1, "0x%x is not present in the table", c);
} else {
T_EXPECT_GT(prim, 0, "0x%x Has primary weight", c);
/* weight will be 0 for sequences that result in mb failure */
@@ -214,8 +213,9 @@
str[0] = wc & 0xFF;
__collate_lookup_l(wcs, &len, &prim, &sec, LC_GLOBAL_LOCALE);
T_ASSERT_EQ_INT(len, 1, "Only read one character");
- if (prim == 0 || prim == -1) {
- T_EXPECT_EQ(sec, prim, "Wide char 0x%x has no secondary weight", wc);
+ if (strstr(CHARS_WITHOUT_ENTRIES, str)) {
+ T_EXPECT_EQ(prim, -1, "0x%x is not present in the table", wc);
+ T_EXPECT_EQ(sec, -1, "0x%x is not present in the table", wc);
} else {
T_EXPECT_GT(prim, 0, "Wide char 0x%x Has primary weight", wc);
T_EXPECT_GT(sec, 0, "Wide char 0x%x Has secondary weight", wc);
@@ -248,8 +248,9 @@
str[0] = wc & 0xFF;
__collate_lookup_l(wcs, &len, &prim, &sec, LC_GLOBAL_LOCALE);
T_ASSERT_EQ_INT(len, 1, "Only read one character");
- if (prim == 0 || prim == -1) {
- T_EXPECT_EQ(sec, prim, "0x%x has no secondary weight", wc);
+ if (strstr(CHARS_WITHOUT_ENTRIES, str)) {
+ T_EXPECT_EQ(prim, -1, "0x%x is not present in the table", wc);
+ T_EXPECT_EQ(sec, -1, "0x%x is not present in the table", wc);
} else {
T_EXPECT_GT(prim, 0, "Wide char 0x%x Has primary weight", wc);
T_EXPECT_GT(sec, 0, "Wide char 0x%x Has secondary weight", wc);
@@ -277,108 +278,3 @@
T_EXPECT_NE(sec, sec2, "Different secondary weight");
#endif
}
-
-static void
-try_one(regex_t *preg, unsigned char ch, bool expected, const char *type)
-{
- unsigned char str[2] = { ch, 0x00 };
- regmatch_t match;
- int error;
-
- error = regexec(preg, (const char *)&str[0], 1, &match, 0);
- T_ASSERT_EQ(error == 0, expected, "Character 0x%x should %s %s",
- ch, expected ? "match" : "not match", type);
-}
-
-T_DECL(collate_equivalence, "Test __collate_lookup() behavior",
- T_META_ENABLED(TARGET_OS_OSX)) {
- regex_t ireg, reg;
- const char *cpatterns[] = { "[[=a=]]", "[[=A=]]", NULL };
- const char *isopatterns[] = { "[[=\xe5=]]", "[[=a=]]", NULL };
- const char *loc;
- int error;
- bool lower, exp, iexp;
-
- loc = setlocale(LC_ALL, "en_US.ISO8859-1");
- T_ASSERT_EQ_STR(loc, "en_US.ISO8859-1", "setlocale en_US.ISO8859-1");
-
- for (const char **pat = isopatterns; *pat != NULL; pat++) {
- T_LOG("Trying pattern '%s', ISO8859-1 locale", *pat);
- error = regcomp(®, *pat, REG_BASIC);
- T_ASSERT_EQ_INT(error, 0, "Regex compilation");
-
- error = regcomp(&ireg, *pat, REG_BASIC | REG_ICASE);
- T_ASSERT_EQ_INT(error, 0, "Case-insensitive regex compilation");
-
- for (unsigned char ch = 0x00; ch < 0xff; ch++) {
- exp = (ch >= 0xe0 && ch < 0xe6) || ch == 'a';
- iexp = exp || (ch >= 0xc0 && ch < 0xc6) || ch == 'A' ||
- ch == 0xaa /* FEMININE_ORDINAL_INDICATOR */;
-
- try_one(®, ch, exp, "sensitively");
- try_one(&ireg, ch, iexp, "insensitively");
- }
-
- regfree(®);
- regfree(&ireg);
- }
-
- loc = setlocale(LC_ALL, "C");
- T_ASSERT_EQ_STR(loc, "C", "setlocale C");
-
- lower = true;
- for (const char **pat = cpatterns; *pat != NULL; pat++) {
- T_LOG("Trying pattern '%s', C locale", *pat);
- error = regcomp(®, *pat, REG_BASIC);
- T_ASSERT_EQ_INT(error, 0, "Regex compilation");
-
- error = regcomp(&ireg, *pat, REG_BASIC | REG_ICASE);
- T_ASSERT_EQ_INT(error, 0, "Case-insensitive regex compilation");
-
- for (unsigned char ch = 0x00; ch < 0xff; ch++) {
- if (lower) {
- exp = ch == 'a';
- iexp = exp || ch == 'A';
- } else {
- exp = ch == 'A';
- iexp = exp || ch == 'a';
- }
-
- try_one(®, ch, exp, "sensitively");
- try_one(&ireg, ch, iexp, "insensitively");
- }
-
- regfree(®);
- regfree(&ireg);
-
- lower = false;
- }
-}
-
-T_DECL(collate_subst_legacy, "Test legacy substitution behavior") {
- char cwdbuf[MAXPATHLEN], *cwd, *localepath;
- const char *curloc;
- int ret;
-
- cwd = getcwd(cwdbuf, sizeof(cwdbuf));
- T_ASSERT_NE_PTR(cwd, NULL, NULL);
-
- ret = asprintf(&localepath, "%s/locales", cwd);
- T_ASSERT_GT(ret, 0, NULL);
-
- T_LOG("Setting PATH_LOCALE to %s", localepath);
- ret = setenv("PATH_LOCALE", localepath, 1);
- T_ASSERT_EQ(ret, 0, NULL);
-
- /* They should not be equivalent in the C locale. */
- setlocale(LC_COLLATE, "C");
- ret = strcoll("ss", "\xdf");
- T_ASSERT_NE(ret, 0, NULL);
-
- curloc = setlocale(LC_COLLATE, "legacy.subst");
- T_ASSERT_EQ_STR(curloc, "legacy.subst", "Set LC_COLLATE to a legacy definition");
-
- ret = strcoll("ss", "\xdf");
- T_ASSERT_EQ(ret, 0, "Compare with substitutions applied");
- free(localepath);
-}