fs/unicode/tests/utf8_kunit.c

Source file repositories/reference/linux-study-clean/fs/unicode/tests/utf8_kunit.c

File Facts

System
Linux kernel
Corpus path
fs/unicode/tests/utf8_kunit.c
Extension
.c
Size
8402 bytes
Lines
298
Domain
Core OS
Bucket
VFS And Filesystem Core
Inferred role
Core OS: implementation source
Status
source implementation candidate

Why This File Exists

Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.

Dependency Surface

Detected Declarations

Annotated Snippet

while ((c = utf8byte(&u8c)) > 0) {
			KUNIT_EXPECT_EQ_MSG(test, c, nfdi_test_data[i].dec[j],
					    "Unexpected byte 0x%x should be 0x%x\n",
					    c, nfdi_test_data[i].dec[j]);
			j++;
		}

		KUNIT_EXPECT_EQ(test, j, nlen);
	}
}

static void check_utf8_nfdicf(struct kunit *test)
{
	int i;
	struct utf8cursor u8c;
	struct unicode_map *um = test->priv;

	for (i = 0; i < ARRAY_SIZE(nfdicf_test_data); i++) {
		int len = strlen(nfdicf_test_data[i].str);
		int nlen = strlen(nfdicf_test_data[i].ncf);
		int j = 0;
		int ret;
		unsigned char c;

		KUNIT_EXPECT_EQ(test, utf8len(um, UTF8_NFDICF, nfdicf_test_data[i].str),
				nlen);
		KUNIT_EXPECT_EQ(test, utf8nlen(um, UTF8_NFDICF, nfdicf_test_data[i].str, len),
				nlen);

		ret = utf8cursor(&u8c, um, UTF8_NFDICF, nfdicf_test_data[i].str);
		KUNIT_EXPECT_TRUE_MSG(test, ret >= 0, "Can't create cursor\n");

		while ((c = utf8byte(&u8c)) > 0) {
			KUNIT_EXPECT_EQ_MSG(test, c, nfdicf_test_data[i].ncf[j],
					    "Unexpected byte 0x%x should be 0x%x\n",
					    c, nfdicf_test_data[i].ncf[j]);
			j++;
		}

		KUNIT_EXPECT_EQ(test, j, nlen);
	}
}

static void check_utf8_comparisons(struct kunit *test)
{
	int i;
	struct unicode_map *um = test->priv;

	for (i = 0; i < ARRAY_SIZE(nfdi_test_data); i++) {
		const struct qstr s1 = {.name = nfdi_test_data[i].str,
					.len = sizeof(nfdi_test_data[i].str)};
		const struct qstr s2 = {.name = nfdi_test_data[i].dec,
					.len = sizeof(nfdi_test_data[i].dec)};

		/* strncmp returns 0 when strings are equal */
		KUNIT_EXPECT_TRUE_MSG(test, utf8_strncmp(um, &s1, &s2) == 0,
				    "%s %s comparison mismatch\n", s1.name, s2.name);
	}

	for (i = 0; i < ARRAY_SIZE(nfdicf_test_data); i++) {
		const struct qstr s1 = {.name = nfdicf_test_data[i].str,
					.len = sizeof(nfdicf_test_data[i].str)};
		const struct qstr s2 = {.name = nfdicf_test_data[i].ncf,
					.len = sizeof(nfdicf_test_data[i].ncf)};

		/* strncasecmp returns 0 when strings are equal */
		KUNIT_EXPECT_TRUE_MSG(test, utf8_strncasecmp(um, &s1, &s2) == 0,
				    "%s %s comparison mismatch\n", s1.name, s2.name);
	}
}

static void check_supported_versions(struct kunit *test)
{
	struct unicode_map *um = test->priv;
	/* Unicode 7.0.0 should be supported. */
	KUNIT_EXPECT_TRUE(test, utf8version_is_supported(um, UNICODE_AGE(7, 0, 0)));

	/* Unicode 9.0.0 should be supported. */
	KUNIT_EXPECT_TRUE(test, utf8version_is_supported(um, UNICODE_AGE(9, 0, 0)));

	/* Unicode 1x.0.0 (the latest version) should be supported. */
	KUNIT_EXPECT_TRUE(test, utf8version_is_supported(um, UTF8_LATEST));

	/* Next versions don't exist. */
	KUNIT_EXPECT_FALSE(test, utf8version_is_supported(um, UNICODE_AGE(13, 0, 0)));
	KUNIT_EXPECT_FALSE(test, utf8version_is_supported(um, UNICODE_AGE(0, 0, 0)));
	KUNIT_EXPECT_FALSE(test, utf8version_is_supported(um, UNICODE_AGE(-1, -1, -1)));
}

static struct kunit_case unicode_normalization_test_cases[] = {

Annotation

Implementation Notes