Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test for v5 property #1681

Merged
merged 2 commits into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions nanomq/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ nanomq_test(bridge_rap_rh_test)
nanomq_test(bridge_aws_test)
nanomq_test(bridge_muti_bridge_test)
nanomq_test(mqtt_api_test)
nanomq_test(properties_test)
if(ENABLE_PARQUET)
nanomq_test(parquet_test)
endif()
88 changes: 88 additions & 0 deletions nanomq/tests/properties_test.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
//
// Copyright 2023 NanoMQ Team, Inc. <jaylin@emqx.io>
//
// This software is supplied under the terms of the MIT License, a
// copy of which should be located in the distribution where this
// file was obtained (LICENSE.txt). A copy of the license may also be
// found online at https://opensource.org/licenses/MIT.
//
#include "include/broker.h"
#include "tests_api.h"

int
main()
{
int rv = 0;

char *cmd_pub = "mosquitto_pub -h 127.0.0.1 -p 1881 -t topic1 -m "
"message -q 2 -V mqttv5"
" -D CONNECT authentication-data 101"
" -D CONNECT authentication-method auth-mtd"
" -D CONNECT maximum-packet-size 512"
" -D CONNECT receive-maximum 16"
" -D CONNECT request-problem-information 1"
" -D CONNECT request-response-information 0"
" -D CONNECT session-expiry-interval 32"
" -D CONNECT topic-alias-maximum 16"
" -D CONNECT user-property c-up-n c-up-v"
" -D PUBLISH content-type ct"
" -D PUBLISH correlation-data 010101"
" -D PUBLISH message-expiry-interval 32"
" -D PUBLISH payload-format-indicator 8"
" -D PUBLISH response-topic response-t"
" -D PUBLISH topic-alias 16"
" -D PUBLISH user-property p-up-n p-up-v"
" -D DISCONNECT session-expiry-interval 32"
" -D DISCONNECT user-property d-up-n d-up-v"
" -D WILL content-type ct-tp"
" -D WILL correlation-data 0100101"
" -D WILL message-expiry-interval 32"
" -D WILL payload-format-indicator 8"
" -D WILL response-topic resp-tp"
" -D WILL user-property w-up-n w-up-v"
" -D WILL will-delay-interval 32";

nng_thread *nmq;
pid_t pid_sub;
FILE *p_pub = NULL;
conf *conf;

int buf_size = 128;
char buf[buf_size];
int infp, outfp;

// create nmq thread
conf = get_test_conf(ALL_FEATURE_CONF);
assert(conf != NULL);
nng_thread_create(&nmq, (void *) broker_start_with_conf, (void *) conf);
nng_msleep(50); // wait a while before sub

// pipe to sub
char *arg[] = { "mosquitto_sub", "-t", "topic1", "-t", "topic2", "-U",
"topic2", "-h", "127.0.0.1", "-p", "1881", "-q", "2", "-V",
"mqttv5",
// regard as invalid sub and unsub packet
// "-D", "SUBSCRIBE", "user-property", "s-up-n",
// "s-up-v", "-D", "UNSUBSCRIBE", "user-property", "u-up-n",
// "u-up-v",
NULL };

pid_sub = popen_sub_with_cmd(&outfp, arg);
nng_msleep(50); // pub should be slightly behind sub

// pipe to pub
p_pub = popen(cmd_pub, "r");

// check recv msg
assert(read(outfp, buf, buf_size) != -1);
printf("what we got:%s", buf);
assert(strncmp(buf, "message", 7) == 0);

kill(pid_sub, SIGKILL);
pclose(p_pub);
close(outfp);

nng_thread_destroy(nmq);

return 0;
}