Move to kernel style SPDX license identifiers
[babeltrace.git] / tests / lib / plugin.c
index 1f0d783a2d7b5f724cdee6e6daec40fb59e1d23e..7e3c3e74183d27615e4ae7495305a47cac992736 100644 (file)
@@ -1,18 +1,7 @@
 /*
- * Copyright (c) 2017 Philippe Proulx <pproulx@efficios.com>
+ * SPDX-License-Identifier: GPL-2.0-only
  *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; under version 2 of the License.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ * Copyright (C) 2017 Philippe Proulx <pproulx@efficios.com>
  */
 
 #include <babeltrace2/babeltrace.h>
@@ -41,8 +30,8 @@ static int check_env_var(const char *name)
 
 static void reset_test_plugin_env_vars(void)
 {
-       g_setenv("BT_TEST_PLUGIN_INIT_CALLED", "0", 1);
-       g_setenv("BT_TEST_PLUGIN_EXIT_CALLED", "0", 1);
+       g_setenv("BT_TEST_PLUGIN_INITIALIZE_CALLED", "0", 1);
+       g_setenv("BT_TEST_PLUGIN_FINALIZE_CALLED", "0", 1);
 }
 
 static char *get_test_plugin_path(const char *plugin_dir,
@@ -79,7 +68,7 @@ static void test_minimal(const char *plugin_dir)
                "bt_plugin_find_all_from_file() succeeds with a valid file");
        ok(plugin_set,
                "bt_plugin_find_all_from_file() returns a plugin set");
-       ok(check_env_var("BT_TEST_PLUGIN_INIT_CALLED") == 1,
+       ok(check_env_var("BT_TEST_PLUGIN_INITIALIZE_CALLED") == 1,
                "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_find_all_from_file() returns the expected number of plugins");
@@ -105,8 +94,8 @@ static void test_minimal(const char *plugin_dir)
        ok(bt_plugin_get_sink_component_class_count(plugin) == 0,
                "bt_plugin_get_sink_component_class_count() returns the expected value");
        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");
+       ok(check_env_var("BT_TEST_PLUGIN_FINALIZE_CALLED") == 1,
+               "plugin's finalize function is called when the plugin is destroyed");
 
        free(minimal_path);
 }
@@ -129,11 +118,10 @@ static void test_sfs(const char *plugin_dir)
        bt_graph *graph;
        const char *object_str;
        bt_graph_add_component_status graph_ret;
-       bt_query_executor *query_exec = bt_query_executor_create();
+       bt_query_executor *query_exec;
        int ret;
        bt_plugin_find_all_from_file_status status;
 
-       BT_ASSERT(query_exec);
        BT_ASSERT(sfs_path);
        diag("sfs plugin test below");
 
@@ -179,32 +167,32 @@ static void test_sfs(const char *plugin_dir)
                plugin, "filter");
        ok(filter_comp_class,
                "bt_plugin_borrow_filter_component_class_by_name_const() finds a filter component class");
-       params = bt_value_signed_integer_create_init(23);
+       params = bt_value_integer_signed_create_init(23);
        BT_ASSERT(params);
-       ret = bt_query_executor_query(query_exec,
-               bt_component_class_filter_as_component_class_const(filter_comp_class),
-               "get-something", params, BT_LOGGING_LEVEL_NONE, &results);
+       query_exec = bt_query_executor_create(
+               bt_component_class_filter_as_component_class_const(
+                       filter_comp_class), "get-something", params);
+       BT_ASSERT(query_exec);
+       ret = bt_query_executor_query(query_exec, &results);
        ok(ret == 0 && results, "bt_query_executor_query() succeeds");
-       BT_ASSERT(bt_value_is_array(results) && bt_value_array_get_size(results) == 2);
+       BT_ASSERT(bt_value_is_array(results) && bt_value_array_get_length(results) == 2);
        object = bt_value_array_borrow_element_by_index_const(results, 0);
-       BT_ASSERT(object && bt_value_is_string(object));
+       BT_ASSERT(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_const(results, 1);
-       ok(bt_value_compare(res_params, params),
+       ok(bt_value_is_equal(res_params, params),
                "bt_component_class_query() receives the expected parameters");
 
        bt_component_class_sink_get_ref(sink_comp_class);
-       diag("> putting the plugin set object here");
        BT_PLUGIN_SET_PUT_REF_AND_RESET(plugin_set);
-       graph = bt_graph_create();
+       graph = bt_graph_create(0);
        BT_ASSERT(graph);
        graph_ret = bt_graph_add_sink_component(graph, sink_comp_class,
                "the-sink", NULL, BT_LOGGING_LEVEL_NONE, &sink_component);
        ok(graph_ret == BT_GRAPH_ADD_COMPONENT_STATUS_OK && sink_component,
                "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);
@@ -225,6 +213,7 @@ static void test_create_all_from_dir(const char *plugin_dir)
                BT_FALSE, &plugin_set);
        ok(status == BT_PLUGIN_FIND_ALL_FROM_DIR_STATUS_ERROR,
                "bt_plugin_find_all_from_dir() fails with an invalid path");
+       bt_current_thread_clear_error();
 
        plugin_set = NULL;
        status = bt_plugin_find_all_from_dir(plugin_dir, BT_FALSE, BT_FALSE,
@@ -249,8 +238,8 @@ static void test_find(const char *plugin_dir)
        char *plugin_path;
        bt_plugin_find_status status;
 
-       ok(bt_plugin_find(NON_EXISTING_PATH, BT_FALSE, &plugin) ==
-               BT_PLUGIN_FIND_STATUS_NOT_FOUND,
+       ok(bt_plugin_find(NON_EXISTING_PATH, BT_TRUE, BT_FALSE, BT_FALSE,
+               BT_FALSE, BT_FALSE, &plugin) == BT_PLUGIN_FIND_STATUS_NOT_FOUND,
                "bt_plugin_find() returns BT_PLUGIN_STATUS_NOT_FOUND with an unknown plugin name");
        ret = asprintf(&plugin_path, "%s" G_SEARCHPATH_SEPARATOR_S
                        G_DIR_SEPARATOR_S "ec1d09e5-696c-442e-b1c3-f9c6cf7f5958"
@@ -262,7 +251,8 @@ static void test_find(const char *plugin_dir)
        BT_ASSERT(ret > 0 && plugin_path);
        g_setenv("BABELTRACE_PLUGIN_PATH", plugin_path, 1);
        plugin = NULL;
-       status = bt_plugin_find("test_minimal", BT_FALSE, &plugin);
+       status = bt_plugin_find("test_minimal", BT_TRUE, BT_FALSE, BT_FALSE,
+               BT_FALSE, BT_FALSE, &plugin);
        ok(status == BT_PLUGIN_FIND_STATUS_OK,
                "bt_plugin_find() succeeds with a plugin name it can find");
        ok(plugin, "bt_plugin_find() returns a plugin object");
This page took 0.026743 seconds and 4 git commands to generate.