]> saetta.ns0.it Git - reptool/libreptool/commitdiff
Added command line arguments to test_rptreport (refs #178).
authorAndrea Zagli <azagli@libero.it>
Wed, 2 Nov 2011 16:46:39 +0000 (17:46 +0100)
committerAndrea Zagli <azagli@libero.it>
Wed, 2 Nov 2011 16:46:39 +0000 (17:46 +0100)
TODO
tests/test_rptprint.c
tests/test_rptreport.c

diff --git a/TODO b/TODO
index 842bfa76b3bc757c54aca23fd694ad2c64868670..ebf72b3528e8425ef3dcb419b344877f93ac4104 100644 (file)
--- a/TODO
+++ b/TODO
@@ -1,11 +1,3 @@
-- visibile
-- nascondi duplicati
-- espandibile
-- riducibile
-- ombra
 - interruzione di pagina (solo nel corpo???)
 - stampa sezione unita
-- attributi template
-- attributi globali
-- watermark
 
index d0c1fbe85c4bf10123de2ada7e985758d2111061..8b56093f3ef470bdeabf6a33fe3a736adf15c6ff 100644 (file)
@@ -44,9 +44,10 @@ main (int argc, char **argv)
        g_option_context_add_main_entries (context, entries, NULL);
 
        error = NULL;
-       if (!g_option_context_parse (context, &argc, &argv, &error))
+       if (!g_option_context_parse (context, &argc, &argv, &error)
+           || error != NULL)
                {
-                       g_error ("option parsing failed: %s\n", error->message);
+                       g_error ("Option parsing failed: %s.", error != NULL && error->message != NULL ? error->message : "no details");
                        return 0;
                }
 
@@ -55,9 +56,20 @@ main (int argc, char **argv)
        if (rptp != NULL)
                {
                        rpt_print_set_output_type (rptp, rpt_common_stroutputtype_to_enum (output_type));
-                       rpt_print_set_output_filename (rptp, output_file_name == NULL ? "test.out" : output_file_name);
+                       if (g_strcmp0 (output_type, "png") == 0
+                           || g_strcmp0 (output_type, "pdf") == 0
+                           || g_strcmp0 (output_type, "ps") == 0
+                           || g_strcmp0 (output_type, "svg") == 0)
+                               {
+                                       rpt_print_set_output_filename (rptp, output_file_name == NULL ? g_strdup_printf ("test.%s", output_type) : output_file_name);
+                               }
                        rpt_print_print (rptp, NULL);
                }
+       else
+               {
+                       g_error ("Error on creating RptPrint object.");
+                       return 0;
+               }
 
        return 0;
 }
index cb9066c0aebef56aae32af86dc6ab3b811abafeb..2cb7c798106b161b28e89e0b2620210ff57be728 100644 (file)
 #include <rptreport.h>
 #include <rptprint.h>
 
+static gchar *rpt_file_name = NULL;
+static gchar *xml_rpt_file_name = NULL;
+static gchar *xml_rptr_file_name = NULL;
+static gchar *path_relatives_to  = NULL;
+static gchar *output_type = NULL;
+static gchar *output_file_name = NULL;
+
+static GOptionEntry entries[] =
+{
+       { "rpt-file-name", 'r', 0, G_OPTION_ARG_STRING, &rpt_file_name, "RptReport definition file name", "RPT_FILE_NAME" },
+       { "xml-report-file-name", 'x', 0, G_OPTION_ARG_FILENAME, &xml_rpt_file_name, "RptReport xml output file name", "FILE-NAME" },
+       { "xml-print-file-name", 'p', 0, G_OPTION_ARG_FILENAME, &xml_rptr_file_name, "RptPrint xml output file name", "FILE-NAME" },
+       { "path-relatives-to", 't', 0, G_OPTION_ARG_FILENAME, &path_relatives_to, "Path relatives to", "FILE-NAME" },
+       { "output-type", 'o', 0, G_OPTION_ARG_STRING, &output_type, "Output type (png | pdf | ps | svg | gtk | gtk-default)", "OUTPUT-TYPE" },
+       { "output-file-name", 'f', 0, G_OPTION_ARG_FILENAME, &output_file_name, "Output file name", "FILE-NAME" },
+       { NULL }
+};
+
 gchar
 *field_request (RptReport *rpt_report,
                 gchar *field_name,
@@ -49,35 +67,70 @@ gchar
 int
 main (int argc, char **argv)
 {
+       GError *error;
+       GOptionContext *context;
+
        RptReport *rptr;
        RptPrint *rptp;
 
        g_type_init ();
 
-       rptr = rpt_report_new_from_file (argv[1]);
+       context = g_option_context_new ("- test rptprint");
+       g_option_context_add_main_entries (context, entries, NULL);
+
+       error = NULL;
+       if (!g_option_context_parse (context, &argc, &argv, &error)
+           || error != NULL)
+               {
+                       g_error ("Option parsing failed: %s.", error != NULL && error->message != NULL ? error->message : "no details");
+                       return 0;
+               }
+
+       rptr = rpt_report_new_from_file (rpt_file_name);
+       if (rptr == NULL)
+               {
+                       g_error ("Error on creating RptReport object.");
+                       return 0;
+               }
 
        g_signal_connect (rptr, "field-request", G_CALLBACK (field_request), NULL);
 
        if (rptr != NULL)
                {
                        xmlDoc *report = rpt_report_get_xml (rptr);
-                       xmlSaveFormatFile ("test_report.rpt", report, 2);
+                       if (xml_rpt_file_name != NULL)
+                               {
+                                       xmlSaveFormatFileEnc (xml_rpt_file_name, report, "UTF-8", 2);
+                               }
 
                        xmlDoc *rptprint = rpt_report_get_xml_rptprint (rptr);
-                       xmlSaveFormatFile ("test_report.rptr", rptprint, 2);
-               
+                       if (xml_rptr_file_name)
+                               {
+                                       xmlSaveFormatFileEnc (xml_rptr_file_name, rptprint, "UTF-8", 2);
+                               }
+
                        rptp = rpt_print_new_from_xml (rptprint);
                        if (rptp != NULL)
                                {
-                                       g_object_set (G_OBJECT (rptp), "path-relatives-to", "..", NULL);
+                                       if (path_relatives_to != NULL)
+                                               {
+                                                       g_object_set (G_OBJECT (rptp), "path-relatives-to", path_relatives_to, NULL);
+                                               }
 
-                                       rpt_print_set_output_type (rptp, RPT_OUTPUT_PDF);
-                                       rpt_print_set_output_filename (rptp, "test.pdf");
+                                       rpt_print_set_output_type (rptp, rpt_common_stroutputtype_to_enum (output_type));
+                                       if (g_strcmp0 (output_type, "png") == 0
+                                           || g_strcmp0 (output_type, "pdf") == 0
+                                           || g_strcmp0 (output_type, "ps") == 0
+                                           || g_strcmp0 (output_type, "svg") == 0)
+                                               {
+                                                       rpt_print_set_output_filename (rptp, output_file_name == NULL ? g_strdup_printf ("test.%s", output_type) : output_file_name);
+                                               }
                                        rpt_print_print (rptp, NULL);
                                }
                        else
                                {
-                                       g_warning ("Error on creating RptPrint.");
+                                       g_error ("Error on creating RptPrint object.");
+                                       return 0;
                                }
                }