Add shared object comp. class help attribute test
[babeltrace.git] / tests / lib / test_plugin.c
index e52617290793897c631bb13f3e864a8a6d8af1c0..7fa338f60af9920078b05775090d30996874bb42 100644 (file)
 #include <stdio.h>
 #include <assert.h>
 #include <glib.h>
+#include <linux/limits.h>
 #include "tap/tap.h"
 #include "common.h"
 
-#define NR_TESTS               33
+#define NR_TESTS               45
 #define NON_EXISTING_PATH      "/this/hopefully/does/not/exist/5bc75f8d-0dba-4043-a509-d7984b97e42b.so"
 
 /* Those symbols are written to by some test plugins */
@@ -58,28 +59,25 @@ static char *get_test_plugin_path(const char *plugin_dir,
 
 static void test_invalid(const char *plugin_dir)
 {
-       struct bt_plugin *plugin;
-       char *invalid_path = get_test_plugin_path(plugin_dir, "invalid");;
-
-       assert(invalid_path);
-
-       plugin = bt_plugin_create_from_file(NON_EXISTING_PATH);
-       ok(!plugin, "bt_plugin_create_from_file() fails with a non-existing file");
+       struct bt_plugin **plugins;
 
-       plugin = bt_plugin_create_from_file(plugin_dir);
-       ok(!plugin, "bt_plugin_create_from_file() fails with a directory");
+       plugins = bt_plugin_create_all_from_file(NON_EXISTING_PATH);
+       ok(!plugins, "bt_plugin_create_all_from_file() fails with a non-existing file");
 
-       plugin = bt_plugin_create_from_file(invalid_path);
-       ok(!plugin, "bt_plugin_create_from_file() fails with an invalid plugin file");
+       plugins = bt_plugin_create_all_from_file(plugin_dir);
+       ok(!plugins, "bt_plugin_create_all_from_file() fails with a directory");
 
-       ok(!bt_plugin_create_from_file(NULL),
-               "bt_plugin_create_from_file() handles NULL correctly");
+       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),
                "bt_plugin_create_all_from_dir() handles NULL correctly");
        ok(!bt_plugin_get_name(NULL),
                "bt_plugin_get_name() handles NULL correctly");
        ok(!bt_plugin_get_description(NULL),
                "bt_plugin_get_description() handles NULL correctly");
+       ok(bt_plugin_get_version(NULL, NULL, NULL, NULL, NULL) !=
+               BT_PLUGIN_STATUS_OK,
+               "bt_plugin_get_version() handles NULL correctly");
        ok(!bt_plugin_get_author(NULL),
                "bt_plugin_get_author() handles NULL correctly");
        ok(!bt_plugin_get_license(NULL),
@@ -92,12 +90,11 @@ static void test_invalid(const char *plugin_dir)
                "bt_plugin_get_component_class() handles NULL correctly");
        ok(!bt_plugin_get_component_class_by_name_and_type(NULL, NULL, 0),
                "bt_plugin_get_component_class_by_name_and_type() handles NULL correctly");
-
-       free(invalid_path);
 }
 
 static void test_minimal(const char *plugin_dir)
 {
+       struct bt_plugin **plugins;
        struct bt_plugin *plugin;
        char *minimal_path = get_test_plugin_path(plugin_dir, "minimal");
 
@@ -105,15 +102,20 @@ static void test_minimal(const char *plugin_dir)
        diag("minimal plugin test below");
 
        reset_test_plugin_symbols();
-       plugin = bt_plugin_create_from_file(minimal_path);
-       ok(plugin, "bt_plugin_create_from_file() succeeds with a valid file");
-       ok(test_plugin_init_called && !test_plugin_exit_called,
-               "plugin's initialization function is called during bt_plugin_create_from_file()");
-       ok(strcmp(bt_plugin_get_name(plugin), "test-minimal") == 0,
+       plugins = bt_plugin_create_all_from_file(minimal_path);
+       ok(plugins && plugins[0], "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(plugins && plugins[0] && !plugins[1],
+               "bt_plugin_create_all_from_file() returns the expected number of plugins");
+       plugin = plugins[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),
                "Minimal Babeltrace plugin with no component classes") == 0,
                "bt_plugin_get_description() returns the expected description");
