From 8ea91b2aa2b1a6a3fdbf47a2eb36e7c2c997bec8 Mon Sep 17 00:00:00 2001 From: Alan Conway Date: Wed, 27 Jun 2007 00:12:26 +0000 Subject: Make check now starts a broker on a dynamically assigned port, so multiple qpid builds on one host will not conflict. * src/tests/run_test, start_broker, kill_broker: Broker writes port to file, run_test sets QPID_PORT in environment of all tests. * src/tests/topic_publisher.cpp, topic_listener.cpp, client_test.cpp: All test clients use TestOptions to parse options from args and env. * src/qpid/Options.h: Renamed from CommonOptions.h Simplified use of Options class. * src/qpid/Url.h: Renamed defaultPort constant. * src/tests/logging.cpp: * src/tests/interop_runner.cpp: * src/tests/TestOptions.h: * src/qpidd.cpp: * src/qpid/log/Options.cpp: * src/qpid/log/Logger.cpp: * src/qpid/broker/Broker.cpp: Updated for changes to Options. git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk@550993 13f79535-47bb-0310-9956-ffa450edef68 --- qpid/cpp/src/tests/client_test.cpp | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) (limited to 'qpid/cpp/src/tests/client_test.cpp') diff --git a/qpid/cpp/src/tests/client_test.cpp b/qpid/cpp/src/tests/client_test.cpp index a05c01043f..3b8a3a2ee6 100644 --- a/qpid/cpp/src/tests/client_test.cpp +++ b/qpid/cpp/src/tests/client_test.cpp @@ -28,6 +28,7 @@ #include +#include "TestOptions.h" #include "qpid/QpidError.h" #include "qpid/client/ClientChannel.h" #include "qpid/client/Connection.h" @@ -59,38 +60,39 @@ public: } }; -int main(int argc, char**) +int main(int argc, char** argv) { - verbose = argc > 1; try { + qpid::TestOptions opts; + opts.parse(argc, argv); + //Use a custom exchange Exchange exchange("MyExchange", Exchange::TOPIC_EXCHANGE); //Use a named, temporary queue Queue queue("MyQueue", true); - Connection con(verbose); - string host("localhost"); - con.open(host, 5672, "guest", "guest", "/test"); - if (verbose) + Connection con(opts.trace); + con.open(opts.host, opts.port, opts.username, opts.password, opts.virtualhost); + if (opts.trace) std::cout << "Opened connection." << std::endl; //Create and open a channel on the connection through which //most functionality is exposed Channel channel; con.openChannel(channel); - if (verbose) std::cout << "Opened channel." << std::endl; + if (opts.trace) std::cout << "Opened channel." << std::endl; //'declare' the exchange and the queue, which will create them //as they don't exist channel.declareExchange(exchange); - if (verbose) std::cout << "Declared exchange." << std::endl; + if (opts.trace) std::cout << "Declared exchange." << std::endl; channel.declareQueue(queue); - if (verbose) std::cout << "Declared queue." << std::endl; + if (opts.trace) std::cout << "Declared queue." << std::endl; //now bind the queue to the exchange channel.bind(exchange, queue, "MyTopic"); - if (verbose) std::cout << "Bound queue to exchange." << std::endl; + if (opts.trace) std::cout << "Bound queue to exchange." << std::endl; //Set up a message listener to receive any messages that //arrive in our queue on the broker. We only expect one, and @@ -101,7 +103,7 @@ int main(int argc, char**) SimpleListener listener(&monitor); string tag("MyTag"); channel.consume(queue, tag, &listener); - if (verbose) std::cout << "Registered consumer." << std::endl; + if (opts.trace) std::cout << "Registered consumer." << std::endl; //we need to enable the message dispatching for this channel //and we want that to occur on another thread so we call @@ -114,7 +116,7 @@ int main(int argc, char**) string data("MyMessage"); msg.setData(data); channel.publish(msg, exchange, "MyTopic"); - if (verbose) std::cout << "Published message: " << data << std::endl; + if (opts.trace) std::cout << "Published message: " << data << std::endl; { Monitor::ScopedLock l(monitor); @@ -125,9 +127,9 @@ int main(int argc, char**) //close the channel & connection channel.close(); - if (verbose) std::cout << "Closed channel." << std::endl; + if (opts.trace) std::cout << "Closed channel." << std::endl; con.close(); - if (verbose) std::cout << "Closed connection." << std::endl; + if (opts.trace) std::cout << "Closed connection." << std::endl; return 0; } catch(const std::exception& e) { std::cout << e.what() << std::endl; -- cgit v1.2.1