Add tests for Content Type property sending.
parent
7020fad86c
commit
085fdf3593
@ -1,47 +0,0 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
# Test whether a client subscribed to a topic receives its own message sent to that topic.
|
||||
# Does the Payload Format Indicator property get sent through?
|
||||
# MQTT v5
|
||||
|
||||
from mosq_test_helper import *
|
||||
|
||||
rc = 1
|
||||
mid = 53
|
||||
keepalive = 60
|
||||
connect_packet = mosq_test.gen_connect("subpub-qos0-test", keepalive=keepalive, proto_ver=5)
|
||||
connack_packet = mosq_test.gen_connack(rc=0, proto_ver=5)
|
||||
|
||||
subscribe_packet = mosq_test.gen_subscribe(mid, "subpub/qos0", 0, proto_ver=5)
|
||||
suback_packet = mosq_test.gen_suback(mid, 0, proto_ver=5)
|
||||
|
||||
props = mqtt5_props.gen_byte_prop(mqtt5_props.PROP_PAYLOAD_FORMAT_INDICATOR, 0xed)
|
||||
props = props+mqtt5_props.gen_uint16_prop(mqtt5_props.PROP_TOPIC_ALIAS, 1)
|
||||
props = mqtt5_props.prop_finalise(props)
|
||||
publish_packet_out = mosq_test.gen_publish("subpub/qos0", qos=0, payload="message", proto_ver=5, properties=props)
|
||||
|
||||
props = mqtt5_props.gen_byte_prop(mqtt5_props.PROP_PAYLOAD_FORMAT_INDICATOR, 0xed)
|
||||
props = mqtt5_props.prop_finalise(props)
|
||||
publish_packet_expected = mosq_test.gen_publish("subpub/qos0", qos=0, payload="message", proto_ver=5, properties=props)
|
||||
|
||||
port = mosq_test.get_port()
|
||||
broker = mosq_test.start_broker(filename=os.path.basename(__file__), port=port)
|
||||
|
||||
try:
|
||||
sock = mosq_test.do_client_connect(connect_packet, connack_packet, timeout=20, port=port)
|
||||
|
||||
mosq_test.do_send_receive(sock, subscribe_packet, suback_packet, "suback")
|
||||
mosq_test.do_send_receive(sock, publish_packet_out, publish_packet_expected, "publish")
|
||||
|
||||
rc = 0
|
||||
|
||||
sock.close()
|
||||
finally:
|
||||
broker.terminate()
|
||||
broker.wait()
|
||||
(stdo, stde) = broker.communicate()
|
||||
if rc:
|
||||
print(stde)
|
||||
|
||||
exit(rc)
|
||||
|
@ -0,0 +1,17 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
# Test whether a client subscribed to a topic receives its own message sent to that topic.
|
||||
# Does the Content Type property get sent through?
|
||||
# MQTT v5
|
||||
|
||||
import prop_subpub_helper as helper
|
||||
from mosq_test_helper import *
|
||||
|
||||
props_out = mqtt5_props.gen_string_prop(mqtt5_props.PROP_CONTENT_TYPE, "text")
|
||||
props_out = props_out+mqtt5_props.gen_uint16_prop(mqtt5_props.PROP_TOPIC_ALIAS, 1)
|
||||
props_out = mqtt5_props.prop_finalise(props_out)
|
||||
|
||||
props_in = mqtt5_props.gen_string_prop(mqtt5_props.PROP_CONTENT_TYPE, "text")
|
||||
props_in = mqtt5_props.prop_finalise(props_in)
|
||||
|
||||
helper.prop_subpub_helper(props_out, props_in)
|
@ -0,0 +1,17 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
# Test whether a client subscribed to a topic receives its own message sent to that topic.
|
||||
# Does the Payload Format Indicator property get sent through?
|
||||
# MQTT v5
|
||||
|
||||
import prop_subpub_helper as helper
|
||||
from mosq_test_helper import *
|
||||
|
||||
props_out = mqtt5_props.gen_byte_prop(mqtt5_props.PROP_PAYLOAD_FORMAT_INDICATOR, 0xed)
|
||||
props_out = props_out+mqtt5_props.gen_uint16_prop(mqtt5_props.PROP_TOPIC_ALIAS, 1)
|
||||
props_out = mqtt5_props.prop_finalise(props_out)
|
||||
|
||||
props_in = mqtt5_props.gen_byte_prop(mqtt5_props.PROP_PAYLOAD_FORMAT_INDICATOR, 0xed)
|
||||
props_in = mqtt5_props.prop_finalise(props_in)
|
||||
|
||||
helper.prop_subpub_helper(props_out, props_in)
|
@ -0,0 +1,43 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
# Test whether a client subscribed to a topic receives its own message sent to that topic.
|
||||
# Does a given property get sent through?
|
||||
# MQTT v5
|
||||
|
||||
from mosq_test_helper import *
|
||||
|
||||
def prop_subpub_helper(props_out, props_in):
|
||||
rc = 1
|
||||
mid = 53
|
||||
keepalive = 60
|
||||
connect_packet = mosq_test.gen_connect("subpub-qos0-test", keepalive=keepalive, proto_ver=5)
|
||||
connack_packet = mosq_test.gen_connack(rc=0, proto_ver=5)
|
||||
|
||||
subscribe_packet = mosq_test.gen_subscribe(mid, "subpub/qos0", 0, proto_ver=5)
|
||||
suback_packet = mosq_test.gen_suback(mid, 0, proto_ver=5)
|
||||
|
||||
publish_packet_out = mosq_test.gen_publish("subpub/qos0", qos=0, payload="message", proto_ver=5, properties=props_out)
|
||||
|
||||
publish_packet_expected = mosq_test.gen_publish("subpub/qos0", qos=0, payload="message", proto_ver=5, properties=props_in)
|
||||
|
||||
port = mosq_test.get_port()
|
||||
broker = mosq_test.start_broker(filename=os.path.basename(__file__), port=port)
|
||||
|
||||
try:
|
||||
sock = mosq_test.do_client_connect(connect_packet, connack_packet, timeout=20, port=port)
|
||||
|
||||
mosq_test.do_send_receive(sock, subscribe_packet, suback_packet, "suback")
|
||||
mosq_test.do_send_receive(sock, publish_packet_out, publish_packet_expected, "publish")
|
||||
|
||||
rc = 0
|
||||
|
||||
sock.close()
|
||||
finally:
|
||||
broker.terminate()
|
||||
broker.wait()
|
||||
(stdo, stde) = broker.communicate()
|
||||
if rc:
|
||||
print(stde)
|
||||
|
||||
exit(rc)
|
||||
|
@ -0,0 +1,54 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
from mosq_test_helper import *
|
||||
|
||||
port = mosq_test.get_lib_port()
|
||||
|
||||
rc = 1
|
||||
keepalive = 60
|
||||
connect_packet = mosq_test.gen_connect("prop-test", keepalive=keepalive, proto_ver=5)
|
||||
connack_packet = mosq_test.gen_connack(rc=0, proto_ver=5)
|
||||
|
||||
props = mqtt5_props.gen_string_prop(mqtt5_props.PROP_CONTENT_TYPE, "application/json")
|
||||
props = mqtt5_props.prop_finalise(props)
|
||||
publish_packet = mosq_test.gen_publish("prop/qos0", qos=0, payload="message", proto_ver=5, properties=props)
|
||||
|
||||
disconnect_packet = mosq_test.gen_disconnect(proto_ver=5)
|
||||
|
||||
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
|
||||
sock.settimeout(10)
|
||||
sock.bind(('', port))
|
||||
sock.listen(5)
|
||||
|
||||
client_args = sys.argv[1:]
|
||||
env = dict(os.environ)
|
||||
env['LD_LIBRARY_PATH'] = '../../lib:../../lib/cpp'
|
||||
try:
|
||||
pp = env['PYTHONPATH']
|
||||
except KeyError:
|
||||
pp = ''
|
||||
env['PYTHONPATH'] = '../../lib/python:'+pp
|
||||
client = mosq_test.start_client(filename=sys.argv[1].replace('/', '-'), cmd=client_args, env=env, port=port)
|
||||
|
||||
try:
|
||||
(conn, address) = sock.accept()
|
||||
conn.settimeout(10)
|
||||
|
||||
if mosq_test.expect_packet(conn, "connect", connect_packet):
|
||||
conn.send(connack_packet)
|
||||
|
||||
if mosq_test.expect_packet(conn, "publish", publish_packet):
|
||||
if mosq_test.expect_packet(conn, "disconnect", disconnect_packet):
|
||||
rc = 0
|
||||
|
||||
conn.close()
|
||||
finally:
|
||||
client.terminate()
|
||||
client.wait()
|
||||
if rc:
|
||||
(stdo, stde) = client.communicate()
|
||||
print(stde)
|
||||
sock.close()
|
||||
|
||||
exit(rc)
|
@ -0,0 +1,58 @@
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <mosquitto.h>
|
||||
#include <mqtt_protocol.h>
|
||||
|
||||
static int run = -1;
|
||||
static int sent_mid = -1;
|
||||
|
||||
void on_connect(struct mosquitto *mosq, void *obj, int rc)
|
||||
{
|
||||
int rc2;
|
||||
mosquitto_property *proplist = NULL;
|
||||
|
||||
if(rc){
|
||||
exit(1);
|
||||
}else{
|
||||
rc2 = mosquitto_property_add_string(&proplist, MQTT_PROP_CONTENT_TYPE, "application/json");
|
||||
mosquitto_publish_v5(mosq, &sent_mid, "prop/qos0", strlen("message"), "message", 0, false, proplist);
|
||||
}
|
||||
}
|
||||
|
||||
void on_publish(struct mosquitto *mosq, void *obj, int mid)
|
||||
{
|
||||
if(mid == sent_mid){
|
||||
mosquitto_disconnect(mosq);
|
||||
run = 0;
|
||||
}else{
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int rc;
|
||||
int tmp;
|
||||
struct mosquitto *mosq;
|
||||
|
||||
int port = atoi(argv[1]);
|
||||
|
||||
mosquitto_lib_init();
|
||||
|
||||
mosq = mosquitto_new("prop-test", true, NULL);
|
||||
mosquitto_connect_callback_set(mosq, on_connect);
|
||||
mosquitto_publish_callback_set(mosq, on_publish);
|
||||
tmp = MQTT_PROTOCOL_V5;
|
||||
mosquitto_opts_set(mosq, MOSQ_OPT_PROTOCOL_VERSION, &tmp);
|
||||
|
||||
rc = mosquitto_connect(mosq, "localhost", port, 60);
|
||||
|
||||
while(run == -1){
|
||||
rc = mosquitto_loop(mosq, -1, 1);
|
||||
}
|
||||
|
||||
mosquitto_lib_cleanup();
|
||||
return run;
|
||||
}
|
Loading…
Reference in New Issue