diff --git a/org.eclipse.paho.mqtt.c/test/MQTTTest_v2.c b/org.eclipse.paho.mqtt.c/test/MQTTTest_v2.c
deleted file mode 100644
index 7fd1527..0000000
--- a/org.eclipse.paho.mqtt.c/test/MQTTTest_v2.c
+++ /dev/null
@@ -1,416 +0,0 @@
-/*
- * -----------------------------------------------------------------
- * IBM Websphere MQ Telemetry
- * MQTTV3ASample MQTT v3 Asynchronous Client application
- *
- * Version: @(#) MQMBID sn=p000-L130522.1 su=_M3QBMsMbEeK31Ln-reX3cg pn=com.ibm.mq.mqxr.listener/SDK/clients/c/samples/MQTTV3ASample.c
- *
- *
- * Licensed Materials - Property of IBM
- *
- * 5724-H72,
- *
- * (C) Copyright IBM Corp. 2010, 2012 All Rights Reserved.
- *
- * US Government Users Restricted Rights - Use, duplication or
- * disclosure restricted by GSA ADP Schedule Contract with
- * IBM Corp.
- *
- * -----------------------------------------------------------------
- */
-
-/**
- * This sample application demonstrates basic usage
- * of the MQTT v3 Asynchronous Client api.
- *
- * It can be run in one of two modes:
- * - as a publisher, sending a single message to a topic on the server
- * - as a subscriber, listening for messages from the server
- *
- */
-
-
-#include
-#include
-#include
-#include
-#include
-#include
-
-#if defined(WIN32)
-#include
-#define sleep Sleep
-#else
-#include
-#include
-#endif
-
- volatile int toStop = 0;
- volatile int finished = 0;
- volatile int connected = 0;
- volatile int quietMode = 0;
- volatile int sent = 0;
- volatile int delivery = 0;
- volatile MQTTAsync_token deliveredtoken;
- static char clientId[24];
- struct Options
- {
- char* action;
- char* topic;
- char* message;
- int qos;
- char* broker;
- char* port;
- int message_count;
- } options =
- {
- "publish",
- NULL,
- "2",
- 2,
- "localhost",
- "1883",
- 100
- };
-
- void printHelp()
- {
- printf("Syntax:\n\n");
- printf(" MQTTV3ASample [-h] [-a publish|subscribe] [-t ] [-m ]\n");
- printf(" [-s 0|1|2] [-b ] [-p ] \n\n");
- printf(" -h Print this help text and quit\n");
- printf(" -q Quiet mode (default is false)\n");
- printf(" -a Perform the relevant action (default is publish)\n");
- printf(" -t Publish/subscribe to instead of the default\n");
- printf(" (publish: \"MQTTV3ASample/C/v3\", subscribe: \"MQTTV3ASample/#\")\n");
- printf(" -m Use this message instead of the default (\"Message from MQTTv3 C asynchronous client\")\n");
- printf(" -s Use this QoS instead of the default (2)\n");
- printf(" -b Use this name/IP address instead of the default (localhost)\n");
- printf(" -p Use this port instead of the default (1883)\n");
- printf("\nDelimit strings containing spaces with \"\"\n");
- printf("\nPublishers transmit a single message then disconnect from the broker.\n");
- printf("Subscribers remain connected to the broker and receive appropriate messages\n");
- printf("until Control-C (^C) is received from the keyboard.\n\n");
- }
-
-
- void handleSignal(int sig)
- {
- toStop = 1;
- }
-
- int messageArrived(void *context, char *topicName, int topicLen, MQTTAsync_message *message)
- {
- int i;
- char* payloadptr;
- if((sent++ % 1000) == 0)
- printf("%d messages received\n", sent++);
- //printf("Message arrived\n");
- //printf(" topic: %s\n", topicName);
- //printf(" message: ");
-
- //payloadptr = message->payload;
- //for(i=0; ipayloadlen; i++)
- //{
- // putchar(*payloadptr++);
- //}
- //putchar('\n');
- MQTTAsync_freeMessage(&message);
- MQTTAsync_free(topicName);
- return 1;
- }
-
- void onSubscribe(void* context, MQTTAsync_successData* response)
- {
- printf("Subscribe succeeded\n");
- }
-
- void onSubscribeFailure(void* context, MQTTAsync_failureData* response)
- {
- printf("Subscribe failed\n");
- finished = 1;
- }
-
- void onDisconnect(void* context, MQTTAsync_successData* response)
- {
- printf("Successful disconnection\n");
- finished = 1;
- }
-
-
- void onSendFailure(void* context, MQTTAsync_failureData* response)
- {
- printf("onSendFailure: message with token value %d delivery failed\n", response->token);
- }
-
-
-
- void onSend(void* context, MQTTAsync_successData* response)
- {
- static last_send = 0;
-
- if (response->token - last_send != 1)
- printf("Error in onSend, token value %d, last_send %d\n", response->token, last_send);
-
- last_send++;
-
- if ((response->token % 1000) == 0)
- printf("onSend: message with token value %d delivery confirmed\n", response->token);
- }
-
- void deliveryComplete(void* context, MQTTAsync_token token)
- {
- sent++;
- if ((sent % 1000) == 0)
- printf("deliveryComplete: message with token value %d delivery confirmed\n", token);
- if (sent != token)
- printf("Error, sent %d != token %d\n", sent, token);
- if (sent == options.message_count)
- toStop = 1;
- }
-
- void onConnectFailure(void* context, MQTTAsync_failureData* response)
- {
- printf("Connect failed\n");
- finished = 1;
- }
-
-
- void onConnect(void* context, MQTTAsync_successData* response)
- {
- printf("Connected\n");
- connected=1;
- }
-
- void connectionLost(void *context, char *cause)
- {
- MQTTAsync client = (MQTTAsync)context;
- MQTTAsync_connectOptions conn_opts = MQTTAsync_connectOptions_initializer;
- int rc;
-
- printf("\nConnection lost\n");
- printf(" cause: %s\n", cause);
-
- printf("Reconnecting\n");
- conn_opts.keepAliveInterval = 20;
- conn_opts.cleansession = 1;
- conn_opts.onSuccess = onConnect;
- conn_opts.onFailure = onConnectFailure;
- conn_opts.context = client;
- conn_opts.retryInterval = 1000;
- if ((rc = MQTTAsync_connect(client, &conn_opts)) != MQTTASYNC_SUCCESS)
- {
- printf("Failed to start connect, return code %d\n", rc);
- finished = 1;
- }
- }
-
-
-void handleTrace(enum MQTTASYNC_TRACE_LEVELS level, char* message)
-{
- printf("%s\n", message);
-}
-
-
-/**
- * The main entry point of the sample.
- *
- * This method handles parsing the arguments specified on the
- * command-line before performing the specified action.
- */
- int main(int argc, char** argv)
- {
- int rc = 0;
- int ch;
- char url[256];
-
- // Default settings:
- int i=0;
-
- MQTTAsync client;
- MQTTAsync_connectOptions conn_opts = MQTTAsync_connectOptions_initializer;
- MQTTAsync_message pubmsg = MQTTAsync_message_initializer;
- MQTTAsync_token token;
-
- signal(SIGINT, handleSignal);
- signal(SIGTERM, handleSignal);
-
- quietMode = 0;
- // Parse the arguments -
- for (i=1; i 2)
- {
- printf("Invalid QoS: %d\n", options.qos);
- printHelp();
- return 255;
- }
- if (options.topic == NULL || ( options.topic != NULL && strlen(options.topic) == 0) )
- {
- // Set the default topic according to the specified action
- if (strcmp(options.action, "publish") == 0)
- options.topic = "MQTTV3ASample/C/v3";
- else
- options.topic = "MQTTV3ASample/#";
- }
-
- // Construct the full broker URL and clientId
- sprintf(url, "tcp://%s:%s", options.broker, options.port);
- sprintf(clientId, "SampleCV3A_%s", options.action);
-
-
- MQTTAsync_create(&client, url, clientId, MQTTCLIENT_PERSISTENCE_NONE, NULL);
-
- MQTTAsync_setTraceCallback(handleTrace);
- MQTTAsync_setTraceLevel(MQTTASYNC_TRACE_ERROR);
-
- MQTTAsync_setCallbacks(client, client, connectionLost, messageArrived, deliveryComplete);
-
- conn_opts.cleansession = 0;
- conn_opts.onSuccess = onConnect;
- conn_opts.onFailure = onConnectFailure;
- conn_opts.context = client;
- conn_opts.keepAliveInterval = 0;
- conn_opts.retryInterval = 0;
- //conn_opts.maxInflight= 30;
-
- if ((rc = MQTTAsync_connect(client, &conn_opts)) != MQTTASYNC_SUCCESS)
- {
- printf("Failed to start connect, return code %d\n", rc);
- goto exit;
- }
- printf("Waiting for connect\n");
- while (connected == 0 && finished == 0 && toStop == 0) {
- printf("Waiting for connect: %d %d %d\n", connected, finished, toStop);
- usleep(10000L);
- }
-
- MQTTAsync_responseOptions opts = MQTTAsync_responseOptions_initializer;
- printf("Waiting for connect: %d %d %d\n", connected, finished, toStop);
-
- printf("Successful connection\n");
-
- if (connected == 1 && strcmp(options.action, "publish") == 0)
- {
- unsigned long i;
- struct timeval tv;
- gettimeofday(&tv,NULL);
- printf("start seconds : %ld\n",tv.tv_sec);
- for (i = 0; i < options.message_count; i++)
- {
- opts.onSuccess = onSend;
- opts.onFailure = onSendFailure;
- opts.context = client;
- pubmsg.payload = options.message;
- pubmsg.payloadlen = strlen(options.message);
- pubmsg.qos = options.qos;
- pubmsg.retained = 0;
- deliveredtoken = 0;
- usleep(100);
-
- if ((rc = MQTTAsync_sendMessage(client, options.topic, &pubmsg, &opts))
- != MQTTASYNC_SUCCESS)
- {
- printf("Failed to start sendMessage, return code %d\n", rc);
- exit(-1);
- }
- }
-
- gettimeofday(&tv,NULL);
-
- printf("end seconds : %ld\n",tv.tv_sec);
- } else if (strcmp(options.action, "subscribe") == 0) {
- opts.onSuccess = onSubscribe;
- opts.onFailure = onSubscribeFailure;
- opts.context = client;
- if ((rc = MQTTAsync_subscribe(client, options.topic, options.qos, &opts)) != MQTTASYNC_SUCCESS) {
- printf("Failed to subscribe, return code %d\n", rc);
- exit(-1);
- }
- }
-
- while (!finished)
- {
-#if defined(WIN32)
- Sleep(100);
-#else
- usleep(1000L);
-#endif
- if (toStop == 1)
- {
- MQTTAsync_disconnectOptions opts = MQTTAsync_disconnectOptions_initializer;
-
- opts.onSuccess = onDisconnect;
- opts.context = client;
- printf("Entering disconnection phase\n");
- if ((rc = MQTTAsync_disconnect(client, &opts)) != MQTTASYNC_SUCCESS)
- {
- printf("Failed to start disconnect, return code %d\n", rc);
- exit(-1);
- }
- toStop = 0;
- }
- }
-
- exit:
- printf("calling destroy\n");
- MQTTAsync_destroy(&client);
- return rc;
- }
diff --git a/org.eclipse.paho.mqtt.c/test/ssl/all-ca.crt b/org.eclipse.paho.mqtt.c/test/ssl/all-ca.crt
deleted file mode 100644
index 696a5f7..0000000
--- a/org.eclipse.paho.mqtt.c/test/ssl/all-ca.crt
+++ /dev/null
@@ -1,35 +0,0 @@
------BEGIN CERTIFICATE-----
-MIICnTCCAgagAwIBAgIBATANBgkqhkiG9w0BAQUFADByMQswCQYDVQQGEwJHQjET
-MBEGA1UECAwKRGVyYnlzaGlyZTEOMAwGA1UEBwwFRGVyYnkxGjAYBgNVBAoMEU1v
-c3F1aXR0byBQcm9qZWN0MRAwDgYDVQQLDAdUZXN0aW5nMRAwDgYDVQQDDAdSb290
-IENBMB4XDTEzMDcyNDIzNTExNloXDTE4MDcyMzIzNTExNlowZTELMAkGA1UEBhMC
-R0IxEzARBgNVBAgMCkRlcmJ5c2hpcmUxGjAYBgNVBAoMEU1vc3F1aXR0byBQcm9q
-ZWN0MRAwDgYDVQQLDAdUZXN0aW5nMRMwEQYDVQQDDApTaWduaW5nIENBMIGfMA0G
-CSqGSIb3DQEBAQUAA4GNADCBiQKBgQC1Sir65IBDbm7bI4lHDakEoN0Y6DUg/Spz
-FoPe4cbixwS1pg3514X2srv9w03Kzp/obDOs/JzbqcPfOBAuiiPlMm1hw9az1B7N
-9lg/2DKHL/7Oq8IZUKsFjhbFAMjQd/PAZCkBO1FS1Y0jZes4/1fzlqq4rYItTie+
-YX8tTDc/7QIDAQABo1AwTjAdBgNVHQ4EFgQU5W621SksDwZxSpsZsFkm6/QuAQYw
-HwYDVR0jBBgwFoAUq92KK7UYT6V7F1mySt6+LWTPzr4wDAYDVR0TBAUwAwEB/zAN
-BgkqhkiG9w0BAQUFAAOBgQBMcwdjElUOhXqoqlX1DWik58X73GHxjE52jao4BHRZ
-S+PpwOOjfnq4CfIXF1cMp95cK+Eh566lEJf2udlV1waKew578T86+UsRO/T/a0bb
-3FuuZH3TXnO+OjNMTWKMZ0iLQtPwNN4m9lszECrSgJ53yCIB6iq/zfXVSop7XFzd
-VQ==
------END CERTIFICATE-----
------BEGIN CERTIFICATE-----
-MIICqDCCAhGgAwIBAgIJAKrzwmdXIUxsMA0GCSqGSIb3DQEBBQUAMG0xCzAJBgNV
-BAYTAkdCMRMwEQYDVQQIDApEZXJieXNoaXJlMQ4wDAYDVQQHDAVEZXJieTEVMBMG
-A1UECgwMUGFobyBQcm9qZWN0MRAwDgYDVQQLDAdUZXN0aW5nMRAwDgYDVQQDDAdS
-b290IENBMB4XDTEzMDcyOTE5MjEyOVoXDTIzMDcyNzE5MjEyOVowbTELMAkGA1UE
-BhMCR0IxEzARBgNVBAgMCkRlcmJ5c2hpcmUxDjAMBgNVBAcMBURlcmJ5MRUwEwYD
-VQQKDAxQYWhvIFByb2plY3QxEDAOBgNVBAsMB1Rlc3RpbmcxEDAOBgNVBAMMB1Jv
-b3QgQ0EwgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBAKbPzEEWCKsjjwjJ787u
-Q32k5EdqoDddMEjSVbZNSNEwUew1L7O8NTbmtCEeVFQjOLAdmdiF3rQbXHV+Zew0
-jt2g4vtPpl1GOG6jA/6YznKAyQdvGCdYfGZUN2tN+mbtVxWqkHZitQDQGaSHnx24
-NX649La2uyFy+7l9o8++xPONAgMBAAGjUDBOMB0GA1UdDgQWBBRKK2nWMR2jaOhG
-b/tL8462jVEOvzAfBgNVHSMEGDAWgBRKK2nWMR2jaOhGb/tL8462jVEOvzAMBgNV
-HRMEBTADAQH/MA0GCSqGSIb3DQEBBQUAA4GBAEd+gW86/W+fisz5PFHAeEw7zn9q
-dzLHm7+QZgNLZ9h7/ZbhObRUFMRtU2xm4amyh85h7hUE5R2E2uW2OXumic7/D4ZD
-6unjr4m5jwVWDTqTUYIcNSriyoDWAVlPfOWaU5NyUhqS1DM28tvOWVHVLCxmVcZl
-tJQqo5eHbQ/+Hjfx
------END CERTIFICATE-----
-
diff --git a/org.eclipse.paho.mqtt.c/test/ssl/all-ca.crt.text b/org.eclipse.paho.mqtt.c/test/ssl/all-ca.crt.text
deleted file mode 100644
index a672f77..0000000
--- a/org.eclipse.paho.mqtt.c/test/ssl/all-ca.crt.text
+++ /dev/null
@@ -1,58 +0,0 @@
-Certificate:
- Data:
- Version: 3 (0x2)
- Serial Number: 1 (0x1)
- Signature Algorithm: sha1WithRSAEncryption
- Issuer: C=GB, ST=Derbyshire, L=Derby, O=Mosquitto Project, OU=Testing, CN=Root CA
- Validity
- Not Before: Jul 24 23:51:16 2013 GMT
- Not After : Jul 23 23:51:16 2018 GMT
- Subject: C=GB, ST=Derbyshire, O=Mosquitto Project, OU=Testing, CN=Signing CA
- Subject Public Key Info:
- Public Key Algorithm: rsaEncryption
- Public-Key: (1024 bit)
- Modulus:
- 00:b5:4a:2a:fa:e4:80:43:6e:6e:db:23:89:47:0d:
- a9:04:a0:dd:18:e8:35:20:fd:2a:73:16:83:de:e1:
- c6:e2:c7:04:b5:a6:0d:f9:d7:85:f6:b2:bb:fd:c3:
- 4d:ca:ce:9f:e8:6c:33:ac:fc:9c:db:a9:c3:df:38:
- 10:2e:8a:23:e5:32:6d:61:c3:d6:b3:d4:1e:cd:f6:
- 58:3f:d8:32:87:2f:fe:ce:ab:c2:19:50:ab:05:8e:
- 16:c5:00:c8:d0:77:f3:c0:64:29:01:3b:51:52:d5:
- 8d:23:65:eb:38:ff:57:f3:96:aa:b8:ad:82:2d:4e:
- 27:be:61:7f:2d:4c:37:3f:ed
- Exponent: 65537 (0x10001)
- X509v3 extensions:
- X509v3 Subject Key Identifier:
- E5:6E:B6:D5:29:2C:0F:06:71:4A:9B:19:B0:59:26:EB:F4:2E:01:06
- X509v3 Authority Key Identifier:
- keyid:AB:DD:8A:2B:B5:18:4F:A5:7B:17:59:B2:4A:DE:BE:2D:64:CF:CE:BE
-
- X509v3 Basic Constraints:
- CA:TRUE
- Signature Algorithm: sha1WithRSAEncryption
- 4c:73:07:63:12:55:0e:85:7a:a8:aa:55:f5:0d:68:a4:e7:c5:
- fb:dc:61:f1:8c:4e:76:8d:aa:38:04:74:59:4b:e3:e9:c0:e3:
- a3:7e:7a:b8:09:f2:17:17:57:0c:a7:de:5c:2b:e1:21:e7:ae:
- a5:10:97:f6:b9:d9:55:d7:06:8a:7b:0e:7b:f1:3f:3a:f9:4b:
- 11:3b:f4:ff:6b:46:db:dc:5b:ae:64:7d:d3:5e:73:be:3a:33:
- 4c:4d:62:8c:67:48:8b:42:d3:f0:34:de:26:f6:5b:33:10:2a:
- d2:80:9e:77:c8:22:01:ea:2a:bf:cd:f5:d5:4a:8a:7b:5c:5c:
- dd:55
------BEGIN CERTIFICATE-----
-MIICnTCCAgagAwIBAgIBATANBgkqhkiG9w0BAQUFADByMQswCQYDVQQGEwJHQjET
-MBEGA1UECAwKRGVyYnlzaGlyZTEOMAwGA1UEBwwFRGVyYnkxGjAYBgNVBAoMEU1v
-c3F1aXR0byBQcm9qZWN0MRAwDgYDVQQLDAdUZXN0aW5nMRAwDgYDVQQDDAdSb290
-IENBMB4XDTEzMDcyNDIzNTExNloXDTE4MDcyMzIzNTExNlowZTELMAkGA1UEBhMC
-R0IxEzARBgNVBAgMCkRlcmJ5c2hpcmUxGjAYBgNVBAoMEU1vc3F1aXR0byBQcm9q
-ZWN0MRAwDgYDVQQLDAdUZXN0aW5nMRMwEQYDVQQDDApTaWduaW5nIENBMIGfMA0G
-CSqGSIb3DQEBAQUAA4GNADCBiQKBgQC1Sir65IBDbm7bI4lHDakEoN0Y6DUg/Spz
-FoPe4cbixwS1pg3514X2srv9w03Kzp/obDOs/JzbqcPfOBAuiiPlMm1hw9az1B7N
-9lg/2DKHL/7Oq8IZUKsFjhbFAMjQd/PAZCkBO1FS1Y0jZes4/1fzlqq4rYItTie+
-YX8tTDc/7QIDAQABo1AwTjAdBgNVHQ4EFgQU5W621SksDwZxSpsZsFkm6/QuAQYw
-HwYDVR0jBBgwFoAUq92KK7UYT6V7F1mySt6+LWTPzr4wDAYDVR0TBAUwAwEB/zAN
-BgkqhkiG9w0BAQUFAAOBgQBMcwdjElUOhXqoqlX1DWik58X73GHxjE52jao4BHRZ
-S+PpwOOjfnq4CfIXF1cMp95cK+Eh566lEJf2udlV1waKew578T86+UsRO/T/a0bb
-3FuuZH3TXnO+OjNMTWKMZ0iLQtPwNN4m9lszECrSgJ53yCIB6iq/zfXVSop7XFzd
-VQ==
------END CERTIFICATE-----
diff --git a/org.eclipse.paho.mqtt.c/test/ssl/cert.zip b/org.eclipse.paho.mqtt.c/test/ssl/cert.zip
deleted file mode 100644
index dc13869..0000000
Binary files a/org.eclipse.paho.mqtt.c/test/ssl/cert.zip and /dev/null differ
diff --git a/org.eclipse.paho.mqtt.c/test/ssl/client.crt b/org.eclipse.paho.mqtt.c/test/ssl/client.crt
deleted file mode 100644
index b007d4c..0000000
--- a/org.eclipse.paho.mqtt.c/test/ssl/client.crt
+++ /dev/null
@@ -1,60 +0,0 @@
-Certificate:
- Data:
- Version: 3 (0x2)
- Serial Number: 2 (0x2)
- Signature Algorithm: sha1WithRSAEncryption
- Issuer: C=GB, ST=Derbyshire, O=Paho Project, OU=Testing, CN=Signing CA
- Validity
- Not Before: Jul 29 19:21:31 2013 GMT
- Not After : Jul 28 19:21:31 2018 GMT
- Subject: C=GB, ST=Nottinghamshire, L=Nottingham, O=Server, OU=Production, CN=test client
- Subject Public Key Info:
- Public Key Algorithm: rsaEncryption
- Public-Key: (1024 bit)
- Modulus:
- 00:dc:17:82:af:47:dc:71:77:73:c3:69:11:4b:ff:
- 27:0e:29:4b:e6:6f:11:78:e4:56:88:c9:34:13:12:
- e1:82:ec:24:fe:65:c8:9d:bb:05:54:20:d0:b4:31:
- b9:4b:87:f8:4d:e5:c1:ba:99:f8:a2:cc:ff:8e:89:
- f2:7a:68:2f:53:42:4d:73:19:5e:ca:7e:b2:fe:3b:
- f7:d1:bc:e8:24:fa:77:47:ee:a4:89:cf:d1:dc:e9:
- 99:3f:da:0e:d0:1e:c6:40:d2:60:ee:38:83:4e:a4:
- dd:46:a3:6a:ac:c9:61:af:d5:23:9d:23:14:b5:31:
- d5:ca:66:7a:30:3f:c2:ce:59
- Exponent: 65537 (0x10001)
- X509v3 extensions:
- X509v3 Basic Constraints:
- CA:FALSE
- Netscape Comment:
- OpenSSL Generated Certificate
- X509v3 Subject Key Identifier:
- 17:CD:6D:67:FB:7D:77:59:0F:6C:F1:9B:0E:B0:EB:AE:BE:E0:9D:47
- X509v3 Authority Key Identifier:
- keyid:29:4D:6E:C7:F2:F7:71:72:DA:27:9C:9C:AB:DA:07:1D:47:9C:D8:41
-
- Signature Algorithm: sha1WithRSAEncryption
- b4:11:e8:8a:f5:21:d1:88:22:9e:f3:05:e6:47:c9:9d:87:10:
- 09:a1:9c:f1:38:5b:a0:5a:b4:f5:fd:8d:cf:ae:01:7d:b4:a8:
- 3c:dd:ed:17:b3:02:56:5b:4a:e6:17:58:8f:46:d4:02:97:95:
- 0b:00:0e:b4:77:3e:ad:f0:ce:06:25:38:2d:ff:df:a4:0e:3b:
- 83:73:f7:a3:da:c1:a1:24:68:a2:18:71:81:4e:3b:26:5a:e2:
- 10:9a:27:95:85:a8:3c:47:3a:60:49:21:2f:12:90:fc:4a:f0:
- 71:4d:bc:19:2a:06:07:f4:35:d9:8d:1d:b2:85:93:61:17:45:
- 26:9a
------BEGIN CERTIFICATE-----
-MIICyTCCAjKgAwIBAgIBAjANBgkqhkiG9w0BAQUFADBgMQswCQYDVQQGEwJHQjET
-MBEGA1UECAwKRGVyYnlzaGlyZTEVMBMGA1UECgwMUGFobyBQcm9qZWN0MRAwDgYD
-VQQLDAdUZXN0aW5nMRMwEQYDVQQDDApTaWduaW5nIENBMB4XDTEzMDcyOTE5MjEz
-MVoXDTE4MDcyODE5MjEzMVoweDELMAkGA1UEBhMCR0IxGDAWBgNVBAgMD05vdHRp
-bmdoYW1zaGlyZTETMBEGA1UEBwwKTm90dGluZ2hhbTEPMA0GA1UECgwGU2VydmVy
-MRMwEQYDVQQLDApQcm9kdWN0aW9uMRQwEgYDVQQDDAt0ZXN0IGNsaWVudDCBnzAN
-BgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEA3BeCr0fccXdzw2kRS/8nDilL5m8ReORW
-iMk0ExLhguwk/mXInbsFVCDQtDG5S4f4TeXBupn4osz/jonyemgvU0JNcxleyn6y
-/jv30bzoJPp3R+6kic/R3OmZP9oO0B7GQNJg7jiDTqTdRqNqrMlhr9UjnSMUtTHV
-ymZ6MD/CzlkCAwEAAaN7MHkwCQYDVR0TBAIwADAsBglghkgBhvhCAQ0EHxYdT3Bl
-blNTTCBHZW5lcmF0ZWQgQ2VydGlmaWNhdGUwHQYDVR0OBBYEFBfNbWf7fXdZD2zx
-mw6w666+4J1HMB8GA1UdIwQYMBaAFClNbsfy93Fy2iecnKvaBx1HnNhBMA0GCSqG
-SIb3DQEBBQUAA4GBALQR6Ir1IdGIIp7zBeZHyZ2HEAmhnPE4W6BatPX9jc+uAX20
-qDzd7RezAlZbSuYXWI9G1AKXlQsADrR3Pq3wzgYlOC3/36QOO4Nz96PawaEkaKIY
-cYFOOyZa4hCaJ5WFqDxHOmBJIS8SkPxK8HFNvBkqBgf0NdmNHbKFk2EXRSaa
------END CERTIFICATE-----
diff --git a/org.eclipse.paho.mqtt.c/test/ssl/client.key b/org.eclipse.paho.mqtt.c/test/ssl/client.key
deleted file mode 100644
index 4be1b32..0000000
--- a/org.eclipse.paho.mqtt.c/test/ssl/client.key
+++ /dev/null
@@ -1,15 +0,0 @@
------BEGIN RSA PRIVATE KEY-----
-MIICXAIBAAKBgQDcF4KvR9xxd3PDaRFL/ycOKUvmbxF45FaIyTQTEuGC7CT+Zcid
-uwVUINC0MblLh/hN5cG6mfiizP+OifJ6aC9TQk1zGV7KfrL+O/fRvOgk+ndH7qSJ
-z9Hc6Zk/2g7QHsZA0mDuOINOpN1Go2qsyWGv1SOdIxS1MdXKZnowP8LOWQIDAQAB
-AoGAa+NifoXdfAmwR7QzdGuJO5nmyPjdOcPE35yx2D/DKCiWIdbHNvq8q/bCF/Lg
-ADSQ9a6Q/uYHSdbv13Gr2XFE8MSOCex5cWe7xcQ4jHM9AR4soMxDLXoEqia6QtFg
-RLrVolER/h1QcqJ4pP3QC025JLADXTAvarKAJlkR4nQPigECQQD1xCdxY3mHkl0C
-KSVVjyALKrRHoqIxu2w1qivfTqA/S02Ws5tn6g+lkAEUa7Jg2s1/U2HybRAdGz5v
-fuIW7eOhAkEA5UGrc2z7TyfKIwO5I6aRLFMqwyMKVdO5v4RZlJGBhtGHLEd5nJMw
-ueKLVAUa5/1LaowfLQxYZD+yF8dWdpbvuQJAAbik+hNTR5LL2fcFzuqYs9tRteq6
-rhR89odBlWfMkYTqfzK01O57u5Idn9H9RtZheBHSbss6wKlvL4K4/KYf4QJAZKXk
-A5TA8Atj7uNfkIs8CN2qVGk5zFxbm/0a5uLKnsm2MnZeqaLlLXaL/KMRIPBO/8Ps
-m/Zjh/9+zHmzN/Uj4QJBAPFmzczJDxDviQcEo7qL9J6JAJtijqDAgv9u1XpqIfIx
-GveE+zuKYC2g2Absn1Art3dQgJAsttOF/40HykRLeGc=
------END RSA PRIVATE KEY-----
diff --git a/org.eclipse.paho.mqtt.c/test/ssl/client.pem b/org.eclipse.paho.mqtt.c/test/ssl/client.pem
deleted file mode 100644
index 0f89fde..0000000
--- a/org.eclipse.paho.mqtt.c/test/ssl/client.pem
+++ /dev/null
@@ -1,149 +0,0 @@
-Certificate:
- Data:
- Version: 3 (0x2)
- Serial Number: 2 (0x2)
- Signature Algorithm: sha1WithRSAEncryption
- Issuer: C=GB, ST=Derbyshire, O=Paho Project, OU=Testing, CN=Signing CA
- Validity
- Not Before: Jul 29 19:21:31 2013 GMT
- Not After : Jul 28 19:21:31 2018 GMT
- Subject: C=GB, ST=Nottinghamshire, L=Nottingham, O=Server, OU=Production, CN=test client
- Subject Public Key Info:
- Public Key Algorithm: rsaEncryption
- Public-Key: (1024 bit)
- Modulus:
- 00:dc:17:82:af:47:dc:71:77:73:c3:69:11:4b:ff:
- 27:0e:29:4b:e6:6f:11:78:e4:56:88:c9:34:13:12:
- e1:82:ec:24:fe:65:c8:9d:bb:05:54:20:d0:b4:31:
- b9:4b:87:f8:4d:e5:c1:ba:99:f8:a2:cc:ff:8e:89:
- f2:7a:68:2f:53:42:4d:73:19:5e:ca:7e:b2:fe:3b:
- f7:d1:bc:e8:24:fa:77:47:ee:a4:89:cf:d1:dc:e9:
- 99:3f:da:0e:d0:1e:c6:40:d2:60:ee:38:83:4e:a4:
- dd:46:a3:6a:ac:c9:61:af:d5:23:9d:23:14:b5:31:
- d5:ca:66:7a:30:3f:c2:ce:59
- Exponent: 65537 (0x10001)
- X509v3 extensions:
- X509v3 Basic Constraints:
- CA:FALSE
- Netscape Comment:
- OpenSSL Generated Certificate
- X509v3 Subject Key Identifier:
- 17:CD:6D:67:FB:7D:77:59:0F:6C:F1:9B:0E:B0:EB:AE:BE:E0:9D:47
- X509v3 Authority Key Identifier:
- keyid:29:4D:6E:C7:F2:F7:71:72:DA:27:9C:9C:AB:DA:07:1D:47:9C:D8:41
-
- Signature Algorithm: sha1WithRSAEncryption
- b4:11:e8:8a:f5:21:d1:88:22:9e:f3:05:e6:47:c9:9d:87:10:
- 09:a1:9c:f1:38:5b:a0:5a:b4:f5:fd:8d:cf:ae:01:7d:b4:a8:
- 3c:dd:ed:17:b3:02:56:5b:4a:e6:17:58:8f:46:d4:02:97:95:
- 0b:00:0e:b4:77:3e:ad:f0:ce:06:25:38:2d:ff:df:a4:0e:3b:
- 83:73:f7:a3:da:c1:a1:24:68:a2:18:71:81:4e:3b:26:5a:e2:
- 10:9a:27:95:85:a8:3c:47:3a:60:49:21:2f:12:90:fc:4a:f0:
- 71:4d:bc:19:2a:06:07:f4:35:d9:8d:1d:b2:85:93:61:17:45:
- 26:9a
------BEGIN CERTIFICATE-----
-MIICyTCCAjKgAwIBAgIBAjANBgkqhkiG9w0BAQUFADBgMQswCQYDVQQGEwJHQjET
-MBEGA1UECAwKRGVyYnlzaGlyZTEVMBMGA1UECgwMUGFobyBQcm9qZWN0MRAwDgYD
-VQQLDAdUZXN0aW5nMRMwEQYDVQQDDApTaWduaW5nIENBMB4XDTEzMDcyOTE5MjEz
-MVoXDTE4MDcyODE5MjEzMVoweDELMAkGA1UEBhMCR0IxGDAWBgNVBAgMD05vdHRp
-bmdoYW1zaGlyZTETMBEGA1UEBwwKTm90dGluZ2hhbTEPMA0GA1UECgwGU2VydmVy
-MRMwEQYDVQQLDApQcm9kdWN0aW9uMRQwEgYDVQQDDAt0ZXN0IGNsaWVudDCBnzAN
-BgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEA3BeCr0fccXdzw2kRS/8nDilL5m8ReORW
-iMk0ExLhguwk/mXInbsFVCDQtDG5S4f4TeXBupn4osz/jonyemgvU0JNcxleyn6y
-/jv30bzoJPp3R+6kic/R3OmZP9oO0B7GQNJg7jiDTqTdRqNqrMlhr9UjnSMUtTHV
-ymZ6MD/CzlkCAwEAAaN7MHkwCQYDVR0TBAIwADAsBglghkgBhvhCAQ0EHxYdT3Bl
-blNTTCBHZW5lcmF0ZWQgQ2VydGlmaWNhdGUwHQYDVR0OBBYEFBfNbWf7fXdZD2zx
-mw6w666+4J1HMB8GA1UdIwQYMBaAFClNbsfy93Fy2iecnKvaBx1HnNhBMA0GCSqG
-SIb3DQEBBQUAA4GBALQR6Ir1IdGIIp7zBeZHyZ2HEAmhnPE4W6BatPX9jc+uAX20
-qDzd7RezAlZbSuYXWI9G1AKXlQsADrR3Pq3wzgYlOC3/36QOO4Nz96PawaEkaKIY
-cYFOOyZa4hCaJ5WFqDxHOmBJIS8SkPxK8HFNvBkqBgf0NdmNHbKFk2EXRSaa
------END CERTIFICATE-----
------BEGIN RSA PRIVATE KEY-----
-MIICXAIBAAKBgQDcF4KvR9xxd3PDaRFL/ycOKUvmbxF45FaIyTQTEuGC7CT+Zcid
-uwVUINC0MblLh/hN5cG6mfiizP+OifJ6aC9TQk1zGV7KfrL+O/fRvOgk+ndH7qSJ
-z9Hc6Zk/2g7QHsZA0mDuOINOpN1Go2qsyWGv1SOdIxS1MdXKZnowP8LOWQIDAQAB
-AoGAa+NifoXdfAmwR7QzdGuJO5nmyPjdOcPE35yx2D/DKCiWIdbHNvq8q/bCF/Lg
-ADSQ9a6Q/uYHSdbv13Gr2XFE8MSOCex5cWe7xcQ4jHM9AR4soMxDLXoEqia6QtFg
-RLrVolER/h1QcqJ4pP3QC025JLADXTAvarKAJlkR4nQPigECQQD1xCdxY3mHkl0C
-KSVVjyALKrRHoqIxu2w1qivfTqA/S02Ws5tn6g+lkAEUa7Jg2s1/U2HybRAdGz5v
-fuIW7eOhAkEA5UGrc2z7TyfKIwO5I6aRLFMqwyMKVdO5v4RZlJGBhtGHLEd5nJMw
-ueKLVAUa5/1LaowfLQxYZD+yF8dWdpbvuQJAAbik+hNTR5LL2fcFzuqYs9tRteq6
-rhR89odBlWfMkYTqfzK01O57u5Idn9H9RtZheBHSbss6wKlvL4K4/KYf4QJAZKXk
-A5TA8Atj7uNfkIs8CN2qVGk5zFxbm/0a5uLKnsm2MnZeqaLlLXaL/KMRIPBO/8Ps
-m/Zjh/9+zHmzN/Uj4QJBAPFmzczJDxDviQcEo7qL9J6JAJtijqDAgv9u1XpqIfIx
-GveE+zuKYC2g2Absn1Art3dQgJAsttOF/40HykRLeGc=
------END RSA PRIVATE KEY-----
-Certificate:
- Data:
- Version: 3 (0x2)
- Serial Number: 1 (0x1)
- Signature Algorithm: sha1WithRSAEncryption
- Issuer: C=GB, ST=Derbyshire, L=Derby, O=Paho Project, OU=Testing, CN=Root CA
- Validity
- Not Before: Jul 29 19:21:30 2013 GMT
- Not After : Jul 28 19:21:30 2018 GMT
- Subject: C=GB, ST=Derbyshire, O=Paho Project, OU=Testing, CN=Signing CA
- Subject Public Key Info:
- Public Key Algorithm: rsaEncryption
- Public-Key: (1024 bit)
- Modulus:
- 00:dc:26:78:40:ae:b2:ad:2f:26:12:0a:d5:b1:18:
- 80:16:d8:88:be:0b:42:ce:32:ad:12:d5:f5:78:1b:
- 35:28:f2:13:1b:05:09:fb:7e:d7:d9:a1:8a:0d:4a:
- fe:95:37:d4:16:75:83:e4:6a:44:34:33:57:2e:49:
- ba:bc:b4:cf:d0:c0:87:e0:bc:f0:60:76:14:00:d6:
- eb:cb:f6:db:b3:43:f1:c8:4d:4a:0a:bb:e0:37:7c:
- 8e:93:1f:a0:87:68:59:fe:0c:25:40:f3:7c:fd:71:
- 90:55:ef:de:18:b4:08:86:c9:75:c2:99:2f:ce:12:
- bf:c5:5e:cf:5f:f1:06:53:07
- Exponent: 65537 (0x10001)
- X509v3 extensions:
- X509v3 Subject Key Identifier:
- 29:4D:6E:C7:F2:F7:71:72:DA:27:9C:9C:AB:DA:07:1D:47:9C:D8:41
- X509v3 Authority Key Identifier:
- keyid:4A:2B:69:D6:31:1D:A3:68:E8:46:6F:FB:4B:F3:8E:B6:8D:51:0E:BF
-
- X509v3 Basic Constraints:
- CA:TRUE
- Signature Algorithm: sha1WithRSAEncryption
- 48:ec:d7:80:8a:8f:82:a6:42:b1:89:2c:b9:4b:6d:0a:37:b8:
- 72:19:05:de:75:80:0c:d6:41:97:b2:d7:fe:99:cb:7e:c4:0e:
- 77:97:09:a8:9f:87:ff:0b:de:3f:1c:dc:1e:fe:09:36:a7:f5:
- 54:9a:85:4e:fb:6f:27:fe:0f:29:45:61:8d:07:c6:0c:da:37:
- 3d:a3:69:4b:82:71:e6:24:e0:87:a6:ee:d5:87:61:dd:8f:08:
- fe:33:a6:1f:ae:b2:ae:1f:d8:2c:20:c8:a6:fc:33:0e:82:68:
- 80:23:61:10:ad:5c:1d:80:d6:b1:5f:e4:af:66:6d:63:10:e4:
- 96:e4
------BEGIN CERTIFICATE-----
-MIICkzCCAfygAwIBAgIBATANBgkqhkiG9w0BAQUFADBtMQswCQYDVQQGEwJHQjET
-MBEGA1UECAwKRGVyYnlzaGlyZTEOMAwGA1UEBwwFRGVyYnkxFTATBgNVBAoMDFBh
-aG8gUHJvamVjdDEQMA4GA1UECwwHVGVzdGluZzEQMA4GA1UEAwwHUm9vdCBDQTAe
-Fw0xMzA3MjkxOTIxMzBaFw0xODA3MjgxOTIxMzBaMGAxCzAJBgNVBAYTAkdCMRMw
-EQYDVQQIDApEZXJieXNoaXJlMRUwEwYDVQQKDAxQYWhvIFByb2plY3QxEDAOBgNV
-BAsMB1Rlc3RpbmcxEzARBgNVBAMMClNpZ25pbmcgQ0EwgZ8wDQYJKoZIhvcNAQEB
-BQADgY0AMIGJAoGBANwmeECusq0vJhIK1bEYgBbYiL4LQs4yrRLV9XgbNSjyExsF
-Cft+19mhig1K/pU31BZ1g+RqRDQzVy5Jury0z9DAh+C88GB2FADW68v227ND8chN
-Sgq74Dd8jpMfoIdoWf4MJUDzfP1xkFXv3hi0CIbJdcKZL84Sv8Vez1/xBlMHAgMB
-AAGjUDBOMB0GA1UdDgQWBBQpTW7H8vdxctonnJyr2gcdR5zYQTAfBgNVHSMEGDAW
-gBRKK2nWMR2jaOhGb/tL8462jVEOvzAMBgNVHRMEBTADAQH/MA0GCSqGSIb3DQEB
-BQUAA4GBAEjs14CKj4KmQrGJLLlLbQo3uHIZBd51gAzWQZey1/6Zy37EDneXCaif
-h/8L3j8c3B7+CTan9VSahU77byf+DylFYY0HxgzaNz2jaUuCceYk4Iem7tWHYd2P
-CP4zph+usq4f2CwgyKb8Mw6CaIAjYRCtXB2A1rFf5K9mbWMQ5Jbk
------END CERTIFICATE-----
------BEGIN CERTIFICATE-----
-MIICqDCCAhGgAwIBAgIJAKrzwmdXIUxsMA0GCSqGSIb3DQEBBQUAMG0xCzAJBgNV
-BAYTAkdCMRMwEQYDVQQIDApEZXJieXNoaXJlMQ4wDAYDVQQHDAVEZXJieTEVMBMG
-A1UECgwMUGFobyBQcm9qZWN0MRAwDgYDVQQLDAdUZXN0aW5nMRAwDgYDVQQDDAdS
-b290IENBMB4XDTEzMDcyOTE5MjEyOVoXDTIzMDcyNzE5MjEyOVowbTELMAkGA1UE
-BhMCR0IxEzARBgNVBAgMCkRlcmJ5c2hpcmUxDjAMBgNVBAcMBURlcmJ5MRUwEwYD
-VQQKDAxQYWhvIFByb2plY3QxEDAOBgNVBAsMB1Rlc3RpbmcxEDAOBgNVBAMMB1Jv
-b3QgQ0EwgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBAKbPzEEWCKsjjwjJ787u
-Q32k5EdqoDddMEjSVbZNSNEwUew1L7O8NTbmtCEeVFQjOLAdmdiF3rQbXHV+Zew0
-jt2g4vtPpl1GOG6jA/6YznKAyQdvGCdYfGZUN2tN+mbtVxWqkHZitQDQGaSHnx24
-NX649La2uyFy+7l9o8++xPONAgMBAAGjUDBOMB0GA1UdDgQWBBRKK2nWMR2jaOhG
-b/tL8462jVEOvzAfBgNVHSMEGDAWgBRKK2nWMR2jaOhGb/tL8462jVEOvzAMBgNV
-HRMEBTADAQH/MA0GCSqGSIb3DQEBBQUAA4GBAEd+gW86/W+fisz5PFHAeEw7zn9q
-dzLHm7+QZgNLZ9h7/ZbhObRUFMRtU2xm4amyh85h7hUE5R2E2uW2OXumic7/D4ZD
-6unjr4m5jwVWDTqTUYIcNSriyoDWAVlPfOWaU5NyUhqS1DM28tvOWVHVLCxmVcZl
-tJQqo5eHbQ/+Hjfx
------END CERTIFICATE-----
diff --git a/org.eclipse.paho.mqtt.c/test/ssl/gen.sh b/org.eclipse.paho.mqtt.c/test/ssl/gen.sh
deleted file mode 100644
index dec4743..0000000
--- a/org.eclipse.paho.mqtt.c/test/ssl/gen.sh
+++ /dev/null
@@ -1,72 +0,0 @@
-# This file generates the keys and certificates used for testing mosquitto.
-# None of the keys are encrypted, so do not just use this script to generate
-# files for your own use.
-
-rm -f *.crt *.key *.csr
-for a in root signing; do
- rm -rf ${a}CA/
- mkdir -p ${a}CA/newcerts
- touch ${a}CA/index.txt
- echo 01 > ${a}CA/serial
- echo 01 > ${a}CA/crlnumber
-done
-rm -rf certs
-
-BASESUBJ="/C=GB/ST=Derbyshire/L=Derby/O=Mosquitto Project/OU=Testing"
-SBASESUBJ="/C=GB/ST=Nottinghamshire/L=Nottingham/O=Server/OU=Production"
-BBASESUBJ="/C=GB/ST=Nottinghamshire/L=Nottingham/O=Server/OU=Bridge"
-
-# The root CA
-openssl genrsa -out test-root-ca.key 1024
-openssl req -new -x509 -days 3650 -key test-root-ca.key -out test-root-ca.crt -config openssl.cnf -subj "${BASESUBJ}/CN=Root CA/"
-
-# Another root CA that doesn't sign anything
-openssl genrsa -out test-bad-root-ca.key 1024
-openssl req -new -x509 -days 3650 -key test-bad-root-ca.key -out test-bad-root-ca.crt -config openssl.cnf -subj "${BASESUBJ}/CN=Bad Root CA/"
-
-# This is a root CA that has the exact same details as the real root CA, but is a different key and certificate. Effectively a "fake" CA.
-openssl genrsa -out test-fake-root-ca.key 1024
-openssl req -new -x509 -days 3650 -key test-fake-root-ca.key -out test-fake-root-ca.crt -config openssl.cnf -subj "${BASESUBJ}/CN=Root CA/"
-
-# An intermediate CA, signed by the root CA, used to sign server/client csrs.
-openssl genrsa -out test-signing-ca.key 1024
-openssl req -out test-signing-ca.csr -key test-signing-ca.key -new -config openssl.cnf -subj "${BASESUBJ}/CN=Signing CA/"
-openssl ca -config openssl.cnf -name CA_root -extensions v3_ca -out test-signing-ca.crt -infiles test-signing-ca.csr
-
-# An alternative intermediate CA, signed by the root CA, not used to sign anything.
-openssl genrsa -out test-alt-ca.key 1024
-openssl req -out test-alt-ca.csr -key test-alt-ca.key -new -config openssl.cnf -subj "${BASESUBJ}/CN=Alternative Signing CA/"
-openssl ca -config openssl.cnf -name CA_root -extensions v3_ca -out test-alt-ca.crt -infiles test-alt-ca.csr
-
-# Valid server key and certificate.
-openssl genrsa -out server.key 1024
-openssl req -new -key server.key -out server.csr -config openssl.cnf -subj "${SBASESUBJ}/CN=localhost/"
-openssl ca -config openssl.cnf -name CA_signing -out server.crt -infiles server.csr
-
-# Expired server certificate, based on the above server key.
-openssl req -new -days 1 -key server.key -out server-expired.csr -config openssl.cnf -subj "${SBASESUBJ}/CN=localhost/"
-openssl ca -config openssl.cnf -name CA_signing -days 1 -startdate 120820000000Z -enddate 120821000000Z -out server-expired.crt -infiles server-expired.csr
-
-# Valid client key and certificate.
-openssl genrsa -out client.key 1024
-openssl req -new -key client.key -out client.csr -config openssl.cnf -subj "${SBASESUBJ}/CN=test client/"
-openssl ca -config openssl.cnf -name CA_signing -out client.crt -infiles client.csr
-
-# Expired client certificate, based on the above client key.
-openssl req -new -days 1 -key client.key -out client-expired.csr -config openssl.cnf -subj "${SBASESUBJ}/CN=test client expired/"
-openssl ca -config openssl.cnf -name CA_signing -days 1 -startdate 120820000000Z -enddate 120821000000Z -out client-expired.crt -infiles client-expired.csr
-
-# Revoked client certificate, based on a new client key.
-openssl genrsa -out client-revoked.key 1024
-openssl req -new -days 1 -key client-revoked.key -out client-revoked.csr -config openssl.cnf -subj "${SBASESUBJ}/CN=test client revoked/"
-openssl ca -config openssl.cnf -name CA_signing -out client-revoked.crt -infiles client-revoked.csr
-openssl ca -config openssl.cnf -name CA_signing -revoke client-revoked.crt
-openssl ca -config openssl.cnf -name CA_signing -gencrl -out crl.pem
-
-cat test-signing-ca.crt test-root-ca.crt > all-ca.crt
-
-cat client.crt client.key all-ca.crt > client.pem
-#mkdir certs
-#cp test-signing-ca.crt certs/test-signing-ca.pem
-#cp test-root-ca.crt certs/test-root.ca.pem
-c_rehash certs
diff --git a/org.eclipse.paho.mqtt.c/test/ssl/mosquitto.conf b/org.eclipse.paho.mqtt.c/test/ssl/mosquitto.conf
deleted file mode 100644
index a70959e..0000000
--- a/org.eclipse.paho.mqtt.c/test/ssl/mosquitto.conf
+++ /dev/null
@@ -1,40 +0,0 @@
-log_type error
-log_type warning
-log_type notice
-log_type information
-log_type debug
-
-allow_anonymous true
-
-# non-SSL listener
-listener 18883
-
-# listener for mutual authentication
-listener 18884
-cafile /etc/mosquitto/tls-testing/keys/all-ca.crt
-certfile /etc/mosquitto/tls-testing/keys/server/server.crt
-keyfile /etc/mosquitto/tls-testing/keys/server/server.key
-require_certificate true
-
-# server authentication - no client authentication
-listener 18885
-cafile /etc/mosquitto/tls-testing/keys/all-ca.crt
-certfile /etc/mosquitto/tls-testing/keys/server/server.crt
-keyfile /etc/mosquitto/tls-testing/keys/server/server.key
-require_certificate false
-
-listener 18886
-cafile /etc/mosquitto/tls-testing/keys/all-ca.crt
-certfile /etc/mosquitto/tls-testing/keys/server/server.crt
-keyfile /etc/mosquitto/tls-testing/keys/server/server.key
-require_certificate false
-ciphers ADH-DES-CBC-SHA
-
-# server authentication - no client authentication - uses fake hostname to
-# simulate mitm attack. Clients should refuse to connect to this listener.
-listener 18887
-cafile /etc/mosquitto/tls-testing/keys/all-ca.crt
-certfile /etc/mosquitto/tls-testing/keys/server/server-mitm.crt
-keyfile /etc/mosquitto/tls-testing/keys/server/server-mitm.key
-require_certificate false
-
diff --git a/org.eclipse.paho.mqtt.c/test/ssl/openssl.cnf b/org.eclipse.paho.mqtt.c/test/ssl/openssl.cnf
deleted file mode 100644
index e0cff18..0000000
--- a/org.eclipse.paho.mqtt.c/test/ssl/openssl.cnf
+++ /dev/null
@@ -1,406 +0,0 @@
-#
-# OpenSSL example configuration file.
-# This is mostly being used for generation of certificate requests.
-#
-
-# This definition stops the following lines choking if HOME isn't
-# defined.
-HOME = .
-RANDFILE = $ENV::HOME/.rnd
-
-# Extra OBJECT IDENTIFIER info:
-#oid_file = $ENV::HOME/.oid
-oid_section = new_oids
-
-# To use this configuration file with the "-extfile" option of the
-# "openssl x509" utility, name here the section containing the
-# X.509v3 extensions to use:
-# extensions =
-# (Alternatively, use a configuration file that has only
-# X.509v3 extensions in its main [= default] section.)
-
-[ new_oids ]
-
-# We can add new OIDs in here for use by 'ca', 'req' and 'ts'.
-# Add a simple OID like this:
-# testoid1=1.2.3.4
-# Or use config file substitution like this:
-# testoid2=${testoid1}.5.6
-
-# Policies used by the TSA examples.
-tsa_policy1 = 1.2.3.4.1
-tsa_policy2 = 1.2.3.4.5.6
-tsa_policy3 = 1.2.3.4.5.7
-
-####################################################################
-[ ca ]
-default_ca = CA_default # The default ca section
-
-####################################################################
-[ CA_signing ]
-
-dir = ./signingCA # Where everything is kept
-certs = $dir/certs # Where the issued certs are kept
-crl_dir = $dir/crl # Where the issued crl are kept
-database = $dir/index.txt # database index file.
-#unique_subject = no # Set to 'no' to allow creation of
- # several ctificates with same subject.
-new_certs_dir = $dir/newcerts # default place for new certs.
-
-certificate = test-signing-ca.crt # The CA certificate
-serial = $dir/serial # The current serial number
-crlnumber = $dir/crlnumber # the current crl number
- # must be commented out to leave a V1 CRL
-crl = $dir/crl.pem # The current CRL
-private_key = test-signing-ca.key # The private key
-RANDFILE = $dir/.rand # private random number file
-
-x509_extensions = usr_cert # The extentions to add to the cert
-
-# Comment out the following two lines for the "traditional"
-# (and highly broken) format.
-name_opt = ca_default # Subject Name options
-cert_opt = ca_default # Certificate field options
-
-# Extension copying option: use with caution.
-# copy_extensions = copy
-
-# Extensions to add to a CRL. Note: Netscape communicator chokes on V2 CRLs
-# so this is commented out by default to leave a V1 CRL.
-# crlnumber must also be commented out to leave a V1 CRL.
-# crl_extensions = crl_ext
-
-default_days = 1825 # how long to certify for
-default_crl_days= 30 # how long before next CRL
-default_md = default # use public key default MD
-preserve = no # keep passed DN ordering
-
-# A few difference way of specifying how similar the request should look
-# For type CA, the listed attributes must be the same, and the optional
-# and supplied fields are just that :-)
-policy = policy_anything
-
-[ CA_inter ]
-dir = ./interCA
-certs = $dir/certs
-crl_dir = $dir/crl
-database = $dir/index.txt
-new_certs_dir = $dir/newcerts
-
-certificate = test-inter-ca.crt
-serial = $dir/serial
-crlnumber = $dir/crlnumber
-crl = $dir/crl.pem
-private_key = test-inter-ca.key
-RANDFILE = $dir/.rand
-
-#x509_extensions = v3_ca
-x509_extensions = usr_cert
-
-name_opt = ca_default
-cert_opt = ca_default
-
-default_days = 1825
-default_crl_days = 30
-default_md = default
-preserve = no
-
-policy = policy_match
-unique_subject = yes
-
-[ CA_root ]
-dir = ./rootCA
-certs = $dir/certs
-crl_dir = $dir/crl
-database = $dir/index.txt
-new_certs_dir = $dir/newcerts
-
-certificate = test-root-ca.crt
-serial = $dir/serial
-crlnumber = $dir/crlnumber
-crl = $dir/crl.pem
-private_key = test-root-ca.key
-RANDFILE = $dir/.rand
-
-x509_extensions = v3_ca
-
-name_opt = ca_default
-cert_opt = ca_default
-
-default_days = 1825
-default_crl_days = 30
-default_md = default
-preserve = no
-
-policy = policy_match
-unique_subject = yes
-
-# For the CA policy
-[ policy_match ]
-countryName = match
-stateOrProvinceName = match
-organizationName = match
-organizationalUnitName = optional
-commonName = supplied
-emailAddress = optional
-
-# For the 'anything' policy
-# At this point in time, you must list all acceptable 'object'
-# types.
-[ policy_anything ]
-countryName = optional
-stateOrProvinceName = optional
-localityName = optional
-organizationName = optional
-organizationalUnitName = optional
-commonName = supplied
-emailAddress = optional
-
-####################################################################
-[ req ]
-default_bits = 2048
-default_keyfile = privkey.pem
-distinguished_name = req_distinguished_name
-attributes = req_attributes
-x509_extensions = v3_ca # The extentions to add to the self signed cert
-
-# Passwords for private keys if not present they will be prompted for
-# input_password = secret
-# output_password = secret
-
-# This sets a mask for permitted string types. There are several options.
-# default: PrintableString, T61String, BMPString.
-# pkix : PrintableString, BMPString (PKIX recommendation before 2004)
-# utf8only: only UTF8Strings (PKIX recommendation after 2004).
-# nombstr : PrintableString, T61String (no BMPStrings or UTF8Strings).
-# MASK:XXXX a literal mask value.
-# WARNING: ancient versions of Netscape crash on BMPStrings or UTF8Strings.
-string_mask = utf8only
-
-# req_extensions = v3_req # The extensions to add to a certificate request
-
-[ req_distinguished_name ]
-countryName = Country Name (2 letter code)
-countryName_default = GB
-countryName_min = 2
-countryName_max = 2
-
-stateOrProvinceName = State or Province Name (full name)
-stateOrProvinceName_default = Derbyshire
-
-localityName = Locality Name (eg, city)
-localityName_default = Derby
-
-0.organizationName = Organization Name (eg, company)
-0.organizationName_default = Mosquitto Project
-
-# we can do this but it is not needed normally :-)
-#1.organizationName = Second Organization Name (eg, company)
-#1.organizationName_default = World Wide Web Pty Ltd
-
-organizationalUnitName = Organizational Unit Name (eg, section)
-organizationalUnitName_default = Testing
-
-commonName = Common Name (e.g. server FQDN or YOUR name)
-commonName_max = 64
-
-emailAddress = Email Address
-emailAddress_max = 64
-
-# SET-ex3 = SET extension number 3
-
-[ req_attributes ]
-challengePassword = A challenge password
-challengePassword_min = 4
-challengePassword_max = 20
-
-unstructuredName = An optional company name
-
-[ usr_cert ]
-
-# These extensions are added when 'ca' signs a request.
-
-# This goes against PKIX guidelines but some CAs do it and some software
-# requires this to avoid interpreting an end user certificate as a CA.
-
-basicConstraints=CA:FALSE
-
-# Here are some examples of the usage of nsCertType. If it is omitted
-# the certificate can be used for anything *except* object signing.
-
-# This is OK for an SSL server.
-# nsCertType = server
-
-# For an object signing certificate this would be used.
-# nsCertType = objsign
-
-# For normal client use this is typical
-# nsCertType = client, email
-
-# and for everything including object signing:
-# nsCertType = client, email, objsign
-
-# This is typical in keyUsage for a client certificate.
-# keyUsage = nonRepudiation, digitalSignature, keyEncipherment
-
-# This will be displayed in Netscape's comment listbox.
-nsComment = "OpenSSL Generated Certificate"
-
-# PKIX recommendations harmless if included in all certificates.
-subjectKeyIdentifier=hash
-authorityKeyIdentifier=keyid,issuer
-
-# This stuff is for subjectAltName and issuerAltname.
-# Import the email address.
-# subjectAltName=email:copy
-# An alternative to produce certificates that aren't
-# deprecated according to PKIX.
-# subjectAltName=email:move
-
-# Copy subject details
-# issuerAltName=issuer:copy
-
-#nsCaRevocationUrl = http://www.domain.dom/ca-crl.pem
-#nsBaseUrl
-#nsRevocationUrl
-#nsRenewalUrl
-#nsCaPolicyUrl
-#nsSslServerName
-
-# This is required for TSA certificates.
-# extendedKeyUsage = critical,timeStamping
-
-[ v3_req ]
-
-# Extensions to add to a certificate request
-
-basicConstraints = CA:FALSE
-keyUsage = nonRepudiation, digitalSignature, keyEncipherment
-
-[ v3_ca ]
-
-
-# Extensions for a typical CA
-
-
-# PKIX recommendation.
-
-subjectKeyIdentifier=hash
-
-authorityKeyIdentifier=keyid:always,issuer
-
-# This is what PKIX recommends but some broken software chokes on critical
-# extensions.
-#basicConstraints = critical,CA:true
-# So we do this instead.
-basicConstraints = CA:true
-
-# Key usage: this is typical for a CA certificate. However since it will
-# prevent it being used as an test self-signed certificate it is best
-# left out by default.
-# keyUsage = cRLSign, keyCertSign
-
-# Some might want this also
-# nsCertType = sslCA, emailCA
-
-# Include email address in subject alt name: another PKIX recommendation
-# subjectAltName=email:copy
-# Copy issuer details
-# issuerAltName=issuer:copy
-
-# DER hex encoding of an extension: beware experts only!
-# obj=DER:02:03
-# Where 'obj' is a standard or added object
-# You can even override a supported extension:
-# basicConstraints= critical, DER:30:03:01:01:FF
-
-[ crl_ext ]
-
-# CRL extensions.
-# Only issuerAltName and authorityKeyIdentifier make any sense in a CRL.
-
-# issuerAltName=issuer:copy
-authorityKeyIdentifier=keyid:always
-
-[ proxy_cert_ext ]
-# These extensions should be added when creating a proxy certificate
-
-# This goes against PKIX guidelines but some CAs do it and some software
-# requires this to avoid interpreting an end user certificate as a CA.
-
-basicConstraints=CA:FALSE
-
-# Here are some examples of the usage of nsCertType. If it is omitted
-# the certificate can be used for anything *except* object signing.
-
-# This is OK for an SSL server.
-# nsCertType = server
-
-# For an object signing certificate this would be used.
-# nsCertType = objsign
-
-# For normal client use this is typical
-# nsCertType = client, email
-
-# and for everything including object signing:
-# nsCertType = client, email, objsign
-
-# This is typical in keyUsage for a client certificate.
-# keyUsage = nonRepudiation, digitalSignature, keyEncipherment
-
-# This will be displayed in Netscape's comment listbox.
-nsComment = "OpenSSL Generated Certificate"
-
-# PKIX recommendations harmless if included in all certificates.
-subjectKeyIdentifier=hash
-authorityKeyIdentifier=keyid,issuer
-
-# This stuff is for subjectAltName and issuerAltname.
-# Import the email address.
-# subjectAltName=email:copy
-# An alternative to produce certificates that aren't
-# deprecated according to PKIX.
-# subjectAltName=email:move
-
-# Copy subject details
-# issuerAltName=issuer:copy
-
-#nsCaRevocationUrl = http://www.domain.dom/ca-crl.pem
-#nsBaseUrl
-#nsRevocationUrl
-#nsRenewalUrl
-#nsCaPolicyUrl
-#nsSslServerName
-
-# This really needs to be in place for it to be a proxy certificate.
-proxyCertInfo=critical,language:id-ppl-anyLanguage,pathlen:3,policy:foo
-
-####################################################################
-[ tsa ]
-
-default_tsa = tsa_config1 # the default TSA section
-
-[ tsa_config1 ]
-
-# These are used by the TSA reply generation only.
-dir = ./demoCA # TSA root directory
-serial = $dir/tsaserial # The current serial number (mandatory)
-crypto_device = builtin # OpenSSL engine to use for signing
-signer_cert = $dir/tsacert.pem # The TSA signing certificate
- # (optional)
-certs = $dir/cacert.pem # Certificate chain to include in reply
- # (optional)
-signer_key = $dir/private/tsakey.pem # The TSA private key (optional)
-
-default_policy = tsa_policy1 # Policy if request did not specify it
- # (optional)
-other_policies = tsa_policy2, tsa_policy3 # acceptable policies (optional)
-digests = md5, sha1 # Acceptable message digests (mandatory)
-accuracy = secs:1, millisecs:500, microsecs:100 # (optional)
-clock_precision_digits = 0 # number of digits after dot. (optional)
-ordering = yes # Is ordering defined for timestamps?
- # (optional, default: no)
-tsa_name = yes # Must the TSA name be included in the reply?
- # (optional, default: no)
-ess_cert_id_chain = no # Must the ESS cert id chain be included?
- # (optional, default: no)
diff --git a/org.eclipse.paho.mqtt.c/test/ssl/server-expired.crt b/org.eclipse.paho.mqtt.c/test/ssl/server-expired.crt
deleted file mode 100644
index e69de29..0000000
diff --git a/org.eclipse.paho.mqtt.c/test/ssl/server.crt b/org.eclipse.paho.mqtt.c/test/ssl/server.crt
deleted file mode 100644
index b0941b9..0000000
--- a/org.eclipse.paho.mqtt.c/test/ssl/server.crt
+++ /dev/null
@@ -1,60 +0,0 @@
-Certificate:
- Data:
- Version: 3 (0x2)
- Serial Number: 1 (0x1)
- Signature Algorithm: sha1WithRSAEncryption
- Issuer: C=GB, ST=Derbyshire, O=Paho Project, OU=Testing, CN=Signing CA
- Validity
- Not Before: Jul 29 19:21:30 2013 GMT
- Not After : Jul 28 19:21:30 2018 GMT
- Subject: C=GB, ST=Nottinghamshire, L=Nottingham, O=Server, OU=Production, CN=localhost
- Subject Public Key Info:
- Public Key Algorithm: rsaEncryption
- Public-Key: (1024 bit)
- Modulus:
- 00:be:b7:65:98:5e:e1:e0:68:e7:14:04:e5:40:2d:
- d3:b4:f2:b2:dd:6e:5c:97:7a:5b:c5:4f:7a:45:11:
- 99:4e:56:30:c6:d6:50:29:88:c3:31:6d:b0:f1:a8:
- 5f:f5:fd:cc:d1:52:0f:40:70:04:cc:14:0d:98:45:
- 62:a8:f9:88:0a:be:20:32:53:c5:48:fb:b0:e4:25:
- db:25:ec:0d:c4:6a:28:dc:af:d7:2d:63:99:b9:f4:
- c0:32:54:dc:be:4d:9f:7f:67:7e:2a:be:82:2d:de:
- 37:35:0b:0d:7b:b8:9c:55:ff:cf:ab:fe:61:e9:8c:
- bf:c4:27:e2:56:2f:1a:73:87
- Exponent: 65537 (0x10001)
- X509v3 extensions:
- X509v3 Basic Constraints:
- CA:FALSE
- Netscape Comment:
- OpenSSL Generated Certificate
- X509v3 Subject Key Identifier:
- A1:8C:9A:D1:28:58:68:C5:46:5B:FA:C5:48:01:96:67:55:97:65:8A
- X509v3 Authority Key Identifier:
- keyid:29:4D:6E:C7:F2:F7:71:72:DA:27:9C:9C:AB:DA:07:1D:47:9C:D8:41
-
- Signature Algorithm: sha1WithRSAEncryption
- 78:f6:a1:34:ac:2c:a5:0a:1d:82:97:97:1f:f5:03:44:a7:c0:
- 4d:e8:8d:67:e7:71:50:30:3c:8b:77:eb:81:96:78:6b:ab:31:
- 5a:ba:7b:1c:ad:ec:fd:a6:5d:73:ef:99:2d:6f:9f:7e:13:ac:
- b2:61:2f:e4:56:cc:28:f1:e4:7f:ea:a9:b2:f2:85:87:68:52:
- 65:b0:42:54:84:92:2f:fb:45:d4:36:e2:3c:0e:4c:a6:6d:82:
- 8f:72:c0:66:0c:5f:b2:a7:7c:9b:be:cd:19:55:5d:40:27:99:
- 14:e2:cf:59:cb:4b:40:e4:98:2d:f7:93:14:4a:50:dc:75:9c:
- 5c:9d
------BEGIN CERTIFICATE-----
-MIICxzCCAjCgAwIBAgIBATANBgkqhkiG9w0BAQUFADBgMQswCQYDVQQGEwJHQjET
-MBEGA1UECAwKRGVyYnlzaGlyZTEVMBMGA1UECgwMUGFobyBQcm9qZWN0MRAwDgYD
-VQQLDAdUZXN0aW5nMRMwEQYDVQQDDApTaWduaW5nIENBMB4XDTEzMDcyOTE5MjEz
-MFoXDTE4MDcyODE5MjEzMFowdjELMAkGA1UEBhMCR0IxGDAWBgNVBAgMD05vdHRp
-bmdoYW1zaGlyZTETMBEGA1UEBwwKTm90dGluZ2hhbTEPMA0GA1UECgwGU2VydmVy
-MRMwEQYDVQQLDApQcm9kdWN0aW9uMRIwEAYDVQQDDAlsb2NhbGhvc3QwgZ8wDQYJ
-KoZIhvcNAQEBBQADgY0AMIGJAoGBAL63ZZhe4eBo5xQE5UAt07Tyst1uXJd6W8VP
-ekURmU5WMMbWUCmIwzFtsPGoX/X9zNFSD0BwBMwUDZhFYqj5iAq+IDJTxUj7sOQl
-2yXsDcRqKNyv1y1jmbn0wDJU3L5Nn39nfiq+gi3eNzULDXu4nFX/z6v+YemMv8Qn
-4lYvGnOHAgMBAAGjezB5MAkGA1UdEwQCMAAwLAYJYIZIAYb4QgENBB8WHU9wZW5T
-U0wgR2VuZXJhdGVkIENlcnRpZmljYXRlMB0GA1UdDgQWBBShjJrRKFhoxUZb+sVI
-AZZnVZdlijAfBgNVHSMEGDAWgBQpTW7H8vdxctonnJyr2gcdR5zYQTANBgkqhkiG
-9w0BAQUFAAOBgQB49qE0rCylCh2Cl5cf9QNEp8BN6I1n53FQMDyLd+uBlnhrqzFa
-unscrez9pl1z75ktb59+E6yyYS/kVswo8eR/6qmy8oWHaFJlsEJUhJIv+0XUNuI8
-DkymbYKPcsBmDF+yp3ybvs0ZVV1AJ5kU4s9Zy0tA5Jgt95MUSlDcdZxcnQ==
------END CERTIFICATE-----
diff --git a/org.eclipse.paho.mqtt.c/test/ssl/server.key b/org.eclipse.paho.mqtt.c/test/ssl/server.key
deleted file mode 100644
index bbf5c60..0000000
--- a/org.eclipse.paho.mqtt.c/test/ssl/server.key
+++ /dev/null
@@ -1,15 +0,0 @@
------BEGIN RSA PRIVATE KEY-----
-MIICWwIBAAKBgQC+t2WYXuHgaOcUBOVALdO08rLdblyXelvFT3pFEZlOVjDG1lAp
-iMMxbbDxqF/1/czRUg9AcATMFA2YRWKo+YgKviAyU8VI+7DkJdsl7A3Eaijcr9ct
-Y5m59MAyVNy+TZ9/Z34qvoIt3jc1Cw17uJxV/8+r/mHpjL/EJ+JWLxpzhwIDAQAB
-AoGAW1dC1UM8M1qKsc/WbHKGXreOavccaYA0y79Q9BuFrTsiiVjDc+EIe3fpsxPN
-QeeYXPhMTbRY19US3cb9hahdOtPZc1zKRoloWl995v6X5XufTmgigBRUrRKG6rln
-wok6PYwKQmcG+yVaOjPwiJBx+4gfGjD6qO/fhK2sWWtyneECQQDrUEiaWvQE0uli
-EI34MhO3As0iYyw1qFHVck4bbFS4RT0gnhWYVeabd5mTKx1ztLlr0ykwaCf9FoMG
-U2liyV/VAkEAz3t0v8vZrlpotW9CRzBQ63vYW3+d8m5Hmkvsghrfem52je6MN0oL
-2Y7F3JrJh1bC9ZNgtkBF/mIQgv9jGBoP6wJASKTYRQ6fFn4mHmgN6/lJrM3olh0X
-oNj9qm9HPaAL53c4j8E92XFrZ8NcXdqJlRbNx0PBC3icH727ZVCK0DxqoQJABTRn
-nVgTwdfqwIJl+zsvDHky2Di/UZGKokg9SpY5/OxAdRcC1XA6E98M/5eybn6yrU5h
-IrFCEDuNhnu5lKUyuQJAAiNPFWPkl4XeghyzPDA1lUYMwKPr7oEwELqS8fIq/g4K
-BI10X7qlpioI4I6jA9lwlIdtR+q620UFZRlQts9nug==
------END RSA PRIVATE KEY-----
diff --git a/org.eclipse.paho.mqtt.c/test/ssl/server.pem b/org.eclipse.paho.mqtt.c/test/ssl/server.pem
deleted file mode 100644
index 3436f12..0000000
--- a/org.eclipse.paho.mqtt.c/test/ssl/server.pem
+++ /dev/null
@@ -1,117 +0,0 @@
-Certificate:
- Data:
- Version: 3 (0x2)
- Serial Number: 1 (0x1)
- Signature Algorithm: sha1WithRSAEncryption
- Issuer: C=GB, ST=Derbyshire, O=Paho Project, OU=Testing, CN=Signing CA
- Validity
- Not Before: Jul 29 19:21:30 2013 GMT
- Not After : Jul 28 19:21:30 2018 GMT
- Subject: C=GB, ST=Nottinghamshire, L=Nottingham, O=Server, OU=Production, CN=localhost
- Subject Public Key Info:
- Public Key Algorithm: rsaEncryption
- Public-Key: (1024 bit)
- Modulus:
- 00:be:b7:65:98:5e:e1:e0:68:e7:14:04:e5:40:2d:
- d3:b4:f2:b2:dd:6e:5c:97:7a:5b:c5:4f:7a:45:11:
- 99:4e:56:30:c6:d6:50:29:88:c3:31:6d:b0:f1:a8:
- 5f:f5:fd:cc:d1:52:0f:40:70:04:cc:14:0d:98:45:
- 62:a8:f9:88:0a:be:20:32:53:c5:48:fb:b0:e4:25:
- db:25:ec:0d:c4:6a:28:dc:af:d7:2d:63:99:b9:f4:
- c0:32:54:dc:be:4d:9f:7f:67:7e:2a:be:82:2d:de:
- 37:35:0b:0d:7b:b8:9c:55:ff:cf:ab:fe:61:e9:8c:
- bf:c4:27:e2:56:2f:1a:73:87
- Exponent: 65537 (0x10001)
- X509v3 extensions:
- X509v3 Basic Constraints:
- CA:FALSE
- Netscape Comment:
- OpenSSL Generated Certificate
- X509v3 Subject Key Identifier:
- A1:8C:9A:D1:28:58:68:C5:46:5B:FA:C5:48:01:96:67:55:97:65:8A
- X509v3 Authority Key Identifier:
- keyid:29:4D:6E:C7:F2:F7:71:72:DA:27:9C:9C:AB:DA:07:1D:47:9C:D8:41
-
- Signature Algorithm: sha1WithRSAEncryption
- 78:f6:a1:34:ac:2c:a5:0a:1d:82:97:97:1f:f5:03:44:a7:c0:
- 4d:e8:8d:67:e7:71:50:30:3c:8b:77:eb:81:96:78:6b:ab:31:
- 5a:ba:7b:1c:ad:ec:fd:a6:5d:73:ef:99:2d:6f:9f:7e:13:ac:
- b2:61:2f:e4:56:cc:28:f1:e4:7f:ea:a9:b2:f2:85:87:68:52:
- 65:b0:42:54:84:92:2f:fb:45:d4:36:e2:3c:0e:4c:a6:6d:82:
- 8f:72:c0:66:0c:5f:b2:a7:7c:9b:be:cd:19:55:5d:40:27:99:
- 14:e2:cf:59:cb:4b:40:e4:98:2d:f7:93:14:4a:50:dc:75:9c:
- 5c:9d
------BEGIN CERTIFICATE-----
-MIICxzCCAjCgAwIBAgIBATANBgkqhkiG9w0BAQUFADBgMQswCQYDVQQGEwJHQjET
-MBEGA1UECAwKRGVyYnlzaGlyZTEVMBMGA1UECgwMUGFobyBQcm9qZWN0MRAwDgYD
-VQQLDAdUZXN0aW5nMRMwEQYDVQQDDApTaWduaW5nIENBMB4XDTEzMDcyOTE5MjEz
-MFoXDTE4MDcyODE5MjEzMFowdjELMAkGA1UEBhMCR0IxGDAWBgNVBAgMD05vdHRp
-bmdoYW1zaGlyZTETMBEGA1UEBwwKTm90dGluZ2hhbTEPMA0GA1UECgwGU2VydmVy
-MRMwEQYDVQQLDApQcm9kdWN0aW9uMRIwEAYDVQQDDAlsb2NhbGhvc3QwgZ8wDQYJ
-KoZIhvcNAQEBBQADgY0AMIGJAoGBAL63ZZhe4eBo5xQE5UAt07Tyst1uXJd6W8VP
-ekURmU5WMMbWUCmIwzFtsPGoX/X9zNFSD0BwBMwUDZhFYqj5iAq+IDJTxUj7sOQl
-2yXsDcRqKNyv1y1jmbn0wDJU3L5Nn39nfiq+gi3eNzULDXu4nFX/z6v+YemMv8Qn
-4lYvGnOHAgMBAAGjezB5MAkGA1UdEwQCMAAwLAYJYIZIAYb4QgENBB8WHU9wZW5T
-U0wgR2VuZXJhdGVkIENlcnRpZmljYXRlMB0GA1UdDgQWBBShjJrRKFhoxUZb+sVI
-AZZnVZdlijAfBgNVHSMEGDAWgBQpTW7H8vdxctonnJyr2gcdR5zYQTANBgkqhkiG
-9w0BAQUFAAOBgQB49qE0rCylCh2Cl5cf9QNEp8BN6I1n53FQMDyLd+uBlnhrqzFa
-unscrez9pl1z75ktb59+E6yyYS/kVswo8eR/6qmy8oWHaFJlsEJUhJIv+0XUNuI8
-DkymbYKPcsBmDF+yp3ybvs0ZVV1AJ5kU4s9Zy0tA5Jgt95MUSlDcdZxcnQ==
------END CERTIFICATE-----
-Certificate:
- Data:
- Version: 3 (0x2)
- Serial Number: 1 (0x1)
- Signature Algorithm: sha1WithRSAEncryption
- Issuer: C=GB, ST=Derbyshire, L=Derby, O=Paho Project, OU=Testing, CN=Root CA
- Validity
- Not Before: Jul 29 19:21:30 2013 GMT
- Not After : Jul 28 19:21:30 2018 GMT
- Subject: C=GB, ST=Derbyshire, O=Paho Project, OU=Testing, CN=Signing CA
- Subject Public Key Info:
- Public Key Algorithm: rsaEncryption
- Public-Key: (1024 bit)
- Modulus:
- 00:dc:26:78:40:ae:b2:ad:2f:26:12:0a:d5:b1:18:
- 80:16:d8:88:be:0b:42:ce:32:ad:12:d5:f5:78:1b:
- 35:28:f2:13:1b:05:09:fb:7e:d7:d9:a1:8a:0d:4a:
- fe:95:37:d4:16:75:83:e4:6a:44:34:33:57:2e:49:
- ba:bc:b4:cf:d0:c0:87:e0:bc:f0:60:76:14:00:d6:
- eb:cb:f6:db:b3:43:f1:c8:4d:4a:0a:bb:e0:37:7c:
- 8e:93:1f:a0:87:68:59:fe:0c:25:40:f3:7c:fd:71:
- 90:55:ef:de:18:b4:08:86:c9:75:c2:99:2f:ce:12:
- bf:c5:5e:cf:5f:f1:06:53:07
- Exponent: 65537 (0x10001)
- X509v3 extensions:
- X509v3 Subject Key Identifier:
- 29:4D:6E:C7:F2:F7:71:72:DA:27:9C:9C:AB:DA:07:1D:47:9C:D8:41
- X509v3 Authority Key Identifier:
- keyid:4A:2B:69:D6:31:1D:A3:68:E8:46:6F:FB:4B:F3:8E:B6:8D:51:0E:BF
-
- X509v3 Basic Constraints:
- CA:TRUE
- Signature Algorithm: sha1WithRSAEncryption
- 48:ec:d7:80:8a:8f:82:a6:42:b1:89:2c:b9:4b:6d:0a:37:b8:
- 72:19:05:de:75:80:0c:d6:41:97:b2:d7:fe:99:cb:7e:c4:0e:
- 77:97:09:a8:9f:87:ff:0b:de:3f:1c:dc:1e:fe:09:36:a7:f5:
- 54:9a:85:4e:fb:6f:27:fe:0f:29:45:61:8d:07:c6:0c:da:37:
- 3d:a3:69:4b:82:71:e6:24:e0:87:a6:ee:d5:87:61:dd:8f:08:
- fe:33:a6:1f:ae:b2:ae:1f:d8:2c:20:c8:a6:fc:33:0e:82:68:
- 80:23:61:10:ad:5c:1d:80:d6:b1:5f:e4:af:66:6d:63:10:e4:
- 96:e4
------BEGIN CERTIFICATE-----
-MIICkzCCAfygAwIBAgIBATANBgkqhkiG9w0BAQUFADBtMQswCQYDVQQGEwJHQjET
-MBEGA1UECAwKRGVyYnlzaGlyZTEOMAwGA1UEBwwFRGVyYnkxFTATBgNVBAoMDFBh
-aG8gUHJvamVjdDEQMA4GA1UECwwHVGVzdGluZzEQMA4GA1UEAwwHUm9vdCBDQTAe
-Fw0xMzA3MjkxOTIxMzBaFw0xODA3MjgxOTIxMzBaMGAxCzAJBgNVBAYTAkdCMRMw
-EQYDVQQIDApEZXJieXNoaXJlMRUwEwYDVQQKDAxQYWhvIFByb2plY3QxEDAOBgNV
-BAsMB1Rlc3RpbmcxEzARBgNVBAMMClNpZ25pbmcgQ0EwgZ8wDQYJKoZIhvcNAQEB
-BQADgY0AMIGJAoGBANwmeECusq0vJhIK1bEYgBbYiL4LQs4yrRLV9XgbNSjyExsF
-Cft+19mhig1K/pU31BZ1g+RqRDQzVy5Jury0z9DAh+C88GB2FADW68v227ND8chN
-Sgq74Dd8jpMfoIdoWf4MJUDzfP1xkFXv3hi0CIbJdcKZL84Sv8Vez1/xBlMHAgMB
-AAGjUDBOMB0GA1UdDgQWBBQpTW7H8vdxctonnJyr2gcdR5zYQTAfBgNVHSMEGDAW
-gBRKK2nWMR2jaOhGb/tL8462jVEOvzAMBgNVHRMEBTADAQH/MA0GCSqGSIb3DQEB
-BQUAA4GBAEjs14CKj4KmQrGJLLlLbQo3uHIZBd51gAzWQZey1/6Zy37EDneXCaif
-h/8L3j8c3B7+CTan9VSahU77byf+DylFYY0HxgzaNz2jaUuCceYk4Iem7tWHYd2P
-CP4zph+usq4f2CwgyKb8Mw6CaIAjYRCtXB2A1rFf5K9mbWMQ5Jbk
------END CERTIFICATE-----
diff --git a/org.eclipse.paho.mqtt.c/test/ssl/test-alt-ca.crt b/org.eclipse.paho.mqtt.c/test/ssl/test-alt-ca.crt
deleted file mode 100644
index 87f092a..0000000
--- a/org.eclipse.paho.mqtt.c/test/ssl/test-alt-ca.crt
+++ /dev/null
@@ -1,58 +0,0 @@
-Certificate:
- Data:
- Version: 3 (0x2)
- Serial Number: 2 (0x2)
- Signature Algorithm: sha1WithRSAEncryption
- Issuer: C=GB, ST=Derbyshire, L=Derby, O=Paho Project, OU=Testing, CN=Root CA
- Validity
- Not Before: Jul 29 19:21:30 2013 GMT
- Not After : Jul 28 19:21:30 2018 GMT
- Subject: C=GB, ST=Derbyshire, O=Paho Project, OU=Testing, CN=Alternative Signing CA
- Subject Public Key Info:
- Public Key Algorithm: rsaEncryption
- Public-Key: (1024 bit)
- Modulus:
- 00:d3:16:c8:c3:0c:90:e5:68:3d:11:13:a7:8e:fb:
- 11:c5:de:aa:3f:4d:ac:95:4f:c4:c2:60:8a:df:95:
- b5:db:75:04:76:42:19:5f:d9:63:0e:e4:c0:8e:db:
- a5:5f:21:ec:f3:3d:a0:c1:82:8b:61:b4:1a:5b:3c:
- 9e:42:bd:5f:5b:b4:a8:00:8d:e1:bf:99:93:c8:45:
- 1f:6d:29:ab:67:f0:35:9c:48:0b:a0:a2:18:32:70:
- 35:5e:ea:fe:1f:33:ab:b5:85:ef:1d:2a:a9:75:60:
- 38:ed:3a:33:be:5d:40:89:cb:0b:b3:25:e8:e7:bc:
- 13:6b:62:28:1d:a7:9c:aa:99
- Exponent: 65537 (0x10001)
- X509v3 extensions:
- X509v3 Subject Key Identifier:
- 3A:70:4C:5D:76:C6:B4:CF:E7:BC:4B:F4:CE:C6:B8:46:C2:95:41:9B
- X509v3 Authority Key Identifier:
- keyid:4A:2B:69:D6:31:1D:A3:68:E8:46:6F:FB:4B:F3:8E:B6:8D:51:0E:BF
-
- X509v3 Basic Constraints:
- CA:TRUE
- Signature Algorithm: sha1WithRSAEncryption
- 2f:74:dd:ef:da:03:cf:14:78:ae:6f:0d:04:29:75:db:c5:a2:
- c0:fd:1e:46:bf:3c:25:3c:03:3b:a6:f4:f1:3a:89:54:83:e9:
- 3a:0f:d7:81:9a:8d:7f:2d:6b:b1:ca:17:7f:ef:93:18:c4:68:
- b8:b2:1d:d2:9c:d9:9f:66:9d:18:25:18:b4:4f:72:bf:24:c5:
- 0c:2d:fc:cf:ad:c8:ff:25:f1:36:12:72:b4:46:e1:c9:17:19:
- c5:1e:f5:26:8a:ae:33:5f:69:16:6f:62:ce:fc:ba:c3:a3:c5:
- 50:a3:a5:42:a9:02:6a:25:77:90:3e:e3:b7:e5:ac:7f:3f:bb:
- 1c:17
------BEGIN CERTIFICATE-----
-MIICnzCCAgigAwIBAgIBAjANBgkqhkiG9w0BAQUFADBtMQswCQYDVQQGEwJHQjET
-MBEGA1UECAwKRGVyYnlzaGlyZTEOMAwGA1UEBwwFRGVyYnkxFTATBgNVBAoMDFBh
-aG8gUHJvamVjdDEQMA4GA1UECwwHVGVzdGluZzEQMA4GA1UEAwwHUm9vdCBDQTAe
-Fw0xMzA3MjkxOTIxMzBaFw0xODA3MjgxOTIxMzBaMGwxCzAJBgNVBAYTAkdCMRMw
-EQYDVQQIDApEZXJieXNoaXJlMRUwEwYDVQQKDAxQYWhvIFByb2plY3QxEDAOBgNV
-BAsMB1Rlc3RpbmcxHzAdBgNVBAMMFkFsdGVybmF0aXZlIFNpZ25pbmcgQ0EwgZ8w
-DQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBANMWyMMMkOVoPRETp477EcXeqj9NrJVP
-xMJgit+Vtdt1BHZCGV/ZYw7kwI7bpV8h7PM9oMGCi2G0Gls8nkK9X1u0qACN4b+Z
-k8hFH20pq2fwNZxIC6CiGDJwNV7q/h8zq7WF7x0qqXVgOO06M75dQInLC7Ml6Oe8
-E2tiKB2nnKqZAgMBAAGjUDBOMB0GA1UdDgQWBBQ6cExddsa0z+e8S/TOxrhGwpVB
-mzAfBgNVHSMEGDAWgBRKK2nWMR2jaOhGb/tL8462jVEOvzAMBgNVHRMEBTADAQH/
-MA0GCSqGSIb3DQEBBQUAA4GBAC903e/aA88UeK5vDQQpddvFosD9Hka/PCU8Azum
-9PE6iVSD6ToP14GajX8ta7HKF3/vkxjEaLiyHdKc2Z9mnRglGLRPcr8kxQwt/M+t
-yP8l8TYScrRG4ckXGcUe9SaKrjNfaRZvYs78usOjxVCjpUKpAmold5A+47flrH8/
-uxwX
------END CERTIFICATE-----
diff --git a/org.eclipse.paho.mqtt.c/test/ssl/test-alt-ca.key b/org.eclipse.paho.mqtt.c/test/ssl/test-alt-ca.key
deleted file mode 100644
index a9450e1..0000000
--- a/org.eclipse.paho.mqtt.c/test/ssl/test-alt-ca.key
+++ /dev/null
@@ -1,15 +0,0 @@
------BEGIN RSA PRIVATE KEY-----
-MIICXAIBAAKBgQDTFsjDDJDlaD0RE6eO+xHF3qo/TayVT8TCYIrflbXbdQR2Qhlf
-2WMO5MCO26VfIezzPaDBgothtBpbPJ5CvV9btKgAjeG/mZPIRR9tKatn8DWcSAug
-ohgycDVe6v4fM6u1he8dKql1YDjtOjO+XUCJywuzJejnvBNrYigdp5yqmQIDAQAB
-AoGAFaQtWwnrxQlF0X1hXWBSNyYX8DuHaRtvgboiIsAXj/NUTMeEEHaaGEnNkBfm
-wXUZ9OoplA1NOuwbE6WIWDFQGEgma/yLBdy4HYxQpAbJ1qnR7DyoxQ8NHPhBH+cW
-GI92g7NqDEphdoHrWYy5YZYCFVr3pTHXbxlBn/VTLBsQnIECQQDr9BcQxEnPfi6e
-Kk8cenA/54tGl7Ewpklb8XBrQrm/djfOAFt+CTMexerBv7BnfgriAg5wtlHtTkpK
-BLLULE3pAkEA5QXmZ2WvGl0kvgBYGdiOZAruMobOVxxVxF05gvh8Sw6fNj8pI9pn
-sbzyFZWIjcuDBfTLx+GVvkhqtQhs6ZYZMQJBAOSfjR3c45veKrNsUV1Jsavp4cST
-xMdbyCcDaSc07x/6HxZGuGAF7/d4VABJiVauBUN6NJ23uuhR/J99r/zvtMkCQCQe
-qhfkkZk213Sf2UU6QjrE/ow5dpGGhoBRs6BUUEYGKFYF4BcnevMtOYDt9HtofWGT
-GhCMI3G/OhUTHxo38gECQG0nSN+QQ4tddHcktz1rnfwbnmTuNloZLC4ahR67lz75
-uP42Ct0dXPjzakzDCGI2CgNk5QGk/IUO6fq4mYVxqRI=
------END RSA PRIVATE KEY-----
diff --git a/org.eclipse.paho.mqtt.c/test/ssl/test-bad-root-ca.crt b/org.eclipse.paho.mqtt.c/test/ssl/test-bad-root-ca.crt
deleted file mode 100644
index 7d40475..0000000
--- a/org.eclipse.paho.mqtt.c/test/ssl/test-bad-root-ca.crt
+++ /dev/null
@@ -1,17 +0,0 @@
------BEGIN CERTIFICATE-----
-MIICsDCCAhmgAwIBAgIJANKB0fFTAhRpMA0GCSqGSIb3DQEBBQUAMHExCzAJBgNV
-BAYTAkdCMRMwEQYDVQQIDApEZXJieXNoaXJlMQ4wDAYDVQQHDAVEZXJieTEVMBMG
-A1UECgwMUGFobyBQcm9qZWN0MRAwDgYDVQQLDAdUZXN0aW5nMRQwEgYDVQQDDAtC
-YWQgUm9vdCBDQTAeFw0xMzA3MjkxOTIxMjlaFw0yMzA3MjcxOTIxMjlaMHExCzAJ
-BgNVBAYTAkdCMRMwEQYDVQQIDApEZXJieXNoaXJlMQ4wDAYDVQQHDAVEZXJieTEV
-MBMGA1UECgwMUGFobyBQcm9qZWN0MRAwDgYDVQQLDAdUZXN0aW5nMRQwEgYDVQQD
-DAtCYWQgUm9vdCBDQTCBnzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEA6+nf2D7S
-IP42qMVmfAEpKZw22qF0mLVjjL22bWVHwwE1CS5euzD/gBM7i0u7hvFgbvI13Yq4
-Du2ebfjv3n4TAIIQg+UOAY5NbzfUG0A+50J6tPpNtnTij3KXskhQRAlvjDSd3TlU
-UiONY2HMwaU56ktqXZzZE7prU0RICZ+DK8cCAwEAAaNQME4wHQYDVR0OBBYEFH/5
-0qkqiFd2x/lspeK61TO4PGF1MB8GA1UdIwQYMBaAFH/50qkqiFd2x/lspeK61TO4
-PGF1MAwGA1UdEwQFMAMBAf8wDQYJKoZIhvcNAQEFBQADgYEARtsgIzT+IVRJHYT1
-wP7C2PuXxbRXFG8a0qqGaA0f4SuICq7NvC3bF5l9zDh4yMvftj8keTiOIa3+alw3
-ucdTz25Jaq/ZER/c68cklMPqcgdwcb/RbxpY5t3PittU2J5wAn/MmFfRiqbsxhgW
-hkYbAtnqBXzJ8HdN/HmIyFW7+q4=
------END CERTIFICATE-----
diff --git a/org.eclipse.paho.mqtt.c/test/ssl/test-bad-root-ca.key b/org.eclipse.paho.mqtt.c/test/ssl/test-bad-root-ca.key
deleted file mode 100644
index ffa821e..0000000
--- a/org.eclipse.paho.mqtt.c/test/ssl/test-bad-root-ca.key
+++ /dev/null
@@ -1,15 +0,0 @@
------BEGIN RSA PRIVATE KEY-----
-MIICXQIBAAKBgQDr6d/YPtIg/jaoxWZ8ASkpnDbaoXSYtWOMvbZtZUfDATUJLl67
-MP+AEzuLS7uG8WBu8jXdirgO7Z5t+O/efhMAghCD5Q4Bjk1vN9QbQD7nQnq0+k22
-dOKPcpeySFBECW+MNJ3dOVRSI41jYczBpTnqS2pdnNkTumtTREgJn4MrxwIDAQAB
-AoGBAJk4o/bqDkX5dfy1gPOHOXnaCNKEzJqmLMrrKIHypuIjdZPJ9yLzFu7TDvhQ
-rrJdMTm9vHhwMU0Yza41YW2LSsDpeCI0RkpMxG+Aqaxz+kRYPzwDFFI6YAX0NWpS
-O9iie9+sDp0MfOwPlDwtY9T7OegrPH/ngtxWxFp7R0YxVLQJAkEA+Or0TgAklxy/
-2LQV27OPFXc0ejYf67hLNdOC66PhTCO18avjEpDEeA00vF5DkqT+VXJVz2XyXX97
-+cCAf3sYhQJBAPKgM3pmHrhMxr+qgyqiTiKD42kASWLDGEDP0EP4tVaZNdwWH2XG
-tSanhf6eOdoHlq0+3c3tIDwJZ+uCr21ACtsCQAiUeLVTle9Lg2Vh17sJ9m2j/UAV
-K4aBhL4nO0UKEhMAzB23cg1KxirpMZ8olKWyYD3rwf9zISaN5WUXeJZsVM0CQQC5
-GEhNb0yuUzwoil+ojcvH/w/lUeeqZaXCBAghYsKMvzNcpK/tSAt44sKRfYoq8DEe
-F+DEscsuogpanAdS9FGTAkAt8POChqwkCSjXQ9TlPQhdL4bRcENBQz6xp9TEOYT+
-M+FFifLj/ke8sRWXjrar1k45u8VWJJmd/0gmsUSiWoaS
------END RSA PRIVATE KEY-----
diff --git a/org.eclipse.paho.mqtt.c/test/ssl/test-fake-root-ca.crt b/org.eclipse.paho.mqtt.c/test/ssl/test-fake-root-ca.crt
deleted file mode 100644
index 239a74b..0000000
--- a/org.eclipse.paho.mqtt.c/test/ssl/test-fake-root-ca.crt
+++ /dev/null
@@ -1,17 +0,0 @@
------BEGIN CERTIFICATE-----
-MIICqDCCAhGgAwIBAgIJALWM56dkMt5jMA0GCSqGSIb3DQEBBQUAMG0xCzAJBgNV
-BAYTAkdCMRMwEQYDVQQIDApEZXJieXNoaXJlMQ4wDAYDVQQHDAVEZXJieTEVMBMG
-A1UECgwMUGFobyBQcm9qZWN0MRAwDgYDVQQLDAdUZXN0aW5nMRAwDgYDVQQDDAdS
-b290IENBMB4XDTEzMDcyOTE5MjEzMFoXDTIzMDcyNzE5MjEzMFowbTELMAkGA1UE
-BhMCR0IxEzARBgNVBAgMCkRlcmJ5c2hpcmUxDjAMBgNVBAcMBURlcmJ5MRUwEwYD
-VQQKDAxQYWhvIFByb2plY3QxEDAOBgNVBAsMB1Rlc3RpbmcxEDAOBgNVBAMMB1Jv
-b3QgQ0EwgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBAOpNNgRF6qhcGxndkPFE
-1uZVQZ2x9GV3UlARuTnG89MX+6W+fXQ0gfdcbKs1/puhFqvrcqrWmoIgRtM/lZR/
-YDs5EXfpb13V5pDDn8X7AD2+poUb9eHxcB6fKuRbyt1PsS42umwUlpIDtK6p6H8/
-ZfxSiOE73kyY6CUvJfTC4WHrAgMBAAGjUDBOMB0GA1UdDgQWBBSXmasVth7iUHhF
-8MDaBnSIGBV4qzAfBgNVHSMEGDAWgBSXmasVth7iUHhF8MDaBnSIGBV4qzAMBgNV
-HRMEBTADAQH/MA0GCSqGSIb3DQEBBQUAA4GBANAYCcz14fk3Y+9CBMm/kitCWAkI
-Ia54KL0A8ynqrLHssO3Ilq+wb10vSNLxhsdws3zNAfXteFxOvGm24Yu+8oTBQ26K
-QfTp/cH9yoF97ONMxg7rqANOJeYv0BeJdDcgjCMgmql5ETEz2cf9tTWBUAtd1ZZC
-YPS5aiNsetk+XuS9
------END CERTIFICATE-----
diff --git a/org.eclipse.paho.mqtt.c/test/ssl/test-fake-root-ca.key b/org.eclipse.paho.mqtt.c/test/ssl/test-fake-root-ca.key
deleted file mode 100644
index 4a040e9..0000000
--- a/org.eclipse.paho.mqtt.c/test/ssl/test-fake-root-ca.key
+++ /dev/null
@@ -1,15 +0,0 @@
------BEGIN RSA PRIVATE KEY-----
-MIICXQIBAAKBgQDqTTYEReqoXBsZ3ZDxRNbmVUGdsfRld1JQEbk5xvPTF/ulvn10
-NIH3XGyrNf6boRar63Kq1pqCIEbTP5WUf2A7ORF36W9d1eaQw5/F+wA9vqaFG/Xh
-8XAenyrkW8rdT7EuNrpsFJaSA7Suqeh/P2X8UojhO95MmOglLyX0wuFh6wIDAQAB
-AoGBAMhOUgu9Kivc8l5eiXd6fq5T3NDQPjwwknJZdJzsda7WJhFAlUgvS50Jqu2E
-L7MlOJippVJgPZ9ZsLMQ/PQDIWRdLg2K9VLS4nPl3p7LzHoDmqDnMLPo9fUGBile
-EnWwSSCWrz8ATyDO1ct5oJmK/S9QRxdvtw+6SbmorhnzypihAkEA+9LNpjnpuOWf
-iF0TGWKhK53WPtiCBnuisXGZEZws9mzFGlfdR98sBDyekl7oHOb+JI0SDpPl3PBE
-hZXcF7VPtQJBAO4wA1sxXqfYUazt6SInUTzpaNZ9xPrK0p1PgxZLxJrZV6hZByvW
-FGb+cKGnOHIYq4tnCg0cyRe1xX4MJU6wrx8CQGRtNUZNYkAykuS2+Z7uDohucbqu
-bWxYchGB1CGJvwSnbBONZtn6znsCEdsdrkOYe1HoUIMvyEPMLgd4NEXgMOECQF+u
-y/pbR9IXVSAp5oiA0OKuRR49Id85kQf+xAM15sHp44vOT9ItSr7hIa/etA8pl+gF
-OYVw9dtfevmauXX2BjMCQQCrse1jUAp3xmsXwb1JieclSh/C/FcGeo6DYpIcm9bK
-RiVCmpzy3hOqYW137l5WvpUwZmN2wPvaKCacF/t75EiG
------END RSA PRIVATE KEY-----
diff --git a/org.eclipse.paho.mqtt.c/test/ssl/test-root-ca.crt b/org.eclipse.paho.mqtt.c/test/ssl/test-root-ca.crt
deleted file mode 100644
index 92dd583..0000000
--- a/org.eclipse.paho.mqtt.c/test/ssl/test-root-ca.crt
+++ /dev/null
@@ -1,17 +0,0 @@
------BEGIN CERTIFICATE-----
-MIICqDCCAhGgAwIBAgIJAKrzwmdXIUxsMA0GCSqGSIb3DQEBBQUAMG0xCzAJBgNV
-BAYTAkdCMRMwEQYDVQQIDApEZXJieXNoaXJlMQ4wDAYDVQQHDAVEZXJieTEVMBMG
-A1UECgwMUGFobyBQcm9qZWN0MRAwDgYDVQQLDAdUZXN0aW5nMRAwDgYDVQQDDAdS
-b290IENBMB4XDTEzMDcyOTE5MjEyOVoXDTIzMDcyNzE5MjEyOVowbTELMAkGA1UE
-BhMCR0IxEzARBgNVBAgMCkRlcmJ5c2hpcmUxDjAMBgNVBAcMBURlcmJ5MRUwEwYD
-VQQKDAxQYWhvIFByb2plY3QxEDAOBgNVBAsMB1Rlc3RpbmcxEDAOBgNVBAMMB1Jv
-b3QgQ0EwgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBAKbPzEEWCKsjjwjJ787u
-Q32k5EdqoDddMEjSVbZNSNEwUew1L7O8NTbmtCEeVFQjOLAdmdiF3rQbXHV+Zew0
-jt2g4vtPpl1GOG6jA/6YznKAyQdvGCdYfGZUN2tN+mbtVxWqkHZitQDQGaSHnx24
-NX649La2uyFy+7l9o8++xPONAgMBAAGjUDBOMB0GA1UdDgQWBBRKK2nWMR2jaOhG
-b/tL8462jVEOvzAfBgNVHSMEGDAWgBRKK2nWMR2jaOhGb/tL8462jVEOvzAMBgNV
-HRMEBTADAQH/MA0GCSqGSIb3DQEBBQUAA4GBAEd+gW86/W+fisz5PFHAeEw7zn9q
-dzLHm7+QZgNLZ9h7/ZbhObRUFMRtU2xm4amyh85h7hUE5R2E2uW2OXumic7/D4ZD
-6unjr4m5jwVWDTqTUYIcNSriyoDWAVlPfOWaU5NyUhqS1DM28tvOWVHVLCxmVcZl
-tJQqo5eHbQ/+Hjfx
------END CERTIFICATE-----
diff --git a/org.eclipse.paho.mqtt.c/test/ssl/test-root-ca.crt.text b/org.eclipse.paho.mqtt.c/test/ssl/test-root-ca.crt.text
deleted file mode 100644
index bad317d..0000000
--- a/org.eclipse.paho.mqtt.c/test/ssl/test-root-ca.crt.text
+++ /dev/null
@@ -1,59 +0,0 @@
-Certificate:
- Data:
- Version: 3 (0x2)
- Serial Number:
- aa:f3:c2:67:57:21:4c:6c
- Signature Algorithm: sha1WithRSAEncryption
- Issuer: C=GB, ST=Derbyshire, L=Derby, O=Paho Project, OU=Testing, CN=Root CA
- Validity
- Not Before: Jul 29 19:21:29 2013 GMT
- Not After : Jul 27 19:21:29 2023 GMT
- Subject: C=GB, ST=Derbyshire, L=Derby, O=Paho Project, OU=Testing, CN=Root CA
- Subject Public Key Info:
- Public Key Algorithm: rsaEncryption
- Public-Key: (1024 bit)
- Modulus:
- 00:a6:cf:cc:41:16:08:ab:23:8f:08:c9:ef:ce:ee:
- 43:7d:a4:e4:47:6a:a0:37:5d:30:48:d2:55:b6:4d:
- 48:d1:30:51:ec:35:2f:b3:bc:35:36:e6:b4:21:1e:
- 54:54:23:38:b0:1d:99:d8:85:de:b4:1b:5c:75:7e:
- 65:ec:34:8e:dd:a0:e2:fb:4f:a6:5d:46:38:6e:a3:
- 03:fe:98:ce:72:80:c9:07:6f:18:27:58:7c:66:54:
- 37:6b:4d:fa:66:ed:57:15:aa:90:76:62:b5:00:d0:
- 19:a4:87:9f:1d:b8:35:7e:b8:f4:b6:b6:bb:21:72:
- fb:b9:7d:a3:cf:be:c4:f3:8d
- Exponent: 65537 (0x10001)
- X509v3 extensions:
- X509v3 Subject Key Identifier:
- 4A:2B:69:D6:31:1D:A3:68:E8:46:6F:FB:4B:F3:8E:B6:8D:51:0E:BF
- X509v3 Authority Key Identifier:
- keyid:4A:2B:69:D6:31:1D:A3:68:E8:46:6F:FB:4B:F3:8E:B6:8D:51:0E:BF
-
- X509v3 Basic Constraints:
- CA:TRUE
- Signature Algorithm: sha1WithRSAEncryption
- 47:7e:81:6f:3a:fd:6f:9f:8a:cc:f9:3c:51:c0:78:4c:3b:ce:
- 7f:6a:77:32:c7:9b:bf:90:66:03:4b:67:d8:7b:fd:96:e1:39:
- b4:54:14:c4:6d:53:6c:66:e1:a9:b2:87:ce:61:ee:15:04:e5:
- 1d:84:da:e5:b6:39:7b:a6:89:ce:ff:0f:86:43:ea:e9:e3:af:
- 89:b9:8f:05:56:0d:3a:93:51:82:1c:35:2a:e2:ca:80:d6:01:
- 59:4f:7c:e5:9a:53:93:72:52:1a:92:d4:33:36:f2:db:ce:59:
- 51:d5:2c:2c:66:55:c6:65:b4:94:2a:a3:97:87:6d:0f:fe:1e:
- 37:f1
------BEGIN CERTIFICATE-----
-MIICqDCCAhGgAwIBAgIJAKrzwmdXIUxsMA0GCSqGSIb3DQEBBQUAMG0xCzAJBgNV
-BAYTAkdCMRMwEQYDVQQIDApEZXJieXNoaXJlMQ4wDAYDVQQHDAVEZXJieTEVMBMG
-A1UECgwMUGFobyBQcm9qZWN0MRAwDgYDVQQLDAdUZXN0aW5nMRAwDgYDVQQDDAdS
-b290IENBMB4XDTEzMDcyOTE5MjEyOVoXDTIzMDcyNzE5MjEyOVowbTELMAkGA1UE
-BhMCR0IxEzARBgNVBAgMCkRlcmJ5c2hpcmUxDjAMBgNVBAcMBURlcmJ5MRUwEwYD
-VQQKDAxQYWhvIFByb2plY3QxEDAOBgNVBAsMB1Rlc3RpbmcxEDAOBgNVBAMMB1Jv
-b3QgQ0EwgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBAKbPzEEWCKsjjwjJ787u
-Q32k5EdqoDddMEjSVbZNSNEwUew1L7O8NTbmtCEeVFQjOLAdmdiF3rQbXHV+Zew0
-jt2g4vtPpl1GOG6jA/6YznKAyQdvGCdYfGZUN2tN+mbtVxWqkHZitQDQGaSHnx24
-NX649La2uyFy+7l9o8++xPONAgMBAAGjUDBOMB0GA1UdDgQWBBRKK2nWMR2jaOhG
-b/tL8462jVEOvzAfBgNVHSMEGDAWgBRKK2nWMR2jaOhGb/tL8462jVEOvzAMBgNV
-HRMEBTADAQH/MA0GCSqGSIb3DQEBBQUAA4GBAEd+gW86/W+fisz5PFHAeEw7zn9q
-dzLHm7+QZgNLZ9h7/ZbhObRUFMRtU2xm4amyh85h7hUE5R2E2uW2OXumic7/D4ZD
-6unjr4m5jwVWDTqTUYIcNSriyoDWAVlPfOWaU5NyUhqS1DM28tvOWVHVLCxmVcZl
-tJQqo5eHbQ/+Hjfx
------END CERTIFICATE-----
diff --git a/org.eclipse.paho.mqtt.c/test/ssl/test-root-ca.key b/org.eclipse.paho.mqtt.c/test/ssl/test-root-ca.key
deleted file mode 100644
index 3cb7148..0000000
--- a/org.eclipse.paho.mqtt.c/test/ssl/test-root-ca.key
+++ /dev/null
@@ -1,15 +0,0 @@
------BEGIN RSA PRIVATE KEY-----
-MIICXQIBAAKBgQCmz8xBFgirI48Iye/O7kN9pORHaqA3XTBI0lW2TUjRMFHsNS+z
-vDU25rQhHlRUIziwHZnYhd60G1x1fmXsNI7doOL7T6ZdRjhuowP+mM5ygMkHbxgn
-WHxmVDdrTfpm7VcVqpB2YrUA0Bmkh58duDV+uPS2trshcvu5faPPvsTzjQIDAQAB
-AoGAFVhNqJ5rKYr5SISefPocBL3OwByyt6LjBM51TUiCYtIuCW2c1wDkRkwrDHnX
-DJUdMdv3za8DmkROBnLQE/N9vEVhrfrDpBpU6ne/0tbxRlmDi1ihH+zgBUZkIkQo
-kP5kQrV6Tfv7zhFv6cZzewRjGYzTwt8xWB54bKFlsJSlj/kCQQDY0AirnfIVyK+0
-mkqwYEiXWCQfkdRtbLBwpE8S/bbMQVb+Qxh8iCEdw3u1/c/GRFG/qUQ/54/Tetlx
-ZWTTusuXAkEAxPY1+EyW90I8cDSBsrL+S47meut5Qp1Z/WspKjuZgozT7YnECK1k
-JWyXIfBixMIqeQp+pVfVRtYSumvnVhAuewJAA3ylBw2NPShzGvZ4SQnjYPu76P4R
-aoka9VTPKMEH1ZUfbwtpM2eFENN6A91HICstHWX9gQGaYI5TPO2ih30zlQJBAIRH
-06FqVu3DJ3I4YW8R9eXrGHIvmaYapeikQuZhVs0uJdtf7i/hu+PClZIurzb0LLBU
-UxBa+Bt2BOf9NkY/4ecCQQCYLGMiKrfckXC6VtQalLuEXkeE8spcdh/NV22Qpim5
-xfir6M2ZcPDxaFpPmSDSS1TRTaeulX/djUE35EdNPVP8
------END RSA PRIVATE KEY-----
diff --git a/org.eclipse.paho.mqtt.c/test/ssl/test-signing-ca.crt b/org.eclipse.paho.mqtt.c/test/ssl/test-signing-ca.crt
deleted file mode 100644
index 3a10151..0000000
--- a/org.eclipse.paho.mqtt.c/test/ssl/test-signing-ca.crt
+++ /dev/null
@@ -1,57 +0,0 @@
-Certificate:
- Data:
- Version: 3 (0x2)
- Serial Number: 1 (0x1)
- Signature Algorithm: sha1WithRSAEncryption
- Issuer: C=GB, ST=Derbyshire, L=Derby, O=Paho Project, OU=Testing, CN=Root CA
- Validity
- Not Before: Jul 29 19:21:30 2013 GMT
- Not After : Jul 28 19:21:30 2018 GMT
- Subject: C=GB, ST=Derbyshire, O=Paho Project, OU=Testing, CN=Signing CA
- Subject Public Key Info:
- Public Key Algorithm: rsaEncryption
- Public-Key: (1024 bit)
- Modulus:
- 00:dc:26:78:40:ae:b2:ad:2f:26:12:0a:d5:b1:18:
- 80:16:d8:88:be:0b:42:ce:32:ad:12:d5:f5:78:1b:
- 35:28:f2:13:1b:05:09:fb:7e:d7:d9:a1:8a:0d:4a:
- fe:95:37:d4:16:75:83:e4:6a:44:34:33:57:2e:49:
- ba:bc:b4:cf:d0:c0:87:e0:bc:f0:60:76:14:00:d6:
- eb:cb:f6:db:b3:43:f1:c8:4d:4a:0a:bb:e0:37:7c:
- 8e:93:1f:a0:87:68:59:fe:0c:25:40:f3:7c:fd:71:
- 90:55:ef:de:18:b4:08:86:c9:75:c2:99:2f:ce:12:
- bf:c5:5e:cf:5f:f1:06:53:07
- Exponent: 65537 (0x10001)
- X509v3 extensions:
- X509v3 Subject Key Identifier:
- 29:4D:6E:C7:F2:F7:71:72:DA:27:9C:9C:AB:DA:07:1D:47:9C:D8:41
- X509v3 Authority Key Identifier:
- keyid:4A:2B:69:D6:31:1D:A3:68:E8:46:6F:FB:4B:F3:8E:B6:8D:51:0E:BF
-
- X509v3 Basic Constraints:
- CA:TRUE
- Signature Algorithm: sha1WithRSAEncryption
- 48:ec:d7:80:8a:8f:82:a6:42:b1:89:2c:b9:4b:6d:0a:37:b8:
- 72:19:05:de:75:80:0c:d6:41:97:b2:d7:fe:99:cb:7e:c4:0e:
- 77:97:09:a8:9f:87:ff:0b:de:3f:1c:dc:1e:fe:09:36:a7:f5:
- 54:9a:85:4e:fb:6f:27:fe:0f:29:45:61:8d:07:c6:0c:da:37:
- 3d:a3:69:4b:82:71:e6:24:e0:87:a6:ee:d5:87:61:dd:8f:08:
- fe:33:a6:1f:ae:b2:ae:1f:d8:2c:20:c8:a6:fc:33:0e:82:68:
- 80:23:61:10:ad:5c:1d:80:d6:b1:5f:e4:af:66:6d:63:10:e4:
- 96:e4
------BEGIN CERTIFICATE-----
-MIICkzCCAfygAwIBAgIBATANBgkqhkiG9w0BAQUFADBtMQswCQYDVQQGEwJHQjET
-MBEGA1UECAwKRGVyYnlzaGlyZTEOMAwGA1UEBwwFRGVyYnkxFTATBgNVBAoMDFBh
-aG8gUHJvamVjdDEQMA4GA1UECwwHVGVzdGluZzEQMA4GA1UEAwwHUm9vdCBDQTAe
-Fw0xMzA3MjkxOTIxMzBaFw0xODA3MjgxOTIxMzBaMGAxCzAJBgNVBAYTAkdCMRMw
-EQYDVQQIDApEZXJieXNoaXJlMRUwEwYDVQQKDAxQYWhvIFByb2plY3QxEDAOBgNV
-BAsMB1Rlc3RpbmcxEzARBgNVBAMMClNpZ25pbmcgQ0EwgZ8wDQYJKoZIhvcNAQEB
-BQADgY0AMIGJAoGBANwmeECusq0vJhIK1bEYgBbYiL4LQs4yrRLV9XgbNSjyExsF
-Cft+19mhig1K/pU31BZ1g+RqRDQzVy5Jury0z9DAh+C88GB2FADW68v227ND8chN
-Sgq74Dd8jpMfoIdoWf4MJUDzfP1xkFXv3hi0CIbJdcKZL84Sv8Vez1/xBlMHAgMB
-AAGjUDBOMB0GA1UdDgQWBBQpTW7H8vdxctonnJyr2gcdR5zYQTAfBgNVHSMEGDAW
-gBRKK2nWMR2jaOhGb/tL8462jVEOvzAMBgNVHRMEBTADAQH/MA0GCSqGSIb3DQEB
-BQUAA4GBAEjs14CKj4KmQrGJLLlLbQo3uHIZBd51gAzWQZey1/6Zy37EDneXCaif
-h/8L3j8c3B7+CTan9VSahU77byf+DylFYY0HxgzaNz2jaUuCceYk4Iem7tWHYd2P
-CP4zph+usq4f2CwgyKb8Mw6CaIAjYRCtXB2A1rFf5K9mbWMQ5Jbk
------END CERTIFICATE-----
diff --git a/org.eclipse.paho.mqtt.c/test/ssl/test-signing-ca.key b/org.eclipse.paho.mqtt.c/test/ssl/test-signing-ca.key
deleted file mode 100644
index 2826af0..0000000
--- a/org.eclipse.paho.mqtt.c/test/ssl/test-signing-ca.key
+++ /dev/null
@@ -1,15 +0,0 @@
------BEGIN RSA PRIVATE KEY-----
-MIICWwIBAAKBgQDcJnhArrKtLyYSCtWxGIAW2Ii+C0LOMq0S1fV4GzUo8hMbBQn7
-ftfZoYoNSv6VN9QWdYPkakQ0M1cuSbq8tM/QwIfgvPBgdhQA1uvL9tuzQ/HITUoK
-u+A3fI6TH6CHaFn+DCVA83z9cZBV794YtAiGyXXCmS/OEr/FXs9f8QZTBwIDAQAB
-AoGAEEMDNPvylNpbvI9yU3+Uzps2FpusVqDlqfOGC1YvKhQflypbH2myNhA5q1uz
-zH/wOax6jp/O4/A6619k3NWaWBUSDeD1jczdzzDB6Eq1+6oj1szwLBA5EQHz5tuM
-0BIWVGv12bqY/LGBbYsIABBTr584rA3QSgM3K4SPxKKiyYECQQD6ELRf6hfd5qhs
-8RJY5f3yXaV6rSpz8meht4VwMguiYwNBHrHAHxgumMfLiJ2PWa+6aFUxcWs93RfL
-5Tzn2DtHAkEA4WADib1R05V3X2XcU9ursA0va5nPEtQ0fNJAUm4iJOtEElk61Ku4
-0KFokloTovpAgno+QxQdy1trwBz/ov2KQQJAaNeaGGCYUxPC57IHBDihSP1UROPX
-Wbd3FYlRK+H/mLy0f5fz5F3lEJxDoCUOEi0DDT9zAIDR+qT4tibNa1LwPwJAQDtT
-BtCUH487pE6tiqDSv6wiVbJSV/VuuBxcBKIqzQbYMbqIj9AZLiyyVvOhIRPditI4
-KHn1O93kSa56FQPZgQJAV0mCqYciPBU4z3qtLGIDqdzTszBh4U5cTu5M+TICrg20
-dtH2X0dETx7c2+7FDkr1ktVq9skJAXMw6mWM8FMYFg==
------END RSA PRIVATE KEY-----
diff --git a/org.eclipse.paho.mqtt.c/test/sync_client_test.c b/org.eclipse.paho.mqtt.c/test/sync_client_test.c
deleted file mode 100644
index 31c776d..0000000
--- a/org.eclipse.paho.mqtt.c/test/sync_client_test.c
+++ /dev/null
@@ -1,1122 +0,0 @@
-/*******************************************************************
- Copyright (c) 2013, 2014 IBM Corp.
-
- All rights reserved. This program and the accompanying materials
- are made available under the terms of the Eclipse Public License v1.0
- and Eclipse Distribution License v1.0 which accompany this distribution.
-
- The Eclipse Public License is available at
- http://www.eclipse.org/legal/epl-v10.html
- and the Eclipse Distribution License is available at
- http://www.eclipse.org/org/documents/edl-v10.php.
-
- Contributors:
- Ian Craggs - initial implementation and/or documentation
-*******************************************************************/
-
-#include "MQTTClient.h"
-#include
-#include
-
-#if !defined(_WINDOWS)
- #include
- #include
- #include
- #include
-#else
-#include
-#include
-#define MAXHOSTNAMELEN 256
-#define EAGAIN WSAEWOULDBLOCK
-#define EINTR WSAEINTR
-#define EINPROGRESS WSAEINPROGRESS
-#define EWOULDBLOCK WSAEWOULDBLOCK
-#define ENOTCONN WSAENOTCONN
-#define ECONNRESET WSAECONNRESET
-#endif
-
-#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
-
-
-char* topics[] = {"TopicA", "TopicA/B", "Topic/C", "TopicA/C", "/TopicA"};
-char* wildtopics[] = {"TopicA/+", "+/C", "#", "/#", "/+", "+/+", "TopicA/#"};
-char* nosubscribe_topics[] = {"nosubscribe",};
-
-struct Options
-{
- char* connection; /**< connection to system under test. */
- char* clientid1;
- char* clientid2;
- char* username;
- char* password;
- int verbose;
- int MQTTVersion;
- int iterations;
- int run_dollar_topics_test;
- int run_subscribe_failure_test;
-} options =
-{
- "tcp://localhost:1883",
- "myclientid",
- "myclientid2",
- NULL,
- NULL,
- 0,
- MQTTVERSION_3_1_1,
- 1,
- 0,
- 0,
-};
-
-
-void usage()
-{
- printf("options:\n connection, clientid1, clientid2, username, password, MQTTversion, iterations, verbose\n");
- exit(-1);
-}
-
-void getopts(int argc, char** argv)
-{
- int count = 1;
-
- while (count < argc)
- {
- if (strcmp(argv[count], "--dollar_topics_test") == 0 || strcmp(argv[count], "--$") == 0)
- {
- options.run_dollar_topics_test = 1;
- printf("Running $ topics test\n");
- }
- else if (strcmp(argv[count], "--subscribe_failure_test") == 0 || strcmp(argv[count], "-s") == 0)
- {
- options.run_subscribe_failure_test = 1;
- printf("Running subscribe failure test\n");
- }
- else if (strcmp(argv[count], "--connection") == 0)
- {
- if (++count < argc)
- {
- options.connection = argv[count];
- printf("Setting connection to %s\n", options.connection);
- }
- else
- usage();
- }
- else if (strcmp(argv[count], "--clientid1") == 0)
- {
- if (++count < argc)
- {
- options.clientid1 = argv[count];
- printf("Setting clientid1 to %s\n", options.clientid1);
- }
- else
- usage();
- }
- else if (strcmp(argv[count], "--clientid2") == 0)
- {
- if (++count < argc)
- {
- options.clientid2 = argv[count];
- printf("Setting clientid2 to %s\n", options.clientid2);
- }
- else
- usage();
- }
- else if (strcmp(argv[count], "--username") == 0)
- {
- if (++count < argc)
- {
- options.username = argv[count];
- printf("Setting username to %s\n", options.username);
- }
- else
- usage();
- }
- else if (strcmp(argv[count], "--password") == 0)
- {
- if (++count < argc)
- {
- options.password = argv[count];
- printf("Setting password to %s\n", options.password);
- }
- 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]);
- printf("Setting iterations to %d\n", options.iterations);
- }
- else
- usage();
- }
- else if (strcmp(argv[count], "--verbose") == 0)
- {
- options.verbose = 1;
- printf("\nSetting verbose on\n");
- }
- count++;
- }
-}
-
-
-#if defined(WIN32) || defined(_WINDOWS)
-#define msleep Sleep
-#define START_TIME_TYPE DWORD
-static DWORD start_time = 0;
-START_TIME_TYPE start_clock(void)
-{
- return GetTickCount();
-}
-#elif defined(AIX)
-#define mqsleep sleep
-#define START_TIME_TYPE struct timespec
-START_TIME_TYPE start_clock(void)
-{
- static struct timespec start;
- clock_gettime(CLOCK_REALTIME, &start);
- return start;
-}
-#else
-#define msleep(A) usleep(A*1000)
-#define START_TIME_TYPE struct timeval
-/* TODO - unused - remove? static struct timeval start_time; */
-START_TIME_TYPE start_clock(void)
-{
- struct timeval start_time;
- gettimeofday(&start_time, NULL);
- return start_time;
-}
-#endif
-
-#define LOGA_DEBUG 0
-#define LOGA_INFO 1
-#include
-#include
-#include
-void MyLog(int LOGA_level, char* format, ...)
-{
- static char msg_buf[256];
- va_list args;
- struct timeb ts;
-
- struct tm *timeinfo;
-
- if (LOGA_level == LOGA_DEBUG && options.verbose == 0)
- return;
-
- ftime(&ts);
- timeinfo = localtime(&ts.time);
- strftime(msg_buf, 80, "%Y%m%d %H%M%S", timeinfo);
-
- sprintf(&msg_buf[strlen(msg_buf)], ".%.3hu ", ts.millitm);
-
- va_start(args, format);
- vsnprintf(&msg_buf[strlen(msg_buf)], sizeof(msg_buf) - strlen(msg_buf), format, args);
- va_end(args);
-
- printf("%s\n", msg_buf);
- fflush(stdout);
-}
-
-
-int tests = 0;
-int failures = 0;
-
-
-void myassert(char* filename, int lineno, char* description, int value, char* format, ...)
-{
- ++tests;
- if (!value)
- {
- int count;
- va_list args;
-
- ++failures;
- printf("Assertion failed, file %s, line %d, description: %s\n", filename, lineno, description);
-
- va_start(args, format);
- count = vprintf(format, args);
- va_end(args);
- if (count)
- printf("\n");
-
- //cur_output += sprintf(cur_output, "file %s, line %d \n",
- // description, filename, lineno);
- }
- else
- MyLog(LOGA_DEBUG, "Assertion succeeded, file %s, line %d, description: %s", filename, lineno, description);
-}
-
-
-#define assert(a, b, c, d) myassert(__FILE__, __LINE__, a, b, c, d)
-#define assert1(a, b, c, d, e) myassert(__FILE__, __LINE__, a, b, c, d, e)
-
-typedef struct
-{
- char* topicName;
- int topicLen;
- MQTTClient_message* m;
-} messageStruct;
-
-messageStruct messagesArrived[1000];
-int messageCount = 0;
-
-int messageArrived(void* context, char* topicName, int topicLen, MQTTClient_message* m)
-{
- messagesArrived[messageCount].topicName = topicName;
- messagesArrived[messageCount].topicLen = topicLen;
- messagesArrived[messageCount++].m = m;
- MyLog(LOGA_DEBUG, "Callback: %d message received on topic %s is %.*s.",
- messageCount, topicName, m->payloadlen, (char*)(m->payload));
- return 1;
-}
-
-
-void clearMessages()
-{
- int i;
-
- for (i = 0; i < messageCount; ++i)
- {
- MQTTClient_free(messagesArrived[i].topicName);
- MQTTClient_freeMessage(&messagesArrived[i].m);
- }
- messageCount = 0;
-}
-
-void cleanup()
-{
- // clean all client state
- char* clientids[] = {options.clientid1, options.clientid2};
- int i, rc;
- MQTTClient_connectOptions opts = MQTTClient_connectOptions_initializer;
- MQTTClient aclient;
-
- MyLog(LOGA_INFO, "Cleaning up");
-
- opts.keepAliveInterval = 20;
- opts.cleansession = 1;
- opts.username = options.username;
- opts.password = options.password;
- opts.MQTTVersion = options.MQTTVersion;
-
- for (i = 0; i < 2; ++i)
- {
- rc = MQTTClient_create(&aclient, options.connection, clientids[i], MQTTCLIENT_PERSISTENCE_DEFAULT, NULL);
- assert("good rc from create", rc == MQTTCLIENT_SUCCESS, "rc was %d\n", rc);
-
- rc = MQTTClient_connect(aclient, &opts);
- assert("Good rc from connect", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc);
-
- rc = MQTTClient_disconnect(aclient, 100);
- assert("Disconnect successful", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc);
-
- MQTTClient_destroy(&aclient);
- }
-
- // clean retained messages
- rc = MQTTClient_create(&aclient, options.connection, options.clientid1, MQTTCLIENT_PERSISTENCE_DEFAULT, NULL);
- assert("good rc from create", rc == MQTTCLIENT_SUCCESS, "rc was %d\n", rc);
-
- rc = MQTTClient_setCallbacks(aclient, NULL, NULL, messageArrived, NULL);
- assert("Good rc from setCallbacks", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc);
-
- rc = MQTTClient_connect(aclient, &opts);
- assert("Good rc from connect", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc);
-
- rc = MQTTClient_subscribe(aclient, "#", 0);
- assert("Good rc from subscribe", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc);
-
- msleep(2000); // wait for all retained messages to arrive
-
- rc = MQTTClient_unsubscribe(aclient, "#");
- assert("Good rc from unsubscribe", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc);
-
- for (i = 0; i < messageCount; ++i)
- {
- if (messagesArrived[i].m->retained)
- {
- MyLog(LOGA_INFO, "Deleting retained message for topic %s", (char*)messagesArrived[i].topicName);
- rc = MQTTClient_publish(aclient, messagesArrived[i].topicName, 0, "", 0, 1, NULL);
- assert("Good rc from publish", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc);
- }
- }
-
- rc = MQTTClient_disconnect(aclient, 100);
- assert("Disconnect successful", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc);
-
- MQTTClient_destroy(&aclient);
-
- clearMessages();
-
- MyLog(LOGA_INFO, "Finished cleaning up");
-}
-
-
-int basic_test()
-{
- int i, rc;
- MQTTClient_connectOptions opts = MQTTClient_connectOptions_initializer;
- MQTTClient aclient;
-
- MyLog(LOGA_INFO, "Starting basic test");
-
- tests = failures = 0;
-
- opts.keepAliveInterval = 20;
- opts.cleansession = 1;
- opts.username = options.username;
- opts.password = options.password;
- opts.MQTTVersion = options.MQTTVersion;
-
- rc = MQTTClient_create(&aclient, options.connection, options.clientid1, MQTTCLIENT_PERSISTENCE_DEFAULT, NULL);
- assert("good rc from create", rc == MQTTCLIENT_SUCCESS, "rc was %d\n", rc);
-
- rc = MQTTClient_setCallbacks(aclient, NULL, NULL, messageArrived, NULL);
- assert("Good rc from setCallbacks", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc);
-
- rc = MQTTClient_connect(aclient, &opts);
- assert("Good rc from connect", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc);
-
- rc = MQTTClient_disconnect(aclient, 100);
- assert("Disconnect successful", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc);
-
- rc = MQTTClient_connect(aclient, &opts);
- assert("Good rc from connect", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc);
-
- rc = MQTTClient_subscribe(aclient, topics[0], 0);
- assert("Good rc from subscribe", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc);
-
- rc = MQTTClient_publish(aclient, topics[0], 5, "qos 0", 0, 0, NULL);
- assert("Good rc from publish", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc);
-
- rc = MQTTClient_publish(aclient, topics[0], 5, "qos 1", 1, 0, NULL);
- assert("Good rc from publish", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc);
-
- rc = MQTTClient_publish(aclient, topics[0], 5, "qos 2", 2, 0, NULL);
- assert("Good rc from publish", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc);
-
- msleep(1000);
-
- rc = MQTTClient_disconnect(aclient, 10000);
- assert("Disconnect successful", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc);
-
- assert("3 Messages received", messageCount == 3, "messageCount was %d", messageCount);
- clearMessages();
-
- /*opts.MQTTVersion = MQTTVERSION_3_1;
- rc = MQTTClient_connect(aclient, &opts); // should fail - wrong protocol version
- assert("Bad rc from connect", rc == MQTTCLIENT_FAILURE, "rc was %d", rc);*/
-
- MQTTClient_destroy(&aclient);
-
- MyLog(LOGA_INFO, "Basic test %s", (failures == 0) ? "succeeded" : "failed");
- return failures;
-}
-
-
-
-int offline_message_queueing_test()
-{
- int i, rc;
- MQTTClient_connectOptions opts = MQTTClient_connectOptions_initializer;
- MQTTClient aclient;
- MQTTClient bclient;
-
- MyLog(LOGA_INFO, "Offline message queueing test");
-
- tests = failures = 0;
-
- opts.keepAliveInterval = 20;
- opts.cleansession = 0;
- opts.username = options.username;
- opts.password = options.password;
- opts.MQTTVersion = options.MQTTVersion;
-
- rc = MQTTClient_create(&aclient, options.connection, options.clientid1, MQTTCLIENT_PERSISTENCE_DEFAULT, NULL);
- assert("good rc from create", rc == MQTTCLIENT_SUCCESS, "rc was %d\n", rc);
-
- rc = MQTTClient_setCallbacks(aclient, NULL, NULL, messageArrived, NULL);
- assert("Good rc from setCallbacks", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc);
-
- rc = MQTTClient_connect(aclient, &opts);
- assert("Good rc from connect", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc);
-
- rc = MQTTClient_subscribe(aclient, wildtopics[5], 2);
- assert("Good rc from subscribe", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc);
-
- rc = MQTTClient_disconnect(aclient, 100);
- assert("Disconnect successful", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc);
-
- rc = MQTTClient_create(&bclient, options.connection, options.clientid2, MQTTCLIENT_PERSISTENCE_DEFAULT, NULL);
- assert("good rc from create", rc == MQTTCLIENT_SUCCESS, "rc was %d\n", rc);
-
- opts.cleansession = 1;
- rc = MQTTClient_connect(bclient, &opts);
- assert("Good rc from connect", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc);
-
- rc = MQTTClient_publish(bclient, topics[1], 5, "qos 0", 0, 0, NULL);
- assert("Good rc from publish", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc);
-
- rc = MQTTClient_publish(bclient, topics[2], 5, "qos 1", 1, 0, NULL);
- assert("Good rc from publish", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc);
-
- rc = MQTTClient_publish(bclient, topics[3], 5, "qos 2", 2, 0, NULL);
- assert("Good rc from publish", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc);
-
- msleep(2000);
-
- rc = MQTTClient_disconnect(bclient, 100);
- assert("Disconnect successful", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc);
-
- MQTTClient_destroy(&bclient);
-
- opts.cleansession = 0;
- rc = MQTTClient_connect(aclient, &opts);
- assert("Good rc from connect", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc);
-
- msleep(1000); // receive the queued messages
-
- rc = MQTTClient_disconnect(aclient, 100);
- assert("Disconnect successful", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc);
-
- MQTTClient_destroy(&aclient);
-
- assert("2 or 3 messages received", messageCount == 3 || messageCount == 2, "messageCount was %d", messageCount);
-
- MyLog(LOGA_INFO, "This server %s queueing QoS 0 messages for offline clients", (messageCount == 3) ? "is" : "is not");
-
- clearMessages();
-
- MyLog(LOGA_INFO, "Offline message queueing test %s", (failures == 0) ? "succeeded" : "failed");
- return failures;
-}
-
-
-int retained_message_test()
-{
- int i, rc;
- MQTTClient_connectOptions opts = MQTTClient_connectOptions_initializer;
- MQTTClient aclient;
-
- MyLog(LOGA_INFO, "Retained message test");
-
- tests = failures = 0;
-
- opts.keepAliveInterval = 20;
- opts.cleansession = 1;
- opts.username = options.username;
- opts.password = options.password;
- opts.MQTTVersion = options.MQTTVersion;
-
- assert("0 messages received", messageCount == 0, "messageCount was %d", messageCount);
-
- // set retained messages
- rc = MQTTClient_create(&aclient, options.connection, options.clientid1, MQTTCLIENT_PERSISTENCE_DEFAULT, NULL);
- assert("good rc from create", rc == MQTTCLIENT_SUCCESS, "rc was %d\n", rc);
-
- rc = MQTTClient_setCallbacks(aclient, NULL, NULL, messageArrived, NULL);
- assert("Good rc from setCallbacks", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc);
-
- rc = MQTTClient_connect(aclient, &opts);
- assert("Good rc from connect", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc);
-
- rc = MQTTClient_publish(aclient, topics[1], 5, "qos 0", 0, 1, NULL);
- assert("Good rc from publish", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc);
-
- rc = MQTTClient_publish(aclient, topics[2], 5, "qos 1", 1, 1, NULL);
- assert("Good rc from publish", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc);
-
- rc = MQTTClient_publish(aclient, topics[3], 5, "qos 2", 2, 1, NULL);
- assert("Good rc from publish", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc);
-
- msleep(1000);
-
- rc = MQTTClient_subscribe(aclient, wildtopics[5], 2);
- assert("Good rc from subscribe", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc);
-
- msleep(2000);
-
- rc = MQTTClient_disconnect(aclient, 100);
- assert("Disconnect successful", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc);
-
- assert("3 messages received", messageCount == 3, "messageCount was %d", messageCount);
-
- for (i = 0; i < messageCount; ++i)
- {
- assert("messages should be retained", messagesArrived[i].m->retained, "retained was %d",
- messagesArrived[i].m->retained);
- MQTTClient_free(messagesArrived[i].topicName);
- MQTTClient_freeMessage(&messagesArrived[i].m);
- }
- messageCount = 0;
-
- // clear retained messages
- rc = MQTTClient_connect(aclient, &opts);
- assert("Good rc from connect", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc);
-
- rc = MQTTClient_publish(aclient, topics[1], 0, "", 0, 1, NULL);
- assert("Good rc from publish", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc);
-
- rc = MQTTClient_publish(aclient, topics[2], 0, "", 1, 1, NULL);
- assert("Good rc from publish", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc);
-
- rc = MQTTClient_publish(aclient, topics[3], 0, "", 2, 1, NULL);
- assert("Good rc from publish", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc);
-
- msleep(200); // wait for QoS 2 exchange to be completed
- rc = MQTTClient_subscribe(aclient, wildtopics[5], 2);
- assert("Good rc from subscribe", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc);
-
- msleep(200);
-
- rc = MQTTClient_disconnect(aclient, 100);
- assert("Disconnect successful", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc);
-
- assert("0 messages received", messageCount == 0, "messageCount was %d", messageCount);
-
- MQTTClient_destroy(&aclient);
-
- MyLog(LOGA_INFO, "Retained message test %s", (failures == 0) ? "succeeded" : "failed");
- return failures;
-}
-
-#define SOCKET_ERROR -1
-
-int test6_socket_error(char* aString, int sock)
-{
-#if defined(WIN32)
- int errno;
-#endif
-
-#if defined(WIN32)
- errno = WSAGetLastError();
-#endif
- if (errno != EINTR && errno != EAGAIN && errno != EINPROGRESS && errno != EWOULDBLOCK)
- {
- if (strcmp(aString, "shutdown") != 0 || (errno != ENOTCONN && errno != ECONNRESET))
- printf("Socket error %d in %s for socket %d", errno, aString, sock);
- }
- return errno;
-}
-
-int test6_socket_close(int socket)
-{
- int rc;
-
-#if defined(WIN32)
- if (shutdown(socket, SD_BOTH) == SOCKET_ERROR)
- test6_socket_error("shutdown", socket);
- if ((rc = closesocket(socket)) == SOCKET_ERROR)
- test6_socket_error("close", socket);
-#else
- if (shutdown(socket, SHUT_RDWR) == SOCKET_ERROR)
- test6_socket_error("shutdown", socket);
- if ((rc = close(socket)) == SOCKET_ERROR)
- test6_socket_error("close", socket);
-#endif
- return rc;
-}
-
-typedef struct
-{
- int socket;
- time_t lastContact;
-#if defined(OPENSSL)
- SSL* ssl;
- SSL_CTX* ctx;
-#endif
-} networkHandles;
-
-
-typedef struct
-{
- char* clientID; /**< the string id of the client */
- char* username; /**< MQTT v3.1 user name */
- char* password; /**< MQTT v3.1 password */
- unsigned int cleansession : 1; /**< MQTT clean session flag */
- unsigned int connected : 1; /**< whether it is currently connected */
- unsigned int good : 1; /**< if we have an error on the socket we turn this off */
- unsigned int ping_outstanding : 1;
- int connect_state : 4;
- networkHandles net;
-/* ... */
-} Clients;
-
-
-typedef struct
-{
- char* serverURI;
- Clients* c;
- MQTTClient_connectionLost* cl;
- MQTTClient_messageArrived* ma;
- MQTTClient_deliveryComplete* dc;
- void* context;
-
- int connect_sem;
- int rc; /* getsockopt return code in connect */
- int connack_sem;
- int suback_sem;
- int unsuback_sem;
- void* pack;
-} MQTTClients;
-
-
-int will_message_test()
-{
- int i, rc, count = 0;
- MQTTClient_connectOptions opts = MQTTClient_connectOptions_initializer;
- MQTTClient_willOptions wopts = MQTTClient_willOptions_initializer;
- MQTTClient aclient, bclient;
-
- MyLog(LOGA_INFO, "Will message test");
-
- tests = failures = 0;
-
- opts.keepAliveInterval = 2;
- opts.cleansession = 1;
- opts.username = options.username;
- opts.password = options.password;
- opts.MQTTVersion = options.MQTTVersion;
-
- opts.will = &wopts;
- opts.will->message = "client not disconnected";
- opts.will->qos = 1;
- opts.will->retained = 0;
- opts.will->topicName = topics[2];
-
- rc = MQTTClient_create(&aclient, options.connection, options.clientid1, MQTTCLIENT_PERSISTENCE_DEFAULT, NULL);
- assert("good rc from create", rc == MQTTCLIENT_SUCCESS, "rc was %d\n", rc);
-
- rc = MQTTClient_connect(aclient, &opts);
- assert("Good rc from connect", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc);
-
- rc = MQTTClient_create(&bclient, options.connection, options.clientid2, MQTTCLIENT_PERSISTENCE_DEFAULT, NULL);
- assert("good rc from create", rc == MQTTCLIENT_SUCCESS, "rc was %d\n", rc);
-
- rc = MQTTClient_setCallbacks(bclient, NULL, NULL, messageArrived, NULL);
- assert("Good rc from setCallbacks", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc);
-
- opts.keepAliveInterval = 20;
- opts.will = NULL;
- rc = MQTTClient_connect(bclient, &opts);
- assert("Good rc from connect", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc);
-
- rc = MQTTClient_subscribe(bclient, topics[2], 2);
- assert("Good rc from subscribe", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc);
-
- msleep(100);
-
- test6_socket_close(((MQTTClients*)aclient)->c->net.socket);
-
- while (messageCount == 0 && ++count < 10)
- msleep(1000);
-
- rc = MQTTClient_disconnect(bclient, 100);
- assert("Disconnect successful", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc);
-
- MQTTClient_destroy(&bclient);
-
- assert("will message received", messageCount == 1, "messageCount was %d", messageCount);
-
- rc = MQTTClient_disconnect(aclient, 100);
-
- MQTTClient_destroy(&aclient);
-
- MyLog(LOGA_INFO, "Will message test %s", (failures == 0) ? "succeeded" : "failed");
- return failures;
-}
-
-
-int overlapping_subscriptions_test()
-{
- /* overlapping subscriptions. When there is more than one matching subscription for the same client for a topic,
- the server may send back one message with the highest QoS of any matching subscription, or one message for
- each subscription with a matching QoS. */
-
- int i, rc;
- MQTTClient_connectOptions opts = MQTTClient_connectOptions_initializer;
- MQTTClient aclient;
- char* topicList[] = {wildtopics[6], wildtopics[0]};
- int qosList[] = {2, 1};
-
- MyLog(LOGA_INFO, "Starting overlapping subscriptions test");
-
- clearMessages();
- tests = failures = 0;
-
- opts.keepAliveInterval = 20;
- opts.cleansession = 1;
- opts.username = options.username;
- opts.password = options.password;
- opts.MQTTVersion = options.MQTTVersion;
-
- rc = MQTTClient_create(&aclient, options.connection, options.clientid1, MQTTCLIENT_PERSISTENCE_DEFAULT, NULL);
- assert("good rc from create", rc == MQTTCLIENT_SUCCESS, "rc was %d\n", rc);
-
- rc = MQTTClient_setCallbacks(aclient, NULL, NULL, messageArrived, NULL);
- assert("Good rc from setCallbacks", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc);
-
- rc = MQTTClient_connect(aclient, &opts);
- assert("Good rc from connect", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc);
-
- rc = MQTTClient_subscribeMany(aclient, 2, topicList, qosList);
- assert("Good rc from subscribe", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc);
-
- rc = MQTTClient_publish(aclient, topics[3], strlen("overlapping topic filters") + 1,
- "overlapping topic filters", 2, 0, NULL);
- assert("Good rc from publish", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc);
-
- msleep(1000);
-
- assert("1 or 2 messages received", messageCount == 1 || messageCount == 2, "messageCount was %d", messageCount);
-
- if (messageCount == 1)
- {
- MyLog(LOGA_INFO, "This server is publishing one message for all matching overlapping subscriptions, not one for each.");
- assert("QoS should be 2", messagesArrived[0].m->qos == 2, "QoS was %d", messagesArrived[0].m->qos);
- }
- else
- {
- MyLog(LOGA_INFO, "This server is publishing one message per each matching overlapping subscription.");
- assert1("QoSs should be 1 and 2",
- (messagesArrived[0].m->qos == 2 && messagesArrived[1].m->qos == 1) ||
- (messagesArrived[0].m->qos == 1 && messagesArrived[1].m->qos == 2),
- "QoSs were %d %d", messagesArrived[0].m->qos, messagesArrived[1].m->qos);
- }
-
- rc = MQTTClient_disconnect(aclient, 100);
-
- MQTTClient_destroy(&aclient);
-
- MyLog(LOGA_INFO, "Overlapping subscription test %s", (failures == 0) ? "succeeded" : "failed");
- return failures;
-}
-
-
-int keepalive_test()
-{
- /* keepalive processing. We should be kicked off by the server if we don't send or receive any data, and don't send
- any pings either. */
-
- int i, rc, count = 0;
- MQTTClient_connectOptions opts = MQTTClient_connectOptions_initializer;
- MQTTClient_willOptions wopts = MQTTClient_willOptions_initializer;
- MQTTClient aclient, bclient;
-
- MyLog(LOGA_INFO, "Starting keepalive test");
-
- tests = failures = 0;
- clearMessages();
-
- opts.cleansession = 1;
- opts.username = options.username;
- opts.password = options.password;
- opts.MQTTVersion = options.MQTTVersion;
-
- opts.will = &wopts;
- opts.will->message = "keepalive expiry";
- opts.will->qos = 1;
- opts.will->retained = 0;
- opts.will->topicName = topics[4];
-
- opts.keepAliveInterval = 20;
- rc = MQTTClient_create(&bclient, options.connection, options.clientid2, MQTTCLIENT_PERSISTENCE_DEFAULT, NULL);
- assert("good rc from create", rc == MQTTCLIENT_SUCCESS, "rc was %d\n", rc);
-
- rc = MQTTClient_setCallbacks(bclient, NULL, NULL, messageArrived, NULL);
- assert("Good rc from setCallbacks", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc);
-
- rc = MQTTClient_connect(bclient, &opts);
- assert("Good rc from connect", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc);
-
- rc = MQTTClient_subscribe(bclient, topics[4], 2);
- assert("Good rc from subscribe", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc);
-
- opts.keepAliveInterval = 2;
- rc = MQTTClient_create(&aclient, options.connection, options.clientid1, MQTTCLIENT_PERSISTENCE_DEFAULT, NULL);
- assert("good rc from create", rc == MQTTCLIENT_SUCCESS, "rc was %d\n", rc);
-
- rc = MQTTClient_connect(aclient, &opts);
- assert("Good rc from connect", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc);
-
- while (messageCount == 0 && ++count < 20)
- msleep(1000);
-
- rc = MQTTClient_disconnect(bclient, 100);
- assert("Disconnect successful", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc);
-
- assert("Should have will message", messageCount == 1, "messageCount was %d", messageCount);
-
- rc = MQTTClient_disconnect(aclient, 100);
-
- MQTTClient_destroy(&aclient);
-
- MyLog(LOGA_INFO, "Keepalive test %s", (failures == 0) ? "succeeded" : "failed");
- return failures;
-}
-
-
-
-int redelivery_on_reconnect_test()
-{
- /* redelivery on reconnect. When a QoS 1 or 2 exchange has not been completed, the server should retry the
- appropriate MQTT packets */
-
- int i, rc, count = 0;
- MQTTClient_connectOptions opts = MQTTClient_connectOptions_initializer;
- MQTTClient aclient;
-
- MyLog(LOGA_INFO, "Starting redelivery on reconnect test");
-
- tests = failures = 0;
- clearMessages();
-
- opts.keepAliveInterval = 0;
- opts.cleansession = 0;
- opts.username = options.username;
- opts.password = options.password;
- opts.MQTTVersion = options.MQTTVersion;
-
- rc = MQTTClient_create(&aclient, options.connection, options.clientid1, MQTTCLIENT_PERSISTENCE_DEFAULT, NULL);
- assert("good rc from create", rc == MQTTCLIENT_SUCCESS, "rc was %d\n", rc);
-
- rc = MQTTClient_connect(aclient, &opts);
- assert("Good rc from connect", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc);
-
- rc = MQTTClient_subscribe(aclient, wildtopics[6], 2);
- assert("Good rc from subscribe", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc);
- MQTTClient_yield();
-
- // no background processing because no callback has been set
- rc = MQTTClient_publish(aclient, topics[1], 6, "qos 1", 2, 0, NULL);
- assert("Good rc from publish", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc);
-
- rc = MQTTClient_publish(aclient, topics[3], 6, "qos 2", 2, 0, NULL);
- assert("Good rc from publish", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc);
-
- rc = MQTTClient_disconnect(aclient, 0);
-
- assert("No messages should have been received yet", messageCount == 0, "messageCount was %d", messageCount);
-
- rc = MQTTClient_setCallbacks(aclient, NULL, NULL, messageArrived, NULL);
- assert("Good rc from setCallbacks", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc);
-
- rc = MQTTClient_connect(aclient, &opts);
- assert("Good rc from connect", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc);
-
- while (messageCount < 2 && ++count < 5)
- msleep(1000);
-
- assert("Should have 2 messages", messageCount == 2, "messageCount was %d", messageCount);
-
- rc = MQTTClient_disconnect(aclient, 100);
-
- MQTTClient_destroy(&aclient);
-
- MyLog(LOGA_INFO, "Redelivery on reconnect test %s", (failures == 0) ? "succeeded" : "failed");
- return failures;
-}
-
-
-
-int zero_length_clientid_test()
-{
- int i, rc, count = 0;
- MQTTClient_connectOptions opts = MQTTClient_connectOptions_initializer;
- MQTTClient aclient;
-
- MyLog(LOGA_INFO, "Starting zero length clientid test");
-
- tests = failures = 0;
- clearMessages();
-
- opts.keepAliveInterval = 0;
- opts.cleansession = 0;
- opts.username = options.username;
- opts.password = options.password;
- opts.MQTTVersion = options.MQTTVersion;
-
- rc = MQTTClient_create(&aclient, options.connection, "", MQTTCLIENT_PERSISTENCE_DEFAULT, NULL);
- assert("good rc from create", rc == MQTTCLIENT_SUCCESS, "rc was %d\n", rc);
-
- rc = MQTTClient_connect(aclient, &opts);
- assert("rc 2 from connect", rc == 2, "rc was %d", rc); // this should always fail
-
- opts.cleansession = 1;
- rc = MQTTClient_connect(aclient, &opts);
- assert("Connack rc should be 0 or 2", rc == MQTTCLIENT_SUCCESS || rc == 2, "rc was %d", rc);
-
- MyLog(LOGA_INFO, "This server %s support zero length clientids", (rc == 2) ? "does not" : "does");
-
- if (rc == MQTTCLIENT_SUCCESS)
- rc = MQTTClient_disconnect(aclient, 100);
-
- MQTTClient_destroy(&aclient);
-
- MyLog(LOGA_INFO, "Zero length clientid test %s", (failures == 0) ? "succeeded" : "failed");
- return failures;
-}
-
-
-int dollar_topics_test()
-{
- /* $ topics. The specification says that a topic filter which starts with a wildcard does not match topic names that
- begin with a $. Publishing to a topic which starts with a $ may not be allowed on some servers (which is entirely valid),
- so this test will not work and should be omitted in that case.
- */
- int i, rc, count = 0;
- MQTTClient_connectOptions opts = MQTTClient_connectOptions_initializer;
- MQTTClient aclient;
- char dollartopic[20];
-
- MyLog(LOGA_INFO, "Starting $ topics test");
-
- sprintf(dollartopic, "$%s", topics[1]);
-
- clearMessages();
-
- opts.keepAliveInterval = 5;
- opts.cleansession = 1;
- opts.username = options.username;
- opts.password = options.password;
- opts.MQTTVersion = options.MQTTVersion;
-
- rc = MQTTClient_create(&aclient, options.connection, options.clientid1, MQTTCLIENT_PERSISTENCE_DEFAULT, NULL);
- assert("good rc from create", rc == MQTTCLIENT_SUCCESS, "rc was %d\n", rc);
-
- rc = MQTTClient_setCallbacks(aclient, NULL, NULL, messageArrived, NULL);
- assert("Good rc from setCallbacks", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc);
-
- rc = MQTTClient_connect(aclient, &opts);
- assert("Good rc from connect", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc);
-
- rc = MQTTClient_subscribe(aclient, wildtopics[5], 2);
- assert("Good rc from subscribe", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc);
-
- msleep(1000); // wait for any retained messages, hopefully
- clearMessages();
-
- rc = MQTTClient_publish(aclient, topics[1], 20, "not sent to dollar topic", 1, 0, NULL);
- assert("Good rc from publish", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc);
-
- rc = MQTTClient_publish(aclient, dollartopic, 20, "sent to dollar topic", 1, 0, NULL);
- assert("Good rc from publish", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc);
-
- msleep(1000);
- assert("Should have 1 message", messageCount == 1, "messageCount was %d", messageCount);
-
- rc = MQTTClient_disconnect(aclient, 100);
- assert("Disconnect successful", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc);
-
- MQTTClient_destroy(&aclient);
-
- MyLog(LOGA_INFO, "$ topics test %s", (failures == 0) ? "succeeded" : "failed");
- return failures;
-}
-
-
-int subscribe_failure_test()
-{
- /* Subscribe failure. A new feature of MQTT 3.1.1 is the ability to send back negative reponses to subscribe
- requests. One way of doing this is to subscribe to a topic which is not allowed to be subscribed to.
- */
- int i, rc, count = 0;
- MQTTClient_connectOptions opts = MQTTClient_connectOptions_initializer;
- MQTTClient aclient;
- int subqos = 2;
-
- MyLog(LOGA_INFO, "Starting subscribe failure test");
-
- clearMessages();
-
- opts.keepAliveInterval = 5;
- opts.cleansession = 1;
- opts.username = options.username;
- opts.password = options.password;
- opts.MQTTVersion = options.MQTTVersion;
-
- rc = MQTTClient_create(&aclient, options.connection, options.clientid1, MQTTCLIENT_PERSISTENCE_DEFAULT, NULL);
- assert("good rc from create", rc == MQTTCLIENT_SUCCESS, "rc was %d\n", rc);
-
- rc = MQTTClient_setCallbacks(aclient, NULL, NULL, messageArrived, NULL);
- assert("Good rc from setCallbacks", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc);
-
- rc = MQTTClient_connect(aclient, &opts);
- assert("Good rc from connect", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc);
-
- rc = MQTTClient_subscribeMany(aclient, 1, &nosubscribe_topics[0], &subqos);
- assert("Good rc from subscribe", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc);
- assert("0x80 rc from subscribe", subqos == 0x80, "subqos was %d", subqos);
-
- rc = MQTTClient_disconnect(aclient, 100);
- assert("Disconnect successful", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc);
-
- MQTTClient_destroy(&aclient);
-
- MyLog(LOGA_INFO, "Subscribe failure test %s", (failures == 0) ? "succeeded" : "failed");
- return failures;
-}
-
-
-int main(int argc, char** argv)
-{
- int i;
- int all_failures = 0;
-
- getopts(argc, argv);
-
- for (i = 0; i < options.iterations; ++i)
- {
- cleanup();
- all_failures += basic_test() +
- offline_message_queueing_test() +
- retained_message_test() +
- will_message_test() +
- overlapping_subscriptions_test() +
- keepalive_test() +
- redelivery_on_reconnect_test() +
- zero_length_clientid_test();
-
- if (options.run_dollar_topics_test)
- all_failures += dollar_topics_test();
-
- if (options.run_subscribe_failure_test)
- all_failures += subscribe_failure_test();
- }
-
- MyLog(LOGA_INFO, "Test suite %s", (all_failures == 0) ? "succeeded" : "failed");
-}
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/org.eclipse.paho.mqtt.c/test/test1.c b/org.eclipse.paho.mqtt.c/test/test1.c
deleted file mode 100644
index b0e18e7..0000000
--- a/org.eclipse.paho.mqtt.c/test/test1.c
+++ /dev/null
@@ -1,1168 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2009, 2014 IBM Corp.
- *
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * and Eclipse Distribution License v1.0 which accompany this distribution.
- *
- * The Eclipse Public License is available at
- * http://www.eclipse.org/legal/epl-v10.html
- * and the Eclipse Distribution License is available at
- * http://www.eclipse.org/org/documents/edl-v10.php.
- *
- * Contributors:
- * Ian Craggs - initial API and implementation and/or initial documentation
- * Ian Craggs - MQTT 3.1.1 support
- *******************************************************************************/
-
-
-/**
- * @file
- * Tests for the MQ Telemetry MQTT C client
- */
-
-
-/*
-#if !defined(_RTSHEADER)
- #include
-#endif
-*/
-
-#include "MQTTClient.h"
-#include
-#include
-
-#if !defined(_WINDOWS)
- #include
- #include
- #include
- #include
-#else
-#include
-#include
-#define MAXHOSTNAMELEN 256
-#define EAGAIN WSAEWOULDBLOCK
-#define EINTR WSAEINTR
-#define EINPROGRESS WSAEINPROGRESS
-#define EWOULDBLOCK WSAEWOULDBLOCK
-#define ENOTCONN WSAENOTCONN
-#define ECONNRESET WSAECONNRESET
-#define setenv(a, b, c) _putenv_s(a, b)
-#endif
-
-#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
-
-void usage()
-{
- printf("help!!\n");
- exit(-1);
-}
-
-struct Options
-{
- char* connection; /**< connection to system under test. */
- char** haconnections;
- int hacount;
- int verbose;
- int test_no;
- int MQTTVersion;
- int iterations;
-} options =
-{
- "tcp://m2m.eclipse.org:1883",
- NULL,
- 0,
- 0,
- 0,
- MQTTVERSION_DEFAULT,
- 1,
-};
-
-void getopts(int argc, char** argv)
-{
- int count = 1;
-
- while (count < argc)
- {
- if (strcmp(argv[count], "--test_no") == 0)
- {
- if (++count < argc)
- options.test_no = atoi(argv[count]);
- else
- usage();
- }
- else if (strcmp(argv[count], "--connection") == 0)
- {
- if (++count < argc)
- {
- options.connection = argv[count];
- printf("\nSetting connection to %s\n", options.connection);
- }
- else
- usage();
- }
- else if (strcmp(argv[count], "--haconnections") == 0)
- {
- if (++count < argc)
- {
- char* tok = strtok(argv[count], " ");
- options.hacount = 0;
- options.haconnections = malloc(sizeof(char*) * 5);
- while (tok)
- {
- options.haconnections[options.hacount] = malloc(strlen(tok) + 1);
- strcpy(options.haconnections[options.hacount], tok);
- options.hacount++;
- tok = strtok(NULL, " ");
- }
- }
- 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;
- printf("\nSetting verbose on\n");
- }
- count++;
- }
-}
-
-
-#define LOGA_DEBUG 0
-#define LOGA_INFO 1
-#include
-#include
-#include
-void MyLog(int LOGA_level, char* format, ...)
-{
- static char msg_buf[256];
- va_list args;
- struct timeb ts;
-
- struct tm *timeinfo;
-
- if (LOGA_level == LOGA_DEBUG && options.verbose == 0)
- return;
-
- ftime(&ts);
- timeinfo = localtime(&ts.time);
- strftime(msg_buf, 80, "%Y%m%d %H%M%S", timeinfo);
-
- sprintf(&msg_buf[strlen(msg_buf)], ".%.3hu ", ts.millitm);
-
- va_start(args, format);
- vsnprintf(&msg_buf[strlen(msg_buf)], sizeof(msg_buf) - strlen(msg_buf), format, args);
- va_end(args);
-
- printf("%s\n", msg_buf);
- fflush(stdout);
-}
-
-
-#if defined(WIN32) || defined(_WINDOWS)
-#define mqsleep(A) Sleep(1000*A)
-#define START_TIME_TYPE DWORD
-static DWORD start_time = 0;
-START_TIME_TYPE start_clock(void)
-{
- return GetTickCount();
-}
-#elif defined(AIX)
-#define mqsleep sleep
-#define START_TIME_TYPE struct timespec
-START_TIME_TYPE start_clock(void)
-{
- static struct timespec start;
- clock_gettime(CLOCK_REALTIME, &start);
- return start;
-}
-#else
-#define mqsleep sleep
-#define START_TIME_TYPE struct timeval
-/* TODO - unused - remove? static struct timeval start_time; */
-START_TIME_TYPE start_clock(void)
-{
- struct timeval start_time;
- gettimeofday(&start_time, NULL);
- return start_time;
-}
-#endif
-
-
-#if defined(WIN32)
-long elapsed(START_TIME_TYPE start_time)
-{
- return GetTickCount() - start_time;
-}
-#elif defined(AIX)
-#define assert(a)
-long elapsed(struct timespec start)
-{
- struct timespec now, res;
-
- clock_gettime(CLOCK_REALTIME, &now);
- ntimersub(now, start, res);
- return (res.tv_sec)*1000L + (res.tv_nsec)/1000000L;
-}
-#else
-long elapsed(START_TIME_TYPE start_time)
-{
- struct timeval now, res;
-
- gettimeofday(&now, NULL);
- timersub(&now, &start_time, &res);
- return (res.tv_sec)*1000 + (res.tv_usec)/1000;
-}
-#endif
-
-
-#define assert(a, b, c, d) myassert(__FILE__, __LINE__, a, b, c, d)
-#define assert1(a, b, c, d, e) myassert(__FILE__, __LINE__, a, b, c, d, e)
-
-int tests = 0;
-int failures = 0;
-FILE* xml;
-START_TIME_TYPE global_start_time;
-char output[3000];
-char* cur_output = output;
-
-
-void write_test_result()
-{
- long duration = elapsed(global_start_time);
-
- fprintf(xml, " time=\"%ld.%.3ld\" >\n", duration / 1000, duration % 1000);
- if (cur_output != output)
- {
- fprintf(xml, "%s", output);
- cur_output = output;
- }
- fprintf(xml, "\n");
-}
-
-
-void myassert(char* filename, int lineno, char* description, int value, char* format, ...)
-{
- ++tests;
- if (!value)
- {
- va_list args;
-
- ++failures;
- MyLog(LOGA_INFO, "Assertion failed, file %s, line %d, description: %s\n", filename, lineno, description);
-
- va_start(args, format);
- vprintf(format, args);
- va_end(args);
-
- cur_output += sprintf(cur_output, "file %s, line %d \n",
- description, filename, lineno);
- }
- else
- MyLog(LOGA_DEBUG, "Assertion succeeded, file %s, line %d, description: %s", filename, lineno, description);
-}
-
-
-/*********************************************************************
-
-Test1: single-threaded client
-
-*********************************************************************/
-void test1_sendAndReceive(MQTTClient* c, int qos, char* test_topic)
-{
- MQTTClient_deliveryToken dt;
- MQTTClient_message pubmsg = MQTTClient_message_initializer;
- MQTTClient_message* m = NULL;
- char* topicName = NULL;
- int topicLen;
- int i = 0;
- int iterations = 50;
- int rc;
-
- MyLog(LOGA_DEBUG, "%d messages at QoS %d", iterations, qos);
- pubmsg.payload = "a much longer message that we can shorten to the extent that we need to payload up to 11";
- pubmsg.payloadlen = 11;
- pubmsg.qos = qos;
- pubmsg.retained = 0;
-
- for (i = 0; i< iterations; ++i)
- {
- if (i % 10 == 0)
- rc = MQTTClient_publish(c, test_topic, pubmsg.payloadlen, pubmsg.payload, pubmsg.qos, pubmsg.retained, &dt);
- else
- rc = MQTTClient_publishMessage(c, test_topic, &pubmsg, &dt);
- assert("Good rc from publish", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc);
-
- if (qos > 0)
- {
- rc = MQTTClient_waitForCompletion(c, dt, 1000L);
- assert("Good rc from waitforCompletion", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc);
- }
-
- rc = MQTTClient_receive(c, &topicName, &topicLen, &m, 1000);
- assert("Good rc from receive", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc);
- if (topicName)
- {
- MyLog(LOGA_DEBUG, "Message received on topic %s is %.*s", topicName, m->payloadlen, (char*)(m->payload));
- if (pubmsg.payloadlen != m->payloadlen ||
- memcmp(m->payload, pubmsg.payload, m->payloadlen) != 0)
- {
- failures++;
- MyLog(LOGA_INFO, "Error: wrong data - received lengths %d %d", pubmsg.payloadlen, m->payloadlen);
- break;
- }
- MQTTClient_free(topicName);
- MQTTClient_freeMessage(&m);
- }
- else
- printf("No message received within timeout period\n");
- }
-
- /* receive any outstanding messages */
- MQTTClient_receive(c, &topicName, &topicLen, &m, 1000);
- while (topicName)
- {
- printf("Message received on topic %s is %.*s.\n", topicName, m->payloadlen, (char*)(m->payload));
- MQTTClient_free(topicName);
- MQTTClient_freeMessage(&m);
- MQTTClient_receive(c, &topicName, &topicLen, &m, 1000);
- }
-}
-
-
-int test1(struct Options options)
-{
- int subsqos = 2;
- MQTTClient c;
- MQTTClient_connectOptions opts = MQTTClient_connectOptions_initializer;
- MQTTClient_willOptions wopts = MQTTClient_willOptions_initializer;
- int rc = 0;
- char* test_topic = "C client test1";
-
- fprintf(xml, "message = "will message";
- opts.will->qos = 1;
- opts.will->retained = 0;
- opts.will->topicName = "will topic";
- opts.will = NULL;
-
- MyLog(LOGA_DEBUG, "Connecting");
- rc = MQTTClient_connect(c, &opts);
- assert("Good rc from connect", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc);
- if (rc != MQTTCLIENT_SUCCESS)
- goto exit;
-
- rc = MQTTClient_subscribe(c, test_topic, subsqos);
- assert("Good rc from subscribe", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc);
-
- test1_sendAndReceive(c, 0, test_topic);
- test1_sendAndReceive(c, 1, test_topic);
- test1_sendAndReceive(c, 2, test_topic);
-
- MyLog(LOGA_DEBUG, "Stopping\n");
-
- rc = MQTTClient_unsubscribe(c, test_topic);
- assert("Unsubscribe successful", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc);
- rc = MQTTClient_disconnect(c, 0);
- assert("Disconnect successful", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc);
-
- /* Just to make sure we can connect again */
- rc = MQTTClient_connect(c, &opts);
- assert("Connect successful", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc);
- rc = MQTTClient_disconnect(c, 0);
- assert("Disconnect successful", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc);
-
- MQTTClient_destroy(&c);
-
-exit:
- MyLog(LOGA_INFO, "TEST1: test %s. %d tests run, %d failures.",
- (failures == 0) ? "passed" : "failed", tests, failures);
- write_test_result();
- return failures;
-}
-
-
-/*********************************************************************
-
-Test2: multi-threaded client using callbacks
-
-*********************************************************************/
-volatile int test2_arrivedcount = 0;
-int test2_deliveryCompleted = 0;
-MQTTClient_message test2_pubmsg = MQTTClient_message_initializer;
-
-void test2_deliveryComplete(void* context, MQTTClient_deliveryToken dt)
-{
- ++test2_deliveryCompleted;
-}
-
-int test2_messageArrived(void* context, char* topicName, int topicLen, MQTTClient_message* m)
-{
- ++test2_arrivedcount;
- MyLog(LOGA_DEBUG, "Callback: %d message received on topic %s is %.*s.",
- test2_arrivedcount, topicName, m->payloadlen, (char*)(m->payload));
- if (test2_pubmsg.payloadlen != m->payloadlen ||
- memcmp(m->payload, test2_pubmsg.payload, m->payloadlen) != 0)
- {
- failures++;
- MyLog(LOGA_INFO, "Error: wrong data received lengths %d %d\n", test2_pubmsg.payloadlen, m->payloadlen);
- }
- MQTTClient_free(topicName);
- MQTTClient_freeMessage(&m);
- return 1;
-}
-
-
-void test2_sendAndReceive(MQTTClient* c, int qos, char* test_topic)
-{
- MQTTClient_deliveryToken dt;
- int i = 0;
- int iterations = 50;
- int rc = 0;
- int wait_seconds = 0;
-
- test2_deliveryCompleted = 0;
-
- MyLog(LOGA_INFO, "%d messages at QoS %d", iterations, qos);
- test2_pubmsg.payload = "a much longer message that we can shorten to the extent that we need to";
- test2_pubmsg.payloadlen = 27;
- test2_pubmsg.qos = qos;
- test2_pubmsg.retained = 0;
-
- for (i = 1; i <= iterations; ++i)
- {
- if (i % 10 == 0)
- rc = MQTTClient_publish(c, test_topic, test2_pubmsg.payloadlen, test2_pubmsg.payload,
- test2_pubmsg.qos, test2_pubmsg.retained, NULL);
- else
- rc = MQTTClient_publishMessage(c, test_topic, &test2_pubmsg, &dt);
- assert("Good rc from publish", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc);
-
- #if defined(WIN32)
- Sleep(100);
- #else
- usleep(100000L);
- #endif
-
- wait_seconds = 10;
- while ((test2_arrivedcount < i) && (wait_seconds-- > 0))
- {
- MyLog(LOGA_DEBUG, "Arrived %d count %d", test2_arrivedcount, i);
- #if defined(WIN32)
- Sleep(1000);
- #else
- usleep(1000000L);
- #endif
- }
- assert("Message Arrived", wait_seconds > 0,
- "Time out waiting for message %d\n", i );
- }
- if (qos > 0)
- {
- /* MQ Telemetry can send a message to a subscriber before the server has
- completed the QoS 2 handshake with the publisher. For QoS 1 and 2,
- allow time for the final delivery complete callback before checking
- that all expected callbacks have been made */
- wait_seconds = 10;
- while ((test2_deliveryCompleted < iterations) && (wait_seconds-- > 0))
- {
- MyLog(LOGA_DEBUG, "Delivery Completed %d count %d", test2_deliveryCompleted, i);
- #if defined(WIN32)
- Sleep(1000);
- #else
- usleep(1000000L);
- #endif
- }
- assert("All Deliveries Complete", wait_seconds > 0,
- "Number of deliveryCompleted callbacks was %d\n",
- test2_deliveryCompleted);
- }
-}
-
-
-int test2(struct Options options)
-{
- char* testname = "test2";
- int subsqos = 2;
- /* TODO - usused - remove ? MQTTClient_deliveryToken* dt = NULL; */
- MQTTClient c;
- MQTTClient_connectOptions opts = MQTTClient_connectOptions_initializer;
- int rc = 0;
- char* test_topic = "C client test2";
-
- fprintf(xml, "message = "will message";
- opts.will->qos = 1;
- opts.will->retained = 0;
- opts.will->topicName = "will topic";*/
- rc = MQTTClient_connect(c, &opts);
- //assert("Not authorized", rc == 5, "rc was %d\n", rc);
-
-#if 0
- /* successful connection (RC = 0) */
- opts.username = "Admin";
- opts.password = "Admin";
- opts.will = NULL;
- rc = MQTTClient_connect(c, &opts);
- assert("successful connection", rc == MQTTCLIENT_SUCCESS, "rc was %d\n", rc);
- MQTTClient_disconnect(c, 0);
- MQTTClient_destroy(&c);
-#endif
-
-/* TODO - unused - remove ? exit: */
- MyLog(LOGA_INFO, "%s: test %s. %d tests run, %d failures.",
- (failures == 0) ? "passed" : "failed", testname, tests, failures);
- write_test_result();
- return failures;
-}
-
-
-/*********************************************************************
-
-Test 4: client persistence 1
-
-
-*********************************************************************/
-int test4_run(int qos)
-{
- char* testname = "test 4";
- char* topic = "Persistence test 1";
- int subsqos = 2;
- MQTTClient c;
- MQTTClient_connectOptions opts = MQTTClient_connectOptions_initializer;
- MQTTClient_message* m = NULL;
- char* topicName = NULL;
- int topicLen;
- MQTTClient_deliveryToken* tokens = NULL;
- int mytoken = -99;
- char buffer[100];
- int count = 3;
- int i, rc;
-
- failures = 0;
- MyLog(LOGA_INFO, "Starting test 4 - persistence, qos %d", qos);
-
- MQTTClient_create(&c, options.connection, "xrctest1_test_4", MQTTCLIENT_PERSISTENCE_DEFAULT, NULL);
-
- opts.keepAliveInterval = 20;
- opts.reliable = 0;
- opts.MQTTVersion = options.MQTTVersion;
- if (options.haconnections != NULL)
- {
- opts.serverURIs = options.haconnections;
- opts.serverURIcount = options.hacount;
- }
-
- MyLog(LOGA_DEBUG, "Cleanup by connecting clean session\n");
- opts.cleansession = 1;
- if ((rc = MQTTClient_connect(c, &opts)) != 0)
- {
- assert("Good rc from connect", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc);
- return -1;
- }
- opts.cleansession = 0;
- MQTTClient_disconnect(c, 0);
-
- MyLog(LOGA_DEBUG, "Connecting\n");
- if ((rc = MQTTClient_connect(c, &opts)) != 0)
- {
- assert("Good rc from connect", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc);
- return -1;
- }
-
- /* subscribe so we can get messages back */
- rc = MQTTClient_subscribe(c, topic, subsqos);
- assert("Good rc from subscribe", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc);
-
- /* send messages so that we can receive the same ones */
- for (i = 0; i < count; ++i)
- {
- sprintf(buffer, "Message sequence no %d", i);
- rc = MQTTClient_publish(c, topic, 10, buffer, qos, 0, NULL);
- assert("Good rc from publish", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc);
- }
-
- /* disconnect immediately without receiving the incoming messages */
- MQTTClient_disconnect(c, 0); /* now there should be "orphaned" publications */
-
- rc = MQTTClient_getPendingDeliveryTokens(c, &tokens);
- assert("getPendingDeliveryTokens rc == 0", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc);
-
- assert("should get some tokens back", tokens != NULL, "tokens was %p", tokens);
- if (tokens)
- {
- int i = 0;
-
- while (tokens[i] != -1)
- MyLog(LOGA_DEBUG, "Pending delivery token %d", tokens[i++]);
- MQTTClient_free(tokens);
- assert1("no of tokens should be count", i == count, "no of tokens %d count %d", i, count);
- mytoken = tokens[0];
- }
-
- MQTTClient_destroy(&c); /* force re-reading persistence on create */
-
- MQTTClient_create(&c, options.connection, "xrctest1_test_4", MQTTCLIENT_PERSISTENCE_DEFAULT, NULL);
-
- rc = MQTTClient_getPendingDeliveryTokens(c, &tokens);
- assert("getPendingDeliveryTokens rc == 0", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc);
-
- assert("should get some tokens back", tokens != NULL, "tokens was %p", tokens);
- if (tokens)
- {
- int i = 0;
- while (tokens[i] != -1)
- MyLog(LOGA_DEBUG, "Pending delivery token %d", tokens[i++]);
- MQTTClient_free(tokens);
- assert1("no of tokens should be count", i == count, "no of tokens %d count %d", i, count);
- }
-
- MyLog(LOGA_DEBUG, "Reconnecting");
- if (MQTTClient_connect(c, &opts) != 0)
- {
- assert("Good rc from connect", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc);
- return -1;
- }
-
- for (i = 0; i < count; ++i)
- {
- int dup = 0;
- do
- {
- dup = 0;
- MQTTClient_receive(c, &topicName, &topicLen, &m, 1000);
- if (m && m->dup)
- {
- assert("No duplicates should be received for qos 2", qos == 1, "qos is %d", qos);
- MyLog(LOGA_DEBUG, "Duplicate message id %d", m->msgid);
- MQTTClient_freeMessage(&m);
- MQTTClient_free(topicName);
- dup = 1;
- }
- } while (dup == 1);
- assert("should get a message", m != NULL, "m was %p", m);
- if (m)
- {
- MyLog(LOGA_DEBUG, "Received message id %d", m->msgid);
- assert("topicName is correct", strcmp(topicName, topic) == 0, "topicName is %s", topicName);
- MQTTClient_freeMessage(&m);
- MQTTClient_free(topicName);
- }
- }
-
- MQTTClient_yield(); /* allow any unfinished protocol exchanges to finish */
-
- rc = MQTTClient_getPendingDeliveryTokens(c, &tokens);
- assert("getPendingDeliveryTokens rc == 0", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc);
- assert("should get no tokens back", tokens == NULL, "tokens was %p", tokens);
-
- MQTTClient_disconnect(c, 0);
-
- MQTTClient_destroy(&c);
-
-/* TODO - unused -remove? exit: */
- MyLog(LOGA_INFO, "%s: test %s. %d tests run, %d failures.",
- (failures == 0) ? "passed" : "failed", testname, tests, failures);
-
- return failures;
-}
-
-
-int test4(struct Options options)
-{
- int rc = 0;
- fprintf(xml, "\n", elapsed(global_start_time) / 1000);
- if (cur_output != output)
- {
- fprintf(xml, "%s", output);
- cur_output = output;
- }
- fprintf(xml, "\n");
- return rc;
-}
-
-
-/*********************************************************************
-
-Test 5: disconnect with quiesce timeout should allow exchanges to complete
-
-*********************************************************************/
-int test5(struct Options options)
-{
- char* testname = "test 5";
- /* TODO - unused -remove? char summaryname[50]; */
- /* TODO - unused -remove? FILE *outfile = NULL; */
- char* topic = "Persistence test 2";
- int subsqos = 2;
- MQTTClient c;
- MQTTClient_connectOptions opts = MQTTClient_connectOptions_initializer;
- /* TODO - unused -remove? MQTTClient_message* m = NULL; */
- /* TODO - unused -remove? char* topicName = NULL; */
- MQTTClient_deliveryToken* tokens = NULL;
- /* TODO - unused -remove? int mytoken = -99; */
- char buffer[100];
- int count = 5;
- int i, rc;
-
- fprintf(xml, " Callback: connection lost\n", (c == test6_c1) ? "Client-1" : "Client-2");
- test6_connection_lost_called = 1;
-}
-
-void test6_deliveryComplete(void* context, MQTTClient_deliveryToken token)
-{
- printf("Client-2 -> Callback: publish complete for token %d\n", token);
-}
-
-char* test6_will_topic = "C Test 2: will topic";
-char* test6_will_message = "will message from Client-1";
-
-int test6_messageArrived(void* context, char* topicName, int topicLen, MQTTClient_message* m)
-{
- MQTTClient c = (MQTTClient)context;
- printf("%s -> Callback: message received on topic '%s' is '%.*s'.\n",
- (c == test6_c1) ? "Client-1" : "Client-2", topicName, m->payloadlen, (char*)(m->payload));
- if (c == test6_c2 && strcmp(topicName, test6_will_topic) == 0 && memcmp(m->payload, test6_will_message, m->payloadlen) == 0)
- test6_will_message_arrived = 1;
- MQTTClient_free(topicName);
- MQTTClient_freeMessage(&m);
- return 1;
-}
-
-
-int test6_socket_error(char* aString, int sock)
-{
-#if defined(WIN32)
- int errno;
-#endif
-
-#if defined(WIN32)
- errno = WSAGetLastError();
-#endif
- if (errno != EINTR && errno != EAGAIN && errno != EINPROGRESS && errno != EWOULDBLOCK)
- {
- if (strcmp(aString, "shutdown") != 0 || (errno != ENOTCONN && errno != ECONNRESET))
- printf("Socket error %d in %s for socket %d", errno, aString, sock);
- }
- return errno;
-}
-
-#if !defined(SOCKET_ERROR)
-#define SOCKET_ERROR -1
-#endif
-
-int test6_socket_close(int socket)
-{
- int rc;
-
-#if defined(WIN32)
- if (shutdown(socket, SD_BOTH) == SOCKET_ERROR)
- test6_socket_error("shutdown", socket);
- if ((rc = closesocket(socket)) == SOCKET_ERROR)
- test6_socket_error("close", socket);
-#else
- if (shutdown(socket, SHUT_RDWR) == SOCKET_ERROR)
- test6_socket_error("shutdown", socket);
- if ((rc = close(socket)) == SOCKET_ERROR)
- test6_socket_error("close", socket);
-#endif
- return rc;
-}
-
-typedef struct
-{
- int socket;
- time_t lastContact;
-#if defined(OPENSSL)
- SSL* ssl;
- SSL_CTX* ctx;
-#endif
-} networkHandles;
-
-
-typedef struct
-{
- char* clientID; /**< the string id of the client */
- char* username; /**< MQTT v3.1 user name */
- char* password; /**< MQTT v3.1 password */
- unsigned int cleansession : 1; /**< MQTT clean session flag */
- unsigned int connected : 1; /**< whether it is currently connected */
- unsigned int good : 1; /**< if we have an error on the socket we turn this off */
- unsigned int ping_outstanding : 1;
- int connect_state : 4;
- networkHandles net;
-/* ... */
-} Clients;
-
-
-typedef struct
-{
- char* serverURI;
- Clients* c;
- MQTTClient_connectionLost* cl;
- MQTTClient_messageArrived* ma;
- MQTTClient_deliveryComplete* dc;
- void* context;
-
- int connect_sem;
- int rc; /* getsockopt return code in connect */
- int connack_sem;
- int suback_sem;
- int unsuback_sem;
- void* pack;
-} MQTTClients;
-
-
-int test6(struct Options options)
-{
- char* testname = "test6";
- MQTTClient_connectOptions opts = MQTTClient_connectOptions_initializer;
- MQTTClient_willOptions wopts = MQTTClient_willOptions_initializer;
- MQTTClient_connectOptions opts2 = MQTTClient_connectOptions_initializer;
- int rc, count;
- char* mqttsas_topic = "MQTTSAS topic";
-
- failures = 0;
- MyLog(LOGA_INFO, "Starting test 6 - connectionLost and will messages");
- fprintf(xml, "message = test6_will_message;
- opts.will->qos = 1;
- opts.will->retained = 0;
- opts.will->topicName = test6_will_topic;
- if (options.haconnections != NULL)
- {
- opts.serverURIs = options.haconnections;
- opts.serverURIcount = options.hacount;
- }
-
- /* Client-1 with Will options */
- rc = MQTTClient_create(&test6_c1, options.connection, "Client_1", MQTTCLIENT_PERSISTENCE_DEFAULT, NULL);
- assert("good rc from create", rc == MQTTCLIENT_SUCCESS, "rc was %d\n", rc);
- if (rc != MQTTCLIENT_SUCCESS)
- goto exit;
-
- rc = MQTTClient_setCallbacks(test6_c1, (void*)test6_c1, test6_connectionLost, test6_messageArrived, test6_deliveryComplete);
- assert("good rc from setCallbacks", rc == MQTTCLIENT_SUCCESS, "rc was %d\n", rc);
- if (rc != MQTTCLIENT_SUCCESS)
- goto exit;
-
- /* Connect to the broker */
- rc = MQTTClient_connect(test6_c1, &opts);
- assert("good rc from connect", rc == MQTTCLIENT_SUCCESS, "rc was %d\n", rc);
- if (rc != MQTTCLIENT_SUCCESS)
- goto exit;
-
- /* Client - 2 (multi-threaded) */
- rc = MQTTClient_create(&test6_c2, options.connection, "Client_2", MQTTCLIENT_PERSISTENCE_DEFAULT, NULL);
- assert("good rc from create", rc == MQTTCLIENT_SUCCESS, "rc was %d\n", rc);
-
- /* Set the callback functions for the client */
- rc = MQTTClient_setCallbacks(test6_c2, (void*)test6_c2, test6_connectionLost, test6_messageArrived, test6_deliveryComplete);
- assert("good rc from setCallbacks", rc == MQTTCLIENT_SUCCESS, "rc was %d\n", rc);
-
- /* Connect to the broker */
- opts2.keepAliveInterval = 20;
- opts2.cleansession = 1;
- MyLog(LOGA_INFO, "Connecting Client_2 ...");
- rc = MQTTClient_connect(test6_c2, &opts2);
- assert("Good rc from connect", rc == MQTTCLIENT_SUCCESS, "rc was %d\n", rc);
-
- rc = MQTTClient_subscribe(test6_c2, test6_will_topic, 2);
- assert("Good rc from subscribe", rc == MQTTCLIENT_SUCCESS, "rc was %d\n", rc);
-
- /* now send the command which will break the connection and cause the will message to be sent */
- /*rc = MQTTClient_publish(test6_c1, mqttsas_topic, strlen("TERMINATE"), "TERMINATE", 0, 0, NULL);
- assert("Good rc from publish", rc == MQTTCLIENT_SUCCESS, "rc was %d\n", rc);*/
- test6_socket_close(((MQTTClients*)test6_c1)->c->net.socket);
-
- MyLog(LOGA_INFO, "Waiting to receive the will message");
- count = 0;
- while (++count < 40)
- {
- #if defined(WIN32)
- Sleep(1000L);
- #else
- sleep(1);
- #endif
- if (test6_will_message_arrived == 1 && test6_connection_lost_called == 1)
- break;
- }
- assert("will message arrived", test6_will_message_arrived == 1,
- "will_message_arrived was %d\n", test6_will_message_arrived);
- assert("connection lost called", test6_connection_lost_called == 1,
- "connection_lost_called %d\n", test6_connection_lost_called);
-
- rc = MQTTClient_unsubscribe(test6_c2, test6_will_topic);
- assert("Good rc from unsubscribe", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc);
-
- rc = MQTTClient_isConnected(test6_c2);
- assert("Client-2 still connected", rc == 1, "isconnected is %d", rc);
-
- rc = MQTTClient_isConnected(test6_c1);
- assert("Client-1 not connected", rc == 0, "isconnected is %d", rc);
-
- /* rc = MQTTClient_disconnect(test6_c2, 100L); */
- /* assert("Good rc from disconnect", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc); */
-
- MQTTClient_destroy(&test6_c1);
- /* MQTTClient_destroy(&test6_c2); */
-
-exit:
- MyLog(LOGA_INFO, "%s: test %s. %d tests run, %d failures.\n",
- (failures == 0) ? "passed" : "failed", testname, tests, failures);
- write_test_result();
- return failures;
-}
-
-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, "\n", (int)(ARRAY_SIZE(tests) - 1));
-
- setenv("MQTT_C_CLIENT_TRACE", "ON", 1);
- setenv("MQTT_C_CLIENT_TRACE_LEVEL", "ERROR", 1);
-
- 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)
- 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 */
- }
-
- if (rc == 0)
- MyLog(LOGA_INFO, "verdict pass");
- else
- MyLog(LOGA_INFO, "verdict fail");
-
- fprintf(xml, "\n");
- fclose(xml);
- return rc;
-}
diff --git a/org.eclipse.paho.mqtt.c/test/test3.c b/org.eclipse.paho.mqtt.c/test/test3.c
deleted file mode 100644
index a6fc291..0000000
--- a/org.eclipse.paho.mqtt.c/test/test3.c
+++ /dev/null
@@ -1,1553 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2012, 2014 IBM Corp.
- *
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * and Eclipse Distribution License v1.0 which accompany this distribution.
- *
- * The Eclipse Public License is available at
- * http://www.eclipse.org/legal/epl-v10.html
- * and the Eclipse Distribution License is available at
- * http://www.eclipse.org/org/documents/edl-v10.php.
- *
- * Contributors:
- * Allan Stockdill-Mander - initial API and implementation and/or initial documentation
- *******************************************************************************/
-
-
-/**
- * @file
- * SSL tests for the MQ Telemetry MQTT C client
- */
-
-#include "MQTTClient.h"
-#include
-#include
-
-#if !defined(_WINDOWS)
- #include
- #include
- #include
- #include
-#else
-#include
-#include
-#define MAXHOSTNAMELEN 256
-#define EAGAIN WSAEWOULDBLOCK
-#define EINTR WSAEINTR
-#define EINPROGRESS WSAEINPROGRESS
-#define EWOULDBLOCK WSAEWOULDBLOCK
-#define ENOTCONN WSAENOTCONN
-#define ECONNRESET WSAECONNRESET
-#define snprintf _snprintf
-#define setenv(a, b, c) _putenv_s(a, b)
-#endif
-
-#if defined(IOS)
-char skeytmp[1024];
-char ckeytmp[1024];
-char persistenceStore[1024];
-#else
-char* persistenceStore = NULL;
-#endif
-
-#if 0
-#include /* For general log messages */
-#define MyLog logaLine
-#else
-#define LOGA_DEBUG 0
-#define LOGA_INFO 1
-#include
-#include
-#include
-
-#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
-
-void usage()
-{
- printf("Options:\n");
- printf("\t--test_no - Run test number \n");
- printf("\t--connection - Connect to for tests\n");
- printf("\t--haconnections \"\" - Use \"\" as the list of servers for HA tests (space separated)\n");
- printf("\t--client_key - Use as the client certificate for SSL authentication\n");
- printf("\t--client_key_pass - Use to access the private key in the client certificate\n");
- printf("\t--client_privatekey - Client private key file if not in certificate file\n");
- printf("\t--server_key - Use as the trusted certificate for server\n");
- printf("\t--verbose - Enable verbose output \n");
- printf("\tserver connection URLs should be in the form; (tcp|ssl)://hostname:port\n");
- printf("\t--help - This help output\n");
- exit(-1);
-}
-
-struct Options
-{
- char connection[100];
- char mutual_auth_connection[100]; /**< connection to system under test. */
- char nocert_mutual_auth_connection[100];
- char server_auth_connection[100];
- char anon_connection[100];
- char** haconnections; /**< connection to system under test. */
- int hacount;
- char* client_key_file;
- char* client_key_pass;
- char* server_key_file;
- char* client_private_key_file;
- int verbose;
- int test_no;
-} options =
-{
- "ssl://m2m.eclipse.org:18883",
- "ssl://m2m.eclipse.org:18884",
- "ssl://m2m.eclipse.org:18887",
- "ssl://m2m.eclipse.org:18885",
- "ssl://m2m.eclipse.org:18886",
- NULL,
- 0,
- "../../../test/ssl/client.pem",
- NULL,
- "../../../test/ssl/test-root-ca.crt",
- NULL,
- 0,
- 0,
-};
-
-
-char* test_map[] =
-{
- "none",
- "1", // 1
- "2a_s", // 2
- "2a_m", // 3
- "2b", // 4
- "2c", // 5
- "3a_s", // 6
- "3a_m", // 7
- "3b", // 8
- "4s", // 9
- "4m", // 10
- "5a", // 11
- "5b", // 12
- "5c", // 13
-};
-
-
-void getopts(int argc, char** argv)
-{
- int count = 1;
-
- while (count < argc)
- {
- if (strcmp(argv[count], "--help") == 0)
- usage();
- else if (strcmp(argv[count], "--test_no") == 0)
- {
- if (++count < argc)
- {
- int i;
-
- for (i = 1; i < ARRAY_SIZE(test_map); ++i)
- {
- if (strcmp(argv[count], test_map[i]) == 0)
- {
- options.test_no = i;
- break;
- }
- }
- if (options.test_no == 0)
- options.test_no = atoi(argv[count]);
-
- }
- else
- usage();
- }
- else if (strcmp(argv[count], "--hostname") == 0)
- {
- if (++count < argc)
- {
- sprintf(options.connection, "ssl://%s:18883", argv[count]);
- printf("Setting connection to %s\n", options.connection);
- sprintf(options.mutual_auth_connection, "ssl://%s:18884", argv[count]);
- printf("Setting mutual_auth_connection to %s\n", options.mutual_auth_connection);
- sprintf(options.nocert_mutual_auth_connection, "ssl://%s:18887", argv[count]);
- printf("Setting nocert_mutual_auth_connection to %s\n",
- options.nocert_mutual_auth_connection);
- sprintf(options.server_auth_connection, "ssl://%s:18885", argv[count]);
- printf("Setting server_auth_connection to %s\n", options.server_auth_connection);
- sprintf(options.anon_connection, "ssl://%s:18886", argv[count]);
- printf("Setting anon_connection to %s\n", options.anon_connection);
- }
- else
- usage();
- }
- else if (strcmp(argv[count], "--haconnections") == 0)
- {
- if (++count < argc)
- {
- char* tok = strtok(argv[count], " ");
- options.hacount = 0;
- options.haconnections = malloc(sizeof(char*) * 5);
- while (tok)
- {
- options.haconnections[options.hacount] = malloc(strlen(tok) + 1);
- strcpy(options.haconnections[options.hacount], tok);
- options.hacount++;
- tok = strtok(NULL, " ");
- }
- }
- else
- usage();
- }
- else if (strcmp(argv[count], "--client_key") == 0)
- {
- if (++count < argc)
- {
-#if defined(IOS)
- strcat(ckeytmp, getenv("HOME"));
- strcat(ckeytmp, argv[count]);
- options.client_key_file = ckeytmp;
-#else
- options.client_key_file = argv[count];
-#endif
- }
- else
- usage();
- }
- else if (strcmp(argv[count], "--client_privatekey") == 0)
- {
- if (++count < argc)
- {
-#if defined(IOS)
- strcat(ckeytmp, getenv("HOME"));
- strcat(ckeytmp, argv[count]);
- options.client_private_key_file = ckeytmp;
-#else
- options.client_private_key_file = argv[count];
-#endif
- }
- else
- usage();
- }
- else if (strcmp(argv[count], "--client_key_pass") == 0)
- {
- if (++count < argc)
- options.client_key_pass = argv[count];
- else
- usage();
- }
- else if (strcmp(argv[count], "--server_key") == 0)
- {
- if (++count < argc)
- {
-#if defined(IOS)
- strcat(skeytmp, getenv("HOME"));
- strcat(skeytmp, argv[count]);
- options.server_key_file = skeytmp;
-#else
- options.server_key_file = argv[count];
-#endif
- }
- else
- usage();
- }
- else if (strcmp(argv[count], "--verbose") == 0)
- {
- options.verbose = 1;
- //TODO
- printf("\nSetting verbose on\n");
- }
- count++;
- }
-#if defined(IOS)
- strcpy(persistenceStore, getenv("HOME"));
- strcat(persistenceStore, "/Library/Caches");
-#endif
-}
-
-void MyLog(int LOGA_level, char* format, ...)
-{
- static char msg_buf[256];
- va_list args;
- struct timeb ts;
-
- struct tm *timeinfo;
-
- if (LOGA_level == LOGA_DEBUG && options.verbose == 0)
- return;
-
- ftime(&ts);
- timeinfo = localtime(&ts.time);
- strftime(msg_buf, 80, "%Y%m%d %H%M%S", timeinfo);
-
- sprintf(&msg_buf[strlen(msg_buf)], ".%.3hu ", ts.millitm);
-
- va_start(args, format);
- vsnprintf(&msg_buf[strlen(msg_buf)], sizeof(msg_buf) - strlen(msg_buf), format, args);
- va_end(args);
-
- printf("%s\n", msg_buf);
- fflush(stdout);
-}
-#endif
-
-
-#if defined(WIN32) || defined(_WINDOWS)
-#define mqsleep(A) Sleep(1000*A)
-#define START_TIME_TYPE DWORD
-static DWORD start_time = 0;
-START_TIME_TYPE start_clock(void)
-{
- return GetTickCount();
-}
-#elif defined(AIX)
-#define mqsleep sleep
-#define START_TIME_TYPE struct timespec
-START_TIME_TYPE start_clock(void)
-{
- static struct timespec start;
- clock_gettime(CLOCK_REALTIME, &start);
- return start;
-}
-#else
-#define mqsleep sleep
-#define START_TIME_TYPE struct timeval
-/* TODO - unused - remove? static struct timeval start_time; */
-START_TIME_TYPE start_clock(void)
-{
- struct timeval start_time;
- gettimeofday(&start_time, NULL);
- return start_time;
-}
-#endif
-
-
-#if defined(WIN32)
-long elapsed(START_TIME_TYPE start_time)
-{
- return GetTickCount() - start_time;
-}
-#elif defined(AIX)
-#define assert(a)
-long elapsed(struct timespec start)
-{
- struct timespec now, res;
-
- clock_gettime(CLOCK_REALTIME, &now);
- ntimersub(now, start, res);
- return (res.tv_sec)*1000L + (res.tv_nsec)/1000000L;
-}
-#else
-long elapsed(START_TIME_TYPE start_time)
-{
- struct timeval now, res;
-
- gettimeofday(&now, NULL);
- timersub(&now, &start_time, &res);
- return (res.tv_sec)*1000 + (res.tv_usec)/1000;
-}
-#endif
-
-
-#define assert(a, b, c, d) myassert(__FILE__, __LINE__, a, b, c, d)
-#define assert1(a, b, c, d, e) myassert(__FILE__, __LINE__, a, b, c, d, e)
-
-
-int tests = 0;
-int failures = 0;
-FILE* xml;
-START_TIME_TYPE global_start_time;
-char output[3000];
-char* cur_output = output;
-
-
-void write_test_result()
-{
- long duration = elapsed(global_start_time);
-
- fprintf(xml, " time=\"%ld.%.3ld\" >\n", duration / 1000, duration % 1000);
- if (cur_output != output)
- {
- fprintf(xml, "%s", output);
- cur_output = output;
- }
- fprintf(xml, "\n");
-}
-
-
-int myassert(char* filename, int lineno, char* description, int value, char* format, ...)
-{
- ++tests;
- if (!value)
- {
- va_list args;
-
- ++failures;
- printf("Assertion failed, file %s, line %d, description: %s\n", filename, lineno, description);
-
- va_start(args, format);
- vprintf(format, args);
- va_end(args);
-
- cur_output += sprintf(cur_output, "file %s, line %d \n",
- description, filename, lineno);
- }
- else
- MyLog(LOGA_DEBUG, "Assertion succeeded, file %s, line %d, description: %s", filename, lineno, description);
- return value;
-}
-
-
-/*********************************************************************
-
-Test: single-threaded client
-
-*********************************************************************/
-void singleThread_sendAndReceive(MQTTClient* c, int qos, char* test_topic)
-{
- MQTTClient_deliveryToken dt;
- MQTTClient_message pubmsg = MQTTClient_message_initializer;
- MQTTClient_message* m = NULL;
- char* topicName = NULL;
- int topicLen;
- int i = 0;
- int iterations = 50;
- int rc;
-
- MyLog(LOGA_DEBUG, "%d messages at QoS %d", iterations, qos);
- pubmsg.payload = "a much longer message that we can shorten to the extent that we need to payload up to 11";
- pubmsg.payloadlen = 11;
- pubmsg.qos = qos;
- pubmsg.retained = 0;
-
- for (i = 0; i< iterations; ++i)
- {
- if (i % 10 == 0)
- rc = MQTTClient_publish(c, test_topic, pubmsg.payloadlen, pubmsg.payload, pubmsg.qos, pubmsg.retained, NULL);
- else
- rc = MQTTClient_publishMessage(c, test_topic, &pubmsg, &dt);
- assert("Good rc from publish", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc);
-
- if (qos > 0)
- {
- rc = MQTTClient_waitForCompletion(c, dt, 20000L);
- assert("Good rc from waitforCompletion", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc);
- }
-
- rc = MQTTClient_receive(c, &topicName, &topicLen, &m, 10000);
- assert("Good rc from receive", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc);
- if (topicName)
- {
- MyLog(LOGA_DEBUG, "Message received on topic %s is %.*s", topicName, m->payloadlen, (char*)(m->payload));
- if (pubmsg.payloadlen != m->payloadlen ||
- memcmp(m->payload, pubmsg.payload, m->payloadlen) != 0)
- {
- failures++;
- MyLog(LOGA_INFO, "Error: wrong data - received lengths %d %d", pubmsg.payloadlen, m->payloadlen);
- break;
- }
- MQTTClient_free(topicName);
- MQTTClient_freeMessage(&m);
- }
- else
- printf("No message received within timeout period\n");
- }
-
- /* receive any outstanding messages */
- MQTTClient_receive(c, &topicName, &topicLen, &m, 1000);
- while (topicName)
- {
- printf("Message received on topic %s is %.*s.\n", topicName, m->payloadlen, (char*)(m->payload));
- MQTTClient_free(topicName);
- MQTTClient_freeMessage(&m);
- MQTTClient_receive(c, &topicName, &topicLen, &m, 1000);
- }
-}
-
-/*********************************************************************
-
-Test: multi-threaded client using callbacks
-
-*********************************************************************/
-volatile int multiThread_arrivedcount = 0;
-int multiThread_deliveryCompleted = 0;
-MQTTClient_message multiThread_pubmsg = MQTTClient_message_initializer;
-
-void multiThread_deliveryComplete(void* context, MQTTClient_deliveryToken dt)
-{
- ++multiThread_deliveryCompleted;
-}
-
-int multiThread_messageArrived(void* context, char* topicName, int topicLen, MQTTClient_message* m)
-{
- ++multiThread_arrivedcount;
- MyLog(LOGA_DEBUG, "Callback: %d message received on topic %s is %.*s.",
- multiThread_arrivedcount, topicName, m->payloadlen, (char*)(m->payload));
- if (multiThread_pubmsg.payloadlen != m->payloadlen ||
- memcmp(m->payload, multiThread_pubmsg.payload, m->payloadlen) != 0)
- {
- failures++;
- MyLog(LOGA_INFO, "Error: wrong data received lengths %d %d\n", multiThread_pubmsg.payloadlen, m->payloadlen);
- }
- MQTTClient_free(topicName);
- MQTTClient_freeMessage(&m);
- return 1;
-}
-
-
-void multiThread_sendAndReceive(MQTTClient* c, int qos, char* test_topic)
-{
- MQTTClient_deliveryToken dt;
- int i = 0;
- int iterations = 50;
- int rc = 0;
- int wait_seconds = 0;
-
- multiThread_deliveryCompleted = 0;
- multiThread_arrivedcount = 0;
-
- MyLog(LOGA_DEBUG, "%d messages at QoS %d", iterations, qos);
- multiThread_pubmsg.payload = "a much longer message that we can shorten to the extent that we need to";
- multiThread_pubmsg.payloadlen = 27;
- multiThread_pubmsg.qos = qos;
- multiThread_pubmsg.retained = 0;
-
- for (i = 1; i <= iterations; ++i)
- {
- if (i % 10 == 0)
- rc = MQTTClient_publish(c, test_topic, multiThread_pubmsg.payloadlen, multiThread_pubmsg.payload,
- multiThread_pubmsg.qos, multiThread_pubmsg.retained, NULL);
- else
- rc = MQTTClient_publishMessage(c, test_topic, &multiThread_pubmsg, &dt);
- assert("Good rc from publish", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc);
-
- #if defined(WIN32)
- Sleep(100);
- #else
- usleep(100000L);
- #endif
-
- wait_seconds = 20;
- while ((multiThread_arrivedcount < i) && (wait_seconds-- > 0))
- {
- MyLog(LOGA_DEBUG, "Arrived %d count %d", multiThread_arrivedcount, i);
- #if defined(WIN32)
- Sleep(1000);
- #else
- usleep(1000000L);
- #endif
- }
- assert("Message Arrived", wait_seconds > 0,
- "Time out waiting for message %d\n", i );
- }
- if (qos > 0)
- {
- /* MQ Telemetry can send a message to a subscriber before the server has
- completed the QoS 2 handshake with the publisher. For QoS 1 and 2,
- allow time for the final delivery complete callback before checking
- that all expected callbacks have been made */
- wait_seconds = 10;
- while ((multiThread_deliveryCompleted < iterations) && (wait_seconds-- > 0))
- {
- MyLog(LOGA_DEBUG, "Delivery Completed %d count %d", multiThread_deliveryCompleted, i);
- #if defined(WIN32)
- Sleep(1000);
- #else
- usleep(1000000L);
- #endif
- }
- assert("All Deliveries Complete", wait_seconds > 0,
- "Number of deliveryCompleted callbacks was %d\n",
- multiThread_deliveryCompleted);
- }
-}
-
-
-/*********************************************************************
-
-Test1: SSL connection to non SSL MQTT server
-
-*********************************************************************/
-int test1(struct Options options)
-{
- char* testname = "test1";
- char* test_topic = "C client SSL test1";
- int subsqos = 2;
- MQTTClient c;
- MQTTClient_connectOptions opts = MQTTClient_connectOptions_initializer;
- MQTTClient_willOptions wopts = MQTTClient_willOptions_initializer;
- MQTTClient_SSLOptions sslopts = MQTTClient_SSLOptions_initializer;
- int rc = 0;
-
- failures = 0;
- MyLog(LOGA_INFO, "Starting SSL test 1 - connection to nonSSL MQTT server");
- fprintf(xml, "trustStore = options.server_key_file; /*file of certificates trusted by client*/
-
- MyLog(LOGA_DEBUG, "Connecting");
-
- rc = MQTTClient_connect(c, &opts);
- if (!(assert("Connect should fail", rc == MQTTCLIENT_FAILURE, "rc was %d ", rc)))
- goto exit;
-
-exit:
- MQTTClient_destroy(&c);
- MyLog(LOGA_INFO, "%s: test %s. %d tests run, %d failures.",
- (failures == 0) ? "passed" : "failed", testname, tests, failures);
- write_test_result();
- return failures;
-}
-
-
-/*********************************************************************
-
-Test2a: Mutual SSL Authentication - Certificates in place on client and server - single threaded
-
-*********************************************************************/
-
-int test2a_s(struct Options options)
-{
- char* testname = "test2a_s";
- char* test_topic = "C client test2a_s";
- int subsqos = 2;
- MQTTClient c;
- MQTTClient_connectOptions opts = MQTTClient_connectOptions_initializer;
- MQTTClient_willOptions wopts = MQTTClient_willOptions_initializer;
- MQTTClient_SSLOptions sslopts = MQTTClient_SSLOptions_initializer;
- int rc = 0;
-
- failures = 0;
- MyLog(LOGA_INFO, "Starting test 2a_s - Mutual SSL authentication - single threaded client using receive");
- fprintf(xml, "trustStore = options.server_key_file; /*file of certificates trusted by client*/
- opts.ssl->keyStore = options.client_key_file; /*file of certificate for client to present to server*/
- if (options.client_key_pass)
- opts.ssl->privateKeyPassword = options.client_key_pass;
- if (options.client_private_key_file)
- opts.ssl->privateKey = options.client_private_key_file;
-
- MyLog(LOGA_DEBUG, "Connecting");
-
- rc = MQTTClient_connect(c, &opts);
- if (!(assert("Good rc from connect", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc)))
- goto exit;
-
- rc = MQTTClient_subscribe(c, test_topic, subsqos);
- if (!(assert("Good rc from subscribe", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc)))
- goto exit;
-
- singleThread_sendAndReceive(c, 0, test_topic);
- singleThread_sendAndReceive(c, 1, test_topic);
- singleThread_sendAndReceive(c, 2, test_topic);
-
- MyLog(LOGA_DEBUG, "Stopping\n");
-
- rc = MQTTClient_unsubscribe(c, test_topic);
- if (!(assert("Unsubscribe successful", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc)))
- goto exit;
- rc = MQTTClient_disconnect(c, 0);
- if (!(assert("Disconnect successful", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc)))
- goto exit;
-
- /* Just to make sure we can connect again */
- rc = MQTTClient_connect(c, &opts);
- if (!(assert("Connect successful", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc)))
- goto exit;
- rc = MQTTClient_disconnect(c, 0);
- if (!(assert("Disconnect successful", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc)))
- goto exit;
-
-exit:
- MQTTClient_destroy(&c);
- MyLog(LOGA_INFO, "%s: test %s. %d tests run, %d failures.",
- (failures == 0) ? "passed" : "failed", testname, tests, failures);
- write_test_result();
- return failures;
-}
-
-/*********************************************************************
-
-Test2a: Mutual SSL Authentication - Certificates in place on client and server - multi threaded
-
-*********************************************************************/
-
-int test2a_m(struct Options options)
-{
- char* testname = "test2a_m";
- char* test_topic = "C client test2a_m";
- int subsqos = 2;
- /* TODO - usused - remove ? MQTTClient_deliveryToken* dt = NULL; */
- MQTTClient c;
- MQTTClient_connectOptions opts = MQTTClient_connectOptions_initializer;
- MQTTClient_willOptions wopts = MQTTClient_willOptions_initializer;
- MQTTClient_SSLOptions sslopts = MQTTClient_SSLOptions_initializer;
- int rc = 0;
-
- failures = 0;
- MyLog(LOGA_INFO, "Starting test 2a_m - Mutual SSL authentication - multi-threaded client using callbacks");
- fprintf(xml, "trustStore = options.server_key_file; /*file of certificates trusted by client*/
- opts.ssl->keyStore = options.client_key_file; /*file of certificate for client to present to server*/
- if (options.client_key_pass)
- opts.ssl->privateKeyPassword = options.client_key_pass;
- if (options.client_private_key_file)
- opts.ssl->privateKey = options.client_private_key_file;
- //opts.ssl->enabledCipherSuites = "DEFAULT";
- //opts.ssl->enabledServerCertAuth = 1;
-
- rc = MQTTClient_setCallbacks(c, NULL, NULL, multiThread_messageArrived, multiThread_deliveryComplete);
- if (!(assert("Good rc from setCallbacks", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc)))
- goto exit;
-
- MyLog(LOGA_DEBUG, "Connecting");
-
- rc = MQTTClient_connect(c, &opts);
- if (!(assert("Good rc from connect", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc)))
- goto exit;
-
- rc = MQTTClient_subscribe(c, test_topic, subsqos);
- if (!(assert("Good rc from subscribe", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc)))
- goto exit;
-
- multiThread_sendAndReceive(c, 0, test_topic);
- multiThread_sendAndReceive(c, 1, test_topic);
- multiThread_sendAndReceive(c, 2, test_topic);
-
- MyLog(LOGA_DEBUG, "Stopping");
-
- rc = MQTTClient_unsubscribe(c, test_topic);
- if (!(assert("Unsubscribe successful", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc)))
- goto exit;
- rc = MQTTClient_disconnect(c, 0);
- if (!(assert("Disconnect successful", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc)))
- goto exit;
-
-exit:
- MQTTClient_destroy(&c);
- MyLog(LOGA_INFO, "%s: test %s. %d tests run, %d failures.",
- (failures == 0) ? "passed" : "failed", testname, tests, failures);
- write_test_result();
- return failures;
-}
-
-/*********************************************************************
-
-Test2b: Mutual SSL Authentication - Server does not have Client cert, connection fails
-
-*********************************************************************/
-int test2b(struct Options options)
-{
- char* testname = "test2b";
- char* test_topic = "C client test2b";
- int subsqos = 2;
- MQTTClient c;
- MQTTClient_connectOptions opts = MQTTClient_connectOptions_initializer;
- MQTTClient_willOptions wopts = MQTTClient_willOptions_initializer;
- MQTTClient_SSLOptions sslopts = MQTTClient_SSLOptions_initializer;
- int rc = 0;
-
- failures = 0;
- MyLog(LOGA_INFO, "Starting test 2b - connection to SSL MQTT server with clientauth=req but server does not have client cert");
- fprintf(xml, "trustStore = options.server_key_file; /*file of certificates trusted by client*/
- opts.ssl->keyStore = options.client_key_file; /*file of certificate for client to present to server*/
- if (options.client_key_pass)
- opts.ssl->privateKeyPassword = options.client_key_pass;
- if (options.client_private_key_file)
- opts.ssl->privateKey = options.client_private_key_file;
- //opts.ssl->enabledCipherSuites = "DEFAULT";
- //opts.ssl->enabledServerCertAuth = 0;
-
- MyLog(LOGA_DEBUG, "Connecting");
-
- rc = MQTTClient_connect(c, &opts);
- if (!(assert("Bad rc from connect", rc == MQTTCLIENT_FAILURE, "rc was %d\n", rc)))
- goto exit;
-
-exit:
- MQTTClient_destroy(&c);
- MyLog(LOGA_INFO, "%s: test %s. %d tests run, %d failures.",
- (failures == 0) ? "passed" : "failed", testname, tests, failures);
- write_test_result();
- return failures;
-}
-
-/*********************************************************************
-
-Test2c: Mutual SSL Authentication - Client does not have Server cert
-
-*********************************************************************/
-int test2c(struct Options options)
-{
- char* testname = "test2c";
- char* test_topic = "C client test2c";
- int subsqos = 2;
- MQTTClient c;
- MQTTClient_connectOptions opts = MQTTClient_connectOptions_initializer;
- MQTTClient_willOptions wopts = MQTTClient_willOptions_initializer;
- MQTTClient_SSLOptions sslopts = MQTTClient_SSLOptions_initializer;
- int rc = 0;
-
- failures = 0;
- MyLog(LOGA_INFO, "Starting test 2c - connection to SSL MQTT server, server auth enabled but unknown cert");
- fprintf(xml, "trustStore = options.server_key_file; /*file of certificates trusted by client*/
- opts.ssl->keyStore = options.client_key_file; /*file of certificate for client to present to server*/
- if (options.client_key_pass)
- opts.ssl->privateKeyPassword = options.client_key_pass;
- if (options.client_private_key_file)
- opts.ssl->privateKey = options.client_private_key_file;
- //opts.ssl->enabledCipherSuites = "DEFAULT";
- //opts.ssl->enabledServerCertAuth = 0;
-
- MyLog(LOGA_DEBUG, "Connecting");
-
- rc = MQTTClient_connect(c, &opts);
- if (!(assert("Good rc from connect", rc == MQTTCLIENT_FAILURE, "rc was %d", rc)))
- goto exit;
-
-exit:
- MQTTClient_destroy(&c);
- MyLog(LOGA_INFO, "%s: test %s. %d tests run, %d failures.",
- (failures == 0) ? "passed" : "failed", testname, tests, failures);
- write_test_result();
- return failures;
-}
-
-/*********************************************************************
-
-Test3a: Server Authentication - server certificate in client trust store - single threaded
-
-*********************************************************************/
-
-int test3a_s(struct Options options)
-{
- char* testname = "test3a_s";
- char* test_topic = "C client test3a_s";
- int subsqos = 2;
- MQTTClient c;
- MQTTClient_connectOptions opts = MQTTClient_connectOptions_initializer;
- MQTTClient_willOptions wopts = MQTTClient_willOptions_initializer;
- MQTTClient_SSLOptions sslopts = MQTTClient_SSLOptions_initializer;
- int rc = 0;
-
- failures = 0;
- MyLog(LOGA_INFO, "Starting test 3a_s - Server authentication - single threaded client using receive");
- fprintf(xml, "trustStore = options.server_key_file; /*file of certificates trusted by client*/
-
- MyLog(LOGA_DEBUG, "Connecting");
-
- rc = MQTTClient_connect(c, &opts);
- if (!(assert("Good rc from connect", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc)))
- goto exit;
-
- rc = MQTTClient_subscribe(c, test_topic, subsqos);
- if (!(assert("Good rc from subscribe", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc)))
-
- singleThread_sendAndReceive(c, 0, test_topic);
- singleThread_sendAndReceive(c, 1, test_topic);
- singleThread_sendAndReceive(c, 2, test_topic);
-
- MyLog(LOGA_DEBUG, "Stopping\n");
-
- rc = MQTTClient_unsubscribe(c, test_topic);
- if (!(assert("Unsubscribe successful", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc)))
- goto exit;
- rc = MQTTClient_disconnect(c, 0);
- if (!(assert("Disconnect successful", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc)))
- goto exit;
-
- /* Just to make sure we can connect again */
-
- rc = MQTTClient_connect(c, &opts);
- if (!(assert("Connect successful", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc)))
- goto exit;
- rc = MQTTClient_disconnect(c, 0);
- if (!(assert("Disconnect successful", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc)))
- goto exit;
-
-exit:
- MQTTClient_destroy(&c);
- MyLog(LOGA_INFO, "%s: test %s. %d tests run, %d failures.",
- (failures == 0) ? "passed" : "failed", testname, tests, failures);
- write_test_result();
- return failures;
-}
-
-/*********************************************************************
-
-Test3a: Server Authentication - server certificate in client trust store - multi threaded
-
-*********************************************************************/
-
-int test3a_m(struct Options options)
-{
- char* testname = "test3a_m";
- char* test_topic = "C client test3a_m";
- int subsqos = 2;
- MQTTClient c;
- MQTTClient_connectOptions opts = MQTTClient_connectOptions_initializer;
- MQTTClient_willOptions wopts = MQTTClient_willOptions_initializer;
- MQTTClient_SSLOptions sslopts = MQTTClient_SSLOptions_initializer;
- int rc = 0;
-
- failures = 0;
- MyLog(LOGA_INFO, "Starting test 3a_m - Server authentication - multi-threaded client using callbacks");
- fprintf(xml, "trustStore = options.server_key_file; /*file of certificates trusted by client*/
-
- rc = MQTTClient_setCallbacks(c, NULL, NULL, multiThread_messageArrived, multiThread_deliveryComplete);
- if (!(assert("Good rc from setCallbacks", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc)))
- goto exit;
-
- MyLog(LOGA_DEBUG, "Connecting");
-
- rc = MQTTClient_connect(c, &opts);
- if (!(assert("Good rc from connect", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc)))
- goto exit;
-
- rc = MQTTClient_subscribe(c, test_topic, subsqos);
- if (!(assert("Good rc from subscribe", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc)))
- goto exit;
-
- multiThread_sendAndReceive(c, 0, test_topic);
- multiThread_sendAndReceive(c, 1, test_topic);
- multiThread_sendAndReceive(c, 2, test_topic);
-
- MyLog(LOGA_DEBUG, "Stopping\n");
-
- rc = MQTTClient_unsubscribe(c, test_topic);
- if (!(assert("Unsubscribe successful", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc)))
- goto exit;
- rc = MQTTClient_disconnect(c, 0);
- if (!(assert("Disconnect successful", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc)))
- goto exit;
-
-exit:
- MQTTClient_destroy(&c);
- MyLog(LOGA_INFO, "%s: test %s. %d tests run, %d failures.",
- (failures == 0) ? "passed" : "failed", testname, tests, failures);
- write_test_result();
- return failures;
-}
-
-/*********************************************************************
-
-Test3b: Server Authentication - Client does not have server cert
-
-*********************************************************************/
-int test3b(struct Options options)
-{
- char* testname = "test3b";
- char* test_topic = "C client test3b";
- int subsqos = 2;
- MQTTClient c;
- MQTTClient_connectOptions opts = MQTTClient_connectOptions_initializer;
- MQTTClient_willOptions wopts = MQTTClient_willOptions_initializer;
- MQTTClient_SSLOptions sslopts = MQTTClient_SSLOptions_initializer;
- int rc = 0;
-
- failures = 0;
- MyLog(LOGA_INFO, "Starting test 3b - connection to SSL MQTT server with clientauth=opt but client does not have server cert");
- fprintf(xml, "enableServerCertAuth = 0;
-
- MyLog(LOGA_DEBUG, "Connecting");
-
- rc = MQTTClient_connect(c, &opts);
- if (!(assert("Good rc from connect", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc)))
- goto exit;
- rc = MQTTClient_subscribe(c, test_topic, subsqos);
- if (!(assert("Good rc from subscribe", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc)))
- goto exit;
-
- singleThread_sendAndReceive(c, 0, test_topic);
- singleThread_sendAndReceive(c, 1, test_topic);
- singleThread_sendAndReceive(c, 2, test_topic);
-
- MyLog(LOGA_DEBUG, "Stopping\n");
-
- rc = MQTTClient_unsubscribe(c, test_topic);
- if (!(assert("Unsubscribe successful", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc)))
- goto exit;
- rc = MQTTClient_disconnect(c, 0);
- if (!(assert("Disconnect successful", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc)))
- goto exit;
-
- /* Just to make sure we can connect again */
- rc = MQTTClient_connect(c, &opts);
- if (!(assert("Connect successful", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc)))
- goto exit;
- rc = MQTTClient_disconnect(c, 0);
- if (!(assert("Disconnect successful", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc)))
- goto exit;
-
-exit:
- MQTTClient_destroy(&c);
- MyLog(LOGA_INFO, "%s: test %s. %d tests run, %d failures.",
- (failures == 0) ? "passed" : "failed", testname, tests, failures);
- write_test_result();
- return failures;
-}
-
-/*********************************************************************
-
-Test4_m: Accept invalid server certificates - multi threaded
-
-*********************************************************************/
-
-int test4_m(struct Options options)
-{
- char* testname = "test4_m";
- char* test_topic = "C client test4_m";
- int subsqos = 2;
- MQTTClient c;
- MQTTClient_connectOptions opts = MQTTClient_connectOptions_initializer;
- MQTTClient_willOptions wopts = MQTTClient_willOptions_initializer;
- MQTTClient_SSLOptions sslopts = MQTTClient_SSLOptions_initializer;
- int rc = 0;
-
- failures = 0;
- MyLog(LOGA_INFO, "Starting test 4_m - accept invalid server certificates - multi-threaded");
- fprintf(xml, "enableServerCertAuth = 0;
-
- rc = MQTTClient_setCallbacks(c, NULL, NULL, multiThread_messageArrived, multiThread_deliveryComplete);
- if (!(assert("Good rc from setCallbacks", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc)))
- goto exit;
-
- MyLog(LOGA_DEBUG, "Connecting");
-
- rc = MQTTClient_connect(c, &opts);
- if (!(assert("Good rc from connect", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc)))
- goto exit;
- rc = MQTTClient_subscribe(c, test_topic, subsqos);
- if (!(assert("Good rc from subscribe", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc)))
- goto exit;
-
- multiThread_sendAndReceive(c, 0, test_topic);
- multiThread_sendAndReceive(c, 1, test_topic);
- multiThread_sendAndReceive(c, 2, test_topic);
-
- MyLog(LOGA_DEBUG, "Stopping");
-
- rc = MQTTClient_unsubscribe(c, test_topic);
- if (!(assert("Unsubscribe successful", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc)))
- goto exit;
- rc = MQTTClient_disconnect(c, 0);
- if (!(assert("Disconnect successful", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc)))
- goto exit;
-
-exit:
- MQTTClient_destroy(&c);
-
- MyLog(LOGA_INFO, "%s: test %s. %d tests run, %d failures.",
- (failures == 0) ? "passed" : "failed", testname, tests, failures);
- write_test_result();
- return failures;
-}
-
-/*********************************************************************
-
-Test5a: Anonymous ciphers - server auth disabled
-
-*********************************************************************/
-
-int test5a(struct Options options)
-{
- char* testname = "test5a";
- char* test_topic = "C client SSL test5a";
- int subsqos = 2;
- MQTTClient c;
- MQTTClient_connectOptions opts = MQTTClient_connectOptions_initializer;
- MQTTClient_willOptions wopts = MQTTClient_willOptions_initializer;
- MQTTClient_SSLOptions sslopts = MQTTClient_SSLOptions_initializer;
- int rc = 0;
-
- failures = 0;
- MyLog(LOGA_INFO, "Starting SSL test 5a - Anonymous ciphers - server authentication disabled");
- fprintf(xml, "enabledCipherSuites = "aNULL";
- opts.ssl->enableServerCertAuth = 0;
-
- MyLog(LOGA_DEBUG, "Connecting");
-
- rc = MQTTClient_connect(c, &opts);
- if (!(assert("Good rc from connect", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc)))
- goto exit;
- rc = MQTTClient_subscribe(c, test_topic, subsqos);
- if (!(assert("Good rc from subscribe", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc)))
- goto exit;
-
- singleThread_sendAndReceive(c, 0, test_topic);
- singleThread_sendAndReceive(c, 1, test_topic);
- singleThread_sendAndReceive(c, 2, test_topic);
-
- MyLog(LOGA_DEBUG, "Stopping\n");
-
- rc = MQTTClient_unsubscribe(c, test_topic);
- if (!(assert("Unsubscribe successful", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc)))
- goto exit;
- rc = MQTTClient_disconnect(c, 0);
- if (!(assert("Disconnect successful", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc)))
- goto exit;
-
- /* Just to make sure we can connect again */
-
- rc = MQTTClient_connect(c, &opts);
- if (!(assert("Connect successful", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc)))
- goto exit;
- rc = MQTTClient_disconnect(c, 0);
- if (!(assert("Disconnect successful", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc)))
- goto exit;
-
-exit:
- MQTTClient_destroy(&c);
- MyLog(LOGA_INFO, "%s: test %s. %d tests run, %d failures.",
- (failures == 0) ? "passed" : "failed", testname, tests, failures);
- write_test_result();
- return failures;
-}
-
-/*********************************************************************
-
-Test5b: Anonymous ciphers - server auth enabled
-
-*********************************************************************/
-
-int test5b(struct Options options)
-{
- char* testname = "test5b";
- char* test_topic = "C client SSL test5b";
- int subsqos = 2;
- MQTTClient c;
- MQTTClient_connectOptions opts = MQTTClient_connectOptions_initializer;
- MQTTClient_willOptions wopts = MQTTClient_willOptions_initializer;
- MQTTClient_SSLOptions sslopts = MQTTClient_SSLOptions_initializer;
- int rc = 0;
-
- failures = 0;
- MyLog(LOGA_INFO, "Starting SSL test 5b - Anonymous ciphers - server authentication enabled");
- fprintf(xml, "trustStore = /*file of certificates trusted by client*/
- //opts.ssl->keyStore = options.client_key_file; /*file of certificate for client to present to server*/
- //if (options.client_key_pass != NULL) opts.ssl->privateKeyPassword = options.client_key_pass;
- opts.ssl->enabledCipherSuites = "aNULL";
- opts.ssl->enableServerCertAuth = 1;
-
- MyLog(LOGA_DEBUG, "Connecting");
-
- rc = MQTTClient_connect(c, &opts);
- if (!(assert("Good rc from connect", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc)))
- goto exit;
- rc = MQTTClient_subscribe(c, test_topic, subsqos);
- if (!(assert("Good rc from subscribe", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc)))
- goto exit;
-
- singleThread_sendAndReceive(c, 0, test_topic);
- singleThread_sendAndReceive(c, 1, test_topic);
- singleThread_sendAndReceive(c, 2, test_topic);
-
- MyLog(LOGA_DEBUG, "Stopping\n");
-
- rc = MQTTClient_unsubscribe(c, test_topic);
- if (!(assert("Unsubscribe successful", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc)))
- goto exit;
- rc = MQTTClient_disconnect(c, 0);
- if (!(assert("Disconnect successful", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc)))
- goto exit;
-
- /* Just to make sure we can connect again */
- rc = MQTTClient_connect(c, &opts);
- if (!(assert("Connect successful", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc)))
- goto exit;
- rc = MQTTClient_disconnect(c, 0);
- if (!(assert("Disconnect successful", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc)))
- goto exit;
-
-exit:
- MQTTClient_destroy(&c);
- MyLog(LOGA_INFO, "%s: test %s. %d tests run, %d failures.",
- (failures == 0) ? "passed" : "failed", testname, tests, failures);
- write_test_result();
- return failures;
-}
-
-
-/*********************************************************************
-
-Test5c: Anonymous ciphers - client not using anonymous ciphers
-
-*********************************************************************/
-
-int test5c(struct Options options)
-{
- char* testname = "test5c";
- char* test_topic = "C client SSL test5c";
- int subsqos = 2;
- MQTTClient c;
- MQTTClient_connectOptions opts = MQTTClient_connectOptions_initializer;
- MQTTClient_willOptions wopts = MQTTClient_willOptions_initializer;
- MQTTClient_SSLOptions sslopts = MQTTClient_SSLOptions_initializer;
- int rc = 0;
-
- failures = 0;
- MyLog(LOGA_INFO, "Starting SSL test 5c - Anonymous ciphers - client not using anonymous cipher");
- fprintf(xml, "trustStore = /*file of certificates trusted by client*/
- //opts.ssl->keyStore = options.client_key_file; /*file of certificate for client to present to server*/
- //if (options.client_key_pass != NULL) opts.ssl->privateKeyPassword = options.client_key_pass;
- opts.ssl->enabledCipherSuites = "DEFAULT";
- opts.ssl->enableServerCertAuth = 0;
-
- MyLog(LOGA_DEBUG, "Connecting");
-
- rc = MQTTClient_connect(c, &opts);
- if (!(assert("Good rc from connect", rc == MQTTCLIENT_FAILURE, "rc was %d", rc)))
- goto exit;
-
-exit:
- MQTTClient_destroy(&c);
- MyLog(LOGA_INFO, "%s: test %s. %d tests run, %d failures.",
- (failures == 0) ? "passed" : "failed", testname, tests, failures);
- write_test_result();
- return failures;
-}
-
-typedef struct
-{
- char* clientID; /**< the string id of the client */
- char* username; /**< MQTT v3.1 user name */
- char* password; /**< MQTT v3.1 password */
- unsigned int cleansession : 1; /**< MQTT clean session flag */
- unsigned int connected : 1; /**< whether it is currently connected */
- unsigned int good : 1; /**< if we have an error on the socket we turn this off */
- unsigned int ping_outstanding : 1;
- unsigned int connect_state : 2;
- int socket;
- int msgID;
- int keepAliveInterval;
- int retryInterval;
- int maxInflightMessages;
- time_t lastContact;
- void* will;
- void* inboundMsgs;
- void* outboundMsgs; /**< in flight */
- void* messageQueue;
- void* phandle; /* the persistence handle */
- MQTTClient_persistence* persistence; /* a persistence implementation */
- int connectOptionsVersion;
-} Clients;
-
-typedef struct
-{
- char* serverURI;
- Clients* c;
- MQTTClient_connectionLost* cl;
- MQTTClient_messageArrived* ma;
- MQTTClient_deliveryComplete* dc;
- void* context;
-
- int connect_sem;
- int rc; /* getsockopt return code in connect */
- int connack_sem;
- int suback_sem;
- int unsuback_sem;
- void* pack;
-} MQTTClients;
-
-
-int main(int argc, char** argv)
-{
- int* numtests = &tests;
- int rc = 0;
- int (*tests[])() = {NULL, test1, test2a_s, test2a_m, test2b, test2c, test3a_s, test3a_m, test3b, test4_s, test4_m, /*test5a, test5b,test5c */};
- //MQTTClient_nameValue* info;
-
- xml = fopen("TEST-test3.xml", "w");
- fprintf(xml, "\n", (int)(ARRAY_SIZE(tests) - 1));
-
- setenv("MQTT_C_CLIENT_TRACE", "ON", 1);
- setenv("MQTT_C_CLIENT_TRACE_LEVEL", "ERROR", 1);
- getopts(argc, argv);
- if (options.test_no == 0)
- { /* 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 */
-
- MyLog(LOGA_INFO, "Total tests run: %d", *numtests);
- if (rc == 0)
- MyLog(LOGA_INFO, "verdict pass");
- else
- MyLog(LOGA_INFO, "verdict fail");
-
- fprintf(xml, "\n");
- fclose(xml);
-
- return rc;
-}
diff --git a/org.eclipse.paho.mqtt.c/test/test4.c b/org.eclipse.paho.mqtt.c/test/test4.c
deleted file mode 100644
index 31edbf4..0000000
--- a/org.eclipse.paho.mqtt.c/test/test4.c
+++ /dev/null
@@ -1,1499 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2009, 2014 IBM Corp.
- *
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * and Eclipse Distribution License v1.0 which accompany this distribution.
- *
- * The Eclipse Public License is available at
- * http://www.eclipse.org/legal/epl-v10.html
- * and the Eclipse Distribution License is available at
- * http://www.eclipse.org/org/documents/edl-v10.php.
- *
- * Contributors:
- * Ian Craggs - initial API and implementation and/or initial documentation
- * Ian Craggs - MQTT 3.1.1 support
- *******************************************************************************/
-
-
-/**
- * @file
- * Tests for the Paho Asynchronous MQTT C client
- */
-
-
-/*
-#if !defined(_RTSHEADER)
- #include
-#endif
-*/
-
-#include "MQTTAsync.h"
-#include
-#include
-
-#if !defined(_WINDOWS)
- #include
- #include
- #include
- #include
-#else
-#include
-#include
-#define MAXHOSTNAMELEN 256
-#define EAGAIN WSAEWOULDBLOCK
-#define EINTR WSAEINTR
-#define EINPROGRESS WSAEINPROGRESS
-#define EWOULDBLOCK WSAEWOULDBLOCK
-#define ENOTCONN WSAENOTCONN
-#define ECONNRESET WSAECONNRESET
-#endif
-
-#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
-
-void usage()
-{
- printf("help!!\n");
- exit(-1);
-}
-
-struct Options
-{
- char* connection; /**< connection to system under test. */
- int verbose;
- int test_no;
- int size; /**< size of big message */
- int MQTTVersion;
- int iterations;
-} options =
-{
- "iot.eclipse.org:1883",
- 0,
- -1,
- 10000,
- MQTTVERSION_DEFAULT,
- 1,
-};
-
-void getopts(int argc, char** argv)
-{
- int count = 1;
-
- while (count < argc)
- {
- if (strcmp(argv[count], "--test_no") == 0)
- {
- if (++count < argc)
- options.test_no = atoi(argv[count]);
- else
- usage();
- }
- else if (strcmp(argv[count], "--size") == 0)
- {
- if (++count < argc)
- options.size = atoi(argv[count]);
- else
- usage();
- }
- else if (strcmp(argv[count], "--connection") == 0)
- {
- if (++count < argc)
- options.connection = argv[count];
- 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;
- count++;
- }
-}
-
-#if 0
-#include /* For general log messages */
-#define MyLog logaLine
-#else
-#define LOGA_DEBUG 0
-#define LOGA_INFO 1
-#include
-#include
-#include
-void MyLog(int LOGA_level, char* format, ...)
-{
- static char msg_buf[256];
- va_list args;
- struct timeb ts;
-
- struct tm *timeinfo;
-
- if (LOGA_level == LOGA_DEBUG && options.verbose == 0)
- return;
-
- ftime(&ts);
- timeinfo = localtime(&ts.time);
- strftime(msg_buf, 80, "%Y%m%d %H%M%S", timeinfo);
-
- sprintf(&msg_buf[strlen(msg_buf)], ".%.3hu ", ts.millitm);
-
- va_start(args, format);
- vsnprintf(&msg_buf[strlen(msg_buf)], sizeof(msg_buf) - strlen(msg_buf), format, args);
- va_end(args);
-
- printf("%s\n", msg_buf);
- fflush(stdout);
-}
-#endif
-
-
-#if defined(WIN32) || defined(_WINDOWS)
-#define mqsleep(A) Sleep(1000*A)
-#define START_TIME_TYPE DWORD
-static DWORD start_time = 0;
-START_TIME_TYPE start_clock(void)
-{
- return GetTickCount();
-}
-#elif defined(AIX)
-#define mqsleep sleep
-#define START_TIME_TYPE struct timespec
-START_TIME_TYPE start_clock(void)
-{
- static struct timespec start;
- clock_gettime(CLOCK_REALTIME, &start);
- return start;
-}
-#else
-#define mqsleep sleep
-#define START_TIME_TYPE struct timeval
-/* TODO - unused - remove? static struct timeval start_time; */
-START_TIME_TYPE start_clock(void)
-{
- struct timeval start_time;
- gettimeofday(&start_time, NULL);
- return start_time;
-}
-#endif
-
-
-#if defined(WIN32)
-long elapsed(START_TIME_TYPE start_time)
-{
- return GetTickCount() - start_time;
-}
-#elif defined(AIX)
-#define assert(a)
-long elapsed(struct timespec start)
-{
- struct timespec now, res;
-
- clock_gettime(CLOCK_REALTIME, &now);
- ntimersub(now, start, res);
- return (res.tv_sec)*1000L + (res.tv_nsec)/1000000L;
-}
-#else
-long elapsed(START_TIME_TYPE start_time)
-{
- struct timeval now, res;
-
- gettimeofday(&now, NULL);
- timersub(&now, &start_time, &res);
- return (res.tv_sec)*1000 + (res.tv_usec)/1000;
-}
-#endif
-
-#define assert(a, b, c, d) myassert(__FILE__, __LINE__, a, b, c, d)
-#define assert1(a, b, c, d, e) myassert(__FILE__, __LINE__, a, b, c, d, e)
-
-int tests = 0;
-int failures = 0;
-FILE* xml;
-START_TIME_TYPE global_start_time;
-char output[3000];
-char* cur_output = output;
-
-void write_test_result()
-{
- long duration = elapsed(global_start_time);
-
- fprintf(xml, " time=\"%ld.%.3ld\" >\n", duration / 1000, duration % 1000);
- if (cur_output != output)
- {
- fprintf(xml, "%s", output);
- cur_output = output;
- }
- fprintf(xml, "\n");
-}
-
-void myassert(char* filename, int lineno, char* description, int value, char* format, ...)
-{
- ++tests;
- if (!value)
- {
- va_list args;
-
- ++failures;
- printf("Assertion failed, file %s, line %d, description: %s\n", filename, lineno, description);
-
- va_start(args, format);
- vprintf(format, args);
- va_end(args);
-
- cur_output += sprintf(cur_output, "file %s, line %d \n",
- description, filename, lineno);
- }
- else
- MyLog(LOGA_DEBUG, "Assertion succeeded, file %s, line %d, description: %s", filename, lineno, description);
-}
-
-volatile int test_finished = 0;
-
-char* test_topic = "async test topic";
-
-
-void test1_onDisconnect(void* context, MQTTAsync_successData* response)
-{
- MQTTAsync c = (MQTTAsync)context;
- MyLog(LOGA_DEBUG, "In onDisconnect callback %p", c);
- test_finished = 1;
-}
-
-
-void test1_onUnsubscribe(void* context, MQTTAsync_successData* response)
-{
- MQTTAsync c = (MQTTAsync)context;
- MQTTAsync_disconnectOptions opts = MQTTAsync_disconnectOptions_initializer;
- int rc;
-
- MyLog(LOGA_DEBUG, "In onUnsubscribe onSuccess callback %p", c);
- opts.onSuccess = test1_onDisconnect;
- opts.context = c;
-
- rc = MQTTAsync_disconnect(c, &opts);
- assert("Disconnect successful", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
-}
-
-
-int test1_messageArrived(void* context, char* topicName, int topicLen, MQTTAsync_message* message)
-{
- MQTTAsync c = (MQTTAsync)context;
- static int message_count = 0;
- int rc;
-
- MyLog(LOGA_DEBUG, "In messageArrived callback %p", c);
-
- if (++message_count == 1)
- {
- MQTTAsync_message pubmsg = MQTTAsync_message_initializer;
- MQTTAsync_responseOptions opts = MQTTAsync_responseOptions_initializer;
- pubmsg.payload = "a much longer message that we can shorten to the extent that we need to payload up to 11";
- pubmsg.payloadlen = 11;
- pubmsg.qos = 2;
- pubmsg.retained = 0;
- rc = MQTTAsync_sendMessage(c, test_topic, &pubmsg, &opts);
- }
- else
- {
- MQTTAsync_responseOptions opts = MQTTAsync_responseOptions_initializer;
-
- opts.onSuccess = test1_onUnsubscribe;
- opts.context = c;
- rc = MQTTAsync_unsubscribe(c, test_topic, &opts);
- assert("Unsubscribe successful", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
- }
-
- MQTTAsync_freeMessage(&message);
- MQTTAsync_free(topicName);
-
- return 1;
-}
-
-void test1_onSubscribe(void* context, MQTTAsync_successData* response)
-{
- MQTTAsync c = (MQTTAsync)context;
- MQTTAsync_message pubmsg = MQTTAsync_message_initializer;
- int rc;
-
- MyLog(LOGA_DEBUG, "In subscribe onSuccess callback %p granted qos %d", c, response->alt.qos);
-
- pubmsg.payload = "a much longer message that we can shorten to the extent that we need to payload up to 11";
- pubmsg.payloadlen = 11;
- pubmsg.qos = 2;
- pubmsg.retained = 0;
-
- rc = MQTTAsync_send(c, test_topic, pubmsg.payloadlen, pubmsg.payload, pubmsg.qos, pubmsg.retained, NULL);
-}
-
-
-void test1_onConnect(void* context, MQTTAsync_successData* response)
-{
- MQTTAsync c = (MQTTAsync)context;
- MQTTAsync_responseOptions opts = MQTTAsync_responseOptions_initializer;
- int rc;
-
- MyLog(LOGA_DEBUG, "In connect onSuccess callback, context %p", context);
- opts.onSuccess = test1_onSubscribe;
- opts.context = c;
-
- rc = MQTTAsync_subscribe(c, test_topic, 2, &opts);
- assert("Good rc from subscribe", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
- if (rc != MQTTASYNC_SUCCESS)
- test_finished = 1;
-}
-
-
-/*********************************************************************
-
-Test1: Basic connect, subscribe send and receive.
-
-*********************************************************************/
-int test1(struct Options options)
-{
- int subsqos = 2;
- MQTTAsync c;
- MQTTAsync_connectOptions opts = MQTTAsync_connectOptions_initializer;
- MQTTAsync_willOptions wopts = MQTTAsync_willOptions_initializer;
- int rc = 0;
- char* test_topic = "C client test1";
-
- MyLog(LOGA_INFO, "Starting test 1 - asynchronous connect");
- fprintf(xml, "message = "will message";
- opts.will->qos = 1;
- opts.will->retained = 0;
- opts.will->topicName = "will topic";
- opts.will = NULL;
- opts.onSuccess = test1_onConnect;
- opts.onFailure = NULL;
- opts.context = c;
-
- MyLog(LOGA_DEBUG, "Connecting");
- rc = MQTTAsync_connect(c, &opts);
- rc = 0;
- assert("Good rc from connect", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
- if (rc != MQTTASYNC_SUCCESS)
- goto exit;
-
- while (!test_finished)
- #if defined(WIN32)
- Sleep(100);
- #else
- usleep(10000L);
- #endif
-
- MQTTAsync_destroy(&c);
-
-exit:
- MyLog(LOGA_INFO, "TEST1: test %s. %d tests run, %d failures.",
- (failures == 0) ? "passed" : "failed", tests, failures);
- write_test_result();
- return failures;
-}
-
-int test2_onFailure_called = 0;
-
-void test2_onFailure(void* context, MQTTAsync_failureData* response)
-{
- MyLog(LOGA_DEBUG, "In connect onFailure callback, context %p", context);
-
- test2_onFailure_called++;
- test_finished = 1;
-}
-
-
-void test2_onConnect(void* context, MQTTAsync_successData* response)
-{
-
- MyLog(LOGA_DEBUG, "In connect onSuccess callback, context %p\n", context);
-
- assert("Connect should not succeed", 0, "connect success callback was called", 0);
-
- test_finished = 1;
-}
-
-/*********************************************************************
-
-Test2: connect timeout
-
-*********************************************************************/
-int test2(struct Options options)
-{
- int subsqos = 2;
- MQTTAsync c;
- MQTTAsync_connectOptions opts = MQTTAsync_connectOptions_initializer;
- MQTTAsync_willOptions wopts = MQTTAsync_willOptions_initializer;
- int rc = 0;
- char* test_topic = "C client test2";
-
- test_finished = 0;
-
- MyLog(LOGA_INFO, "Starting test 2 - connect timeout");
- fprintf(xml, "message = "will message";
- opts.will->qos = 1;
- opts.will->retained = 0;
- opts.will->topicName = "will topic";
- opts.will = NULL;
- opts.onSuccess = test2_onConnect;
- opts.onFailure = test2_onFailure;
- opts.context = c;
-
- MyLog(LOGA_DEBUG, "Connecting");
- rc = MQTTAsync_connect(c, &opts);
- rc = 0;
- assert("Good rc from connect", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
- if (rc != MQTTASYNC_SUCCESS)
- goto exit;
-
- while (!test_finished)
- #if defined(WIN32)
- Sleep(100);
- #else
- usleep(10000L);
- #endif
-
- MQTTAsync_destroy(&c);
-
-exit:
- assert("Connect onFailure should be called once", test2_onFailure_called == 1,
- "connect onFailure was called %d times", test2_onFailure_called);
-
- MyLog(LOGA_INFO, "TEST2: test %s. %d tests run, %d failures.",
- (failures == 0) ? "passed" : "failed", tests, failures);
- write_test_result();
- return failures;
-}
-
-
-typedef struct
-{
- MQTTAsync c;
- int index;
- char clientid[24];
- char test_topic[100];
- int message_count;
-} client_data;
-
-
-void test3_onDisconnect(void* context, MQTTAsync_successData* response)
-{
- client_data* cd = (client_data*)context;
- MyLog(LOGA_DEBUG, "In onDisconnect callback for client \"%s\"", cd->clientid);
- test_finished++;
-}
-
-
-void test3_onPublish(void* context, MQTTAsync_successData* response)
-{
- client_data* cd = (client_data*)context;
- MyLog(LOGA_DEBUG, "In QoS 0 onPublish callback for client \"%s\"", cd->clientid);
-}
-
-
-void test3_onUnsubscribe(void* context, MQTTAsync_successData* response)
-{
- client_data* cd = (client_data*)context;
- MQTTAsync_disconnectOptions opts = MQTTAsync_disconnectOptions_initializer;
- int rc;
-
- MyLog(LOGA_DEBUG, "In onUnsubscribe onSuccess callback \"%s\"", cd->clientid);
- opts.onSuccess = test3_onDisconnect;
- opts.context = cd;
-
- rc = MQTTAsync_disconnect(cd->c, &opts);
- assert("Disconnect successful", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
-}
-
-
-int test3_messageArrived(void* context, char* topicName, int topicLen, MQTTAsync_message* message)
-{
- client_data* cd = (client_data*)context;
- int rc;
-
- MyLog(LOGA_DEBUG, "In messageArrived callback \"%s\" message count ", cd->clientid);
-
- if (++cd->message_count == 1)
- {
- MQTTAsync_message pubmsg = MQTTAsync_message_initializer;
- MQTTAsync_responseOptions opts = MQTTAsync_responseOptions_initializer;
- pubmsg.payload = "a much longer message that we can shorten to the extent that we need to payload up to 11";
- pubmsg.payloadlen = 25;
- pubmsg.qos = 1;
- pubmsg.retained = 0;
- rc = MQTTAsync_sendMessage(cd->c, cd->test_topic, &pubmsg, &opts);
- assert("Good rc from publish", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
- }
- else if (cd->message_count == 2)
- {
- MQTTAsync_message pubmsg = MQTTAsync_message_initializer;
- MQTTAsync_responseOptions opts = MQTTAsync_responseOptions_initializer;
- pubmsg.payload = "a QoS 0 message that we can shorten to the extent that we need to payload up to 11";
- pubmsg.payloadlen = 29;
- pubmsg.qos = 0;
- pubmsg.retained = 0;
- opts.context = cd;
- opts.onSuccess = test3_onPublish;
-
- rc = MQTTAsync_sendMessage(cd->c, cd->test_topic, &pubmsg, &opts);
- assert("Good rc from publish", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
- }
- else
- {
- MQTTAsync_responseOptions opts = MQTTAsync_responseOptions_initializer;
-
- opts.onSuccess = test3_onUnsubscribe;
- opts.context = cd;
- rc = MQTTAsync_unsubscribe(cd->c, cd->test_topic, &opts);
- assert("Unsubscribe successful", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
- }
- MQTTAsync_freeMessage(&message);
- MQTTAsync_free(topicName);
- return 1;
-}
-
-void test3_onSubscribe(void* context, MQTTAsync_successData* response)
-{
- client_data* cd = (client_data*)context;
- MQTTAsync_message pubmsg = MQTTAsync_message_initializer;
- int rc;
-
- MyLog(LOGA_DEBUG, "In subscribe onSuccess callback \"%s\"", cd->clientid);
-
- pubmsg.payload = "a much longer message that we can shorten to the extent that we need to payload up to 11";
- pubmsg.payloadlen = 11;
- pubmsg.qos = 2;
- pubmsg.retained = 0;
-
- rc = MQTTAsync_send(cd->c, cd->test_topic, pubmsg.payloadlen, pubmsg.payload, pubmsg.qos, pubmsg.retained, NULL);
- assert("Good rc from publish", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
-}
-
-
-void test3_onConnect(void* context, MQTTAsync_successData* response)
-{
- client_data* cd = (client_data*)context;
- MQTTAsync_responseOptions opts = MQTTAsync_responseOptions_initializer;
- int rc;
-
- MyLog(LOGA_DEBUG, "In connect onSuccess callback, \"%s\"", cd->clientid);
- opts.onSuccess = test3_onSubscribe;
- opts.context = cd;
-
- rc = MQTTAsync_subscribe(cd->c, cd->test_topic, 2, &opts);
- assert("Good rc from subscribe", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
- if (rc != MQTTASYNC_SUCCESS)
- test_finished++;
-}
-
-
-void test3_onFailure(void* context, MQTTAsync_failureData* response)
-{
- client_data* cd = (client_data*)context;
- MQTTAsync_responseOptions opts = MQTTAsync_responseOptions_initializer;
-
- assert("Should have connected", 0, "%s failed to connect\n", cd->clientid);
- MyLog(LOGA_DEBUG, "In connect onFailure callback, \"%s\" rc %d\n", cd->clientid, response ? response->code : -999);
- if (response && response->message)
- MyLog(LOGA_DEBUG, "In connect onFailure callback, \"%s\"\n", response->message);
-
- test_finished++;
-}
-
-
-/*********************************************************************
-
-Test3: More than one client object - simultaneous working.
-
-*********************************************************************/
-int test3(struct Options options)
-{
- #define num_clients 10
- int subsqos = 2;
- MQTTAsync_connectOptions opts = MQTTAsync_connectOptions_initializer;
- MQTTAsync_willOptions wopts = MQTTAsync_willOptions_initializer;
- int rc = 0;
- int i;
- client_data clientdata[num_clients];
-
- test_finished = 0;
- MyLog(LOGA_INFO, "Starting test 3 - multiple connections");
- fprintf(xml, "message = "will message";
- opts.will->qos = 1;
- opts.will->retained = 0;
- opts.will->topicName = "will topic";
- opts.onSuccess = test3_onConnect;
- opts.onFailure = test3_onFailure;
- opts.context = &clientdata[i];
-
- MyLog(LOGA_DEBUG, "Connecting");
- rc = MQTTAsync_connect(clientdata[i].c, &opts);
- assert("Good rc from connect", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
- }
-
- while (test_finished < num_clients)
- {
- MyLog(LOGA_DEBUG, "num_clients %d test_finished %d\n", num_clients, test_finished);
- #if defined(WIN32)
- Sleep(100);
- #else
- usleep(10000L);
- #endif
- }
-
- MyLog(LOGA_DEBUG, "TEST3: destroying clients");
-
- for (i = 0; i < num_clients; ++i)
- MQTTAsync_destroy(&clientdata[i].c);
-
-//exit:
- MyLog(LOGA_INFO, "TEST3: test %s. %d tests run, %d failures.",
- (failures == 0) ? "passed" : "failed", tests, failures);
- write_test_result();
- return failures;
-}
-
-
-void* test4_payload = NULL;
-int test4_payloadlen = 0;
-
-void test4_onPublish(void* context, MQTTAsync_successData* response)
-{
- MQTTAsync c = (MQTTAsync)context;
-
- MyLog(LOGA_DEBUG, "In publish onSuccess callback, context %p", context);
-}
-
-int test4_messageArrived(void* context, char* topicName, int topicLen, MQTTAsync_message* message)
-{
- MQTTAsync c = (MQTTAsync)context;
- static int message_count = 0;
- int rc, i;
-
- MyLog(LOGA_DEBUG, "In messageArrived callback %p", c);
-
- assert("Message size correct", message->payloadlen == test4_payloadlen,
- "message size was %d", message->payloadlen);
-
- for (i = 0; i < options.size; ++i)
- {
- if (((char*)test4_payload)[i] != ((char*)message->payload)[i])
- {
- assert("Message contents correct", ((char*)test4_payload)[i] != ((char*)message->payload)[i],
- "message content was %c", ((char*)message->payload)[i]);
- break;
- }
- }
-
- if (++message_count == 1)
- {
- MQTTAsync_message pubmsg = MQTTAsync_message_initializer;
- MQTTAsync_responseOptions opts = MQTTAsync_responseOptions_initializer;
-
- pubmsg.payload = test4_payload;
- pubmsg.payloadlen = test4_payloadlen;
- pubmsg.qos = 1;
- pubmsg.retained = 0;
- opts.onSuccess = test4_onPublish;
- opts.context = c;
-
- rc = MQTTAsync_sendMessage(c, test_topic, &pubmsg, &opts);
- }
- else if (message_count == 2)
- {
- MQTTAsync_message pubmsg = MQTTAsync_message_initializer;
- MQTTAsync_responseOptions opts = MQTTAsync_responseOptions_initializer;
-
- pubmsg.payload = test4_payload;
- pubmsg.payloadlen = test4_payloadlen;
- pubmsg.qos = 0;
- pubmsg.retained = 0;
- opts.onSuccess = test4_onPublish;
- opts.context = c;
- rc = MQTTAsync_sendMessage(c, test_topic, &pubmsg, &opts);
- }
- else
- {
- MQTTAsync_responseOptions opts = MQTTAsync_responseOptions_initializer;
-
- opts.onSuccess = test1_onUnsubscribe;
- opts.context = c;
- rc = MQTTAsync_unsubscribe(c, test_topic, &opts);
- assert("Unsubscribe successful", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
- }
-
- MQTTAsync_freeMessage(&message);
- MQTTAsync_free(topicName);
-
- return 1;
-}
-
-
-void test4_onSubscribe(void* context, MQTTAsync_successData* response)
-{
- MQTTAsync c = (MQTTAsync)context;
- MQTTAsync_message pubmsg = MQTTAsync_message_initializer;
- int rc, i;
-
- MyLog(LOGA_DEBUG, "In subscribe onSuccess callback %p", c);
-
- pubmsg.payload = test4_payload = malloc(options.size);
- pubmsg.payloadlen = test4_payloadlen = options.size;
-
- srand(33);
- for (i = 0; i < options.size; ++i)
- ((char*)pubmsg.payload)[i] = rand() % 256;
-
- pubmsg.qos = 2;
- pubmsg.retained = 0;
-
- rc = MQTTAsync_send(c, test_topic, pubmsg.payloadlen, pubmsg.payload, pubmsg.qos, pubmsg.retained, NULL);
-}
-
-
-void test4_onConnect(void* context, MQTTAsync_successData* response)
-{
- MQTTAsync c = (MQTTAsync)context;
- MQTTAsync_responseOptions opts = MQTTAsync_responseOptions_initializer;
- int rc;
-
- MyLog(LOGA_DEBUG, "In connect onSuccess callback, context %p", context);
- opts.onSuccess = test4_onSubscribe;
- opts.context = c;
-
- rc = MQTTAsync_subscribe(c, test_topic, 2, &opts);
- assert("Good rc from subscribe", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
- if (rc != MQTTASYNC_SUCCESS)
- test_finished = 1;
-}
-
-
-/*********************************************************************
-
-Test4: Send and receive big messages
-
-*********************************************************************/
-int test4(struct Options options)
-{
- int subsqos = 2;
- MQTTAsync c;
- MQTTAsync_connectOptions opts = MQTTAsync_connectOptions_initializer;
- MQTTAsync_willOptions wopts = MQTTAsync_willOptions_initializer;
- int rc = 0;
- char* test_topic = "C client test4";
-
- test_finished = failures = 0;
- MyLog(LOGA_INFO, "Starting test 4 - big messages");
- fprintf(xml, "message = "will message";
- opts.will->qos = 1;
- opts.will->retained = 0;
- opts.will->topicName = "will topic";
- opts.will = NULL;
- opts.onSuccess = test4_onConnect;
- opts.onFailure = NULL;
- opts.context = c;
-
- MyLog(LOGA_DEBUG, "Connecting");
- rc = MQTTAsync_connect(c, &opts);
- rc = 0;
- assert("Good rc from connect", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
- if (rc != MQTTASYNC_SUCCESS)
- goto exit;
-
- while (!test_finished)
- #if defined(WIN32)
- Sleep(100);
- #else
- usleep(1000L);
- #endif
-
- MQTTAsync_destroy(&c);
-
-exit:
- MyLog(LOGA_INFO, "TEST4: test %s. %d tests run, %d failures.",
- (failures == 0) ? "passed" : "failed", tests, failures);
- write_test_result();
- return failures;
-}
-
-
-void test5_onConnectFailure(void* context, MQTTAsync_failureData* response)
-{
- MQTTAsync c = (MQTTAsync)context;
- MQTTAsync_responseOptions opts = MQTTAsync_responseOptions_initializer;
-
- MyLog(LOGA_DEBUG, "In connect onFailure callback, context %p", context);
-
- MyLog(LOGA_INFO, "Connack rc is %d", response ? response->code : -999);
-
- test_finished = 1;
-}
-
-
-void test5_onConnect(void* context, MQTTAsync_successData* response)
-{
- MQTTAsync c = (MQTTAsync)context;
- MQTTAsync_responseOptions opts = MQTTAsync_responseOptions_initializer;
-
- MyLog(LOGA_DEBUG, "In connect onFailure callback, context %p", context);
-
- test_finished = 1;
-}
-
-
-/********************************************************************
-
-Test5: Connack return codes
-
-*********************************************************************/
-int test5(struct Options options)
-{
- int subsqos = 2;
- MQTTAsync c;
- MQTTAsync_connectOptions opts = MQTTAsync_connectOptions_initializer;
- MQTTAsync_willOptions wopts = MQTTAsync_willOptions_initializer;
- int rc = 0;
- char* test_topic = "C client test1";
-
- test_finished = failures = 0;
- MyLog(LOGA_INFO, "Starting test 5 - connack return codes");
- fprintf(xml, "code);
-
- assert("Should fail to connect", cinfo.should_fail, "should_fail was %d", cinfo.should_fail);
-
- test_finished = 1;
-}
-
-
-void test6_onConnect(void* context, MQTTAsync_successData* response)
-{
- test6_client_info cinfo = *(test6_client_info*)context;
-
- MyLog(LOGA_DEBUG, "In connect success callback, context %p", context);
-
- assert("Should connect correctly", !cinfo.should_fail, "should_fail was %d", cinfo.should_fail);
-
- test_finished = 1;
-}
-
-
-/********************************************************************
-
-Test6: HA connections
-
-*********************************************************************/
-int test6(struct Options options)
-{
- int subsqos = 2;
- test6_client_info cinfo;
- MQTTAsync_connectOptions opts = MQTTAsync_connectOptions_initializer;
- MQTTAsync_willOptions wopts = MQTTAsync_willOptions_initializer;
- int rc = 0;
- char* test_topic = "C client test1";
- char* uris[2] = {options.connection, options.connection};
-
- failures = 0;
- MyLog(LOGA_INFO, "Starting test 6 - HA connections");
- fprintf(xml, "msgid);
-
- test7_messageCount++;
-
- MQTTAsync_freeMessage(&message);
- MQTTAsync_free(topicName);
-
- return 1;
-}
-
-
-static int test7_subscribed = 0;
-
-void test7_onSubscribe(void* context, MQTTAsync_successData* response)
-{
- MQTTAsync c = (MQTTAsync)context;
-
- MyLog(LOGA_DEBUG, "In subscribe onSuccess callback %p granted qos %d", c, response->alt.qos);
-
- test7_subscribed = 1;
-}
-
-
-void test7_onConnect(void* context, MQTTAsync_successData* response)
-{
- MQTTAsync c = (MQTTAsync)context;
- MQTTAsync_responseOptions opts = MQTTAsync_responseOptions_initializer;
- int rc;
-
- MyLog(LOGA_DEBUG, "In connect onSuccess callback, context %p", context);
- opts.onSuccess = test7_onSubscribe;
- opts.context = c;
-
- rc = MQTTAsync_subscribe(c, test7_topic, 2, &opts);
- assert("Good rc from subscribe", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
- if (rc != MQTTASYNC_SUCCESS)
- test_finished = 1;
-}
-
-
-void test7_onConnectOnly(void* context, MQTTAsync_successData* response)
-{
- MQTTAsync c = (MQTTAsync)context;
- MQTTAsync_disconnectOptions dopts = MQTTAsync_disconnectOptions_initializer;
- int rc;
-
- MyLog(LOGA_DEBUG, "In connect onSuccess callback, context %p", context);
- dopts.context = context;
- dopts.timeout = 1000;
- dopts.onSuccess = test7_onDisconnect;
- rc = MQTTAsync_disconnect(c, &dopts);
-
- assert("Good rc from disconnect", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
- if (rc != MQTTASYNC_SUCCESS)
- test_finished = 1;
-}
-
-
-/*********************************************************************
-
-Test7: Pending tokens
-
-*********************************************************************/
-int test7(struct Options options)
-{
- int subsqos = 2;
- MQTTAsync c;
- MQTTAsync_connectOptions opts = MQTTAsync_connectOptions_initializer;
- MQTTAsync_willOptions wopts = MQTTAsync_willOptions_initializer;
- int rc = 0;
- MQTTAsync_message pubmsg = MQTTAsync_message_initializer;
- MQTTAsync_responseOptions ropts = MQTTAsync_responseOptions_initializer;
- MQTTAsync_disconnectOptions dopts = MQTTAsync_disconnectOptions_initializer;
- MQTTAsync_token* tokens = NULL;
- int msg_count = 6;
-
- MyLog(LOGA_INFO, "Starting test 7 - pending tokens");
- fprintf(xml, "message = "will message";
- opts.will->qos = 1;
- opts.will->retained = 0;
- opts.will->topicName = "will topic";
- opts.will = NULL;
-
- opts.onFailure = NULL;
- opts.context = c;
-
- opts.cleansession = 1;
- opts.onSuccess = test7_onConnectOnly;
- MyLog(LOGA_DEBUG, "Connecting to clean up");
- rc = MQTTAsync_connect(c, &opts);
- rc = 0;
- assert("Good rc from connect", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
- if (rc != MQTTASYNC_SUCCESS)
- goto exit;
-
- while (!test_finished)
- #if defined(WIN32)
- Sleep(100);
- #else
- usleep(10000L);
- #endif
-
- test_finished = 0;
- MyLog(LOGA_DEBUG, "Connecting");
- opts.cleansession = 0;
- opts.onSuccess = test7_onConnect;
- rc = MQTTAsync_connect(c, &opts);
- rc = 0;
- assert("Good rc from connect", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
- if (rc != MQTTASYNC_SUCCESS)
- goto exit;
-
- while (!test7_subscribed)
- #if defined(WIN32)
- Sleep(100);
- #else
- usleep(10000L);
- #endif
-
- pubmsg.payload = "a much longer message that we can shorten to the extent that we need to payload up to 11";
- pubmsg.payloadlen = 11;
- pubmsg.qos = 2;
- pubmsg.retained = 0;
- rc = MQTTAsync_send(c, test_topic, pubmsg.payloadlen, pubmsg.payload, pubmsg.qos, pubmsg.retained, &ropts);
- MyLog(LOGA_DEBUG, "Token was %d", ropts.token);
- rc = MQTTAsync_isComplete(c, ropts.token);
- assert("0 rc from isComplete", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
- rc = MQTTAsync_waitForCompletion(c, ropts.token, 5000L);
- assert("Good rc from waitForCompletion", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
- rc = MQTTAsync_isComplete(c, ropts.token);
- assert("1 rc from isComplete", rc == 1, "rc was %d", rc);
-
- test7_messageCount = 0;
- int i = 0;
- pubmsg.qos = 2;
- for (i = 0; i < msg_count; ++i)
- {
- pubmsg.payload = "a much longer message that we can shorten to the extent that we need to payload up to 11";
- pubmsg.payloadlen = 11;
- //pubmsg.qos = (pubmsg.qos == 2) ? 1 : 2;
- pubmsg.retained = 0;
- rc = MQTTAsync_sendMessage(c, test_topic, &pubmsg, &ropts);
- }
- /* disconnect immediately without receiving the incoming messages */
- dopts.timeout = 0;
- dopts.onSuccess = test7_onDisconnect;
- dopts.context = c;
- MQTTAsync_disconnect(c, &dopts); /* now there should be "orphaned" publications */
-
- while (!test_finished)
- #if defined(WIN32)
- Sleep(100);
- #else
- usleep(10000L);
- #endif
- test_finished = 0;
-
- rc = MQTTAsync_getPendingTokens(c, &tokens);
- assert("getPendingTokens rc == 0", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
-
- assert("should get some tokens back", tokens != NULL, "tokens was %p", tokens);
- MQTTAsync_free(tokens);
-
- MQTTAsync_destroy(&c); /* force re-reading persistence on create */
-
- MQTTAsync_setTraceLevel(MQTTASYNC_TRACE_ERROR);
- rc = MQTTAsync_create(&c, options.connection, "async_test7", MQTTCLIENT_PERSISTENCE_DEFAULT, NULL);
- assert("good rc from create", rc == MQTTASYNC_SUCCESS, "rc was %d\n", rc);
- if (rc != MQTTASYNC_SUCCESS)
- {
- MQTTAsync_destroy(&c);
- goto exit;
- }
-
- rc = MQTTAsync_getPendingTokens(c, &tokens);
- assert("getPendingTokens rc == 0", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
-
- assert("should get some tokens back", tokens != NULL, "tokens was %p", tokens);
- if (tokens)
- {
- int i = 0;
- while (tokens[i] != -1)
- MyLog(LOGA_DEBUG, "Delivery token %d", tokens[i++]);
- MQTTAsync_free(tokens);
- //The following assertion should work, does with RSMB, but not Mosquitto
- //assert1("no of tokens should be count", i == msg_count, "no of tokens %d count %d", i, msg_count);
- }
-
- rc = MQTTAsync_setCallbacks(c, c, NULL, test7_messageArrived, NULL);
- assert("Good rc from setCallbacks", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
-
- MyLog(LOGA_DEBUG, "Reconnecting");
- opts.context = c;
- if (MQTTAsync_connect(c, &opts) != 0)
- {
- assert("Good rc from connect", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
- goto exit;
- }
-
- #if defined(WIN32)
- Sleep(5000);
- #else
- usleep(5000000L);
- #endif
-
- rc = MQTTAsync_getPendingTokens(c, &tokens);
- assert("getPendingTokens rc == 0", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
- /* assert("should get no tokens back", tokens == NULL, "tokens was %p", tokens);
-
- assert1("no of messages should be count", test7_messageCount == msg_count, "no of tokens %d count %d",
- test7_messageCount, msg_count);
-
- assertions fail against Mosquitto - needs testing */
-
- dopts.onFailure = test7_onDisconnectFailure;
- dopts.onSuccess = test7_onDisconnect;
- dopts.timeout = 1000;
- MQTTAsync_disconnect(c, &dopts);
-
- while (!test_finished)
- #if defined(WIN32)
- Sleep(100);
- #else
- usleep(10000L);
- #endif
-
- MQTTAsync_destroy(&c);
-
-exit:
- MyLog(LOGA_INFO, "TEST7: test %s. %d tests run, %d failures.",
- (failures == 0) ? "passed" : "failed", tests, failures);
- write_test_result();
- return failures;
-}
-
-
-
-void trace_callback(enum MQTTASYNC_TRACE_LEVELS level, char* message)
-{
- printf("Trace : %d, %s\n", level, message);
-}
-
-
-
-
-int main(int argc, char** argv)
-{
- int rc = 0;
- int (*tests[])() = {NULL, test1, test2, test3, test4, test5, test6, test7}; /* indexed starting from 1 */
- MQTTAsync_nameValue* info;
- int i;
-
- xml = fopen("TEST-test4.xml", "w");
- fprintf(xml, "\n", (int)(ARRAY_SIZE(tests)) - 1);
-
- getopts(argc, argv);
-
- MQTTAsync_setTraceCallback(trace_callback);
-
- info = MQTTAsync_getVersionInfo();
- while (info->name)
- {
- MyLog(LOGA_INFO, "%s: %s", info->name, info->value);
- 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)
- {
- failures = 0;
- MQTTAsync_setTraceLevel(MQTTASYNC_TRACE_ERROR);
- rc += tests[options.test_no](options); /* return number of failures. 0 = test succeeded */
- }
- }
- else
- {
- MQTTAsync_setTraceLevel(MQTTASYNC_TRACE_ERROR);
- rc = tests[options.test_no](options); /* run just the selected test */
- }
- }
-
- if (rc == 0)
- MyLog(LOGA_INFO, "verdict pass");
- else
- MyLog(LOGA_INFO, "verdict fail");
-
- fprintf(xml, "\n");
- fclose(xml);
-
- return rc;
-}
diff --git a/org.eclipse.paho.mqtt.c/test/test5.c b/org.eclipse.paho.mqtt.c/test/test5.c
deleted file mode 100644
index 9502434..0000000
--- a/org.eclipse.paho.mqtt.c/test/test5.c
+++ /dev/null
@@ -1,2074 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2012, 2014 IBM Corp.
- *
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * and Eclipse Distribution License v1.0 which accompany this distribution.
- *
- * The Eclipse Public License is available at
- * http://www.eclipse.org/legal/epl-v10.html
- * and the Eclipse Distribution License is available at
- * http://www.eclipse.org/org/documents/edl-v10.php.
- *
- * Contributors:
- * Allan Stockdill-Mander - initial API and implementation and/or initial documentation
- *******************************************************************************/
-
-
-/**
- * @file
- * SSL tests for the MQ Telemetry Asynchronous MQTT C client
- */
-
-/*
- #if !defined(_RTSHEADER)
- #include
- #endif
- */
-
-#include "MQTTAsync.h"
-#include
-#include
-#include "Thread.h"
-
-#if !defined(_WINDOWS)
-#include
-#include
-#include
-#include
-#else
-#include
-#include
-#define MAXHOSTNAMELEN 256
-#define EAGAIN WSAEWOULDBLOCK
-#define EINTR WSAEINTR
-#define EINPROGRESS WSAEINPROGRESS
-#define EWOULDBLOCK WSAEWOULDBLOCK
-#define ENOTCONN WSAENOTCONN
-#define ECONNRESET WSAECONNRESET
-#define snprintf _snprintf
-#endif
-
-#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
-
-void usage()
-{
- printf("Options:\n");
- printf("\t--test_no - Run test number \n");
- printf("\t--server - Connect to for tests\n");
- printf("\t--client_key - Use as the client certificate for SSL authentication\n");
- printf("\t--client_key_pass - Use to access the private key in the client certificate\n");
- printf("\t--server_key - Use as the trusted certificate for server\n");
- printf("\t--verbose - Enable verbose output \n");
- printf("\t--help - This help output\n");
- exit(-1);
-}
-
-struct Options
-{
- char connection[100]; /**< connection to system under test. */
- char mutual_auth_connection[100]; /**< connection to system under test. */
- char nocert_mutual_auth_connection[100];
- char server_auth_connection[100];
- char anon_connection[100];
- char* client_key_file;
- char* client_key_pass;
- char* server_key_file;
- char* client_private_key_file;
- int verbose;
- int test_no;
- int size;
-} options =
-{
- "ssl://m2m.eclipse.org:18883",
- "ssl://m2m.eclipse.org:18884",
- "ssl://m2m.eclipse.org:18887",
- "ssl://m2m.eclipse.org:18885",
- "ssl://m2m.eclipse.org:18886",
- "../../../test/ssl/client.pem",
- NULL,
- "../../../test/ssl/test-root-ca.crt",
- NULL,
- 0,
- 0,
- 5000000
-};
-
-typedef struct
-{
- MQTTAsync client;
- char clientid[24];
- char topic[100];
- int maxmsgs;
- int rcvdmsgs[3];
- int sentmsgs[3];
- int testFinished;
- int subscribed;
-} AsyncTestClient;
-
-#define AsyncTestClient_initializer {NULL, "\0", "\0", 0, {0, 0, 0}, {0, 0, 0}, 0, 0}
-
-void getopts(int argc, char** argv)
-{
- int count = 1;
-
- while (count < argc)
- {
- if (strcmp(argv[count], "--help") == 0)
- {
- usage();
- }
- else if (strcmp(argv[count], "--test_no") == 0)
- {
- if (++count < argc)
- options.test_no = atoi(argv[count]);
- else
- usage();
- }
- else if (strcmp(argv[count], "--client_key") == 0)
- {
- if (++count < argc)
- options.client_key_file = argv[count];
- else
- usage();
- }
- else if (strcmp(argv[count], "--client_key_pass") == 0)
- {
- if (++count < argc)
- options.client_key_pass = argv[count];
- else
- usage();
- }
- else if (strcmp(argv[count], "--server_key") == 0)
- {
- if (++count < argc)
- options.server_key_file = argv[count];
- else
- usage();
- }
- else if (strcmp(argv[count], "--verbose") == 0)
- {
- options.verbose = 1;
- printf("\nSetting verbose on\n");
- }
- else if (strcmp(argv[count], "--hostname") == 0)
- {
- if (++count < argc)
- {
- sprintf(options.connection, "ssl://%s:18883", argv[count]);
- printf("Setting connection to %s\n", options.connection);
- sprintf(options.mutual_auth_connection, "ssl://%s:18884", argv[count]);
- printf("Setting mutual_auth_connection to %s\n", options.mutual_auth_connection);
- sprintf(options.nocert_mutual_auth_connection, "ssl://%s:18887", argv[count]);
- printf("Setting nocert_mutual_auth_connection to %s\n",
- options.nocert_mutual_auth_connection);
- sprintf(options.server_auth_connection, "ssl://%s:18885", argv[count]);
- printf("Setting server_auth_connection to %s\n", options.server_auth_connection);
- sprintf(options.anon_connection, "ssl://%s:18886", argv[count]);
- printf("Setting anon_connection to %s\n", options.anon_connection);
- }
- else
- usage();
- }
- count++;
- }
-}
-
-#if 0
-#include /* For general log messages */
-#define MyLog logaLine
-#else
-#define LOGA_DEBUG 0
-#define LOGA_INFO 1
-#include
-#include
-#include
-void MyLog(int LOGA_level, char* format, ...)
-{
- static char msg_buf[256];
- va_list args;
- struct timeb ts;
-
- struct tm *timeinfo;
-
- if (LOGA_level == LOGA_DEBUG && options.verbose == 0)
- return;
-
- ftime(&ts);
- timeinfo = localtime(&ts.time);
- strftime(msg_buf, 80, "%Y%m%d %H%M%S", timeinfo);
-
- sprintf(&msg_buf[strlen(msg_buf)], ".%.3hu ", ts.millitm);
-
- va_start(args, format);
- vsnprintf(&msg_buf[strlen(msg_buf)], sizeof(msg_buf) - strlen(msg_buf),
- format, args);
- va_end(args);
-
- printf("%s\n", msg_buf);
- fflush(stdout);
-}
-#endif
-
-#if defined(WIN32) || defined(_WINDOWS)
-#define mqsleep(A) Sleep(1000*A)
-#define START_TIME_TYPE DWORD
-static DWORD start_time = 0;
-START_TIME_TYPE start_clock(void)
-{
- return GetTickCount();
-}
-#elif defined(AIX)
-#define mqsleep sleep
-#define START_TIME_TYPE struct timespec
-START_TIME_TYPE start_clock(void)
-{
- static struct timespec start;
- clock_gettime(CLOCK_REALTIME, &start);
- return start;
-}
-#else
-#define mqsleep sleep
-#define START_TIME_TYPE struct timeval
-/* TODO - unused - remove? static struct timeval start_time; */
-START_TIME_TYPE start_clock(void)
-{
- struct timeval start_time;
- gettimeofday(&start_time, NULL);
- return start_time;
-}
-#endif
-
-#if defined(WIN32)
-long elapsed(START_TIME_TYPE start_time)
-{
- return GetTickCount() - start_time;
-}
-#elif defined(AIX)
-#define assert(a)
-long elapsed(struct timespec start)
-{
- struct timespec now, res;
-
- clock_gettime(CLOCK_REALTIME, &now);
- ntimersub(now, start, res);
- return (res.tv_sec)*1000L + (res.tv_nsec)/1000000L;
-}
-#else
-long elapsed(START_TIME_TYPE start_time)
-{
- struct timeval now, res;
-
- gettimeofday(&now, NULL);
- timersub(&now, &start_time, &res);
- return (res.tv_sec) * 1000 + (res.tv_usec) / 1000;
-}
-#endif
-
-#define assert(a, b, c, d) myassert(__FILE__, __LINE__, a, b, c, d)
-#define assert1(a, b, c, d, e) myassert(__FILE__, __LINE__, a, b, c, d, e)
-
-#define MAXMSGS 30;
-
-int tests = 0;
-int failures = 0;
-FILE* xml;
-START_TIME_TYPE global_start_time;
-char output[3000];
-char* cur_output = output;
-
-
-void write_test_result()
-{
- long duration = elapsed(global_start_time);
-
- fprintf(xml, " time=\"%ld.%.3ld\" >\n", duration / 1000, duration % 1000);
- if (cur_output != output)
- {
- fprintf(xml, "%s", output);
- cur_output = output;
- }
- fprintf(xml, "\n");
-}
-
-void myassert(char* filename, int lineno, char* description, int value,
- char* format, ...)
-{
- ++tests;
- if (!value)
- {
- va_list args;
-
- ++failures;
- printf("Assertion failed, file %s, line %d, description: %s", filename,
- lineno, description);
-
- va_start(args, format);
- vprintf(format, args);
- va_end(args);
-
- cur_output += sprintf(cur_output, "file %s, line %d \n",
- description, filename, lineno);
- }
- else
- MyLog(LOGA_DEBUG,
- "Assertion succeeded, file %s, line %d, description: %s",
- filename, lineno, description);
-}
-
-/*********************************************************************
-
- Test: multi-threaded client using callbacks
-
- *********************************************************************/
-volatile int multiThread_arrivedcount = 0;
-int multiThread_deliveryCompleted = 0;
-MQTTAsync_message multiThread_pubmsg = MQTTAsync_message_initializer;
-
-void multiThread_deliveryComplete(void* context, MQTTAsync_token dt)
-{
- ++multiThread_deliveryCompleted;
-}
-
-int multiThread_messageArrived(void* context, char* topicName, int topicLen,
- MQTTAsync_message* m)
-{
- ++multiThread_arrivedcount;
- MyLog(LOGA_DEBUG, "Callback: %d message received on topic %s is %.*s.",
- multiThread_arrivedcount, topicName, m->payloadlen,
- (char*) (m->payload));
- if (multiThread_pubmsg.payloadlen != m->payloadlen || memcmp(m->payload,
- multiThread_pubmsg.payload, m->payloadlen) != 0)
- {
- failures++;
- MyLog(LOGA_INFO, "Error: wrong data received lengths %d %d\n",
- multiThread_pubmsg.payloadlen, m->payloadlen);
- }
- MQTTAsync_free(topicName);
- MQTTAsync_freeMessage(&m);
- return 1;
-}
-
-void sendAndReceive(MQTTAsync* c, int qos, char* test_topic)
-{
- MQTTAsync_responseOptions ropts;
- int i = 0;
- int iterations = 50;
- int rc = 0;
- int wait_seconds = 0;
-
- multiThread_deliveryCompleted = 0;
- multiThread_arrivedcount = 0;
-
- MyLog(LOGA_DEBUG, "%d messages at QoS %d", iterations, qos);
- multiThread_pubmsg.payload
- = "a much longer message that we can shorten to the extent that we need to";
- multiThread_pubmsg.payloadlen = 27;
- multiThread_pubmsg.qos = qos;
- multiThread_pubmsg.retained = 0;
-
- for (i = 1; i <= iterations; ++i)
- {
- if (i % 10 == 0)
- rc = MQTTAsync_send(c, test_topic, multiThread_pubmsg.payloadlen,
- multiThread_pubmsg.payload, multiThread_pubmsg.qos,
- multiThread_pubmsg.retained, NULL);
- else
- rc = MQTTAsync_sendMessage(c, test_topic, &multiThread_pubmsg,
- &ropts);
- assert("Good rc from publish", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
-
-#if defined(WIN32)
- Sleep(100);
-#else
- usleep(100000L);
-#endif
-
- wait_seconds = 10;
- while ((multiThread_arrivedcount < i) && (wait_seconds-- > 0))
- {
- MyLog(LOGA_DEBUG, "Arrived %d count %d", multiThread_arrivedcount,
- i);
-#if defined(WIN32)
- Sleep(1000);
-#else
- usleep(1000000L);
-#endif
- }
- assert("Message Arrived", wait_seconds > 0,
- "Time out waiting for message %d\n", i );
- }
- if (qos > 0)
- {
- /* MQ Telemetry can send a message to a subscriber before the server has
- completed the QoS 2 handshake with the publisher. For QoS 1 and 2,
- allow time for the final delivery complete callback before checking
- that all expected callbacks have been made */
- wait_seconds = 10;
- while ((multiThread_deliveryCompleted < iterations) && (wait_seconds--
- > 0))
- {
- MyLog(LOGA_DEBUG, "Delivery Completed %d count %d",
- multiThread_deliveryCompleted, i);
-#if defined(WIN32)
- Sleep(1000);
-#else
- usleep(1000000L);
-#endif
- }
- assert("All Deliveries Complete", wait_seconds > 0,
- "Number of deliveryCompleted callbacks was %d\n",
- multiThread_deliveryCompleted);
- }
-}
-
-/*********************************************************************
-
- Async Callbacks - generic callbacks for send/receive tests
-
- *********************************************************************/
-
-//static mutex_type client_mutex = NULL;
-//static pthread_mutex_t client_mutex_store = PTHREAD_MUTEX_INITIALIZER;
-//static mutex_type client_mutex = &client_mutex_store;
-
-void asyncTestOnDisconnect(void* context, MQTTAsync_successData* response)
-{
- //int rc;
-
- AsyncTestClient* tc = (AsyncTestClient*) context;
- MyLog(LOGA_DEBUG, "In asyncTestOnDisconnect callback, %s", tc->clientid);
- //rc = Thread_lock_mutex(client_mutex);
- tc->testFinished = 1;
- //rc = Thread_unlock_mutex(client_mutex);
-}
-
-void asyncTestOnSend(void* context, MQTTAsync_successData* response)
-{
- AsyncTestClient* tc = (AsyncTestClient*) context;
- //int rc;
- int qos = response->alt.pub.message.qos;
- MyLog(LOGA_DEBUG, "In asyncTestOnSend callback, %s", tc->clientid);
- //rc = Thread_lock_mutex(client_mutex);
- tc->sentmsgs[qos]++;
- //rc = Thread_unlock_mutex(client_mutex);
-}
-
-void asyncTestOnSubscribeFailure(void* context, MQTTAsync_failureData* response)
-{
- AsyncTestClient* tc = (AsyncTestClient*) context;
- MyLog(LOGA_DEBUG, "In asyncTestOnSubscribeFailure callback, %s",
- tc->clientid);
-
- assert("There should be no failures in this test. ", 0, "asyncTestOnSubscribeFailure callback was called\n", 0);
-}
-
-void asyncTestOnUnsubscribe(void* context, MQTTAsync_successData* response)
-{
- AsyncTestClient* tc = (AsyncTestClient*) context;
- MQTTAsync_disconnectOptions opts = MQTTAsync_disconnectOptions_initializer;
- int rc;
-
- MyLog(LOGA_DEBUG, "In asyncTestOnUnsubscribe callback, %s", tc->clientid);
- opts.onSuccess = asyncTestOnDisconnect;
- opts.context = tc;
-
- rc = MQTTAsync_disconnect(tc->client, &opts);
-}
-
-void asyncTestOnSubscribe(void* context, MQTTAsync_successData* response)
-{
- AsyncTestClient* tc = (AsyncTestClient*) context;
- int rc, i;
- MyLog(LOGA_DEBUG, "In asyncTestOnSubscribe callback, %s", tc->clientid);
- //rc = Thread_lock_mutex(client_mutex);
- tc->subscribed = 1;
- //rc = Thread_unlock_mutex(client_mutex);
- for (i = 0; i < 3; i++)
- {
- MQTTAsync_message pubmsg = MQTTAsync_message_initializer;
-
- pubmsg.payload
- = "a much longer message that we can shorten to the extent that we need to payload up to 11";
- pubmsg.payloadlen = 11;
- pubmsg.qos = i;
- pubmsg.retained = 0;
-
- MQTTAsync_responseOptions opts = MQTTAsync_responseOptions_initializer;
- //opts.onSuccess = asyncTestOnSend;
- opts.context = &tc;
-
- rc = MQTTAsync_send(tc->client, tc->topic, pubmsg.payloadlen,
- pubmsg.payload, pubmsg.qos, pubmsg.retained, &opts);
- assert("Good rc from publish", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
- tc->sentmsgs[i]++;
- MyLog(LOGA_DEBUG, "Maxmsgs %d", tc->maxmsgs);
- }
-}
-
-int asyncTestMessageArrived(void* context, char* topicName, int topicLen,
- MQTTAsync_message* m)
-{
- AsyncTestClient* tc = (AsyncTestClient*) context;
- int rc;
- //rc = Thread_lock_mutex(client_mutex);
- tc->rcvdmsgs[m->qos]++;
-
- //printf("Received messages: %d\n", tc->rcvdmsgs[m->qos]);
-
- MyLog(
- LOGA_DEBUG,
- "In asyncTestMessageArrived callback, %s total to exit %d, total received %d,%d,%d",
- tc->clientid, (tc->maxmsgs * 3), tc->rcvdmsgs[0], tc->rcvdmsgs[1],
- tc->rcvdmsgs[2]);
-
- if (tc->sentmsgs[m->qos] < tc->maxmsgs)
- {
- MQTTAsync_responseOptions opts = MQTTAsync_responseOptions_initializer;
-
- //opts.onSuccess = asyncTestOnSend;
- opts.context = tc;
-
- MQTTAsync_message pubmsg = MQTTAsync_message_initializer;
- pubmsg.payload
- = "a much longer message that we can shorten to the extent that we need to payload up to 11";
- pubmsg.payloadlen = 11;
- pubmsg.qos = m->qos;
- pubmsg.retained = 0;
-
- rc = MQTTAsync_send(tc->client, tc->topic, pubmsg.payloadlen,
- pubmsg.payload, pubmsg.qos, pubmsg.retained, &opts);
- assert("Good rc from publish", rc == MQTTASYNC_SUCCESS, "rc was %d messages sent %d,%d,%d", rc);
- MyLog(LOGA_DEBUG, "Messages sent %d,%d,%d", tc->sentmsgs[0],
- tc->sentmsgs[1], tc->sentmsgs[2]);
- tc->sentmsgs[m->qos]++;
- }
- if ((tc->rcvdmsgs[0] + tc->rcvdmsgs[1] + tc->rcvdmsgs[2]) == (tc->maxmsgs
- * 3))
- {
- MyLog(LOGA_DEBUG, "Ready to unsubscribe");
- MQTTAsync_responseOptions opts = MQTTAsync_responseOptions_initializer;
-
- opts.onSuccess = asyncTestOnUnsubscribe;
- opts.context = tc;
- rc = MQTTAsync_unsubscribe(tc->client, tc->topic, &opts);
- assert("Unsubscribe successful", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
- }
- //rc = Thread_unlock_mutex(client_mutex);
- MyLog(LOGA_DEBUG, "Leaving asyncTestMessageArrived callback");
- MQTTAsync_freeMessage(&m);
- MQTTAsync_free(topicName);
- return 1;
-}
-
-void asyncTestOnDeliveryComplete(void* context, MQTTAsync_token token)
-{
-
-}
-
-void asyncTestOnConnect(void* context, MQTTAsync_successData* response)
-{
- AsyncTestClient* tc = (AsyncTestClient*) context;
- int subsqos = 2;
- int rc;
- MyLog(LOGA_DEBUG, "In asyncTestOnConnect callback, %s", tc->clientid);
-
- MQTTAsync_responseOptions opts = MQTTAsync_responseOptions_initializer;
- opts.onSuccess = asyncTestOnSubscribe;
- opts.onFailure = asyncTestOnSubscribeFailure;
- opts.context = tc;
-
- rc = MQTTAsync_subscribe(tc->client, tc->topic, subsqos, &opts);
- assert("Good rc from subscribe", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
-}
-
-/*********************************************************************
-
- Test1: SSL connection to non SSL MQTT server
-
- *********************************************************************/
-
-int test1Finished = 0;
-
-int test1OnFailureCalled = 0;
-
-void test1OnFailure(void* context, MQTTAsync_failureData* response)
-{
- MyLog(LOGA_DEBUG, "In connect onFailure callback, context %p", context);
-
- test1OnFailureCalled++;
- test1Finished = 1;
-}
-
-void test1OnConnect(void* context, MQTTAsync_successData* response)
-{
-
- MyLog(LOGA_DEBUG, "In connect onSuccess callback, context %p\n", context);
-
- assert("Connect should not succeed", 0, "connect success callback was called", 0);
-
- test1Finished = 1;
-}
-
-int test1(struct Options options)
-{
- char* testname = "test1";
- int subsqos = 2;
- MQTTAsync c;
- MQTTAsync_connectOptions opts = MQTTAsync_connectOptions_initializer;
- MQTTAsync_willOptions wopts = MQTTAsync_willOptions_initializer;
- MQTTAsync_SSLOptions sslopts = MQTTAsync_SSLOptions_initializer;
- int rc = 0;
- char* test_topic = "C client SSL test1";
- int count = 0;
-
- test1Finished = 0;
- failures = 0;
- MyLog(LOGA_INFO, "Starting SSL test 1 - connection to nonSSL MQTT server");
- fprintf(xml, "message = "will message";
- opts.will->qos = 1;
- opts.will->retained = 0;
- opts.will->topicName = "will topic";
- opts.will = NULL;
- opts.onSuccess = test1OnConnect;
- opts.onFailure = test1OnFailure;
- opts.context = c;
-
- opts.ssl = &sslopts;
- opts.ssl->enableServerCertAuth = 0;
-
- MyLog(LOGA_DEBUG, "Connecting");
- rc = MQTTAsync_connect(c, &opts);
- assert("Good rc from connect", rc == MQTTASYNC_SUCCESS, "rc was %d ", rc);
- if (rc != MQTTASYNC_SUCCESS)
- {
- failures++;
- goto exit;
- }
-
- /* wait for success or failure callback */
- while (!test1Finished && ++count < 10000)
-#if defined(WIN32)
- Sleep(100);
-#else
- usleep(10000L);
-#endif
-
- exit: MQTTAsync_destroy(&c);
- MyLog(LOGA_INFO, "%s: test %s. %d tests run, %d failures.",
- (failures == 0) ? "passed" : "failed", testname, tests, failures);
- write_test_result();
- return failures;
-}
-
-/*********************************************************************
-
- Test2a: Mutual SSL Authentication - Certificates in place on client and server
-
- *********************************************************************/
-
-void test2aOnConnectFailure(void* context, MQTTAsync_failureData* response)
-{
- AsyncTestClient* client = (AsyncTestClient*) context;
- MyLog(LOGA_DEBUG, "In test2aOnConnectFailure callback, %s",
- client->clientid);
-
- assert("There should be no failures in this test. ", 0, "test2aOnConnectFailure callback was called\n", 0);
- client->testFinished = 1;
-}
-
-void test2aOnPublishFailure(void* context, MQTTAsync_failureData* response)
-{
- AsyncTestClient* client = (AsyncTestClient*) context;
- MyLog(LOGA_DEBUG, "In test2aOnPublishFailure callback, %s",
- client->clientid);
-
- assert("There should be no failures in this test. ", 0, "test2aOnPublishFailure callback was called\n", 0);
-}
-
-int test2a(struct Options options)
-{
- char* testname = "test2a";
-
- AsyncTestClient tc =
- AsyncTestClient_initializer;
- MQTTAsync c;
- MQTTAsync_connectOptions opts = MQTTAsync_connectOptions_initializer;
- MQTTAsync_willOptions wopts = MQTTAsync_willOptions_initializer;
- MQTTAsync_SSLOptions sslopts = MQTTAsync_SSLOptions_initializer;
- int rc = 0;
-
- failures = 0;
- MyLog(LOGA_INFO, "Starting test 2a - Mutual SSL authentication");
- fprintf(xml, "message = "will message";
- opts.will->qos = 1;
- opts.will->retained = 0;
- opts.will->topicName = "will topic";
- opts.will = NULL;
- opts.onSuccess = asyncTestOnConnect;
- opts.onFailure = test2aOnConnectFailure;
- opts.context = &tc;
-
- opts.ssl = &sslopts;
- if (options.server_key_file != NULL)
- opts.ssl->trustStore = options.server_key_file; /*file of certificates trusted by client*/
- opts.ssl->keyStore = options.client_key_file; /*file of certificate for client to present to server*/
- if (options.client_key_pass != NULL)
- opts.ssl->privateKeyPassword = options.client_key_pass;
- //opts.ssl->enabledCipherSuites = "DEFAULT";
- //opts.ssl->enabledServerCertAuth = 1;
-
- rc = MQTTAsync_setCallbacks(c, &tc, NULL, asyncTestMessageArrived,
- asyncTestOnDeliveryComplete);
- assert("Good rc from setCallbacks", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
-
- MyLog(LOGA_DEBUG, "Connecting");
- rc = MQTTAsync_connect(c, &opts);
- assert("Good rc from connect", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
- if (rc != MQTTASYNC_SUCCESS)
- goto exit;
-
- while (!tc.subscribed && !tc.testFinished)
-#if defined(WIN32)
- Sleep(100);
-#else
- usleep(10000L);
-#endif
-
- if (tc.testFinished)
- goto exit;
-
- while (!tc.testFinished)
-#if defined(WIN32)
- Sleep(100);
-#else
- usleep(10000L);
-#endif
-
- MyLog(LOGA_DEBUG, "Stopping");
-
- exit: MQTTAsync_destroy(&c);
- MyLog(LOGA_INFO, "%s: test %s. %d tests run, %d failures.",
- (failures == 0) ? "passed" : "failed", testname, tests, failures);
- write_test_result();
- return failures;
-}
-
-/*********************************************************************
-
- Test2b: Mutual SSL Authentication - Server does not have Client cert
-
- *********************************************************************/
-
-int test2bFinished;
-
-void test2bOnConnectFailure(void* context, MQTTAsync_failureData* response)
-{
- MyLog(LOGA_DEBUG, "In test2bOnConnectFailure callback, context %p", context);
-
- assert("This test should call test2bOnConnectFailure. ", 1, "test2bOnConnectFailure callback was called\n", 1);
- test2bFinished = 1;
-}
-
-void test2bOnConnect(void* context, MQTTAsync_successData* response)
-{
- MyLog(LOGA_DEBUG, "In test2bOnConnectFailure callback, context %p", context);
-
- assert("This connect should not succeed. ", 0, "test2bOnConnect callback was called\n", 0);
- test2bFinished = 1;
-}
-
-int test2b(struct Options options)
-{
- char* testname = "test2b";
- int subsqos = 2;
- MQTTAsync c;
- MQTTAsync_connectOptions opts = MQTTAsync_connectOptions_initializer;
- MQTTAsync_willOptions wopts = MQTTAsync_willOptions_initializer;
- MQTTAsync_SSLOptions sslopts = MQTTAsync_SSLOptions_initializer;
- int rc = 0;
- int count = 0;
-
- test2bFinished = 0;
- failures = 0;
- MyLog(LOGA_INFO,
- "Starting test 2b - connection to SSL MQTT server with clientauth=req but server does not have client cert");
- fprintf(xml, "message = "will message";
- opts.will->qos = 1;
- opts.will->retained = 0;
- opts.will->topicName = "will topic";
- opts.will = NULL;
- opts.onSuccess = test2bOnConnect;
- opts.onFailure = test2bOnConnectFailure;
- opts.context = c;
-
- opts.ssl = &sslopts;
- if (options.server_key_file != NULL)
- opts.ssl->trustStore = options.server_key_file; /*file of certificates trusted by client*/
- opts.ssl->keyStore = options.client_key_file; /*file of certificate for client to present to server*/
- if (options.client_key_pass != NULL)
- opts.ssl->privateKeyPassword = options.client_key_pass;
- //opts.ssl->enabledCipherSuites = "DEFAULT";
- //opts.ssl->enabledServerCertAuth = 0;
-
- MyLog(LOGA_DEBUG, "Connecting");
- rc = MQTTAsync_connect(c, &opts);
- assert("Good rc from connect", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
- if (rc != MQTTASYNC_SUCCESS)
- goto exit;
-
- while (!test2bFinished && ++count < 10000)
-#if defined(WIN32)
- Sleep(100);
-#else
- usleep(10000L);
-#endif
-
- exit: MQTTAsync_destroy(&c);
- MyLog(LOGA_INFO, "%s: test %s. %d tests run, %d failures.",
- (failures == 0) ? "passed" : "failed", testname, tests, failures);
- write_test_result();
- return failures;
-}
-
-/*********************************************************************
-
- Test2c: Mutual SSL Authentication - Client does not have Server cert
-
- *********************************************************************/
-
-int test2cFinished;
-
-void test2cOnConnectFailure(void* context, MQTTAsync_failureData* response)
-{
- MyLog(LOGA_DEBUG, "In test2cOnConnectFailure callback, context %p", context);
-
- assert("This test should call test2cOnConnectFailure. ", 1, "test2cOnConnectFailure callback was called\n", 0);
- test2cFinished = 1;
-}
-
-void test2cOnConnect(void* context, MQTTAsync_successData* response)
-{
- MyLog(LOGA_DEBUG, "In test2cOnConnectFailure callback, context %p", context);
-
- assert("This connect should not succeed. ", 0, "test2cOnConnect callback was called\n", 0);
- test2cFinished = 1;
-}
-
-int test2c(struct Options options)
-{
- char* testname = "test2c";
- int subsqos = 2;
- MQTTAsync c;
- MQTTAsync_connectOptions opts = MQTTAsync_connectOptions_initializer;
- MQTTAsync_willOptions wopts = MQTTAsync_willOptions_initializer;
- MQTTAsync_SSLOptions sslopts = MQTTAsync_SSLOptions_initializer;
- int rc = 0;
- char* test_topic = "C client test2c";
- int count = 0;
-
- failures = 0;
- MyLog(
- LOGA_INFO,
- "Starting test 2c - connection to SSL MQTT server, server auth enabled but unknown cert");
- fprintf(xml, "message = "will message";
- opts.will->qos = 1;
- opts.will->retained = 0;
- opts.will->topicName = "will topic";
- opts.will = NULL;
- opts.onSuccess = test2cOnConnect;
- opts.onFailure = test2cOnConnectFailure;
- opts.context = c;
-
- opts.ssl = &sslopts;
- //if (options.server_key_file != NULL) opts.ssl->trustStore = options.server_key_file; /*file of certificates trusted by client*/
- opts.ssl->keyStore = options.client_key_file; /*file of certificate for client to present to server*/
- if (options.client_key_pass != NULL)
- opts.ssl->privateKeyPassword = options.client_key_pass;
- //opts.ssl->enabledCipherSuites = "DEFAULT";
- //opts.ssl->enabledServerCertAuth = 0;
-
- MyLog(LOGA_DEBUG, "Connecting");
- rc = MQTTAsync_connect(c, &opts);
- assert("Good rc from connect", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
- if (rc != MQTTASYNC_SUCCESS)
- {
- failures++;
- goto exit;
- }
-
- while (!test2cFinished && ++count < 10000)
-#if defined(WIN32)
- Sleep(100);
-#else
- usleep(10000L);
-#endif
-
- exit: MQTTAsync_destroy(&c);
- MyLog(LOGA_INFO, "%s: test %s. %d tests run, %d failures.",
- (failures == 0) ? "passed" : "failed", testname, tests, failures);
- write_test_result();
- return failures;
-}
-
-/*********************************************************************
-
- Test3a: Server Authentication - server certificate in client trust store
-
- *********************************************************************/
-
-void test3aOnConnectFailure(void* context, MQTTAsync_failureData* response)
-{
- AsyncTestClient* client = (AsyncTestClient*) context;
- MyLog(LOGA_DEBUG, "In test3aOnConnectFailure callback, context %p", context);
-
- assert("There should be no failures in this test. ", 0, "test3aOnConnectFailure callback was called\n", 0);
- client->testFinished = 1;
-}
-
-int test3a(struct Options options)
-{
- char* testname = "test3a";
- int subsqos = 2;
- /* TODO - usused - remove ? MQTTAsync_deliveryToken* dt = NULL; */
- AsyncTestClient tc =
- AsyncTestClient_initializer;
- MQTTAsync c;
- MQTTAsync_connectOptions opts = MQTTAsync_connectOptions_initializer;
- MQTTAsync_willOptions wopts = MQTTAsync_willOptions_initializer;
- MQTTAsync_SSLOptions sslopts = MQTTAsync_SSLOptions_initializer;
- int rc = 0;
- int i;
-
- failures = 0;
-
- MyLog(LOGA_INFO, "Starting test 3a - Server authentication");
- fprintf(xml, "message = "will message";
- opts.will->qos = 1;
- opts.will->retained = 0;
- opts.will->topicName = "will topic";
- opts.will = NULL;
- opts.onSuccess = asyncTestOnConnect;
- opts.onFailure = test3aOnConnectFailure;
- opts.context = &tc;
-
- opts.ssl = &sslopts;
- if (options.server_key_file != NULL)
- opts.ssl->trustStore = options.server_key_file; /*file of certificates trusted by client*/
- //opts.ssl->keyStore = options.client_key_file; /*file of certificate for client to present to server*/
- //if (options.client_key_pass != NULL) opts.ssl->privateKeyPassword = options.client_key_pass;
- //opts.ssl->enabledCipherSuites = "DEFAULT";
- //opts.ssl->enabledServerCertAuth = 1;
-
- rc = MQTTAsync_setCallbacks(c, &tc, NULL, asyncTestMessageArrived,
- asyncTestOnDeliveryComplete);
- assert("Good rc from setCallbacks", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
-
- MyLog(LOGA_DEBUG, "Connecting");
- rc = MQTTAsync_connect(c, &opts);
- assert("Good rc from connect", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
- if (rc != MQTTASYNC_SUCCESS)
- goto exit;
-
- while (!tc.subscribed && !tc.testFinished)
-#if defined(WIN32)
- Sleep(100);
-#else
- usleep(10000L);
-#endif
-
- if (tc.testFinished)
- goto exit;
-
- for (i = 0; i < 3; i++)
- {
- MQTTAsync_message pubmsg = MQTTAsync_message_initializer;
-
- pubmsg.payload
- = "a much longer message that we can shorten to the extent that we need to payload up to 11";
- pubmsg.payloadlen = 11;
- pubmsg.qos = i;
- pubmsg.retained = 0;
-
- MQTTAsync_responseOptions opts = MQTTAsync_responseOptions_initializer;
- opts.onSuccess = asyncTestOnSend;
- opts.context = &tc;
-
- rc = MQTTAsync_send(c, tc.topic, pubmsg.payloadlen, pubmsg.payload,
- pubmsg.qos, pubmsg.retained, &opts);
- assert("Good rc from publish", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
- }
-
- while (!tc.testFinished)
-#if defined(WIN32)
- Sleep(100);
-#else
- usleep(10000L);
-#endif
-
- MyLog(LOGA_DEBUG, "Stopping");
-
- MQTTAsync_destroy(&c);
-
- exit: MyLog(LOGA_INFO, "%s: test %s. %d tests run, %d failures.", (failures
- == 0) ? "passed" : "failed", testname, tests, failures);
- write_test_result();
- return failures;
-}
-
-/*********************************************************************
-
- Test3b: Server Authentication - Client does not have server cert
-
- *********************************************************************/
-
-int test3bFinished;
-
-void test3bOnConnectFailure(void* context, MQTTAsync_failureData* response)
-{
- MyLog(LOGA_DEBUG, "In test3bOnConnectFailure callback, context %p", context);
-
- assert("This test should call test3bOnConnectFailure. ", 1, "test3bOnConnectFailure callback was called\n", 1);
- test3bFinished = 1;
-}
-
-void test3bOnConnect(void* context, MQTTAsync_successData* response)
-{
- MyLog(LOGA_DEBUG, "In test3bOnConnectFailure callback, context %p", context);
-
- assert("This connect should not succeed. ", 0, "test3bOnConnect callback was called\n", 0);
- test3bFinished = 1;
-}
-
-int test3b(struct Options options)
-{
- char* testname = "test3b";
- int subsqos = 2;
- MQTTAsync c;
- MQTTAsync_connectOptions opts = MQTTAsync_connectOptions_initializer;
- MQTTAsync_willOptions wopts = MQTTAsync_willOptions_initializer;
- MQTTAsync_SSLOptions sslopts = MQTTAsync_SSLOptions_initializer;
- int rc = 0;
- int count = 0;
-
- test3bFinished = 0;
- failures = 0;
- MyLog(
- LOGA_INFO,
- "Starting test 3b - connection to SSL MQTT server with clientauth=opt but client does not have server cert");
- fprintf(xml, "message = "will message";
- opts.will->qos = 1;
- opts.will->retained = 0;
- opts.will->topicName = "will topic";
- opts.will = NULL;
- opts.onSuccess = test3bOnConnect;
- opts.onFailure = test3bOnConnectFailure;
- opts.context = c;
-
- opts.ssl = &sslopts;
- //if (options.server_key_file != NULL) opts.ssl->trustStore = options.server_key_file; /*file of certificates trusted by client*/
- //opts.ssl->keyStore = options.client_key_file; /*file of certificate for client to present to server*/
- //if (options.client_key_pass != NULL) opts.ssl->privateKeyPassword = options.client_key_pass;
- //opts.ssl->enabledCipherSuites = "DEFAULT";
- //opts.ssl->enabledServerCertAuth = 0;
-
- MyLog(LOGA_DEBUG, "Connecting");
- rc = MQTTAsync_connect(c, &opts);
- assert("Good rc from connect", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
- if (rc != MQTTASYNC_SUCCESS)
- goto exit;
-
- while (!test3bFinished && ++count < 10000)
-#if defined(WIN32)
- Sleep(100);
-#else
- usleep(10000L);
-#endif
-
- exit: MQTTAsync_destroy(&c);
- MyLog(LOGA_INFO, "%s: test %s. %d tests run, %d failures.",
- (failures == 0) ? "passed" : "failed", testname, tests, failures);
- write_test_result();
- return failures;
-}
-
-/*********************************************************************
-
- Test4: Accept invalid server certificates
-
- *********************************************************************/
-
-void test4OnConnectFailure(void* context, MQTTAsync_failureData* response)
-{
- AsyncTestClient* client = (AsyncTestClient*) context;
- MyLog(LOGA_DEBUG, "In test4OnConnectFailure callback, context %p", context);
-
- assert("There should be no failures in this test. ", 0, "test4OnConnectFailure callback was called\n", 0);
- client->testFinished = 1;
-}
-
-void test4OnPublishFailure(void* context, MQTTAsync_failureData* response)
-{
- MyLog(LOGA_DEBUG, "In test4OnPublishFailure callback, context %p", context);
-
- assert("There should be no failures in this test. ", 0, "test4OnPublishFailure callback was called\n", 0);
-}
-
-int test4(struct Options options)
-{
- char* testname = "test4";
- int subsqos = 2;
- /* TODO - usused - remove ? MQTTAsync_deliveryToken* dt = NULL; */
- AsyncTestClient tc =
- AsyncTestClient_initializer;
- MQTTAsync c;
- MQTTAsync_connectOptions opts = MQTTAsync_connectOptions_initializer;
- MQTTAsync_willOptions wopts = MQTTAsync_willOptions_initializer;
- MQTTAsync_SSLOptions sslopts = MQTTAsync_SSLOptions_initializer;
- int rc = 0;
- int i;
-
- failures = 0;
-
- MyLog(LOGA_INFO, "Starting test 4 - accept invalid server certificates");
- fprintf(xml, "message = "will message";
- opts.will->qos = 1;
- opts.will->retained = 0;
- opts.will->topicName = "will topic";
- opts.will = NULL;
- opts.onSuccess = asyncTestOnConnect;
- opts.onFailure = test4OnConnectFailure;
- opts.context = &tc;
-
- opts.ssl = &sslopts;
- //if (options.server_key_file != NULL) opts.ssl->trustStore = options.server_key_file; /*file of certificates trusted by client*/
- //opts.ssl->keyStore = options.client_key_file; /*file of certificate for client to present to server*/
- //if (options.client_key_pass != NULL) opts.ssl->privateKeyPassword = options.client_key_pass;
- //opts.ssl->enabledCipherSuites = "DEFAULT";
- opts.ssl->enableServerCertAuth = 0;
-
- rc = MQTTAsync_setCallbacks(c, &tc, NULL, asyncTestMessageArrived,
- asyncTestOnDeliveryComplete);
- assert("Good rc from setCallbacks", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
-
- MyLog(LOGA_DEBUG, "Connecting");
- rc = MQTTAsync_connect(c, &opts);
- assert("Good rc from connect", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
- if (rc != MQTTASYNC_SUCCESS)
- goto exit;
-
- while (!tc.subscribed && !tc.testFinished)
-#if defined(WIN32)
- Sleep(100);
-#else
- usleep(10000L);
-#endif
-
- if (tc.testFinished)
- goto exit;
-
- for (i = 0; i < 3; i++)
- {
- MQTTAsync_message pubmsg = MQTTAsync_message_initializer;
-
- pubmsg.payload
- = "a much longer message that we can shorten to the extent that we need to payload up to 11";
- pubmsg.payloadlen = 11;
- pubmsg.qos = i;
- pubmsg.retained = 0;
-
- MQTTAsync_responseOptions opts = MQTTAsync_responseOptions_initializer;
- opts.onSuccess = asyncTestOnSend;
- opts.context = &tc;
-
- rc = MQTTAsync_send(c, tc.topic, pubmsg.payloadlen, pubmsg.payload,
- pubmsg.qos, pubmsg.retained, &opts);
- assert("Good rc from publish", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
- }
-
- while (!tc.testFinished)
-#if defined(WIN32)
- Sleep(100);
-#else
- usleep(10000L);
-#endif
-
- MyLog(LOGA_DEBUG, "Stopping");
-
- exit: MQTTAsync_destroy(&c);
- MyLog(LOGA_INFO, "%s: test %s. %d tests run, %d failures.",
- (failures == 0) ? "passed" : "failed", testname, tests, failures);
- write_test_result();
- return failures;
-}
-
-/*********************************************************************
-
- Test5a: Anonymous ciphers - server auth disabled
-
- *********************************************************************/
-
-void test5aOnConnectFailure(void* context, MQTTAsync_failureData* response)
-{
- AsyncTestClient* client = (AsyncTestClient*) context;
- MyLog(LOGA_DEBUG, "In test5aOnConnectFailure callback, context %p", context);
-
- assert("There should be no failures in this test. ", 0, "test5aOnConnectFailure callback was called\n", 0);
- client->testFinished = 1;
-}
-
-void test5aOnPublishFailure(void* context, MQTTAsync_failureData* response)
-{
- MyLog(LOGA_DEBUG, "In test5aOnPublishFailure callback, context %p", context);
-
- assert("There should be no failures in this test. ", 0, "test5aOnPublishFailure callback was called\n", 0);
-}
-
-int test5a(struct Options options)
-{
- char* testname = "test5a";
-
- AsyncTestClient tc =
- AsyncTestClient_initializer;
- MQTTAsync c;
- MQTTAsync_connectOptions opts = MQTTAsync_connectOptions_initializer;
- MQTTAsync_willOptions wopts = MQTTAsync_willOptions_initializer;
- MQTTAsync_SSLOptions sslopts = MQTTAsync_SSLOptions_initializer;
- int rc = 0;
- int i;
-
- failures = 0;
-
- MyLog(LOGA_INFO,
- "Starting SSL test 5a - Anonymous ciphers - server authentication disabled");
- fprintf(xml, "message = "will message";
- opts.will->qos = 1;
- opts.will->retained = 0;
- opts.will->topicName = "will topic";
- opts.will = NULL;
- opts.onSuccess = asyncTestOnConnect;
- opts.onFailure = test5aOnConnectFailure;
- opts.context = &tc;
-
- opts.ssl = &sslopts;
- //opts.ssl->trustStore = /*file of certificates trusted by client*/
- //opts.ssl->keyStore = options.client_key_file; /*file of certificate for client to present to server*/
- //if (options.client_key_pass != NULL) opts.ssl->privateKeyPassword = options.client_key_pass;
- opts.ssl->enabledCipherSuites = "aNULL";
- opts.ssl->enableServerCertAuth = 0;
-
- rc = MQTTAsync_setCallbacks(c, &tc, NULL, asyncTestMessageArrived,
- asyncTestOnDeliveryComplete);
- assert("Good rc from setCallbacks", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
-
- MyLog(LOGA_DEBUG, "Connecting");
- rc = MQTTAsync_connect(c, &opts);
- assert("Good rc from connect", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
- if (rc != MQTTASYNC_SUCCESS)
- goto exit;
-
- while (!tc.subscribed && !tc.testFinished)
-#if defined(WIN32)
- Sleep(100);
-#else
- usleep(10000L);
-#endif
-
- if (tc.testFinished)
- goto exit;
-
- for (i = 0; i < 3; i++)
- {
- MQTTAsync_message pubmsg = MQTTAsync_message_initializer;
-
- pubmsg.payload
- = "a much longer message that we can shorten to the extent that we need to payload up to 11";
- pubmsg.payloadlen = 11;
- pubmsg.qos = i;
- pubmsg.retained = 0;
-
- MQTTAsync_responseOptions opts = MQTTAsync_responseOptions_initializer;
- opts.onSuccess = asyncTestOnSend;
- opts.context = &tc;
-
- rc = MQTTAsync_send(c, tc.topic, pubmsg.payloadlen, pubmsg.payload,
- pubmsg.qos, pubmsg.retained, &opts);
- assert("Good rc from publish", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
- }
-
- while (!tc.testFinished)
-#if defined(WIN32)
- Sleep(100);
-#else
- usleep(10000L);
-#endif
-
- MyLog(LOGA_DEBUG, "Stopping");
-
- exit: MQTTAsync_destroy(&c);
- MyLog(LOGA_INFO, "%s: test %s. %d tests run, %d failures.",
- (failures == 0) ? "passed" : "failed", testname, tests, failures);
- write_test_result();
- return failures;
-}
-
-/*********************************************************************
-
- Test5b: Anonymous ciphers - server auth enabled
-
- ********************************************************************/
-
-void test5bOnConnectFailure(void* context, MQTTAsync_failureData* response)
-{
- AsyncTestClient* client = (AsyncTestClient*) context;
- MyLog(LOGA_DEBUG, "In test5bOnConnectFailure callback, context %p", context);
-
- assert("There should be no failures in this test. ", 0, "test5bOnConnectFailure callback was called\n", 0);
- client->testFinished = 1;
-}
-
-void test5bOnPublishFailure(void* context, MQTTAsync_failureData* response)
-{
- MyLog(LOGA_DEBUG, "In test5bOnPublishFailure callback, context %p", context);
-
- assert("There should be no failures in this test. ", 0, "test5bOnPublishFailure callback was called\n", 0);
-}
-
-int test5b(struct Options options)
-{
- char* testname = "test5b";
-
- AsyncTestClient tc =
- AsyncTestClient_initializer;
- MQTTAsync c;
- MQTTAsync_connectOptions opts = MQTTAsync_connectOptions_initializer;
- MQTTAsync_willOptions wopts = MQTTAsync_willOptions_initializer;
- MQTTAsync_SSLOptions sslopts = MQTTAsync_SSLOptions_initializer;
- int rc = 0;
- int i;
-
- failures = 0;
-
- MyLog(LOGA_INFO,
- "Starting SSL test 5b - Anonymous ciphers - server authentication enabled");
- fprintf(xml, "message = "will message";
- opts.will->qos = 1;
- opts.will->retained = 0;
- opts.will->topicName = "will topic";
- opts.will = NULL;
- opts.onSuccess = asyncTestOnConnect;
- opts.onFailure = test5bOnConnectFailure;
- opts.context = &tc;
-
- opts.ssl = &sslopts;
- //opts.ssl->trustStore = /*file of certificates trusted by client*/
- //opts.ssl->keyStore = options.client_key_file; /*file of certificate for client to present to server*/
- //if (options.client_key_pass != NULL) opts.ssl->privateKeyPassword = options.client_key_pass;
- opts.ssl->enabledCipherSuites = "aNULL";
- opts.ssl->enableServerCertAuth = 1;
-
- rc = MQTTAsync_setCallbacks(c, &tc, NULL, asyncTestMessageArrived,
- asyncTestOnDeliveryComplete);
- assert("Good rc from setCallbacks", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
-
- MyLog(LOGA_DEBUG, "Connecting");
- rc = MQTTAsync_connect(c, &opts);
- assert("Good rc from connect", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
- if (rc != MQTTASYNC_SUCCESS)
- goto exit;
-
- while (!tc.subscribed && !tc.testFinished)
-#if defined(WIN32)
- Sleep(100);
-#else
- usleep(10000L);
-#endif
-
- if (tc.testFinished)
- goto exit;
-
- for (i = 0; i < 3; i++)
- {
- MQTTAsync_message pubmsg = MQTTAsync_message_initializer;
-
- pubmsg.payload
- = "a much longer message that we can shorten to the extent that we need to payload up to 11";
- pubmsg.payloadlen = 11;
- pubmsg.qos = i;
- pubmsg.retained = 0;
-
- MQTTAsync_responseOptions opts = MQTTAsync_responseOptions_initializer;
- opts.onSuccess = asyncTestOnSend;
- opts.context = &tc;
-
- rc = MQTTAsync_send(c, tc.topic, pubmsg.payloadlen, pubmsg.payload,
- pubmsg.qos, pubmsg.retained, &opts);
- assert("Good rc from publish", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
- }
-
- while (!tc.testFinished)
-#if defined(WIN32)
- Sleep(100);
-#else
- usleep(10000L);
-#endif
-
- MyLog(LOGA_DEBUG, "Stopping");
-
- exit: MQTTAsync_destroy(&c);
- MyLog(LOGA_INFO, "%s: test %s. %d tests run, %d failures.",
- (failures == 0) ? "passed" : "failed", testname, tests, failures);
- write_test_result();
- return failures;
-}
-
-/*********************************************************************
-
- Test5c: Anonymous ciphers - client not using anonymous ciphers
-
- *********************************************************************/
-
-int test5cFinished;
-
-void test5cOnConnectFailure(void* context, MQTTAsync_failureData* response)
-{
- MyLog(LOGA_DEBUG, "In test5cOnConnectFailure callback, context %p", context);
-
- assert("This test should call test5cOnConnectFailure. ", 1, "test5cOnConnectFailure callback was called\n", 1);
- test5cFinished = 1;
-}
-
-void test5cOnConnect(void* context, MQTTAsync_successData* response)
-{
- MyLog(LOGA_DEBUG, "In test5cOnConnectFailure callback, context %p", context);
-
- assert("This connect should not succeed. ", 0, "test5cOnConnect callback was called\n", 0);
- test5cFinished = 1;
-}
-
-int test5c(struct Options options)
-{
- char* testname = "test5c";
- int subsqos = 2;
- MQTTAsync c;
- MQTTAsync_connectOptions opts = MQTTAsync_connectOptions_initializer;
- MQTTAsync_willOptions wopts = MQTTAsync_willOptions_initializer;
- MQTTAsync_SSLOptions sslopts = MQTTAsync_SSLOptions_initializer;
- int rc = 0;
- int count = 0;
-
- test5cFinished = 0;
- failures = 0;
- MyLog(LOGA_INFO,
- "Starting SSL test 5c - Anonymous ciphers - client not using anonymous cipher");
- fprintf(xml, "message = "will message";
- opts.will->qos = 1;
- opts.will->retained = 0;
- opts.will->topicName = "will topic";
- opts.will = NULL;
- opts.onSuccess = test5cOnConnect;
- opts.onFailure = test5cOnConnectFailure;
- opts.context = c;
-
- opts.ssl = &sslopts;
- //opts.ssl->trustStore = /*file of certificates trusted by client*/
- //opts.ssl->keyStore = options.client_key_file; /*file of certificate for client to present to server*/
- //if (options.client_key_pass != NULL) opts.ssl->privateKeyPassword = options.client_key_pass;
- //opts.ssl->enabledCipherSuites = "DEFAULT";
- opts.ssl->enableServerCertAuth = 0;
-
- MyLog(LOGA_DEBUG, "Connecting");
- rc = MQTTAsync_connect(c, &opts);
- assert("Good rc from connect", rc == MQTTASYNC_SUCCESS, "rc was %d\n", rc);
- if (rc != MQTTASYNC_SUCCESS)
- goto exit;
-
- while (!test5cFinished && ++count < 10000)
-#if defined(WIN32)
- Sleep(100);
-#else
- usleep(10000L);
-#endif
-
-exit:
- MQTTAsync_destroy(&c);
- MyLog(LOGA_INFO, "%s: test %s. %d tests run, %d failures.",
- (failures == 0) ? "passed" : "failed", testname, tests, failures);
- write_test_result();
- return failures;
-}
-
-/*********************************************************************
-
- Test6: More than one client object - simultaneous working.
-
- *********************************************************************/
-
-void test6OnConnectFailure(void* context, MQTTAsync_failureData* response)
-{
- AsyncTestClient* client = (AsyncTestClient*) context;
- MyLog(LOGA_DEBUG, "In test6OnConnectFailure callback, context %p", context);
-
- assert("There should be no failures in this test. ", 0, "test6OnConnectFailure callback was called\n", 0);
- client->testFinished = 1;
-}
-
-void test6OnPublishFailure(void* context, MQTTAsync_failureData* response)
-{
- MyLog(LOGA_DEBUG, "In test6OnPublishFailure callback, context %p", context);
-
- assert("There should be no failures in this test. ", 0, "test6OnPublishFailure callback was called\n", 0);
-}
-
-int test6(struct Options options)
-{
- char* testname = "test6";
-#define num_clients 10
- int subsqos = 2;
- MQTTAsync_connectOptions opts = MQTTAsync_connectOptions_initializer;
- MQTTAsync_willOptions wopts = MQTTAsync_willOptions_initializer;
- MQTTAsync_SSLOptions sslopts = MQTTAsync_SSLOptions_initializer;
- int rc = 0;
- int i;
- AsyncTestClient tc[num_clients];
- int test6finished = 0;
-
- MyLog(LOGA_INFO, "Starting test 6 - multiple connections");
- fprintf(xml, "message = "will message";
- opts.will->qos = 1;
- opts.will->retained = 0;
- opts.will->topicName = "will topic";
- opts.onSuccess = asyncTestOnConnect;
- opts.onFailure = test6OnConnectFailure;
- opts.context = &tc[i];
-
- opts.ssl = &sslopts;
- if (options.server_key_file != NULL)
- opts.ssl->trustStore = options.server_key_file; /*file of certificates trusted by client*/
- opts.ssl->keyStore = options.client_key_file; /*file of certificate for client to present to server*/
- if (options.client_key_pass != NULL)
- opts.ssl->privateKeyPassword = options.client_key_pass;
- //opts.ssl->enabledCipherSuites = "DEFAULT";
- //opts.ssl->enabledServerCertAuth = 1;
-
- MyLog(LOGA_DEBUG, "Connecting");
- rc = MQTTAsync_connect(tc[i].client, &opts);
- assert("Good rc from connect", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
- }
-
- while (test6finished < num_clients)
- {
- MyLog(LOGA_DEBUG, "num_clients %d test_finished %d\n", num_clients,
- test6finished);
-#if defined(WIN32)
- Sleep(100);
-
-#else
- usleep(10000L);
-#endif
- for (i = 0; i < num_clients; ++i)
- {
- if (tc[i].testFinished)
- {
- test6finished++;
- tc[i].testFinished = 0;
- }
- }
- }
-
- MyLog(LOGA_DEBUG, "test6: destroying clients");
-
- for (i = 0; i < num_clients; ++i)
- MQTTAsync_destroy(&tc[i].client);
-
-//exit:
- MyLog(LOGA_INFO, "%s: test %s. %d tests run, %d failures.",
- (failures == 0) ? "passed" : "failed", testname, tests, failures);
- write_test_result();
- return failures;
-}
-
-/*********************************************************************
-
- Test7: Send and receive big messages
-
- *********************************************************************/
-
-void* test7_payload = NULL;
-int test7_payloadlen = 0;
-
-void test7OnConnectFailure(void* context, MQTTAsync_failureData* response)
-{
- AsyncTestClient* client = (AsyncTestClient*) context;
- MyLog(LOGA_DEBUG, "In test7OnConnectFailure callback, %s", client->clientid);
-
- assert("There should be no failures in this test. ", 0, "test7OnConnectFailure callback was called\n", 0);
- client->testFinished = 1;
-}
-
-void test7OnPublishFailure(void* context, MQTTAsync_failureData* response)
-{
- AsyncTestClient* client = (AsyncTestClient*) context;
- MyLog(LOGA_DEBUG, "In test7OnPublishFailure callback, %s", client->clientid);
-
- assert("There should be no failures in this test. ", 0, "test7OnPublishFailure callback was called\n", 0);
- client->testFinished = 1;
-}
-
-int test7MessageArrived(void* context, char* topicName, int topicLen,
- MQTTAsync_message* message)
-{
- AsyncTestClient* tc = (AsyncTestClient*) context;
- static int message_count = 0;
- int rc, i;
-
- MyLog(LOGA_DEBUG, "In messageArrived callback %p", tc);
-
- assert("Message size correct", message->payloadlen == test7_payloadlen,
- "message size was %d", message->payloadlen);
-
- for (i = 0; i < options.size; ++i)
- {
- if (((char*) test7_payload)[i] != ((char*) message->payload)[i])
- {
- assert("Message contents correct", ((char*)test7_payload)[i] != ((char*)message->payload)[i],
- "message content was %c", ((char*)message->payload)[i]);
- break;
- }
- }
-
- if (++message_count == 1)
- {
- MQTTAsync_message pubmsg = MQTTAsync_message_initializer;
- MQTTAsync_responseOptions opts = MQTTAsync_responseOptions_initializer;
-
- pubmsg.payload = test7_payload;
- pubmsg.payloadlen = test7_payloadlen;
- pubmsg.qos = 1;
- pubmsg.retained = 0;
- opts.onSuccess = NULL;
- opts.onFailure = test7OnPublishFailure;
- opts.context = tc;
-
- rc = MQTTAsync_sendMessage(tc->client, tc->topic, &pubmsg, &opts);
- }
- else if (message_count == 2)
- {
- MQTTAsync_message pubmsg = MQTTAsync_message_initializer;
- MQTTAsync_responseOptions opts = MQTTAsync_responseOptions_initializer;
-
- pubmsg.payload = test7_payload;
- pubmsg.payloadlen = test7_payloadlen;
- pubmsg.qos = 0;
- pubmsg.retained = 0;
- opts.onSuccess = NULL;
- opts.onFailure = test7OnPublishFailure;
- opts.context = tc;
- rc = MQTTAsync_sendMessage(tc->client, tc->topic, &pubmsg, &opts);
- }
- else
- {
- MQTTAsync_responseOptions opts = MQTTAsync_responseOptions_initializer;
-
- opts.onSuccess = asyncTestOnUnsubscribe;
- opts.context = tc;
- rc = MQTTAsync_unsubscribe(tc->client, tc->topic, &opts);
- assert("Unsubscribe successful", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
- }
-
- MQTTAsync_freeMessage(&message);
- MQTTAsync_free(topicName);
-
- return 1;
-}
-
-void test7OnSubscribe(void* context, MQTTAsync_successData* response)
-{
- AsyncTestClient* tc = (AsyncTestClient*) context;
- MQTTAsync_message pubmsg = MQTTAsync_message_initializer;
- int rc, i;
-
- MyLog(LOGA_DEBUG, "In subscribe onSuccess callback %p", tc);
-
- pubmsg.payload = test7_payload = malloc(options.size);
- pubmsg.payloadlen = test7_payloadlen = options.size;
-
- srand(33);
- for (i = 0; i < options.size; ++i)
- ((char*) pubmsg.payload)[i] = rand() % 256;
-
- pubmsg.qos = 2;
- pubmsg.retained = 0;
-
- rc = MQTTAsync_send(tc->client, tc->topic, pubmsg.payloadlen, pubmsg.payload,
- pubmsg.qos, pubmsg.retained, NULL);
-}
-
-void test7OnConnect(void* context, MQTTAsync_successData* response)
-{
- AsyncTestClient* tc = (AsyncTestClient*) context;
- MQTTAsync_responseOptions opts = MQTTAsync_responseOptions_initializer;
- int rc;
-
- MyLog(LOGA_DEBUG, "In connect onSuccess callback, context %p", context);
- opts.onSuccess = test7OnSubscribe;
- opts.context = tc;
-
- rc = MQTTAsync_subscribe(tc->client, tc->topic, 2, &opts);
- assert("Good rc from subscribe", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
- if (rc != MQTTASYNC_SUCCESS)
- tc->testFinished = 1;
-}
-
-int test7(struct Options options)
-{
- char* testname = "test7";
- int subsqos = 2;
- AsyncTestClient tc =
- AsyncTestClient_initializer;
- MQTTAsync c;
- MQTTAsync_connectOptions opts = MQTTAsync_connectOptions_initializer;
- MQTTAsync_willOptions wopts = MQTTAsync_willOptions_initializer;
- MQTTAsync_SSLOptions sslopts = MQTTAsync_SSLOptions_initializer;
- int rc = 0;
- char* test_topic = "C client test7";
- int test_finished;
-
- test_finished = failures = 0;
-
- MyLog(LOGA_INFO, "Starting test 7 - big messages");
- fprintf(xml, "message = "will message";
- opts.will->qos = 1;
- opts.will->retained = 0;
- opts.will->topicName = "will topic";
- opts.will = NULL;
- opts.onSuccess = test7OnConnect;
- opts.onFailure = test7OnConnectFailure;
- opts.context = &tc;
-
- opts.ssl = &sslopts;
- if (options.server_key_file != NULL)
- opts.ssl->trustStore = options.server_key_file; /*file of certificates trusted by client*/
- opts.ssl->keyStore = options.client_key_file; /*file of certificate for client to present to server*/
- if (options.client_key_pass != NULL)
- opts.ssl->privateKeyPassword = options.client_key_pass;
- //opts.ssl->enabledCipherSuites = "DEFAULT";
- //opts.ssl->enabledServerCertAuth = 1;
-
- MyLog(LOGA_DEBUG, "Connecting");
- rc = MQTTAsync_connect(c, &opts);
- rc = 0;
- assert("Good rc from connect", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
- if (rc != MQTTASYNC_SUCCESS)
- goto exit;
-
- while (!tc.testFinished)
-#if defined(WIN32)
- Sleep(100);
-#else
- usleep(1000L);
-#endif
-
- MQTTAsync_destroy(&c);
-
- exit: MyLog(LOGA_INFO, "%s: test %s. %d tests run, %d failures.",
- (failures == 0) ? "passed" : "failed", testname, tests, failures);
- write_test_result();
- return failures;
-}
-
-void handleTrace(enum MQTTASYNC_TRACE_LEVELS level, char* message)
-{
- printf("%s\n", message);
-}
-
-int main(int argc, char** argv)
-{
- int* numtests = &tests;
- int rc = 0;
- int (*tests[])() =
- { NULL, test1, test2a, test2b, test2c, test3a, test3b, test4, /* test5a,
- test5b, test5c, */ test6, test7 };
-
- xml = fopen("TEST-test5.xml", "w");
- fprintf(xml, "\n", ARRAY_SIZE(tests) - 1);
-
- MQTTAsync_setTraceCallback(handleTrace);
- getopts(argc, argv);
-
- if (options.test_no == 0)
- { /* 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
- {
- MQTTAsync_setTraceLevel(MQTTASYNC_TRACE_ERROR);
- rc = tests[options.test_no](options); /* run just the selected test */
- }
-
- MyLog(LOGA_INFO, "Total tests run: %d", *numtests);
- if (rc == 0)
- MyLog(LOGA_INFO, "verdict pass");
- else
- MyLog(LOGA_INFO, "verdict fail");
-
- fprintf(xml, "\n");
- fclose(xml);
-
- return rc;
-}
-
diff --git a/org.eclipse.paho.mqtt.c/test/test6.c b/org.eclipse.paho.mqtt.c/test/test6.c
deleted file mode 100644
index 8ddd13c..0000000
--- a/org.eclipse.paho.mqtt.c/test/test6.c
+++ /dev/null
@@ -1,1002 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2011, 2014 IBM Corp.
- *
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * and Eclipse Distribution License v1.0 which accompany this distribution.
- *
- * The Eclipse Public License is available at
- * http://www.eclipse.org/legal/epl-v10.html
- * and the Eclipse Distribution License is available at
- * http://www.eclipse.org/org/documents/edl-v10.php.
- *
- * Contributors:
- * Ian Craggs - initial API and implementation and/or initial documentation
- *******************************************************************************/
-
-
-/**
- * @file
- * Async C client program for the MQTT v3 restart/recovery test suite.
- */
-
-/*
-#if !defined(_RTSHEADER)
- #include
-#endif
-*/
-
-#include "MQTTAsync.h"
-#include
-#include
-
-#if !defined(_WINDOWS)
- #include
- #include
- #include
-#else
- #include
-#endif
-
-void usage()
-{
- printf("help!!\n");
- exit(-1);
-}
-
-static char pub_topic[200];
-static char sub_topic[200];
-
-struct
-{
- char* connection; /**< connection to system under test. */
- char** connections; /**< HA connection list */
- int connection_count;
- char* control_connection; /**< MQTT control connection, for test sync */
- char* topic;
- char* control_topic;
- char* clientid;
- int slot_no;
- int qos;
- int retained;
- char* username;
- char* password;
- int verbose;
- int persistence;
-} opts =
-{
- "tcp://localhost:1885",
- NULL,
- 0,
- "tcp://localhost:7777",
- "XR9TT3",
- "XR9TT3/control",
- "C_broken_client",
- 1,
- 2,
- 0,
- NULL,
- NULL,
- 0,
- 0,
-};
-
-void getopts(int argc, char** argv)
-{
- int count = 1;
-
- while (count < argc)
- {
- if (strcmp(argv[count], "--qos") == 0)
- {
- if (++count < argc)
- {
- if (strcmp(argv[count], "0") == 0)
- opts.qos = 0;
- else if (strcmp(argv[count], "1") == 0)
- opts.qos = 1;
- else if (strcmp(argv[count], "2") == 0)
- opts.qos = 2;
- else
- usage();
- }
- else
- usage();
- }
- else if (strcmp(argv[count], "--slot_no") == 0)
- {
- if (++count < argc)
- opts.slot_no = atoi(argv[count]);
- else
- usage();
- }
- else if (strcmp(argv[count], "--connection") == 0)
- {
- if (++count < argc)
- opts.connection = argv[count];
- else
- usage();
- }
- else if (strcmp(argv[count], "--connections") == 0)
- {
- if (++count < argc)
- {
- opts.connection_count = 0;
- opts.connections = malloc(sizeof(char*) * 5);
- char* tok = strtok(argv[count], " ");
- while (tok)
- {
- opts.connections[opts.connection_count] = malloc(strlen(tok)+1);
- strcpy(opts.connections[opts.connection_count], tok);
- opts.connection_count++;
- tok = strtok(NULL, " ");
- }
- }
- else
- usage();
- }
- else if (strcmp(argv[count], "--control_connection") == 0)
- {
- if (++count < argc)
- opts.control_connection = argv[count];
- else
- usage();
- }
- else if (strcmp(argv[count], "--clientid") == 0)
- {
- if (++count < argc)
- opts.clientid = argv[count];
- else
- usage();
- }
- else if (strcmp(argv[count], "--username") == 0)
- {
- if (++count < argc)
- opts.username = argv[count];
- else
- usage();
- }
- else if (strcmp(argv[count], "--password") == 0)
- {
- if (++count < argc)
- opts.password = argv[count];
- else
- usage();
- }
- else if (strcmp(argv[count], "--persistent") == 0)
- opts.persistence = 1;
- else if (strcmp(argv[count], "--verbose") == 0)
- opts.verbose = 1;
- count++;
- }
-}
-
-#if 0
-#include /* For general log messages */
-#define MyLog logaLine
-#else
-#define LOGA_DEBUG 0
-#define LOGA_ALWAYS 1
-#define LOGA_INFO 2
-#include
-#include
-#include
-void MyLog(int log_level, char* format, ...)
-{
- static char msg_buf[256];
- va_list args;
- struct timeb ts;
-
- struct tm *timeinfo;
-
- if (log_level == LOGA_DEBUG && opts.verbose == 0)
- return;
-
- ftime(&ts);
- timeinfo = localtime(&ts.time);
- strftime(msg_buf, 80, "%Y%m%d %H%M%S", timeinfo);
-
- sprintf(&msg_buf[strlen(msg_buf)], ".%.3hu ", ts.millitm);
-
- sprintf(&msg_buf[strlen(msg_buf)], "%s ", opts.clientid);
-
- va_start(args, format);
- vsnprintf(&msg_buf[strlen(msg_buf)], sizeof(msg_buf) - strlen(msg_buf), format, args);
- va_end(args);
-
- printf("%s\n", msg_buf);
- fflush(stdout);
-}
-#endif
-
-
-#if defined(WIN32) || defined(_WINDOWS)
-#define mqsleep(A) Sleep(1000*A)
-#define START_TIME_TYPE DWORD
-static DWORD start_time = 0;
-START_TIME_TYPE start_clock(void)
-{
- return GetTickCount();
-}
-#elif defined(AIX)
-#define mqsleep sleep
-#define START_TIME_TYPE struct timespec
-START_TIME_TYPE start_clock(void)
-{
- static struct timespec start;
- clock_gettime(CLOCK_REALTIME, &start);
- return start;
-}
-#else
-#define mqsleep sleep
-#define START_TIME_TYPE struct timeval
-static struct timeval start_time;
-START_TIME_TYPE start_clock(void)
-{
- struct timeval start_time;
- gettimeofday(&start_time, NULL);
- return start_time;
-}
-#endif
-
-
-#if defined(WIN32)
-long elapsed(START_TIME_TYPE start_time)
-{
- return GetTickCount() - start_time;
-}
-#elif defined(AIX)
-#define assert(a)
-long elapsed(struct timespec start)
-{
- struct timespec now, res;
-
- clock_gettime(CLOCK_REALTIME, &now);
- ntimersub(now, start, res);
- return (res.tv_sec)*1000L + (res.tv_nsec)/1000000L;
-}
-#else
-long elapsed(START_TIME_TYPE start_time)
-{
- struct timeval now, res;
-
- gettimeofday(&now, NULL);
- timersub(&now, &start_time, &res);
- return (res.tv_sec)*1000 + (res.tv_usec)/1000;
-}
-#endif
-
-MQTTAsync control_client;
-MQTTAsync_connectOptions conn_opts = MQTTAsync_connectOptions_initializer;
-MQTTAsync client;
-int arrivedCount = 0;
-int expectedCount = 0;
-int measuring = 0;
-long roundtrip_time = 0L;
-int errors = 0;
-int stopping = 0;
-int connection_lost = 0; /* for use with the persistence option */
-int recreated = 0;
-int client_cleaned = 0;
-
-char* wait_message = NULL;
-char* wait_message2 = NULL;
-int control_found = 0;
-long last_completion_time = -1;
-int test_count = 1000;
-
-void control_connectionLost(void* context, char* cause)
-{
- MyLog(LOGA_ALWAYS, "Control connection lost - stopping");
-
- stopping = 1;
-}
-
-/**-----------------------------------------------------------------------------
- * Callback which receives messages from the control connection
- * @param context
- * @param topicName the name of the topic on which the message is received
- * @param topicLen the length of the topic name (in case of embedded nulls)
- * @param m pointer to the message received
- * @return boolean
- */
-int control_messageArrived(void* context, char* topicName, int topicLen, MQTTAsync_message* m)
-{
- MyLog(LOGA_DEBUG, "Control message arrived: %.*s %s",
- m->payloadlen, m->payload, wait_message);
- if (strcmp(m->payload, "stop") == 0)
- stopping = 1;
- else if (wait_message != NULL && strncmp(wait_message, m->payload,
- strlen(wait_message)) == 0)
- {
- control_found = 1;
- wait_message = NULL;
- }
- else if (wait_message2 != NULL && strncmp(wait_message2, m->payload,
- strlen(wait_message2)) == 0)
- {
- control_found = 2;
- wait_message2 = NULL;
- }
-
- MQTTAsync_free(topicName);
- MQTTAsync_freeMessage(&m);
- return 1;
-}
-
-
-/* wait for a specific message on the control topic. */
-int control_wait(char* message)
-{
- int count = 0;
- char buf[120];
-
- control_found = 0;
- wait_message = message;
-
- sprintf(buf, "waiting for: %s", message);
- control_send(buf);
-
- while (control_found == 0 && stopping == 0)
- {
- if (++count == 300)
- {
- stopping = 1;
- MyLog(LOGA_ALWAYS, "Failed to receive message %s, stopping ", message);
- return 0; /* time out and tell the caller the message was not found */
- }
- mqsleep(1);
- }
- return control_found;
-}
-
-
-/* wait for a specific message on the control topic. */
-int control_which(char* message1, char* message2)
-{
- int count = 0;
- control_found = 0;
- wait_message = message1;
- wait_message2 = message2;
-
- while (control_found == 0)
- {
- if (++count == 300)
- return 0; /* time out and tell the caller the message was not found */
- mqsleep(1);
- }
- return control_found;
-}
-
-
-int control_send(char* message)
-{
- char buf[156];
- int rc = 0;
- MQTTAsync_responseOptions ropts = MQTTAsync_responseOptions_initializer;
-
- sprintf(buf, "%s: %s", opts.clientid, message);
- rc = MQTTAsync_send(control_client, pub_topic, strlen(buf),
- buf, 1, 0, &ropts);
- MyLog(LOGA_DEBUG, "Control message sent: %s", buf);
-
- return rc;
-}
-
-START_TIME_TYPE global_start_time;
-
-int messageArrived(void* context, char* topicName, int topicLen,
- MQTTAsync_message* m)
-{
- int seqno = -1;
- char* token = NULL;
-
- token = strtok(m->payload, " ");
- token = strtok(NULL, " ");
- token = strtok(NULL, " ");
-
- if (token)
- seqno = atoi(token);
- if (m->qos != opts.qos)
- {
- MyLog(LOGA_ALWAYS, "Error, expecting QoS %d but got %d", opts.qos,
- m->qos);
- errors++;
- } else if (seqno != arrivedCount + 1)
- {
- if (m->qos == 2 || (m->qos == 1 && seqno > arrivedCount + 1))
- {
- if (seqno == -1)
- MyLog(LOGA_ALWAYS,
- "Error, expecting sequence number %d but got message id %d, payload was %.*s",
- arrivedCount + 1, m->msgid, m->payloadlen, m->payload);
- else
- MyLog(LOGA_ALWAYS,
- "Error, expecting sequence number %d but got %d message id %d",
- arrivedCount + 1, seqno, m->msgid);
- errors++;
- }
- }
- arrivedCount++;
- MQTTAsync_free(topicName);
- MQTTAsync_freeMessage(&m);
-
- if (measuring && arrivedCount == test_count)
- roundtrip_time = elapsed(global_start_time);
- return 1;
-}
-
-
-void client_onReconnect(void* context, MQTTAsync_successData* response)
-{
- MQTTAsync c = (MQTTAsync)context;
-
- MyLog(LOGA_ALWAYS, "Successfully reconnected");
-}
-
-
-void client_onReconnectFailure(void* context, MQTTAsync_failureData* response)
-{
- MQTTAsync c = (MQTTAsync)context;
- int rc;
-
- MyLog(LOGA_ALWAYS, "Failed to reconnect with return code %d", (response) ? response->code : -9999);
-
- conn_opts.context = context;
- conn_opts.keepAliveInterval = 10;
- conn_opts.username = opts.username;
- conn_opts.password = opts.password;
- conn_opts.cleansession = 0;
- conn_opts.onSuccess = client_onReconnect;
- conn_opts.onFailure = client_onReconnectFailure;
- rc = MQTTAsync_connect(c, &conn_opts);
- if (rc != MQTTASYNC_SUCCESS)
- {
- MyLog(LOGA_ALWAYS, "Failed to start reconnect with return code %d", rc);
- stopping = 1;
- }
-}
-
-
-void connectionLost(void* context, char* cause)
-{
- MQTTAsync c = (MQTTAsync)context;
- int rc = 0;
-
- MyLog(LOGA_ALWAYS, "Connection lost when %d messages arrived out of %d expected",
- arrivedCount, expectedCount);
- //dotrace = 1;
-
- if (opts.persistence)
- connection_lost = 1;
- else
- {
- conn_opts.context = context;
- conn_opts.keepAliveInterval = 10;
- conn_opts.username = opts.username;
- conn_opts.password = opts.password;
- conn_opts.cleansession = 0;
- conn_opts.onSuccess = client_onReconnect;
- conn_opts.onFailure = client_onReconnectFailure;
- if (opts.connections)
- {
- conn_opts.serverURIcount = opts.connection_count;
- conn_opts.serverURIs = opts.connections;
- }
- else
- {
- conn_opts.serverURIcount = 0;
- conn_opts.serverURIs = NULL;
- }
- printf("reconnecting to first serverURI %s\n", conn_opts.serverURIs[0]);
- rc = MQTTAsync_connect(context, &conn_opts);
- if (rc != MQTTASYNC_SUCCESS)
- {
- MyLog(LOGA_ALWAYS, "Failed to start reconnect with return code %d", rc);
- stopping = 1;
- }
- }
-}
-
-
-int recreateReconnect()
-{
- int rc;
-
- if (recreated == 0)
- {
- MyLog(LOGA_ALWAYS, "Recreating client");
-
- MQTTAsync_destroy(&client); /* destroy the client object so that we force persistence to be read on recreate */
-
- rc = MQTTAsync_create(&client, opts.connection, opts.clientid, MQTTCLIENT_PERSISTENCE_DEFAULT, NULL);
- if (rc != MQTTASYNC_SUCCESS)
- {
- MyLog(LOGA_ALWAYS, "MQTTAsync_create failed, rc %d", rc);
- goto exit;
- }
-
- if ((rc = MQTTAsync_setCallbacks(client, client, connectionLost,
- messageArrived, NULL)) != MQTTASYNC_SUCCESS)
- {
- MyLog(LOGA_ALWAYS, "MQTTAsync_setCallbacks failed, rc %d", rc);
- goto exit;
- }
- recreated = 1;
- }
-
- MyLog(LOGA_ALWAYS, "Reconnecting client");
- conn_opts.keepAliveInterval = 10;
- conn_opts.username = opts.username;
- conn_opts.password = opts.password;
- conn_opts.cleansession = 0;
- conn_opts.context = client;
- conn_opts.onSuccess = client_onReconnect;
- conn_opts.onFailure = client_onReconnectFailure;
- if ((rc = MQTTAsync_connect(client, &conn_opts)) != MQTTASYNC_SUCCESS)
- MyLog(LOGA_ALWAYS, "MQTTAsync_connect failed, rc %d", rc);
- else
- connection_lost = 0;
-
-exit:
- return rc;
-}
-
-
-int success(int count)
-{
- int rc = 1;
-
- if (errors)
- {
- MyLog(LOGA_ALWAYS, "Workload test failed because the callback had errors");
- rc = 0;
- }
- if (arrivedCount != count)
- {
- if (opts.qos == 2 || (opts.qos == 1 && arrivedCount < count))
- {
- MyLog(LOGA_ALWAYS,
- "Workload test failed because the wrong number of messages"
- " was received: %d whereas %d were expected",
- arrivedCount, count);
- rc = 0;
- }
- }
- if (rc == 1)
- control_send("verdict: pass");
- else
- control_send("verdict: fail");
- return rc;
-}
-
-
-int waitForCompletion(START_TIME_TYPE start_time)
-{
- int lastreport = 0;
- int wait_count = 0;
- int limit = 120;
-
- mqsleep(1);
- while (arrivedCount < expectedCount)
- {
- if (arrivedCount > lastreport)
- {
- MyLog(LOGA_ALWAYS, "%d messages arrived out of %d expected, in %d seconds",
- arrivedCount, expectedCount, elapsed(start_time) / 1000);
- lastreport = arrivedCount;
- }
- mqsleep(1);
- if (opts.persistence && connection_lost)
- recreateReconnect();
- if (++wait_count > limit || stopping)
- break;
- }
- last_completion_time = elapsed(start_time) / 1000;
- MyLog(LOGA_ALWAYS, "Extra wait to see if any duplicates arrive");
- mqsleep(10); /* check if any duplicate messages arrive */
- MyLog(LOGA_ALWAYS, "%d messages arrived out of %d expected, in %d seconds",
- arrivedCount, expectedCount, elapsed(start_time) / 1000);
- return success(expectedCount);
-}
-
-int messagesSent = 0;
-
-void messageSent(void* context, MQTTAsync_successData* response)
-{
- messagesSent++;
-}
-
-
-void one_iteration()
-{
- int interval = 0;
- int i = 0;
- int seqno = 0;
- int rc = 0;
- START_TIME_TYPE start_time;
- int last_expected_count = expectedCount;
- int test_interval = 30;
-
- if (control_wait("start_measuring") == 0)
- goto exit;
-
- connection_lost = 0;
- recreated = 0;
-
- /* find the time for evaluation_count round-trip messages */
- MyLog(LOGA_INFO, "Evaluating how many messages needed");
- expectedCount = arrivedCount = 0;
- measuring = 1;
- global_start_time = start_clock();
- for (i = 1; i <= test_count; ++i)
- {
- char payload[128];
-
- sprintf(payload, "message number %d", i);
-
- rc = MQTTAsync_send(client, opts.topic, strlen(payload)+1, payload,
- opts.qos, opts.retained, NULL);
- while (rc != MQTTASYNC_SUCCESS)
- {
- if (opts.persistence && (connection_lost || rc == MQTTASYNC_DISCONNECTED))
- recreateReconnect();
- if (stopping)
- goto exit;
- mqsleep(1);
- rc = MQTTAsync_send(client, opts.topic, strlen(payload)+1, payload,
- opts.qos, opts.retained, NULL);
- }
- }
- MyLog(LOGA_INFO, "Messages sent... waiting for echoes");
- while (arrivedCount < test_count)
- {
- if (stopping)
- goto exit;
- mqsleep(1);
- printf("arrivedCount %d\n", arrivedCount);
- }
- measuring = 0;
-
- /* Now set a target of 30 seconds total round trip */
- if (last_completion_time == -1)
- {
- MyLog(LOGA_ALWAYS, "Round trip time for %d messages is %d ms", test_count, roundtrip_time);
- expectedCount = 1000 * test_count * test_interval / roundtrip_time / 2;
- }
- else
- {
- MyLog(LOGA_ALWAYS, "Last time, %d messages took %d s.", last_expected_count, last_completion_time);
- expectedCount = last_expected_count * test_interval / last_completion_time;
- }
- MyLog(LOGA_ALWAYS, "Therefore %d messages needed for 30 seconds", expectedCount);
-
- if (control_wait("start_test") == 0) /* now synchronize the test interval */
- goto exit;
-
- MyLog(LOGA_ALWAYS, "Starting 30 second test run with %d messages", expectedCount);
- arrivedCount = 0;
- messagesSent = 0;
- start_time = start_clock();
- while (seqno < expectedCount)
- {
- MQTTAsync_responseOptions ropts = MQTTAsync_responseOptions_initializer;
- char payload[128];
-
- ropts.onSuccess = messageSent;
- seqno++;
- sprintf(payload, "message number %d", seqno);
- rc = MQTTAsync_send(client, opts.topic, strlen(payload)+1, payload,
- opts.qos, opts.retained, &ropts);
- while (rc != MQTTASYNC_SUCCESS)
- {
- MyLog(LOGA_DEBUG, "Rc %d from publish with payload %s, retrying", rc, payload);
- if (opts.persistence && (connection_lost || rc == MQTTASYNC_DISCONNECTED))
- recreateReconnect();
- if (stopping)
- goto exit;
- mqsleep(1);
- rc = MQTTAsync_send(client, opts.topic, strlen(payload)+1, payload,
- opts.qos, opts.retained, &ropts);
- }
- //MyLog(LOGA_DEBUG, "Successful publish with payload %s", payload);
- while (seqno - messagesSent > 2000)
- mqsleep(1);
- }
- MyLog(LOGA_ALWAYS, "%d messages sent in %d seconds", expectedCount, elapsed(start_time) / 1000);
-
- waitForCompletion(start_time);
- control_wait("test finished");
-exit:
- ; /* dummy statement for target of exit */
-}
-
-
-static int client_subscribed = 0;
-
-void client_onSubscribe(void* context, MQTTAsync_successData* response)
-{
- MQTTAsync c = (MQTTAsync)context;
-
- MyLog(LOGA_DEBUG, "In client subscribe onSuccess callback %p granted qos %d", c, response->alt.qos);
-
- client_subscribed = 1;
-}
-
-void client_onFailure(void* context, MQTTAsync_failureData* response)
-{
- MQTTAsync c = (MQTTAsync)context;
- MyLog(LOGA_DEBUG, "In failure callback");
-
- client_subscribed = -1;
-}
-
-
-void client_onConnect(void* context, MQTTAsync_successData* response)
-{
- MQTTAsync c = (MQTTAsync)context;
- MQTTAsync_responseOptions ropts = MQTTAsync_responseOptions_initializer;
- int rc;
-
- sprintf(sub_topic, "%s/send", opts.control_topic);
- sprintf(pub_topic, "%s/receive", opts.control_topic);
- ropts.context = context;
- ropts.onSuccess = client_onSubscribe;
- ropts.onFailure = client_onFailure;
- ropts.context = c;
- if ((rc = MQTTAsync_subscribe(c, opts.topic, opts.qos, &ropts)) != MQTTASYNC_SUCCESS)
- {
- MyLog(LOGA_ALWAYS, "client MQTTAsync_subscribe failed, rc %d", rc);
- client_subscribed = -1;
- }
-}
-
-
-void client_onCleanedDisconnected(void* context, MQTTAsync_successData* response)
-{
- client_cleaned = 1;
-}
-
-
-void client_onCleaned(void* context, MQTTAsync_successData* response)
-{
- MQTTAsync c = (MQTTAsync)context;
- MQTTAsync_disconnectOptions dopts = MQTTAsync_disconnectOptions_initializer;
- int rc;
-
- dopts.context = context;
- dopts.onSuccess = client_onCleanedDisconnected;
- dopts.onFailure = client_onFailure;
- dopts.context = c;
- if ((rc = MQTTAsync_disconnect(c, &dopts)) != MQTTASYNC_SUCCESS)
- {
- MyLog(LOGA_ALWAYS, "client MQTTAsync_disconnect failed, rc %d", rc);
- stopping = 1;
- }
-}
-
-
-int sendAndReceive(void)
-{
- int rc = 0;
- int persistence = MQTTCLIENT_PERSISTENCE_NONE;
-
- MyLog(LOGA_ALWAYS, "v3 async C client topic workload using QoS %d", opts.qos);
- MyLog(LOGA_DEBUG, "Connecting to %s", opts.connection);
-
- if (opts.persistence)
- persistence = MQTTCLIENT_PERSISTENCE_DEFAULT;
-
- rc = MQTTAsync_create(&client, opts.connection, opts.clientid, persistence, NULL);
- if (rc != MQTTASYNC_SUCCESS)
- {
- MyLog(LOGA_ALWAYS, "MQTTAsync_create failed, rc %d", rc);
- rc = 99;
- goto exit;
- }
-
- if ((rc = MQTTAsync_setCallbacks(client, client, connectionLost,
- messageArrived, NULL)) != MQTTASYNC_SUCCESS)
- {
- MyLog(LOGA_ALWAYS, "MQTTAsync_setCallbacks failed, rc %d", rc);
- rc = 99;
- goto destroy_exit;
- }
-
- /* wait to know that the controlling process is running before connecting to the SUT */
- control_wait("who is ready?");
-
- /* connect cleansession, and then disconnect, to clean up */
- conn_opts.keepAliveInterval = 10;
- conn_opts.username = opts.username;
- conn_opts.password = opts.password;
- conn_opts.cleansession = 1;
- conn_opts.context = client;
- conn_opts.onSuccess = client_onCleaned;
- conn_opts.onFailure = client_onFailure;
- if (opts.connections)
- {
- conn_opts.serverURIcount = opts.connection_count;
- conn_opts.serverURIs = opts.connections;
- }
- else
- {
- conn_opts.serverURIcount = 0;
- conn_opts.serverURIs = NULL;
- }
- if ((rc = MQTTAsync_connect(client, &conn_opts)) != MQTTASYNC_SUCCESS)
- {
- MyLog(LOGA_ALWAYS, "MQTTAsync_connect failed, rc %d", rc);
- rc = 99;
- goto destroy_exit;
- }
-
- while (client_cleaned == 0)
- mqsleep(1);
-
- MyLog(LOGA_ALWAYS, "Client state cleaned up");
-
- conn_opts.cleansession = 0;
- conn_opts.context = client;
- conn_opts.onSuccess = client_onConnect;
- conn_opts.onFailure = client_onFailure;
- conn_opts.retryInterval = 1;
- if ((rc = MQTTAsync_connect(client, &conn_opts)) != MQTTASYNC_SUCCESS)
- {
- MyLog(LOGA_ALWAYS, "MQTTAsync_connect failed, rc %d", rc);
- rc = 99;
- goto destroy_exit;
- }
-
- /* wait until subscribed */
- while (client_subscribed == 0)
- mqsleep(1);
-
- if (client_subscribed != 1)
- goto disconnect_exit;
-
- while (1)
- {
- control_send("Ready");
- if (control_which("who is ready?", "continue") == 2)
- break;
- control_send("Ready");
- }
-
- while (!stopping)
- {
- one_iteration(client);
- }
-
-disconnect_exit:
- MQTTAsync_disconnect(client, 0);
-
-destroy_exit:
- MQTTAsync_destroy(&client);
-
-exit:
- return rc;
-}
-
-
-static int control_subscribed = 0;
-
-void control_onSubscribe(void* context, MQTTAsync_successData* response)
-{
- MQTTAsync c = (MQTTAsync)context;
-
- MyLog(LOGA_DEBUG, "In control subscribe onSuccess callback %p granted qos %d", c, response->alt.qos);
-
- control_subscribed = 1;
-}
-
-void control_onFailure(void* context, MQTTAsync_failureData* response)
-{
- MQTTAsync c = (MQTTAsync)context;
-
- control_subscribed = -1;
-}
-
-
-void control_onConnect(void* context, MQTTAsync_successData* response)
-{
- MQTTAsync c = (MQTTAsync)context;
- MQTTAsync_responseOptions ropts = MQTTAsync_responseOptions_initializer;
- int rc;
-
- sprintf(sub_topic, "%s/send", opts.control_topic);
- sprintf(pub_topic, "%s/receive", opts.control_topic);
- ropts.onSuccess = control_onSubscribe;
- ropts.onFailure = control_onFailure;
- ropts.context = c;
- if ((rc = MQTTAsync_subscribe(c, sub_topic, 2, &ropts)) != MQTTASYNC_SUCCESS)
- {
- MyLog(LOGA_ALWAYS, "control MQTTAsync_subscribe failed, rc %d", rc);
- control_subscribed = -1;
- }
-}
-
-void trace_callback(enum MQTTASYNC_TRACE_LEVELS level, char* message)
-{
- if (level == MQTTASYNC_TRACE_ERROR || strstr(message, "Connect") || strstr(message, "failed"))
- printf("Trace : %d, %s\n", level, message);
-}
-
-int main(int argc, char** argv)
-{
- MQTTAsync_connectOptions control_conn_opts = MQTTAsync_connectOptions_initializer;
- int rc = 0;
- static char topic_buf[200];
- static char clientid[40];
-
-#if !defined(WIN32)
- signal(SIGPIPE, SIG_IGN);
-#endif
-
- MQTTAsync_nameValue* info = MQTTAsync_getVersionInfo();
-
- while (info->name)
- {
- MyLog(LOGA_ALWAYS, "%s: %s\n", info->name, info->value);
- info++;
- }
-
- getopts(argc, argv);
-
- sprintf(topic_buf, "%s_%d", opts.topic, opts.slot_no);
- opts.topic = topic_buf;
-
- sprintf(clientid, "%s_%d", opts.clientid, opts.slot_no);
- opts.clientid = clientid;
-
- MyLog(LOGA_ALWAYS, "Starting with clientid %s", opts.clientid);
-
- //MQTTAsync_setTraceLevel(MQTTASYNC_TRACE_MAXIMUM);
- MQTTAsync_setTraceCallback(trace_callback);
-
- rc = MQTTAsync_create(&control_client, opts.control_connection,
- opts.clientid, MQTTCLIENT_PERSISTENCE_NONE, NULL);
- if (rc != MQTTASYNC_SUCCESS)
- {
- MyLog(LOGA_ALWAYS, "control MQTTAsync_create failed, rc %d", rc);
- rc = 99;
- goto exit;
- }
-
- if ((rc = MQTTAsync_setCallbacks(control_client, control_client, control_connectionLost,
- control_messageArrived, NULL)) != MQTTASYNC_SUCCESS)
- {
- MyLog(LOGA_ALWAYS, "control MQTTAsync_setCallbacks failed, rc %d", rc);
- rc = 99;
- goto destroy_exit;
- }
-
- control_subscribed = 0;
- control_conn_opts.context = control_client;
- control_conn_opts.keepAliveInterval = 10;
- control_conn_opts.onSuccess = control_onConnect;
- control_conn_opts.onFailure = control_onFailure;
- if ((rc = MQTTAsync_connect(control_client, &control_conn_opts))
- != MQTTASYNC_SUCCESS)
- {
- MyLog(LOGA_ALWAYS, "control MQTTAsync_connect failed, rc %d", rc);
- rc = 99;
- goto destroy_exit;
- }
-
- while (control_subscribed == 0)
- mqsleep(1);
-
- if (control_subscribed != 1)
- goto destroy_exit;
-
- sendAndReceive();
-
-exit:
- MQTTAsync_disconnect(control_client, 0);
-
-destroy_exit:
- MQTTAsync_destroy(&control_client);
-
- return 0;
-}
diff --git a/org.eclipse.paho.mqtt.c/test/test8.c b/org.eclipse.paho.mqtt.c/test/test8.c
deleted file mode 100644
index 4ea3564..0000000
--- a/org.eclipse.paho.mqtt.c/test/test8.c
+++ /dev/null
@@ -1,934 +0,0 @@
-/*--------------------------------------------------------------------*/
-/* [Platforms]UNIX NT[/Platforms] */
-/* [Title]MQ Telemetry MQTT Async C client tests - HA and connect */
-/* failures */
-/* [/Title] */
-/* [Testclasses]stcom1 stmqcom1[/Category] */
-/* [Category]MQ Telemetry[/Category] */
-/* */
-/* Copyright IBM 2013 */
-/* All rights reserved. */
-/*--------------------------------------------------------------------*/
-
-
-/**
- * @file
- * Tests for the MQ Telemetry MQTT Async C client
- */
-
-
-/*
-#if !defined(_RTSHEADER)
- #include
-#endif
-*/
-
-#include "MQTTAsync.h"
-#include
-#include
-
-#if !defined(_WINDOWS)
- #include
- #include
- #include
- #include
-#else
-#include
-#include
-#define MAXHOSTNAMELEN 256
-#define EAGAIN WSAEWOULDBLOCK
-#define EINTR WSAEINTR
-#define EINPROGRESS WSAEINPROGRESS
-#define EWOULDBLOCK WSAEWOULDBLOCK
-#define ENOTCONN WSAENOTCONN
-#define ECONNRESET WSAECONNRESET
-#endif
-
-#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
-
-void usage()
-{
- printf("help!!\n");
- exit(-1);
-}
-
-struct Options
-{
- char* connection; /**< connection to system under test. */
- int verbose;
- int test_no;
- int size; /**< size of big message */
-} options =
-{
- "tcp://localhost:1883",
- 0,
- -1,
- 5000000,
-};
-
-void getopts(int argc, char** argv)
-{
- int count = 1;
-
- while (count < argc)
- {
- if (strcmp(argv[count], "--test_no") == 0)
- {
- if (++count < argc)
- options.test_no = atoi(argv[count]);
- else
- usage();
- }
- else if (strcmp(argv[count], "--size") == 0)
- {
- if (++count < argc)
- options.size = atoi(argv[count]);
- else
- usage();
- }
- else if (strcmp(argv[count], "--connection") == 0)
- {
- if (++count < argc)
- options.connection = argv[count];
- else
- usage();
- }
- else if (strcmp(argv[count], "--verbose") == 0)
- options.verbose = 1;
- count++;
- }
-}
-
-#if 0
-#include /* For general log messages */
-#define MyLog logaLine
-#else
-#define LOGA_DEBUG 0
-#define LOGA_INFO 1
-#include
-#include
-#include
-void MyLog(int LOGA_level, char* format, ...)
-{
- static char msg_buf[256];
- va_list args;
- struct timeb ts;
-
- struct tm *timeinfo;
-
- if (LOGA_level == LOGA_DEBUG && options.verbose == 0)
- return;
-
- ftime(&ts);
- timeinfo = localtime(&ts.time);
- strftime(msg_buf, 80, "%Y%m%d %H%M%S", timeinfo);
-
- sprintf(&msg_buf[strlen(msg_buf)], ".%.3hu ", ts.millitm);
-
- va_start(args, format);
- vsnprintf(&msg_buf[strlen(msg_buf)], sizeof(msg_buf) - strlen(msg_buf), format, args);
- va_end(args);
-
- printf("%s\n", msg_buf);
- fflush(stdout);
-}
-#endif
-
-
-#if defined(WIN32) || defined(_WINDOWS)
-#define mqsleep(A) Sleep(1000*A)
-#define START_TIME_TYPE DWORD
-static DWORD start_time = 0;
-START_TIME_TYPE start_clock(void)
-{
- return GetTickCount();
-}
-#elif defined(AIX)
-#define mqsleep sleep
-#define START_TIME_TYPE struct timespec
-START_TIME_TYPE start_clock(void)
-{
- static struct timespec start;
- clock_gettime(CLOCK_REALTIME, &start);
- return start;
-}
-#else
-#define mqsleep sleep
-#define START_TIME_TYPE struct timeval
-/* TODO - unused - remove? static struct timeval start_time; */
-START_TIME_TYPE start_clock(void)
-{
- struct timeval start_time;
- gettimeofday(&start_time, NULL);
- return start_time;
-}
-#endif
-
-
-#if defined(WIN32)
-long elapsed(START_TIME_TYPE start_time)
-{
- return GetTickCount() - start_time;
-}
-#elif defined(AIX)
-#define assert(a)
-long elapsed(struct timespec start)
-{
- struct timespec now, res;
-
- clock_gettime(CLOCK_REALTIME, &now);
- ntimersub(now, start, res);
- return (res.tv_sec)*1000L + (res.tv_nsec)/1000000L;
-}
-#else
-long elapsed(START_TIME_TYPE start_time)
-{
- struct timeval now, res;
-
- gettimeofday(&now, NULL);
- timersub(&now, &start_time, &res);
- return (res.tv_sec)*1000 + (res.tv_usec)/1000;
-}
-#endif
-
-
-START_TIME_TYPE global_start_time;
-
-
-#define assert(a, b, c, d) myassert(__FILE__, __LINE__, a, b, c, d)
-#define assert1(a, b, c, d, e) myassert(__FILE__, __LINE__, a, b, c, d, e)
-
-
-int tests = 0;
-int failures = 0;
-
-
-void myassert(char* filename, int lineno, char* description, int value, char* format, ...)
-{
- ++tests;
- if (!value)
- {
- va_list args;
-
- ++failures;
- printf("Assertion failed, file %s, line %d, description: %s\n", filename, lineno, description);
-
- va_start(args, format);
- vprintf(format, args);
- va_end(args);
- }
- else
- MyLog(LOGA_DEBUG, "Assertion succeeded, file %s, line %d, description: %s", filename, lineno, description);
-}
-
-volatile int test_finished = 0;
-
-char* test_topic = "async test topic";
-
-
-void test1_onDisconnect(void* context, MQTTAsync_successData* response)
-{
- MQTTAsync c = (MQTTAsync)context;
- MyLog(LOGA_DEBUG, "In onDisconnect callback %p", c);
- test_finished = 1;
-}
-
-
-void test1_onUnsubscribe(void* context, MQTTAsync_successData* response)
-{
- MQTTAsync c = (MQTTAsync)context;
- MQTTAsync_disconnectOptions opts = MQTTAsync_disconnectOptions_initializer;
- int rc;
-
- MyLog(LOGA_DEBUG, "In onUnsubscribe onSuccess callback %p", c);
- opts.onSuccess = test1_onDisconnect;
- opts.context = c;
-
- rc = MQTTAsync_disconnect(c, &opts);
- assert("Disconnect successful", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
-}
-
-
-int test1_messageArrived(void* context, char* topicName, int topicLen, MQTTAsync_message* message)
-{
- MQTTAsync c = (MQTTAsync)context;
- static int message_count = 0;
- int rc;
-
- MyLog(LOGA_DEBUG, "In messageArrived callback %p", c);
-
- if (++message_count == 1)
- {
- MQTTAsync_message pubmsg = MQTTAsync_message_initializer;
- MQTTAsync_responseOptions opts = MQTTAsync_responseOptions_initializer;
- pubmsg.payload = "a much longer message that we can shorten to the extent that we need to payload up to 11";
- pubmsg.payloadlen = 11;
- pubmsg.qos = 2;
- pubmsg.retained = 0;
- rc = MQTTAsync_sendMessage(c, test_topic, &pubmsg, &opts);
- }
- else
- {
- MQTTAsync_responseOptions opts = MQTTAsync_responseOptions_initializer;
-
- opts.onSuccess = test1_onUnsubscribe;
- opts.context = c;
- rc = MQTTAsync_unsubscribe(c, test_topic, &opts);
- assert("Unsubscribe successful", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
- }
-
- MQTTAsync_freeMessage(&message);
- MQTTAsync_free(topicName);
-
- return 1;
-}
-
-void test1_onSubscribe(void* context, MQTTAsync_successData* response)
-{
- MQTTAsync c = (MQTTAsync)context;
- MQTTAsync_message pubmsg = MQTTAsync_message_initializer;
- int rc;
-
- MyLog(LOGA_DEBUG, "In subscribe onSuccess callback %p granted qos %d", c, response->alt.qos);
-
- pubmsg.payload = "a much longer message that we can shorten to the extent that we need to payload up to 11";
- pubmsg.payloadlen = 11;
- pubmsg.qos = 2;
- pubmsg.retained = 0;
-
- rc = MQTTAsync_send(c, test_topic, pubmsg.payloadlen, pubmsg.payload, pubmsg.qos, pubmsg.retained, NULL);
-}
-
-
-void test1_onConnect(void* context, MQTTAsync_successData* response)
-{
- MQTTAsync c = (MQTTAsync)context;
- MQTTAsync_responseOptions opts = MQTTAsync_responseOptions_initializer;
- int rc;
-
- MyLog(LOGA_DEBUG, "In connect onSuccess callback, context %p", context);
- opts.onSuccess = test1_onSubscribe;
- opts.context = c;
-
- rc = MQTTAsync_subscribe(c, test_topic, 2, &opts);
- assert("Good rc from subscribe", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
- if (rc != MQTTASYNC_SUCCESS)
- test_finished = 1;
-}
-
-
-void test1_onConnectFailure(void* context, MQTTAsync_failureData* response)
-{
- MQTTAsync c = (MQTTAsync)context;
- MQTTAsync_responseOptions opts = MQTTAsync_responseOptions_initializer;
- int rc;
-
- MyLog(LOGA_DEBUG, "In connect onFailure callback, context %p", context);
-
- test_finished = 1;
-}
-
-
-/*********************************************************************
-
-Test1: Basic connect, subscribe send and receive.
-
-*********************************************************************/
-int test1(struct Options options)
-{
- int subsqos = 2;
- MQTTAsync c;
- MQTTAsync_connectOptions opts = MQTTAsync_connectOptions_initializer;
- MQTTAsync_willOptions wopts = MQTTAsync_willOptions_initializer;
- int rc = 0;
- char* test_topic = "C client test1";
- char* serverURIs[2] = {"tcp://localhost:1882", options.connection};
-
- failures = 0;
- MyLog(LOGA_INFO, "Starting test 1 - asynchronous connect");
-
- rc = MQTTAsync_create(&c, options.connection, "async_test",
- MQTTCLIENT_PERSISTENCE_DEFAULT, NULL);
- assert("good rc from create", rc == MQTTASYNC_SUCCESS, "rc was %d\n", rc);
- if (rc != MQTTASYNC_SUCCESS)
- {
- MQTTAsync_destroy(&c);
- goto exit;
- }
-
- rc = MQTTAsync_setCallbacks(c, c, NULL, test1_messageArrived, NULL);
- assert("Good rc from setCallbacks", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
-
- opts.keepAliveInterval = 20;
- opts.cleansession = 1;
- opts.username = "testuser";
- opts.password = "testpassword";
-
- opts.will = &wopts;
- opts.will->message = "will message";
- opts.will->qos = 1;
- opts.will->retained = 0;
- opts.will->topicName = "will topic";
- opts.will = NULL;
- opts.onSuccess = test1_onConnect;
- opts.onFailure = test1_onConnectFailure;
- opts.context = c;
- opts.serverURIcount = 2;
- opts.serverURIs = serverURIs;
-
- MyLog(LOGA_DEBUG, "Connecting");
- rc = MQTTAsync_connect(c, &opts);
- rc = 0;
- assert("Good rc from connect", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
- if (rc != MQTTASYNC_SUCCESS)
- goto exit;
-
- while (!test_finished)
- #if defined(WIN32)
- Sleep(100);
- #else
- usleep(10000L);
- #endif
-
- MQTTAsync_destroy(&c);
-
-exit:
- MyLog(LOGA_INFO, "TEST1: test %s. %d tests run, %d failures.",
- (failures == 0) ? "passed" : "failed", tests, failures);
-
- return failures;
-}
-
-int test2_onFailure_called = 0;
-
-void test2_onFailure(void* context, MQTTAsync_failureData* response)
-{
- MyLog(LOGA_DEBUG, "In connect onFailure callback, context %p", context);
-
- test2_onFailure_called++;
- test_finished = 1;
-}
-
-
-void test2_onConnect(void* context, MQTTAsync_successData* response)
-{
-
- MyLog(LOGA_DEBUG, "In connect onSuccess callback, context %p\n", context);
-
- assert("Connect should not succeed", 0, "connect success callback was called", 0);
-
- test_finished = 1;
-}
-
-/*********************************************************************
-
-Test2: connect timeout
-
-*********************************************************************/
-int test2(struct Options options)
-{
- int subsqos = 2;
- MQTTAsync c;
- MQTTAsync_connectOptions opts = MQTTAsync_connectOptions_initializer;
- MQTTAsync_willOptions wopts = MQTTAsync_willOptions_initializer;
- int rc = 0;
- char* test_topic = "C client test2";
-
- test_finished = 0;
-
- MyLog(LOGA_INFO, "Starting test 2 - connect timeout");
-
- rc = MQTTAsync_create(&c, "tcp://9.20.96.160:66", "connect timeout",
- MQTTCLIENT_PERSISTENCE_DEFAULT, NULL);
- assert("good rc from create", rc == MQTTASYNC_SUCCESS, "rc was %d\n", rc);
- if (rc != MQTTASYNC_SUCCESS)
- {
- MQTTAsync_destroy(&c);
- goto exit;
- }
-
- rc = MQTTAsync_setCallbacks(c, c, NULL, test1_messageArrived, NULL);
- assert("Good rc from setCallbacks", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
-
- opts.connectTimeout = 5;
- opts.keepAliveInterval = 20;
- opts.cleansession = 1;
- opts.username = "testuser";
- opts.password = "testpassword";
-
- opts.will = &wopts;
- opts.will->message = "will message";
- opts.will->qos = 1;
- opts.will->retained = 0;
- opts.will->topicName = "will topic";
- opts.will = NULL;
- opts.onSuccess = test2_onConnect;
- opts.onFailure = test2_onFailure;
- opts.context = c;
-
- MyLog(LOGA_DEBUG, "Connecting");
- rc = MQTTAsync_connect(c, &opts);
- rc = 0;
- assert("Good rc from connect", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
- if (rc != MQTTASYNC_SUCCESS)
- goto exit;
-
- while (!test_finished)
- #if defined(WIN32)
- Sleep(100);
- #else
- usleep(10000L);
- #endif
-
- MQTTAsync_destroy(&c);
-
-exit:
- assert("Connect onFailure should be called once", test2_onFailure_called == 1,
- "connect onFailure was called %d times", test2_onFailure_called);
-
- MyLog(LOGA_INFO, "TEST2: test %s. %d tests run, %d failures.",
- (failures == 0) ? "passed" : "failed", tests, failures);
-
- return failures;
-}
-
-
-typedef struct
-{
- MQTTAsync c;
- int index;
- char clientid[24];
- char test_topic[100];
- int message_count;
-} client_data;
-
-
-void test3_onDisconnect(void* context, MQTTAsync_successData* response)
-{
- client_data* cd = (client_data*)context;
- MyLog(LOGA_DEBUG, "In onDisconnect callback for client \"%s\"", cd->clientid);
- test_finished++;
-}
-
-
-void test3_onPublish(void* context, MQTTAsync_successData* response)
-{
- client_data* cd = (client_data*)context;
- MyLog(LOGA_DEBUG, "In QoS 0 onPublish callback for client \"%s\"", cd->clientid);
-}
-
-
-void test3_onUnsubscribe(void* context, MQTTAsync_successData* response)
-{
- client_data* cd = (client_data*)context;
- MQTTAsync_disconnectOptions opts = MQTTAsync_disconnectOptions_initializer;
- int rc;
-
- MyLog(LOGA_DEBUG, "In onUnsubscribe onSuccess callback \"%s\"", cd->clientid);
- opts.onSuccess = test3_onDisconnect;
- opts.context = cd;
-
- rc = MQTTAsync_disconnect(cd->c, &opts);
- assert("Disconnect successful", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
-}
-
-
-int test3_messageArrived(void* context, char* topicName, int topicLen, MQTTAsync_message* message)
-{
- client_data* cd = (client_data*)context;
- int rc;
-
- MyLog(LOGA_DEBUG, "In messageArrived callback \"%s\" message count ", cd->clientid);
-
- if (++cd->message_count == 1)
- {
- MQTTAsync_message pubmsg = MQTTAsync_message_initializer;
- MQTTAsync_responseOptions opts = MQTTAsync_responseOptions_initializer;
- pubmsg.payload = "a much longer message that we can shorten to the extent that we need to payload up to 11";
- pubmsg.payloadlen = 25;
- pubmsg.qos = 1;
- pubmsg.retained = 0;
- rc = MQTTAsync_sendMessage(cd->c, cd->test_topic, &pubmsg, &opts);
- assert("Good rc from publish", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
- }
- else if (cd->message_count == 2)
- {
- MQTTAsync_message pubmsg = MQTTAsync_message_initializer;
- MQTTAsync_responseOptions opts = MQTTAsync_responseOptions_initializer;
- pubmsg.payload = "a QoS 0 message that we can shorten to the extent that we need to payload up to 11";
- pubmsg.payloadlen = 29;
- pubmsg.qos = 0;
- pubmsg.retained = 0;
- opts.context = cd;
- opts.onSuccess = test3_onPublish;
-
- rc = MQTTAsync_sendMessage(cd->c, cd->test_topic, &pubmsg, &opts);
- assert("Good rc from publish", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
- }
- else
- {
- MQTTAsync_responseOptions opts = MQTTAsync_responseOptions_initializer;
-
- opts.onSuccess = test3_onUnsubscribe;
- opts.context = cd;
- rc = MQTTAsync_unsubscribe(cd->c, cd->test_topic, &opts);
- assert("Unsubscribe successful", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
- }
- MQTTAsync_freeMessage(&message);
- MQTTAsync_free(topicName);
- return 1;
-}
-
-void test3_onSubscribe(void* context, MQTTAsync_successData* response)
-{
- client_data* cd = (client_data*)context;
- MQTTAsync_message pubmsg = MQTTAsync_message_initializer;
- int rc;
-
- MyLog(LOGA_DEBUG, "In subscribe onSuccess callback \"%s\"", cd->clientid);
-
- pubmsg.payload = "a much longer message that we can shorten to the extent that we need to payload up to 11";
- pubmsg.payloadlen = 11;
- pubmsg.qos = 2;
- pubmsg.retained = 0;
-
- rc = MQTTAsync_send(cd->c, cd->test_topic, pubmsg.payloadlen, pubmsg.payload, pubmsg.qos, pubmsg.retained, NULL);
- assert("Good rc from publish", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
-}
-
-
-void test3_onConnect(void* context, MQTTAsync_successData* response)
-{
- client_data* cd = (client_data*)context;
- MQTTAsync_responseOptions opts = MQTTAsync_responseOptions_initializer;
- int rc;
-
- MyLog(LOGA_DEBUG, "In connect onSuccess callback, \"%s\"", cd->clientid);
- opts.onSuccess = test3_onSubscribe;
- opts.context = cd;
-
- rc = MQTTAsync_subscribe(cd->c, cd->test_topic, 2, &opts);
- assert("Good rc from subscribe", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
- if (rc != MQTTASYNC_SUCCESS)
- test_finished++;
-}
-
-
-void test3_onFailure(void* context, MQTTAsync_failureData* response)
-{
- client_data* cd = (client_data*)context;
- MQTTAsync_responseOptions opts = MQTTAsync_responseOptions_initializer;
-
- assert("Should have connected", 0, "failed to connect", NULL);
- MyLog(LOGA_DEBUG, "In connect onFailure callback, \"%s\" rc %d\n", cd->clientid, response->code);
- if (response->message)
- MyLog(LOGA_DEBUG, "In connect onFailure callback, \"%s\"\n", response->message);
-
- test_finished++;
-}
-
-
-/*********************************************************************
-
-Test3: More than one client object - simultaneous working.
-
-*********************************************************************/
-int test3(struct Options options)
-{
- #define TEST3_CLIENTS 10
- int num_clients = TEST3_CLIENTS;
- int subsqos = 2;
- MQTTAsync_connectOptions opts = MQTTAsync_connectOptions_initializer;
- MQTTAsync_willOptions wopts = MQTTAsync_willOptions_initializer;
- int rc = 0;
- int i;
- client_data clientdata[TEST3_CLIENTS];
-
- test_finished = 0;
- MyLog(LOGA_INFO, "Starting test 3 - multiple connections");
-
- for (i = 0; i < num_clients; ++i)
- {
- sprintf(clientdata[i].clientid, "async_test3_num_%d", i);
- sprintf(clientdata[i].test_topic, "async test3 topic num %d", i);
- clientdata[i].index = i;
- clientdata[i].message_count = 0;
-
- rc = MQTTAsync_create(&(clientdata[i].c), options.connection, clientdata[i].clientid,
- MQTTCLIENT_PERSISTENCE_NONE, NULL);
- assert("good rc from create", rc == MQTTASYNC_SUCCESS, "rc was %d\n", rc);
-
- rc = MQTTAsync_setCallbacks(clientdata[i].c, &clientdata[i], NULL, test3_messageArrived, NULL);
- assert("Good rc from setCallbacks", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
-
- opts.keepAliveInterval = 20;
- opts.cleansession = 1;
- opts.username = "testuser";
- opts.password = "testpassword";
-
- opts.will = &wopts;
- opts.will->message = "will message";
- opts.will->qos = 1;
- opts.will->retained = 0;
- opts.will->topicName = "will topic";
- opts.onSuccess = test3_onConnect;
- opts.onFailure = test3_onFailure;
- opts.context = &clientdata[i];
-
- MyLog(LOGA_DEBUG, "Connecting");
- rc = MQTTAsync_connect(clientdata[i].c, &opts);
- assert("Good rc from connect", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
- }
-
- while (test_finished < num_clients)
- {
- MyLog(LOGA_DEBUG, "num_clients %d test_finished %d\n", num_clients, test_finished);
- #if defined(WIN32)
- Sleep(100);
- #else
- usleep(10000L);
- #endif
- }
-
- MyLog(LOGA_DEBUG, "TEST3: destroying clients");
-
- for (i = 0; i < num_clients; ++i)
- MQTTAsync_destroy(&clientdata[i].c);
-
-exit:
- MyLog(LOGA_INFO, "TEST3: test %s. %d tests run, %d failures.",
- (failures == 0) ? "passed" : "failed", tests, failures);
-
- return failures;
-}
-
-
-void* test4_payload = NULL;
-int test4_payloadlen = 0;
-
-void test4_onPublish(void* context, MQTTAsync_successData* response)
-{
- MQTTAsync c = (MQTTAsync)context;
-
- MyLog(LOGA_DEBUG, "In publish onSuccess callback, context %p", context);
-}
-
-int test4_messageArrived(void* context, char* topicName, int topicLen, MQTTAsync_message* message)
-{
- MQTTAsync c = (MQTTAsync)context;
- static int message_count = 0;
- int rc, i;
-
- MyLog(LOGA_DEBUG, "In messageArrived callback %p", c);
-
- assert("Message size correct", message->payloadlen == test4_payloadlen,
- "message size was %d", message->payloadlen);
-
- for (i = 0; i < options.size; ++i)
- {
- if (((char*)test4_payload)[i] != ((char*)message->payload)[i])
- {
- assert("Message contents correct", ((char*)test4_payload)[i] != ((char*)message->payload)[i],
- "message content was %c", ((char*)message->payload)[i]);
- break;
- }
- }
-
- if (++message_count == 1)
- {
- MQTTAsync_message pubmsg = MQTTAsync_message_initializer;
- MQTTAsync_responseOptions opts = MQTTAsync_responseOptions_initializer;
-
- pubmsg.payload = test4_payload;
- pubmsg.payloadlen = test4_payloadlen;
- pubmsg.qos = 1;
- pubmsg.retained = 0;
- opts.onSuccess = test4_onPublish;
- opts.context = c;
-
- rc = MQTTAsync_sendMessage(c, test_topic, &pubmsg, &opts);
- }
- else if (message_count == 2)
- {
- MQTTAsync_message pubmsg = MQTTAsync_message_initializer;
- MQTTAsync_responseOptions opts = MQTTAsync_responseOptions_initializer;
-
- pubmsg.payload = test4_payload;
- pubmsg.payloadlen = test4_payloadlen;
- pubmsg.qos = 0;
- pubmsg.retained = 0;
- opts.onSuccess = test4_onPublish;
- opts.context = c;
- rc = MQTTAsync_sendMessage(c, test_topic, &pubmsg, &opts);
- }
- else
- {
- MQTTAsync_responseOptions opts = MQTTAsync_responseOptions_initializer;
-
- opts.onSuccess = test1_onUnsubscribe;
- opts.context = c;
- rc = MQTTAsync_unsubscribe(c, test_topic, &opts);
- assert("Unsubscribe successful", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
- }
-
- MQTTAsync_freeMessage(&message);
- MQTTAsync_free(topicName);
-
- return 1;
-}
-
-
-void test4_onSubscribe(void* context, MQTTAsync_successData* response)
-{
- MQTTAsync c = (MQTTAsync)context;
- MQTTAsync_message pubmsg = MQTTAsync_message_initializer;
- int rc, i;
-
- MyLog(LOGA_DEBUG, "In subscribe onSuccess callback %p", c);
-
- pubmsg.payload = test4_payload = malloc(options.size);
- pubmsg.payloadlen = test4_payloadlen = options.size;
-
- srand(33);
- for (i = 0; i < options.size; ++i)
- ((char*)pubmsg.payload)[i] = rand() % 256;
-
- pubmsg.qos = 2;
- pubmsg.retained = 0;
-
- rc = MQTTAsync_send(c, test_topic, pubmsg.payloadlen, pubmsg.payload, pubmsg.qos, pubmsg.retained, NULL);
-}
-
-
-void test4_onConnect(void* context, MQTTAsync_successData* response)
-{
- MQTTAsync c = (MQTTAsync)context;
- MQTTAsync_responseOptions opts = MQTTAsync_responseOptions_initializer;
- int rc;
-
- MyLog(LOGA_DEBUG, "In connect onSuccess callback, context %p", context);
- opts.onSuccess = test4_onSubscribe;
- opts.context = c;
-
- rc = MQTTAsync_subscribe(c, test_topic, 2, &opts);
- assert("Good rc from subscribe", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
- if (rc != MQTTASYNC_SUCCESS)
- test_finished = 1;
-}
-
-
-/*********************************************************************
-
-Test4: Send and receive big messages
-
-*********************************************************************/
-int test4(struct Options options)
-{
- int subsqos = 2;
- MQTTAsync c;
- MQTTAsync_connectOptions opts = MQTTAsync_connectOptions_initializer;
- MQTTAsync_willOptions wopts = MQTTAsync_willOptions_initializer;
- int rc = 0;
- char* test_topic = "C client test4";
-
- test_finished = failures = 0;
- MyLog(LOGA_INFO, "Starting test 4 - big messages");
-
- rc = MQTTAsync_create(&c, options.connection, "async_test_4",
- MQTTCLIENT_PERSISTENCE_DEFAULT, NULL);
- assert("good rc from create", rc == MQTTASYNC_SUCCESS, "rc was %d\n", rc);
- if (rc != MQTTASYNC_SUCCESS)
- {
- MQTTAsync_destroy(&c);
- goto exit;
- }
-
- rc = MQTTAsync_setCallbacks(c, c, NULL, test4_messageArrived, NULL);
- assert("Good rc from setCallbacks", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
-
- opts.keepAliveInterval = 20;
- opts.cleansession = 1;
- opts.username = "testuser";
- opts.password = "testpassword";
-
- opts.will = &wopts;
- opts.will->message = "will message";
- opts.will->qos = 1;
- opts.will->retained = 0;
- opts.will->topicName = "will topic";
- opts.will = NULL;
- opts.onSuccess = test4_onConnect;
- opts.onFailure = NULL;
- opts.context = c;
-
- MyLog(LOGA_DEBUG, "Connecting");
- rc = MQTTAsync_connect(c, &opts);
- rc = 0;
- assert("Good rc from connect", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
- if (rc != MQTTASYNC_SUCCESS)
- goto exit;
-
- while (!test_finished)
- #if defined(WIN32)
- Sleep(100);
- #else
- usleep(1000L);
- #endif
-
- MQTTAsync_destroy(&c);
-
-exit:
- MyLog(LOGA_INFO, "TEST4: test %s. %d tests run, %d failures.",
- (failures == 0) ? "passed" : "failed", tests, failures);
-
- return failures;
-}
-
-
-void trace_callback(enum MQTTASYNC_TRACE_LEVELS level, char* message)
-{
- if (strstr(message, "onnect") && !strstr(message, "isconnect"))
- printf("Trace : %d, %s\n", level, message);
-}
-
-
-int main(int argc, char** argv)
-{
- int rc = 0;
- int (*tests[])() = {NULL, test1, test2, test3, test4}; /* indexed starting from 1 */
- MQTTAsync_nameValue* info;
-
- getopts(argc, argv);
-
- MQTTAsync_setTraceCallback(trace_callback);
-
- info = MQTTAsync_getVersionInfo();
-
- while (info->name)
- {
- MyLog(LOGA_INFO, "%s: %s", info->name, info->value);
- info++;
- }
-
- 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
- {
- //MQTTAsync_setTraceLevel(MQTTASYNC_TRACE_ERROR);
- rc = tests[options.test_no](options); /* run just the selected test */
- }
-
- if (failures == 0)
- MyLog(LOGA_INFO, "verdict pass");
- else
- MyLog(LOGA_INFO, "verdict fail");
-
- return rc;
-}
diff --git a/org.eclipse.paho.mqtt.c/test/test_mqtt4async.c b/org.eclipse.paho.mqtt.c/test/test_mqtt4async.c
deleted file mode 100644
index 603abd5..0000000
--- a/org.eclipse.paho.mqtt.c/test/test_mqtt4async.c
+++ /dev/null
@@ -1,628 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2009, 2014 IBM Corp.
- *
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * and Eclipse Distribution License v1.0 which accompany this distribution.
- *
- * The Eclipse Public License is available at
- * http://www.eclipse.org/legal/epl-v10.html
- * and the Eclipse Distribution License is available at
- * http://www.eclipse.org/org/documents/edl-v10.php.
- *
- * Contributors:
- * Ian Craggs - initial API and implementation and/or initial documentation
- * Ian Craggs - MQTT 3.1.1 support
- *******************************************************************************/
-
-
-/**
- * @file
- * MQTT 3.1.1 Tests for the asynchronous Paho MQTT C client
- */
-
-
-/*
-#if !defined(_RTSHEADER)
- #include
-#endif
-*/
-
-#include "MQTTAsync.h"
-#include
-#include
-
-#if !defined(_WINDOWS)
- #include
- #include
- #include
- #include
-#else
-#include
-#include
-#define MAXHOSTNAMELEN 256
-#define EAGAIN WSAEWOULDBLOCK
-#define EINTR WSAEINTR
-#define EINPROGRESS WSAEINPROGRESS
-#define EWOULDBLOCK WSAEWOULDBLOCK
-#define ENOTCONN WSAENOTCONN
-#define ECONNRESET WSAECONNRESET
-#define setenv(a, b, c) _putenv_s(a, b)
-#endif
-
-#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
-
-void usage()
-{
- printf("help!!\n");
- exit(-1);
-}
-
-struct Options
-{
- char* connection; /**< connection to system under test. */
- char** haconnections;
- int hacount;
- int verbose;
- int test_no;
- int iterations;
-} options =
-{
- "m2m.eclipse.org:1883",
- NULL,
- 0,
- 0,
- 0,
- 1,
-};
-
-void getopts(int argc, char** argv)
-{
- int count = 1;
-
- while (count < argc)
- {
- if (strcmp(argv[count], "--test_no") == 0)
- {
- if (++count < argc)
- options.test_no = atoi(argv[count]);
- else
- usage();
- }
- else if (strcmp(argv[count], "--connection") == 0)
- {
- if (++count < argc)
- {
- options.connection = argv[count];
- printf("\nSetting connection to %s\n", options.connection);
- }
- else
- usage();
- }
- else if (strcmp(argv[count], "--haconnections") == 0)
- {
- if (++count < argc)
- {
- char* tok = strtok(argv[count], " ");
- options.hacount = 0;
- options.haconnections = malloc(sizeof(char*) * 5);
- while (tok)
- {
- options.haconnections[options.hacount] = malloc(strlen(tok) + 1);
- strcpy(options.haconnections[options.hacount], tok);
- options.hacount++;
- tok = strtok(NULL, " ");
- }
- }
- 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;
- printf("\nSetting verbose on\n");
- }
- count++;
- }
-}
-
-
-#define LOGA_DEBUG 0
-#define LOGA_INFO 1
-#include
-#include
-#include
-void MyLog(int LOGA_level, char* format, ...)
-{
- static char msg_buf[256];
- va_list args;
- struct timeb ts;
-
- struct tm *timeinfo;
-
- if (LOGA_level == LOGA_DEBUG && options.verbose == 0)
- return;
-
- ftime(&ts);
- timeinfo = localtime(&ts.time);
- strftime(msg_buf, 80, "%Y%m%d %H%M%S", timeinfo);
-
- sprintf(&msg_buf[strlen(msg_buf)], ".%.3hu ", ts.millitm);
-
- va_start(args, format);
- vsnprintf(&msg_buf[strlen(msg_buf)], sizeof(msg_buf) - strlen(msg_buf), format, args);
- va_end(args);
-
- printf("%s\n", msg_buf);
- fflush(stdout);
-}
-
-
-#if defined(WIN32) || defined(_WINDOWS)
-#define mqsleep(A) Sleep(1000*A)
-#define START_TIME_TYPE DWORD
-static DWORD start_time = 0;
-START_TIME_TYPE start_clock(void)
-{
- return GetTickCount();
-}
-#elif defined(AIX)
-#define mqsleep sleep
-#define START_TIME_TYPE struct timespec
-START_TIME_TYPE start_clock(void)
-{
- static struct timespec start;
- clock_gettime(CLOCK_REALTIME, &start);
- return start;
-}
-#else
-#define mqsleep sleep
-#define START_TIME_TYPE struct timeval
-/* TODO - unused - remove? static struct timeval start_time; */
-START_TIME_TYPE start_clock(void)
-{
- struct timeval start_time;
- gettimeofday(&start_time, NULL);
- return start_time;
-}
-#endif
-
-
-#if defined(WIN32)
-long elapsed(START_TIME_TYPE start_time)
-{
- return GetTickCount() - start_time;
-}
-#elif defined(AIX)
-#define assert(a)
-long elapsed(struct timespec start)
-{
- struct timespec now, res;
-
- clock_gettime(CLOCK_REALTIME, &now);
- ntimersub(now, start, res);
- return (res.tv_sec)*1000L + (res.tv_nsec)/1000000L;
-}
-#else
-long elapsed(START_TIME_TYPE start_time)
-{
- struct timeval now, res;
-
- gettimeofday(&now, NULL);
- timersub(&now, &start_time, &res);
- return (res.tv_sec)*1000 + (res.tv_usec)/1000;
-}
-#endif
-
-
-#define assert(a, b, c, d) myassert(__FILE__, __LINE__, a, b, c, d)
-#define assert1(a, b, c, d, e) myassert(__FILE__, __LINE__, a, b, c, d, e)
-
-int tests = 0;
-int failures = 0;
-FILE* xml;
-START_TIME_TYPE global_start_time;
-char output[3000];
-char* cur_output = output;
-int test_finished = 0;
-
-
-void write_test_result()
-{
- long duration = elapsed(global_start_time);
-
- fprintf(xml, " time=\"%ld.%.3ld\" >\n", duration / 1000, duration % 1000);
- if (cur_output != output)
- {
- fprintf(xml, "%s", output);
- cur_output = output;
- }
- fprintf(xml, "\n");
-}
-
-
-void myassert(char* filename, int lineno, char* description, int value, char* format, ...)
-{
- ++tests;
- if (!value)
- {
- va_list args;
-
- ++failures;
- MyLog(LOGA_INFO, "Assertion failed, file %s, line %d, description: %s\n", filename, lineno, description);
-
- va_start(args, format);
- vprintf(format, args);
- va_end(args);
-
- cur_output += sprintf(cur_output, "file %s, line %d \n",
- description, filename, lineno);
- }
- else
- MyLog(LOGA_DEBUG, "Assertion succeeded, file %s, line %d, description: %s", filename, lineno, description);
-}
-
-
-void test1_onDisconnect3(void* context, MQTTAsync_successData* response)
-{
- MQTTAsync c = (MQTTAsync)context;
-
- MyLog(LOGA_DEBUG, "In onDisconnect callback %p", c);
- test_finished = 1;
-}
-
-
-void test1_onConnect3(void* context, MQTTAsync_successData* response)
-{
- MQTTAsync c = (MQTTAsync)context;
- MQTTAsync_disconnectOptions opts = MQTTAsync_disconnectOptions_initializer;
- int rc;
-
- MyLog(LOGA_DEBUG, "In connect onSuccess callback, context %p", context);
- opts.onSuccess = test1_onDisconnect3;
- opts.context = c;
-
- assert("Correct serverURI returned", strstr(response->alt.connect.serverURI, options.connection) != NULL,
- "serverURI was %s", response->alt.connect.serverURI);
- assert("Correct MQTTVersion returned", response->alt.connect.MQTTVersion == 4,
- "MQTTVersion was %d", response->alt.connect.MQTTVersion);
- assert("Correct sessionPresent returned", response->alt.connect.sessionPresent == 1,
- "sessionPresent was %d", response->alt.connect.sessionPresent);
-
- rc = MQTTAsync_disconnect(c, &opts);
- assert("Disconnect successful", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
-}
-
-
-void test1_onDisconnect2(void* context, MQTTAsync_successData* response)
-{
- MQTTAsync c = (MQTTAsync)context;
- MQTTAsync_connectOptions opts = MQTTAsync_connectOptions_initializer;
- int rc;
-
- MyLog(LOGA_DEBUG, "In onDisconnect callback %p", c);
-
- opts.MQTTVersion = 4;
- opts.cleansession = 0;
- if (options.haconnections != NULL)
- {
- opts.serverURIs = options.haconnections;
- opts.serverURIcount = options.hacount;
- }
- opts.onSuccess = test1_onConnect3;
- opts.onFailure = NULL;
- opts.context = c;
-
- opts.cleansession = 0;
- rc = MQTTAsync_connect(c, &opts);
- assert("Connect successful", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
-}
-
-
-void test1_onConnect2(void* context, MQTTAsync_successData* response)
-{
- MQTTAsync c = (MQTTAsync)context;
- MQTTAsync_disconnectOptions opts = MQTTAsync_disconnectOptions_initializer;
- int rc;
-
- MyLog(LOGA_DEBUG, "In connect onSuccess callback, context %p", context);
- opts.onSuccess = test1_onDisconnect2;
- opts.context = c;
-
- assert("Correct serverURI returned", strcmp(response->alt.connect.serverURI, options.connection) == 0,
- "serverURI was %s", response->alt.connect.serverURI);
- assert("Correct MQTTVersion returned", response->alt.connect.MQTTVersion == 4,
- "MQTTVersion was %d", response->alt.connect.MQTTVersion);
- assert("Correct sessionPresent returned", response->alt.connect.sessionPresent == 0,
- "sessionPresent was %d", response->alt.connect.sessionPresent);
-
- rc = MQTTAsync_disconnect(c, &opts);
- assert("Disconnect successful", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
-}
-
-
-void test1_onDisconnect1(void* context, MQTTAsync_successData* response)
-{
- MQTTAsync c = (MQTTAsync)context;
- MQTTAsync_connectOptions opts = MQTTAsync_connectOptions_initializer;
- int rc;
-
- MyLog(LOGA_DEBUG, "In onDisconnect callback %p", c);
-
- opts.MQTTVersion = 4;
- opts.cleansession = 0;
- if (options.haconnections != NULL)
- {
- opts.serverURIs = options.haconnections;
- opts.serverURIcount = options.hacount;
- }
- opts.onSuccess = test1_onConnect2;
- opts.onFailure = NULL;
- opts.context = c;
-
- opts.cleansession = 0;
- rc = MQTTAsync_connect(c, &opts);
- assert("Connect successful", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
-}
-
-
-void test1_onConnect1(void* context, MQTTAsync_successData* response)
-{
- MQTTAsync c = (MQTTAsync)context;
- MQTTAsync_disconnectOptions opts = MQTTAsync_disconnectOptions_initializer;
- int rc;
-
- MyLog(LOGA_DEBUG, "In connect onSuccess callback 1, context %p", context);
- opts.onSuccess = test1_onDisconnect1;
- opts.context = c;
-
- assert("Correct serverURI returned", strcmp(response->alt.connect.serverURI, options.connection) == 0,
- "serverURI was %s", response->alt.connect.serverURI);
- assert("Correct MQTTVersion returned", response->alt.connect.MQTTVersion == 4,
- "MQTTVersion was %d", response->alt.connect.MQTTVersion);
- assert("Correct sessionPresent returned", response->alt.connect.sessionPresent == 0,
- "sessionPresent was %d", response->alt.connect.sessionPresent);
-
- rc = MQTTAsync_disconnect(c, &opts);
- assert("Disconnect successful", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
-}
-
-
-/*********************************************************************
-
-Test1: sessionPresent
-
-*********************************************************************/
-int test1(struct Options options)
-{
- MQTTAsync c;
- MQTTAsync_connectOptions opts = MQTTAsync_connectOptions_initializer;
- int rc = 0;
- char* test_topic = "C client test1";
-
- fprintf(xml, "code == MQTT_BAD_SUBSCRIBE,
- "qos was %d", response->code);
-
- opts.onSuccess = test2_onDisconnect;
- rc = MQTTAsync_disconnect(c, &opts);
- assert("Disconnect successful", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
-}
-
-
-void test2_onSubscribe1(void* context, MQTTAsync_successData* response)
-{
- MQTTAsync c = (MQTTAsync)context;
- MQTTAsync_responseOptions opts = MQTTAsync_responseOptions_initializer;
- int rc;
-
- MyLog(LOGA_DEBUG, "In subscribe onSuccess callback, context %p", context);
-
- assert("Correct subscribe return code", response->alt.qos == 2,
- "qos was %d", response->alt.qos);
-}
-
-
-void test2_onConnect1(void* context, MQTTAsync_successData* response)
-{
- MQTTAsync c = (MQTTAsync)context;
- MQTTAsync_responseOptions opts = MQTTAsync_responseOptions_initializer;
- int rc;
-
- MyLog(LOGA_DEBUG, "In connect onSuccess callback 1, context %p", context);
-
- assert("Correct serverURI returned", strcmp(response->alt.connect.serverURI, options.connection) == 0,
- "serverURI was %s", response->alt.connect.serverURI);
- assert("Correct MQTTVersion returned", response->alt.connect.MQTTVersion == 4,
- "MQTTVersion was %d", response->alt.connect.MQTTVersion);
- assert("Correct sessionPresent returned", response->alt.connect.sessionPresent == 0,
- "sessionPresent was %d", response->alt.connect.sessionPresent);
-
- MyLog(LOGA_DEBUG, "In connect onSuccess callback, context %p", context);
- opts.context = c;
-
- opts.onSuccess = test2_onSubscribe1;
- rc = MQTTAsync_subscribe(c, "a topic I can subscribe to", 2, &opts);
- assert("Good rc from subscribe", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
- if (rc != MQTTASYNC_SUCCESS)
- test_finished = 1;
-
- opts.onSuccess = NULL;
- opts.onFailure = test2_onSubscribe2;
- rc = MQTTAsync_subscribe(c, "nosubscribe", 2, &opts);
- assert("Good rc from subscribe", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
- if (rc != MQTTASYNC_SUCCESS)
- test_finished = 1;
-}
-
-
-
-/*********************************************************************
-
-Test1: 0x80 from subscribe
-
-*********************************************************************/
-int test2(struct Options options)
-{
- MQTTAsync c;
- MQTTAsync_connectOptions opts = MQTTAsync_connectOptions_initializer;
- int rc = 0;
- char* test_topic = "C client test1";
-
- fprintf(xml, "\n", (int)(ARRAY_SIZE(tests) - 1));
-
- setenv("MQTT_C_CLIENT_TRACE", "ON", 1);
- setenv("MQTT_C_CLIENT_TRACE_LEVEL", "ERROR", 1);
-
- 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)
- 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 */
- }
-
- if (rc == 0)
- MyLog(LOGA_INFO, "verdict pass");
- else
- MyLog(LOGA_INFO, "verdict fail");
-
- fprintf(xml, "\n");
- fclose(xml);
- return rc;
-}
diff --git a/org.eclipse.paho.mqtt.c/test/test_mqtt4sync.c b/org.eclipse.paho.mqtt.c/test/test_mqtt4sync.c
deleted file mode 100644
index b6bae8d..0000000
--- a/org.eclipse.paho.mqtt.c/test/test_mqtt4sync.c
+++ /dev/null
@@ -1,498 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2009, 2014 IBM Corp.
- *
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * and Eclipse Distribution License v1.0 which accompany this distribution.
- *
- * The Eclipse Public License is available at
- * http://www.eclipse.org/legal/epl-v10.html
- * and the Eclipse Distribution License is available at
- * http://www.eclipse.org/org/documents/edl-v10.php.
- *
- * Contributors:
- * Ian Craggs - initial API and implementation and/or initial documentation
- * Ian Craggs - MQTT 3.1.1 support
- *******************************************************************************/
-
-
-/**
- * @file
- * MQTT 3.1.1 Tests for the synchronous Paho MQTT C client
- */
-
-
-/*
-#if !defined(_RTSHEADER)
- #include
-#endif
-*/
-
-#include "MQTTClient.h"
-#include
-#include
-
-#if !defined(_WINDOWS)
- #include
- #include
- #include
- #include
-#else
-#include
-#include
-#define MAXHOSTNAMELEN 256
-#define EAGAIN WSAEWOULDBLOCK
-#define EINTR WSAEINTR
-#define EINPROGRESS WSAEINPROGRESS
-#define EWOULDBLOCK WSAEWOULDBLOCK
-#define ENOTCONN WSAENOTCONN
-#define ECONNRESET WSAECONNRESET
-#define setenv(a, b, c) _putenv_s(a, b)
-#endif
-
-#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
-
-void usage()
-{
- printf("help!!\n");
- exit(-1);
-}
-
-struct Options
-{
- char* connection; /**< connection to system under test. */
- char** haconnections;
- int hacount;
- int verbose;
- int test_no;
- int iterations;
-} options =
-{
- "tcp://m2m.eclipse.org:1883",
- NULL,
- 0,
- 0,
- 0,
- 1,
-};
-
-void getopts(int argc, char** argv)
-{
- int count = 1;
-
- while (count < argc)
- {
- if (strcmp(argv[count], "--test_no") == 0)
- {
- if (++count < argc)
- options.test_no = atoi(argv[count]);
- else
- usage();
- }
- else if (strcmp(argv[count], "--connection") == 0)
- {
- if (++count < argc)
- {
- options.connection = argv[count];
- printf("\nSetting connection to %s\n", options.connection);
- }
- else
- usage();
- }
- else if (strcmp(argv[count], "--haconnections") == 0)
- {
- if (++count < argc)
- {
- char* tok = strtok(argv[count], " ");
- options.hacount = 0;
- options.haconnections = malloc(sizeof(char*) * 5);
- while (tok)
- {
- options.haconnections[options.hacount] = malloc(strlen(tok) + 1);
- strcpy(options.haconnections[options.hacount], tok);
- options.hacount++;
- tok = strtok(NULL, " ");
- }
- }
- 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;
- printf("\nSetting verbose on\n");
- }
- count++;
- }
-}
-
-
-#define LOGA_DEBUG 0
-#define LOGA_INFO 1
-#include
-#include
-#include
-void MyLog(int LOGA_level, char* format, ...)
-{
- static char msg_buf[256];
- va_list args;
- struct timeb ts;
-
- struct tm *timeinfo;
-
- if (LOGA_level == LOGA_DEBUG && options.verbose == 0)
- return;
-
- ftime(&ts);
- timeinfo = localtime(&ts.time);
- strftime(msg_buf, 80, "%Y%m%d %H%M%S", timeinfo);
-
- sprintf(&msg_buf[strlen(msg_buf)], ".%.3hu ", ts.millitm);
-
- va_start(args, format);
- vsnprintf(&msg_buf[strlen(msg_buf)], sizeof(msg_buf) - strlen(msg_buf), format, args);
- va_end(args);
-
- printf("%s\n", msg_buf);
- fflush(stdout);
-}
-
-
-#if defined(WIN32) || defined(_WINDOWS)
-#define mqsleep(A) Sleep(1000*A)
-#define START_TIME_TYPE DWORD
-static DWORD start_time = 0;
-START_TIME_TYPE start_clock(void)
-{
- return GetTickCount();
-}
-#elif defined(AIX)
-#define mqsleep sleep
-#define START_TIME_TYPE struct timespec
-START_TIME_TYPE start_clock(void)
-{
- static struct timespec start;
- clock_gettime(CLOCK_REALTIME, &start);
- return start;
-}
-#else
-#define mqsleep sleep
-#define START_TIME_TYPE struct timeval
-/* TODO - unused - remove? static struct timeval start_time; */
-START_TIME_TYPE start_clock(void)
-{
- struct timeval start_time;
- gettimeofday(&start_time, NULL);
- return start_time;
-}
-#endif
-
-
-#if defined(WIN32)
-long elapsed(START_TIME_TYPE start_time)
-{
- return GetTickCount() - start_time;
-}
-#elif defined(AIX)
-#define assert(a)
-long elapsed(struct timespec start)
-{
- struct timespec now, res;
-
- clock_gettime(CLOCK_REALTIME, &now);
- ntimersub(now, start, res);
- return (res.tv_sec)*1000L + (res.tv_nsec)/1000000L;
-}
-#else
-long elapsed(START_TIME_TYPE start_time)
-{
- struct timeval now, res;
-
- gettimeofday(&now, NULL);
- timersub(&now, &start_time, &res);
- return (res.tv_sec)*1000 + (res.tv_usec)/1000;
-}
-#endif
-
-
-#define assert(a, b, c, d) myassert(__FILE__, __LINE__, a, b, c, d)
-#define assert1(a, b, c, d, e) myassert(__FILE__, __LINE__, a, b, c, d, e)
-
-int tests = 0;
-int failures = 0;
-FILE* xml;
-START_TIME_TYPE global_start_time;
-char output[3000];
-char* cur_output = output;
-
-
-void write_test_result()
-{
- long duration = elapsed(global_start_time);
-
- fprintf(xml, " time=\"%ld.%.3ld\" >\n", duration / 1000, duration % 1000);
- if (cur_output != output)
- {
- fprintf(xml, "%s", output);
- cur_output = output;
- }
- fprintf(xml, "\n");
-}
-
-
-void myassert(char* filename, int lineno, char* description, int value, char* format, ...)
-{
- ++tests;
- if (!value)
- {
- va_list args;
-
- ++failures;
- MyLog(LOGA_INFO, "Assertion failed, file %s, line %d, description: %s\n", filename, lineno, description);
-
- va_start(args, format);
- vprintf(format, args);
- va_end(args);
-
- cur_output += sprintf(cur_output, "file %s, line %d \n",
- description, filename, lineno);
- }
- else
- MyLog(LOGA_DEBUG, "Assertion succeeded, file %s, line %d, description: %s", filename, lineno, description);
-}
-
-
-/*********************************************************************
-
-Test1: sessionPresent
-
-*********************************************************************/
-int test1(struct Options options)
-{
- MQTTClient c;
- MQTTClient_connectOptions opts = MQTTClient_connectOptions_initializer;
- MQTTClient_willOptions wopts = MQTTClient_willOptions_initializer;
- int rc = 0;
- char* test_topic = "C client test1";
-
- fprintf(xml, "message = "will message";
- opts.will->qos = 1;
- opts.will->retained = 0;
- opts.will->topicName = "will topic";
- opts.will = NULL;
-
- /* Connect cleansession */
- opts.cleansession = 1;
- MyLog(LOGA_DEBUG, "Connecting");
- rc = MQTTClient_connect(c, &opts);
- assert("Good rc from connect", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc);
- if (rc != MQTTCLIENT_SUCCESS)
- goto exit;
-
- assert("Correct serverURI returned", strcmp(opts.returned.serverURI, options.connection) == 0, "serverURI was %s",
- opts.returned.serverURI);
- assert("Correct MQTTVersion returned", opts.returned.MQTTVersion == 4, "MQTTVersion was %d",
- opts.returned.MQTTVersion);
- assert("Correct sessionPresent returned", opts.returned.sessionPresent == 0, "sessionPresent was %d",
- opts.returned.sessionPresent);
-
- rc = MQTTClient_disconnect(c, 0);
- assert("Disconnect successful", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc);
-
- /* Connect again, non-cleansession */
- opts.cleansession = 0;
- rc = MQTTClient_connect(c, &opts);
- assert("Connect successful", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc);
-
- assert("Correct serverURI returned", strcmp(opts.returned.serverURI, options.connection) == 0, "serverURI was %s",
- opts.returned.serverURI);
- assert("Correct MQTTVersion returned", opts.returned.MQTTVersion == 4, "MQTTVersion was %d",
- opts.returned.MQTTVersion);
- assert("Correct sessionPresent returned", opts.returned.sessionPresent == 0, "sessionPresent was %d",
- opts.returned.sessionPresent);
-
- rc = MQTTClient_disconnect(c, 0);
- assert("Disconnect successful", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc);
-
- /* Connect again, non-cleansession */
- opts.cleansession = 0;
- rc = MQTTClient_connect(c, &opts);
- assert("Connect successful", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc);
- assert("Correct serverURI returned", strcmp(opts.returned.serverURI, options.connection) == 0, "serverURI was %s",
- opts.returned.serverURI);
- assert("Correct MQTTVersion returned", opts.returned.MQTTVersion == 4, "MQTTVersion was %d",
- opts.returned.MQTTVersion);
- assert("Correct sessionPresent returned", opts.returned.sessionPresent == 1, "sessionPresent was %d",
- opts.returned.sessionPresent);
- rc = MQTTClient_disconnect(c, 0);
- assert("Disconnect successful", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc);
-
- MQTTClient_destroy(&c);
-
-exit:
- MyLog(LOGA_INFO, "TEST1: test %s. %d tests run, %d failures.",
- (failures == 0) ? "passed" : "failed", tests, failures);
- write_test_result();
- return failures;
-}
-
-
-/*********************************************************************
-
-Test2: 0x80 return code from subscribe
-
-*********************************************************************/
-volatile int test2_arrivedcount = 0;
-int test2_deliveryCompleted = 0;
-MQTTClient_message test2_pubmsg = MQTTClient_message_initializer;
-
-void test2_deliveryComplete(void* context, MQTTClient_deliveryToken dt)
-{
- ++test2_deliveryCompleted;
-}
-
-int test2_messageArrived(void* context, char* topicName, int topicLen, MQTTClient_message* m)
-{
- ++test2_arrivedcount;
- MyLog(LOGA_DEBUG, "Callback: %d message received on topic %s is %.*s.",
- test2_arrivedcount, topicName, m->payloadlen, (char*)(m->payload));
- MQTTClient_free(topicName);
- MQTTClient_freeMessage(&m);
- return 1;
-}
-
-int test2(struct Options options)
-{
- char* testname = "test2";
- int subsqos = 2;
- MQTTClient c;
- MQTTClient_connectOptions opts = MQTTClient_connectOptions_initializer;
- int rc = 0;
- char* test_topic = "C client test2";
- char* topics[2] = {"test_topic", "nosubscribe"};
- int qoss[2] = {2, 2};
-
- fprintf(xml, "\n", (int)(ARRAY_SIZE(tests) - 1));
-
- setenv("MQTT_C_CLIENT_TRACE", "ON", 1);
- setenv("MQTT_C_CLIENT_TRACE_LEVEL", "ERROR", 1);
-
- 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)
- 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 */
- }
-
- if (rc == 0)
- MyLog(LOGA_INFO, "verdict pass");
- else
- MyLog(LOGA_INFO, "verdict fail");
-
- fprintf(xml, "\n");
- fclose(xml);
- return rc;
-}