Skip to content

Commit

Permalink
Added more tests to test_shared_library
Browse files Browse the repository at this point in the history
  • Loading branch information
ahcorde committed Mar 24, 2020
1 parent 4a128d9 commit 5630628
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions test/test_shared_library.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,33 @@ TEST(test_shared_library, valid_load) {
const std::string library_path = std::string("libdummy_shared_library.so");

EXPECT_NO_THROW(std::make_shared<rcpputils::SharedLibrary>(library_path));
EXPECT_ANY_THROW(std::make_shared<rcpputils::SharedLibrary>("library_path"));

auto library = std::make_shared<rcpputils::SharedLibrary>(library_path);
EXPECT_STREQ(library->get_library_path().c_str(), library_path.c_str());

EXPECT_TRUE(library->has_symbol("print_name"));
EXPECT_FALSE(library->has_symbol("symbol"));

EXPECT_TRUE(library->get_symbol("print_name") != NULL);
EXPECT_ANY_THROW(library->get_symbol("symbol"));
}

TEST(test_shared_library, failed_test) {
// Trying to reset the object two times
try {
std::shared_ptr<rcpputils::SharedLibrary> library;
library.reset();
library.reset();

This comment has been minimized.

Copy link
@wjwwood

wjwwood Mar 26, 2020

Member

What is this testing?

This comment has been minimized.

Copy link
@ahcorde

ahcorde Mar 26, 2020

Author Contributor

I was trying to call the destructor twice, but maybe with smartpoints it doesn't make sense. 😅

This comment has been minimized.

Copy link
@wjwwood

wjwwood Mar 27, 2020

Member

No that will not work, after the first one, library will point to nullptr.

} catch (...) {
FAIL();
}
// loading a library that doesn't exists
std::string library_path = std::string("error_library.so");
EXPECT_THROW(std::make_shared<rcpputils::SharedLibrary>(library_path), std::runtime_error);

// Loading a valid library
library_path = std::string("libdummy_shared_library.so");
auto library = std::make_shared<rcpputils::SharedLibrary>(library_path);

This comment has been minimized.

Copy link
@wjwwood

wjwwood Mar 26, 2020

Member

Does this need to be a shared pointer?

This comment has been minimized.

Copy link
@ahcorde

ahcorde Mar 26, 2020

Author Contributor

not really, but I activated the sanitizer for this test

This comment has been minimized.

Copy link
@wjwwood

wjwwood Mar 27, 2020

Member

What does the sanitizer have to do with that? You mean address sanitizer or ...?


// getting and asking for an unvalid symbol
EXPECT_THROW(library->get_symbol("symbol"), std::runtime_error);
EXPECT_FALSE(library->has_symbol("symbol"));
}

0 comments on commit 5630628

Please sign in to comment.