[libgda] Added GdauiRawGrid test



commit 453486e644339dae44c101fb2670b24246736a53
Author: Vivien Malerba <malerba gnome-db org>
Date:   Wed Apr 18 20:20:12 2012 +0200

    Added GdauiRawGrid test

 tests/ui/.gitignore             |    3 +-
 tests/ui/Makefile.am            |   11 ++++-
 tests/ui/check_raw_grid_model.c |   82 +++++++++++++++++++++++++++++++++++++++
 3 files changed, 93 insertions(+), 3 deletions(-)
---
diff --git a/tests/ui/.gitignore b/tests/ui/.gitignore
index 4bfdf4c..615f76c 100644
--- a/tests/ui/.gitignore
+++ b/tests/ui/.gitignore
@@ -1 +1,2 @@
-check_sets
\ No newline at end of file
+check_sets
+check_raw_grid_model
\ No newline at end of file
diff --git a/tests/ui/Makefile.am b/tests/ui/Makefile.am
index 434edf9..d5ce07a 100644
--- a/tests/ui/Makefile.am
+++ b/tests/ui/Makefile.am
@@ -7,8 +7,8 @@ AM_CPPFLAGS = \
 	$(GTK_CFLAGS) \
 	-DROOT_DIR=\""$(top_srcdir)"\"
 
-TESTS = check_sets
-check_PROGRAMS = check_sets
+TESTS = check_sets check_raw_grid_model
+check_PROGRAMS = check_sets check_raw_grid_model
 
 check_sets_SOURCES = common.c common.h check_sets.c
 check_sets_LDADD = \
@@ -16,3 +16,10 @@ check_sets_LDADD = \
 	$(top_builddir)/libgda-ui/libgda-ui-5.0.la \
 	$(COREDEPS_LIBS) \
 	$(GTK_LIBS)
+
+check_raw_grid_model_SOURCES = common.c common.h check_raw_grid_model.c
+check_raw_grid_model_LDADD = \
+        $(top_builddir)/libgda/libgda-5.0.la \
+        $(top_builddir)/libgda-ui/libgda-ui-5.0.la \
+        $(COREDEPS_LIBS) \
+        $(GTK_LIBS)
diff --git a/tests/ui/check_raw_grid_model.c b/tests/ui/check_raw_grid_model.c
new file mode 100644
index 0000000..c9effdf
--- /dev/null
+++ b/tests/ui/check_raw_grid_model.c
@@ -0,0 +1,82 @@
+/*
+ * Copyright (C) 2012 Vivien Malerba <malerba gnome-db org>
+ *
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+#include <stdio.h>
+#include <libgda/libgda.h>
+#include <libgda-ui/libgda-ui.h>
+#include "common.h"
+
+GdaConnection *cnc = NULL;
+
+int 
+main (int argc, char** argv)
+{
+	gtk_init (&argc, &argv);
+	gdaui_init ();
+
+	/* open connection */
+	cnc = ui_tests_common_open_connection ();
+
+	GdaSet *set;
+	GdauiRawGrid *grid;
+	GdaDataModel *model;
+	GdaDataModelIter *iter1, *iter2;
+	GdaDataModel *gm1, *gm2;
+	gint nrows1, nrows2;
+
+	model = ui_tests_common_get_products (cnc, FALSE);
+	nrows1 = gda_data_model_get_n_rows (model);
+	grid = GDAUI_RAW_GRID (gdaui_raw_grid_new (model));
+	g_object_unref (model);
+	iter1 = gdaui_data_selector_get_data_set (GDAUI_DATA_SELECTOR (grid));
+	gm1 = gdaui_data_selector_get_model (GDAUI_DATA_SELECTOR (grid));
+	if (nrows1 != gda_data_model_get_n_rows (gm1)) {
+		g_print ("Error: wrong number of rows\n");
+		return 1;
+	}
+
+	model = ui_tests_common_get_products (cnc, TRUE);
+	nrows2 = gda_data_model_get_n_rows (model);
+	g_assert (nrows1 != nrows2);
+	gdaui_data_selector_set_model (GDAUI_DATA_SELECTOR (grid), model);
+	g_object_unref (model);
+	iter2 = gdaui_data_selector_get_data_set (GDAUI_DATA_SELECTOR (grid));
+	gm2 = gdaui_data_selector_get_model (GDAUI_DATA_SELECTOR (grid));
+	if (nrows2 != gda_data_model_get_n_rows (gm2)) {
+		g_print ("Error: wrong number of rows\n");
+		return 1;
+	}
+
+	if (gm1 != gm2) {
+		g_print ("Error: GdauiDataSelector's returned model changed when not expected\n");
+		return 1;
+	}
+
+
+	if (nrows1 == gda_data_model_get_n_rows (gm2)) {
+		g_print ("Error: data model not actually changed\n");
+		return 1;
+	}
+
+	iter2 = gdaui_data_selector_get_data_set (GDAUI_DATA_SELECTOR (grid));
+	if (iter1 != iter2) {
+		g_print ("Error: iterators are not the same!\n");
+		return 1;
+	}
+	return 0;
+}
+



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