diff options
author | Thibault Saunier <thibault.saunier@collabora.com> | 2012-06-01 00:13:40 +0800 |
---|---|---|
committer | Sebastian Dröge <sebastian.droege@collabora.co.uk> | 2012-06-18 09:29:51 +0100 |
commit | d703ee27628181e6ddf8e17f43e63a4ed27dd27d (patch) | |
tree | 9b8925279ee11d8f5fa8edff75027fdded1c3a02 | |
parent | 8b43d11b989508cbd517ea9ebc71b62b46458e86 (diff) |
lib: Add a way to specify checklist items that are shared between iterations of start/stop
In some cases, checklist items are shared between iterations of start/stop, so this way,
the tests can specify which ones and not have to validate it for each iterations itself.
API: insanity_test_add_shared_checklist_item
-rw-r--r-- | docs/insanity/insanity-sections.txt | 1 | ||||
-rw-r--r-- | lib/insanity/insanitytest.c | 61 | ||||
-rw-r--r-- | lib/insanity/insanitytest.h | 1 |
3 files changed, 63 insertions, 0 deletions
diff --git a/docs/insanity/insanity-sections.txt b/docs/insanity/insanity-sections.txt index 86c35da..01738af 100644 --- a/docs/insanity/insanity-sections.txt +++ b/docs/insanity/insanity-sections.txt @@ -19,6 +19,7 @@ insanity_test_new insanity_test_add_argument insanity_test_add_checklist_item +insanity_test_add_shared_checklist_item insanity_test_add_extra_info insanity_test_add_output_file diff --git a/lib/insanity/insanitytest.c b/lib/insanity/insanitytest.c index 453d579..33205ef 100644 --- a/lib/insanity/insanitytest.c +++ b/lib/insanity/insanitytest.c @@ -132,6 +132,7 @@ struct _InsanityTestPrivateData char *test_name; char *test_desc; char *test_full_desc; + GList *shareditems; GHashTable *test_checklist; GHashTable *test_arguments; GHashTable *test_extra_infos; @@ -216,6 +217,7 @@ typedef struct _Argument typedef struct _ChecklistItem { + char *label; char *description; char *likely_error; } ChecklistItem; @@ -241,6 +243,7 @@ free_checklist_item (void *ptr) { ChecklistItem *i = ptr; + g_free (i->label); g_free (i->description); g_free (i->likely_error); @@ -1475,6 +1478,30 @@ output_checklist_table (InsanityTest * test, FILE * f) } static void +output_shared_items (InsanityTest * test, FILE * f) +{ + GList *tmp; + const char *comma = ""; + + fprintf (f, ",\n \"__shared_checklist_items__\": {\n"); + for (tmp = test->priv->shareditems; tmp; tmp = tmp->next) { + ChecklistItem *item = (ChecklistItem *) tmp->data; + + fprintf (f, "%s \"%s\" : \n", comma, item->label); + fprintf (f, " {\n"); + fprintf (f, " \"description\" : \"%s\"", item->description); + if (item->likely_error) { + fprintf (f, ",\n \"likely_error\" : \"%s\"", item->likely_error); + } + fprintf (f, "\n }"); + + comma = ",\n"; + } + + fprintf (f, "\n }"); +} + +static void output_arguments_table (InsanityTest * test, FILE * f) { GHashTableIter it; @@ -1552,6 +1579,7 @@ insanity_test_write_metadata (InsanityTest * test) fprintf (f, " \"__name__\": \"%s\",\n", name); fprintf (f, " \"__description__\": \"%s\"", desc); output_checklist_table (test, f); + output_shared_items (test, f); output_arguments_table (test, f); output_table (test, f, test->priv->test_extra_infos, "__extra_infos__", &get_raw_string); @@ -1898,6 +1926,7 @@ insanity_test_finalize (GObject * gobject) g_free (test->priv->test_name); g_free (test->priv->test_desc); g_free (test->priv->test_full_desc); + g_list_free (priv->shareditems); g_hash_table_destroy (priv->test_checklist); g_hash_table_destroy (priv->test_arguments); g_hash_table_destroy (priv->test_extra_infos); @@ -2163,6 +2192,7 @@ insanity_test_add_checklist_item (InsanityTest * test, const char *label, label) == NULL); i = g_slice_new (ChecklistItem); + i->label = g_strdup (label); i->description = g_strdup (description); i->likely_error = g_strdup (error_hint); @@ -2170,6 +2200,37 @@ insanity_test_add_checklist_item (InsanityTest * test, const char *label, } /** + * insanity_test_add_shared_checklist_item: + * @test: A #InsanityTest to operate on + * @label: The label of the checklist item that is shared between start/stop + * iterations. + * + * This function adds a checklist item as being shared between iterations of + * start/stop when the test is run. This means that the item value of this + * checklist item will be the same between all iterations of start/stop. + */ +void +insanity_test_add_shared_checklist_item (InsanityTest * test, + const gchar * label) +{ + ChecklistItem *item; + + g_return_if_fail (INSANITY_IS_TEST (test)); + + item = g_hash_table_lookup (test->priv->test_checklist, label); + + if (item == NULL) { + INSANITY_LOG (INSANITY_TEST ((test)), "test", INSANITY_LOG_LEVEL_INFO, + "%s not in the checklist item list, can't add it to the shared item list", + label); + + return; + } + + test->priv->shareditems = g_list_prepend (test->priv->shareditems, item); +} + +/** * insanity_test_add_argument: * @test: a #InsanityTest instance to operate on. * @label: the new argument's label diff --git a/lib/insanity/insanitytest.h b/lib/insanity/insanitytest.h index c304e40..3bd9ac2 100644 --- a/lib/insanity/insanitytest.h +++ b/lib/insanity/insanitytest.h @@ -94,6 +94,7 @@ GType insanity_test_get_type (void); InsanityTest *insanity_test_new(const char *name, const char *description, const char *full_description); void insanity_test_add_checklist_item(InsanityTest *test, const char *label, const char *description, const char *error_hint); +void insanity_test_add_shared_checklist_item (InsanityTest * test, const gchar * label); void insanity_test_add_argument(InsanityTest *test, const char *label, const char *description, const char *full_description, gboolean global, const GValue *default_value); void insanity_test_add_output_file(InsanityTest *test, const char *label, const char *description, gboolean global); void insanity_test_add_extra_info(InsanityTest *test, const char *label, const char *description); |