@@ -77,6 +77,10 @@ void cache_change_fragment(
7777 {
7878 ASSERT_EQ (result, 0 );
7979 }
80+
81+ RTPSDomain::removeRTPSWriter (writer);
82+ RTPSDomain::removeRTPSParticipant (participant);
83+ delete history;
8084}
8185
8286/* *
@@ -92,6 +96,125 @@ TEST(WriterHistoryTests, final_high_mark_for_frag_overflow)
9296 }
9397}
9498
99+ <<<<<<< HEAD
100+ =======
101+ TEST (WriterHistoryTests, add_change_with_undefined_instance_handle_and_no_payload)
102+ {
103+ uint32_t domain_id = 0 ;
104+
105+ RTPSParticipantAttributes p_attr;
106+ RTPSParticipant* participant = RTPSDomain::createParticipant (
107+ domain_id, true , p_attr);
108+
109+ ASSERT_NE (participant, nullptr );
110+
111+ HistoryAttributes h_attr;
112+ WriterHistory* history = new WriterHistory (h_attr);
113+
114+ WriterAttributes w_attr;
115+ // The topic must be keyed to use instance handles
116+ w_attr.endpoint .topicKind = WITH_KEY ;
117+ RTPSWriter* writer = RTPSDomain::createRTPSWriter (participant, w_attr, history);
118+
119+ ASSERT_NE (writer, nullptr );
120+
121+ // Any of these changes have a well defined instance handle
122+ CacheChange_t* change = history->create_change (ALIVE );
123+ // Valid because ALIVE changes don't enforce defined instance handles
124+ ASSERT_TRUE (history->add_change (change));
125+ // Rest are invalid because instance handle is enforced to be defined
126+ change = history->create_change (NOT_ALIVE_DISPOSED );
127+ ASSERT_FALSE (history->add_change (change));
128+ change = history->create_change (NOT_ALIVE_UNREGISTERED );
129+ ASSERT_FALSE (history->add_change (change));
130+ change = history->create_change (NOT_ALIVE_DISPOSED_UNREGISTERED );
131+ ASSERT_FALSE (history->add_change (change));
132+
133+ RTPSDomain::removeRTPSWriter (writer);
134+ RTPSDomain::removeRTPSParticipant (participant);
135+ delete history;
136+ }
137+
138+ TEST (WriterHistoryTests, add_change_with_defined_instance_handle_and_no_payload)
139+ {
140+ uint32_t domain_id = 0 ;
141+
142+ RTPSParticipantAttributes p_attr;
143+ RTPSParticipant* participant = RTPSDomain::createParticipant (
144+ domain_id, true , p_attr);
145+
146+ ASSERT_NE (participant, nullptr );
147+
148+ HistoryAttributes h_attr;
149+ WriterHistory* history = new WriterHistory (h_attr);
150+
151+ WriterAttributes w_attr;
152+ // The topic must be keyed to use instance handles
153+ w_attr.endpoint .topicKind = WITH_KEY ;
154+ RTPSWriter* writer = RTPSDomain::createRTPSWriter (participant, w_attr, history);
155+
156+ ASSERT_NE (writer, nullptr );
157+
158+ // All these changes have a well defined instance handle and they must be added successfully
159+ CacheChange_t* change = history->create_change (ALIVE );
160+ // Setting any value makes the handle defined because of its = operator
161+ change->instanceHandle .value [0 ] = 1 ;
162+ ASSERT_TRUE (history->add_change (change));
163+ change = history->create_change (NOT_ALIVE_DISPOSED );
164+ change->instanceHandle .value [0 ] = 1 ;
165+ ASSERT_TRUE (history->add_change (change));
166+ change = history->create_change (NOT_ALIVE_UNREGISTERED );
167+ change->instanceHandle .value [0 ] = 1 ;
168+ ASSERT_TRUE (history->add_change (change));
169+ change = history->create_change (NOT_ALIVE_DISPOSED_UNREGISTERED );
170+ change->instanceHandle .value [0 ] = 1 ;
171+ ASSERT_TRUE (history->add_change (change));
172+
173+ RTPSDomain::removeRTPSWriter (writer);
174+ RTPSDomain::removeRTPSParticipant (participant);
175+ delete history;
176+ }
177+
178+ TEST (WriterHistoryTests, add_change_with_payload_but_undefined_handle)
179+ {
180+ uint32_t domain_id = 0 ;
181+
182+ RTPSParticipantAttributes p_attr;
183+ RTPSParticipant* participant = RTPSDomain::createParticipant (
184+ domain_id, true , p_attr);
185+
186+ ASSERT_NE (participant, nullptr );
187+
188+ HistoryAttributes h_attr;
189+ WriterHistory* history = new WriterHistory (h_attr);
190+
191+ WriterAttributes w_attr;
192+ // The topic must be keyed to use instance handles
193+ w_attr.endpoint .topicKind = WITH_KEY ;
194+ RTPSWriter* writer = RTPSDomain::createRTPSWriter (participant, w_attr, history);
195+
196+ ASSERT_NE (writer, nullptr );
197+
198+ CacheChange_t* change = history->create_change (ALIVE );
199+ // This len simulates a payload
200+ change->serializedPayload .length = 10 ;
201+ ASSERT_TRUE (history->add_change (change));
202+ change = history->create_change (NOT_ALIVE_DISPOSED );
203+ change->serializedPayload .length = 10 ;
204+ ASSERT_TRUE (history->add_change (change));
205+ change = history->create_change (NOT_ALIVE_UNREGISTERED );
206+ change->serializedPayload .length = 10 ;
207+ ASSERT_TRUE (history->add_change (change));
208+ change = history->create_change (NOT_ALIVE_DISPOSED_UNREGISTERED );
209+ change->serializedPayload .length = 10 ;
210+ ASSERT_TRUE (history->add_change (change));
211+
212+ RTPSDomain::removeRTPSWriter (writer);
213+ RTPSDomain::removeRTPSParticipant (participant);
214+ delete history;
215+ }
216+
217+ >>>>>>> e8294c00d (Improve windows tests (#6373 ))
95218} // namespace rtps
96219} // namespace fastdds
97220} // namespace eprosima
0 commit comments