## Convenience test data API Convenience test data API — API to create test data without structure definition. |

## Synopsis

    void                gcut_add_datum                      (const gchar *name,
                                                             const gchar *first_field_name,
                                                             ...);
    const gchar *       gcut_data_get_string                (gconstpointer data,
                                                             const gchar *field_name);
    gint                gcut_data_get_int                   (gconstpointer data,
                                                             const gchar *field_name);
    guint               gcut_data_get_uint                  (gconstpointer data,
                                                             const gchar *field_name);
    GType               gcut_data_get_type                  (gconstpointer data,
                                                             const gchar *field_name);
    guint               gcut_data_get_flags                 (gconstpointer data,
                                                             const gchar *field_name);
    gint                gcut_data_get_enum                  (gconstpointer data,
                                                             const gchar *field_name);
    gconstpointer       gcut_data_get_pointer               (gconstpointer data,
                                                             const gchar *field_name);
    gconstpointer       gcut_data_get_boxed                 (gconstpointer data,
                                                             const gchar *field_name);

## Description

`cut_add_data()` requires custom data type for complex test data. But it's not easy to write. `gcut_add_datum()` provides API to use complex test data without custom data type. It uses GType for providing complex data.

## Details

### gcut_add_datum ()

    void                gcut_add_datum                      (const gchar *name,
                                                             const gchar *first_field_name,
                                                             ...);

Adds a datum to be used in data driven test. It's convenient rather than `cut_add_data()` because you doesn't need to define a new structure for a complex test data.

e.g.:

    #include <gcutter.h>

    void data_translate (void);
    void test_translate (gconstpointer data);

    static const gchar*
    translate (gint input)
    {
       switch(input) {
       case 1:
           return "first";
       case 111:
           return "a hundred eleven";
       default:
           return "unsupported";
       }
    }

    void
    data_translate(void)
    {
        gcut_add_datum("simple data",
                       "translated", G_TYPE_STRING, "first",
                       "input", G_TYPE_INT, 1,
                       NULL);
        gcut_add_datum("complex data",
                       "translated", G_TYPE_STRING, "a hundred eleven",
                       "input", G_TYPE_INT, 111,
                       NULL);
    }

    void
    test_translate(gconstpointer data)
    {
        cut_assert_equal_string(gcut_data_get_string(data, "translated"),
                                gcut_data_get_int(data, "input"));
    }

Available types and their values are the followings:

G_TYPE_STRING | const gchar *value e.g.:
    gcut_add_datum("data name",
                   "field-name", G_TYPE_STRING, "string value",
                   NULL);
G_TYPE_INT | gint value e.g.:
    gcut_add_datum("data name",
                   "field-name", G_TYPE_INT, 100,
                   NULL);
G_TYPE_UINT | guint value e.g.:
    gcut_add_datum("data name",
                   "field-name", G_TYPE_UINT, 100,
                   NULL);
G_TYPE_GTYPE | GType value e.g.:
    gut_add_datum("data name",
                  "field-name", G_TYPE_GTYPE, G_TYPE_OBJECT,
                  NULL);
GFlags types | its type value. e.g.:
    gcut_add_datum("data name",
                   "field-name", GTK_TYPE_WIDGET_FLAGS, GTK_TOPLEVEL | GTK_MAPPED,
                   NULL);
GEnum types | its type value. e.g.:
    gcut_add_datum("data name",
                   "field-name", GTK_TYPE_WRAP_MODE, GTK_WRAP_NONE,
                   NULL);
G_TYPE_POINTER | gconstpointer value, GDestroyNotify notify notify is called when value is destroyed. e.g.:
    gcut_add_datum("data name",
                   "field-name", G_TYPE_POINTER, my_structure_new(...), my_structure_free,
                   NULL);
NOTE: value's ownership is passed to Cutter. Don't free it.
GBoxed types | its type value. e.g.:
    gcut_add_datum("data name",
                   "field-name", G_TYPE_HASH_TABLE,
                   gcut_hash_table_string_string_new("name1", "value1",
                                                     "name2", "value2",
                                                     NULL),
                   NULL);
NOTE: value's ownership is passed to Cutter. Don't free it.

`name` : | the name of the data.
`first_field_name` : | the first field name.
`...` : | the type and value pair of the first field, followed optionally by the next field name, type and value triples. `NULL`-terminated. See description for more details.

Since 1.0.6

### gcut_data_get_string ()

    const gchar *       gcut_data_get_string                (gconstpointer data,
                                                             const gchar *field_name);

Gets a field value identified by `field_name` as string.

`data` : | the data added by `gcut_add_datum()`.
`field_name` : | the field name.
Returns : | a field value corresponded to `field_name`.

Since 1.0.6

### gcut_data_get_int ()

    gint                gcut_data_get_int                   (gconstpointer data,
                                                             const gchar *field_name);

Gets a field value identified by `field_name` as integer.

`data` : | the data added by `gcut_add_datum()`.
`field_name` : | the field name.
Returns : | a field value corresponded to `field_name`.

Since 1.0.6

### gcut_data_get_uint ()

    guint               gcut_data_get_uint                  (gconstpointer data,
                                                             const gchar *field_name);

Gets a field value identified by `field_name` as unsigned integer.

`data` : | the data added by `gcut_add_datum()`.
`field_name` : | the field name.
Returns : | a field value corresponded to `field_name`.

Since 1.0.6

### gcut_data_get_type ()

    GType               gcut_data_get_type                  (gconstpointer data,
                                                             const gchar *field_name);

Gets a field value identified by `field_name` as GType.

`data` : | the data added by `gcut_add_datum()`.
`field_name` : | the field name.
Returns : | a field value corresponded to `field_name`.

Since 1.0.6

### gcut_data_get_flags ()

    guint               gcut_data_get_flags                 (gconstpointer data,
                                                             const gchar *field_name);

Gets a field value identified by `field_name` as unsigned integer of GFlags.

`data` : | the data added by `gcut_add_datum()`.
`field_name` : | the field name.
Returns : | a field value corresponded to `field_name`.

Since 1.0.6

### gcut_data_get_enum ()

    gint                gcut_data_get_enum                  (gconstpointer data,
                                                             const gchar *field_name);

Gets a field value identified by `field_name` as integer of GEnum type.

`data` : | the data added by `gcut_add_datum()`.
`field_name` : | the field name.
Returns : | a field value corresponded to `field_name`.

Since 1.0.6

### gcut_data_get_pointer ()

    gconstpointer       gcut_data_get_pointer               (gconstpointer data,
                                                             const gchar *field_name);

Gets a field value identified by `field_name` as pointer.

`data` : | the data added by `gcut_add_datum()`.
`field_name` : | the field name.
Returns : | a field value corresponded to `field_name`.

Since 1.0.6

### gcut_data_get_boxed ()

    gconstpointer       gcut_data_get_boxed                 (gconstpointer data,
                                                             const gchar *field_name);

Gets a field value identified by `field_name` as GBoxed type value.

`data` : | the data added by `gcut_add_datum()`.
`field_name` : | the field name.
Returns : | a field value corresponded to `field_name`.

Since 1.0.7