-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add dummy shared lib to test mef::ExternLibrary
Basic smoke tests are provided to check if the dynamic library loading works on the given platform. Issue #74
- Loading branch information
Showing
5 changed files
with
122 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/* | ||
* Copyright (C) 2017 Olzhas Rakhimov | ||
* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation; either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#include "expression/extern.h" | ||
|
||
#include <memory> | ||
|
||
#include <gtest/gtest.h> | ||
|
||
#include <boost/predef.h> | ||
|
||
#if BOOST_OS_LINUX | ||
#include <stdlib.h> | ||
#endif | ||
|
||
#include "env.h" | ||
|
||
namespace scram { | ||
namespace mef { | ||
namespace test { | ||
|
||
const char kLibName[] = "scram_dummy_extern"; | ||
const char kLibRelPath[] = "../lib/scram/test/scram_dummy_extern"; | ||
|
||
#if BOOST_OS_LINUX | ||
const char kLibRelPathLinux[] = "../lib/scram/test/libscram_dummy_extern.so"; | ||
#endif | ||
|
||
TEST(ExternTest, ExternLibraryLoad) { | ||
const std::string bin_dir = Env::install_dir() + "/bin"; | ||
EXPECT_THROW(ExternLibrary("dummy", kLibName, "", false, false), IOError); | ||
EXPECT_THROW(ExternLibrary("dummy", kLibName, "", false, true), IOError); | ||
EXPECT_THROW(ExternLibrary("dummy", kLibName, "", true, true), IOError); | ||
EXPECT_THROW(ExternLibrary("dummy", kLibRelPath, bin_dir, false, false), | ||
IOError); | ||
EXPECT_NO_THROW(ExternLibrary("dummy", kLibRelPath, bin_dir, false, true)); | ||
EXPECT_NO_THROW(ExternLibrary("dummy", kLibRelPath, bin_dir, true, true)); | ||
|
||
#if BOOST_OS_LINUX | ||
EXPECT_NO_THROW( | ||
ExternLibrary("dummy", kLibRelPathLinux, bin_dir, false, false)); | ||
// The system search with LD_LIBRARY_PATH must be tested outside. | ||
#endif | ||
} | ||
|
||
TEST(ExternTest, ExternLibraryGet) { | ||
const std::string bin_dir = Env::install_dir() + "/bin"; | ||
|
||
std::unique_ptr<ExternLibrary> library; | ||
ASSERT_NO_THROW(library = std::make_unique<ExternLibrary>( | ||
"dummy", kLibRelPath, bin_dir, false, true)); | ||
|
||
EXPECT_NO_THROW(library->get<int(*)()>("foo")); | ||
EXPECT_NO_THROW(library->get<double(*)()>("bar")); | ||
EXPECT_NO_THROW(library->get<float(*)()>("baz")); | ||
EXPECT_THROW(library->get<int(*)()>("foobar"), UndefinedElement); | ||
|
||
EXPECT_EQ(42, library->get<int(*)()>("foo")()); | ||
EXPECT_EQ(42, library->get<double(*)()>("bar")()); | ||
EXPECT_EQ(42, library->get<float(*)()>("baz")()); | ||
} | ||
|
||
} // namespace test | ||
} // namespace mef | ||
} // namespace scram |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* | ||
* Copyright (C) 2017 Olzhas Rakhimov | ||
* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation; either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
/// @file scram_dummy_extern.cc | ||
/// Dummy library with extern functions to test dynamic loading in MEF extern. | ||
|
||
extern "C" { | ||
int foo() { return 42; } | ||
double bar() { return 42; } | ||
float baz() { return 42; } | ||
} |