You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by ta...@apache.org on 2009/04/22 20:25:56 UTC
svn commit: r767603 - in /activemq/activemq-cpp/trunk/activemq-cpp/src/test:
Makefile.am main.cpp util/ util/teamcity/
util/teamcity/TeamCityProgressListener.cpp
util/teamcity/TeamCityProgressListener.h
Author: tabish
Date: Wed Apr 22 18:25:55 2009
New Revision: 767603
URL: http://svn.apache.org/viewvc?rev=767603&view=rev
Log:
http://issues.apache.org/activemq/browse/AMQCPP-238
Added:
activemq/activemq-cpp/trunk/activemq-cpp/src/test/util/
activemq/activemq-cpp/trunk/activemq-cpp/src/test/util/teamcity/
activemq/activemq-cpp/trunk/activemq-cpp/src/test/util/teamcity/TeamCityProgressListener.cpp (with props)
activemq/activemq-cpp/trunk/activemq-cpp/src/test/util/teamcity/TeamCityProgressListener.h
Modified:
activemq/activemq-cpp/trunk/activemq-cpp/src/test/Makefile.am
activemq/activemq-cpp/trunk/activemq-cpp/src/test/main.cpp
Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/test/Makefile.am
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/test/Makefile.am?rev=767603&r1=767602&r2=767603&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/test/Makefile.am (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/test/Makefile.am Wed Apr 22 18:25:55 2009
@@ -74,6 +74,7 @@
decaf/io/FilterOutputStreamTest.cpp \
decaf/io/ByteArrayInputStreamTest.cpp \
main.cpp \
+ util/teamcity/TeamCityProgressListener.cpp \
testRegistry.cpp \
activemq/transport/TransportRegistryTest.cpp \
activemq/transport/mock/MockTransportFactoryTest.cpp \
@@ -183,6 +184,7 @@
decaf/io/FilterOutputStreamTest.h \
decaf/io/DataInputStreamTest.h \
decaf/io/BufferedInputStreamTest.h \
+ util/teamcity/TeamCityProgressListener.h \
activemq/transport/IOTransportTest.h \
activemq/transport/mock/MockTransportFactoryTest.h \
activemq/transport/failover/FailoverTransportTest.h \
Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/test/main.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/test/main.cpp?rev=767603&r1=767602&r2=767603&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/test/main.cpp (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/test/main.cpp Wed Apr 22 18:25:55 2009
@@ -17,14 +17,18 @@
#include <cppunit/extensions/TestFactoryRegistry.h>
#include <cppunit/ui/text/TestRunner.h>
+#include <cppunit/TestListener.h>
#include <cppunit/BriefTestProgressListener.h>
+#include <cppunit/Outputter.h>
#include <cppunit/XmlOutputter.h>
#include <cppunit/TestResult.h>
+#include <util/teamcity/TeamCityProgressListener.h>
#include <activemq/util/Config.h>
#include <activemq/library/ActiveMQCPP.h>
#include <decaf/lang/Runtime.h>
#include <decaf/lang/Integer.h>
#include <iostream>
+#include <memory>
int main( int argc, char **argv ) {
@@ -32,34 +36,63 @@
bool wasSuccessful = false;
int iterations = 1;
+ std::ofstream outputFile;
+ bool useXMLOutputter = false;
+ std::auto_ptr<CppUnit::TestListener> listener( new CppUnit::BriefTestProgressListener );
if( argc > 1 ) {
- try {
- iterations = decaf::lang::Integer::parseInt( argv[1] );
- } catch( decaf::lang::exceptions::NumberFormatException& ex ) {
- iterations = 1;
+ for( int i = 1; i < argc; ++i ) {
+ const std::string arg( argv[i] );
+ if( arg == "-runs" ) {
+ if( ( i + 1 ) >= argc ) {
+ std::cout << "-runs requires a value for the iteration count" << std::endl;
+ return -1;
+ }
+ try {
+ iterations = decaf::lang::Integer::parseInt( argv[++i] );
+ } catch( decaf::lang::exceptions::NumberFormatException& ex ) {
+ std::cout << "Invalid iteration count specified on command line: "
+ << argv[i] << std::endl;
+ return -1;
+ }
+ } else if( arg == "-teamcity" ) {
+ listener.reset( new test::util::teamcity::TeamCityProgressListener() );
+ } else if( arg == "-quiet" ) {
+ listener.reset( NULL );
+ } else if( arg == "-xml" ) {
+ if( ( i + 1 ) >= argc ) {
+ std::cout << "-xml requires a filename to be specified" << std::endl;
+ return -1;
+ }
+
+ std::ofstream outputFile( argv[++i] );
+ useXMLOutputter = true;
+ }
}
}
for( int i = 0; i < iterations; ++i ) {
- std::ofstream outputFile( "activemq-test.xml" );
-
CppUnit::TextUi::TestRunner runner;
CppUnit::TestFactoryRegistry ®istry = CppUnit::TestFactoryRegistry::getRegistry();
runner.addTest( registry.makeTest() );
// Shows a message as each test starts
- CppUnit::BriefTestProgressListener listener;
- runner.eventManager().addListener( &listener );
+ if( listener.get() != NULL ) {
+ runner.eventManager().addListener( listener.get() );
+ }
// Specify XML output and inform the test runner of this format. The TestRunner
// will delete the passed XmlOutputter for us.
- runner.setOutputter( new CppUnit::XmlOutputter( &runner.result(), outputFile ) );
+ if( useXMLOutputter ) {
+ runner.setOutputter( new CppUnit::XmlOutputter( &runner.result(), outputFile ) );
+ }
wasSuccessful = runner.run( "", false );
- outputFile.close();
+ if( useXMLOutputter ) {
+ outputFile.close();
+ }
}
activemq::library::ActiveMQCPP::shutdownLibrary();
Added: activemq/activemq-cpp/trunk/activemq-cpp/src/test/util/teamcity/TeamCityProgressListener.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/test/util/teamcity/TeamCityProgressListener.cpp?rev=767603&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/test/util/teamcity/TeamCityProgressListener.cpp (added)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/test/util/teamcity/TeamCityProgressListener.cpp Wed Apr 22 18:25:55 2009
@@ -0,0 +1,136 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <iostream>
+#include <sstream>
+#include "cppunit/Test.h"
+#include "cppunit/Exception.h"
+
+#include <util/teamcity/TeamCityProgressListener.h>
+
+using namespace CPPUNIT_NS;
+using namespace std;
+using namespace test;
+using namespace test::util;
+using namespace test::util::teamcity;
+
+////////////////////////////////////////////////////////////////////////////////
+void TeamCityProgressListener::startTest( Test* test ) {
+ writeOpen( "testStarted" );
+ writeProperty( "name", test->getName() );
+ writeClose();
+}
+
+////////////////////////////////////////////////////////////////////////////////
+static string sourceLine2string( const SourceLine& sline ) {
+
+ std::stringstream ss;
+ ss << sline.fileName() << ":" << sline.lineNumber();
+ return ss.str();
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void TeamCityProgressListener::addFailure( const TestFailure& failure ) {
+
+ const Exception *e = failure.thrownException();
+
+ string details = e->message().details();
+
+ if( e->sourceLine().isValid() ) {
+ details.append( " at " );
+ details.append( sourceLine2string( e->sourceLine() ) );
+ details.append( "\n" );
+ }
+
+ writeOpen( "testFailed" );
+ writeProperty( "name", failure.failedTest()->getName() );
+ writeProperty( "message", e->message().shortDescription() );
+ writeProperty( "details", details );
+ writeClose();
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void TeamCityProgressListener::endTest( Test* test ) {
+ writeOpen( "testFinished" );
+ writeProperty("name", test->getName() );
+ writeClose();
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void TeamCityProgressListener::startSuite( Test* test ) {
+ writeOpen( "testSuiteStarted" );
+ writeProperty( "name", test->getName() );
+ writeClose();
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void TeamCityProgressListener::endSuite( Test* test ) {
+ writeOpen( "testSuiteFinished" );
+ writeProperty( "name", test->getName() );
+ writeClose();
+}
+
+////////////////////////////////////////////////////////////////////////////////
+std::string TeamCityProgressListener::escape( const std::string& value ) const {
+
+ std::string result;
+
+ for( std::size_t i = 0; i < value.length(); i++ ) {
+
+ char c = value[i];
+
+ switch(c) {
+ case '\n':
+ result.append( "|n" );
+ break;
+ case '\r':
+ result.append( "|r" );
+ break;
+ case '\'':
+ result.append( "|'" );
+ break;
+ case '|':
+ result.append( "||" );
+ break;
+ case ']':
+ result.append( "|]" );
+ break;
+ default:
+ result.append( &c, 1 );
+ }
+ }
+
+ return result;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void TeamCityProgressListener::writeOpen( const std::string& name ) {
+ std::cout << std::endl << "##teamcity[" << name;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void TeamCityProgressListener::writeClose() {
+ std::cout << "]" << std::endl;
+ std::cout.flush();
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void TeamCityProgressListener::writeProperty( const std::string& name,
+ const std::string& value ) {
+
+ std::cout << " " << name << "='" << escape( value ) << "'";
+}
Propchange: activemq/activemq-cpp/trunk/activemq-cpp/src/test/util/teamcity/TeamCityProgressListener.cpp
------------------------------------------------------------------------------
svn:eol-style = native
Added: activemq/activemq-cpp/trunk/activemq-cpp/src/test/util/teamcity/TeamCityProgressListener.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/test/util/teamcity/TeamCityProgressListener.h?rev=767603&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/test/util/teamcity/TeamCityProgressListener.h (added)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/test/util/teamcity/TeamCityProgressListener.h Wed Apr 22 18:25:55 2009
@@ -0,0 +1,72 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef _TEST_UTIL_TEAMCITY_TEAMCITYPROGRESSLISTENER_H_
+#define _TEST_UTIL_TEAMCITY_TEAMCITYPROGRESSLISTENER_H_
+
+#include <cppunit/TestFailure.h>
+#include <cppunit/TestListener.h>
+
+#include <string>
+
+namespace test {
+namespace util {
+namespace teamcity {
+
+ /**
+ * CPPUnit Derived Test Listener that can output the test life cycle messages in
+ * a manner that can be processed by the TeamCity Continuous integration tool.
+ */
+ class TeamCityProgressListener: public CPPUNIT_NS::TestListener {
+ public:
+
+ TeamCityProgressListener() {}
+ ~TeamCityProgressListener() {}
+
+ void startTest( CPPUNIT_NS::Test *test );
+ void addFailure( const CPPUNIT_NS::TestFailure &failure );
+ void endTest( CPPUNIT_NS::Test *test );
+ void startSuite( CPPUNIT_NS::Test *test );
+ void endSuite( CPPUNIT_NS::Test *test );
+
+ private:
+
+ // Prevents the use of the copy constructor.
+ TeamCityProgressListener( const TeamCityProgressListener& );
+
+ // Prevents the use of the copy operator.
+ void operator =( const TeamCityProgressListener& );
+
+ protected:
+
+ /**
+ * Escapes the control characters in a string.
+ *
+ * @param value - String to escape
+ * @return the new escaped string.
+ */
+ virtual std::string escape( const std::string& value ) const;
+
+ virtual void writeOpen( const std::string& name );
+ virtual void writeProperty( const std::string& name, const std::string& value );
+ virtual void writeClose();
+
+ };
+
+}}}
+
+#endif /* _TEST_UTIL_TEAMCITY_TEAMCITYPROGRESSLISTENER_H_ */