+       ok(bt_plugin_get_version(plugin, NULL, NULL, NULL, NULL) !=
+               BT_PLUGIN_STATUS_OK,
+               "bt_plugin_get_version() fails when there's no version");
        ok(strcmp(bt_plugin_get_author(plugin), "Janine Sutto") == 0,
                "bt_plugin_get_author() returns the expected author");
        ok(strcmp(bt_plugin_get_license(plugin), "Beerware") == 0,
@@ -126,42 +128,63 @@ static void test_minimal(const char *plugin_dir)
        ok(test_plugin_exit_called, "plugin's exit function is called when the plugin is destroyed");
 
        free(minimal_path);
+       free(plugins);
 }
 
 static void test_sfs(const char *plugin_dir)
 {
+       struct bt_plugin **plugins;
        struct bt_plugin *plugin;
        struct bt_component_class *sink_comp_class;
        struct bt_component_class *source_comp_class;
        struct bt_component_class *filter_comp_class;
        struct bt_component *sink_component;
        char *sfs_path = get_test_plugin_path(plugin_dir, "sfs");
+       unsigned int major, minor, patch;
+       const char *extra;
 
        assert(sfs_path);
        diag("sfs plugin test below");
 
-       plugin = bt_plugin_create_from_file(sfs_path);
-       assert(plugin);
+       plugins = bt_plugin_create_all_from_file(sfs_path);
+       assert(plugins && plugins[0]);
+       plugin = plugins[0];
+       ok(bt_plugin_get_version(plugin, &major, &minor, &patch, &extra) ==
+               BT_PLUGIN_STATUS_OK,
+               "bt_plugin_get_version() succeeds when there's a version");
+       ok(major == 1,
+               "bt_plugin_get_version() returns the expected major version");
+       ok(minor == 2,
+               "bt_plugin_get_version() returns the expected minor version");
+       ok(patch == 3,
+               "bt_plugin_get_version() returns the expected patch version");
+       ok(strcmp(extra, "yes") == 0,
+               "bt_plugin_get_version() returns the expected extra version");
        ok(bt_plugin_get_component_class_count(plugin) == 3,
                "bt_plugin_get_component_class_count() returns the expected value");
 
        source_comp_class = bt_plugin_get_component_class_by_name_and_type(
-               plugin, "source", BT_COMPONENT_TYPE_SOURCE);
+               plugin, "source", BT_COMPONENT_CLASS_TYPE_SOURCE);
        ok(source_comp_class,
                "bt_plugin_get_component_class_by_name_and_type() finds a source component class");
 
        sink_comp_class = bt_plugin_get_component_class_by_name_and_type(
-               plugin, "sink", BT_COMPONENT_TYPE_SINK);
-
+               plugin, "sink", BT_COMPONENT_CLASS_TYPE_SINK);
        ok(sink_comp_class,
                "bt_plugin_get_component_class_by_name_and_type() finds a sink component class");
-       filter_comp_class = bt_plugin_get_component_class_by_name_and_type(
-               plugin, "filter", BT_COMPONENT_TYPE_FILTER);
+       ok(strcmp(bt_component_class_get_help(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_get_component_class_by_name_and_type(
+               plugin, "filter", BT_COMPONENT_CLASS_TYPE_FILTER);
        ok(filter_comp_class,
                "bt_plugin_get_component_class_by_name_and_type() finds a filter component class");
        ok(!bt_plugin_get_component_class_by_name_and_type(plugin, "filter",
-               BT_COMPONENT_TYPE_SOURCE),
+               BT_COMPONENT_CLASS_TYPE_SOURCE),
                "bt_plugin_get_component_class_by_name_and_type() does not find a component class given the wrong type");
 
        diag("> putting the plugin object here");
@@ -180,6 +203,7 @@ static void test_sfs(const char *plugin_dir)
        BT_PUT(sink_component);
 
        free(sfs_path);
+       free(plugins);
 }
 
 static void test_create_all_from_dir(const char *plugin_dir)
@@ -209,6 +233,29 @@ static void test_create_all_from_dir(const char *plugin_dir)
        free(plugins);
 }
 
+static void test_create_from_name(const char *plugin_dir)
+{
+       struct bt_plugin *plugin;
+       char *plugin_path;
+
+       ok(!bt_plugin_create_from_name(NULL),
+               "bt_plugin_create_from_name() handles NULL");
+       ok(!bt_plugin_create_from_name(NON_EXISTING_PATH),
+               "bt_plugin_create_from_name() 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:",
+               NON_EXISTING_PATH, plugin_dir);
+       setenv("BABELTRACE_PLUGIN_PATH", plugin_path, 1);
+       plugin = bt_plugin_create_from_name("test_minimal");
+       ok(plugin,
+               "bt_plugin_create_from_name() succeeds with a plugin name it can find");
+       ok(strcmp(bt_plugin_get_author(plugin), "Janine Sutto") == 0,
+               "bt_plugin_create_from_name() finds the correct plugin for a given name");
+       BT_PUT(plugin);
+       free(plugin_path);
+}
+
 int main(int argc, char **argv)
 {
        int ret;
@@ -226,6 +273,7 @@ int main(int argc, char **argv)
        test_minimal(plugin_dir);
        test_sfs(plugin_dir);
        test_create_all_from_dir(plugin_dir);
+       test_create_from_name(plugin_dir);
        ret = exit_status();
 end:
        return ret;
This page took 0.029988 seconds and 4 git commands to generate.