![]() |
![]() |
![]() |
Cutter Reference Manual | ![]() |
---|---|---|---|---|
Top | Description |
Convenience test data APIConvenience test data API — API to create test data without structure definition. |
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);
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.
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:
const gchar *value e.g.: gcut_add_datum("data name", "field-name", G_TYPE_STRING, "string value", NULL);
|
|
gint value e.g.: gcut_add_datum("data name", "field-name", G_TYPE_INT, 100, NULL);
|
|
guint value e.g.: gcut_add_datum("data name", "field-name", G_TYPE_UINT, 100, NULL);
|
|
GType value e.g.: gcut_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);
|
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. |
|
the name of the data. |
|
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
const gchar * gcut_data_get_string (gconstpointer data, const gchar *field_name);
Gets a field value identified by field_name
as string.
|
the data added by gcut_add_datum() .
|
|
the field name. |
Returns : |
a field value corresponded to field_name .
|
Since 1.0.6
gint gcut_data_get_int (gconstpointer data, const gchar *field_name);
Gets a field value identified by field_name
as integer.
|
the data added by gcut_add_datum() .
|
|
the field name. |
Returns : |
a field value corresponded to field_name .
|
Since 1.0.6
guint gcut_data_get_uint (gconstpointer data, const gchar *field_name);
Gets a field value identified by field_name
as
unsigned integer.
|
the data added by gcut_add_datum() .
|
|
the field name. |
Returns : |
a field value corresponded to field_name .
|
Since 1.0.6
GType gcut_data_get_type (gconstpointer data, const gchar *field_name);
Gets a field value identified by field_name
as GType.
|
the data added by gcut_add_datum() .
|
|
the field name. |
Returns : |
a field value corresponded to field_name .
|
Since 1.0.6
guint gcut_data_get_flags (gconstpointer data, const gchar *field_name);
Gets a field value identified by field_name
as
unsigned integer of GFlags.
|
the data added by gcut_add_datum() .
|
|
the field name. |
Returns : |
a field value corresponded to field_name .
|
Since 1.0.6
gint gcut_data_get_enum (gconstpointer data, const gchar *field_name);
Gets a field value identified by field_name
as
integer of GEnum type.
|
the data added by gcut_add_datum() .
|
|
the field name. |
Returns : |
a field value corresponded to field_name .
|
Since 1.0.6
gconstpointer gcut_data_get_pointer (gconstpointer data, const gchar *field_name);
Gets a field value identified by field_name
as
pointer.
|
the data added by gcut_add_datum() .
|
|
the field name. |
Returns : |
a field value corresponded to field_name .
|
Since 1.0.6
gconstpointer gcut_data_get_boxed (gconstpointer data, const gchar *field_name);
Gets a field value identified by field_name
as
GBoxed type value.
|
the data added by gcut_add_datum() .
|
|
the field name. |
Returns : |
a field value corresponded to field_name .
|
Since 1.0.7