Re-organize sources
[babeltrace.git] / tests / lib / test_plugin.c
index eae1ab51374164804357660a824a9b2338e5ae98..39b054e53ee3ddac324839284d9fa04fc12fce2f 100644 (file)
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
-#include <babeltrace/babeltrace.h>
+#include <babeltrace2/babeltrace.h>
 #include <stdlib.h>
 #include <string.h>
 #include <stdio.h>
-#include <babeltrace/assert-internal.h>
+#include "common/assert.h"
 #include <glib.h>
 #include "tap/tap.h"
 #include "common.h"
@@ -64,22 +64,22 @@ static char *get_test_plugin_path(const char *plugin_dir,
 
 static void test_minimal(const char *plugin_dir)
 {
-       struct bt_plugin_set *plugin_set;
-       struct bt_plugin *plugin;
+       const bt_plugin_set *plugin_set;
+       const bt_plugin *plugin;
        char *minimal_path = get_test_plugin_path(plugin_dir, "minimal");
 
        BT_ASSERT(minimal_path);
        diag("minimal plugin test below");
 
        reset_test_plugin_env_vars();
-       plugin_set = bt_plugin_create_all_from_file(minimal_path);
+       plugin_set = bt_plugin_find_all_from_file(minimal_path);
        ok(plugin_set && bt_plugin_set_get_plugin_count(plugin_set) == 1,
-               "bt_plugin_create_all_from_file() succeeds with a valid file");
+               "bt_plugin_find_all_from_file() succeeds with a valid file");
        ok(check_env_var("BT_TEST_PLUGIN_INIT_CALLED") == 1,
-               "plugin's initialization function is called during bt_plugin_create_all_from_file()");
+               "plugin's initialization function is called during bt_plugin_find_all_from_file()");
        ok(bt_plugin_set_get_plugin_count(plugin_set) == 1,
-               "bt_plugin_create_all_from_file() returns the expected number of plugins");
-       plugin = bt_plugin_set_borrow_plugin_by_index(plugin_set, 0);
+               "bt_plugin_find_all_from_file() returns the expected number of plugins");
+       plugin = bt_plugin_set_borrow_plugin_by_index_const(plugin_set, 0);
        ok(strcmp(bt_plugin_get_name(plugin), "test_minimal") == 0,
                "bt_plugin_get_name() returns the expected name");
        ok(strcmp(bt_plugin_get_description(plugin),
@@ -100,7 +100,7 @@ static void test_minimal(const char *plugin_dir)
                "bt_plugin_get_filter_component_class_count() returns the expected value");
        ok(bt_plugin_get_sink_component_class_count(plugin) == 0,
                "bt_plugin_get_sink_component_class_count() returns the expected value");
-       bt_object_put_ref(plugin_set);
+       bt_plugin_set_put_ref(plugin_set);
        ok(check_env_var("BT_TEST_PLUGIN_EXIT_CALLED") == 1,
                "plugin's exit function is called when the plugin is destroyed");
 
@@ -109,33 +109,32 @@ static void test_minimal(const char *plugin_dir)
 
 static void test_sfs(const char *plugin_dir)
 {
-       struct bt_plugin_set *plugin_set;
-       struct bt_plugin *plugin;
-       struct bt_component_class_sink *sink_comp_class;
-       struct bt_component_class_source *source_comp_class;
-       struct bt_component_class_filter *filter_comp_class;
-       struct bt_component_sink *sink_component;
+       const bt_plugin_set *plugin_set;
+       const bt_plugin *plugin;
+       const bt_component_class_sink *sink_comp_class;
+       const bt_component_class_source *source_comp_class;
+       const bt_component_class_filter *filter_comp_class;
+       const bt_component_sink *sink_component;
        char *sfs_path = get_test_plugin_path(plugin_dir, "sfs");
        unsigned int major, minor, patch;
        const char *extra;
-       struct bt_private_value *params;
-       struct bt_value *results;
-       struct bt_value *object;
-       struct bt_value *res_params;
-       struct bt_private_graph *graph;
+       bt_value *params;
+       const bt_value *results;
+       const bt_value *object;
+       const bt_value *res_params;
+       bt_graph *graph;
        const char *object_str;
-       enum bt_graph_status graph_ret;
-       struct bt_private_query_executor *query_exec =
-               bt_private_query_executor_create();
+       bt_graph_status graph_ret;
+       bt_query_executor *query_exec = bt_query_executor_create();
        int ret;
 
        BT_ASSERT(query_exec);
        BT_ASSERT(sfs_path);
        diag("sfs plugin test below");
 
-       plugin_set = bt_plugin_create_all_from_file(sfs_path);
+       plugin_set = bt_plugin_find_all_from_file(sfs_path);
        BT_ASSERT(plugin_set && bt_plugin_set_get_plugin_count(plugin_set) == 1);
-       plugin = bt_plugin_set_borrow_plugin_by_index(plugin_set, 0);
+       plugin = bt_plugin_set_borrow_plugin_by_index_const(plugin_set, 0);
        ok(bt_plugin_get_version(plugin, &major, &minor, &patch, &extra) ==
                BT_PROPERTY_AVAILABILITY_AVAILABLE,
                "bt_plugin_get_version() succeeds when there's a version");
@@ -154,88 +153,86 @@ static void test_sfs(const char *plugin_dir)
        ok(bt_plugin_get_sink_component_class_count(plugin) == 1,
                "bt_plugin_get_sink_component_class_count() returns the expected value");
 
-       source_comp_class = bt_plugin_borrow_source_component_class_by_name(
+       source_comp_class = bt_plugin_borrow_source_component_class_by_name_const(
                plugin, "source");
        ok(source_comp_class,
-               "bt_plugin_borrow_source_component_class_by_name() finds a source component class");
+               "bt_plugin_borrow_source_component_class_by_name_const() finds a source component class");
 
-       sink_comp_class = bt_plugin_borrow_sink_component_class_by_name(
+       sink_comp_class = bt_plugin_borrow_sink_component_class_by_name_const(
                plugin, "sink");
        ok(sink_comp_class,
-               "bt_plugin_borrow_sink_component_class_by_name() finds a sink component class");
-       ok(strcmp(bt_component_class_get_help(
-               bt_component_class_sink_as_component_class(sink_comp_class)),
-               "Bacon ipsum dolor amet strip steak cupim pastrami venison shoulder.\n"
-               "Prosciutto beef ribs flank meatloaf pancetta brisket kielbasa drumstick\n"
-               "venison tenderloin cow tail. Beef short loin shoulder meatball, sirloin\n"
-               "ground round brisket salami cupim pork bresaola turkey bacon boudin.\n") == 0,
+               "bt_plugin_borrow_sink_component_class_by_name_const() finds a sink component class");
+       ok(strcmp(bt_component_class_get_help(bt_component_class_sink_as_component_class_const(sink_comp_class)),
+                 "Bacon ipsum dolor amet strip steak cupim pastrami venison shoulder.\n"
+                 "Prosciutto beef ribs flank meatloaf pancetta brisket kielbasa drumstick\n"
+                 "venison tenderloin cow tail. Beef short loin shoulder meatball, sirloin\n"
+                 "ground round brisket salami cupim pork bresaola turkey bacon boudin.\n") == 0,
                "bt_component_class_get_help() returns the expected help text");
 
-       filter_comp_class = bt_plugin_borrow_filter_component_class_by_name(
+       filter_comp_class = bt_plugin_borrow_filter_component_class_by_name_const(
                plugin, "filter");
        ok(filter_comp_class,
-               "bt_plugin_borrow_filter_component_class_by_name() finds a filter component class");
-       params = bt_private_value_integer_create_init(23);
+               "bt_plugin_borrow_filter_component_class_by_name_const() finds a filter component class");
+       params = bt_value_signed_integer_create_init(23);
        BT_ASSERT(params);
-       ret = bt_private_query_executor_query(query_exec,
-               bt_component_class_filter_as_component_class(filter_comp_class),
-               "get-something", bt_private_value_as_value(params),
-               &results);
-       ok(ret == 0 && results, "bt_private_query_executor_query() succeeds");
+       ret = bt_query_executor_query(query_exec,
+               bt_component_class_filter_as_component_class_const(filter_comp_class),
+               "get-something", params, &results);
+       ok(ret == 0 && results, "bt_query_executor_query() succeeds");
        BT_ASSERT(bt_value_is_array(results) && bt_value_array_get_size(results) == 2);
-       object = bt_value_array_borrow_element_by_index(results, 0);
+       object = bt_value_array_borrow_element_by_index_const(results, 0);
        BT_ASSERT(object && bt_value_is_string(object));
        object_str = bt_value_string_get(object);
        ok(strcmp(object_str, "get-something") == 0,
                "bt_component_class_query() receives the expected object name");
-       res_params = bt_value_array_borrow_element_by_index(results, 1);
-       ok(res_params == bt_private_value_as_value(params),
+       res_params = bt_value_array_borrow_element_by_index_const(results, 1);
+       ok(bt_value_compare(res_params, params),
                "bt_component_class_query() receives the expected parameters");
 
-       bt_object_get_ref(sink_comp_class);
+       bt_component_class_sink_get_ref(sink_comp_class);
        diag("> putting the plugin set object here");
-       BT_OBJECT_PUT_REF_AND_RESET(plugin_set);
-       graph = bt_private_graph_create();
+       BT_PLUGIN_SET_PUT_REF_AND_RESET(plugin_set);
+       graph = bt_graph_create();
        BT_ASSERT(graph);
-       graph_ret = bt_private_graph_add_sink_component(graph, sink_comp_class, "the-sink",
-               NULL, &sink_component);
+       graph_ret = bt_graph_add_sink_component(graph, sink_comp_class,
+               "the-sink", NULL, &sink_component);
        ok(graph_ret == BT_GRAPH_STATUS_OK && sink_component,
-               "bt_private_graph_add_sink_component() still works after the plugin object is destroyed");
-       BT_OBJECT_PUT_REF_AND_RESET(sink_component);
-       bt_object_put_ref(graph);
+               "bt_graph_add_sink_component() still works after the plugin object is destroyed");
+       BT_COMPONENT_SINK_PUT_REF_AND_RESET(sink_component);
+       bt_graph_put_ref(graph);
 
        free(sfs_path);
-       bt_object_put_ref(sink_comp_class);
-       bt_object_put_ref(results);
-       bt_object_put_ref(params);
-       bt_object_put_ref(query_exec);
+       bt_component_class_sink_put_ref(sink_comp_class);
+       bt_value_put_ref(results);
+       bt_value_put_ref(params);
+       bt_query_executor_put_ref(query_exec);
 }
 
 static void test_create_all_from_dir(const char *plugin_dir)
 {
-       struct bt_plugin_set *plugin_set;
+       const bt_plugin_set *plugin_set;
 
        diag("create from all test below");
 
-       plugin_set = bt_plugin_create_all_from_dir(NON_EXISTING_PATH, BT_FALSE);
+       plugin_set = bt_plugin_find_all_from_dir(NON_EXISTING_PATH, BT_FALSE);
        ok(!plugin_set,
-               "bt_plugin_create_all_from_dir() fails with an invalid path");
+               "bt_plugin_find_all_from_dir() fails with an invalid path");
 
-       plugin_set = bt_plugin_create_all_from_dir(plugin_dir, BT_FALSE);
-       ok(plugin_set, "bt_plugin_create_all_from_dir() succeeds with a valid path");
+       plugin_set = bt_plugin_find_all_from_dir(plugin_dir, BT_FALSE);
+       ok(plugin_set, "bt_plugin_find_all_from_dir() succeeds with a valid path");
 
        /* 2 or 4, if `.la` files are considered or not */
        ok(bt_plugin_set_get_plugin_count(plugin_set) == 2 ||
                bt_plugin_set_get_plugin_count(plugin_set) == 4,
-               "bt_plugin_create_all_from_dir() returns the expected number of plugin objects");
+               "bt_plugin_find_all_from_dir() returns the expected number of plugin objects");
 
-       bt_object_put_ref(plugin_set);
+       bt_plugin_set_put_ref(plugin_set);
 }
 
 static void test_find(const char *plugin_dir)
 {
        int ret;
-       struct bt_plugin *plugin;
+       const bt_plugin *plugin;
        char *plugin_path;
 
        ok(!bt_plugin_find(NON_EXISTING_PATH),
@@ -254,7 +251,7 @@ static void test_find(const char *plugin_dir)
                "bt_plugin_find() succeeds with a plugin name it can find");
        ok(strcmp(bt_plugin_get_author(plugin), "Janine Sutto") == 0,
                "bt_plugin_find() finds the correct plugin for a given name");
-       BT_OBJECT_PUT_REF_AND_RESET(plugin);
+       BT_PLUGIN_PUT_REF_AND_RESET(plugin);
        free(plugin_path);
 }
 
This page took 0.027865 seconds and 4 git commands to generate.