Move test directory one up

This commit is contained in:
Dennis Klein
2018-04-12 17:46:18 +02:00
parent 33fffb1644
commit 2327fd2115
51 changed files with 21 additions and 85 deletions

79
test/plugins/_plugin.cxx Normal file
View File

@@ -0,0 +1,79 @@
/********************************************************************************
* Copyright (C) 2017 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
* *
* This software is distributed under the terms of the *
* GNU Lesser General Public Licence (LGPL) version 3, *
* copied verbatim in the file "LICENSE" *
********************************************************************************/
#include <gtest/gtest.h>
#include <fairmq/Plugin.h>
#include <fairmq/PluginServices.h>
#include <fairmq/Tools.h>
#include <FairMQDevice.h>
#include <options/FairMQProgOptions.h>
#include <memory>
#include <sstream>
#include <string>
#include <vector>
namespace
{
using namespace std;
using namespace fair::mq;
auto control(shared_ptr<FairMQDevice> device) -> void
{
device->SetTransport("zeromq");
for (const auto event : {
FairMQDevice::INIT_DEVICE,
FairMQDevice::RESET_DEVICE,
FairMQDevice::END,
}) {
device->ChangeState(event);
if (event != FairMQDevice::END) device->WaitForEndOfState(event);
}
}
TEST(Plugin, Operators)
{
FairMQProgOptions config{};
auto device = make_shared<FairMQDevice>();
PluginServices services{&config, device};
Plugin p1{"dds", {1, 0, 0}, "Foo Bar <foo.bar@test.net>", "https://git.test.net/dds.git", &services};
Plugin p2{"dds", {1, 0, 0}, "Foo Bar <foo.bar@test.net>", "https://git.test.net/dds.git", &services};
Plugin p3{"file", {1, 0, 0}, "Foo Bar <foo.bar@test.net>", "https://git.test.net/file.git", &services};
EXPECT_EQ(p1, p2);
EXPECT_NE(p1, p3);
control(device);
}
TEST(Plugin, OstreamOperators)
{
FairMQProgOptions config{};
auto device = make_shared<FairMQDevice>();
PluginServices services{&config, device};
Plugin p1{"dds", {1, 0, 0}, "Foo Bar <foo.bar@test.net>", "https://git.test.net/dds.git", &services};
stringstream ss;
ss << p1;
EXPECT_EQ(ss.str(), string{"'dds', version '1.0.0', maintainer 'Foo Bar <foo.bar@test.net>', homepage 'https://git.test.net/dds.git'"});
control(device);
}
TEST(PluginVersion, Operators)
{
struct fair::mq::tools::Version v1{1, 0, 0};
struct fair::mq::tools::Version v2{1, 0, 0};
struct fair::mq::tools::Version v3{1, 2, 0};
EXPECT_EQ(v1, v2);
EXPECT_NE(v1, v3);
EXPECT_GT(v3, v2);
EXPECT_LT(v1, v3);
EXPECT_GE(v3, v2);
EXPECT_GE(v2, v1);
EXPECT_LE(v1, v2);
EXPECT_LE(v2, v3);
}
} /* namespace */

View File

