[gtk/prop-list] Add some tests for expression binding
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/prop-list] Add some tests for expression binding
- Date: Sat, 14 Dec 2019 21:52:44 +0000 (UTC)
commit 86d312c7db2c7bf84dd5b61732316a6cc1ffca6d
Author: Matthias Clasen <mclasen redhat com>
Date: Sat Dec 14 15:36:34 2019 -0500
Add some tests for expression binding
These unveil a crash in the handling of @this.
testsuite/gtk/expression.c | 131 +++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 131 insertions(+)
---
diff --git a/testsuite/gtk/expression.c b/testsuite/gtk/expression.c
index 663e0fcbaf..36ff4a24eb 100644
--- a/testsuite/gtk/expression.c
+++ b/testsuite/gtk/expression.c
@@ -414,6 +414,134 @@ test_constant_watch_this_destroyed (void)
g_assert_cmpint (counter, ==, 1);
}
+/* Basic test of gtk_expression_bind */
+static void
+test_bind (void)
+{
+ GtkFilter *filter;
+ GtkFilter *filter2;
+ GtkExpression *expr;
+ GtkExpressionWatch *watch;
+ GValue value = G_VALUE_INIT;
+ gboolean res;
+
+ expr = gtk_property_expression_new (GTK_TYPE_STRING_FILTER, NULL, "search");
+
+ filter = gtk_string_filter_new ();
+ gtk_string_filter_set_search (GTK_STRING_FILTER (filter), "word");
+ g_assert_cmpstr (gtk_string_filter_get_search (GTK_STRING_FILTER (filter)), ==, "word");
+
+ filter2 = gtk_string_filter_new ();
+ gtk_string_filter_set_search (GTK_STRING_FILTER (filter2), "sausage");
+
+ watch = gtk_expression_bind (expr, filter, filter2, "search");
+ gtk_expression_watch_ref (watch);
+
+ gtk_string_filter_set_search (GTK_STRING_FILTER (filter2), "sausage");
+ /* this isn't watched */
+ g_assert_cmpstr (gtk_string_filter_get_search (GTK_STRING_FILTER (filter)), ==, "word");
+ /* even though it is taken into account for evaluation */
+ res = gtk_expression_watch_evaluate (watch, &value);
+ g_assert_true (res);
+ g_assert_cmpstr (g_value_get_string (&value), ==, "sausage");
+
+ g_object_unref (filter);
+ g_object_unref (filter2);
+ gtk_expression_watch_unref (watch);
+}
+
+/* Another test of gtk_expression_bind, this one at least watches the property.
+ * It also test the problematic situation of object == this
+ */
+static void
+test_bind_more (void)
+{
+ GtkFilter *filter;
+ GtkFilter *filter2;
+ GtkExpression *expr;
+
+ filter2 = gtk_string_filter_new ();
+ gtk_string_filter_set_search (GTK_STRING_FILTER (filter2), "sausage");
+
+ expr = gtk_property_expression_new (GTK_TYPE_STRING_FILTER,
+ gtk_constant_expression_new (GTK_TYPE_STRING_FILTER, filter2),
+ "search");
+
+ filter = gtk_string_filter_new ();
+ gtk_string_filter_set_search (GTK_STRING_FILTER (filter), "word");
+ g_assert_cmpstr (gtk_string_filter_get_search (GTK_STRING_FILTER (filter)), ==, "word");
+
+ gtk_expression_bind (expr, filter, filter, "search");
+
+ gtk_string_filter_set_search (GTK_STRING_FILTER (filter2), "sausage");
+ g_assert_cmpstr (gtk_string_filter_get_search (GTK_STRING_FILTER (filter)), ==, "sausage");
+
+ g_object_unref (filter);
+ g_object_unref (filter2);
+}
+
+/* Another test of gtk_expression_bind that exercises the subwatch code paths */
+static void
+test_nested_bind (void)
+{
+ GtkFilter *filter;
+ GtkFilter *filter2;
+ GtkFilter *filter3;
+ GListModel *list;
+ GtkFilterListModel *filtered;
+ GtkExpression *expr;
+ GtkExpression *filter_expr;
+ gboolean res;
+ GValue value = G_VALUE_INIT;
+
+ filter2 = gtk_string_filter_new ();
+ gtk_string_filter_set_search (GTK_STRING_FILTER (filter2), "sausage");
+
+ list = G_LIST_MODEL (g_list_store_new (G_TYPE_OBJECT));
+ filtered = gtk_filter_list_model_new (list, filter2);
+
+ filter_expr = gtk_property_expression_new (GTK_TYPE_FILTER_LIST_MODEL,
+ gtk_object_expression_new (G_OBJECT (filtered)),
+ "filter");
+ expr = gtk_property_expression_new (GTK_TYPE_STRING_FILTER, gtk_expression_ref (filter_expr), "search");
+
+ filter = gtk_string_filter_new ();
+ gtk_string_filter_set_search (GTK_STRING_FILTER (filter), "word");
+ g_assert_cmpstr (gtk_string_filter_get_search (GTK_STRING_FILTER (filter)), ==, "word");
+
+ gtk_expression_bind (gtk_expression_ref (expr), filter, NULL, "search");
+
+ gtk_string_filter_set_search (GTK_STRING_FILTER (filter2), "sausage");
+ g_assert_cmpstr (gtk_string_filter_get_search (GTK_STRING_FILTER (filter)), ==, "sausage");
+
+ filter3 = gtk_string_filter_new ();
+ gtk_string_filter_set_search (GTK_STRING_FILTER (filter3), "banana");
+ gtk_filter_list_model_set_filter (filtered, filter3);
+
+ /* check that the expressions evaluate correctly */
+ res = gtk_expression_evaluate (filter_expr, NULL, &value);
+ g_assert_true (res);
+ g_assert (g_value_get_object (&value) == filter3);
+ g_value_unset (&value);
+
+ res = gtk_expression_evaluate (expr, NULL, &value);
+ g_assert_true (res);
+ g_assert_cmpstr (g_value_get_string (&value), ==, "banana");
+ g_value_unset (&value);
+
+ /* and the bind too */
+ g_assert_cmpstr (gtk_string_filter_get_search (GTK_STRING_FILTER (filter)), ==, "banana");
+
+ g_object_unref (filter);
+ g_object_unref (filter2);
+ g_object_unref (filter3);
+ g_object_unref (filtered);
+ g_object_unref (list);
+
+ gtk_expression_unref (expr);
+ gtk_expression_unref (filter_expr);
+}
+
int
main (int argc, char *argv[])
{
@@ -429,6 +557,9 @@ main (int argc, char *argv[])
g_test_add_func ("/expression/nested-this-destroyed", test_nested_this_destroyed);
g_test_add_func ("/expression/type-mismatch", test_type_mismatch);
g_test_add_func ("/expression/this", test_this);
+ g_test_add_func ("/expression/bind", test_bind);
+ g_test_add_func ("/expression/bind-more", test_bind_more);
+ g_test_add_func ("/expression/nested-bind", test_nested_bind);
return g_test_run ();
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]