From df9595cc52dd9182fc8e3c1f21702f1ffba6dcc8 Mon Sep 17 00:00:00 2001 From: Andrea Zagli Date: Sat, 26 Dec 2015 10:32:12 +0100 Subject: [PATCH] Aggiunto il test di TerritorioComune::get_by_id. --- .gitignore | 1 + tests/Makefile.am | 6 ++- tests/comune_by_id.c | 116 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 121 insertions(+), 2 deletions(-) create mode 100644 tests/comune_by_id.c diff --git a/.gitignore b/.gitignore index e8d6505..7896823 100644 --- a/.gitignore +++ b/.gitignore @@ -26,5 +26,6 @@ missing .libs stamp-h1 *exe +tests/comune_by_id tests/widget compile diff --git a/tests/Makefile.am b/tests/Makefile.am index 1cf865d..4347489 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -10,8 +10,10 @@ AM_CPPFLAGS = $(TERRITORIO_CFLAGS) \ -DGUIDIR=\""$(guidir)"\" \ -DFORMDIR=\""$(formdir)"\" -noinst_PROGRAMS = widget +noinst_PROGRAMS = \ + comune_by_id \ + widget LDADD = $(top_builddir)/libreria/libterritorio.la -EXTRA_DIST = +EXTRA_DIST = diff --git a/tests/comune_by_id.c b/tests/comune_by_id.c new file mode 100644 index 0000000..36b3291 --- /dev/null +++ b/tests/comune_by_id.c @@ -0,0 +1,116 @@ +/* + * Copyright (C) 2015 Andrea Zagli + * + * 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. + */ + +#include +#include + +#include "commons.h" +#include "comune.h" + +static GKeyFile *config; + +static TerritorioCommons *commons; + +int +main (int argc, char **argv) +{ + GError *error; + + gchar *cnc_string; + + gtk_init (&argc, &argv); + + /* leggo la configurazione dal file */ + if (argc == 1) + { + g_error ("Occorre passare a riga di comando il file di configurazione."); + } + + error = NULL; + config = g_key_file_new (); + if (!g_key_file_load_from_file (config, argv[1], G_KEY_FILE_NONE, &error)) + { + g_error ("Impossibile caricare il file di configurazione specificato: %s.", argv[1]); + } + + commons = g_new0 (TerritorioCommons, 1); + +#ifdef G_OS_WIN32 + + gchar *moddir; + gchar *p; + + moddir = g_win32_get_package_installation_directory_of_module (NULL); + + p = strrchr (moddir, G_DIR_SEPARATOR); + if (p != NULL + && (g_ascii_strcasecmp (p + 1, "src") == 0 + || g_ascii_strcasecmp (p + 1, ".libs") == 0)) + { + commons->guidir = g_strdup (GUIDIR); + commons->formdir = g_strdup (FORMDIR); + } + else + { + commons->guidir = g_build_filename (moddir, "share", PACKAGE, "gui", NULL); + commons->formdir = g_build_filename (moddir, "share", PACKAGE, "form", NULL); + } + +#else + + commons->guidir = g_strdup (GUIDIR); + commons->formdir = g_strdup (FORMDIR); + +#endif + + commons->guifile = g_build_filename (commons->guidir, "territorio.gui", NULL); + + /* leggo la stringa di connessione al db */ + error = NULL; + cnc_string = g_key_file_get_value (config, "DB", "cnc_string", &error); + if (cnc_string == NULL) + { + g_error ("Impossibile leggere la stringa di connessione dal file di configurazione: %s.", + error != NULL && error->message != NULL ? error->message : "nessun dettaglio"); + } + + commons->gdaex = gdaex_new_from_string (cnc_string); + if (commons->gdaex == NULL) + { + g_error ("Errore nella connessione al database: %s", cnc_string); + } + + /* inizializzo solipa */ + commons->solipa = solipa_new (); + + + GHashTable *ht; + GHashTableIter iter; + gpointer key; + gpointer value; + + ht = territorio_comune_get_by_id (commons, strtol (argv[2], NULL, 10)); + + g_hash_table_iter_init (&iter, ht); + while (g_hash_table_iter_next (&iter, &key, &value)) + { + g_message ("%s: %s\n", (gchar *)key, gda_value_stringify ((GValue *)value)); + } + + return 0; +} -- 2.49.0