@@ -0,0 +1,157 @@
/********************************************************************************
* Copyright (C) 2017 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
* *
* This software is distributed under the terms of the *
* GNU Lesser General Public Licence (LGPL) version 3, *
* copied verbatim in the file "LICENSE" *
********************************************************************************/
#include <gtest/gtest.h>
#include <fairmq/PluginManager.h>
#include <fairmq/PluginServices.h>
#include <FairMQDevice.h>
#include <options/FairMQProgOptions.h>
#include <FairMQLogger.h>
#include <fstream>
#include <memory>
#include <vector>
namespace
{
using namespace fair::mq;
using namespace boost::filesystem;
using namespace boost::program_options;
using namespace std;
auto control(shared_ptr<FairMQDevice> device) -> void
{
device->SetTransport("zeromq");
for (const auto event : {
FairMQDevice::INIT_DEVICE,
FairMQDevice::RESET_DEVICE,
FairMQDevice::END,
}) {
device->ChangeState(event);
if (event != FairMQDevice::END) device->WaitForEndOfState(event);
}
}
TEST(PluginManager, LoadPluginDynamic)
{
FairMQProgOptions config{};
auto mgr = PluginManager{};
auto device = make_shared<FairMQDevice>();
mgr.EmplacePluginServices(&config, device);
mgr.PrependSearchPath("./lib");
ASSERT_NO_THROW(mgr.LoadPlugin("test_dummy"));
ASSERT_NO_THROW(mgr.LoadPlugin("test_dummy2"));
ASSERT_NO_THROW(mgr.InstantiatePlugins());
// check order
const auto expected = vector<string>{"test_dummy", "test_dummy2"};
auto actual = vector<string>{};
mgr.ForEachPlugin([&](Plugin& plugin){ actual.push_back(plugin.GetName()); });
ASSERT_TRUE(actual == expected);
// program options
auto count = 0;
mgr.ForEachPluginProgOptions([&count](const options_description& /*d*/){ ++count; });
ASSERT_EQ(count, 1);
control(device);
}
TEST(PluginManager, LoadPluginStatic)
{
auto mgr = PluginManager{};
auto device = make_shared<FairMQDevice>();
device->SetTransport("zeromq");
ASSERT_NO_THROW(mgr.LoadPlugin("s:control"));
FairMQProgOptions config{};
config.SetValue<string>("control", "static");
config.SetValue("catch-signals", 0);
mgr.EmplacePluginServices(&config, device);
ASSERT_NO_THROW(mgr.InstantiatePlugins());
// check order
const auto expected = vector<string>{"control"};
auto actual = vector<string>{};
mgr.ForEachPlugin([&](Plugin& plugin){ actual.push_back(plugin.GetName()); });
ASSERT_TRUE(actual == expected);
// program options
auto count = 0;
mgr.ForEachPluginProgOptions([&count](const options_description& d){ ++count; });
ASSERT_EQ(count, 1);
mgr.WaitForPluginsToReleaseDeviceControl();
}
TEST(PluginManager, Factory)
{
const auto args = vector<string>{"-l", "debug", "--help", "-S", ">/lib", "</home/user/lib", "/usr/local/lib", "/usr/lib"};
auto mgr = PluginManager::MakeFromCommandLineOptions(args);
const auto path1 = path{"/home/user/lib"};
const auto path2 = path{"/usr/local/lib"};
const auto path3 = path{"/usr/lib"};
const auto path4 = path{"/lib"};
const auto expected = vector<path>{path1, path2, path3, path4};
ASSERT_TRUE(static_cast<bool>(mgr));
ASSERT_TRUE(mgr->SearchPaths() == expected);
}
TEST(PluginManager, SearchPathValidation)
{
const auto path1 = path{"/tmp/test1"};
const auto path2 = path{"/tmp/test2"};
const auto path3 = path{"/tmp/test3"};
auto mgr = PluginManager{};
mgr.SetSearchPaths({path1, path2});
auto expected = vector<path>{path1, path2};
ASSERT_EQ(mgr.SearchPaths(), expected);
mgr.AppendSearchPath(path3);
expected = vector<path>{path1, path2, path3};
ASSERT_EQ(mgr.SearchPaths(), expected);
mgr.PrependSearchPath(path3);
expected = vector<path>{path3, path1, path2, path3};
ASSERT_EQ(mgr.SearchPaths(), expected);
}
TEST(PluginManager, SearchPaths)
{
const auto temp = temp_directory_path() / unique_path();
create_directories(temp);
const auto non_existing_dir = temp / "non-existing-dir";
const auto existing_dir = temp / "existing-dir";
create_directories(existing_dir);
const auto existing_file = temp / "existing-file.so";
std::fstream fs;
fs.open(existing_file.string(), std::fstream::out);
fs.close();
const auto empty_path = path{""};
auto mgr = PluginManager{};
ASSERT_NO_THROW(mgr.AppendSearchPath(non_existing_dir));
ASSERT_NO_THROW(mgr.AppendSearchPath(existing_dir));
ASSERT_THROW(mgr.AppendSearchPath(existing_file), PluginManager::BadSearchPath);
ASSERT_NO_THROW(mgr.PrependSearchPath(non_existing_dir));
ASSERT_NO_THROW(mgr.PrependSearchPath(existing_dir));
ASSERT_THROW(mgr.PrependSearchPath(existing_file), PluginManager::BadSearchPath);
ASSERT_NO_THROW(mgr.SetSearchPaths({non_existing_dir, existing_dir}));
ASSERT_THROW(mgr.SetSearchPaths({non_existing_dir, existing_file}), PluginManager::BadSearchPath);
ASSERT_THROW(mgr.SetSearchPaths({non_existing_dir, empty_path}), PluginManager::BadSearchPath);
remove_all(temp);
}
} /* namespace */

View File

@@ -0,0 +1,26 @@
/********************************************************************************
* Copyright (C) 2017 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
* *
* This software is distributed under the terms of the *
* GNU Lesser General Public Licence (LGPL) version 3, *
* copied verbatim in the file "LICENSE" *
********************************************************************************/
#include <gtest/gtest.h>
#include <fairmq/PluginManager.h>
namespace
{
using namespace fair::mq;
using namespace std;
TEST(PluginManager, LoadPluginPrelinkedDynamic)
{
auto mgr = PluginManager{};
ASSERT_NO_THROW(mgr.LoadPlugin("p:test_dummy"));
ASSERT_NO_THROW(mgr.LoadPlugin("p:test_dummy2"));
}
} /* namespace */

16
test/plugins/runner.cxx Normal file
View File

@@ -0,0 +1,16 @@
/********************************************************************************
* Copyright (C) 2017 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
* *
* This software is distributed under the terms of the *
* GNU Lesser General Public Licence (LGPL) version 3, *
* copied verbatim in the file "LICENSE" *
********************************************************************************/
#include <gtest/gtest.h>
int main(int argc, char** argv)
{
::testing::InitGoogleTest(&argc, argv);
::testing::FLAGS_gtest_death_test_style = "threadsafe";
return RUN_ALL_TESTS();
}