/*
 * Testcase for bug# :
 *  1) create horizontal separator
 *  2) get it's style context and add a simple css style provider
 *  3) get the "padding" style & print it
 *  4) change the orientation to vertical
 *      - adds vertical style class, removes horizontal style class
 *  5) get the "padding" style & print it
 *  6) change the separator orientation back to horizontal
 *      - adds horizontal style class, removes vertical style class
 *  7) get the "padding" style & print it
 *
 *  The last "padding" get should retrieve values corresponding to the
 *   horizontal style class but instead retrieves the stale vertical padding
 *   values.
 */

#include <gtk/gtk.h>

int main(int argc, char** argv)
{
    GtkCssProvider  *provider;
    GtkWidget       *separator;
    GtkBorder        padding;
    GtkStyleContext *context;
    GtkStateFlags    state;

    const gchar styling[] = "GtkSeparator.horizontal { padding: 10 9 8 7; }\n"
                            "GtkSeparator.vertical { padding: 5 4 3 2; }\n";


    gtk_init(&argc, &argv);

    separator = gtk_separator_new(GTK_ORIENTATION_HORIZONTAL);
    context = gtk_widget_get_style_context(separator);

    provider = gtk_css_provider_new();
    gtk_css_provider_load_from_data(provider, styling, -1, NULL);
    gtk_style_context_add_provider(context, GTK_STYLE_PROVIDER(provider),
                                   GTK_STYLE_PROVIDER_PRIORITY_THEME);

    state = gtk_widget_get_state_flags(separator);
    gtk_style_context_get_padding(context, state, &padding);

    g_debug ("As expected: horizontal padding = %d %d %d %d",
                                                padding.top, padding.right,
                                                padding.bottom, padding.left);

    gtk_orientable_set_orientation(GTK_ORIENTABLE(separator),
    							   GTK_ORIENTATION_VERTICAL);
    gtk_style_context_get_padding(context, state, &padding);
    g_debug ("As expected: vertical padding = %d %d %d %d",
                                                padding.top, padding.right,
                                                padding.bottom, padding.left);

    /* Not only does style reset build the correct widget_path but it also
     *  flushes the style_data lookaside -- now the style_data will be rebuilt
     *  from scratch on the next style_data_lookup -- and expose the problem
     */
    gtk_widget_reset_style(separator);

    /* gtk_orientable_set_orientation adds the "horizontal" style class and
     *  removes the "vertical" style class. Note that both
     *  gtk_style_context_add_class & gtk_style_context_remove_class modify
     *  *only* the StyleInfo in the context and *not* the style classes in
     *  the widget_path element corresponding to this style context.
     */
    gtk_orientable_set_orientation(GTK_ORIENTABLE(separator),
                                   GTK_ORIENTATION_HORIZONTAL);

    /* Because the cached style_data was invalidated by the style class
     *  changes, the style_data is rebuilt when style_data_lookup is next
     *  called. So, in create_query_path, when all the current style classes
     *  from the context are added to the widget_path, the old style
     *  classes which were removed from the context are still in the
     *  widget_path element.
     */
    gtk_style_context_get_padding(context, state, &padding);


    g_debug ("What??: horizontal padding = %d %d %d %d",
                                                padding.top, padding.right,
                                                padding.bottom, padding.left);

    return 0;
}
