Cleanup: mixing enum types
[babeltrace.git] / tests / lib / test_plugin.c
index ad8489e88a27a60ea605886a269168f5eaace91c..f3f229f55f3193fd56cab595181f0e9ef20b36f5 100644 (file)
 #define NON_EXISTING_PATH      "/this/hopefully/does/not/exist/5bc75f8d-0dba-4043-a509-d7984b97e42b.so"
 
 /* Those symbols are written to by some test plugins */
-int test_plugin_init_called;
-int test_plugin_exit_called;
+static int check_env_var(const char *name)
+{
+       const char *val = getenv(name);
+
+       if (!val) {
+               return -1;
+       }
 
-static void reset_test_plugin_symbols(void)
+       return atoi(val);
+}
+
+static void reset_test_plugin_env_vars(void)
 {
-       test_plugin_init_called = 0;
-       test_plugin_exit_called = 0;
+       g_setenv("BT_TEST_PLUGIN_INIT_CALLED", "0", 1);
+       g_setenv("BT_TEST_PLUGIN_EXIT_CALLED", "0", 1);
 }
 
 static char *get_test_plugin_path(const char *plugin_dir,
@@ -102,11 +110,12 @@ static void test_minimal(const char *plugin_dir)
        assert(minimal_path);
        diag("minimal plugin test below");
 
-       reset_test_plugin_symbols();
+       reset_test_plugin_env_vars();
        plugin_set = bt_plugin_create_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");
-       ok(test_plugin_init_called, "plugin's initialization function is called during bt_plugin_create_all_from_file()");
+       ok(check_env_var("BT_TEST_PLUGIN_INIT_CALLED") == 1,
+               "plugin's initialization function is called during bt_plugin_create_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_get_plugin(plugin_set, 0);
@@ -128,7 +137,8 @@ static void test_minimal(const char *plugin_dir)
                "bt_plugin_get_component_class_count() returns the expected value");
        bt_put(plugin);
        bt_put(plugin_set);
-       ok(test_plugin_exit_called, "plugin's exit function is called when the plugin is destroyed");
+       ok(check_env_var("BT_TEST_PLUGIN_EXIT_CALLED") == 1,
+               "plugin's exit function is called when the plugin is destroyed");
 
        free(minimal_path);
 }
@@ -150,7 +160,8 @@ static void test_sfs(const char *plugin_dir)
        struct bt_value *res_params;
        struct bt_graph *graph;
        const char *object_str;
-       int ret;
+       enum bt_value_status value_ret;
+       enum bt_graph_status graph_ret;
 
        assert(sfs_path);
        diag("sfs plugin test below");
@@ -209,8 +220,8 @@ static void test_sfs(const char *plugin_dir)
        assert(bt_value_is_array(results) && bt_value_array_size(results) == 2);
        object = bt_value_array_get(results, 0);
        assert(object && bt_value_is_string(object));
-       ret = bt_value_string_get(object, &object_str);
-       assert(ret == 0);
+       value_ret = bt_value_string_get(object, &object_str);
+       assert(value_ret == BT_VALUE_STATUS_OK);
        ok(strcmp(object_str, "get-something") == 0,
                "bt_component_class_query() receives the expected object name");
        res_params = bt_value_array_get(results, 1);
@@ -221,27 +232,27 @@ static void test_sfs(const char *plugin_dir)
        BT_PUT(plugin);
        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,
+       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);
        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,
+       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);
        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,
+       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);
This page took 0.025755 seconds and 4 git commands to generate.