Values API: standardize parameters and return values
[babeltrace.git] / tests / lib / test_plugin.c
index c8578827b32e2418e90be6fda6072e1bee19a21d..c11fd12f9773d3d98e71a1a3d2790d623a3cffbf 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * test_plugin.c
  *
- * CTF IR Reference Count test
+ * Trace IR Reference Count test
  *
  * Copyright (c) 2017 Philippe Proulx <pproulx@efficios.com>
  *
@@ -20,8 +20,9 @@
  */
 
 #include <babeltrace/plugin/plugin.h>
-#include <babeltrace/ref.h>
+#include <babeltrace/object.h>
 #include <babeltrace/values.h>
+#include <babeltrace/private-values.h>
 #include <babeltrace/graph/component.h>
 #include <babeltrace/graph/graph.h>
 #include <babeltrace/graph/query-executor.h>
@@ -142,8 +143,8 @@ static void test_minimal(const char *plugin_dir)
                "bt_plugin_get_path() returns the expected path");
        ok(bt_plugin_get_component_class_count(plugin) == 0,
                "bt_plugin_get_component_class_count() returns the expected value");
-       bt_put(plugin);
-       bt_put(plugin_set);
+       bt_object_put_ref(plugin);
+       bt_object_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");
 
@@ -161,13 +162,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_private_value *params;
        struct bt_value *results;
        struct bt_value *object;
        struct bt_value *res_params;
        struct bt_graph *graph;
        const char *object_str;
-       enum bt_value_status value_ret;
        enum bt_graph_status graph_ret;
        struct bt_query_executor *query_exec = bt_query_executor_create();
        int ret;
@@ -216,68 +216,66 @@ 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);
+       params = bt_private_value_integer_create_init(23);
        BT_ASSERT(params);
        ret = bt_query_executor_query(NULL, filter_comp_class, "object",
-               params, &results);
+               bt_value_borrow_from_private(params), &results);
        ok (ret, "bt_query_executor_query() handles NULL (query executor)");
        ret = bt_query_executor_query(query_exec, NULL, "object",
-               params, &results);
+               bt_value_borrow_from_private(params), &results);
        ok (ret, "bt_query_executor_query() handles NULL (component class)");
        ret = bt_query_executor_query(query_exec, filter_comp_class, NULL,
-               params, &results);
+               bt_value_borrow_from_private(params), &results);
        ok (ret, "bt_query_executor_query() handles NULL (object)");
        ret = bt_query_executor_query(query_exec, filter_comp_class,
-               "get-something", params, &results);
+               "get-something", bt_value_borrow_from_private(params),
+               &results);
        ok(ret == 0 && results, "bt_query_executor_query() succeeds");
-       BT_ASSERT(bt_value_is_array(results) && bt_value_array_size(results) == 2);
-       object = bt_value_array_get(results, 0);
+       BT_ASSERT(bt_value_is_array(results) && bt_value_array_get_size(results) == 2);
+       object = bt_value_array_borrow_element_by_index(results, 0);
        BT_ASSERT(object && bt_value_is_string(object));
-       value_ret = bt_value_string_get(object, &object_str);
-       BT_ASSERT(value_ret == BT_VALUE_STATUS_OK);
+       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_get(results, 1);
-       ok(res_params == params,
+       res_params = bt_value_array_borrow_element_by_index(results, 1);
+       ok(res_params == bt_value_borrow_from_private(params),
                "bt_component_class_query() receives the expected parameters");
 
        diag("> putting the plugin object here");
-       BT_PUT(plugin);
+       BT_OBJECT_PUT_REF_AND_RESET(plugin);
        graph = bt_graph_create();
        BT_ASSERT(graph);
        graph_ret = bt_graph_add_component(graph, sink_comp_class, "the-sink",
                NULL, &sink_component);
        ok(graph_ret == BT_GRAPH_STATUS_OK && sink_component,
                "bt_graph_add_component() still works after the plugin object is destroyed");
-       BT_PUT(sink_component);
-       BT_PUT(source_comp_class);
-       bt_put(graph);
+       BT_OBJECT_PUT_REF_AND_RESET(sink_component);
+       BT_OBJECT_PUT_REF_AND_RESET(source_comp_class);
+       bt_object_put_ref(graph);
        graph = bt_graph_create();
        BT_ASSERT(graph);
        graph_ret = bt_graph_add_component(graph, sink_comp_class, "the-sink",
                NULL, &sink_component);
        ok(graph_ret == BT_GRAPH_STATUS_OK && sink_component,
                "bt_graph_add_component() still works after the source component class object is destroyed");
-       BT_PUT(sink_component);
-       BT_PUT(filter_comp_class);
-       bt_put(graph);
+       BT_OBJECT_PUT_REF_AND_RESET(sink_component);
+       BT_OBJECT_PUT_REF_AND_RESET(filter_comp_class);
+       bt_object_put_ref(graph);
        graph = bt_graph_create();
        BT_ASSERT(graph);
        graph_ret = bt_graph_add_component(graph, sink_comp_class, "the-sink",
                NULL, &sink_component);
        ok(graph_ret == BT_GRAPH_STATUS_OK && sink_component,
                "bt_graph_add_component() still works after the filter component class object is destroyed");
-       BT_PUT(sink_comp_class);
-       BT_PUT(sink_component);
+       BT_OBJECT_PUT_REF_AND_RESET(sink_comp_class);
+       BT_OBJECT_PUT_REF_AND_RESET(sink_component);
 
        free(sfs_path);
-       bt_put(graph);
-       bt_put(plugin_set);
-       bt_put(object);
-       bt_put(res_params);
-       bt_put(results);
-       bt_put(params);
-       bt_put(query_exec);
+       bt_object_put_ref(graph);
+       bt_object_put_ref(plugin_set);
+       bt_object_put_ref(results);
+       bt_object_put_ref(params);
+       bt_object_put_ref(query_exec);
 }
 
 static void test_create_all_from_dir(const char *plugin_dir)
@@ -298,7 +296,7 @@ static void test_create_all_from_dir(const char *plugin_dir)
                bt_plugin_set_get_plugin_count(plugin_set) == 4,
                "bt_plugin_create_all_from_dir() returns the expected number of plugin objects");
 
-       bt_put(plugin_set);
+       bt_object_put_ref(plugin_set);
 }
 
 static void test_find(const char *plugin_dir)
@@ -327,7 +325,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_PUT(plugin);
+       BT_OBJECT_PUT_REF_AND_RESET(plugin);
        comp_cls_sink = bt_plugin_find_component_class(NULL, "sink",
                BT_COMPONENT_CLASS_TYPE_SINK);
        ok(!comp_cls_sink, "bt_plugin_find_component_class() handles NULL (plugin name)");
@@ -347,8 +345,8 @@ static void test_find(const char *plugin_dir)
        ok(comp_cls_sink, "bt_plugin_find_component_class() succeeds with another component class name (same plugin)");
        ok(strcmp(bt_component_class_get_name(comp_cls_source), "source") == 0,
                "bt_plugin_find_component_class() returns the appropriate component class (source)");
-       BT_PUT(comp_cls_sink);
-       BT_PUT(comp_cls_source);
+       BT_OBJECT_PUT_REF_AND_RESET(comp_cls_sink);
+       BT_OBJECT_PUT_REF_AND_RESET(comp_cls_source);
        free(plugin_path);
 }
 
This page took 0.039635 seconds and 4 git commands to generate.