]> saetta.ns0.it Git - zakform/tests/commitdiff
Added test for ZakFormElement::get_validators and ::get_validators_by_type.
authorAndrea Zagli <azagli@libero.it>
Sat, 28 Jan 2017 10:54:26 +0000 (11:54 +0100)
committerAndrea Zagli <azagli@libero.it>
Sat, 28 Jan 2017 10:54:26 +0000 (11:54 +0100)
.gitignore
src/Makefile.am
src/get_element_validators.c [new file with mode: 0644]

index d16a8ba4f375761ae5ca2288f4e92520ca05b7a8..bbf1b2e41c631bbecbeab8ab1847bfe6303b65c4 100644 (file)
@@ -53,6 +53,7 @@ Rules-quot
 cgi_ini
 get_elements
 get_element_filters
+get_element_validators
 get_validators
 gtk_gdaex
 gtk_ini
\ No newline at end of file
index 752b5df0d1f112392fdad88a2ea736e105ad0b96..7252f5f4657e2369afa4c91536a0be2d20dcc55d 100644 (file)
@@ -11,6 +11,7 @@ noinst_PROGRAMS = \
                   cgi_ini \
                   get_elements \
                   get_element_filters \
+                  get_element_validators \
                   get_validators \
                   gtk_gdaex \
                   gtk_ini
diff --git a/src/get_element_validators.c b/src/get_element_validators.c
new file mode 100644 (file)
index 0000000..005fc96
--- /dev/null
@@ -0,0 +1,74 @@
+/*
+ * Copyright (C) 2017 Andrea Zagli <azagli@libero.it>
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program 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 General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+       #include <config.h>
+#endif
+
+#include <glib/gprintf.h>
+
+#include <libzakform/libzakform.h>
+#include <libzakformgtk/libzakformgtk.h>
+
+ZakFormGtkForm *form;
+
+int
+main (int argc, char *argv[])
+{
+       GtkBuilder *builder;
+
+       ZakFormElement *element;
+       GPtrArray *ar;
+       guint i;
+
+       gtk_init (&argc, &argv);
+
+       builder = gtk_builder_new ();
+       gtk_builder_add_objects_from_file (builder, GUIDIR "/main.ui",
+                                                                          g_strsplit ("w_main"
+                                                                                                  "|adjustment1", "|", -1), NULL);
+
+       form = zak_form_gtk_form_new ();
+       zak_form_gtk_form_set_gtkbuilder (form, builder);
+       zak_form_form_load_from_file (ZAK_FORM_FORM (form), XMLDIR "/main.xml");
+       zak_form_form_clear (ZAK_FORM_FORM (form));
+       zak_form_form_set_as_original (ZAK_FORM_FORM (form));
+
+       element = zak_form_form_get_element_by_id (ZAK_FORM_FORM (form), "name");
+       ar = zak_form_element_get_validators (element);
+
+       g_printf ("GET ELEMENT VALIDATORS (%d validators):\n"
+                         "---------------------------------\n", ar->len);
+       for (i = 0; i < ar->len; i++)
+               {
+                       g_printf ("- %s\n", G_OBJECT_TYPE_NAME ((ZakFormElementValidator *)g_ptr_array_index (ar, i)));
+               }
+
+       ar = zak_form_element_get_validators_by_type (element, ZAK_FORM_TYPE_ELEMENT_VALIDATOR_NOTEMPTY);
+
+       g_printf ("\nGET ELEMENT VALIDATORS BY TYPE: ZAK_FORM_TYPE_ELEMENT_VALIDATOR_NOTEMPTY  (%d validators):\n"
+                         "------------------------------\n", ar->len);
+       for (i = 0; i < ar->len; i++)
+               {
+                       g_printf ("- %s\n", G_OBJECT_TYPE_NAME ((ZakFormElementValidator *)g_ptr_array_index (ar, i)));
+               }
+
+       g_ptr_array_free (ar, FALSE);
+
+       return 0;
+}