mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-11-06 17:36:14 +01:00
tests: Add some additional pattern_coalesce() tests
The first of these tests is to cover the extreme case where the number of bytes written out by `pattern_coalesce()` is as close to `strlen (left) + strlen (right)` as we can manage, due to both inputs being really small and hence `max (strlen (left), strlen (right))` being only 1 less than `strlen (left) + strlen (right)`, which is as close as we can get to triggering an off-by-one error. The second of these tests is an attempt to encode the case used in the proof for correctness of `pattern_coalesce()` not overflowing its buffer bounds: `(*(iii)) + ((iii)*) = ((iii)(iii))`. I don’t think it’s actually possible to hit that case, as it’s not possible to generate a plain `*` in either of the input patterns. `Ma*` is the best we can manage in practice. See https://gitlab.gnome.org/GNOME/glib/-/issues/3469#note_2226901 for reasoning. Signed-off-by: Philip Withnall <pwithnall@gnome.org> Helps: #3469
This commit is contained in:
parent
1cb682b320
commit
c7e3512902
@ -4025,6 +4025,29 @@ test_parses (void)
|
||||
g_variant_unref (value);
|
||||
}
|
||||
|
||||
/* pattern coalesce of `u` and `u` is `u`; this operates close to the string
|
||||
* length bounds in pattern_coalesce() */
|
||||
{
|
||||
GVariant *value = NULL;
|
||||
GError *error = NULL;
|
||||
|
||||
value = g_variant_parse (NULL, "[@u 5, @u 15]", NULL, NULL, &error);
|
||||
g_assert_no_error (error);
|
||||
g_assert_cmpstr (g_variant_get_type_string (value), ==, "au");
|
||||
g_variant_unref (value);
|
||||
}
|
||||
|
||||
/* pattern coalesce of `(Ma*Ma(iii))` and `(Ma(iii)Ma*)` is `(Ma(iii)Ma(iii))` */
|
||||
{
|
||||
GVariant *value = NULL;
|
||||
GError *error = NULL;
|
||||
|
||||
value = g_variant_parse (NULL, "[([], [(1,2,3)]), ([(1,2,3)], [])]", NULL, NULL, &error);
|
||||
g_assert_no_error (error);
|
||||
g_assert_cmpstr (g_variant_get_type_string (value), ==, "a(a(iii)a(iii))");
|
||||
g_variant_unref (value);
|
||||
}
|
||||
|
||||
#ifndef _MSC_VER
|
||||
/* inf/nan strings are C99 features which Visual C++ does not support */
|
||||
/* inf/nan mini test */
|
||||
|
Loading…
Reference in New Issue
Block a user