]> saetta.ns0.it Git - zakform/tests/commitdiff
Added test to load cgi from ini.
authorAndrea Zagli <azagli@libero.it>
Sun, 25 Jun 2017 11:05:49 +0000 (13:05 +0200)
committerAndrea Zagli <azagli@libero.it>
Sun, 25 Jun 2017 11:05:49 +0000 (13:05 +0200)
src/cgi_ini.c

index 9d0465da10b8eb7cc81b8aa434671b5e905f0759..bbe5d4d4eeb70cd372e2472c9ebdfb1b98f57e60 100644 (file)
@@ -37,6 +37,7 @@ main (int argc, char *argv[])
 
        GValue *val;
        gchar *filename;
+       gint id;
 
        ZakFormCgiForm *form;
 
@@ -61,7 +62,24 @@ main (int argc, char *argv[])
                                                "<div class=\"container\">\n");
 
        val = zak_cgi_main_get_parameter (zakcgimain, "filename");
-       filename = (gchar *)g_value_get_string (val);
+       if (val != NULL)
+               {
+                       filename = (gchar *)g_value_get_string (val);
+               }
+       else
+               {
+                       filename = g_strdup ("");
+               }
+
+       val = zak_cgi_main_get_parameter (zakcgimain, "id");
+       if (val != NULL)
+               {
+                       id = strtol (g_value_get_string (val), NULL, 10);
+               }
+       else
+               {
+                       id = 0;
+               }
 
        form = zak_form_cgi_form_new (zakcgimain,
                                                         "method", "post",
@@ -72,7 +90,6 @@ main (int argc, char *argv[])
                {
                        if (zak_cgi_main_is_post (zakcgimain))
                                {
-                                       sleep(10);
                                        /* validating the form */
                                        zak_form_cgi_form_bind (form);
                                        if (zak_form_form_is_valid (ZAK_FORM_FORM (form)))
@@ -112,6 +129,17 @@ main (int argc, char *argv[])
                        else
                                {
                                        zak_form_form_clear (ZAK_FORM_FORM (form));
+                                       if (id > 0)
+                                               {
+                                                       zak_form_element_set_value (zak_form_form_get_element_by_id (ZAK_FORM_FORM (form), "id"), g_strdup_printf ("%d", id));
+
+                                                       provider = zak_form_ini_provider_new_from_file (filename);
+                                                       if (provider != NULL)
+                                                               {
+                                                                       zak_form_form_load (ZAK_FORM_FORM (form), ZAK_FORM_IPROVIDER (provider));
+                                                                       g_object_unref (provider);
+                                                               }
+                                               }
                                        g_string_append (str, zak_form_cgi_form_render (form));
                                }
                }