[gtef] testsuite: add basic unit test for GtefActionInfoStore



commit 9f5d7f57d580ebb3d08ddb61f3102f0128a2c57a
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Sat Mar 11 10:14:31 2017 +0100

    testsuite: add basic unit test for GtefActionInfoStore
    
    This is especially useful with the valgrind check, to see if there are
    memory leaks. `make check-valgrind-memcheck` passes for this unit test.

 testsuite/Makefile.am              |    3 ++
 testsuite/test-action-info-store.c |   71 ++++++++++++++++++++++++++++++++++++
 2 files changed, 74 insertions(+), 0 deletions(-)
---
diff --git a/testsuite/Makefile.am b/testsuite/Makefile.am
index 17b905c..7f49531 100644
--- a/testsuite/Makefile.am
+++ b/testsuite/Makefile.am
@@ -24,6 +24,9 @@ noinst_PROGRAMS = $(UNIT_TEST_PROGS)
 TESTS = $(UNIT_TEST_PROGS)
 UNIT_TEST_PROGS =
 
+UNIT_TEST_PROGS += test-action-info-store
+test_action_info_store_SOURCES = test-action-info-store.c
+
 UNIT_TEST_PROGS += test-action-map
 test_action_map_SOURCES = test-action-map.c
 
diff --git a/testsuite/test-action-info-store.c b/testsuite/test-action-info-store.c
new file mode 100644
index 0000000..0e08550
--- /dev/null
+++ b/testsuite/test-action-info-store.c
@@ -0,0 +1,71 @@
+/*
+ * This file is part of Gtef, a text editor library.
+ *
+ * Copyright 2017 - Sébastien Wilmet <swilmet gnome org>
+ *
+ * Gtef is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU Lesser General Public License as published by the
+ * Free Software Foundation; either version 2.1 of the License, or (at your
+ * option) any later version.
+ *
+ * Gtef is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <gtef/gtef.h>
+
+static void
+test_add_entries (void)
+{
+       GtefActionInfoStore *store;
+       GtefActionInfoCentralStore *central_store;
+       const GtefActionInfo *info1;
+       const GtefActionInfo *info2;
+
+       const GtefActionInfoEntry entries[] =
+       {
+               /* action, icon, label, accel, tooltip */
+
+               { "app.quit", "application-exit", "_Quit", "<Control>q",
+                 "Quit the application" },
+
+               /* Tooltip field missing, must be NULL. */
+               { "win.open", "document-open", "_Open", "<Control>o" },
+       };
+
+       store = gtef_action_info_store_new (NULL);
+
+       gtef_action_info_store_add_entries (store,
+                                           entries,
+                                           G_N_ELEMENTS (entries),
+                                           NULL);
+
+       info1 = gtef_action_info_store_lookup (store, "win.open");
+       g_assert (info1 != NULL);
+       g_assert_cmpstr (gtef_action_info_get_icon_name (info1), ==, "document-open");
+       g_assert (gtef_action_info_get_tooltip (info1) == NULL);
+
+       central_store = gtef_action_info_central_store_get_instance ();
+       info2 = gtef_action_info_central_store_lookup (central_store, "win.open");
+       g_assert (info1 == info2);
+
+       info1 = gtef_action_info_store_lookup (store, "plouf");
+       g_assert (info1 == NULL);
+
+       g_object_unref (store);
+}
+
+int
+main (int argc, char **argv)
+{
+       gtk_test_init (&argc, &argv);
+
+       g_test_add_func ("/action-info-store/add-entries", test_add_entries);
+
+       return g_test_run ();
+}


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]