![]() |
![]() |
![]() |
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); gpointer gcut_data_get_object (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.:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
#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.:
|
|||
gint value e.g.:
|
|||
guint value e.g.:
|
|||
GType value e.g.:
|
|||
GFlags types |
its type value. e.g.:
|
||
GEnum types |
its type value. e.g.:
|
||
gconstpointer value, GDestroyNotify notify notify is called when value is destroyed. e.g.:
NOTE: value's ownership is passed to Cutter. Don't free it. |
|||
GBoxed types |
its type value. e.g.:
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
gpointer gcut_data_get_object (gconstpointer data, const gchar *field_name);
Gets a field value identified by field_name
as
GObject type value.
|
the data added by gcut_add_datum() .
|
|
the field name. |
Returns : |
a field value corresponded to field_name .
|
Since 1.1.1