Increase coverage by subscribing to more than one topic and unsubscribing afterwards.

This commit is contained in:
Johannes Schriewer 2018-07-30 03:14:24 +02:00
parent 13056f9ce8
commit 883a3cc476

View file

@ -16,6 +16,20 @@ bool err_handler(MQTTHandle *handle, MQTTErrorCode error) {
void callback(MQTTHandle *handle, char *topic, char *payload) { void callback(MQTTHandle *handle, char *topic, char *payload) {
LOG("Received publish: %s -> %s", topic, payload); LOG("Received publish: %s -> %s", topic, payload);
MQTTStatus result = mqtt_unsubscribe(handle, "testsuite/mqtt/test");
if (result != MQTT_STATUS_OK) {
LOG("Could not unsubscribe test");
exit(1);
}
result = mqtt_unsubscribe(handle, "testsuite/mqtt/test2");
if (result != MQTT_STATUS_OK) {
LOG("Could not unsubscribe test 2");
exit(1);
}
sleep(1);
leave = true; leave = true;
} }
@ -25,7 +39,13 @@ void mqtt_connected(MQTTHandle *handle, void *context) {
LOG("Trying subscribe on testsuite/mqtt/test..."); LOG("Trying subscribe on testsuite/mqtt/test...");
MQTTStatus result = mqtt_subscribe(handle, "testsuite/mqtt/test", callback); MQTTStatus result = mqtt_subscribe(handle, "testsuite/mqtt/test", callback);
if (result != MQTT_STATUS_OK) { if (result != MQTT_STATUS_OK) {
LOG("Could not subscribe"); LOG("Could not subscribe test");
exit(1);
}
result = mqtt_subscribe(handle, "testsuite/mqtt/test2", callback);
if (result != MQTT_STATUS_OK) {
LOG("Could not subscribe test 2");
exit(1); exit(1);
} }
} }