* MDF [sub_handler_test] Update tests for multi-topic.
#include <assert.h>
#include <stdio.h>
-#include "include/sub_handler.h"
#include "include/nanomq.h"
+#include "include/sub_handler.h"
int
main()
@@ -33,7 +33,8 @@ main()
payload_ptr = NULL;
variable_ptr = NULL;
// set topic for test:$MQTT.
- uint8_t topic[] = { 0x00, 0x05, 0x24, 0x4D, 0x51, 0x54, 0x54, '\0' };
+ uint8_t topic[] = { 0x00, 0x05, 0x24, 0x4D, 0x51, 0x54, 0x54, '\0',
+ 0x00, 0x05, 0x25, 0x4D, 0x51, 0x54, 0x54, '\0' };
payload_ptr = topic;
nng_msg_set_payload_ptr(msg, payload_ptr);
// set remaining_len.
@@ -44,7 +45,6 @@ main()
// alloc sub_pkt.
work->sub_pkt = nng_alloc(sizeof(packet_subscribe));
-
/* test for function decode_sub_msg() */
// test for case: packet_id == 0.
rv = decode_sub_msg(work);
@@ -54,13 +54,18 @@ main()
// set packet_id: 0x05.
uint8_t packet_id[2] = { 0x00, 0x05 };
nng_msg_append(work->msg, packet_id, 2);
- remaining_len = nng_msg_len(work->msg);
+ remaining_len = 12;
nng_msg_set_remaining_len(work->msg, remaining_len);
rv = decode_sub_msg(work);
assert(rv == 0);
- rv = strcmp(work->sub_pkt->node->topic.body, "$MQTT");
+ topic_node *node = work->sub_pkt->node;
+ rv = strcmp(node->topic.body, "$MQTT");
+ assert(rv == 0);
+
+ node = node->next;
+ rv = strcmp(node->topic.body, "%MQTT");
assert(rv == 0);
/* test for encode_suback_msg() */
@@ -74,12 +79,11 @@ main()
assert(pkt_id == 5);
NNI_GET16(variable_ptr + 2, reason_code);
- assert(reason_code == 0);
+ assert(reason_code == GRANTED_QOS_2);
fix_ptr = nng_msg_header(msg);
assert(*(uint8_t *) fix_ptr == CMD_SUBACK);
-
/* test for sub_ctx_handle() */
// rv = sub_ctx_handle(work);
// assert(rv == 0);
@@ -95,5 +99,4 @@ main()
nng_msg_free(msg);
nng_free(work, sizeof(struct work));
-
}
