@@ -149,6 +149,30 @@ struct MockTransport final : PublisherTransport {
149149 std::function<void (const MockTransport&, std::uint64_t )> on_read;
150150};
151151
152+ std::vector<std::size_t > object_write_indices (const MockTransport& transport) {
153+ std::vector<std::size_t > indices;
154+ for (std::size_t index = 0 ; index < transport.writes .size (); ++index) {
155+ if (transport.writes [index].stream_id != 0 ) {
156+ indices.push_back (index);
157+ }
158+ }
159+ return indices;
160+ }
161+
162+ std::size_t control_message_count (const MockTransport& transport, std::uint8_t type) {
163+ std::size_t count = 0 ;
164+ for (const auto & write : transport.writes ) {
165+ if (write.stream_id == 0 ) {
166+ std::size_t cursor = 0 ;
167+ std::uint64_t decoded_type = 0 ;
168+ if (decode_varint (write.bytes , cursor, decoded_type) && decoded_type == type) {
169+ ++count;
170+ }
171+ }
172+ }
173+ return count;
174+ }
175+
152176void append_be16 (std::vector<std::uint8_t >& out, std::uint16_t value) {
153177 out.push_back (static_cast <std::uint8_t >((value >> 8U ) & 0xffU ));
154178 out.push_back (static_cast <std::uint8_t >(value & 0xffU ));
@@ -690,16 +714,18 @@ int main() {
690714 " expected namespace write to use the configured track namespace" );
691715 ok &= expect (message_type (transport.writes [2 ].bytes ) == 0x04 , " expected first SUBSCRIBE_OK" );
692716 ok &= expect (message_type (transport.writes [3 ].bytes ) == 0x04 , " expected second SUBSCRIBE_OK" );
693- ok &= expect (transport.writes [4 ].stream_id == 2 , " expected first object stream to be unidirectional stream 2" );
694- ok &= expect (!transport.writes [4 ].bytes .empty () && transport.writes [4 ].bytes .front () == 0x18 ,
717+ const auto object_indices = object_write_indices (transport);
718+ ok &= expect (object_indices.size () == 2 , " expected two object stream writes" );
719+ ok &= expect (!transport.writes [object_indices[0 ]].bytes .empty () &&
720+ transport.writes [object_indices[0 ]].bytes .front () == 0x18 ,
695721 " expected first draft-14 object stream to use draft-14 subgroup header with end-of-group" );
696722 std::uint64_t stream_type = 0 ;
697723 std::uint64_t track_alias = 0 ;
698724 std::uint64_t group_id = 0 ;
699725 std::uint64_t object_id_delta = 0 ;
700726 std::uint64_t payload_length = 0 ;
701727 std::vector<std::uint8_t > payload;
702- ok &= expect (decode_object_stream_fields (transport.writes [4 ].bytes ,
728+ ok &= expect (decode_object_stream_fields (transport.writes [object_indices[ 0 ] ].bytes ,
703729 stream_type,
704730 track_alias,
705731 group_id,
@@ -713,12 +739,12 @@ int main() {
713739 ok &= expect (payload_length == 4 , " expected catalog payload length to be encoded after object id delta" );
714740 ok &= expect (payload == std::vector<std::uint8_t >({' I' , ' N' , ' I' , ' T' }),
715741 " expected catalog payload bytes after subgroup object fields" );
716- ok &= expect (transport.writes [4 ].fin , " expected first object stream write to set FIN" );
717- ok &= expect (transport.writes [5 ]. stream_id == 6 , " expected second object stream to be unidirectional stream 6 " );
718- ok &= expect (!transport. writes [ 5 ]. bytes . empty () && transport.writes [5 ].bytes .front () == 0x18 ,
742+ ok &= expect (transport.writes [object_indices[ 0 ] ].fin , " expected first object stream write to set FIN" );
743+ ok &= expect (! transport.writes [object_indices[ 1 ]]. bytes . empty () &&
744+ transport.writes [object_indices[ 1 ] ].bytes .front () == 0x18 ,
719745 " expected second draft-14 object stream to use draft-14 subgroup header with end-of-group" );
720746 payload.clear ();
721- ok &= expect (decode_object_stream_fields (transport.writes [5 ].bytes ,
747+ ok &= expect (decode_object_stream_fields (transport.writes [object_indices[ 1 ] ].bytes ,
722748 stream_type,
723749 track_alias,
724750 group_id,
@@ -731,9 +757,8 @@ int main() {
731757 ok &= expect (payload_length == 3 , " expected media payload length to be encoded after object id delta" );
732758 ok &= expect (payload == std::vector<std::uint8_t >({' M' , ' S' , ' G' }),
733759 " expected media payload bytes after subgroup object fields" );
734- ok &= expect (transport.writes [5 ].fin , " expected second object stream write to set FIN" );
735- ok &= expect (message_type (transport.writes [6 ].bytes ) == 0x0b , " expected first PUBLISH_DONE" );
736- ok &= expect (message_type (transport.writes [7 ].bytes ) == 0x0b , " expected second PUBLISH_DONE" );
760+ ok &= expect (transport.writes [object_indices[1 ]].fin , " expected second object stream write to set FIN" );
761+ ok &= expect (control_message_count (transport, 0x0b ) == 2 , " expected two PUBLISH_DONE messages" );
737762 ok &= expect (message_type (transport.writes [8 ].bytes ) == 0x09 , " expected PUBLISH_NAMESPACE_DONE" );
738763 ok &= expect (transport.writes [8 ].bytes == std::vector<std::uint8_t >({0x09 , 0x00 , 0x09 , 0x01 , 0x07 , 0x69 , 0x6e ,
739764 0x74 , 0x65 , 0x72 , 0x6f , 0x70 }),
@@ -1041,14 +1066,10 @@ int main() {
10411066 " expected catalog PUBLISH before alias-based update activation" );
10421067 ok &= expect (message_type (transport.writes [3 ].bytes ) == 0x04 ,
10431068 " expected media SUBSCRIBE_OK while catalog activation is pending" );
1044- ok &= expect (transport.writes [4 ].stream_id == 2 ,
1045- " expected catalog object stream after alias-based SUBSCRIBE_UPDATE activation" );
1046- ok &= expect (transport.writes [5 ].stream_id == 6 ,
1047- " expected media object stream after alias-based catalog activation" );
1048- ok &= expect (message_type (transport.writes [6 ].bytes ) == 0x0b ,
1049- " expected catalog PUBLISH_DONE after alias-based SUBSCRIBE_UPDATE activation" );
1050- ok &= expect (message_type (transport.writes [7 ].bytes ) == 0x0b ,
1051- " expected media PUBLISH_DONE after alias-based catalog activation" );
1069+ ok &= expect (object_write_indices (transport).size () == 2 ,
1070+ " expected catalog and media object stream writes after alias-based activation" );
1071+ ok &= expect (control_message_count (transport, 0x0b ) == 2 ,
1072+ " expected catalog and media PUBLISH_DONE after alias-based activation" );
10521073 ok &= expect (message_type (transport.writes [8 ].bytes ) == 0x09 ,
10531074 " expected namespace done after alias-based catalog activation" );
10541075 }
@@ -1159,14 +1180,10 @@ int main() {
11591180 " expected downgraded catalog SUBSCRIBE_OK" );
11601181 ok &= expect (message_type (transport.writes [5 ].bytes ) == 0x04 ,
11611182 " expected downgraded media SUBSCRIBE_OK" );
1162- ok &= expect (transport.writes [6 ].stream_id == 2 ,
1163- " expected downgraded catalog object stream on stream 2" );
1164- ok &= expect (transport.writes [7 ].stream_id == 6 ,
1165- " expected downgraded media object stream on stream 6" );
1166- ok &= expect (message_type (transport.writes [8 ].bytes ) == 0x0b ,
1167- " expected downgraded catalog PUBLISH_DONE" );
1168- ok &= expect (message_type (transport.writes [9 ].bytes ) == 0x0b ,
1169- " expected downgraded media PUBLISH_DONE" );
1183+ ok &= expect (object_write_indices (transport).size () == 2 ,
1184+ " expected downgraded catalog and media object stream writes" );
1185+ ok &= expect (control_message_count (transport, 0x0b ) == 2 ,
1186+ " expected downgraded catalog and media PUBLISH_DONE" );
11701187 ok &= expect (message_type (transport.writes [10 ].bytes ) == 0x09 ,
11711188 " expected downgraded auto-forward PUBLISH_NAMESPACE_DONE" );
11721189 }
@@ -1262,10 +1279,9 @@ int main() {
12621279 " expected draft-16 namespace write to use the configured track namespace" );
12631280 ok &= expect (message_type (draft16_transport.writes [2 ].bytes ) == 0x04 , " expected first draft-16 SUBSCRIBE_OK" );
12641281 ok &= expect (message_type (draft16_transport.writes [3 ].bytes ) == 0x04 , " expected second draft-16 SUBSCRIBE_OK" );
1265- ok &= expect (draft16_transport.writes [4 ].stream_id == 2 , " expected first draft-16 object stream" );
1266- ok &= expect (draft16_transport.writes [5 ].stream_id == 6 , " expected second draft-16 object stream" );
1267- ok &= expect (message_type (draft16_transport.writes [6 ].bytes ) == 0x0b , " expected first draft-16 PUBLISH_DONE" );
1268- ok &= expect (message_type (draft16_transport.writes [7 ].bytes ) == 0x0b , " expected second draft-16 PUBLISH_DONE" );
1282+ ok &= expect (object_write_indices (draft16_transport).size () == 2 , " expected two draft-16 object stream writes" );
1283+ ok &= expect (control_message_count (draft16_transport, 0x0b ) == 2 ,
1284+ " expected two draft-16 PUBLISH_DONE messages" );
12691285 ok &= expect (message_type (draft16_transport.writes [8 ].bytes ) == 0x09 ,
12701286 " expected draft-16 PUBLISH_NAMESPACE_DONE" );
12711287 ok &= expect (draft16_transport.writes [8 ].bytes == std::vector<std::uint8_t >({0x09 , 0x00 , 0x01 , 0x00 }),
0 commit comments