Commit 2c108549 authored by Ian Craggs's avatar Ian Craggs

MQTT 3.1.1 changes in tests and synchronous client

parent 5ea74966
...@@ -1030,7 +1030,8 @@ int MQTTClient_connect(MQTTClient handle, MQTTClient_connectOptions* options) ...@@ -1030,7 +1030,8 @@ int MQTTClient_connect(MQTTClient handle, MQTTClient_connectOptions* options)
} }
if (strncmp(options->struct_id, "MQTC", 4) != 0 || if (strncmp(options->struct_id, "MQTC", 4) != 0 ||
(options->struct_version != 0 && options->struct_version != 1 && options->struct_version != 2)) (options->struct_version != 0 && options->struct_version != 1 && options->struct_version != 2
&& options->struct_version != 3))
{ {
rc = MQTTCLIENT_BAD_STRUCTURE; rc = MQTTCLIENT_BAD_STRUCTURE;
goto exit; goto exit;
......
...@@ -607,7 +607,7 @@ typedef struct ...@@ -607,7 +607,7 @@ typedef struct
int MQTTVersion; int MQTTVersion;
} MQTTClient_connectOptions; } MQTTClient_connectOptions;
#define MQTTClient_connectOptions_initializer { {'M', 'Q', 'T', 'C'}, 2, 60, 1, 1, NULL, NULL, NULL, 30, 20, NULL, 0, NULL, 0} #define MQTTClient_connectOptions_initializer { {'M', 'Q', 'T', 'C'}, 3, 60, 1, 1, NULL, NULL, NULL, 30, 20, NULL, 0, NULL, 0}
/** /**
* MQTTClient_libraryInfo is used to store details relating to the currently used * MQTTClient_libraryInfo is used to store details relating to the currently used
......
...@@ -64,6 +64,8 @@ struct Options ...@@ -64,6 +64,8 @@ struct Options
int hacount; int hacount;
int verbose; int verbose;
int test_no; int test_no;
int MQTTVersion;
int iterations;
} options = } options =
{ {
"tcp://m2m.eclipse.org:1883", "tcp://m2m.eclipse.org:1883",
...@@ -71,6 +73,8 @@ struct Options ...@@ -71,6 +73,8 @@ struct Options
0, 0,
0, 0,
0, 0,
MQTTVERSION_DEFAULT,
1,
}; };
void getopts(int argc, char** argv) void getopts(int argc, char** argv)
...@@ -114,6 +118,23 @@ void getopts(int argc, char** argv) ...@@ -114,6 +118,23 @@ void getopts(int argc, char** argv)
else else
usage(); usage();
} }
else if (strcmp(argv[count], "--MQTTversion") == 0)
{
if (++count < argc)
{
options.MQTTVersion = atoi(argv[count]);
printf("setting MQTT version to %d\n", options.MQTTVersion);
}
else
usage();
}
else if (strcmp(argv[count], "--iterations") == 0)
{
if (++count < argc)
options.iterations = atoi(argv[count]);
else
usage();
}
else if (strcmp(argv[count], "--verbose") == 0) else if (strcmp(argv[count], "--verbose") == 0)
{ {
options.verbose = 1; options.verbose = 1;
...@@ -353,6 +374,7 @@ int test1(struct Options options) ...@@ -353,6 +374,7 @@ int test1(struct Options options)
opts.cleansession = 1; opts.cleansession = 1;
opts.username = "testuser"; opts.username = "testuser";
opts.password = "testpassword"; opts.password = "testpassword";
opts.MQTTVersion = options.MQTTVersion;
if (options.haconnections != NULL) if (options.haconnections != NULL)
{ {
opts.serverURIs = options.haconnections; opts.serverURIs = options.haconnections;
...@@ -519,6 +541,7 @@ int test2(struct Options options) ...@@ -519,6 +541,7 @@ int test2(struct Options options)
opts.keepAliveInterval = 20; opts.keepAliveInterval = 20;
opts.cleansession = 1; opts.cleansession = 1;
opts.MQTTVersion = options.MQTTVersion;
if (options.haconnections != NULL) if (options.haconnections != NULL)
{ {
opts.serverURIs = options.haconnections; opts.serverURIs = options.haconnections;
...@@ -667,6 +690,7 @@ int test4_run(int qos) ...@@ -667,6 +690,7 @@ int test4_run(int qos)
opts.keepAliveInterval = 20; opts.keepAliveInterval = 20;
opts.reliable = 0; opts.reliable = 0;
opts.MQTTVersion = options.MQTTVersion;
if (options.haconnections != NULL) if (options.haconnections != NULL)
{ {
opts.serverURIs = options.haconnections; opts.serverURIs = options.haconnections;
...@@ -837,6 +861,7 @@ int test5(struct Options options) ...@@ -837,6 +861,7 @@ int test5(struct Options options)
opts.keepAliveInterval = 20; opts.keepAliveInterval = 20;
opts.cleansession = 0; opts.cleansession = 0;
opts.reliable = 0; opts.reliable = 0;
opts.MQTTVersion = options.MQTTVersion;
if (options.haconnections != NULL) if (options.haconnections != NULL)
{ {
opts.serverURIs = options.haconnections; opts.serverURIs = options.haconnections;
...@@ -1013,6 +1038,7 @@ int test6(struct Options options) ...@@ -1013,6 +1038,7 @@ int test6(struct Options options)
opts.keepAliveInterval = 2; opts.keepAliveInterval = 2;
opts.cleansession = 1; opts.cleansession = 1;
opts.MQTTVersion = options.MQTTVersion;
opts.will = &wopts; opts.will = &wopts;
opts.will->message = test6_will_message; opts.will->message = test6_will_message;
opts.will->qos = 1; opts.will->qos = 1;
...@@ -1103,6 +1129,7 @@ int main(int argc, char** argv) ...@@ -1103,6 +1129,7 @@ int main(int argc, char** argv)
{ {
int rc = 0; int rc = 0;
int (*tests[])() = {NULL, test1, test2, test3, test4, test5, test6}; int (*tests[])() = {NULL, test1, test2, test3, test4, test5, test6};
int i;
xml = fopen("TEST-test1.xml", "w"); xml = fopen("TEST-test1.xml", "w");
fprintf(xml, "<testsuite name=\"test1\" tests=\"%d\">\n", (int)(ARRAY_SIZE(tests) - 1)); fprintf(xml, "<testsuite name=\"test1\" tests=\"%d\">\n", (int)(ARRAY_SIZE(tests) - 1));
...@@ -1112,13 +1139,16 @@ int main(int argc, char** argv) ...@@ -1112,13 +1139,16 @@ int main(int argc, char** argv)
getopts(argc, argv); getopts(argc, argv);
if (options.test_no == 0) for (i = 0; i < options.iterations; ++i)
{ /* run all the tests */ {
for (options.test_no = 1; options.test_no < ARRAY_SIZE(tests); ++options.test_no) if (options.test_no == 0)
rc += tests[options.test_no](options); /* return number of failures. 0 = test succeeded */ { /* run all the tests */
for (options.test_no = 1; options.test_no < ARRAY_SIZE(tests); ++options.test_no)
rc += tests[options.test_no](options); /* return number of failures. 0 = test succeeded */
}
else
rc = tests[options.test_no](options); /* run just the selected test */
} }
else
rc = tests[options.test_no](options); /* run just the selected test */
if (rc == 0) if (rc == 0)
MyLog(LOGA_INFO, "verdict pass"); MyLog(LOGA_INFO, "verdict pass");
......
...@@ -1150,6 +1150,7 @@ int main(int argc, char** argv) ...@@ -1150,6 +1150,7 @@ int main(int argc, char** argv)
int rc = 0; int rc = 0;
int (*tests[])() = {NULL, test1, test2, test3, test4, test5, test6}; /* indexed starting from 1 */ int (*tests[])() = {NULL, test1, test2, test3, test4, test5, test6}; /* indexed starting from 1 */
MQTTAsync_nameValue* info; MQTTAsync_nameValue* info;
int i;
xml = fopen("TEST-test4.xml", "w"); xml = fopen("TEST-test4.xml", "w");
fprintf(xml, "<testsuite name=\"test4\" tests=\"%d\">\n", (int)(ARRAY_SIZE(tests)) - 1); fprintf(xml, "<testsuite name=\"test4\" tests=\"%d\">\n", (int)(ARRAY_SIZE(tests)) - 1);
...@@ -1165,20 +1166,23 @@ int main(int argc, char** argv) ...@@ -1165,20 +1166,23 @@ int main(int argc, char** argv)
info++; info++;
} }
if (options.test_no == -1) for (i = 0; i < options.iterations; ++i)
{ /* run all the tests */ {
for (options.test_no = 1; options.test_no < ARRAY_SIZE(tests); ++options.test_no) if (options.test_no == -1)
{ /* run all the tests */
for (options.test_no = 1; options.test_no < ARRAY_SIZE(tests); ++options.test_no)
{
failures = 0;
MQTTAsync_setTraceLevel(MQTTASYNC_TRACE_ERROR);
rc += tests[options.test_no](options); /* return number of failures. 0 = test succeeded */
}
}
else
{ {
failures = 0;
MQTTAsync_setTraceLevel(MQTTASYNC_TRACE_ERROR); MQTTAsync_setTraceLevel(MQTTASYNC_TRACE_ERROR);
rc += tests[options.test_no](options); /* return number of failures. 0 = test succeeded */ rc = tests[options.test_no](options); /* run just the selected test */
} }
} }
else
{
MQTTAsync_setTraceLevel(MQTTASYNC_TRACE_ERROR);
rc = tests[options.test_no](options); /* run just the selected test */
}
if (rc == 0) if (rc == 0)
MyLog(LOGA_INFO, "verdict pass"); MyLog(LOGA_INFO, "verdict pass");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment