File tree Expand file tree Collapse file tree 2 files changed +28
-1
lines changed
Expand file tree Collapse file tree 2 files changed +28
-1
lines changed Original file line number Diff line number Diff line change @@ -691,7 +691,9 @@ void mqtt_sn_print_publish_packet(publish_packet_t* packet)
691691 switch (topic_type ) {
692692 case MQTT_SN_TOPIC_TYPE_NORMAL : {
693693 const char * topic_name = mqtt_sn_lookup_topic (topic_id );
694- printf ("%s: %s\n" , topic_name , packet -> data );
694+ if (topic_name ) {
695+ printf ("%s: %s\n" , topic_name , packet -> data );
696+ }
695697 break ;
696698 };
697699 case MQTT_SN_TOPIC_TYPE_PREDEFINED : {
Original file line number Diff line number Diff line change @@ -379,6 +379,31 @@ def fs.handle_connect(packet)
379379 assert_equal false , @packet . clean_session
380380 end
381381
382+ def test_recieve_non_registered_topic_id
383+ @fs = fake_server do |fs |
384+ def fs . handle_connect ( packet )
385+ [
386+ MQTT ::SN ::Packet ::Connack . new ( :return_code => 0x00 ) ,
387+ MQTT ::SN ::Packet ::Publish . new ( :topic_id => 5 , :data => 'not registered' )
388+ ]
389+ end
390+
391+ @cmd_result = run_cmd (
392+ 'mqtt-sn-sub' ,
393+ [ '-c' , '-v' ,
394+ '-t' , 'test' ,
395+ '-p' , fs . port ,
396+ '-h' , fs . address ]
397+ ) do |cmd |
398+ @packet = fs . wait_for_packet ( MQTT ::SN ::Packet ::Connect )
399+ wait_for_output_then_kill ( cmd )
400+ end
401+ end
402+
403+ assert_match /Failed to lookup topic id: 0x0005/ , @cmd_result [ 0 ]
404+ assert_match /test: Hello World/ , @cmd_result [ 1 ]
405+ end
406+
382407 def test_packet_too_long
383408 fake_server do |fs |
384409 def fs . handle_subscribe ( packet )
You can’t perform that action at this time.
0 commit comments