diff options
author | Matthias Clasen <mclasen@redhat.com> | 2020-01-17 16:54:38 -0500 |
---|---|---|
committer | Matthias Clasen <mclasen@redhat.com> | 2020-01-17 23:47:34 -0500 |
commit | cc3cf581ab064f989613116705395f6ce71c6070 (patch) | |
tree | 826c04cda0e0342caeeabc76806550e11a6770e5 /gtk/gtkcssnodedeclaration.c | |
parent | 6e09c5cee8377db9bbcf8dff06ccbcb8557abe1c (diff) | |
download | gtk+-cc3cf581ab064f989613116705395f6ce71c6070.tar.gz |
cssnodedeclaration: Make print output deterministic
This was depending on the memory order of quarks, which
is not a good fit for tests that depend on this output.
Diffstat (limited to 'gtk/gtkcssnodedeclaration.c')
-rw-r--r-- | gtk/gtkcssnodedeclaration.c | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/gtk/gtkcssnodedeclaration.c b/gtk/gtkcssnodedeclaration.c index 6fb7422ae4..0d9a28154d 100644 --- a/gtk/gtkcssnodedeclaration.c +++ b/gtk/gtkcssnodedeclaration.c @@ -431,6 +431,17 @@ gtk_css_node_declaration_add_to_widget_path (const GtkCssNodeDeclaration *decl, gtk_widget_path_iter_set_state (path, pos, decl->state); } +static int +cmpstr (gconstpointer a, + gconstpointer b, + gpointer data) +{ + char **ap = (char **) a; + char **bp = (char **) b; + + return g_ascii_strcasecmp (*ap, *bp); +} + /* Append the declaration to the string, in selector format */ void gtk_css_node_declaration_print (const GtkCssNodeDeclaration *decl, @@ -453,6 +464,7 @@ gtk_css_node_declaration_print (const GtkCssNodeDeclaration *decl, }; const GQuark *classes; guint i; + char **classnames; if (decl->name) g_string_append (string, decl->name); @@ -466,11 +478,19 @@ gtk_css_node_declaration_print (const GtkCssNodeDeclaration *decl, } classes = get_classes (decl); + + classnames = g_new (char *, decl->n_classes); + for (i = 0; i < decl->n_classes; i++) + classnames[i] = (char *)g_quark_to_string (classes[i]); + + g_qsort_with_data (classnames, decl->n_classes, sizeof (char *), cmpstr, NULL); + for (i = 0; i < decl->n_classes; i++) { g_string_append_c (string, '.'); - g_string_append (string, g_quark_to_string (classes[i])); + g_string_append (string, classnames[i]); } + g_free (classnames); for (i = 0; i < G_N_ELEMENTS (state_names); i++) { |