From 883a3cc476b07eed5e8107764b01c981ddc32a31 Mon Sep 17 00:00:00 2001 From: Johannes Schriewer Date: Mon, 30 Jul 2018 03:14:24 +0200 Subject: [PATCH] Increase coverage by subscribing to more than one topic and unsubscribing afterwards. --- tests/connect_subscribe.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/tests/connect_subscribe.c b/tests/connect_subscribe.c index ad17f0b..f8e208a 100644 --- a/tests/connect_subscribe.c +++ b/tests/connect_subscribe.c @@ -16,6 +16,20 @@ bool err_handler(MQTTHandle *handle, MQTTErrorCode error) { void callback(MQTTHandle *handle, char *topic, char *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; } @@ -25,7 +39,13 @@ void mqtt_connected(MQTTHandle *handle, void *context) { LOG("Trying subscribe on testsuite/mqtt/test..."); MQTTStatus result = mqtt_subscribe(handle, "testsuite/mqtt/test", callback); 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); } }