Skip to content

Ros2 reenable tests #59

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Nov 8, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ if(WIN32)
target_compile_definitions(${PROJECT_NAME} PRIVATE "CLASS_LOADER_BUILDING_DLL")
endif()

if(AMENT_ENABLE_TESTING)
if(BUILD_TESTING)
add_subdirectory(test)
endif()

Expand Down
4 changes: 0 additions & 4 deletions include/class_loader/class_loader.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,11 @@ std::string systemLibraryFormat(const std::string & library_name);
class ClassLoader
{
public:
#if __cplusplus >= 201103L
template<typename Base>
using DeleterType = std::function<void (Base *)>;

template<typename Base>
using UniquePtr = std::unique_ptr<Base, DeleterType<Base>>;
#endif

/**
* @brief Constructor for ClassLoader
Expand Down Expand Up @@ -125,7 +123,6 @@ class ClassLoader
);
}

#if __cplusplus >= 201103L
/// Generates an instance of loadable classes (i.e. class_loader).
/**
* It is not necessary for the user to call loadLibrary() as it will be
Expand All @@ -148,7 +145,6 @@ class ClassLoader
std::bind(&ClassLoader::onPluginDeletion<Base>, this, std::placeholders::_1)
);
}
#endif

/// Generates an instance of loadable classes (i.e. class_loader).
/**
Expand Down
2 changes: 0 additions & 2 deletions include/class_loader/multi_library_class_loader.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ class CLASS_LOADER_PUBLIC MultiLibraryClassLoader
return loader->createInstance<Base>(class_name);
}

#if __cplusplus >= 201103L
/// Creates an instance of an object of given class name with ancestor class Base
/**
* This version does not look in a specific library for the factory, but rather the first open library that defines the classs
Expand Down Expand Up @@ -152,7 +151,6 @@ class CLASS_LOADER_PUBLIC MultiLibraryClassLoader
}
return loader->createUniqueInstance<Base>(class_name);
}
#endif

/**
* @brief Creates an instance of an object of given class name with ancestor class Base
Expand Down
53 changes: 32 additions & 21 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,36 +14,47 @@ target_include_directories(${PROJECT_NAME}_TestPlugins2
target_link_libraries(${PROJECT_NAME}_TestPlugins2 ${PROJECT_NAME})
class_loader_hide_library_symbols(${PROJECT_NAME}_TestPlugins2)

ament_add_gtest(${PROJECT_NAME}_utest utest.cpp)
if(WIN32)
set(append_library_dirs "$<TARGET_FILE_DIR:${PROJECT_NAME}>;$<TARGET_FILE_DIR:${PROJECT_NAME}_TestPlugins1>")
else()
set(append_library_dirs "${CMAKE_CURRENT_BINARY_DIR}")
endif()

ament_add_gtest(${PROJECT_NAME}_utest utest.cpp
APPEND_LIBRARY_DIRS "${append_library_dirs}"
)

if(TARGET ${PROJECT_NAME}_utest)
target_include_directories(${PROJECT_NAME}_utest
PUBLIC "../include" ${console_bridge_INCLUDE_DIRS} ${Poco_INCLUDE_DIRS})
target_link_libraries(${PROJECT_NAME}_utest ${PROJECT_NAME} ${Poco_LIBRARIES})
target_link_libraries(${PROJECT_NAME}_utest
${PROJECT_NAME}
${Poco_LIBRARIES}
)
if(NOT WIN32)
target_link_libraries(${PROJECT_NAME}_utest pthread)
endif()
add_dependencies(${PROJECT_NAME}_utest ${PROJECT_NAME}_TestPlugins1 ${PROJECT_NAME}_TestPlugins2)
add_dependencies(${PROJECT_NAME}_utest
${PROJECT_NAME}_TestPlugins1
${PROJECT_NAME}_TestPlugins2)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the target already links against these libraries the dependency declaration is redundant.

Same below.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indeed the target should not link these libraries, fixed in 08d4345

endif()

include(CheckCXXCompilerFlag)
CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)
if(COMPILER_SUPPORTS_CXX11)
catkin_add_gtest(${PROJECT_NAME}_unique_ptr_test unique_ptr_test.cpp)
if(TARGET ${PROJECT_NAME}_unique_ptr_test)
target_link_libraries(${PROJECT_NAME}_unique_ptr_test
${Boost_LIBRARIES}
${class_loader_LIBRARIES}
)
set_target_properties(${PROJECT_NAME}_unique_ptr_test
PROPERTIES
COMPILE_FLAGS -std=c++11
LINK_FLAGS -std=c++11
)
add_dependencies(${PROJECT_NAME}_unique_ptr_test
${PROJECT_NAME}_TestPlugins1
${PROJECT_NAME}_TestPlugins2
)
ament_add_gtest(${PROJECT_NAME}_unique_ptr_test unique_ptr_test.cpp
APPEND_LIBRARY_DIRS "${append_library_dirs}"
)
if(TARGET ${PROJECT_NAME}_unique_ptr_test)
target_include_directories(${PROJECT_NAME}_unique_ptr_test
PUBLIC "../include" ${Poco_INCLUDE_DIRS})
target_link_libraries(${PROJECT_NAME}_unique_ptr_test
${PROJECT_NAME}
${Poco_LIBRARIES}
)
if(NOT WIN32)
target_link_libraries(${PROJECT_NAME}_unique_ptr_test pthread)
endif()
add_dependencies(${PROJECT_NAME}_unique_ptr_test
${PROJECT_NAME}_TestPlugins1
${PROJECT_NAME}_TestPlugins2)
endif()

add_subdirectory(fviz_case_study)
10 changes: 9 additions & 1 deletion test/fviz_case_study/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,15 @@ target_link_libraries(${PROJECT_NAME}_Test_FvizDefaultPlugin
${PROJECT_NAME} ${PROJECT_NAME}_Test_Fviz)
class_loader_hide_library_symbols(${PROJECT_NAME}_Test_FvizDefaultPlugin)

ament_add_gtest(${PROJECT_NAME}_fviz_test fviz_test.cpp)
if(WIN32)
set(append_library_dirs "$<TARGET_FILE_DIR:${PROJECT_NAME}>;$<TARGET_FILE_DIR:${PROJECT_NAME}_TestPlugins1>")
else()
set(append_library_dirs "${CMAKE_CURRENT_BINARY_DIR}")
endif()

ament_add_gtest(${PROJECT_NAME}_fviz_test fviz_test.cpp
APPEND_LIBRARY_DIRS "${append_library_dirs}"
)
if(TARGET ${PROJECT_NAME}_fviz_test)
target_include_directories(${PROJECT_NAME}_fviz_test
PUBLIC "../include" ${console_bridge_INCLUDE_DIRS} ${Poco_INCLUDE_DIRS})
Expand Down
19 changes: 11 additions & 8 deletions test/unique_ptr_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@
#include <class_loader/multi_library_class_loader.h>

#include <gtest/gtest.h>
#include <boost/thread.hpp>

#include <chrono>
#include <functional>
#include <iostream>
#include <string>
#include <thread>
#include <vector>

const std::string LIBRARY_1 = "libclass_loader_TestPlugins1.so";
const std::string LIBRARY_2 = "libclass_loader_TestPlugins2.so";
const std::string LIBRARY_1 = class_loader::systemLibraryFormat("class_loader_TestPlugins1");
const std::string LIBRARY_2 = class_loader::systemLibraryFormat("class_loader_TestPlugins2");

using class_loader::ClassLoader;

Expand Down Expand Up @@ -72,7 +75,7 @@ TEST(ClassLoaderUniquePtrTest, nonExistentPlugin)

obj->saySomething();
}
catch(const class_loader::CreateClassException& e)
catch(const class_loader::CreateClassException&)
{
SUCCEED();
return;
Expand All @@ -89,7 +92,7 @@ TEST(ClassLoaderUniquePtrTest, nonExistentPlugin)

void wait(int seconds)
{
boost::this_thread::sleep(boost::posix_time::seconds(seconds));
std::this_thread::sleep_for(std::chrono::seconds(seconds));
}

void run(ClassLoader* loader)
Expand All @@ -111,7 +114,7 @@ TEST(ClassLoaderUniquePtrTest, threadSafety)
//or something if there's some implementation error.
try
{
std::vector<boost::thread> client_threads;
std::vector<std::thread> client_threads;

for(unsigned int c = 0; c < 1000; c++)
client_threads.emplace_back(std::bind(&run, &loader1));
Expand All @@ -123,7 +126,7 @@ TEST(ClassLoaderUniquePtrTest, threadSafety)
ASSERT_FALSE(loader1.isLibraryLoaded());

}
catch(const class_loader::ClassLoaderException& ex)
catch(const class_loader::ClassLoaderException&)
{
FAIL() << "Unexpected ClassLoaderException.";
}
Expand Down Expand Up @@ -170,7 +173,7 @@ TEST(ClassLoaderUniquePtrTest, loadRefCountingLazy)

return;
}
catch(const class_loader::ClassLoaderException& e)
catch(const class_loader::ClassLoaderException&)
{
FAIL() << "Unexpected exception.\n";
}
Expand Down
12 changes: 6 additions & 6 deletions test/utest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ TEST(ClassLoaderTest, nonExistentPlugin)
}

obj->saySomething();
} catch (const class_loader::CreateClassException & e) {
} catch (const class_loader::CreateClassException &) {
SUCCEED();
return;
} catch (...) {
Expand All @@ -88,7 +88,7 @@ TEST(ClassLoaderTest, nonExistentLibrary)
{
try {
class_loader::ClassLoader loader1("libDoesNotExist.so", false);
} catch (const class_loader::LibraryLoadException & e) {
} catch (const class_loader::LibraryLoadException &) {
SUCCEED();
return;
} catch (...) {
Expand All @@ -115,7 +115,7 @@ TEST(ClassLoaderTest, invalidBase)
} else {
FAIL() << "Class not available for correct base class.";
}
} catch (const class_loader::LibraryLoadException & e) {
} catch (const class_loader::LibraryLoadException &) {
FAIL() << "Unexpected exception";
} catch (...) {
FAIL() << "Unexpected and unknown exception caught.\n";
Expand Down Expand Up @@ -161,7 +161,7 @@ TEST(ClassLoaderTest, threadSafety)
loader1.unloadLibrary();
ASSERT_FALSE(loader1.isLibraryLoaded());

} catch (const class_loader::ClassLoaderException & ex) {
} catch (const class_loader::ClassLoaderException &) {
FAIL() << "Unexpected ClassLoaderException.";
} catch (...) {
FAIL() << "Unknown exception.";
Expand Down Expand Up @@ -194,7 +194,7 @@ TEST(ClassLoaderTest, loadRefCountingNonLazy)
ASSERT_TRUE(loader1.isLibraryLoaded());

return;
} catch (const class_loader::ClassLoaderException & e) {
} catch (const class_loader::ClassLoaderException &) {
FAIL() << "Unexpected exception.\n";
} catch (...) {
FAIL() << "Unknown exception caught.\n";
Expand Down Expand Up @@ -235,7 +235,7 @@ TEST(ClassLoaderTest, loadRefCountingLazy)
ASSERT_TRUE(loader1.isLibraryLoaded());

return;
} catch (const class_loader::ClassLoaderException & e) {
} catch (const class_loader::ClassLoaderException &) {
FAIL() << "Unexpected exception.\n";
} catch (...) {
FAIL() << "Unknown exception caught.\n";
Expand Down