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, "<testcase classname=\"test3\" name=\"test 3a_s\""); global_start_time = start_clock(); rc = MQTTClient_create(&c, options.server_auth_connection, "test3a_s", MQTTCLIENT_PERSISTENCE_DEFAULT, persistenceStore); if (!(assert("good rc from create", rc == MQTTCLIENT_SUCCESS, "rc was %d\n", rc))) goto exit; opts.keepAliveInterval = 20; opts.cleansession = 1; opts.username = "******"; opts.password = "******"; if (options.haconnections != NULL) { opts.serverURIs = options.haconnections; opts.serverURIcount = options.hacount; } opts.ssl = &sslopts; if (options.server_key_file != NULL) opts.ssl->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; }
int test4_s(struct Options options) { char* testname = "test4_s"; char* test_topic = "C client test4_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 4_s - accept invalid server certificates - single threaded"); if (!(assert("good rc from create", (rc = MQTTClient_create(&c, options.connection, "test4_s", MQTTCLIENT_PERSISTENCE_DEFAULT, persistenceStore)) == MQTTCLIENT_SUCCESS, "rc was %d\n", rc))) goto exit; opts.keepAliveInterval = 20; opts.cleansession = 1; opts.username = "******"; opts.password = "******"; if (options.haconnections != NULL) { opts.serverURIs = options.haconnections; opts.serverURIcount = options.hacount; } 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; MyLog(LOGA_DEBUG, "Connecting"); if (!(assert("Good rc from connect", (rc = MQTTClient_connect(c, &opts)) == MQTTCLIENT_SUCCESS, "rc was %d", rc))) goto exit; if (!(assert("Good rc from subscribe", (rc = MQTTClient_subscribe(c, test_topic, subsqos)) == 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"); if (!(assert("Unsubscribe successful", (rc = MQTTClient_unsubscribe(c, test_topic)) == MQTTCLIENT_SUCCESS, "rc was %d", rc))) goto exit; if (!(assert("Disconnect successful", (rc = MQTTClient_disconnect(c, 0)) == MQTTCLIENT_SUCCESS, "rc was %d", rc))) goto exit; /* Just to make sure we can connect again */ if (!(assert("Connect successful", (rc = MQTTClient_connect(c, &opts)) == MQTTCLIENT_SUCCESS, "rc was %d", rc))) goto exit; if (!(assert("Disconnect successful", (rc = MQTTClient_disconnect(c, 0)) == 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); return failures; }