Skip to content

Commit 0422b3b

Browse files
Test refactor for windows compilation
Signed-off-by: Eugenio Collado <[email protected]>
1 parent 71a0fb8 commit 0422b3b

File tree

4 files changed

+45
-129
lines changed

4 files changed

+45
-129
lines changed

test/unittest/rtps/history/CMakeLists.txt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -177,11 +177,14 @@ target_compile_definitions(WriterHistoryTests PRIVATE
177177
$<$<BOOL:${INTERNAL_DEBUG}>:__INTERNALDEBUG> # Internal debug activated.
178178
)
179179
target_include_directories(WriterHistoryTests PRIVATE
180-
${Asio_INCLUDE_DIR})
180+
${Asio_INCLUDE_DIR}
181+
${THIRDPARTY_BOOST_INCLUDE_DIR}
182+
${PROJECT_SOURCE_DIR}/src/cpp
183+
${PROJECT_SOURCE_DIR}/include ${PROJECT_BINARY_DIR}/include)
181184
target_link_libraries(WriterHistoryTests
182185
fastcdr
183-
fastdds
186+
fastdds
184187
foonathan_memory
185-
GTest::gmock
188+
GTest::gtest
186189
${CMAKE_DL_LIBS})
187190
gtest_discover_tests(WriterHistoryTests)

test/unittest/rtps/history/WriterHistoryTests.cpp

Lines changed: 39 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
#include <gmock/gmock.h>
1615
#include <gtest/gtest.h>
1716

1817
#include <fastdds/rtps/RTPSDomain.hpp>
@@ -21,8 +20,6 @@
2120
#include <fastdds/rtps/history/IPayloadPool.hpp>
2221
#include <fastdds/rtps/history/WriterHistory.hpp>
2322

24-
#include <rtps/writer/BaseWriter.hpp>
25-
2623

2724
namespace eprosima {
2825
namespace fastdds {
@@ -33,11 +30,12 @@ using namespace testing;
3330
#define MAX_MESSAGE_SIZE 300
3431

3532
void cache_change_fragment(
36-
uint32_t inline_qos_length)
33+
uint32_t max_message_size,
34+
uint32_t inline_qos_length,
35+
bool expected_fragmentation)
3736
{
3837
uint32_t domain_id = 0;
3938
uint32_t initial_reserved_caches = 10;
40-
uint32_t max_message_size = MAX_MESSAGE_SIZE;
4139
std::string max_message_size_str = std::to_string(max_message_size);
4240

4341
RTPSParticipantAttributes p_attr;
@@ -58,31 +56,53 @@ void cache_change_fragment(
5856

5957
ASSERT_NE(writer, nullptr);
6058

61-
BaseWriter* bwriter = BaseWriter::downcast(writer);
62-
auto max_allowed_payload_size = bwriter->get_max_allowed_payload_size();
63-
64-
CacheChange_t change;
65-
change.writerGUID = bwriter->getGuid();
66-
change.serializedPayload.length = 3 * max_allowed_payload_size; // Force to setFragmentSize
67-
change.inline_qos.length = inline_qos_length;
68-
69-
history->add_change(&change);
59+
CacheChange_t* change = history->create_change(ALIVE);
60+
if(expected_fragmentation)
61+
{
62+
change->serializedPayload.length = 3 * max_message_size;
63+
}
64+
else
65+
{
66+
change->serializedPayload.length = max_message_size / 3;
67+
}
68+
change->inline_qos.length = inline_qos_length;
69+
history->add_change(change);
7070

71-
auto result = change.getFragmentSize();
71+
auto result = change->getFragmentSize();
7272
std::cout << "Fragment size: " << result << std::endl;
73-
ASSERT_NE(result, 0); // Fragment size should always be greater than 0
73+
if(expected_fragmentation)
74+
{
75+
ASSERT_NE(result, 0);
76+
}
77+
else
78+
{
79+
ASSERT_EQ(result, 0);
80+
}
81+
}
82+
83+
/**
84+
* This test checks the get_max_allowed_payload_size() method of the BaseWriter class.
85+
* When setting the RTPS Participant Attribute property fastdds.max_message_size to a value lower than the
86+
* message overhead, if the method does not overflow the fragment size will be set.
87+
* If the max_message_size is big enough for the overhead, inline_qos and serializedPayload,
88+
* then no fragmentation will occur.
89+
*/
90+
TEST(WriterHistoryTests, get_max_allowed_payload_size_overflow)
91+
{
92+
cache_change_fragment(100, 0, true);
93+
cache_change_fragment(MAX_MESSAGE_SIZE, 0, false);
7494
}
7595

7696
/**
7797
* This test checks the fragment size calculation for a cache change depending on the inline qos length.
7898
* The change.serializedPayload.length is set to 3 times the max_allowed_payload_size, so the fragment size should always be set.
7999
* In case of an overflow in the attribute high_mark_for_frag_ the fragment size will not be set, which is an error.
80100
*/
81-
TEST(WriterHistoryTests, calculate_max_payload_size_overflow)
101+
TEST(WriterHistoryTests, final_high_mark_for_frag_overflow)
82102
{
83103
for (uint32_t inline_qos_length = 0; inline_qos_length < MAX_MESSAGE_SIZE; inline_qos_length += 40)
84104
{
85-
cache_change_fragment(inline_qos_length);
105+
cache_change_fragment(MAX_MESSAGE_SIZE, inline_qos_length, true);
86106
}
87107
}
88108

@@ -94,6 +114,6 @@ int main(
94114
int argc,
95115
char** argv)
96116
{
97-
testing::InitGoogleMock(&argc, argv);
117+
testing::InitGoogleTest(&argc, argv);
98118
return RUN_ALL_TESTS();
99119
}

test/unittest/rtps/writer/BaseWriterTests.cpp

Lines changed: 0 additions & 91 deletions
This file was deleted.

test/unittest/rtps/writer/CMakeLists.txt

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -108,22 +108,6 @@ target_link_libraries(LivelinessManagerTests PRIVATE
108108
)
109109
gtest_discover_tests(LivelinessManagerTests)
110110

111-
set(BASEWRITERTESTS_SOURCE BaseWriterTests.cpp)
112-
113-
add_executable(BaseWriterTests ${BASEWRITERTESTS_SOURCE})
114-
target_compile_definitions(BaseWriterTests PRIVATE
115-
BOOST_ASIO_STANDALONE
116-
ASIO_STANDALONE
117-
$<$<AND:$<NOT:$<BOOL:${WIN32}>>,$<STREQUAL:"${CMAKE_BUILD_TYPE}","Debug">>:__DEBUG>
118-
$<$<BOOL:${INTERNAL_DEBUG}>:__INTERNALDEBUG> # Internal debug activated.
119-
)
120-
target_include_directories(BaseWriterTests PRIVATE
121-
${Asio_INCLUDE_DIR})
122-
target_link_libraries(BaseWriterTests fastcdr fastdds foonathan_memory
123-
GTest::gmock
124-
${CMAKE_DL_LIBS})
125-
gtest_discover_tests(BaseWriterTests)
126-
127111
if(NOT QNX)
128112
set(RTPSWRITERTESTS_SOURCE RTPSWriterTests.cpp)
129113

0 commit comments

Comments
 (0)