Test fix: fixed allocation size used for variable length input
[babeltrace.git] / tests / lib / test_plugin.c
index a256b7cbcb958ed07c566044d7f22949a3823454..ad8489e88a27a60ea605886a269168f5eaace91c 100644 (file)
 #include <babeltrace/ref.h>
 #include <babeltrace/values.h>
 #include <babeltrace/graph/component.h>
+#include <babeltrace/graph/graph.h>
 #include <stdlib.h>
 #include <string.h>
 #include <stdio.h>
 #include <assert.h>
 #include <glib.h>
-#include <linux/limits.h>
 #include "tap/tap.h"
 #include "common.h"
 
@@ -70,7 +70,7 @@ static void test_invalid(const char *plugin_dir)
 
        ok(!bt_plugin_create_all_from_file(NULL),
                "bt_plugin_create_all_from_file() handles NULL correctly");
-       ok(!bt_plugin_create_all_from_dir(NULL, false),
+       ok(!bt_plugin_create_all_from_dir(NULL, BT_FALSE),
                "bt_plugin_create_all_from_dir() handles NULL correctly");
        ok(!bt_plugin_get_name(NULL),
                "bt_plugin_get_name() handles NULL correctly");
@@ -148,6 +148,7 @@ static void test_sfs(const char *plugin_dir)
        struct bt_value *results;
        struct bt_value *object;
        struct bt_value *res_params;
+       struct bt_graph *graph;
        const char *object_str;
        int ret;
 
@@ -218,20 +219,35 @@ static void test_sfs(const char *plugin_dir)
 
        diag("> putting the plugin object here");
        BT_PUT(plugin);
-       sink_component = bt_component_create(sink_comp_class, NULL, NULL);
-       ok(sink_component, "bt_component_create() still works after the plugin object is destroyed");
+       graph = bt_graph_create();
+       assert(graph);
+       ret = bt_graph_add_component(graph, sink_comp_class, "the-sink", NULL,
+               &sink_component);
+       ok(ret == 0 && sink_component,
+               "bt_graph_add_component() still works after the plugin object is destroyed");
        BT_PUT(sink_component);
        BT_PUT(source_comp_class);
-       sink_component = bt_component_create(sink_comp_class, NULL, NULL);
-       ok(sink_component, "bt_component_create() still works after the source component class object is destroyed");
+       bt_put(graph);
+       graph = bt_graph_create();
+       assert(graph);
+       ret = bt_graph_add_component(graph, sink_comp_class, "the-sink", NULL,
+               &sink_component);
+       ok(ret == 0 && 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);
-       sink_component = bt_component_create(sink_comp_class, NULL, NULL);
-       ok(sink_component, "bt_component_create() still works after the filter component class object is destroyed");
+       bt_put(graph);
+       graph = bt_graph_create();
+       assert(graph);
+       ret = bt_graph_add_component(graph, sink_comp_class, "the-sink", NULL,
+               &sink_component);
+       ok(ret == 0 && 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);
 
        free(sfs_path);
+       bt_put(graph);
        bt_put(plugin_set);
        bt_put(object);
        bt_put(res_params);
@@ -245,11 +261,11 @@ static void test_create_all_from_dir(const char *plugin_dir)
 
        diag("create from all test below");
 
-       plugin_set = bt_plugin_create_all_from_dir(NON_EXISTING_PATH, false);
+       plugin_set = bt_plugin_create_all_from_dir(NON_EXISTING_PATH, BT_FALSE);
        ok(!plugin_set,
                "bt_plugin_create_all_from_dir() fails with an invalid path");
 
-       plugin_set = bt_plugin_create_all_from_dir(plugin_dir, false);
+       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");
 
        /* 2 or 4, if `.la` files are considered or not */
@@ -262,6 +278,7 @@ static void test_create_all_from_dir(const char *plugin_dir)
 
 static void test_find(const char *plugin_dir)
 {
+       int ret;
        struct bt_plugin *plugin;
        struct bt_component_class *comp_cls_sink;
        struct bt_component_class *comp_cls_source;
@@ -271,11 +288,10 @@ static void test_find(const char *plugin_dir)
                "bt_plugin_find() handles NULL");
        ok(!bt_plugin_find(NON_EXISTING_PATH),
                "bt_plugin_find() returns NULL with an unknown plugin name");
-       plugin_path = malloc(PATH_MAX * 5);
-       assert(plugin_path);
-       sprintf(plugin_path, "%s:/ec1d09e5-696c-442e-b1c3-f9c6cf7f5958:::%s:8db46494-a398-466a-9649-c765ae077629:",
+       ret = asprintf(&plugin_path, "%s:/ec1d09e5-696c-442e-b1c3-f9c6cf7f5958:::%s:8db46494-a398-466a-9649-c765ae077629:",
                NON_EXISTING_PATH, plugin_dir);
-       setenv("BABELTRACE_PLUGIN_PATH", plugin_path, 1);
+       assert(ret > 0 && plugin_path);
+       g_setenv("BABELTRACE_PLUGIN_PATH", plugin_path, 1);
        plugin = bt_plugin_find("test_minimal");
        ok(plugin,
                "bt_plugin_find() succeeds with a plugin name it can find");
This page took 0.025349 seconds and 4 git commands to generate.