Skip to content

Commit 3411f8d

Browse files
Ros2 reenable tests (#59)
* reenable tests * remove boost * windows compatibility, fun fact __cplusplus is set to 199711L in VS2015 so we cant use that, removing all cpp11 checks for now given that ros2 and melodic will only target compilers that support it * tidy up code and fix warnings
1 parent 16b37e9 commit 3411f8d

File tree

7 files changed

+59
-43
lines changed

7 files changed

+59
-43
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ if(WIN32)
4343
target_compile_definitions(${PROJECT_NAME} PRIVATE "CLASS_LOADER_BUILDING_DLL")
4444
endif()
4545

46-
if(AMENT_ENABLE_TESTING)
46+
if(BUILD_TESTING)
4747
add_subdirectory(test)
4848
endif()
4949

include/class_loader/class_loader.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,11 @@ std::string systemLibraryFormat(const std::string & library_name);
7575
class ClassLoader
7676
{
7777
public:
78-
#if __cplusplus >= 201103L
7978
template<typename Base>
8079
using DeleterType = std::function<void (Base *)>;
8180

8281
template<typename Base>
8382
using UniquePtr = std::unique_ptr<Base, DeleterType<Base>>;
84-
#endif
8583

8684
/**
8785
* @brief Constructor for ClassLoader
@@ -125,7 +123,6 @@ class ClassLoader
125123
);
126124
}
127125

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

153149
/// Generates an instance of loadable classes (i.e. class_loader).
154150
/**

include/class_loader/multi_library_class_loader.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,6 @@ class CLASS_LOADER_PUBLIC MultiLibraryClassLoader
106106
return loader->createInstance<Base>(class_name);
107107
}
108108

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

157155
/**
158156
* @brief Creates an instance of an object of given class name with ancestor class Base

test/CMakeLists.txt

Lines changed: 32 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14,36 +14,47 @@ target_include_directories(${PROJECT_NAME}_TestPlugins2
1414
target_link_libraries(${PROJECT_NAME}_TestPlugins2 ${PROJECT_NAME})
1515
class_loader_hide_library_symbols(${PROJECT_NAME}_TestPlugins2)
1616

17-
ament_add_gtest(${PROJECT_NAME}_utest utest.cpp)
17+
if(WIN32)
18+
set(append_library_dirs "$<TARGET_FILE_DIR:${PROJECT_NAME}>;$<TARGET_FILE_DIR:${PROJECT_NAME}_TestPlugins1>")
19+
else()
20+
set(append_library_dirs "${CMAKE_CURRENT_BINARY_DIR}")
21+
endif()
22+
23+
ament_add_gtest(${PROJECT_NAME}_utest utest.cpp
24+
APPEND_LIBRARY_DIRS "${append_library_dirs}"
25+
)
26+
1827
if(TARGET ${PROJECT_NAME}_utest)
1928
target_include_directories(${PROJECT_NAME}_utest
2029
PUBLIC "../include" ${console_bridge_INCLUDE_DIRS} ${Poco_INCLUDE_DIRS})
21-
target_link_libraries(${PROJECT_NAME}_utest ${PROJECT_NAME} ${Poco_LIBRARIES})
30+
target_link_libraries(${PROJECT_NAME}_utest
31+
${PROJECT_NAME}
32+
${Poco_LIBRARIES}
33+
)
2234
if(NOT WIN32)
2335
target_link_libraries(${PROJECT_NAME}_utest pthread)
2436
endif()
25-
add_dependencies(${PROJECT_NAME}_utest ${PROJECT_NAME}_TestPlugins1 ${PROJECT_NAME}_TestPlugins2)
37+
add_dependencies(${PROJECT_NAME}_utest
38+
${PROJECT_NAME}_TestPlugins1
39+
${PROJECT_NAME}_TestPlugins2)
2640
endif()
2741

28-
include(CheckCXXCompilerFlag)
29-
CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)
30-
if(COMPILER_SUPPORTS_CXX11)
31-
catkin_add_gtest(${PROJECT_NAME}_unique_ptr_test unique_ptr_test.cpp)
32-
if(TARGET ${PROJECT_NAME}_unique_ptr_test)
33-
target_link_libraries(${PROJECT_NAME}_unique_ptr_test
34-
${Boost_LIBRARIES}
35-
${class_loader_LIBRARIES}
36-
)
37-
set_target_properties(${PROJECT_NAME}_unique_ptr_test
38-
PROPERTIES
39-
COMPILE_FLAGS -std=c++11
40-
LINK_FLAGS -std=c++11
41-
)
42-
add_dependencies(${PROJECT_NAME}_unique_ptr_test
43-
${PROJECT_NAME}_TestPlugins1
44-
${PROJECT_NAME}_TestPlugins2
45-
)
42+
ament_add_gtest(${PROJECT_NAME}_unique_ptr_test unique_ptr_test.cpp
43+
APPEND_LIBRARY_DIRS "${append_library_dirs}"
44+
)
45+
if(TARGET ${PROJECT_NAME}_unique_ptr_test)
46+
target_include_directories(${PROJECT_NAME}_unique_ptr_test
47+
PUBLIC "../include" ${Poco_INCLUDE_DIRS})
48+
target_link_libraries(${PROJECT_NAME}_unique_ptr_test
49+
${PROJECT_NAME}
50+
${Poco_LIBRARIES}
51+
)
52+
if(NOT WIN32)
53+
target_link_libraries(${PROJECT_NAME}_unique_ptr_test pthread)
4654
endif()
55+
add_dependencies(${PROJECT_NAME}_unique_ptr_test
56+
${PROJECT_NAME}_TestPlugins1
57+
${PROJECT_NAME}_TestPlugins2)
4758
endif()
4859

4960
add_subdirectory(fviz_case_study)

test/fviz_case_study/CMakeLists.txt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,15 @@ target_link_libraries(${PROJECT_NAME}_Test_FvizDefaultPlugin
2020
${PROJECT_NAME} ${PROJECT_NAME}_Test_Fviz)
2121
class_loader_hide_library_symbols(${PROJECT_NAME}_Test_FvizDefaultPlugin)
2222

23-
ament_add_gtest(${PROJECT_NAME}_fviz_test fviz_test.cpp)
23+
if(WIN32)
24+
set(append_library_dirs "$<TARGET_FILE_DIR:${PROJECT_NAME}>;$<TARGET_FILE_DIR:${PROJECT_NAME}_TestPlugins1>")
25+
else()
26+
set(append_library_dirs "${CMAKE_CURRENT_BINARY_DIR}")
27+
endif()
28+
29+
ament_add_gtest(${PROJECT_NAME}_fviz_test fviz_test.cpp
30+
APPEND_LIBRARY_DIRS "${append_library_dirs}"
31+
)
2432
if(TARGET ${PROJECT_NAME}_fviz_test)
2533
target_include_directories(${PROJECT_NAME}_fviz_test
2634
PUBLIC "../include" ${console_bridge_INCLUDE_DIRS} ${Poco_INCLUDE_DIRS})

test/unique_ptr_test.cpp

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,16 @@
33
#include <class_loader/multi_library_class_loader.h>
44

55
#include <gtest/gtest.h>
6-
#include <boost/thread.hpp>
76

7+
#include <chrono>
88
#include <functional>
99
#include <iostream>
10+
#include <string>
11+
#include <thread>
12+
#include <vector>
1013

11-
const std::string LIBRARY_1 = "libclass_loader_TestPlugins1.so";
12-
const std::string LIBRARY_2 = "libclass_loader_TestPlugins2.so";
14+
const std::string LIBRARY_1 = class_loader::systemLibraryFormat("class_loader_TestPlugins1");
15+
const std::string LIBRARY_2 = class_loader::systemLibraryFormat("class_loader_TestPlugins2");
1316

1417
using class_loader::ClassLoader;
1518

@@ -72,7 +75,7 @@ TEST(ClassLoaderUniquePtrTest, nonExistentPlugin)
7275

7376
obj->saySomething();
7477
}
75-
catch(const class_loader::CreateClassException& e)
78+
catch(const class_loader::CreateClassException&)
7679
{
7780
SUCCEED();
7881
return;
@@ -89,7 +92,7 @@ TEST(ClassLoaderUniquePtrTest, nonExistentPlugin)
8992

9093
void wait(int seconds)
9194
{
92-
boost::this_thread::sleep(boost::posix_time::seconds(seconds));
95+
std::this_thread::sleep_for(std::chrono::seconds(seconds));
9396
}
9497

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

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

125128
}
126-
catch(const class_loader::ClassLoaderException& ex)
129+
catch(const class_loader::ClassLoaderException&)
127130
{
128131
FAIL() << "Unexpected ClassLoaderException.";
129132
}
@@ -170,7 +173,7 @@ TEST(ClassLoaderUniquePtrTest, loadRefCountingLazy)
170173

171174
return;
172175
}
173-
catch(const class_loader::ClassLoaderException& e)
176+
catch(const class_loader::ClassLoaderException&)
174177
{
175178
FAIL() << "Unexpected exception.\n";
176179
}

test/utest.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ TEST(ClassLoaderTest, nonExistentPlugin)
7474
}
7575

7676
obj->saySomething();
77-
} catch (const class_loader::CreateClassException & e) {
77+
} catch (const class_loader::CreateClassException &) {
7878
SUCCEED();
7979
return;
8080
} catch (...) {
@@ -88,7 +88,7 @@ TEST(ClassLoaderTest, nonExistentLibrary)
8888
{
8989
try {
9090
class_loader::ClassLoader loader1("libDoesNotExist.so", false);
91-
} catch (const class_loader::LibraryLoadException & e) {
91+
} catch (const class_loader::LibraryLoadException &) {
9292
SUCCEED();
9393
return;
9494
} catch (...) {
@@ -115,7 +115,7 @@ TEST(ClassLoaderTest, invalidBase)
115115
} else {
116116
FAIL() << "Class not available for correct base class.";
117117
}
118-
} catch (const class_loader::LibraryLoadException & e) {
118+
} catch (const class_loader::LibraryLoadException &) {
119119
FAIL() << "Unexpected exception";
120120
} catch (...) {
121121
FAIL() << "Unexpected and unknown exception caught.\n";
@@ -161,7 +161,7 @@ TEST(ClassLoaderTest, threadSafety)
161161
loader1.unloadLibrary();
162162
ASSERT_FALSE(loader1.isLibraryLoaded());
163163

164-
} catch (const class_loader::ClassLoaderException & ex) {
164+
} catch (const class_loader::ClassLoaderException &) {
165165
FAIL() << "Unexpected ClassLoaderException.";
166166
} catch (...) {
167167
FAIL() << "Unknown exception.";
@@ -194,7 +194,7 @@ TEST(ClassLoaderTest, loadRefCountingNonLazy)
194194
ASSERT_TRUE(loader1.isLibraryLoaded());
195195

196196
return;
197-
} catch (const class_loader::ClassLoaderException & e) {
197+
} catch (const class_loader::ClassLoaderException &) {
198198
FAIL() << "Unexpected exception.\n";
199199
} catch (...) {
200200
FAIL() << "Unknown exception caught.\n";
@@ -235,7 +235,7 @@ TEST(ClassLoaderTest, loadRefCountingLazy)
235235
ASSERT_TRUE(loader1.isLibraryLoaded());
236236

237237
return;
238-
} catch (const class_loader::ClassLoaderException & e) {
238+
} catch (const class_loader::ClassLoaderException &) {
239239
FAIL() << "Unexpected exception.\n";
240240
} catch (...) {
241241
FAIL() << "Unknown exception caught.\n";

0 commit comments

Comments
 (0)