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)
}
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;
goto exit;
......
......@@ -607,7 +607,7 @@ typedef struct
int MQTTVersion;
} 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
......
......@@ -64,6 +64,8 @@ struct Options
int hacount;
int verbose;
int test_no;
int MQTTVersion;
int iterations;
} options =
{
"tcp://m2m.eclipse.org:1883",
......@@ -71,6 +73,8 @@ struct Options
0,
0,
0,
MQTTVERSION_DEFAULT,
1,
};
void getopts(int argc, char** argv)
......@@ -114,6 +118,23 @@ void getopts(int argc, char** argv)
else
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)
{
options.verbose = 1;
......@@ -353,6 +374,7 @@ int test1(struct Options options)
opts.cleansession = 1;
opts.username = "testuser";
opts.password = "testpassword";
opts.MQTTVersion = options.MQTTVersion;
if (options.haconnections != NULL)
{
opts.serverURIs = options.haconnections;
......@@ -519,6 +541,7 @@ int test2(struct Options options)
opts.keepAliveInterval = 20;
opts.cleansession = 1;
opts.MQTTVersion = options.MQTTVersion;
if (options.haconnections != NULL)
{
opts.serverURIs = options.haconnections;
......@@ -667,6 +690,7 @@ int test4_run(int qos)
opts.keepAliveInterval = 20;
opts.reliable = 0;
opts.MQTTVersion = options.MQTTVersion;
if (options.haconnections != NULL)
{
opts.serverURIs = options.haconnections;
......@@ -837,6 +861,7 @@ int test5(struct Options options)
opts.keepAliveInterval = 20;
opts.cleansession = 0;
opts.reliable = 0;
opts.MQTTVersion = options.MQTTVersion;
if (options.haconnections != NULL)
{
opts.serverURIs = options.haconnections;
......@@ -1013,6 +1038,7 @@ int test6(struct Options options)
opts.keepAliveInterval = 2;
opts.cleansession = 1;
opts.MQTTVersion = options.MQTTVersion;
opts.will = &wopts;
opts.will->message = test6_will_message;
opts.will->qos = 1;
......@@ -1103,6 +1129,7 @@ int main(int argc, char** argv)
{
int rc = 0;
int (*tests[])() = {NULL, test1, test2, test3, test4, test5, test6};
int i;
xml = fopen("TEST-test1.xml", "w");
fprintf(xml, "<testsuite name=\"test1\" tests=\"%d\">\n", (int)(ARRAY_SIZE(tests) - 1));
......@@ -1112,6 +1139,8 @@ int main(int argc, char** argv)
getopts(argc, argv);
for (i = 0; i < options.iterations; ++i)
{
if (options.test_no == 0)
{ /* run all the tests */
for (options.test_no = 1; options.test_no < ARRAY_SIZE(tests); ++options.test_no)
......@@ -1119,6 +1148,7 @@ int main(int argc, char** argv)
}
else
rc = tests[options.test_no](options); /* run just the selected test */
}
if (rc == 0)
MyLog(LOGA_INFO, "verdict pass");
......
......@@ -1150,6 +1150,7 @@ int main(int argc, char** argv)
int rc = 0;
int (*tests[])() = {NULL, test1, test2, test3, test4, test5, test6}; /* indexed starting from 1 */
MQTTAsync_nameValue* info;
int i;
xml = fopen("TEST-test4.xml", "w");
fprintf(xml, "<testsuite name=\"test4\" tests=\"%d\">\n", (int)(ARRAY_SIZE(tests)) - 1);
......@@ -1165,6 +1166,8 @@ int main(int argc, char** argv)
info++;
}
for (i = 0; i < options.iterations; ++i)
{
if (options.test_no == -1)
{ /* run all the tests */
for (options.test_no = 1; options.test_no < ARRAY_SIZE(tests); ++options.test_no)
......@@ -1179,6 +1182,7 @@ int main(int argc, char** argv)
MQTTAsync_setTraceLevel(MQTTASYNC_TRACE_ERROR);
rc = tests[options.test_no](options); /* run just the selected test */
}
}
if (rc == 0)
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