Merge branch 'simplify-tests' into 'master'

Simplify tests

See merge request GNOME/gtk!820
This commit is contained in:
Matthias Clasen 2019-05-05 20:19:13 +00:00
commit 15b8ee4564
13 changed files with 675 additions and 76 deletions

View File

@ -141,8 +141,24 @@ typedef enum {
PROP_KIND_OBJECT,
PROP_KIND_PACKING,
PROP_KIND_CELL_PACKING,
PROP_KIND_LAYOUT
} PropKind;
static PropKind
get_prop_kind (Element *element)
{
g_assert (g_str_equal (element->element_name, "property"));
if (g_str_equal (element->parent->element_name, "packing"))
return PROP_KIND_PACKING;
else if (g_str_equal (element->parent->element_name, "layout"))
return PROP_KIND_LAYOUT;
else if (g_str_equal (element->parent->element_name, "cell-packing"))
return PROP_KIND_CELL_PACKING;
else
return PROP_KIND_OBJECT;
}
/* A number of properties unfortunately can't be omitted even
* if they are nominally set to their default value. In many
* cases, this is due to subclasses not overriding the default
@ -165,6 +181,8 @@ needs_explicit_setting (GParamSpec *pspec,
{ "GtkRadioButton", "draw-indicator", PROP_KIND_OBJECT },
{ "GtkWidget", "hexpand", PROP_KIND_OBJECT },
{ "GtkWidget", "vexpand", PROP_KIND_OBJECT },
{ "GtkGrid", "top-attach", PROP_KIND_LAYOUT },
{ "GtkGrid", "left-attach", PROP_KIND_LAYOUT },
};
gboolean found;
gint k;
@ -179,6 +197,7 @@ needs_explicit_setting (GParamSpec *pspec,
strcmp (pspec->name, props[k].property) == 0 &&
kind == props[k].kind)
{
g_print ("explicit: %s::%s\n", class_name, pspec->name);
found = TRUE;
break;
}
@ -210,6 +229,10 @@ keep_for_rewrite (const char *class_name,
{ "GtkGrid", "top-attach", PROP_KIND_PACKING },
{ "GtkGrid", "width", PROP_KIND_PACKING },
{ "GtkGrid", "height", PROP_KIND_PACKING },
{ "GtkStack", "name", PROP_KIND_PACKING },
{ "GtkStack", "title", PROP_KIND_PACKING },
{ "GtkStack", "icon-name", PROP_KIND_PACKING },
{ "GtkStack", "needs-attention", PROP_KIND_PACKING },
};
gboolean found;
gint k;
@ -225,6 +248,7 @@ keep_for_rewrite (const char *class_name,
strcmp (canonical_name, props[k].property) == 0 &&
kind == props[k].kind)
{
g_print ("keep for rewrite: %s::%s\n", class_name, canonical_name);
found = TRUE;
break;
}
@ -309,6 +333,18 @@ canonicalize_key (gchar *key)
}
}
static struct {
const char *class;
const char *layout_manager;
} layout_managers[] = {
{ "GtkBox", "GtkBoxLayout" },
{ "GtkGrid", "GtkGridLayout" },
{ "GtkFixed", "GtkFixedLayout" },
{ "GtkFileChooserButton", "GtkBinLayout" },
{ "GtkFileChooserWidget", "GtkBinLayout" },
{ "GtkOverlay", "GtkOverlayLayout" }
};
static GParamSpec *
get_property_pspec (MyParserData *data,
const gchar *class_name,
@ -336,9 +372,11 @@ get_property_pspec (MyParserData *data,
case PROP_KIND_OBJECT:
pspec = g_object_class_find_property (class, canonical_name);
break;
case PROP_KIND_PACKING:
pspec = NULL;
break;
case PROP_KIND_CELL_PACKING:
{
GObjectClass *cell_class;
@ -349,6 +387,40 @@ get_property_pspec (MyParserData *data,
g_type_class_unref (cell_class);
}
break;
case PROP_KIND_LAYOUT:
{
int i;
const char *layout_manager = NULL;
pspec = NULL;
for (i = 0; i < G_N_ELEMENTS (layout_managers); i++)
{
if (g_str_equal (layout_managers[i].class, class_name))
{
layout_manager = layout_managers[i].layout_manager;
break;
}
}
if (layout_manager)
{
GtkLayoutManagerClass *layout_manager_class;
layout_manager_class = GTK_LAYOUT_MANAGER_CLASS (g_type_class_ref (g_type_from_name (layout_manager)));
if (layout_manager_class->layout_child_type != G_TYPE_INVALID)
{
GObjectClass *layout_child_class;
layout_child_class = g_type_class_ref (layout_manager_class->layout_child_type);
pspec = g_object_class_find_property (layout_child_class, canonical_name);
g_type_class_unref (layout_child_class);
}
g_type_class_unref (layout_manager_class);
}
}
break;
default:
g_assert_not_reached ();
}
@ -492,11 +564,7 @@ property_is_boolean (Element *element,
int i;
PropKind kind;
if (g_str_equal (element->parent->element_name, "packing"))
kind = PROP_KIND_PACKING;
else
kind = PROP_KIND_OBJECT;
kind = get_prop_kind (element);
class_name = get_class_name (element);
property_name = "";
@ -526,13 +594,7 @@ property_can_be_omitted (Element *element,
GParamSpec *pspec;
PropKind kind;
if (g_str_equal (element->parent->element_name, "packing"))
kind = PROP_KIND_PACKING;
else if (g_str_equal (element->parent->element_name, "cell-packing"))
kind = PROP_KIND_CELL_PACKING;
else
kind = PROP_KIND_OBJECT;
kind = get_prop_kind (element);
class_name = get_class_name (element);
property_name = "";
value_string = element->data;
@ -567,7 +629,8 @@ property_can_be_omitted (Element *element,
const char *kind_str[] = {
"",
"Packing ",
"Cell "
"Cell ",
"Layout "
};
g_printerr (_("%s: %sproperty %s::%s not found\n"),
@ -609,10 +672,7 @@ property_has_been_removed (Element *element,
gint i, k;
PropKind kind;
if (g_str_equal (element->parent->element_name, "packing"))
kind = PROP_KIND_PACKING;
else
kind = PROP_KIND_OBJECT;
kind = get_prop_kind (element);
class_name = get_class_name (element);
property_name = "";
@ -1268,6 +1328,7 @@ rewrite_grid_layout (Element *element,
}
}
/* returns TRUE to remove the element from the parent */
static gboolean
simplify_element (Element *element,
MyParserData *data)
@ -1304,8 +1365,34 @@ simplify_element (Element *element,
property_can_be_omitted (element, data))
return TRUE;
if (data->convert3to4)
return FALSE;
}
static void
simplify_tree (MyParserData *data)
{
simplify_element (data->root, data);
}
static gboolean
rewrite_element (Element *element,
MyParserData *data)
{
GList *l;
l = element->children;
while (l)
{
GList *next = l->next;
Element *child = l->data;
if (rewrite_element (child, data))
{
element->children = g_list_remove (element->children, child);
free_element (child);
}
l = next;
}
if (g_str_equal (element->element_name, "object") &&
g_str_equal (get_class_name (element), "GtkStack"))
rewrite_stack (element, data);
@ -1354,15 +1441,14 @@ simplify_element (Element *element,
if (g_str_equal (element->element_name, "property") &&
property_has_been_removed (element, data))
return TRUE;
}
return FALSE;
}
static void
simplify_tree (MyParserData *data)
rewrite_tree (MyParserData *data)
{
simplify_element (data->root, data);
rewrite_element (data->root, data);
}
/* For properties which have changed their default
@ -1433,7 +1519,6 @@ enhance_element (Element *element,
static void
enhance_tree (MyParserData *data)
{
if (data->convert3to4)
enhance_element (data->root, data);
}
@ -1538,7 +1623,11 @@ simplify_file (const char *filename,
data.builder = gtk_builder_new ();
if (data.convert3to4)
{
enhance_tree (&data);
rewrite_tree (&data);
}
simplify_tree (&data);
dump_tree (&data);

View File

@ -5,7 +5,7 @@ bash = find_program('bash', required : false)
if bash.found()
test_env = environment()
foreach t : ['simplify', 'settings']
foreach t : ['simplify', 'simplify-3to4', 'settings']
if get_option('install-tests')
configure_file(output: t,
input: '@0@.in'.format(t),
@ -44,4 +44,5 @@ if get_option('install-tests')
endforeach
install_subdir('simplify-data', install_dir: testexecdir)
install_subdir('simplify-data-3to4', install_dir: testexecdir)
endif

View File

@ -0,0 +1,31 @@
#! /bin/bash
GTK_BUILDER_TOOL=${GTK_BUILDER_TOOL:-gtk-builder-tool}
TEST_DATA_DIR=${TEST_DATA_DIR:-./simplify-data-3to4}
TEST_RESULT_DIR=${TEST_RESULT_DIR:-/tmp}
shopt -s nullglob
TESTS=( "$TEST_DATA_DIR"/*.ui )
echo "1..${#TESTS[*]}"
I=1
for t in ${TESTS[*]}; do
name=$(basename $t .ui)
expected="$TEST_DATA_DIR/$name.expected"
result="$TEST_RESULT_DIR/$name.out"
diff="$TEST_RESULT_DIR/$name.diff"
ref="$TEST_RESULT_DIR/$name.ref"
$GTK_BUILDER_TOOL simplify --3to4 $t 2>/dev/null >$result
if diff -u "$expected" "$result" > "$diff"; then
echo "ok $I $name"
rm "$diff"
else
echo "not ok $I $name"
cp "$expected" "$ref"
fi
I=$((I+1))
done

View File

@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<object class="GtkAssistant" id="window1">
<property name="type">popup</property>
<child>
<object class="GtkAssistantPage">
<property name="title" translatable="yes">Page 1</property>
<property name="child">
<object class="GtkButton" id="button1">
<property name="label" translatable="yes">Button 1</property>
<property name="can_focus">1</property>
</object>
</property>
</object>
</child>
<child>
<object class="GtkAssistantPage">
<property name="title" translatable="yes">Page 2</property>
<property name="child">
<object class="GtkButton" id="button2">
<property name="label" translatable="yes">Button 2</property>
<property name="can_focus">1</property>
</object>
</property>
</object>
</child>
</object>
</interface>

View File

@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<!-- interface-requires gtk+ 3.0 -->
<object class="GtkAssistant" id="window1">
<property name="can_focus">False</property>
<property name="type">popup</property>
<child>
<object class="GtkButton" id="button1">
<property name="label" translatable="yes">Button 1</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
</object>
<packing>
<property name="title" translatable="yes">Page 1</property>
</packing>
</child>
<child>
<object class="GtkButton" id="button2">
<property name="label" translatable="yes">Button 2</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
</object>
<packing>
<property name="title" translatable="yes">Page 2</property>
</packing>
</child>
</object>
</interface>

View File

@ -0,0 +1,110 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<object class="GtkWindow" id="window1">
<property name="type">popup</property>
<child>
<object class="GtkGrid" id="grid1">
<child>
<object class="GtkToggleButton" id="button1">
<property name="label" translatable="yes">Hello World!</property>
<property name="active">1</property>
<property name="can_focus">1</property>
<property name="receives_default">1</property>
</object>
</child>
<child>
<object class="GtkCheckButton" id="button2">
<property name="label" translatable="yes">Hello World!</property>
<property name="can_focus">1</property>
<property name="receives_default">1</property>
<layout>
<property name="left_attach">1</property>
</layout>
</object>
</child>
<child>
<object class="GtkRadioButton" id="button3">
<property name="label" translatable="yes">Hello World!</property>
<property name="can_focus">1</property>
<property name="receives_default">1</property>
<layout>
<property name="left_attach">2</property>
</layout>
</object>
</child>
<child>
<object class="GtkRadioButton" id="button4">
<property name="label" translatable="yes">Hello World!</property>
<property name="active">1</property>
<property name="group">button3</property>
<property name="can_focus">1</property>
<property name="receives_default">1</property>
<layout>
<property name="left_attach">3</property>
</layout>
</object>
</child>
<child>
<object class="GtkSwitch" id="button5">
<property name="active">1</property>
<property name="can_focus">1</property>
<property name="receives_default">1</property>
<layout>
<property name="left_attach">4</property>
</layout>
</object>
</child>
<child>
<object class="GtkSwitch" id="button6">
<property name="can_focus">1</property>
<property name="receives_default">1</property>
<child internal-child="accessible">
<object class="AtkObject" id="button6-accessible">
<property name="accessible-name">Test switch</property>
</object>
</child>
<layout>
<property name="left_attach">5</property>
</layout>
</object>
</child>
<child>
<object class="GtkButton" id="button7">
<property name="can_focus">1</property>
<property name="receives_default">1</property>
<property name="label">Text Button</property>
<layout>
<property name="top_attach">1</property>
</layout>
</object>
</child>
<child>
<object class="GtkButton" id="button8">
<property name="can_focus">1</property>
<property name="receives_default">1</property>
<property name="halign">center</property>
<property name="valign">center</property>
<layout>
<property name="left_attach">1</property>
<property name="top_attach">1</property>
</layout>
</object>
</child>
<child>
<object class="GtkButton" id="button9">
<property name="can_focus">1</property>
<property name="receives_default">1</property>
<property name="halign">center</property>
<property name="valign">center</property>
<layout>
<property name="left_attach">2</property>
<property name="top_attach">1</property>
<property name="column-span">2</property>
<property name="row-span">2</property>
</layout>
</object>
</child>
</object>
</child>
</object>
</interface>

View File

@ -0,0 +1,138 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<!-- interface-requires gtk+ 3.0 -->
<object class="GtkWindow" id="window1">
<property name="can_focus">False</property>
<property name="type">popup</property>
<child>
<object class="GtkGrid" id="grid1">
<property name="visible">True</property>
<child>
<object class="GtkToggleButton" id="button1">
<property name="label" translatable="yes">Hello World!</property>
<property name="visible">True</property>
<property name="active">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">0</property>
</packing>
</child>
<child>
<object class="GtkCheckButton" id="button2">
<property name="label" translatable="yes">Hello World!</property>
<property name="visible">True</property>
<property name="active">False</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">0</property>
</packing>
</child>
<child>
<object class="GtkRadioButton" id="button3">
<property name="label" translatable="yes">Hello World!</property>
<property name="visible">True</property>
<property name="active">False</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
</object>
<packing>
<property name="left_attach">2</property>
<property name="top_attach">0</property>
</packing>
</child>
<child>
<object class="GtkRadioButton" id="button4">
<property name="label" translatable="yes">Hello World!</property>
<property name="visible">True</property>
<property name="active">True</property>
<property name="group">button3</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
</object>
<packing>
<property name="left_attach">3</property>
<property name="top_attach">0</property>
</packing>
</child>
<child>
<object class="GtkSwitch" id="button5">
<property name="visible">True</property>
<property name="active">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
</object>
<packing>
<property name="left_attach">4</property>
<property name="top_attach">0</property>
</packing>
</child>
<child>
<object class="GtkSwitch" id="button6">
<property name="visible">True</property>
<property name="active">False</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<child internal-child="accessible">
<object class="AtkObject" id="button6-accessible">
<property name="accessible-name">Test switch</property>
</object>
</child>
</object>
<packing>
<property name="left_attach">5</property>
<property name="top_attach">0</property>
</packing>
</child>
<child>
<object class="GtkButton" id="button7">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="label">Text Button</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">1</property>
</packing>
</child>
<child>
<object class="GtkButton" id="button8">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="halign">center</property>
<property name="valign">center</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">1</property>
<property name="width">1</property>
<property name="height">1</property>
</packing>
</child>
<child>
<object class="GtkButton" id="button9">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="halign">center</property>
<property name="valign">center</property>
</object>
<packing>
<property name="left_attach">2</property>
<property name="top_attach">1</property>
<property name="width">2</property>
<property name="height">2</property>
</packing>
</child>
</object>
</child>
</object>
</interface>

View File

@ -0,0 +1,38 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<object class="GtkWindow" id="window1">
<property name="type">popup</property>
<child>
<object class="GtkNotebook" id="notebook1">
<child>
<object class="GtkNotebookPage">
<property name="child">
<object class="GtkButton" id="page1">
<property name="label" translatable="yes">Yes</property>
</object>
</property>
<property name="tab">
<object class="GtkLabel" id="tab1">
<property name="label" translatable="yes">Tab 1</property>
</object>
</property>
</object>
</child>
<child>
<object class="GtkNotebookPage">
<property name="child">
<object class="GtkButton" id="page2">
<property name="label" translatable="yes">No</property>
</object>
</property>
<property name="tab">
<object class="GtkLabel" id="tab2">
<property name="label" translatable="yes">Tab 2</property>
</object>
</property>
</object>
</child>
</object>
</child>
</object>
</interface>

View File

@ -0,0 +1,37 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<!-- interface-requires gtk+ 3.0 -->
<object class="GtkWindow" id="window1">
<property name="can_focus">False</property>
<property name="type">popup</property>
<child>
<object class="GtkNotebook" id="notebook1">
<property name="visible">True</property>
<child>
<object class="GtkButton" id="page1">
<property name="label" translatable="yes">Yes</property>
<property name="visible">True</property>
</object>
</child>
<child type="tab">
<object class="GtkLabel" id="tab1">
<property name="label" translatable="yes">Tab 1</property>
<property name="visible">True</property>
</object>
</child>
<child>
<object class="GtkButton" id="page2">
<property name="label" translatable="yes">No</property>
<property name="visible">True</property>
</object>
</child>
<child type="tab">
<object class="GtkLabel" id="tab2">
<property name="label" translatable="yes">Tab 2</property>
<property name="visible">True</property>
</object>
</child>
</object>
</child>
</object>
</interface>

View File

@ -0,0 +1,43 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<object class="GtkWindow" id="window1">
<property name="type">popup</property>
<child>
<object class="GtkBox" id="box1">
<child>
<object class="GtkStackSwitcher" id="stackswitcher1">
<property name="stack">stack1</property>
</object>
</child>
<child>
<object class="GtkStack" id="stack1">
<child>
<object class="GtkStackPage">
<property name="name">page1</property>
<property name="title">Page 1</property>
<property name="needs-attention">1</property>
<property name="child">
<object class="GtkButton" id="page1">
<property name="label" translatable="yes">Yes</property>
</object>
</property>
</object>
</child>
<child>
<object class="GtkStackPage">
<property name="name">page2</property>
<property name="title">Page 2</property>
<property name="icon-name">page2-icon</property>
<property name="child">
<object class="GtkButton" id="page2">
<property name="label" translatable="yes">No</property>
</object>
</property>
</object>
</child>
</object>
</child>
</object>
</child>
</object>
</interface>

View File

@ -0,0 +1,46 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<!-- interface-requires gtk+ 3.0 -->
<object class="GtkWindow" id="window1">
<property name="can_focus">False</property>
<property name="type">popup</property>
<child>
<object class="GtkBox" id="box1">
<property name="visible">True</property>
<child>
<object class="GtkStackSwitcher" id="stackswitcher1">
<property name="visible">True</property>
<property name="stack">stack1</property>
</object>
</child>
<child>
<object class="GtkStack" id="stack1">
<property name="visible">True</property>
<child>
<object class="GtkButton" id="page1">
<property name="label" translatable="yes">Yes</property>
<property name="visible">True</property>
</object>
<packing>
<property name="name">page1</property>
<property name="title">Page 1</property>
<property name="needs-attention">1</property>
</packing>
</child>
<child>
<object class="GtkButton" id="page2">
<property name="label" translatable="yes">No</property>
<property name="visible">True</property>
</object>
<packing>
<property name="name">page2</property>
<property name="title">Page 2</property>
<property name="icon-name">page2-icon</property>
</packing>
</child>
</object>
</child>
</object>
</child>
</object>
</interface>

View File

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<object class="GtkWindow">
<child>
<object class="GtkLabel">
<property name="visible">0</property>
</object>
</child>
</object>
</interface>

View File

@ -7,7 +7,7 @@ TEST_RESULT_DIR=${TEST_RESULT_DIR:-/tmp}
shopt -s nullglob
TESTS=( "$TEST_DATA_DIR"/*.ui )
echo "1..${#TESTS}"
echo "1..${#TESTS[*]}"
I=1
for t in ${TESTS[*]}; do