12
12
// See the License for the specific language governing permissions and
13
13
// limitations under the License.
14
14
15
- #include < gmock/gmock.h>
16
15
#include < gtest/gtest.h>
17
16
18
17
#include < fastdds/rtps/RTPSDomain.hpp>
21
20
#include < fastdds/rtps/history/IPayloadPool.hpp>
22
21
#include < fastdds/rtps/history/WriterHistory.hpp>
23
22
24
- #include < rtps/writer/BaseWriter.hpp>
25
-
26
23
27
24
namespace eprosima {
28
25
namespace fastdds {
@@ -33,11 +30,12 @@ using namespace testing;
33
30
#define MAX_MESSAGE_SIZE 300
34
31
35
32
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)
37
36
{
38
37
uint32_t domain_id = 0 ;
39
38
uint32_t initial_reserved_caches = 10 ;
40
- uint32_t max_message_size = MAX_MESSAGE_SIZE;
41
39
std::string max_message_size_str = std::to_string (max_message_size);
42
40
43
41
RTPSParticipantAttributes p_attr;
@@ -58,31 +56,53 @@ void cache_change_fragment(
58
56
59
57
ASSERT_NE (writer, nullptr );
60
58
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);
70
70
71
- auto result = change. getFragmentSize ();
71
+ auto result = change-> getFragmentSize ();
72
72
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 );
74
94
}
75
95
76
96
/* *
77
97
* This test checks the fragment size calculation for a cache change depending on the inline qos length.
78
98
* The change.serializedPayload.length is set to 3 times the max_allowed_payload_size, so the fragment size should always be set.
79
99
* In case of an overflow in the attribute high_mark_for_frag_ the fragment size will not be set, which is an error.
80
100
*/
81
- TEST (WriterHistoryTests, calculate_max_payload_size_overflow )
101
+ TEST (WriterHistoryTests, final_high_mark_for_frag_overflow )
82
102
{
83
103
for (uint32_t inline_qos_length = 0 ; inline_qos_length < MAX_MESSAGE_SIZE; inline_qos_length += 40 )
84
104
{
85
- cache_change_fragment (inline_qos_length);
105
+ cache_change_fragment (MAX_MESSAGE_SIZE, inline_qos_length, true );
86
106
}
87
107
}
88
108
@@ -94,6 +114,6 @@ int main(
94
114
int argc,
95
115
char ** argv)
96
116
{
97
- testing::InitGoogleMock (&argc, argv);
117
+ testing::InitGoogleTest (&argc, argv);
98
118
return RUN_ALL_TESTS ();
99
119
}
0 commit comments