tests: Test restricted result_len sizes for g_unichar_fully_decompose()

This pushes the code coverage of that function up to 100%.

And it found no bugs!

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
This commit is contained in:
Philip Withnall 2024-10-21 19:24:08 +01:00
parent 84e3a9cde9
commit 0125c58a05
No known key found for this signature in database
GPG Key ID: C5C42CFB268637CA

View File

@ -1604,9 +1604,20 @@ test_fully_decompose_canonical (void)
g_test_message ("Fully decomposing U+%06x; expecting %" G_GSIZE_FORMAT " codepoints",
vectors[i].input, vectors[i].expected_len);
len = g_unichar_fully_decompose (vectors[i].input, FALSE, decomp, G_N_ELEMENTS (decomp));
g_assert_cmpmem (decomp, len * sizeof (*decomp),
vectors[i].expected_decomposition, vectors[i].expected_len * sizeof (*vectors[i].expected_decomposition));
/* Test with all possible output array sizes, to check that the function
* can write partial results OK. */
for (size_t j = 0; j <= G_N_ELEMENTS (decomp); j++)
{
len = g_unichar_fully_decompose (vectors[i].input, FALSE, decomp, G_N_ELEMENTS (decomp) - j);
g_assert_cmpuint (len, ==, vectors[i].expected_len);
if (len >= j)
g_assert_cmpmem (decomp, (len - j) * sizeof (*decomp),
vectors[i].expected_decomposition, (vectors[i].expected_len - j) * sizeof (*vectors[i].expected_decomposition));
}
/* And again with no result array at all, just to get the length. */
len = g_unichar_fully_decompose (vectors[i].input, FALSE, NULL, 0);
g_assert_cmpuint (len, ==, vectors[i].expected_len);
}
}