From 5933c0f2e81353a0bce0893f44408be7014ca500 Mon Sep 17 00:00:00 2001 From: Philippe Proulx Date: Fri, 10 Feb 2017 23:44:44 -0500 Subject: [PATCH] Add query info API tests MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Philippe Proulx Signed-off-by: Jérémie Galarneau --- tests/lib/test-plugin-plugins/sfs.c | 21 +++++++++++++++++- tests/lib/test_plugin.c | 33 ++++++++++++++++++++++++++++- 2 files changed, 52 insertions(+), 2 deletions(-) diff --git a/tests/lib/test-plugin-plugins/sfs.c b/tests/lib/test-plugin-plugins/sfs.c index dbda1d7e..f86b848b 100644 --- a/tests/lib/test-plugin-plugins/sfs.c +++ b/tests/lib/test-plugin-plugins/sfs.c @@ -16,7 +16,10 @@ */ #include -#include +#include +#include +#include +#include static enum bt_component_status sink_consume(struct bt_component *component) { @@ -54,6 +57,21 @@ static enum bt_notification_iterator_status dummy_iterator_seek_time_method( return BT_NOTIFICATION_ITERATOR_STATUS_OK; } +static struct bt_value *query_info_method( + struct bt_component_class *component_class, + const char *action, struct bt_value *params) +{ + int ret; + struct bt_value *results = bt_value_array_create(); + + assert(results); + ret = bt_value_array_append_string(results, action); + assert(ret == 0); + ret = bt_value_array_append(results, params); + assert(ret == 0); + return results; +} + BT_PLUGIN(test_sfs); BT_PLUGIN_DESCRIPTION("Babeltrace plugin with source, sink, and filter component classes"); BT_PLUGIN_AUTHOR("Janine Sutto"); @@ -88,3 +106,4 @@ BT_PLUGIN_FILTER_COMPONENT_CLASS_NOTIFICATION_ITERATOR_DESTROY_METHOD(filter, dummy_iterator_destroy_method); BT_PLUGIN_FILTER_COMPONENT_CLASS_NOTIFICATION_ITERATOR_SEEK_TIME_METHOD(filter, dummy_iterator_seek_time_method); +BT_PLUGIN_FILTER_COMPONENT_CLASS_QUERY_INFO_METHOD(filter, query_info_method); diff --git a/tests/lib/test_plugin.c b/tests/lib/test_plugin.c index 7fa338f6..4d54bee6 100644 --- a/tests/lib/test_plugin.c +++ b/tests/lib/test_plugin.c @@ -31,7 +31,7 @@ #include "tap/tap.h" #include "common.h" -#define NR_TESTS 45 +#define NR_TESTS 51 #define NON_EXISTING_PATH "/this/hopefully/does/not/exist/5bc75f8d-0dba-4043-a509-d7984b97e42b.so" /* Those symbols are written to by some test plugins */ @@ -142,6 +142,12 @@ static void test_sfs(const char *plugin_dir) char *sfs_path = get_test_plugin_path(plugin_dir, "sfs"); unsigned int major, minor, patch; const char *extra; + struct bt_value *params; + struct bt_value *results; + struct bt_value *action; + struct bt_value *res_params; + const char *action_str; + int ret; assert(sfs_path); diag("sfs plugin test below"); @@ -186,6 +192,27 @@ static void test_sfs(const char *plugin_dir) ok(!bt_plugin_get_component_class_by_name_and_type(plugin, "filter", BT_COMPONENT_CLASS_TYPE_SOURCE), "bt_plugin_get_component_class_by_name_and_type() does not find a component class given the wrong type"); + params = bt_value_integer_create_init(23); + assert(params); + ok (!bt_component_class_query_info(NULL, "get-something", params), + "bt_component_class_query_info() handles NULL (component class)"); + ok (!bt_component_class_query_info(filter_comp_class, NULL, params), + "bt_component_class_query_info() handles NULL (action)"); + ok (!bt_component_class_query_info(filter_comp_class, "get-something", NULL), + "bt_component_class_query_info() handles NULL (parameters)"); + results = bt_component_class_query_info(filter_comp_class, + "get-something", params); + ok(results, "bt_component_class_query_info() succeeds"); + assert(bt_value_is_array(results) && bt_value_array_size(results) == 2); + action = bt_value_array_get(results, 0); + assert(action && bt_value_is_string(action)); + ret = bt_value_string_get(action, &action_str); + assert(ret == 0); + ok(strcmp(action_str, "get-something") == 0, + "bt_component_class_query_info() receives the expected action name"); + res_params = bt_value_array_get(results, 1); + ok(res_params == params, + "bt_component_class_query_info() receives the expected parameters"); diag("> putting the plugin object here"); BT_PUT(plugin); @@ -204,6 +231,10 @@ static void test_sfs(const char *plugin_dir) free(sfs_path); free(plugins); + bt_put(action); + bt_put(res_params); + bt_put(results); + bt_put(params); } static void test_create_all_from_dir(const char *plugin_dir) -- 2.34.1