[gnumeric] Tests: new test for insert/delete column/row
- From: Morten Welinder <mortenw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnumeric] Tests: new test for insert/delete column/row
- Date: Sun, 14 Dec 2014 18:44:32 +0000 (UTC)
commit 01909d96fd5facde594aeb07cb11b5f0b6d81173
Author: Morten Welinder <terra gnome org>
Date: Sun Dec 14 13:36:10 2014 -0500
Tests: new test for insert/delete column/row
src/sstest.c | 109 +++++++++++++++++++++++++++++++++++++++++++
test/Makefile.am | 1 +
test/t2004-insdel-colrow.pl | 83 ++++++++++++++++++++++++++++++++
3 files changed, 193 insertions(+), 0 deletions(-)
---
diff --git a/src/sstest.c b/src/sstest.c
index c6533e8..bd7331c 100644
--- a/src/sstest.c
+++ b/src/sstest.c
@@ -61,6 +61,44 @@ cb_collect_names (G_GNUC_UNUSED const char *name, GnmNamedExpr *nexpr, GSList **
*names = g_slist_prepend (*names, nexpr);
}
+static GnmCell *
+fetch_cell (Sheet *sheet, const char *where)
+{
+ GnmCellPos cp;
+ gboolean ok = cellpos_parse (where,
+ gnm_sheet_get_size (sheet),
+ &cp, TRUE) != NULL;
+ g_return_val_if_fail (ok, NULL);
+ return sheet_cell_fetch (sheet, cp.col, cp.row);
+}
+
+static void
+set_cell (Sheet *sheet, const char *where, const char *what)
+{
+ GnmCell *cell = fetch_cell (sheet, where);
+ if (cell)
+ gnm_cell_set_text (cell, what);
+}
+
+static void
+dump_sheet (Sheet *sheet, const char *header)
+{
+ GPtrArray *cells = sheet_cells (sheet, NULL);
+ unsigned ui;
+
+ if (header)
+ g_printerr ("# %s\n", header);
+ for (ui = 0; ui < cells->len; ui++) {
+ GnmCell *cell = g_ptr_array_index (cells, ui);
+ char *txt = gnm_cell_get_entered_text (cell);
+ g_printerr ("%s: %s\n",
+ cellpos_as_string (&cell->pos), txt);
+ g_free (txt);
+ }
+ g_ptr_array_free (cells, TRUE);
+}
+
+
static void
dump_names (Workbook *wb)
{
@@ -196,6 +234,76 @@ test_insdel_rowcol_names (void)
mark_test_end (test_name);
}
+/*-------------------------------------------------------------------------- */
+
+static void
+test_insert_delete (void)
+{
+ const char *test_name = "test_insert_delete";
+ Workbook *wb;
+ Sheet *sheet1;
+ int i;
+ GOUndo *u = NULL, *u1;
+
+ mark_test_start (test_name);
+
+ wb = workbook_new ();
+ sheet1 = workbook_sheet_add (wb, -1,
+ GNM_DEFAULT_COLS, GNM_DEFAULT_ROWS);
+ set_cell (sheet1, "B2", "=D4+1");
+ set_cell (sheet1, "D2", "=if(TRUE,B2,2)");
+
+ dump_sheet (sheet1, "Init");
+
+ for (i = 5; i >= 0; i--) {
+ g_printerr ("# About to insert column before %s\n",
+ col_name (i));
+ sheet_insert_cols (sheet1, i, 1, &u1, NULL);
+ u = go_undo_combine (u, u1);
+ dump_sheet (sheet1, NULL);
+ }
+
+ for (i = 5; i >= 0; i--) {
+ g_printerr ("# About to insert row before %s\n",
+ row_name (i));
+ sheet_insert_rows (sheet1, i, 1, &u1, NULL);
+ u = go_undo_combine (u, u1);
+ dump_sheet (sheet1, NULL);
+ }
+
+ go_undo_undo (u);
+ g_object_unref (u);
+ u = NULL;
+ dump_sheet (sheet1, "Undo the lot");
+
+ for (i = 5; i >= 0; i--) {
+ g_printerr ("# About to delete column %s\n",
+ col_name (i));
+ sheet_delete_cols (sheet1, i, 1, &u1, NULL);
+ u = go_undo_combine (u, u1);
+ dump_sheet (sheet1, NULL);
+ }
+
+ for (i = 5; i >= 0; i--) {
+ g_printerr ("# About to delete row %s\n",
+ row_name (i));
+ sheet_delete_rows (sheet1, i, 1, &u1, NULL);
+ u = go_undo_combine (u, u1);
+ dump_sheet (sheet1, NULL);
+ }
+
+ go_undo_undo (u);
+ g_object_unref (u);
+ u = NULL;
+ dump_sheet (sheet1, "Undo the lot");
+
+ g_object_unref (wb);
+
+ mark_test_end (test_name);
+}
+
+/*-------------------------------------------------------------------------- */
+
static void
test_func_help (void)
{
@@ -838,6 +946,7 @@ main (int argc, char const **argv)
/* ---------------------------------------- */
MAYBE_DO ("test_insdel_rowcol_names") test_insdel_rowcol_names ();
+ MAYBE_DO ("test_insert_delete") test_insert_delete ();
MAYBE_DO ("test_func_help") test_func_help ();
MAYBE_DO ("test_nonascii_numbers") test_nonascii_numbers ();
MAYBE_DO ("test_random") test_random ();
diff --git a/test/Makefile.am b/test/Makefile.am
index dd72270..56af90d 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -54,6 +54,7 @@ TESTS = t1000-statfuns.pl \
t2001-func-help.pl \
t2002-nonascii-numbers.pl \
t2003-random-generators.pl \
+ t2004-insdel-colrow.pl \
t2800-style-optimizer.pl \
t5900-sc.pl \
t5901-qpro.pl \
diff --git a/test/t2004-insdel-colrow.pl b/test/t2004-insdel-colrow.pl
new file mode 100755
index 0000000..f5b6f6b
--- /dev/null
+++ b/test/t2004-insdel-colrow.pl
@@ -0,0 +1,83 @@
+#!/usr/bin/perl -w
+# -----------------------------------------------------------------------------
+
+use strict;
+use lib ($0 =~ m|^(.*/)| ? $1 : ".");
+use GnumericTest;
+
+my $expected;
+{ local $/; $expected = <DATA>; }
+
+&message ("Check insert/delete col/row.");
+&sstest ("test_insert_delete", $expected);
+
+__DATA__
+-----------------------------------------------------------------------------
+Start: test_insert_delete
+-----------------------------------------------------------------------------
+
+# Init
+B2: =D4+1
+D2: =if(TRUE,B2,2)
+# About to insert column before F
+B2: =D4+1
+D2: =if(TRUE,B2,2)
+# About to insert column before E
+B2: =D4+1
+D2: =if(TRUE,B2,2)
+# About to insert column before D
+B2: =E4+1
+E2: =if(TRUE,B2,2)
+# About to insert column before C
+B2: =F4+1
+F2: =if(TRUE,B2,2)
+# About to insert column before B
+C2: =G4+1
+G2: =if(TRUE,C2,2)
+# About to insert column before A
+D2: =H4+1
+H2: =if(TRUE,D2,2)
+# About to insert row before 6
+D2: =H4+1
+H2: =if(TRUE,D2,2)
+# About to insert row before 5
+D2: =H4+1
+H2: =if(TRUE,D2,2)
+# About to insert row before 4
+D2: =H5+1
+H2: =if(TRUE,D2,2)
+# About to insert row before 3
+D2: =H6+1
+H2: =if(TRUE,D2,2)
+# About to insert row before 2
+D3: =H7+1
+H3: =if(TRUE,D3,2)
+# About to insert row before 1
+D4: =H8+1
+H4: =if(TRUE,D4,2)
+# Undo the lot
+B2: =D4+1
+D2: =if(TRUE,B2,2)
+# About to delete column F
+B2: =D4+1
+D2: =if(TRUE,B2,2)
+# About to delete column E
+B2: =D4+1
+D2: =if(TRUE,B2,2)
+# About to delete column D
+B2: =#REF!+1
+# About to delete column C
+B2: =#REF!+1
+# About to delete column B
+# About to delete column A
+# About to delete row 6
+# About to delete row 5
+# About to delete row 4
+# About to delete row 3
+# About to delete row 2
+# About to delete row 1
+# Undo the lot
+B2: =D4+1
+D2: =if(TRUE,B2,2)
+End: test_insert_delete
+
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]