From: Ben Pfaff Date: Sat, 30 May 2009 04:46:24 +0000 (-0700) Subject: datasheet-test: Add test for datasheet_resize_column(). X-Git-Tag: v0.7.3~63 X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b625c0f9a4991796d7d70b71be518a2ccc42f60e;p=pspp-builds.git datasheet-test: Add test for datasheet_resize_column(). --- diff --git a/tests/data/datasheet-test.c b/tests/data/datasheet-test.c index 56c8d26e..a3fdb608 100644 --- a/tests/data/datasheet-test.c +++ b/tests/data/datasheet-test.c @@ -70,7 +70,7 @@ struct datasheet_test_params int n_widths; /* State. */ - int next_value; + unsigned int next_value; }; static bool @@ -454,10 +454,10 @@ datasheet_mc_init (struct mc *mc) } static void -value_from_param (union value *value, int width, int idx) +value_from_param (union value *value, int width, unsigned int idx) { if (width == 0) - value->f = idx; + value->f = idx & 0xffff; else { unsigned int hash = hash_int (idx, 0); @@ -470,6 +470,21 @@ value_from_param (union value *value, int width, int idx) } } +struct resize_cb_aux + { + int old_width; + int new_width; + }; + +static void +resize_cb (const union value *old_value, union value *new_value, void *aux_) +{ + struct resize_cb_aux *aux = aux_; + + value_from_param (new_value, aux->new_width, + value_hash (old_value, aux->old_width, 0)); +} + /* "mutate" function for struct mc_class. */ static void datasheet_mc_mutate (struct mc *mc, const void *ods_) @@ -524,6 +539,46 @@ datasheet_mc_mutate (struct mc *mc, const void *ods_) caseproto_unref (proto); } + /* Resize each column to each possible new size. */ + for (pos = 0; pos < n_columns; pos++) + for (width_idx = 0; width_idx < params->n_widths; width_idx++) + { + int owidth = caseproto_get_width (oproto, pos); + int width = params->widths[width_idx]; + if (mc_include_state (mc)) + { + struct resize_cb_aux aux; + struct caseproto *proto; + struct datasheet *ds; + size_t i; + + mc_name_operation (mc, "resize column %zu (of %zu) " + "from width %d to %d", + pos, n_columns, owidth, width); + clone_model (ods, odata, &ds, data); + + aux.old_width = owidth; + aux.new_width = width; + if (!datasheet_resize_column (ds, pos, width, resize_cb, &aux)) + NOT_REACHED (); + proto = caseproto_set_width (caseproto_ref (oproto), pos, width); + + for (i = 0; i < n_rows; i++) + { + union value *old_value = &data[i][pos]; + union value new_value; + value_init (&new_value, width); + resize_cb (old_value, &new_value, &aux); + value_swap (old_value, &new_value); + value_destroy (&new_value, owidth); + } + + check_datasheet (mc, ds, data, n_rows, proto); + release_data (n_rows, proto, data); + caseproto_unref (proto); + } + } + /* Delete all possible numbers of columns from all possible positions. */ for (pos = 0; pos < n_columns; pos++)