diff --git a/Doxyfile b/Doxyfile index 013c6dd..aa5c142 100644 --- a/Doxyfile +++ b/Doxyfile @@ -38,7 +38,7 @@ PROJECT_NAME = "Paho C++" # could be handy for archiving the generated documentation or if some version # control system is used. -PROJECT_NUMBER = 0.9 +PROJECT_NUMBER = 1.0 # Using the PROJECT_BRIEF tag one can provide an optional one line description # for a project that appears at the top of each page and should give viewer a diff --git a/src/async_client.cpp b/src/async_client.cpp index e9dd319..9f67147 100644 --- a/src/async_client.cpp +++ b/src/async_client.cpp @@ -155,7 +155,9 @@ int async_client::on_message_arrived(void* context, char* topicName, int topicLe consumer_queue_type& que = cli->que_; if (cb || que) { - string topic(topicName, topicName+topicLen); + size_t len = (topicLen == 0) ? strlen(topicName) : size_t(topicLen); + + string topic(topicName, topicName+len); auto m = message::create(std::move(topic), *msg); if (cb) diff --git a/test/unit/async_client_test.h b/test/unit/async_client_test.h index 1de7c16..4eaf33a 100644 --- a/test/unit/async_client_test.h +++ b/test/unit/async_client_test.h @@ -51,8 +51,9 @@ class async_client_test : public CppUnit::TestFixture CPPUNIT_TEST( test_connect_2_args ); CPPUNIT_TEST( test_connect_3_args ); CPPUNIT_TEST( test_connect_3_args_failure ); + CPPUNIT_TEST( test_connect_uninitialized_ssl ); - CPPUNIT_TEST( test_disconnect_0_arg ); + CPPUNIT_TEST( test_disconnect_0_arg ); CPPUNIT_TEST( test_disconnect_1_arg ); CPPUNIT_TEST( test_disconnect_1_arg_failure ); CPPUNIT_TEST( test_disconnect_2_args ); @@ -97,9 +98,10 @@ class async_client_test : public CppUnit::TestFixture const std::string GOOD_SERVER_URI { "tcp://m2m.eclipse.org:1883" }; #else const std::string GOOD_SERVER_URI { "tcp://localhost:1883" }; + const std::string GOOD_SSL_SERVER_URI { "ssl://localhost:18885" }; #endif const std::string BAD_SERVER_URI { "one://invalid.address" }; - const std::string CLIENT_ID { "async_client_unit_test" }; + const std::string CLIENT_ID { "" }; // { "async_client_unit_test" }; const std::string PERSISTENCE_DIR { "/tmp" }; const std::string TOPIC { "TOPIC" }; const int GOOD_QOS { 0 }; @@ -237,22 +239,44 @@ public: wo.set_qos(BAD_QOS); // Invalid QoS causes connection failure co.set_will(wo); mqtt::test::dummy_action_listener listener; - int reason_code = MQTTASYNC_SUCCESS; + int reasonCode = MQTTASYNC_SUCCESS; try { token_conn = cli.connect(co, &CONTEXT, listener); CPPUNIT_ASSERT(token_conn); token_conn->wait(); } catch (mqtt::exception& ex) { - reason_code = ex.get_reason_code(); + reasonCode = ex.get_reason_code(); } CPPUNIT_ASSERT(nullptr == token_conn); CPPUNIT_ASSERT_EQUAL(false, cli.is_connected()); - CPPUNIT_ASSERT_EQUAL(MQTTASYNC_BAD_QOS, reason_code); + CPPUNIT_ASSERT_EQUAL(MQTTASYNC_BAD_QOS, reasonCode); // TODO Why listener.on_failure() is not called? //CPPUNIT_ASSERT(listener.on_failure_called); } + // An improperly initialized SSL connect request should fail gracefully + void test_connect_uninitialized_ssl() { + mqtt::async_client cli { GOOD_SSL_SERVER_URI, CLIENT_ID }; + + mqtt::connect_options opts; + opts.set_keep_alive_interval(10); + opts.set_clean_session(true); + // Note that we're not setting SSL options. + + mqtt::token_ptr tok; + int reasonCode = MQTTASYNC_SUCCESS; + + try { + tok = cli.connect(opts); + tok->wait(); + } + catch (mqtt::exception& ex) { + reasonCode = ex.get_reason_code(); + } + CPPUNIT_ASSERT(reasonCode != MQTTASYNC_SUCCESS); + } + //---------------------------------------------------------------------- // Test async_client::disconnect() //----------------------------------------------------------------------