Add query info API tests
authorPhilippe Proulx <eeppeliteloop@gmail.com>
Sat, 11 Feb 2017 04:44:44 +0000 (23:44 -0500)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Sun, 28 May 2017 16:57:38 +0000 (12:57 -0400)
Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
tests/lib/test-plugin-plugins/sfs.c
tests/lib/test_plugin.c

index dbda1d7eb460574743ec2794e476e369dadd5de0..f86b848b3a5adbc4a613692edc6d529f05572943 100644 (file)
  */
 
 #include <babeltrace/plugin/plugin-dev.h>
-#include <babeltrace/component/component.h>
+#include <babeltrace/component/component-class.h>
+#include <babeltrace/values.h>
+#include <babeltrace/ref.h>
+#include <assert.h>
 
 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);
index 7fa338f60af9920078b05775090d30996874bb42..4d54bee6e82fcd02957b48369257b5726741bd52 100644 (file)
@@ -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)
This page took 0.027309 seconds and 4 git commands to generate.