diff options
96 files changed, 10877 insertions, 0 deletions
diff --git a/cppunit/inc/cppunit/Asserter.h b/cppunit/inc/cppunit/Asserter.h new file mode 100644 index 000000000000..0ba94eb59d76 --- /dev/null +++ b/cppunit/inc/cppunit/Asserter.h @@ -0,0 +1,106 @@ +#ifndef CPPUNIT_ASSERTER_H +#define CPPUNIT_ASSERTER_H + +#include <cppunit/Portability.h> +#include <cppunit/SourceLine.h> +#include <string> +#include <rtl/ustring.hxx> + +namespace CppUnit +{ + +/*! \brief A set of functions to help writing assertion macros. + * \ingroup CreatingNewAssertions + * + * Here is an example of assertion, a simplified version of the + * actual assertion implemented in examples/cppunittest/XmlUniformiser.h: + * \code + * #include <cppunit/SourceLine.h> + * #include <cppunit/TestAssert.h> + * + * void + * checkXmlEqual( std::string expectedXml, + * std::string actualXml, + * CppUnit::SourceLine sourceLine ) + * { + * std::string expected = XmlUniformiser( expectedXml ).stripped(); + * std::string actual = XmlUniformiser( actualXml ).stripped(); + * + * if ( expected == actual ) + * return; + * + * ::CppUnit::Asserter::failNotEqual( expected, + * actual, + * sourceLine ); + * } + * + * /// Asserts that two XML strings are equivalent. + * #define CPPUNITTEST_ASSERT_XML_EQUAL( expected, actual ) \ + * checkXmlEqual( expected, actual, \ + * CPPUNIT_SOURCELINE() ) + * \endcode + */ +namespace Asserter +{ + + /*! Throws a Exception with the specified message and location. + */ + void CPPUNIT_API fail( std::string const& message, + SourceLine const& sourceLine = SourceLine() ); + + /*! Throws a Exception with the specified message and location. + * \param shouldFail if \c true then the exception is thrown. Otherwise + * nothing happen. + * \param message Message explaining the assertion failiure. + * \param sourceLine Location of the assertion. + */ + void CPPUNIT_API failIf( bool shouldFail, + std::string const& message, + SourceLine const& sourceLine = SourceLine() ); + + + // LLA: test, if it's possible to use a DEFINE twice ;-) + void CPPUNIT_API failIf( bool shouldFail, + rtl::OUString const& message, + SourceLine const& sourceLine = SourceLine() ); + + /*! Throws a NotEqualException with the specified message and location. + * \param expected Text describing the expected value. + * \param actual Text describing the actual value. + * \param additionalMessage Additional message. Usually used to report + * where the "difference" is located. + * \param sourceLine Location of the assertion. + */ + void CPPUNIT_API failNotEqual( std::string const& expected, + std::string const& actual, + SourceLine const& sourceLine = SourceLine(), + std::string const& additionalMessage ="" ); + + /*! Throws a NotEqualException with the specified message and location. + * \param shouldFail if \c true then the exception is thrown. Otherwise + * nothing happen. + * \param expected Text describing the expected value. + * \param actual Text describing the actual value. + * \param additionalMessage Additional message. Usually used to report + * where the "difference" is located. + * \param sourceLine Location of the assertion. + */ + void CPPUNIT_API failNotEqualIf( bool shouldFail, + std::string const& expected, + std::string const& actual, + SourceLine const& sourceLine = SourceLine(), + std::string const& additionalMessage ="" ); + + + /*! Throws an Exception with the specified message and location. + * \param message Message explaining the assertion failure. + * \param sourceLine Location of the assertion. + */ + void CPPUNIT_API failStub( std::string const& message, + SourceLine const& sourceLine = SourceLine() ); + +} // namespace Asserter +} // namespace CppUnit + + +#endif // CPPUNIT_ASSERTER_H diff --git a/cppunit/inc/cppunit/Exception.h b/cppunit/inc/cppunit/Exception.h new file mode 100644 index 000000000000..98839e0846fa --- /dev/null +++ b/cppunit/inc/cppunit/Exception.h @@ -0,0 +1,116 @@ +#ifndef CPPUNIT_EXCEPTION_H +#define CPPUNIT_EXCEPTION_H + +#include <cppunit/Portability.h> +#include <cppunit/SourceLine.h> +#include <exception> +#include <string> + +namespace CppUnit { + +/*! \brief Exceptions thrown by failed assertions. + * \ingroup BrowsingCollectedTestResult + * + * Exception is an exception that serves + * descriptive strings through its what() method + */ +class CPPUNIT_API Exception : public std::exception +{ +public: + + class Type + { + public: + Type( std::string const& _type ) : m_type ( _type ) {} + + bool operator ==( const Type &other ) const + { + return m_type == other.m_type; + } + private: + const std::string m_type; + }; + + + Exception( std::string const& message = "", + SourceLine const& sourceLine = SourceLine() ); + +#ifdef CPPUNIT_ENABLE_SOURCELINE_DEPRECATED + Exception( std::string const& message, + long lineNumber, + std::string const& fileName ); +#endif + + Exception (const Exception& other); + + virtual ~Exception () throw(); + + Exception& operator= (const Exception& other); + + const char *what() const throw (); + + SourceLine sourceLine() const; + +#ifdef CPPUNIT_ENABLE_SOURCELINE_DEPRECATED + long lineNumber() const; + std::string fileName() const; + + static const std::string UNKNOWNFILENAME; + static const long UNKNOWNLINENUMBER; +#endif + + virtual Exception *clone() const; + + virtual bool isInstanceOf( const Type &type ) const; + + static Type type(); + +private: + // VC++ does not recognize call to parent class when prefixed + // with a namespace. This is a workaround. + typedef std::exception SuperClass; + + std::string m_message; + SourceLine m_sourceLine; +}; + +// ----------------------------------------------------------------------------- + +class StubException : public Exception +{ +public: + StubException( std::string const& _message = "", + SourceLine const& _sourceLine = SourceLine() ) + :Exception(_message, _sourceLine) {} + + +#ifdef CPPUNIT_ENABLE_SOURCELINE_DEPRECATED + StubException( std::string const& message, + long lineNumber, + std::string const& fileName ) + :Exception(message, lineNumber, fileName) {} +#endif +}; + +// ----------------------------------------------------------------------------- + +class SignalException : public Exception +{ +public: + SignalException( std::string const& _message = "", + SourceLine const& _sourceLine = SourceLine() ) + :Exception(_message, _sourceLine) {} + + +#ifdef CPPUNIT_ENABLE_SOURCELINE_DEPRECATED + SignalException( std::string const& message, + long lineNumber, + std::string const& fileName ) + :Exception(message, lineNumber, fileName) {} +#endif +}; + +} // namespace CppUnit + +#endif // CPPUNIT_EXCEPTION_H + diff --git a/cppunit/inc/cppunit/NotEqualException.h b/cppunit/inc/cppunit/NotEqualException.h new file mode 100644 index 000000000000..18748fb82142 --- /dev/null +++ b/cppunit/inc/cppunit/NotEqualException.h @@ -0,0 +1,65 @@ +#ifndef NOTEQUALEXCEPTION_H +#define NOTEQUALEXCEPTION_H + +#include <cppunit/Exception.h> + + +namespace CppUnit { + +/*! \brief Exception thrown by failed equality assertions. + * \ingroup BrowsingCollectedTestResult + */ +class CPPUNIT_API NotEqualException : public Exception +{ +public: + /*! Constructs the exception. + * \param expected Text that represents the expected value. + * \param actual Text that represents the actual value. + * \param sourceLine Location of the assertion. + * \param additionalMessage Additionnal information provided to further qualify + * the inequality. + */ + NotEqualException( std::string const& expected, + std::string const& actual, + SourceLine const& sourceLine = SourceLine(), + std::string const& additionalMessage = "" ); + +#ifdef CPPUNIT_ENABLE_SOURCELINE_DEPRECATED + NotEqualException( std::string const& expected, + std::string const& actual, + long lineNumber, + std::string const& fileName ); +#endif + + NotEqualException( const NotEqualException &other ); + + + virtual ~NotEqualException() throw(); + + std::string expectedValue() const; + + std::string actualValue() const; + + std::string additionalMessage() const; + + /*! Copy operator. + * @param other Object to copy. + * @return Reference on this object. + */ + NotEqualException &operator =( const NotEqualException &other ); + + Exception *clone() const; + + bool isInstanceOf( const Type &type ) const; + + static Type type(); + +private: + std::string m_expected; + std::string m_actual; + std::string m_additionalMessage; +}; + +} // namespace CppUnit + +#endif // NOTEQUALEXCEPTION_H diff --git a/cppunit/inc/cppunit/Portability.h b/cppunit/inc/cppunit/Portability.h new file mode 100644 index 000000000000..b81900e9a7df --- /dev/null +++ b/cppunit/inc/cppunit/Portability.h @@ -0,0 +1,85 @@ +#ifndef CPPUNIT_PORTABILITY_H +#define CPPUNIT_PORTABILITY_H + +/* include platform specific config */ +#if defined(__BORLANDC__) +# include <cppunit/portability/config-bcb5.h> +#elif defined (_MSC_VER) +# include <cppunit/portability/config-msvc6.h> +#else +# include <cppunit/portability/config-auto.h> +#endif + + +/* Options that the library user may switch on or off. + * If the user has not done so, we chose default values. + */ + + +/* Define to 1 if you wish to have the old-style macros + assert(), assertEqual(), assertDoublesEqual(), and assertLongsEqual() */ +#ifndef CPPUNIT_ENABLE_NAKED_ASSERT +#define CPPUNIT_ENABLE_NAKED_ASSERT 0 +#endif + +/* Define to 1 if you wish to have the old-style CU_TEST family + of macros. */ +#ifndef CPPUNIT_ENABLE_CU_TEST_MACROS +#define CPPUNIT_ENABLE_CU_TEST_MACROS 0 +#endif + +/* Define to 1 if the preprocessor expands (#foo) to "foo" (quotes incl.) + I don't think there is any C preprocess that does NOT support this! */ +#ifndef CPPUNIT_HAVE_CPP_SOURCE_ANNOTATION +#define CPPUNIT_HAVE_CPP_SOURCE_ANNOTATION 1 +#endif + +// CPPUNIT_API is defined in <config_msvc6.h> if required (building or using as dll) +#ifndef CPPUNIT_API +#define CPPUNIT_API +#undef CPPUNIT_NEED_DLL_DECL +#define CPPUNIT_NEED_DLL_DECL 0 +#endif + + +/* perform portability hacks */ + + +/* Define CPPUNIT_SSTREAM as a stream with a "std::string str()" + * method. + */ +#if CPPUNIT_HAVE_SSTREAM +# include <sstream> + namespace CppUnit { + class OStringStream : public std::ostringstream + { + }; + } +#else +#if CPPUNIT_HAVE_CLASS_STRSTREAM +# include <string> +# if CPPUNIT_HAVE_STRSTREAM +# include <strstream> +# else +# include <strstream.h> +# endif + + namespace CppUnit { + class OStringStream : public std::ostrstream + { + public: + std::string str() + { + (*this) << '\0'; + std::string msg(std::ostrstream::str()); + std::ostrstream::freeze(false); + return msg; + } + }; + } +#else +# error Cannot define CppUnit::OStringStream. +#endif +#endif + +#endif // CPPUNIT_PORTABILITY_H diff --git a/cppunit/inc/cppunit/SourceLine.h b/cppunit/inc/cppunit/SourceLine.h new file mode 100644 index 000000000000..48b87f236cf3 --- /dev/null +++ b/cppunit/inc/cppunit/SourceLine.h @@ -0,0 +1,60 @@ +#ifndef CPPUNIT_SOURCELINE_H +#define CPPUNIT_SOURCELINE_H + +#include <cppunit/Portability.h> +#include <string> + +/*! \brief Constructs a SourceLine object initialized with the location where the macro is expanded. + * \ingroup CreatingNewAssertions + * \relates CppUnit::SourceLine + * Used to write your own assertion macros. + * \see Asserter for example of usage. + */ +#define CPPUNIT_SOURCELINE() ::CppUnit::SourceLine( __FILE__, __LINE__ ) + + +namespace CppUnit +{ + +/*! \brief Represents a source line location. + * \ingroup CreatingNewAssertions + * \ingroup BrowsingCollectedTestResult + * + * Used to capture the failure location in assertion. + * + * Use the CPPUNIT_SOURCELINE() macro to construct that object. Typically used when + * writing an assertion macro in association with Asserter. + * + * \see Asserter. + */ +class CPPUNIT_API SourceLine +{ +public: + SourceLine(); + + SourceLine( const std::string &fileName, + int lineNumber ); + + /// Destructor. + virtual ~SourceLine(); + + bool isValid() const; + + int lineNumber() const; + + std::string fileName() const; + + bool operator ==( const SourceLine &other ) const; + bool operator !=( const SourceLine &other ) const; + +private: + std::string m_fileName; + int m_lineNumber; +}; + + +} // namespace CppUnit + + + +#endif // CPPUNIT_SOURCELINE_H diff --git a/cppunit/inc/cppunit/Test.h b/cppunit/inc/cppunit/Test.h new file mode 100644 index 000000000000..1e7beb39afe7 --- /dev/null +++ b/cppunit/inc/cppunit/Test.h @@ -0,0 +1,64 @@ +#ifndef CPPUNIT_TEST_H +#define CPPUNIT_TEST_H + +#include <cppunit/Portability.h> +#include <string> +#include <cppunit/autoregister/htestresult.h> + +namespace CppUnit { + +//# class TestResult; + +/*! \brief Base class for all test objects. + * \ingroup BrowsingCollectedTestResult + *l- + * All test objects should be a subclass of Test. Some test objects, + * TestCase for example, represent one individual test. Other test + * objects, such as TestSuite, are comprised of several tests. + * + * When a Test is run, the result is collected by a TestResult object. + * + * \see TestCase + * \see TestSuite + */ +class CPPUNIT_API Test +{ +public: + virtual ~Test () {}; + + /*! \brief Run the test, collecting results. + */ + virtual void run (hTestResult pResult) = 0; + + /*! \brief Return the number of test cases invoked by run(). + * + * The base unit of testing is the class TestCase. This + * method returns the number of TestCase objects invoked by + * the run() method. + */ + virtual int countTestCases () const = 0; + + /*! \brief Returns the test name. + * + * Each test has a name. This name may be used to find the + * test in a suite or registry of tests. + */ + virtual std::string getName () const = 0; + + /*! \brief Description of the test, for diagnostic output. + * + * The test description will typically include the test name, + * but may have additional description. For example, a test + * suite named <tt>complex_add</tt> may be described as + * <tt>suite complex_add</tt>. + */ + virtual std::string toString () const = 0; + + +}; + + +} // namespace CppUnit + +#endif // CPPUNIT_TEST_H + diff --git a/cppunit/inc/cppunit/TestAssert.h b/cppunit/inc/cppunit/TestAssert.h new file mode 100644 index 000000000000..d2f4c31ce190 --- /dev/null +++ b/cppunit/inc/cppunit/TestAssert.h @@ -0,0 +1,246 @@ +#ifndef CPPUNIT_TESTASSERT_H +#define CPPUNIT_TESTASSERT_H + +#include <cppunit/Portability.h> +#include <cppunit/Exception.h> +#include <cppunit/Asserter.h> + +#include <cppunit/checkboom.hxx> + +namespace CppUnit { + + + + /*! \brief Traits used by CPPUNIT_ASSERT_EQUAL(). + * + * Here is an example of specialization of that traits: + * + * \code + * template<> + * struct assertion_traits<std::string> // specialization for the std::string type + * { + * static bool equal( const std::string& x, const std::string& y ) + * { + * return x == y; + * } + * + * static std::string toString( const std::string& x ) + * { + * std::string text = '"' + x + '"'; // adds quote around the string to see whitespace + * OStringStream ost; + * ost << text; + * return ost.str(); + * } + * }; + * \endcode + */ + + +template <class T> +struct assertion_traits +{ + static bool equal( const T& x, const T& y ) + { + return x == y; + } + + static std::string toString( const T& x ) + { + OStringStream ost; + ost << x; + return ost.str(); + } +}; + +namespace TestAssert +{ +#ifdef CPPUNIT_ENABLE_SOURCELINE_DEPRECATED + void CPPUNIT_API assertImplementation( bool condition, + std::string conditionExpression = "", + long lineNumber, + std::string fileName ); + + void CPPUNIT_API assertNotEqualImplementation( std::string expected, + std::string actual, + long lineNumber, + std::string fileName ); + + + template <class T> + void assertEquals( const T& expected, + const T& actual, + long lineNumber, + std::string fileName ) + { + if ( !assertion_traits<T>::equal(expected,actual) ) // lazy toString conversion... + { + assertNotEqualImplementation( assertion_traits<T>::toString(expected), + assertion_traits<T>::toString(actual), + lineNumber, + fileName ); + } + } + + void CPPUNIT_API assertEquals( double expected, + double actual, + double delta, + long lineNumber, + std::string fileName ); + +#else // using SourceLine + + template <class T> + void assertEquals( const T& expected, + const T& actual, + SourceLine sourceLine, + const std::string &message ="" ) + { + if ( !assertion_traits<T>::equal(expected,actual) ) // lazy toString conversion... + { + Asserter::failNotEqual( assertion_traits<T>::toString(expected), + assertion_traits<T>::toString(actual), + sourceLine, + message ); + } + } + + void CPPUNIT_API assertDoubleEquals( double expected, + double actual, + double delta, + SourceLine sourceLine ); + +#endif +} + +/* A set of macros which allow us to get the line number + * and file name at the point of an error. + * Just goes to show that preprocessors do have some + * redeeming qualities. + */ +#if CPPUNIT_HAVE_CPP_SOURCE_ANNOTATION +/** Assertions that a condition is \c true. + * \ingroup Assertions + */ + // LLA: due to the fact, that side effects are not wished, we create a local scope, + // assign the condition to a local variable and check this variable again and again. + +#define CPPUNIT_ASSERT(condition) \ + { bool __bLocalCondition = condition; \ + CheckBoom((__bLocalCondition), (#condition)); \ + (::CppUnit::Asserter::failIf( !(__bLocalCondition), \ + (#condition), \ + CPPUNIT_SOURCELINE() ) ); } +#else +#define CPPUNIT_ASSERT(condition) \ + { bool __bLocalCondition = condition; \ + CheckBoom((__bLocalCondition), ""); \ + (::CppUnit::Asserter::failIf( !(__bLocalCondition), \ + "", \ + CPPUNIT_SOURCELINE() ) ); } +#endif + +/** Assertion with a user specified message. + * \ingroup Assertions + * \param message Message reported in diagnostic if \a condition evaluates + * to \c false. + * \param condition If this condition evaluates to \c false then the + * test failed. + */ +#define CPPUNIT_ASSERT_MESSAGE(message,condition) \ + { bool __bLocalCondition = (condition); \ + CheckBoom((__bLocalCondition), (message)); \ + (::CppUnit::Asserter::failIf( !(__bLocalCondition), \ + (message), \ + CPPUNIT_SOURCELINE() ) ); } + +#define CPPUNIT_ASSERT_STUB() \ + CheckBoom((1 == 0), ("This is only a stub.")); \ + (::CppUnit::Asserter::failStub("This is only a stub.", \ + CPPUNIT_SOURCELINE() ) ) + + +/** Fails with the specified message. + * \ingroup Assertions + * \param message Message reported in diagnostic. + */ +#define CPPUNIT_FAIL( message ) \ + ( ::CppUnit::Asserter::fail( message, \ + CPPUNIT_SOURCELINE() ) ) + +#ifdef CPPUNIT_ENABLE_SOURCELINE_DEPRECATED +/// Generalized macro for primitive value comparisons +#define CPPUNIT_ASSERT_EQUAL(expected,actual) \ + ( ::CppUnit::TestAssert::assertEquals( (expected), \ + (actual), \ + __LINE__, __FILE__ ) ) +#else +/** Asserts that two values are equals. + * \ingroup Assertions + * + * Equality and string representation can be defined with + * an appropriate CppUnit::assertion_traits class. + * + * A diagnostic is printed if actual and expected values disagree. + * + * Requirement for \a expected and \a actual parameters: + * - They are exactly of the same type + * - They are serializable into a std::strstream using operator <<. + * - They can be compared using operator ==. + * + * The last two requirements (serialization and comparison) can be + * removed by specializing the CppUnit::assertion_traits. + */ +#define CPPUNIT_ASSERT_EQUAL(expected,actual) \ + ( ::CppUnit::TestAssert::assertEquals( (expected), \ + (actual), \ + CPPUNIT_SOURCELINE() ) ) + +/** Asserts that two values are equals, provides additional messafe on failure. + * \ingroup Assertions + * + * Equality and string representation can be defined with + * an appropriate assertion_traits class. + * + * A diagnostic is printed if actual and expected values disagree. + * The message is printed in addition to the expected and actual value + * to provide additional information. + * + * Requirement for \a expected and \a actual parameters: + * - They are exactly of the same type + * - They are serializable into a std::strstream using operator <<. + * - They can be compared using operator ==. + * + * The last two requirements (serialization and comparison) can be + * removed by specializing the CppUnit::assertion_traits. + */ +#define CPPUNIT_ASSERT_EQUAL_MESSAGE(message,expected,actual) \ + ( ::CppUnit::TestAssert::assertEquals( (expected), \ + (actual), \ + CPPUNIT_SOURCELINE(), \ + (message) ) ) +#endif + +/*! \brief Macro for primitive value comparisons + * \ingroup Assertions + */ +#define CPPUNIT_ASSERT_DOUBLES_EQUAL(expected,actual,delta) \ + ( ::CppUnit::TestAssert::assertDoubleEquals( (expected), \ + (actual), \ + (delta), \ + CPPUNIT_SOURCELINE() ) ) + +// Backwards compatibility + +#if CPPUNIT_ENABLE_NAKED_ASSERT + +#undef assert +#define assert(c) CPPUNIT_ASSERT(c) +#define assertEqual(e,a) CPPUNIT_ASSERT_EQUAL(e,a) +#define assertDoublesEqual(e,a,d) CPPUNIT_ASSERT_DOUBLES_EQUAL(e,a,d) +#define assertLongsEqual(e,a) CPPUNIT_ASSERT_EQUAL(e,a) + +#endif + +} // namespace CppUnit + +#endif // CPPUNIT_TESTASSERT_H diff --git a/cppunit/inc/cppunit/TestCaller.h b/cppunit/inc/cppunit/TestCaller.h new file mode 100644 index 000000000000..77c2743ca66f --- /dev/null +++ b/cppunit/inc/cppunit/TestCaller.h @@ -0,0 +1,204 @@ +#ifndef CPPUNIT_TESTCALLER_H // -*- C++ -*- +#define CPPUNIT_TESTCALLER_H + +#include <cppunit/Exception.h> +#include <cppunit/TestCase.h> + + +#if CPPUNIT_USE_TYPEINFO_NAME +# include <cppunit/extensions/TypeInfoHelper.h> +#endif + + +namespace CppUnit { + +/*! \brief Marker class indicating that no exception is expected by TestCaller. + * This class is an implementation detail. You should never use this class directly. + */ +class CPPUNIT_API NoExceptionExpected +{ +private: + //! Prevent class instantiation. + NoExceptionExpected(); +}; + + +/*! \brief (Implementation) Traits used by TestCaller to expect an exception. + * + * This class is an implementation detail. You should never use this class directly. + */ +template<typename ExceptionType> +struct ExpectedExceptionTraits +{ + static void expectedException() + { +#if CPPUNIT_USE_TYPEINFO_NAME + std::string message( "Expected exception of type " ); + message += TypeInfoHelper::getClassName( typeid( ExceptionType ) ); + message += ", but got none"; +#else + std::string message( "Expected exception but got none" ); +#endif + throw Exception( message ); + } +}; + + +/*! \brief (Implementation) Traits specialization used by TestCaller to + * expect no exception. + * + * This class is an implementation detail. You should never use this class directly. + */ +template<> +struct ExpectedExceptionTraits<NoExceptionExpected> +{ + static void expectedException() + { + } +}; + + + +//*** FIXME: rework this when class Fixture is implemented. ***// + + +/*! \brief Generate a test case from a fixture method. + * \ingroup WritingTestFixture + * + * A test caller provides access to a test case method + * on a test fixture class. Test callers are useful when + * you want to run an individual test or add it to a + * suite. + * Test Callers invoke only one Test (i.e. test method) on one + * Fixture of a TestFixture. + * + * Here is an example: + * \code + * class MathTest : public CppUnit::TestFixture { + * ... + * public: + * void setUp(); + * void tearDown(); + * + * void testAdd(); + * void testSubtract(); + * }; + * + * CppUnit::Test *MathTest::suite() { + * CppUnit::TestSuite *suite = new CppUnit::TestSuite; + * + * suite->addTest( new CppUnit::TestCaller<MathTest>( "testAdd", testAdd ) ); + * return suite; + * } + * \endcode + * + * You can use a TestCaller to bind any test method on a TestFixture + * class, as long as it accepts void and returns void. + * + * \see TestCase + */ + +template <typename Fixture, + typename ExpectedException = NoExceptionExpected> +class TestCaller : public TestCase +{ + typedef void (Fixture::*TestMethod)(); + +public: + /*! + * Constructor for TestCaller. This constructor builds a new Fixture + * instance owned by the TestCaller. + * \param name name of this TestCaller + * \param test the method this TestCaller calls in runTest() + */ + TestCaller( std::string const& name, TestMethod test ) : + TestCase( name ), + m_ownFixture( true ), + m_fixture( new Fixture() ), + m_test( test ) + { + } + + /*! + * Constructor for TestCaller. + * This constructor does not create a new Fixture instance but accepts + * an existing one as parameter. The TestCaller will not own the + * Fixture object. + * \param name name of this TestCaller + * \param test the method this TestCaller calls in runTest() + * \param fixture the Fixture to invoke the test method on. + */ + TestCaller(std::string const& name, TestMethod test, Fixture& fixture) : + TestCase( name ), + m_ownFixture( false ), + m_fixture( &fixture ), + m_test( test ) + { + } + + /*! + * Constructor for TestCaller. + * This constructor does not create a new Fixture instance but accepts + * an existing one as parameter. The TestCaller will own the + * Fixture object and delete it in its destructor. + * \param name name of this TestCaller + * \param test the method this TestCaller calls in runTest() + * \param fixture the Fixture to invoke the test method on. + */ + TestCaller(std::string const& name, TestMethod test, Fixture* fixture) : + TestCase( name ), + m_ownFixture( true ), + m_fixture( fixture ), + m_test( test ) + { + } + + ~TestCaller() + { + if (m_ownFixture) + delete m_fixture; + } + +protected: + void runTest() + { + try { + (m_fixture->*m_test)(); + } + catch ( ExpectedException & ) { + return; + } + + ExpectedExceptionTraits<ExpectedException>::expectedException(); + } + + void setUp() + { + m_fixture->setUp (); + } + + void tearDown() + { + m_fixture->tearDown (); + } + + std::string toString() const + { + return "TestCaller " + getName(); + } + +private: + TestCaller( const TestCaller &other ); + TestCaller &operator =( const TestCaller &other ); + +private: + bool m_ownFixture; + Fixture *m_fixture; + TestMethod m_test; +}; + + + +} // namespace CppUnit + +#endif // CPPUNIT_TESTCALLER_H diff --git a/cppunit/inc/cppunit/TestCase.h b/cppunit/inc/cppunit/TestCase.h new file mode 100644 index 000000000000..0653c07d7f24 --- /dev/null +++ b/cppunit/inc/cppunit/TestCase.h @@ -0,0 +1,59 @@ +#ifndef CPPUNIT_TESTCASE_H +#define CPPUNIT_TESTCASE_H + +#include <cppunit/Portability.h> +#include <cppunit/Test.h> +#include <cppunit/TestFixture.h> +#include <string> +#include <cppunit/autoregister/htestresult.h> + +namespace CppUnit { + +//# class TestResult; + +/*! \brief A single test object. + * + * This class is used to implement a simple test case: define a subclass + * that overrides the runTest method. + * + * You don't usually need to use that class, but TestFixture and TestCaller instead. + * + * You are expected to subclass TestCase is you need to write a class similiar + * to TestCaller. + */ +class CPPUNIT_API TestCase : public Test, + public TestFixture +{ +public: + + TestCase( std::string const& Name ); + //! \internal + TestCase(); + ~TestCase(); + + virtual void run(hTestResult pResult); + virtual int countTestCases() const; + std::string getName() const; + std::string toString() const; + + //! FIXME: what is this for? + //# virtual TestResult *run(); + +protected: + //! FIXME: this should probably be pure virtual. + virtual void runTest(); + + //! Create TestResult for the run(void) method. + //# TestResult *defaultResult(); + +private: + TestCase( const TestCase &other ); + TestCase &operator=( const TestCase &other ); + +private: + const std::string m_name; +}; + +} // namespace CppUnit + +#endif // CPPUNIT_TESTCASE_H diff --git a/cppunit/inc/cppunit/TestFailure.h b/cppunit/inc/cppunit/TestFailure.h new file mode 100644 index 000000000000..d8648177d57c --- /dev/null +++ b/cppunit/inc/cppunit/TestFailure.h @@ -0,0 +1,71 @@ +#ifndef CPPUNIT_TESTFAILURE_H // -*- C++ -*- +#define CPPUNIT_TESTFAILURE_H + +#include <cppunit/Portability.h> +#include <string> + +namespace ErrorType +{ + enum num + { + ET_FAILURE = 1, + ET_ERROR = 2, + ET_SIGNAL = 4 + }; +} + +namespace CppUnit { + +class Exception; +class SourceLine; +class Test; + + +/*! \brief Record of a failed Test execution. + * \ingroup BrowsingCollectedTestResult + * + * A TestFailure collects a failed test together with + * the caught exception. + * + * TestFailure assumes lifetime control for any exception + * passed to it. + */ + +class CPPUNIT_API TestFailure +{ +public: + TestFailure( Test *failedTest, + Exception *thrownException, + ErrorType::num eError ); + + virtual ~TestFailure (); + + virtual Test *failedTest() const; + + virtual Exception *thrownException() const; + + virtual SourceLine sourceLine() const; + + virtual bool isError() const; + virtual ErrorType::num getErrorType() const; + + virtual std::string failedTestName() const; + + virtual std::string toString() const; + + virtual TestFailure *clone() const; + +protected: + Test *m_failedTest; + Exception *m_thrownException; + ErrorType::num m_eError; + +private: + TestFailure( const TestFailure &other ); + TestFailure &operator =( const TestFailure& other ); +}; + + +} // namespace CppUnit + +#endif // CPPUNIT_TESTFAILURE_H diff --git a/cppunit/inc/cppunit/TestFixture.h b/cppunit/inc/cppunit/TestFixture.h new file mode 100644 index 000000000000..edb8320f90c8 --- /dev/null +++ b/cppunit/inc/cppunit/TestFixture.h @@ -0,0 +1,93 @@ +#ifndef CPPUNIT_TESTFIXTURE_H // -*- C++ -*- +#define CPPUNIT_TESTFIXTURE_H + +#include <cppunit/Portability.h> + +namespace CppUnit { + + +/*! \brief Wraps a test case with setUp and tearDown methods. + * \ingroup WritingTestFixture + * + * A TestFixture is used to provide a common environment for a set + * of test cases. + * + * To define a test fixture, do the following: + * - implement a subclass of TestCase + * - the fixture is defined by instance variables + * - initialize the fixture state by overriding setUp + * (i.e. construct the instance variables of the fixture) + * - clean-up after a test by overriding tearDown. + * + * Each test runs in its own fixture so there + * can be no side effects among test runs. + * Here is an example: + * + * \code + * class MathTest : public CppUnit::TestFixture { + * protected: + * int m_value1, m_value2; + * + * public: + * MathTest() {} + * + * void setUp () { + * m_value1 = 2; + * m_value2 = 3; + * } + * } + * \endcode + * + * For each test implement a method which interacts + * with the fixture. Verify the expected results with assertions specified + * by calling CPPUNIT_ASSERT on the expression you want to test: + * + * \code + * public: + * void testAdd () { + * int result = m_value1 + m_value2; + * CPPUNIT_ASSERT( result == 5 ); + * } + * \endcode + * + * Once the methods are defined you can run them. To do this, use + * a TestCaller. + * + * \code + * CppUnit::Test *test = new CppUnit::TestCaller<MathTest>( "testAdd", + * &MathTest::testAdd ); + * test->run(); + * \endcode + * + * + * The tests to be run can be collected into a TestSuite. + * + * \code + * public: + * static CppUnit::TestSuite *MathTest::suite () { + * CppUnit::TestSuite *suiteOfTests = new CppUnit::TestSuite; + * suiteOfTests->addTest(new CppUnit::TestCaller<MathTest>( + * "testAdd", &MathTest::testAdd)); + * suiteOfTests->addTest(new CppUnit::TestCaller<MathTest>( + * "testDivideByZero", &MathTest::testDivideByZero)); + * return suiteOfTests; + * } + * \endcode + * + */ +class CPPUNIT_API TestFixture +{ +public: + virtual ~TestFixture() {}; + + //! \brief Set up context before running a test. + virtual void setUp() {}; + + //! Clean up after the test run. + virtual void tearDown() {}; +}; + + +} + +#endif diff --git a/cppunit/inc/cppunit/TestSuite.h b/cppunit/inc/cppunit/TestSuite.h new file mode 100644 index 000000000000..1a97e94c42b7 --- /dev/null +++ b/cppunit/inc/cppunit/TestSuite.h @@ -0,0 +1,81 @@ +#ifndef CPPUNIT_TESTSUITE_H // -*- C++ -*- +#define CPPUNIT_TESTSUITE_H + +#include <cppunit/Portability.h> + +#if CPPUNIT_NEED_DLL_DECL +#ifdef _MSC_VER +#pragma warning( push ) +#pragma warning( disable: 4251 ) // X needs to have dll-interface to be used by clients of class Z +#endif +#endif + +#include <cppunit/Test.h> +#include <vector> +#include <string> +#include <cppunit/autoregister/htestresult.h> + +namespace CppUnit { + +//# class TestResult; + +#if CPPUNIT_NEED_DLL_DECL + template class CPPUNIT_API std::vector<Test *>; +#endif + + +/*! \brief A Composite of Tests. + * \ingroup CreatingTestSuite + * + * It runs a collection of test cases. Here is an example. + * \code + * CppUnit::TestSuite *suite= new CppUnit::TestSuite(); + * suite->addTest(new CppUnit::TestCaller<MathTest> ( + * "testAdd", testAdd)); + * suite->addTest(new CppUnit::TestCaller<MathTest> ( + * "testDivideByZero", testDivideByZero)); + * \endcode + * Note that TestSuites assume lifetime + * control for any tests added to them. + * + * \see Test + * \see TestCaller + */ + + +class CPPUNIT_API TestSuite : public Test +{ +public: + TestSuite( std::string const& name = "" ); + ~TestSuite(); + + void run( hTestResult pResult ); + int countTestCases() const; + std::string getName() const; + std::string toString() const; + + void addTest( Test *test ); + const std::vector<Test *> &getTests() const; + + virtual void deleteContents(); + +private: + TestSuite( const TestSuite &other ); + TestSuite &operator =( const TestSuite &other ); + +private: + std::vector<Test *> m_tests; + const std::string m_name; +}; + + +} // namespace CppUnit + + +#if CPPUNIT_NEED_DLL_DECL +#ifdef _MSC_VER +#pragma warning( pop ) +#endif +#endif + +#endif // CPPUNIT_TESTSUITE_H diff --git a/cppunit/inc/cppunit/additionalfunc.hxx b/cppunit/inc/cppunit/additionalfunc.hxx new file mode 100644 index 000000000000..f34137936c6f --- /dev/null +++ b/cppunit/inc/cppunit/additionalfunc.hxx @@ -0,0 +1,65 @@ +#ifndef ADDITIONALFUNC_HXX +#define ADDITIONALFUNC_HXX + +#ifndef _registertestfunction_h +#include "cppunit/autoregister/registertestfunction.h" +#endif +#ifndef _SAL_TYPES_H_ +#include "sal/types.h" +#endif + +extern "C" void SAL_CALL RegisterAdditionalFunctions(FktRegFuncPtr _pFunc); + +#define NOADDITIONAL \ +void RegisterAdditionalFunctions(FktRegFuncPtr){} + +namespace { + +enum T2_OSType { + T2_OS_WNT32 = 1, + T2_OS_UNIX, + T2_OS_OS2 +}; + +inline T2_OSType getOSType() +{ +#if defined WNT + return T2_OS_WNT32; +#elif defined OS2 + return T2_OS_OS2; +#else + return T2_OS_UNIX; +#endif +} + +} + +#define TESTSHL2_UNO_BOOTSTRAP(file) \ +void RegisterAdditionalFunctions(FktRegFuncPtr _pFunc) \ +{ \ + com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory> xMS; \ + com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext > xComponentContext; \ + try { \ + if (strlen(#file) > 0) { \ + ::rtl::OUString iniFile(rtl::OUString::createFromAscii(#file)); \ + if (getOSType() == T2_OS_WNT32 || getOSType() == T2_OS_OS2) { \ + iniFile += ::rtl::OUString::createFromAscii(".ini"); \ + } else { \ + iniFile += ::rtl::OUString::createFromAscii("rc"); \ + } \ + xComponentContext = cppu::defaultBootstrap_InitialComponentContext(iniFile); \ + } else { \ + xComponentContext = cppu::defaultBootstrap_InitialComponentContext(); \ + } \ + xMS.set(xComponentContext->getServiceManager(), com::sun::star::uno::UNO_QUERY); \ + comphelper::setProcessServiceFactory(xMS); \ + } \ + catch (::com::sun::star::uno::Exception e ) { \ + rtl::OString aError; \ + aError = rtl::OUStringToOString(e.Message, RTL_TEXTENCODING_ASCII_US); \ + printf("Error at UNO bootstrap time caught: %s\nMust quit.\n", aError.getStr()); \ + exit(1); \ + } \ +} + +#endif diff --git a/cppunit/inc/cppunit/autoregister/callbackfunc_fktptr.h b/cppunit/inc/cppunit/autoregister/callbackfunc_fktptr.h new file mode 100644 index 000000000000..1ba46c0de1d1 --- /dev/null +++ b/cppunit/inc/cppunit/autoregister/callbackfunc_fktptr.h @@ -0,0 +1,68 @@ +/************************************************************************* + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: callbackfunc_fktptr.h,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: lla $ $Date: 2008-02-27 16:18:28 $ + * + * The Contents of this file are made available subject to + * the terms of GNU Lesser General Public License Version 2.1. + * + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2005 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + ************************************************************************/ + +#ifndef _callbackfunc_fktptr_h +#define _callbackfunc_fktptr_h + +#include <sal/types.h> + +#ifdef __cplusplus +extern "C" { +#endif + +// these typedefs are used for the TestCase, to call the TestResult functions. +// The TestResult is only in the testshl tool, not in the test libraries. + +typedef void* hTest; +typedef void* hException; + +typedef sal_Int32 (* FktPtr_CallbackDispatch)(int x, ...); + +//# typedef void (* FktPtr_TestResult_startTest)(hTestResult, hTest ); +//# typedef void (* FktPtr_TestResult_addFailure)( hTestResult, hTest , hException pException ); +//# typedef void (* FktPtr_TestResult_addError)( hTestResult, hTest , hException pException ); +//# typedef void (* FktPtr_TestResult_endTest)( hTestResult, hTest ); +//# typedef bool (* FktPtr_TestResult_shouldStop)(hTestResult); +//# +//# // Additional functions +//# typedef void (* FktPtr_TestResult_addInfo)( hTestResult, hTest, const char* ); +//# typedef void (* FktPtr_TestResult_enterNode)( hTestResult, const char* ); +//# typedef void (* FktPtr_TestResult_leaveNode)( hTestResult, const char* ); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/cppunit/inc/cppunit/autoregister/callbackstructure.h b/cppunit/inc/cppunit/autoregister/callbackstructure.h new file mode 100644 index 000000000000..5106e2b18012 --- /dev/null +++ b/cppunit/inc/cppunit/autoregister/callbackstructure.h @@ -0,0 +1,94 @@ +/************************************************************************* + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: callbackstructure.h,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: lla $ $Date: 2008-02-27 16:18:40 $ + * + * The Contents of this file are made available subject to + * the terms of GNU Lesser General Public License Version 2.1. + * + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2005 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + ************************************************************************/ + +#ifndef _callbackstructure_h +#define _callbackstructure_h + +#include <sal/types.h> +#include <cppunit/autoregister/callbackfunc_fktptr.h> +#include <cppunit/autoregister/registerfunc.h> +#include <cppunit/autoregister/registertestfunction.h> +#include <cppunit/cmdlinebits.hxx> + +// this structure will filled by the testshl tool and hand to the testdll + +struct CallbackStructure +{ + // a version number, if we want to change/expand this struct + sal_Int32 nVersion; + sal_Int64 nMagic; + + FktRegFuncPtr aRegisterFunction; + + FktPtr_CallbackDispatch aCallbackDispatch; + + //# FktPtr_TestResult_startTest aStartTest; + //# FktPtr_TestResult_addFailure aAddFailure; + //# FktPtr_TestResult_addError aAddError; + //# FktPtr_TestResult_endTest aEndTest; + //# FktPtr_TestResult_shouldStop aShouldStop; + //# + //# FktPtr_TestResult_addInfo aAddInfo; + //# FktPtr_TestResult_enterNode aEnterNode; + //# FktPtr_TestResult_leaveNode aLeaveNode; + + const char* psForward; + CmdLineBits nBits; + + // void* pJobList; + + sal_Int64 nMagic2; + + CallbackStructure() + :nVersion(1), + nMagic(SAL_CONST_INT64(0x0123456789abcdef)), + aRegisterFunction(NULL), + aCallbackDispatch(NULL), + /* aStartTest(NULL), + aAddFailure(NULL), + aAddError(NULL), + aEndTest(NULL), + aShouldStop(NULL), + aAddInfo(NULL), + aEnterNode(NULL), + aLeaveNode(NULL), */ + psForward(NULL), + nBits(0), + /* pJobList(NULL), */ + nMagic2(0) + {} +}; + +#endif diff --git a/cppunit/inc/cppunit/autoregister/htestresult.h b/cppunit/inc/cppunit/autoregister/htestresult.h new file mode 100644 index 000000000000..46cfbc8b6808 --- /dev/null +++ b/cppunit/inc/cppunit/autoregister/htestresult.h @@ -0,0 +1,6 @@ +#ifndef _htestresult_h +#define _htestresult_h + +typedef void* hTestResult; + +#endif diff --git a/cppunit/inc/cppunit/autoregister/registerfunc.h b/cppunit/inc/cppunit/autoregister/registerfunc.h new file mode 100644 index 000000000000..c88c14fc9d75 --- /dev/null +++ b/cppunit/inc/cppunit/autoregister/registerfunc.h @@ -0,0 +1,55 @@ +/************************************************************************* + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: registerfunc.h,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: lla $ $Date: 2008-02-27 16:18:16 $ + * + * The Contents of this file are made available subject to + * the terms of GNU Lesser General Public License Version 2.1. + * + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2005 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + ************************************************************************/ + +#ifndef _registerfunc_h +#define _registerfunc_h + +#include <sal/types.h> +#include <cppunit/autoregister/htestresult.h> +#include <cppunit/autoregister/callbackfunc_fktptr.h> +#include <cppunit/autoregister/testfunc.h> + +struct CallbackStructure; + +// this function is used to register one function into a Container in the testshl tool. +extern "C" void SAL_CALL registerFunction(FktPtr aFunc, const char* aFuncName); + +// this function is the register function for auto registering + +extern "C" void SAL_CALL registerAllTestFunction(CallbackStructure* ); +typedef void (* FktRegAllPtr)(CallbackStructure*); + + +#endif diff --git a/cppunit/inc/cppunit/autoregister/registertestfunction.h b/cppunit/inc/cppunit/autoregister/registertestfunction.h new file mode 100644 index 000000000000..5ca6b1fcc825 --- /dev/null +++ b/cppunit/inc/cppunit/autoregister/registertestfunction.h @@ -0,0 +1,59 @@ +/************************************************************************* + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: registertestfunction.h,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: lla $ $Date: 2008-02-27 16:18:04 $ + * + * The Contents of this file are made available subject to + * the terms of GNU Lesser General Public License Version 2.1. + * + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2005 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + ************************************************************************/ + +#ifndef _registertestfunction_h +#define _registertestfunction_h + +#include <sal/types.h> +#include <cppunit/autoregister/testfunc.h> + +#ifdef __cplusplus +extern "C" { +#endif + +// function ptr, to register a function +typedef void (* FktRegFuncPtr)(FktPtr aFunc, const char* aFuncName); + +// this function is used in the testdll to register the given function +// into the testshl +extern "C" void SAL_CALL RegisterTestFunctions(FktRegFuncPtr aFunc); + +#ifdef __cplusplus +} +#endif + +#endif + + diff --git a/cppunit/inc/cppunit/autoregister/testfunc.h b/cppunit/inc/cppunit/autoregister/testfunc.h new file mode 100644 index 000000000000..4eb0d6a3cac0 --- /dev/null +++ b/cppunit/inc/cppunit/autoregister/testfunc.h @@ -0,0 +1,52 @@ +/************************************************************************* + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: testfunc.h,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: lla $ $Date: 2008-02-27 16:17:52 $ + * + * The Contents of this file are made available subject to + * the terms of GNU Lesser General Public License Version 2.1. + * + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2005 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + ************************************************************************/ + +#ifndef _testfunc_h +#define _testfunc_h + +#include <cppunit/autoregister/htestresult.h> + +#ifdef __cplusplus +extern "C" { +#endif + +// typedef for a testfunction +typedef void (* FktPtr)(hTestResult); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/cppunit/inc/cppunit/checkboom.hxx b/cppunit/inc/cppunit/checkboom.hxx new file mode 100644 index 000000000000..e175da2545ef --- /dev/null +++ b/cppunit/inc/cppunit/checkboom.hxx @@ -0,0 +1,45 @@ +/************************************************************************* + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: checkboom.hxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: lla $ $Date: 2008-02-27 16:10:49 $ + * + * The Contents of this file are made available subject to + * the terms of GNU Lesser General Public License Version 2.1. + * + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2005 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + ************************************************************************/ + +#ifndef CHECKBOOM_HXX +#define CHECKBOOM_HXX + +#include <string> +#include <rtl/ustring.hxx> + +void CheckBoom(bool bCondition, std::string const& msg); +void CheckBoom(bool bCondition, rtl::OUString const& msg); + +#endif diff --git a/cppunit/inc/cppunit/cmdlinebits.hxx b/cppunit/inc/cppunit/cmdlinebits.hxx new file mode 100644 index 000000000000..058f6bfe3df5 --- /dev/null +++ b/cppunit/inc/cppunit/cmdlinebits.hxx @@ -0,0 +1,57 @@ +/************************************************************************* + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: cmdlinebits.hxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: lla $ $Date: 2008-02-27 16:11:49 $ + * + * The Contents of this file are made available subject to + * the terms of GNU Lesser General Public License Version 2.1. + * + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2005 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + ************************************************************************/ + +#ifndef CMDLINEBITS_HXX +#define CMDLINEBITS_HXX + +#include <sal/types.h> + +typedef sal_uInt32 CmdLineBits; +const char* getForwardString(); + +#include <stdarg.h> + +enum T_Print_Params { + T_INFO = 1, + T_VERBOSE, + T_DEBUG, + T_ERROR +}; + +// void t_print(const char*); +void t_print(const char*, ...); +void t_print(T_Print_Params, const char*, ...); + +#endif diff --git a/cppunit/inc/cppunit/extensions/AutoRegisterSuite.h b/cppunit/inc/cppunit/extensions/AutoRegisterSuite.h new file mode 100644 index 000000000000..a2138ca8f90e --- /dev/null +++ b/cppunit/inc/cppunit/extensions/AutoRegisterSuite.h @@ -0,0 +1,53 @@ +#ifndef CPPUNIT_EXTENSIONS_AUTOREGISTERSUITE_H +#define CPPUNIT_EXTENSIONS_AUTOREGISTERSUITE_H + +#include <stdio.h> +#include <string> +#include <cppunit/extensions/TestSuiteFactory.h> +#include <cppunit/extensions/TestFactoryRegistry.h> + +namespace CppUnit { + + /** Automatically register the test suite of the specified type. + * + * You should not use this class directly. Instead, use the following macros: + * - CPPUNIT_TEST_SUITE_REGISTRATION() + * - CPPUNIT_TEST_SUITE_NAMED_REGISTRATION() + * + * This object will register the test returned by TestCaseType::suite() + * when constructed to the test registry. + * + * This object is intented to be used as a static variable. + * + * + * \param TestCaseType Type of the test case which suite is registered. + * \see CPPUNIT_TEST_SUITE_REGISTRATION, CPPUNIT_TEST_SUITE_NAMED_REGISTRATION + * \see CppUnit::TestFactoryRegistry. + */ + template<typename TestCaseType> + class AutoRegisterSuite + { + public: + /** Auto-register the suite factory in the global registry. + */ + AutoRegisterSuite() + { + TestFactory *factory = new TestSuiteFactory<TestCaseType>(); + TestFactoryRegistry::getRegistry().registerFactory( factory ); + } + + /** Auto-register the suite factory in the specified registry. + * \param name Name of the registry. + */ + AutoRegisterSuite( const std::string &name ) + { + // printf("AutoRegisterSuite %s\n", name.c_str()); + TestFactory *factory = new TestSuiteFactory<TestCaseType>(); + TestFactoryRegistry::getRegistry( name ).registerFactory( factory ); + } + }; + +} // namespace CppUnit + + +#endif // CPPUNIT_EXTENSIONS_AUTOREGISTERSUITE_H diff --git a/cppunit/inc/cppunit/extensions/HelperMacros.h b/cppunit/inc/cppunit/extensions/HelperMacros.h new file mode 100644 index 000000000000..79eb63e80ab7 --- /dev/null +++ b/cppunit/inc/cppunit/extensions/HelperMacros.h @@ -0,0 +1,333 @@ +// ////////////////////////////////////////////////////////////////////////// +// Header file HelperMacros.h +// (c)Copyright 2000, Baptiste Lepilleur. +// Created: 2001/04/15 +// ////////////////////////////////////////////////////////////////////////// +#ifndef CPPUNIT_EXTENSIONS_HELPERMACROS_H +#define CPPUNIT_EXTENSIONS_HELPERMACROS_H + +#include <cppunit/Portability.h> +#include <cppunit/extensions/AutoRegisterSuite.h> +#include <cppunit/extensions/TestSuiteBuilder.h> +#include <string> + +namespace CppUnit +{ + class TestFixture; + + /*! \brief Abstract TestFixture factory. + */ + class TestFixtureFactory + { + public: + //! Creates a new TestFixture instance. + virtual CppUnit::TestFixture *makeFixture() =0; + }; +} // namespace CppUnit + + +// The macro __CPPUNIT_SUITE_CTOR_ARGS expand to an expression used to construct +// the TestSuiteBuilder with macro CPPUNIT_TEST_SUITE. +// +// The name of the suite is obtained using RTTI if CPPUNIT_USE_TYPEINFO_NAME +// is defined, otherwise it is extracted from the macro parameter +// +// This macro is for cppunit internal and should not be use otherwise. +#if CPPUNIT_USE_TYPEINFO_NAME +# define __CPPUNIT_SUITE_CTOR_ARGS( ATestFixtureType ) +#else +# define __CPPUNIT_SUITE_CTOR_ARGS( ATestFixtureType ) (std::string(#ATestFixtureType)) +#endif + + +/*! \addtogroup WritingTestFixture Writing test fixture + */ +/** @{ + */ + + +/** \file + * Macros intended to ease the definition of test suites. + * + * The macros + * CPPUNIT_TEST_SUITE(), CPPUNIT_TEST(), and CPPUNIT_TEST_SUITE_END() + * are designed to facilitate easy creation of a test suite. + * For example, + * + * \code + * #include <cppunit/extensions/HelperMacros.h> + * class MyTest : public CppUnit::TestFixture { + * CPPUNIT_TEST_SUITE( MyTest ); + * CPPUNIT_TEST( testEquality ); + * CPPUNIT_TEST( testSetName ); + * CPPUNIT_TEST_SUITE_END(); + * public: + * void testEquality(); + * void testSetName(); + * }; + * \endcode + * + * The effect of these macros is to define two methods in the + * class MyTest. The first method is an auxiliary function + * named registerTests that you will not need to call directly. + * The second function + * \code static CppUnit::TestSuite *suite()\endcode + * returns a pointer to the suite of tests defined by the CPPUNIT_TEST() + * macros. + * + * Rather than invoking suite() directly, + * the macro CPPUNIT_TEST_SUITE_REGISTRATION() is + * used to create a static variable that automatically + * registers its test suite in a global registry. + * The registry yields a Test instance containing all the + * registered suites. + * \code + * CPPUNIT_TEST_SUITE_REGISTRATION( MyTest ); + * CppUnit::Test* tp = + * CppUnit::TestFactoryRegistry::getRegistry().makeTest(); + * \endcode + * + * The test suite macros can even be used with templated test classes. + * For example: + * + * \code + * template<typename CharType> + * class StringTest : public CppUnit::TestFixture { + * CPPUNIT_TEST_SUITE( StringTest ); + * CPPUNIT_TEST( testAppend ); + * CPPUNIT_TEST_SUITE_END(); + * public: + * ... + * }; + * \endcode + * + * You need to add in an implementation file: + * + * \code + * CPPUNIT_TEST_SUITE_REGISTRATION( StringTest<char> ); + * CPPUNIT_TEST_SUITE_REGISTRATION( StringTest<wchar_t> ); + * \endcode + */ + + +/*! \brief Begin test suite + * + * This macro starts the declaration of a new test suite. + * Use CPPUNIT_TEST_SUB_SUITE() instead, if you wish to include the + * test suite of the parent class. + * + * \param ATestFixtureType Type of the test case class. This type \b MUST + * be derived from TestFixture. + * \see CPPUNIT_TEST_SUB_SUITE, CPPUNIT_TEST, CPPUNIT_TEST_SUITE_END, + * \see CPPUNIT_TEST_SUITE_REGISTRATION, CPPUNIT_TEST_EXCEPTION, CPPUNIT_TEST_FAIL. + */ +#define CPPUNIT_TEST_SUITE( ATestFixtureType ) \ + private: \ + typedef ATestFixtureType __ThisTestFixtureType; \ + class ThisTestFixtureFactory : public CppUnit::TestFixtureFactory \ + { \ + virtual CppUnit::TestFixture *makeFixture() \ + { \ + return new ATestFixtureType(); \ + } \ + }; \ + public: \ + static CppUnit::TestSuite *suite() \ + { \ + CppUnit::TestSuiteBuilder<__ThisTestFixtureType> \ + builder __CPPUNIT_SUITE_CTOR_ARGS( ATestFixtureType ); \ + ThisTestFixtureFactory factory; \ + __ThisTestFixtureType::registerTests( builder.suite(), &factory ); \ + return builder.takeSuite(); \ + } \ + static void \ + registerTests( CppUnit::TestSuite *suite, \ + CppUnit::TestFixtureFactory *factory ) \ + { \ + CppUnit::TestSuiteBuilder<__ThisTestFixtureType> builder( suite ); + + +/*! \brief Begin test suite (includes parent suite) + * + * This macro may only be used in a class whose parent class + * defines a test suite using CPPUNIT_TEST_SUITE() or CPPUNIT_TEST_SUB_SUITE(). + * + * This macro begins the declaration of a test suite, in the same + * manner as CPPUNIT_TEST_SUITE(). In addition, the test suite of the + * parent is automatically inserted in the test suite being + * defined. + * + * Here is an example: + * + * \code + * #include <cppunit/extensions/HelperMacros.h> + * class MySubTest : public MyTest { + * CPPUNIT_TEST_SUB_SUITE( MySubTest, MyTest ); + * CPPUNIT_TEST( testAdd ); + * CPPUNIT_TEST( testSub ); + * CPPUNIT_TEST_SUITE_END(); + * public: + * void testAdd(); + * void testSub(); + * }; + * \endcode + * + * \param ATestFixtureType Type of the test case class. This type \b MUST + * be derived from TestFixture. + * \param ASuperClass Type of the parent class. + * \see CPPUNIT_TEST_SUITE. + */ +#define CPPUNIT_TEST_SUB_SUITE( ATestFixtureType, ASuperClass ) \ + private: \ + typedef ASuperClass __ThisSuperClassType; \ + CPPUNIT_TEST_SUITE( ATestFixtureType ); \ + __ThisSuperClassType::registerTests( suite, factory ) + + +/*! \brief Add a method to the suite. + * \param testMethod Name of the method of the test case to add to the + * suite. The signature of the method must be of + * type: void testMethod(); + * \see CPPUNIT_TEST_SUITE. + */ +#define CPPUNIT_TEST( testMethod ) \ + builder.addTestCaller( #testMethod, \ + &__ThisTestFixtureType::testMethod , \ + (__ThisTestFixtureType*)factory->makeFixture() ) + + +/*! \brief Add a test which fail if the specified exception is not caught. + * + * Example: + * \code + * #include <cppunit/extensions/HelperMacros.h> + * #include <vector> + * class MyTest : public CppUnit::TestFixture { + * CPPUNIT_TEST_SUITE( MyTest ); + * CPPUNIT_TEST_EXCEPTION( testVectorAtThrow, std::invalid_argument ); + * CPPUNIT_TEST_SUITE_END(); + * public: + * void testVectorAtThrow() + * { + * std::vector<int> v; + * v.at( 1 ); // must throw exception std::invalid_argument + * } + * }; + * \endcode + * + * \param testMethod Name of the method of the test case to add to the suite. + * \param ExceptionType Type of the exception that must be thrown by the test + * method. + */ +#define CPPUNIT_TEST_EXCEPTION( testMethod, ExceptionType ) \ + builder.addTestCallerForException( #testMethod, \ + &__ThisTestFixtureType::testMethod , \ + (__ThisTestFixtureType*)factory->makeFixture(), \ + (ExceptionType *)NULL ); + +/*! \brief Adds a test case which is excepted to fail. + * + * The added test case expect an assertion to fail. You usually used that type + * of test case when testing custom assertion macros. + * + * \code + * CPPUNIT_TEST_FAIL( testAssertFalseFail ); + * + * void testAssertFalseFail() + * { + * CPPUNIT_ASSERT( false ); + * } + * \endcode + * \see CreatingNewAssertions. + */ +#define CPPUNIT_TEST_FAIL( testMethod ) \ + CPPUNIT_TEST_EXCEPTION( testMethod, CppUnit::Exception ) + +/*! \brief End declaration of the test suite. + * + * After this macro, member access is set to "private". + * + * \see CPPUNIT_TEST_SUITE. + * \see CPPUNIT_TEST_SUITE_REGISTRATION. + */ +#define CPPUNIT_TEST_SUITE_END() \ + builder.takeSuite(); \ + } \ + private: /* dummy typedef so that the macro can still end with ';'*/ \ + typedef ThisTestFixtureFactory __ThisTestFixtureFactory + +/** @} + */ + +#define __CPPUNIT_CONCATENATE_DIRECT( s1, s2 ) s1##s2 +#define __CPPUNIT_CONCATENATE( s1, s2 ) __CPPUNIT_CONCATENATE_DIRECT( s1, s2 ) + +/** Decorates the specified string with the line number to obtain a unique name; + * @param str String to decorate. + */ +#define __CPPUNIT_MAKE_UNIQUE_NAME( str ) __CPPUNIT_CONCATENATE( str, __LINE__ ) + + +/** Adds the specified fixture suite to the unnamed registry. + * \ingroup CreatingTestSuite + * + * This macro declares a static variable whose construction + * causes a test suite factory to be inserted in a global registry + * of such factories. The registry is available by calling + * the static function CppUnit::TestFactoryRegistry::getRegistry(). + * + * \param ATestFixtureType Type of the test case class. + * \warning This macro should be used only once per line of code (the line + * number is used to name a hidden static variable). + * \see CPPUNIT_TEST_SUITE_NAMED_REGISTRATION + * \see CPPUNIT_TEST_SUITE, CppUnit::AutoRegisterSuite, + * CppUnit::TestFactoryRegistry. + */ + +/* LLA: + #define CPPUNIT_TEST_SUITE_REGISTRATION( ATestFixtureType ) \ + static CppUnit::AutoRegisterSuite< ATestFixtureType > \ + __CPPUNIT_MAKE_UNIQUE_NAME(__autoRegisterSuite ) +*/ + +/** Adds the specified fixture suite to the specified registry suite. + * \ingroup CreatingTestSuite + * + * This macro declares a static variable whose construction + * causes a test suite factory to be inserted in the global registry + * suite of the specified name. The registry is available by calling + * the static function CppUnit::TestFactoryRegistry::getRegistry(). + * + * For the suite name, use a string returned by a static function rather + * than a hardcoded string. That way, you can know what are the name of + * named registry and you don't risk mistyping the registry name. + * + * \code + * // MySuites.h + * namespace MySuites { + * std::string math() { + * return "Math"; + * } + * } + * + * // ComplexNumberTest.cpp + * #include "MySuites.h" + * + * CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( ComplexNumberTest, MySuites::math() ); + * \endcode + * + * \param ATestFixtureType Type of the test case class. + * \param suiteName Name of the global registry suite the test suite is + * registered into. + * \warning This macro should be used only once per line of code (the line + * number is used to name a hidden static variable). + * \see CPPUNIT_TEST_SUITE_REGISTRATION + * \see CPPUNIT_TEST_SUITE, CppUnit::AutoRegisterSuite, + * CppUnit::TestFactoryRegistry.. + */ +#define CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( ATestFixtureType, suiteName ) \ + static CppUnit::AutoRegisterSuite< ATestFixtureType > \ + __CPPUNIT_MAKE_UNIQUE_NAME(__autoRegisterSuite )( suiteName ) + + +#endif // CPPUNIT_EXTENSIONS_HELPERMACROS_H diff --git a/cppunit/inc/cppunit/extensions/TestFactory.h b/cppunit/inc/cppunit/extensions/TestFactory.h new file mode 100644 index 000000000000..48ad11c92c89 --- /dev/null +++ b/cppunit/inc/cppunit/extensions/TestFactory.h @@ -0,0 +1,25 @@ +#ifndef CPPUNIT_EXTENSIONS_TESTFACTORY_H +#define CPPUNIT_EXTENSIONS_TESTFACTORY_H + +#include <cppunit/Portability.h> + +namespace CppUnit { + +class Test; + +/*! \brief Abstract Test factory. + */ +class CPPUNIT_API TestFactory +{ +public: + virtual ~TestFactory() {} + + /*! Makes a new test. + * \return A new Test. + */ + virtual Test* makeTest() = 0; +}; + +} // namespace CppUnit + +#endif // CPPUNIT_EXTENSIONS_TESTFACTORY_H diff --git a/cppunit/inc/cppunit/extensions/TestFactoryRegistry.h b/cppunit/inc/cppunit/extensions/TestFactoryRegistry.h new file mode 100644 index 000000000000..430f76366c4d --- /dev/null +++ b/cppunit/inc/cppunit/extensions/TestFactoryRegistry.h @@ -0,0 +1,158 @@ +#ifndef CPPUNIT_EXTENSIONS_TESTFACTORYREGISTRY_H +#define CPPUNIT_EXTENSIONS_TESTFACTORYREGISTRY_H + +#include <cppunit/Portability.h> + +#if CPPUNIT_NEED_DLL_DECL +#ifdef _MSC_VER +#pragma warning( push ) +#pragma warning( disable: 4251 ) // X needs to have dll-interface to be used by clients of class Z +#endif +#endif + +#include <cppunit/extensions/TestFactory.h> +#include <map> +#include <string> + +#include <cppunit/autoregister/htestresult.h> + +namespace CppUnit { + +class TestSuite; + +#if CPPUNIT_NEED_DLL_DECL + template class CPPUNIT_API std::map<std::string, TestFactory *>; +#endif + + +/*! \brief Registry for TestFactory. + * \ingroup CreatingTestSuite + * + * Notes that the registry assumes lifetime control for any registered test. + * + * To register tests, use the macros: + * - CPPUNIT_TEST_SUITE_REGISTRATION(): to add tests in the unnamed registry. + * - CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(): to add tests in a named registry. + * + * Example 1: retreiving a suite that contains all the test registered with + * CPPUNIT_TEST_SUITE_REGISTRATION(). + * \code + * CppUnit::TestFactoryRegistry ®istry = CppUnit::TestFactoryRegistry::getRegistry(); + * CppUnit::TestSuite *suite = registry.makeTest(); + * \endcode + * + * Example 2: retreiving a suite that contains all the test registered with + * \link CPPUNIT_TEST_SUITE_NAMED_REGISTRATION() CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( ..., "Math" )\endlink. + * \code + * CppUnit::TestFactoryRegistry &mathRegistry = CppUnit::TestFactoryRegistry::getRegistry( "Math" ); + * CppUnit::TestSuite *mathSuite = mathRegistry.makeTest(); + * \endcode + * + * Example 3: creating a test suite hierarchy composed of unnamed registration and + * named registration: + * - All Tests + * - tests registered with CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( ..., "Graph" ) + * - tests registered with CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( ..., "Math" ) + * - tests registered with CPPUNIT_TEST_SUITE_REGISTRATION + * + * \code + * CppUnit::TestSuite *rootSuite = new CppUnit::TestSuite( "All tests" ); + * rootSuite->addTest( CppUnit::TestFactoryRegistry::getRegistry( "Graph" ).makeTest() ); + * rootSuite->addTest( CppUnit::TestFactoryRegistry::getRegistry( "Math" ).makeTest() ); + * CppUnit::TestFactoryRegistry::getRegistry().addTestToSuite( rootSuite ); + * \endcode + * + * The same result can be obtained with: + * \code + * CppUnit::TestFactoryRegistry ®istry = CppUnit::TestFactoryRegistry::getRegistry(); + * registry.registerFactory( CppUnit::TestFactoryRegistry::getRegistry( "Graph" ) ); + * registry.registerFactory( CppUnit::TestFactoryRegistry::getRegistry( "Math" ) ); + * CppUnit::TestSuite *suite = registry.makeTest(); + * \endcode + * + * Since a TestFactoryRegistry is a TestFactory, the named registries can be + * registered in the unnamed registry, creating the hierarchy links. + * + * \see TestSuiteFactory, AutoRegisterSuite + * \see CPPUNIT_TEST_SUITE_REGISTRATION, CPPUNIT_TEST_SUITE_NAMED_REGISTRATION + */ +class CPPUNIT_API TestFactoryRegistry : public TestFactory +{ +public: + /** Constructs the registry with the specified name. + * \param name Name of the registry. It is the name of TestSuite returned by + * makeTest(). + */ + TestFactoryRegistry( std::string const& name = "All Tests" ); + + /// Destructor. + virtual ~TestFactoryRegistry(); + + /** Returns a new TestSuite that contains the registered test. + * \return A new TestSuite which contains all the test added using + * registerFactory(TestFactory *). + */ + virtual Test *makeTest(); + + /** Returns unnamed the registry. + * TestSuite registered using CPPUNIT_TEST_SUITE_REGISTRATION() are registered + * in this registry. + * \return Registry which name is "All Tests". + */ + static TestFactoryRegistry &getRegistry(); + + /** Returns a named registry. + * TestSuite registered using CPPUNIT_TEST_SUITE_NAMED_REGISTRATION() are registered + * in the registry of the same name. + * \param name Name of the registry to return. + * \return Registry. If the registry does not exist, it is created with the + * specified name. + */ + static TestFactoryRegistry &getRegistry( const std::string &name ); + static void testRegistries(hTestResult _pResult); + + /** Adds the registered tests to the specified suite. + * \param suite Suite the tests are added to. + */ + void addTestToSuite( TestSuite *suite ); + + /** Adds the specified TestFactory with a specific name (DEPRECATED). + * \param name Name associated to the factory. + * \param factory Factory to register. + * \deprecated Use registerFactory( TestFactory *) instead. + */ +protected: + + void registerFactory( const std::string &name, + TestFactory *factory ); +public: + + /** Adds the specified TestFactory to the registry. + * + * \param factory Factory to register. + */ + void registerFactory( TestFactory *factory ); + +private: + TestFactoryRegistry( const TestFactoryRegistry © ); + void operator =( const TestFactoryRegistry © ); + +private: + typedef std::map<std::string, TestFactory *> Factories; + Factories m_factories; + + std::string m_name; +}; + + +} // namespace CppUnit + + +#if CPPUNIT_NEED_DLL_DECL +#ifdef _MSC_VER +#pragma warning( pop ) +#endif +#endif + + +#endif // CPPUNIT_EXTENSIONS_TESTFACTORYREGISTRY_H diff --git a/cppunit/inc/cppunit/extensions/TestSuiteBuilder.h b/cppunit/inc/cppunit/extensions/TestSuiteBuilder.h new file mode 100644 index 000000000000..5ee305df0b35 --- /dev/null +++ b/cppunit/inc/cppunit/extensions/TestSuiteBuilder.h @@ -0,0 +1,106 @@ +#ifndef CPPUNIT_EXTENSIONS_TESTSUITEBUILDER_H +#define CPPUNIT_EXTENSIONS_TESTSUITEBUILDER_H + +#include <cppunit/Portability.h> +#include <memory> +#include <cppunit/TestSuite.h> +#include <cppunit/TestCaller.h> + +#if CPPUNIT_USE_TYPEINFO_NAME +# include <cppunit/extensions/TypeInfoHelper.h> +#endif + +namespace CppUnit { + + /*! \brief Helper to add tests to a TestSuite. + * \ingroup WritingTestFixture + * + * All tests added to the TestSuite are prefixed by TestSuite name. The resulting + * TestCase name has the following pattern: + * + * MyTestSuiteName.myTestName + */ + template<typename Fixture> + class TestSuiteBuilder + { + public: + typedef void (Fixture::*TestMethod)(); + +#if CPPUNIT_USE_TYPEINFO_NAME + TestSuiteBuilder() : + m_suite( new TestSuite( + TypeInfoHelper::getClassName( typeid(Fixture) ) ) ) + { + } +#endif + + TestSuiteBuilder( TestSuite *_suite ) : m_suite( _suite ) + { + } + + TestSuiteBuilder(std::string const& name) : m_suite( new TestSuite(name) ) + { + } + + TestSuite *suite() const + { + return m_suite.get(); + } + + TestSuite *takeSuite() + { + return m_suite.release(); + } + + void addTest( Test *test ) + { + m_suite->addTest( test ); + } + + void addTestCaller( std::string const& methodName, + TestMethod testMethod ) + { + Test *test = + new TestCaller<Fixture>( makeTestName( methodName ), + testMethod ); + addTest( test ); + } + + void addTestCaller( std::string const& methodName, + TestMethod testMethod, + Fixture *fixture ) + { + Test *test = + new TestCaller<Fixture>( makeTestName( methodName ), + testMethod, + fixture); + addTest( test ); + } + + template<typename ExceptionType> + void addTestCallerForException( std::string const& methodName, + TestMethod testMethod, + Fixture *fixture, + ExceptionType *dummyPointer ) + { + Test *test = new TestCaller<Fixture,ExceptionType>( + makeTestName( methodName ), + testMethod, + fixture); + addTest( test ); + } + + + std::string makeTestName( const std::string &methodName ) + { + // return m_suite->getName() + "." + methodName; + return methodName; + } + + private: + std::auto_ptr<TestSuite> m_suite; + }; + +} // namespace CppUnit + +#endif // CPPUNIT_EXTENSIONS_TESTSUITEBUILDER_H diff --git a/cppunit/inc/cppunit/extensions/TestSuiteFactory.h b/cppunit/inc/cppunit/extensions/TestSuiteFactory.h new file mode 100644 index 000000000000..567812d53d5a --- /dev/null +++ b/cppunit/inc/cppunit/extensions/TestSuiteFactory.h @@ -0,0 +1,25 @@ +#ifndef CPPUNIT_EXTENSIONS_TESTSUITEFACTORY_H +#define CPPUNIT_EXTENSIONS_TESTSUITEFACTORY_H + +#include <cppunit/extensions/TestFactory.h> + +namespace CppUnit { + + class Test; + + /*! \brief TestFactory for TestFixture that implements a static suite() method. + * \see AutoRegisterSuite. + */ + template<typename TestCaseType> + class TestSuiteFactory : public TestFactory + { + public: + virtual Test *makeTest() + { + return TestCaseType::suite(); + } + }; + +} // namespace CppUnit + +#endif // CPPUNIT_EXTENSIONS_TESTSUITEFACTORY_H diff --git a/cppunit/inc/cppunit/extensions/TypeInfoHelper.h b/cppunit/inc/cppunit/extensions/TypeInfoHelper.h new file mode 100644 index 000000000000..5199a705ed3b --- /dev/null +++ b/cppunit/inc/cppunit/extensions/TypeInfoHelper.h @@ -0,0 +1,31 @@ +#ifndef CPPUNIT_TYPEINFOHELPER_H +#define CPPUNIT_TYPEINFOHELPER_H + +#include <cppunit/Portability.h> + +#if CPPUNIT_USE_TYPEINFO_NAME + +#include <typeinfo> + + +namespace CppUnit { + + /** Helper to use type_info. + */ + class CPPUNIT_API TypeInfoHelper + { + public: + /** Get the class name of the specified type_info. + * \param info Info which the class name is extracted from. + * \return The string returned by type_info::name() without + * the "class" prefix. If the name is not prefixed + * by "class", it is returned as this. + */ + static std::string getClassName( const std::type_info &info ); + }; + +} // namespace CppUnit + +#endif + +#endif // CPPUNIT_TYPEINFOHELPER_H diff --git a/cppunit/inc/cppunit/externcallbackfunc.hxx b/cppunit/inc/cppunit/externcallbackfunc.hxx new file mode 100644 index 000000000000..58a919c052db --- /dev/null +++ b/cppunit/inc/cppunit/externcallbackfunc.hxx @@ -0,0 +1,63 @@ +/************************************************************************* + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: externcallbackfunc.hxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: lla $ $Date: 2008-02-27 16:08:51 $ + * + * The Contents of this file are made available subject to + * the terms of GNU Lesser General Public License Version 2.1. + * + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2005 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + ************************************************************************/ + +#ifndef _externcallbackfunc_hxx +#define _externcallbackfunc_hxx + +#include <cppunit/autoregister/callbackfunc_fktptr.h> + +// these pointers have they origin in 'tresregister.cxx' +extern FktPtr_CallbackDispatch pCallbackFunc; + +//# extern FktPtr_TestResult_startTest pTestResult_StartTest; +//# extern FktPtr_TestResult_addFailure pTestResult_AddFailure; +//# extern FktPtr_TestResult_addError pTestResult_AddError; +//# extern FktPtr_TestResult_endTest pTestResult_EndTest; +//# extern FktPtr_TestResult_addInfo pTestResult_AddInfo; + +// these pointers have they origin in 'tresregister.cxx' +// extern FktPtr_TestResult_Starter pTestResult_Starter; + +//# extern FktPtr_TestResult_startTest pTestResult_StartTest; +//# extern FktPtr_TestResult_addFailure pTestResult_AddFailure; +//# extern FktPtr_TestResult_addError pTestResult_AddError; +//# extern FktPtr_TestResult_endTest pTestResult_EndTest; +//# extern FktPtr_TestResult_addInfo pTestResult_AddInfo; +//# +//# extern FktPtr_TestResult_enterNode pTestResult_EnterNode; +//# extern FktPtr_TestResult_leaveNode pTestResult_LeaveNode; +//# + +#endif diff --git a/cppunit/inc/cppunit/joblist.hxx b/cppunit/inc/cppunit/joblist.hxx new file mode 100644 index 000000000000..c0a699610401 --- /dev/null +++ b/cppunit/inc/cppunit/joblist.hxx @@ -0,0 +1,107 @@ +/************************************************************************* + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: joblist.hxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: lla $ $Date: 2008-02-27 16:12:01 $ + * + * The Contents of this file are made available subject to + * the terms of GNU Lesser General Public License Version 2.1. + * + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2005 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + ************************************************************************/ + +#ifndef CPPUNIT_JOBLIST_HXX +#define CPPUNIT_JOBLIST_HXX + +#include <vector> +#include <string> +#include <hash_map> + +#ifndef _SAL_TYPES_H_ +#include "sal/types.h" +#endif + +// #include <cppunit/nocopy.hxx> + +/* + struct eqstr + { + bool operator()( std::string const & s1, std::string const& s2 ) const + { + return ( s1 == s2 ); + } + }; +*/ + +/* + struct hashstr + { + sal_uInt32 operator()( std::string const & str ) const + { + return str.hashCode(); + } + }; +*/ +typedef std::hash_map< std::string, int > HashMap; + +// typedef std::vector<std::string> StringList; + +#define JOB_UNKNOWN 0 +#define JOB_NOT_FOUND 1 +#define JOB_PASSED 2 +#define JOB_FAILED 3 +#define JOB_ACCESS 4 + +#define JOB_EXCLUDE_LIST 0x1000 +#define JOB_ONLY_LIST 0x1001 + +typedef sal_Int16 JobType; + +class JobList /* : NOCOPY */ +{ + HashMap m_aJobList; + char** ppsJobList; + + // returns true if the given List contains unxlngi or unxsols or wntmsci... + bool isInCurrentEnvironment(std::string const& _sString); + std::string trim(std::string const& _sStringToTrim); + +public: + JobList(); + ~JobList(); + + bool readfile(std::string const& _sFilename, JobType _nJobType); + const char** getList() const {return (const char**)ppsJobList;} + + int getJobListEntry(std::string const& _sIndexName); + void setJobListEntry(std::string const& _sIndexName, int _nValue); + + int size() {return m_aJobList.size();} + HashMap const& getHashMap() {return m_aJobList;} +}; + +#endif + diff --git a/cppunit/inc/cppunit/nocopy.hxx b/cppunit/inc/cppunit/nocopy.hxx new file mode 100644 index 000000000000..660bb1892e46 --- /dev/null +++ b/cppunit/inc/cppunit/nocopy.hxx @@ -0,0 +1,13 @@ +#ifndef NOCOPY_HXX +#define NOCOPY_HXX + +// prevent illegal copies +class NOCOPY +{ + NOCOPY(NOCOPY const&); + NOCOPY& operator=(NOCOPY const&); +public: + NOCOPY(){} +}; + +#endif diff --git a/cppunit/inc/cppunit/portability/config-auto.h b/cppunit/inc/cppunit/portability/config-auto.h new file mode 100644 index 000000000000..d2286f729981 --- /dev/null +++ b/cppunit/inc/cppunit/portability/config-auto.h @@ -0,0 +1,62 @@ +#ifndef _INCLUDE_CPPUNIT_CONFIG_AUTO_H +#define _INCLUDE_CPPUNIT_CONFIG_AUTO_H 1 + +/* include/cppunit/config-auto.h. Generated automatically at end of configure. */ +/* config/config.h. Generated automatically by configure. */ +/* config/config.h.in. Generated automatically from configure.in by autoheader. */ + +/* define if library uses std::string::compare(string,pos,n) */ +#ifndef CPPUNIT_FUNC_STRING_COMPARE_STRING_FIRST +#define CPPUNIT_FUNC_STRING_COMPARE_STRING_FIRST 1 +#endif + +/* define if the library defines strstream */ +#ifndef CPPUNIT_HAVE_CLASS_STRSTREAM +#define CPPUNIT_HAVE_CLASS_STRSTREAM 1 +#endif + +/* Define if you have the <cmath> header file. */ +#ifndef CPPUNIT_HAVE_CMATH +#define CPPUNIT_HAVE_CMATH 1 +#endif + +/* Define if you have the <dlfcn.h> header file. */ +#ifndef CPPUNIT_HAVE_DLFCN_H +#define CPPUNIT_HAVE_DLFCN_H 1 +#endif + +/* define to 1 if the compiler implements namespaces */ +#ifndef CPPUNIT_HAVE_NAMESPACES +#define CPPUNIT_HAVE_NAMESPACES 1 +#endif + +/* define if the compiler supports Run-Time Type Identification */ +#ifndef CPPUNIT_HAVE_RTTI +#define CPPUNIT_HAVE_RTTI 0 +#endif + +/* define if the compiler has stringstream */ +/* #undef CPPUNIT_HAVE_SSTREAM */ + +/* Define if you have the <strstream> header file. */ +#ifndef CPPUNIT_HAVE_STRSTREAM +#define CPPUNIT_HAVE_STRSTREAM 1 +#endif + +/* Name of package */ +#ifndef CPPUNIT_PACKAGE +#define CPPUNIT_PACKAGE "cppunit" +#endif + +/* Define to 1 to use type_info::name() for class names */ +#ifndef CPPUNIT_USE_TYPEINFO_NAME +#define CPPUNIT_USE_TYPEINFO_NAME CPPUNIT_HAVE_RTTI +#endif + +/* Version number of package */ +#ifndef CPPUNIT_VERSION +#define CPPUNIT_VERSION "1.8.0" +#endif + +/* _INCLUDE_CPPUNIT_CONFIG_AUTO_H */ +#endif diff --git a/cppunit/inc/cppunit/portability/config-bcb5.h b/cppunit/inc/cppunit/portability/config-bcb5.h new file mode 100644 index 000000000000..cecb393efd5d --- /dev/null +++ b/cppunit/inc/cppunit/portability/config-bcb5.h @@ -0,0 +1,48 @@ +#ifndef _INCLUDE_CPPUNIT_CONFIG_BCB5_H +#define _INCLUDE_CPPUNIT_CONFIG_BCB5_H 1 + +#define HAVE_CMATH 1 + +/* include/cppunit/config-bcb5.h. Manually adapted from + include/cppunit/config-auto.h */ + +/* define if library uses std::string::compare(string,pos,n) */ +#ifndef CPPUNIT_FUNC_STRING_COMPARE_STRING_FIRST +#define CPPUNIT_FUNC_STRING_COMPARE_STRING_FIRST 1 +#endif + +/* Define if you have the <dlfcn.h> header file. */ +#ifdef CPPUNIT_HAVE_DLFCN_H +#undef CPPUNIT_HAVE_DLFCN_H +#endif + +/* define to 1 if the compiler implements namespaces */ +#ifndef CPPUNIT_HAVE_NAMESPACES +#define CPPUNIT_HAVE_NAMESPACES 1 +#endif + +/* define if the compiler supports Run-Time Type Identification */ +#ifndef CPPUNIT_HAVE_RTTI +#define CPPUNIT_HAVE_RTTI 1 +#endif + +/* Define to 1 to use type_info::name() for class names */ +#ifndef CPPUNIT_USE_TYPEINFO_NAME +#define CPPUNIT_USE_TYPEINFO_NAME CPPUNIT_HAVE_RTTI +#endif + +#define CPPUNIT_HAVE_SSTREAM 1 + +/* Name of package */ +#ifndef CPPUNIT_PACKAGE +#define CPPUNIT_PACKAGE "cppunit" +#endif + +/* Version number of package */ +#ifndef CPPUNIT_VERSION +#define CPPUNIT_VERSION "1.5.5" +#endif + + +/* _INCLUDE_CPPUNIT_CONFIG_BCB5_H */ +#endif diff --git a/cppunit/inc/cppunit/portability/config-msvc6.h b/cppunit/inc/cppunit/portability/config-msvc6.h new file mode 100644 index 000000000000..9b4c57cfdbb9 --- /dev/null +++ b/cppunit/inc/cppunit/portability/config-msvc6.h @@ -0,0 +1,62 @@ +#ifndef _INCLUDE_CPPUNIT_CONFIG_MSVC6_H +#define _INCLUDE_CPPUNIT_CONFIG_MSVC6_H 1 + +#define HAVE_CMATH 1 + +/* include/cppunit/config-msvc6.h. Manually adapted from + include/cppunit/config-auto.h */ + +/* define if library uses std::string::compare(string,pos,n) */ +#ifdef CPPUNIT_FUNC_STRING_COMPARE_STRING_FIRST +#undef CPPUNIT_FUNC_STRING_COMPARE_STRING_FIRST +#endif + +/* Define if you have the <dlfcn.h> header file. */ +#ifdef CPPUNIT_HAVE_DLFCN_H +#undef CPPUNIT_HAVE_DLFCN_H +#endif + +/* define to 1 if the compiler implements namespaces */ +#ifndef CPPUNIT_HAVE_NAMESPACES +#define CPPUNIT_HAVE_NAMESPACES 1 +#endif + +#ifndef CPPUNIT_HAVE_RTTI +#define CPPUNIT_HAVE_RTTI 0 +#endif + +#ifndef CPPUNIT_USE_TYPEINFO_NAME +#define CPPUNIT_USE_TYPEINFO_NAME CPPUNIT_HAVE_RTTI +#endif + +#define CPPUNIT_HAVE_SSTREAM 1 + +/* Name of package */ +#ifndef CPPUNIT_PACKAGE +#define CPPUNIT_PACKAGE "cppunit" +#endif + +#undef CPPUNIT_API + +// define CPPUNIT_DLL_BUILD when building CppUnit dll. +#ifdef CPPUNIT_BUILD_DLL +#define CPPUNIT_API __declspec(dllexport) +#endif + +// define CPPUNIT_DLL when linking to CppUnit dll. +#ifdef CPPUNIT_DLL +#define CPPUNIT_API __declspec(dllimport) +#endif + +#ifdef CPPUNIT_API +#undef CPPUNIT_NEED_DLL_DECL +#define CPPUNIT_NEED_DLL_DECL 1 +#endif + +#if _MSC_VER > 1000 // VC++ +#pragma warning( disable : 4786 ) // disable warning debug symbol > 255... +#endif // _MSC_VER > 1000 + + +/* _INCLUDE_CPPUNIT_CONFIG_MSVC6_H */ +#endif diff --git a/cppunit/inc/cppunit/result/SynchronizedObject.h b/cppunit/inc/cppunit/result/SynchronizedObject.h new file mode 100644 index 000000000000..83ac098886a9 --- /dev/null +++ b/cppunit/inc/cppunit/result/SynchronizedObject.h @@ -0,0 +1,82 @@ +#ifndef CPPUNIT_SYNCHRONIZEDOBJECT_H +#define CPPUNIT_SYNCHRONIZEDOBJECT_H + +#include <cppunit/Portability.h> +#include <cppunit/nocopy.hxx> + +namespace CppUnit +{ + +/*! \brief Base class for synchronized object. + * + * Synchronized object are object which members are used concurrently by mutiple + * threads. + * + * This class define the class SynchronizationObject which must be subclassed + * to implement an actual lock. + * + * Each instance of this class holds a pointer on a lock object. + * + * See src/msvc6/MfcSynchronizedObject.h for an example. + */ +class CPPUNIT_API SynchronizedObject +{ +public: + /*! \brief Abstract synchronization object (mutex) + */ + class SynchronizationObject + { + public: + SynchronizationObject() {} + virtual ~SynchronizationObject() {} + + virtual void lock() {} + virtual void unlock() {} + }; + + /*! Constructs a SynchronizedObject object. + */ + SynchronizedObject( SynchronizationObject *syncObject =0 ); + + /// Destructor. + virtual ~SynchronizedObject(); + +protected: + /*! \brief Locks a synchronization object in the current scope. + */ + class ExclusiveZone : NOCOPY + { + SynchronizationObject *m_syncObject; + + public: + ExclusiveZone( SynchronizationObject *syncObject ) + : m_syncObject( syncObject ) + { + m_syncObject->lock(); + } + + ~ExclusiveZone() + { + m_syncObject->unlock (); + } + }; + + virtual void setSynchronizationObject( SynchronizationObject *syncObject ); + +protected: + SynchronizationObject *m_syncObject; + +private: + /// Prevents the use of the copy constructor. + SynchronizedObject( const SynchronizedObject © ); + + /// Prevents the use of the copy operator. + void operator =( const SynchronizedObject © ); +}; + + + +} // namespace CppUnit + + +#endif // CPPUNIT_SYNCHRONIZEDOBJECT_H diff --git a/cppunit/inc/cppunit/result/TestListener.h b/cppunit/inc/cppunit/result/TestListener.h new file mode 100644 index 000000000000..0814f21b7e2f --- /dev/null +++ b/cppunit/inc/cppunit/result/TestListener.h @@ -0,0 +1,62 @@ +#ifndef CPPUNIT_TESTLISTENER_H // -*- C++ -*- +#define CPPUNIT_TESTLISTENER_H + +#include <cppunit/Portability.h> + + +namespace CppUnit { + +class Exception; +class Test; +class TestFailure; + + +/*! \brief Listener for test progress and result. + * \ingroup TrackingTestExecution + * + * Implementing the Observer pattern a TestListener may be registered + * to a TestResult to obtain information on the testing progress. Use + * specialized sub classes of TestListener for text output + * (TextTestProgressListener). Do not use the Listener for the test + * result output, use a subclass of Outputter instead. + * + * The test framework distinguishes between failures and errors. + * A failure is anticipated and checked for with assertions. Errors are + * unanticipated problems signified by exceptions that are not generated + * by the framework. + * + * \see TestResult + */ +class CPPUNIT_API TestListener +{ +public: + virtual ~TestListener() {} + + /// Called when just before a TestCase is run. + virtual void startTest( Test *test ) =0 ; + + /*! Called when a failure occurs while running a test. + * \see TestFailure. + * \warning \a failure is a temporary object that is destroyed after the + * method call. Use TestFailure::clone() to create a duplicate. + */ + virtual void addFailure( const TestFailure &failure ) =0; + + /// Called just after a TestCase was run (even if a failure occured). + virtual void endTest( Test *test ) =0; + + // additional info + virtual void addInfo(Test *test, const char*) =0; + + // info in which node we are + // helper functions to create tree structures + // old: virtual void enterNode( const char* ) =0; + // old: virtual void leaveNode( const char* ) =0; +}; + + +} // namespace CppUnit + +#endif // CPPUNIT_TESTLISTENER_H + + diff --git a/cppunit/inc/cppunit/result/TestResult.h b/cppunit/inc/cppunit/result/TestResult.h new file mode 100644 index 000000000000..9c8895a26ff3 --- /dev/null +++ b/cppunit/inc/cppunit/result/TestResult.h @@ -0,0 +1,123 @@ +#ifndef CPPUNIT_TESTRESULT_H +#define CPPUNIT_TESTRESULT_H + +#include <cppunit/Portability.h> + +#if CPPUNIT_NEED_DLL_DECL +#ifdef _MSC_VER +#pragma warning( push ) +#pragma warning( disable: 4251 ) // X needs to have dll-interface to be used by clients of class Z +#endif +#endif + +#include <cppunit/result/SynchronizedObject.h> +#include <vector> +#include <string> +#include <deque> +//!io #include <iostream> + +#include "cppunit/result/optionhelper.hxx" +#include "cppunit/TestFailure.h" + +class Outputter; +namespace CppUnit { + +class Exception; +class Test; +// class TestFailure; +class TestListener; + +#if CPPUNIT_NEED_DLL_DECL + template class CPPUNIT_API std::deque<TestListener *>; +#endif + +/*! \brief Manages TestListener. + * \ingroup TrackingTestExecution + * + * A single instance of this class is used when running the test. It is usually + * created by the test runner (TestRunner). + * + * This class shouldn't have to be inherited from. Use a TestListener + * or one of its subclasses to be informed of the ongoing tests. + * Use a Outputter to receive a test summary once it has finished + * + * TestResult supplies a template method 'setSynchronizationObject()' + * so that subclasses can provide mutual exclusion in the face of multiple + * threads. This can be useful when tests execute in one thread and + * they fill a subclass of TestResult which effects change in another + * thread. To have mutual exclusion, override setSynchronizationObject() + * and make sure that you create an instance of ExclusiveZone at the + * beginning of each method. + * + * \see Test, TestListener, TestResultCollector, Outputter. + */ +class CPPUNIT_API TestResult : protected SynchronizedObject +{ +protected: + OptionHelper m_aOptionHelper; + +public: + TestResult( GetOpt & _aOptions, SynchronizationObject *syncObject = 0 ); + virtual ~TestResult(); + + virtual void addListener( TestListener *listener ); + virtual void removeListener( TestListener *listener ); + + virtual void reset(); + virtual void stop(); + + virtual bool shouldStop() const; + + virtual void startTest( Test *test ); + virtual void addError( Test *test, Exception *e, ErrorType::num eType=ErrorType::ET_ERROR); + virtual void addFailure( Test *test, Exception *e ); + virtual void endTest( Test *test ); + + // LLA: additionals + virtual void addInfo(Test *test, const char *sInfo); + + virtual void enterNode(const char* Node); + virtual void leaveNode(const char* Node); + virtual std::string getNodeName(); + + // if true, execution is allowed. + virtual bool isAllowedToExecute(std::string const & sName); + bool isOnlyShowJobs() {return m_aOptionHelper.isOnlyShowJobs();} + bool isOptionWhereAmI(); + + virtual void print(Outputter &); + void setExitValue(int _nValue) {m_nExitValue = _nValue;} + int getExitValue() {return m_nExitValue;} + +protected: + void addFailure( const TestFailure &failure ); + +protected: + typedef std::deque<TestListener *> TestListeners; + TestListeners m_listeners; + bool m_stop; + + // this vector is used to expand the test name with a current node name + std::vector<std::string> m_aCurrentNodeNames; + + //# std::vector<std::string> m_aNodes; + +private: + TestResult( const TestResult &other ); + TestResult &operator =( const TestResult &other ); + int m_nExitValue; +}; + + +} // namespace CppUnit + + +#if CPPUNIT_NEED_DLL_DECL +#ifdef _MSC_VER +#pragma warning( pop ) +#endif +#endif + +#endif // CPPUNIT_TESTRESULT_H + + diff --git a/cppunit/inc/cppunit/result/TestResultCollector.h b/cppunit/inc/cppunit/result/TestResultCollector.h new file mode 100644 index 000000000000..79d9707b9d92 --- /dev/null +++ b/cppunit/inc/cppunit/result/TestResultCollector.h @@ -0,0 +1,165 @@ +#ifndef CPPUNIT_TESTRESULTCOLLECTOR_H +#define CPPUNIT_TESTRESULTCOLLECTOR_H + +#include <cppunit/Portability.h> + +#if CPPUNIT_NEED_DLL_DECL +#ifdef _MSC_VER +#pragma warning( push ) +#pragma warning( disable: 4251 ) // X needs to have dll-interface to be used by clients of class Z +#endif +#endif + +#include <cppunit/result/TestResult.h> +#include <cppunit/result/TestSucessListener.h> +#include <deque> +#include <vector> + +namespace CppUnit +{ + + +#if CPPUNIT_NEED_DLL_DECL + template class CPPUNIT_API std::deque<TestFailure *>; + template class CPPUNIT_API std::deque<Test *>; +#endif + + +/*! \brief Collects test result. + * \ingroup WritingTestResult + * \ingroup BrowsingCollectedTestResult + * + * A TestResultCollector is a TestListener which collects the results of executing + * a test case. It is an instance of the Collecting Parameter pattern. + * + * The test framework distinguishes between failures and errors. + * A failure is anticipated and checked for with assertions. Errors are + * unanticipated problems signified by exceptions that are not generated + * by the framework. + * \see TestListener, TestFailure. + */ + +class OneStringContainer +{ + std::string m_sName; +protected: + OneStringContainer() {} +public: + OneStringContainer(std::string const& _sName) + :m_sName(_sName){} + std::string getString() const {return m_sName;} + virtual ~OneStringContainer(){} +}; + +// ----------------------------------------------------------------------------- +class TestEnvelope : public OneStringContainer +{ + Test* m_pTest; +public: + TestEnvelope():m_pTest(NULL){} + + TestEnvelope(Test* _pTest, std::string const& _sName) + : OneStringContainer(_sName), + m_pTest(_pTest) + {} + + Test* getTest() {return m_pTest;} + virtual ~TestEnvelope(){} + +}; + +// ----------------------------------------------------------------------------- +class TestInfo : public TestEnvelope +{ +public: + TestInfo(Test* _pTest, std::string const& _sName) + :TestEnvelope(_pTest, _sName) + {} +}; + +// ----------------------------------------------------------------------------- +class TestFailureEnvelope : public OneStringContainer +{ + TestFailure* m_pTestFailure; +public: + TestFailureEnvelope():m_pTestFailure(NULL){} + + TestFailureEnvelope(TestFailure* _pTestFailure, std::string const& _sName) + :OneStringContainer(_sName), + m_pTestFailure(_pTestFailure) + {} + + TestFailure* getTestFailure() {return m_pTestFailure;} + virtual ~TestFailureEnvelope(){} + +}; +// ----------------------------------------------------------------------------- + +class CPPUNIT_API TestResultCollector : public TestSucessListener +{ + TestResult* m_pResult; +public: + typedef std::deque<TestFailureEnvelope *> TestFailures; + typedef std::deque<TestEnvelope *> Tests; + typedef std::vector<TestInfo *> TestInfos; + + + /*! Constructs a TestResultCollector object. + */ + TestResultCollector( TestResult *_pResult, SynchronizationObject *syncObject = 0 ); + + /// Destructor. + virtual ~TestResultCollector(); + + void startTest( Test *test ); + void endTest( Test *test ); + + void addFailure( const TestFailure &failure ); + + virtual void reset(); + + virtual int runTests() const; + virtual int testErrors() const; + virtual int testFailures() const; + virtual int testFailuresTotal() const; + + virtual const TestFailures& failures() const; + virtual const Tests &tests() const; + virtual std::string getInfo(Test*); + + virtual void addInfo(Test *test, const char *sInfo); + + // virtual void enterNode(const char* Node); + // virtual void leaveNode(const char* Node); + +protected: + Tests m_tests; + TestFailures m_failures; + TestInfos m_aInfos; + + int m_testErrors; + + // this vector is used to expand the test name with a current node name + // std::vector<std::string> m_aCurrentNodeNames; + // std::string getNodeName(); +private: + /// Prevents the use of the copy constructor. + TestResultCollector( const TestResultCollector © ); + + /// Prevents the use of the copy operator. + void operator =( const TestResultCollector © ); +}; + + + +} // namespace CppUnit + + +#if CPPUNIT_NEED_DLL_DECL +#ifdef _MSC_VER +#pragma warning( pop ) +#endif +#endif + + +#endif // CPPUNIT_TESTRESULTCOLLECTOR_H diff --git a/cppunit/inc/cppunit/result/TestSucessListener.h b/cppunit/inc/cppunit/result/TestSucessListener.h new file mode 100644 index 000000000000..15794b65f511 --- /dev/null +++ b/cppunit/inc/cppunit/result/TestSucessListener.h @@ -0,0 +1,40 @@ +#ifndef CPPUNIT_TESTSUCESSLISTENER_H +#define CPPUNIT_TESTSUCESSLISTENER_H + +#include <cppunit/result/SynchronizedObject.h> +#include <cppunit/result/TestListener.h> + + +namespace CppUnit +{ + +/*! \brief TestListener that checks if any test case failed. + * \ingroup TrackingTestExecution + */ +class CPPUNIT_API TestSucessListener : public TestListener, + public SynchronizedObject +{ +public: + /*! Constructs a TestSucessListener object. + */ + TestSucessListener( SynchronizationObject *syncObject = 0 ); + + /// Destructor. + virtual ~TestSucessListener(); + + virtual void reset(); + + void addFailure( const TestFailure &failure ); + + /// Returns whether the entire test was successful or not. + virtual bool wasSuccessful() const; + +private: + bool m_sucess; +}; + + +} // namespace CppUnit + + +#endif // CPPUNIT_TESTSUCESSLISTENER_H diff --git a/cppunit/inc/cppunit/result/TextTestResult.h b/cppunit/inc/cppunit/result/TextTestResult.h new file mode 100644 index 000000000000..02eb3344b708 --- /dev/null +++ b/cppunit/inc/cppunit/result/TextTestResult.h @@ -0,0 +1,62 @@ +#ifndef CPPUNIT_TEXTTESTRESULT_H +#define CPPUNIT_TEXTTESTRESULT_H + +#include <cppunit/result/TestResult.h> +#include <cppunit/result/TestResultCollector.h> +#include <ostream> + +class GetOpt; +namespace CppUnit { + +class SourceLine; +class Exception; +class Test; + +/*! \brief Holds printable test result (DEPRECATED). + * \ingroup TrackingTestExecution + * + * deprecated Use class TextTestProgressListener and TextOutputter instead. + */ +class CPPUNIT_API TextTestResult : public TestResult +/* public TestResultCollector*/ +{ + TestResultCollector m_aResulter; +public: + TextTestResult(GetOpt& _aOptions); + + virtual void addFailure( const TestFailure &failure ); + virtual void startTest( Test *test ); + virtual void endTest( Test *test ); + + virtual void print( std::ostream &stream ); +protected: + + virtual void printFailures( std::ostream &stream ); + virtual void printHeader( std::ostream &stream ); + + virtual void printFailure( TestFailure *failure, + int failureNumber, + std::ostream &stream ); + virtual void printFailureListMark( int failureNumber, + std::ostream &stream ); + virtual void printFailureTestName( TestFailure *failure, + std::ostream &stream ); + virtual void printFailureType( TestFailure *failure, + std::ostream &stream ); + virtual void printFailureLocation( SourceLine sourceLine, + std::ostream &stream ); + virtual void printFailureDetail( Exception *thrownException, + std::ostream &stream ); + virtual void printFailureWarning( std::ostream &stream ); + virtual void printStatistics( std::ostream &stream ); +}; + +/** insertion operator for easy output */ +std::ostream &operator <<( std::ostream &stream, + TextTestResult &result ); + +} // namespace CppUnit + +#endif // CPPUNIT_TEXTTESTRESULT_H + + diff --git a/cppunit/inc/cppunit/result/callbackfunc.h b/cppunit/inc/cppunit/result/callbackfunc.h new file mode 100644 index 000000000000..8ff1c7a957f4 --- /dev/null +++ b/cppunit/inc/cppunit/result/callbackfunc.h @@ -0,0 +1,25 @@ +#ifndef _callbackfunc_h +#define _callbackfunc_h + +#ifdef __cplusplus +extern "C" { +#endif + + // this is the entry point from the DLL back to the executable. + sal_Int32 CallbackDispatch(int x, ...); + +//# void TestResult_startTest(hTestResult _pResult, hTest _pTest); +//# void TestResult_addFailure( hTestResult _pResult, hTest _pTest, hException _pException ); +//# void TestResult_addError( hTestResult _pResult, hTest _pTest, hException _pException ); +//# void TestResult_endTest( hTestResult _pResult, hTest _pTest ); +//# bool TestResult_shouldStop(hTestResult _pResult); +//# void TestResult_addInfo( hTestResult _pResult, hTest _pTest, const char* _sInfo ); +//# +//# void TestResult_enterNode( hTestResult _pResult, const char* _sInfo ); +//# void TestResult_leaveNode( hTestResult _pResult, const char* _sInfo ); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/cppunit/inc/cppunit/result/emacsTestResult.hxx b/cppunit/inc/cppunit/result/emacsTestResult.hxx new file mode 100644 index 000000000000..4c7c09a18113 --- /dev/null +++ b/cppunit/inc/cppunit/result/emacsTestResult.hxx @@ -0,0 +1,87 @@ +/************************************************************************* + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: emacsTestResult.hxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: lla $ $Date: 2008-02-27 16:15:24 $ + * + * The Contents of this file are made available subject to + * the terms of GNU Lesser General Public License Version 2.1. + * + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2005 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + ************************************************************************/ + +#ifndef cppunit_emacstestresult_h +#define cppunit_emacstestresult_h + +#include <cppunit/result/TestResult.h> +#include <cppunit/result/TestResultCollector.h> +#include <ostream> +#include "testshl/getopt.hxx" + +class Outputter; +namespace CppUnit { + +class SourceLine; +class Exception; +class Test; + +/*! \brief Holds printable test result (DEPRECATED). + * \ingroup TrackingTestExecution + * + * deprecated Use class TextTestProgressListener and TextOutputter instead. + */ + class CPPUNIT_API emacsTestResult : public TestResult + +/* ,public TestResultCollector*/ + { + GetOpt & m_aOptions; + // OptionHelper m_aOptionHelper; + TestResultCollector m_aResulter; + + public: + emacsTestResult(GetOpt & _aOptions); + + // virtual void addFailure( const TestFailure &failure ); + // virtual void startTest( Test *test ); + // virtual void endTest( Test *test ); + + virtual void print( Outputter &stream ); + + protected: + virtual void printHeader( Outputter &stream ); + // virtual void printTestLine( Outputter &stream, Test* pTest, std::string const& _sNodeName, std::string const& _sInfo); + virtual void printFailureLine( Outputter &stream, TestFailure* pFailure, std::string const& _sNodeName ); + }; + +/** insertion operator for easy output */ +// std::ostream &operator <<( std::ostream &stream, +// emacsTestResult &result ); + +} // namespace CppUnit + +#endif // CPPUNIT_testshlTESTRESULT_H + + diff --git a/cppunit/inc/cppunit/result/log.hxx b/cppunit/inc/cppunit/result/log.hxx new file mode 100644 index 000000000000..8d4d7108f01e --- /dev/null +++ b/cppunit/inc/cppunit/result/log.hxx @@ -0,0 +1,126 @@ +/************************************************************************* + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: log.hxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: lla $ $Date: 2008-02-27 16:13:49 $ + * + * The Contents of this file are made available subject to + * the terms of GNU Lesser General Public License Version 2.1. + * + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2005 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + ************************************************************************/ +#ifndef __QADEV_REGSCAN_LOG_HXX__ +#define __QADEV_REGSCAN_LOG_HXX__ + +#include <time.h> + +#ifndef _RTL_USTRING_HXX_ +#include <rtl/ustring.hxx> +#endif + +#ifndef _RTL_STRBUF_HXX_ +#include <rtl/strbuf.hxx> +#endif + +#ifndef _SAL_TYPES_H_ +#include <sal/types.h> +#endif + +#ifndef _OSL_THREAD_H_ +#include <osl/thread.h> +#endif + +#ifndef _OSL_FILE_HXX_ +#include <osl/file.hxx> +#endif + +#include <cppunit/nocopy.hxx> + +//!io #include <iostream> +#include <vector> + +// using namespace std; + + +/** + * Log derives the interface of the ::osl::File class ( is-a relation ). + * Its members (has-a relation) are the (full qualified)name of the log + * and an OStringBuffer which represents the content of the logfile. + * It provides the functionality of easy-to-use open and write logs + */ +//: Log +class Log : NOCOPY { + + ::osl::File* m_logfile; // fileobject + rtl::OUString m_logurl; // url of log + rtl::OStringBuffer m_buf; // content of log + + Log(); + +public: + + //> c'tor + /** + * constructors argument is a full qualified UNC path + * @param OUString logfile ( full qualified UNC path ) + */ + Log( const rtl::OUString& logURL ) + : m_logfile( new ::osl::File( logURL )) + , m_logurl(logURL) + {} ///< c'tor + + //> d'tor + virtual ~Log() + { + m_logfile->close(); + delete( m_logfile ); + } ///< d'tor + + //> inline methods + // returns a reference to name instance + inline rtl::OUString getLogURL() { return m_logurl; } + inline rtl::OString getName() { return rtl::OUStringToOString( + m_logurl, RTL_TEXTENCODING_ASCII_US ); } + ///< inline methods + + // open logfile for overwrite (default) or append + ::osl::FileBase::RC open( sal_Bool append = sal_False ); + ::osl::FileBase::RC close() { return m_logfile->close(); } + + + // write methods without (default) or with echo on display + ::osl::FileBase::RC write( const sal_Char* buf, sal_Bool v = sal_False ); + ::osl::FileBase::RC write( const rtl::OString& buf, + sal_Bool v = sal_False ); + //! ::osl::FileBase::RC write( rtl::OStringBuffer& buf, + //! sal_Bool v = sal_False ); + ::osl::FileBase::RC write( const rtl::OUString& buf, + rtl_TextEncoding enc = RTL_TEXTENCODING_ASCII_US, + sal_Bool v = sal_False ); + +}; ///:~ Log + +#endif diff --git a/cppunit/inc/cppunit/result/optionhelper.hxx b/cppunit/inc/cppunit/result/optionhelper.hxx new file mode 100644 index 000000000000..0ffb50ff7afc --- /dev/null +++ b/cppunit/inc/cppunit/result/optionhelper.hxx @@ -0,0 +1,103 @@ +/************************************************************************* + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: optionhelper.hxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: lla $ $Date: 2008-02-27 16:13:38 $ + * + * The Contents of this file are made available subject to + * the terms of GNU Lesser General Public License Version 2.1. + * + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2005 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + ************************************************************************/ + +#ifndef optionhelper_hxx +#define optionhelper_hxx + +#include <string> + +#include <sal/types.h> + +#include "cppunit/nocopy.hxx" +#include "testshl/getopt.hxx" +#include "cppunit/joblist.hxx" + +// ----------------------------------------------------------------------------- + +typedef std::vector<rtl::OString> OStringList; + +//!? Better: OptionHelper +class OptionHelper : NOCOPY +{ + GetOpt & m_aOption; + JobList m_aJobOnlyList; + JobList m_aJobExcludeList; + OStringList m_aJobFilter; + + std::string m_sProjectId; + std::string m_sBuildId; + + std::string getProjectId() const; + std::string getBuildId() const; + std::string createDateTag(std::string const& _sProjectId, std::string const& _sBuildId); + + void handleJobs(); +public: + OptionHelper(GetOpt & _aOption) + :m_aOption(_aOption) + { + if (m_aOption.hasOpt("-projectid")) + m_sProjectId = m_aOption.getOpt("-projectid"); + + if (m_aOption.hasOpt("-buildid")) + m_sBuildId = m_aOption.getOpt("-buildid"); + + handleJobs(); + } + + static std::string integerToAscii(sal_Int32 nValue); + static std::string twoDigits(std::string const& _sValue); + + std::string createDateTag(); + bool showErrors(); + bool showTests(); + + JobList getJobOnlyList() {return m_aJobOnlyList;} + JobList getJobExcludeList() {return m_aJobExcludeList;} + + bool isAllowedToExecute(std::string const& _sNode, std::string const& _sName); + + bool isOnlyShowJobs() {return m_aOption.hasOpt("-onlyshowjobs") == sal_True ? true : false;} + GetOpt& getOptions() {return m_aOption;} + bool isVerbose() {return m_aOption.hasOpt("-verbose") == sal_True ? true : false;} + bool isOptionWhereAmI() {return m_aOption.hasOpt("-whereami") == sal_True ? true : false;} +}; + +// ----------------------------------------------------------------------------- + + +#endif + + diff --git a/cppunit/inc/cppunit/result/outputter.hxx b/cppunit/inc/cppunit/result/outputter.hxx new file mode 100644 index 000000000000..c4c828c68ad8 --- /dev/null +++ b/cppunit/inc/cppunit/result/outputter.hxx @@ -0,0 +1,90 @@ +/************************************************************************* + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: outputter.hxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: lla $ $Date: 2008-02-27 16:15:12 $ + * + * The Contents of this file are made available subject to + * the terms of GNU Lesser General Public License Version 2.1. + * + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2005 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + ************************************************************************/ + +// + +#ifndef outputter_hxx +#define outputter_hxx + +#include <string> +#include <ostream> +#include <memory> +#include "testshl/log.hxx" +#include <sal/types.h> +#include "cppunit/nocopy.hxx" + +// #include <fstream> + +class Outputter : NOCOPY +{ + std::auto_ptr<Log> m_pLog; + std::ostream* m_pStream; + + void writeToAll(const sal_Char* _pStr); +public: + class endl + { + char c; + public: + endl():c('\0'){} + }; +public: + Outputter(Log * _pLog ) + :m_pLog(_pLog), + m_pStream(NULL) {} + + Outputter(std::ostream& _aStream) + :m_pLog(NULL), + m_pStream(&_aStream) {} + + ~Outputter(); + + void write(const sal_Char*); + void write(std::string const&); + void write(sal_Int32); + // void write(double); +}; + +Outputter& operator <<( Outputter &stream, const sal_Char* ); +Outputter& operator <<( Outputter &stream, std::string const& ); +Outputter& operator <<( Outputter &stream, sal_Int32 ); +// Outputter& operator <<( Outputter &stream, double ); + +Outputter& operator <<( Outputter &stream, Outputter::endl const&); + +// Outputter& operator <<( Outputter &stream, const char* ); + +#endif + diff --git a/cppunit/inc/cppunit/result/testshlTestResult.h b/cppunit/inc/cppunit/result/testshlTestResult.h new file mode 100644 index 000000000000..0eb629610bc4 --- /dev/null +++ b/cppunit/inc/cppunit/result/testshlTestResult.h @@ -0,0 +1,72 @@ +#ifndef cppunit_testshltestresult_h +#define cppunit_testshltestresult_h + +#include <map> +#include <cppunit/result/TestResult.h> +#include <cppunit/result/TestResultCollector.h> +#include <ostream> +#include "testshl/getopt.hxx" + +class Outputter; + +namespace CppUnit { + +class SourceLine; +class Exception; +class Test; + +struct ltstr +{ + bool operator()(const CppUnit::Test* p1, const CppUnit::Test* p2) const + { + return p1 < p2; + } +}; +typedef std::map<CppUnit::Test*, bool, ltstr> TestPtrList; + + +/*! \brief Holds printable test result (DEPRECATED). + * \ingroup TrackingTestExecution + * + * deprecated Use class TextTestProgressListener and TextOutputter instead. + */ + class CPPUNIT_API testshlTestResult : public TestResult + +/* ,public TestResultCollector*/ + { + GetOpt & m_aOptions; + // OptionHelper m_aOptionHelper; + TestResultCollector m_aResulter; + + public: + testshlTestResult(GetOpt & _aOptions); + virtual ~testshlTestResult(); + + // virtual void addFailure( const TestFailure &failure ); + // virtual void startTest( Test *test ); + // virtual void endTest( Test *test ); + + virtual void print( Outputter &stream ); + + protected: + virtual void printHeader( Outputter &stream ); + + void printLines(Outputter &stream, HashMap & _aJobList); + void printFailedTests(Outputter &stream, TestPtrList &aFailedTests); + void printTestLines(Outputter &stream, TestPtrList &aFailedTests); + void printUnknownLines(Outputter &stream, HashMap & _aJobList); + + virtual void printTestLine( Outputter &stream, Test* pTest, std::string const& _sNodeName, std::string const& _sInfo); + virtual void printFailureLine( Outputter &stream, TestFailure* pFailure, std::string const& _sNodeName ); + virtual void printUnknownLine( Outputter &stream, std::string const& _sTestName); + }; + +/** insertion operator for easy output */ + Outputter &operator <<( Outputter &stream, + testshlTestResult &result ); + +} // namespace CppUnit + +#endif // CPPUNIT_testshlTESTRESULT_H + + diff --git a/cppunit/inc/cppunit/signaltest.h b/cppunit/inc/cppunit/signaltest.h new file mode 100644 index 000000000000..225790bc4ccc --- /dev/null +++ b/cppunit/inc/cppunit/signaltest.h @@ -0,0 +1,70 @@ +/************************************************************************* + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: signaltest.h,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: lla $ $Date: 2008-02-27 16:12:38 $ + * + * The Contents of this file are made available subject to + * the terms of GNU Lesser General Public License Version 2.1. + * + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2005 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + ************************************************************************/ + +#ifndef SIGNALTEST_H +#define SIGNALTEST_H + +#include <string> +#include "cppunit/Test.h" +#include <cppunit/autoregister/htestresult.h> + +namespace CppUnit +{ + +class CPPUNIT_API SignalTest : public Test +{ +public: + + SignalTest( std::string const& Name ); + + ~SignalTest(); + + virtual void run(hTestResult pResult); + virtual int countTestCases() const; + std::string getName() const; + std::string toString() const; + +private: + SignalTest( const SignalTest &other ); + SignalTest &operator=( const SignalTest &other ); + +private: + const std::string m_sName; +}; + +} // namespace CppUnit + + +#endif diff --git a/cppunit/inc/cppunit/simpleheader.hxx b/cppunit/inc/cppunit/simpleheader.hxx new file mode 100644 index 000000000000..811d2c6fce4d --- /dev/null +++ b/cppunit/inc/cppunit/simpleheader.hxx @@ -0,0 +1,50 @@ +/************************************************************************* + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: simpleheader.hxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: lla $ $Date: 2008-02-27 16:12:49 $ + * + * The Contents of this file are made available subject to + * the terms of GNU Lesser General Public License Version 2.1. + * + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2005 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + ************************************************************************/ + +#ifndef CPPUNIT_SIMPLEHEADER_HXX +#define CPPUNIT_SIMPLEHEADER_HXX + +// This file contains only the cppunit header files, for simplification. + +#include <cppunit/TestFixture.h> +#include <cppunit/TestCaller.h> +#include <cppunit/TestSuite.h> +#include <cppunit/TestAssert.h> +#include <cppunit/autoregister/registertestfunction.h> +#include <cppunit/extensions/HelperMacros.h> +#include <cppunit/additionalfunc.hxx> +#include <cppunit/cmdlinebits.hxx> + +#endif diff --git a/cppunit/inc/cppunit/stringhelper.hxx b/cppunit/inc/cppunit/stringhelper.hxx new file mode 100644 index 000000000000..bb43de094a95 --- /dev/null +++ b/cppunit/inc/cppunit/stringhelper.hxx @@ -0,0 +1,17 @@ +#ifndef STRINGHELPER_HXX +#define STRINGHELPER_HXX + +#ifndef _RTL_USTRING_HXX_ +#include <rtl/ustring.hxx> +#endif + +#ifndef _RTL_STRING_HXX_ +#include <rtl/string.hxx> +#endif + +inline void operator <<= (rtl::OString& _rAsciiString, const rtl::OUString& _rUnicodeString) +{ + _rAsciiString = rtl::OUStringToOString(_rUnicodeString,RTL_TEXTENCODING_ASCII_US); +} + +#endif diff --git a/cppunit/inc/cppunit/taghelper.hxx b/cppunit/inc/cppunit/taghelper.hxx new file mode 100644 index 000000000000..e13b1ee67eb0 --- /dev/null +++ b/cppunit/inc/cppunit/taghelper.hxx @@ -0,0 +1,96 @@ +/************************************************************************* + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: taghelper.hxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: lla $ $Date: 2008-02-27 16:09:01 $ + * + * The Contents of this file are made available subject to + * the terms of GNU Lesser General Public License Version 2.1. + * + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2005 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + ************************************************************************/ + +#ifndef TAGHELPER_HXX +#define TAGHELPER_HXX + +#include <map> +#include <sal/types.h> +#include <cppunit/nocopy.hxx> + +/* Tags are a general mechanism of extensible data arrays for parameter + * specification and property inquiry. In practice, tags are used in arrays, + * or chain of arrays. + * + */ + +typedef sal_IntPtr Tag; +typedef sal_IntPtr TagData; + +//# struct TagItem +//# { +//# Tag ti_Tag; /* identifies the type of data */ +//# TagData ti_Data; /* type-specific data */ +//# }; + +/* constants for Tag.ti_Tag, control tag values */ +#define TAG_DONE (Tag(0L)) /* terminates array of TagItems. ti_Data unused */ +#define TAG_END (Tag(0L)) /* synonym for TAG_DONE */ +#define TAG_IGNORE (Tag(1L)) /* ignore this item, not end of array */ +#define TAG_MORE (Tag(2L)) /* ti_Data is pointer to another array of TagItems + * note that this tag terminates the current array + */ +#define TAG_SKIP (Tag(3L)) /* skip this and the next ti_Data items */ + +/* differentiates user tags from control tags */ +#define TAG_USER (Tag(1L<<31)) + +// ----------------------------------------------------------------------------- +class TagHelper /* : NOCOPY */ +{ + typedef std::map<Tag, TagData> TagItems; + TagItems m_aTagItems; + +public: + TagHelper(){} + void insert(Tag _nTag, TagData _nData) + { + m_aTagItems[_nTag] = _nData; + } + // const TagItems& get() const { return m_aTagItems; } + + TagData GetTagData(Tag _aTagValue, TagData _aDefaultValue = 0 /* NULL */) const + { + TagItems::const_iterator it = m_aTagItems.find(_aTagValue); + if (it != m_aTagItems.end()) + return (*it).second; + else + return _aDefaultValue; + } +}; + +#endif + + diff --git a/cppunit/inc/cppunit/tagvalues.hxx b/cppunit/inc/cppunit/tagvalues.hxx new file mode 100644 index 000000000000..d73d132eb335 --- /dev/null +++ b/cppunit/inc/cppunit/tagvalues.hxx @@ -0,0 +1,86 @@ +/************************************************************************* + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: tagvalues.hxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: lla $ $Date: 2008-02-27 16:09:11 $ + * + * The Contents of this file are made available subject to + * the terms of GNU Lesser General Public License Version 2.1. + * + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2005 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + ************************************************************************/ + +#ifndef TAGVALUES_H +#define TAGVALUES_H + +#include <cppunit/taghelper.hxx> + +#define TAG_TYPE (Tag(TAG_USER | (0x01L))) + +#define TAG_RESULT (TAG_USER | 0x100) + +#define RESULT_START (Tag(TAG_RESULT | (0x02L))) +#define TAG_RESULT_PTR (Tag(TAG_RESULT | (0x03L))) +#define TAG_TEST_PTR (Tag(TAG_RESULT | (0x04L))) + +#define RESULT_END (Tag(TAG_RESULT | (0x05L))) + +#define RESULT_ADD_FAILURE (Tag(TAG_RESULT | (0x06L))) +#define RESULT_ADD_ERROR (Tag(TAG_RESULT | (0x07L))) + +#define TAG_EXCEPTION (Tag(TAG_RESULT | (0x08L))) + +#define RESULT_ADD_INFO (Tag(TAG_RESULT | (0x09L))) +#define TAG_INFO (Tag(TAG_RESULT | (0x0aL))) + +#define RESULT_ENTER_NODE (Tag(TAG_RESULT | (0x0bL))) +#define RESULT_LEAVE_NODE (Tag(TAG_RESULT | (0x0cL))) +#define TAG_NODENAME (Tag(TAG_RESULT | (0x0dL))) + +#define RESULT_SHOULD_STOP (Tag(TAG_RESULT | (0x0eL))) + + +#define TAG_SIGNAL (TAG_USER | 0x200) +// #define SIGNAL_CHECK (Tag(TAG_SIGNAL | (0x01L))) +// #define INIT_SIGNAL_HANDLING (Tag(TAG_SIGNAL | (0x04L))) +// #define RELEASE_SIGNAL_HANDLING (Tag(TAG_SIGNAL | (0x05L))) + +#define SIGNAL_START_TEST (Tag(TAG_SIGNAL | (0x06L))) +#define SIGNAL_END_TEST (Tag(TAG_SIGNAL | (0x07L))) + +#define TAG_EXECUTION (TAG_USER | 0x400) +#define EXECUTION_CHECK (Tag(TAG_EXECUTION | (0x01))) +#define INIT_TEST (Tag(TAG_EXECUTION | (0x02))) +#define RELEASE_TEST (Tag(TAG_EXECUTION | (0x03))) +// #define EXECUTION_PUSH_NAME (Tag(TAG_EXECUTION | (0x04))) +// #define EXECUTION_POP_NAME (Tag(TAG_EXECUTION | (0x05))) + +#define DO_NOT_EXECUTE 666 +#define GO_EXECUTE 1 + +typedef sal_Int32 ReturnValue; + +#endif diff --git a/cppunit/inc/makefile.mk b/cppunit/inc/makefile.mk new file mode 100644 index 000000000000..00e214404531 --- /dev/null +++ b/cppunit/inc/makefile.mk @@ -0,0 +1,56 @@ +#************************************************************************* +# +# OpenOffice.org - a multi-platform office productivity suite +# +# $RCSfile: makefile.mk,v $ +# +# $Revision: 1.1 $ +# +# last change: $Author: lla $ $Date: 2008-02-27 16:08:21 $ +# +# The Contents of this file are made available subject to +# the terms of GNU Lesser General Public License Version 2.1. +# +# +# GNU Lesser General Public License Version 2.1 +# ============================================= +# Copyright 2005 by Sun Microsystems, Inc. +# 901 San Antonio Road, Palo Alto, CA 94303, USA +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License version 2.1, as published by the Free Software Foundation. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, +# MA 02111-1307 USA +# +#************************************************************************* +PRJ=.. +# PRJINC=.. + +PRJNAME=cppunit +TARGET=inc + +# --- Settings ----------------------------------------------------- + +.INCLUDE : settings.mk + +# --- Files -------------------------------------------------------- +# --- Targets ------------------------------------------------------- + +.INCLUDE : target.mk + +.IF "$(ENABLE_PCH)"!="" +ALLTAR : \ + $(SLO)$/precompiled.pch \ + $(SLO)$/precompiled_ex.pch + +.ENDIF # "$(ENABLE_PCH)"!="" + diff --git a/cppunit/inc/testshl/autoregisterhelper.hxx b/cppunit/inc/testshl/autoregisterhelper.hxx new file mode 100644 index 000000000000..88653ba0b85d --- /dev/null +++ b/cppunit/inc/testshl/autoregisterhelper.hxx @@ -0,0 +1,67 @@ +/************************************************************************* + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: autoregisterhelper.hxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: lla $ $Date: 2008-02-27 16:19:14 $ + * + * The Contents of this file are made available subject to + * the terms of GNU Lesser General Public License Version 2.1. + * + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2005 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + ************************************************************************/ + +#ifndef AUTOREGISTER_HXX +#define AUTOREGISTER_HXX + +#include <vector> +#include <rtl/ustring.hxx> + +#include <cppunit/autoregister/testfunc.h> + +#include "dynamicregister.hxx" +#include "getopt.hxx" + +typedef std::vector<FktPtr> FunctionList; + +// ----------------------------------------------------------------------------- +class JobList; +class AutomaticRegisterHelper : public DynamicLibraryHelper +{ + FunctionList m_aFunctionList; + bool m_bLoadLibraryOK; + +public: + AutomaticRegisterHelper(rtl::OUString const& _sDLLName, GetOpt & _aOptions/* , JobList * _pJobList = NULL */ ); + + // FunctionList getFunctions(){return m_aFunctionList;} + void CallAll(hTestResult _hResult) const; + + /// @return true, if the given DLLName library could load and initialised. + bool isOkToStartTests() const {return m_bLoadLibraryOK;} +}; + +#endif + diff --git a/cppunit/inc/testshl/dynamicregister.hxx b/cppunit/inc/testshl/dynamicregister.hxx new file mode 100644 index 000000000000..a8bbdccf2488 --- /dev/null +++ b/cppunit/inc/testshl/dynamicregister.hxx @@ -0,0 +1,63 @@ +/************************************************************************* + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: dynamicregister.hxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: lla $ $Date: 2008-02-27 16:20:22 $ + * + * The Contents of this file are made available subject to + * the terms of GNU Lesser General Public License Version 2.1. + * + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2005 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + ************************************************************************/ + +#ifndef DYNAMICREGISTER_HXX +#define DYNAMICREGISTER_HXX + +#include <rtl/ustring.hxx> + +#ifndef _OSL_MODULE_HXX_ +#include <osl/module.hxx> +#endif + +#include "getopt.hxx" +#include "cppunit/nocopy.hxx" + +// ------------------------------------------------- + +class DynamicLibraryHelper : NOCOPY +{ +protected: + osl::Module* m_pModule; + rtl::OUString m_suDLLName; + GetOpt & m_aOptions; + +public: + DynamicLibraryHelper(rtl::OUString const& _sDLLName, GetOpt & _aOptions); + virtual ~DynamicLibraryHelper(); +}; + +#endif + diff --git a/cppunit/inc/testshl/filehelper.hxx b/cppunit/inc/testshl/filehelper.hxx new file mode 100644 index 000000000000..539ba7f0cdb0 --- /dev/null +++ b/cppunit/inc/testshl/filehelper.hxx @@ -0,0 +1,55 @@ +/************************************************************************* + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: filehelper.hxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: lla $ $Date: 2008-02-27 16:19:56 $ + * + * The Contents of this file are made available subject to + * the terms of GNU Lesser General Public License Version 2.1. + * + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2005 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + ************************************************************************/ + +#ifndef FILEHELPER_HXX +#define FILEHELPER_HXX + +#include <string> +#include <rtl/ustring.hxx> +#include <rtl/string.hxx> +#include <cppunit/cmdlinebits.hxx> +#include "getopt.hxx" + +namespace FileHelper +{ + + std::string getTempPath(); + rtl::OUString convertPath( rtl::OUString const& _suSysPath ); + rtl::OUString convertPath( rtl::OString const& sysPth ); + CmdLineBits createFlags( GetOpt & _aOptions ); + +} +#endif + diff --git a/cppunit/inc/testshl/getopt.hxx b/cppunit/inc/testshl/getopt.hxx new file mode 100644 index 000000000000..2a757b0b13f0 --- /dev/null +++ b/cppunit/inc/testshl/getopt.hxx @@ -0,0 +1,350 @@ +/************************************************************************* + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: getopt.hxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: lla $ $Date: 2008-02-27 16:20:09 $ + * + * The Contents of this file are made available subject to + * the terms of GNU Lesser General Public License Version 2.1. + * + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2005 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + ************************************************************************/ + +/************************************************************************* +#* class GetOpt +#* +#* +#* Implementation getopt.cxx +#* +#* Description: class to reflect the commandline options. In addition +#* it provides functinality to get options from an inifile +#* ( getIniOptions()), evaluate, test and get options +#* ( hasOpt(), getOpt() ) and display an usage screen +#* formated in dependance of the given optionset, as well +#* as display a status about activ options +#* +#* +#* further descriptions: +#* +#* the constructor is called with two parameters: +#* char* argv[] and char* optionSet[], +#* the commandline and the available set of options. +#* Valid optionstrings have to start with a minus '-', otherwise it will +#* be ignored. Optionstrings consist of one or two arguments divided by a +#* comma separator, where the second (optional) argument is a short +#* description of the option, called hint. It will be automatically +#* formated and displayed in the usage screen if available. +#* The first argument of the optionstring can consist of two sections, +#* the name and the optional necessity and format. +#* The name of the option will be the starting minus followed by a string +#* like "-src". +#* One section options will be treated as flag (see '-v' option in example). +#* The second section consist of '=' or ':' which defines the necessity, +#* in combination with a character 's' for string or 'n' for numeric and +#* an optional '@' standing for 'vector of'. +#* '=' means this option needs an argument, ':' means can take an argument +#* followed by 's' is, as mentioned above, a single string paramenter, +#* followed by a 's' in combination with '@' means this argument consists +#* of one string or a vector of strings separated by commas +#* +#* an example for an optionset: +#* +#* static char* optionSet[] = { +#* "-src=s, release or version of sources", +#* "-ini=s, ini file with additional options", +#* "-db=s, path of type description database", +#* "-inPth=s, source path of component descriptions", +#* "-outPth=s, destination path for testcases", +#* "-logPth=s, destination path for logging", +#* "-mdl=s@, name(s) of module(s) to generate", +#* "-v, enable verbose screen messages", +#* "-dbg, enable debug messages", +#* "-h:s, display help or help on option", +#* "-help:s, see -h", +#* NULL +#* }; +#* +#* As seen a GetOpt class object will be created via: +#* GetOpt myOptions( argv, optionSet ); +#* +*************************************************************************/ +#ifndef __QADEV_REGSCAN_GETOPT_HXX__ +#define __QADEV_REGSCAN_GETOPT_HXX__ + +#ifndef _OSL_FILE_HXX_ +#include <osl/file.hxx> +#endif + +#ifndef _SAL_TYPES_H_ +#include <sal/types.h> +#endif + +#ifndef _RTL_STRBUF_HXX_ +#include <rtl/strbuf.hxx> +#endif + + +#ifndef _RTL_STRING_HXX_ +#include <rtl/string.hxx> +#endif + +// #ifndef __QADEV_REGSCAN_UTIL_HXX__ +// #include "inc/util.hxx" +// #endif + + +#ifdef SOLARIS +#include <sys/time.h> +#endif + +#include <iostream> +#include <hash_map> +// #include "rsexception.hxx" + +// using namespace std; + +struct gstr { + sal_Bool operator()( const rtl::OString& oStr1, + const rtl::OString& oStr2 ) const { + return( oStr1 == oStr2 ); + } +}; + +struct ghstr +{ + sal_uInt32 operator()( const rtl::OString& str ) const { + return str.hashCode(); + } +}; + +struct frmt { + sal_uInt32 fCol; + sal_uInt32 sCol; + sal_uInt32 len; +}; + +typedef std::hash_map< rtl::OString, std::vector< rtl::OString >, ghstr, gstr > + optHashMap; + +typedef frmt sFormat; +typedef sal_uInt16 optType; + +#define OT_INVALID 0x0000 +#define OT_BOOL 0x0001 +#define OT_STRING 0x0002 +#define OT_NUMBER 0x0004 +#define OT_SINGLE 0x0010 +#define OT_MULTI 0x0020 +#define OT_OPTIONAL 0x0100 + +//: Option +class OptDsc { + + rtl::OString m_name; + rtl::OString m_hint; + rtl::OString m_legend; + optType m_type; + + /** + * analysis of optionstring and creation of option description class + * @param const rtl::OString& opt = optionstring to analyse + * @return void + */ + void createOptDsc( const rtl::OString& opt ); + + /** + * splitting of an optionstring and creation of a tokenvector + * in dependance of a charset + * + * @param const rtl::OString& opt = optionstring to split + * @param const rtl::OString& cSet = delimiter charset + * @param vector< rtl::OString >& optLine = tokenvector to fill + * + * @return void + */ + void split( const rtl::OString& opt, const rtl::OString& charSet, + std::vector< rtl::OString >& optLine ); + + /** + * private default c'tor, copy c'tor and assignment operator + * to get compiler errors on dumb effords + */ + OptDsc(); + OptDsc( OptDsc& ); + OptDsc& operator = ( OptDsc& ); + +public: + + //> c'tor + OptDsc( const rtl::OString& opt ) + : m_name(), + m_hint(), + m_legend(), + m_type( 0 ) { + + createOptDsc( opt ); + } ///< c'tor + + //> d'tor + ~OptDsc(){} + + /** + * returns the name of this option + * @return rtl::OString& + */ + inline rtl::OString& getName() { return m_name; } + /** + * returns the hint of this option + * @return rtl::OString& + */ + inline rtl::OString& getHint() { return m_hint; } + /** + * returns the legend of this option + * @return rtl::OString& + */ + inline rtl::OString& getLegend() { return m_legend; } + + /** + * returns the type of this option + * @return optType + */ + inline optType getType() { return m_type; } + + + inline sal_Bool isFlag() { + return( ( m_type &~ 0xfffe ) == OT_BOOL ) ? sal_True : sal_False; + } + inline sal_Bool isString() { + return( ( m_type &~ 0xfffd ) == OT_STRING ) ? sal_True : sal_False; + } + inline sal_Bool isNumber() { + return( ( m_type &~ 0xfffb ) == OT_NUMBER ) ? sal_True : sal_False; + } + inline sal_Bool isSingle() { + return( ( m_type &~ 0xffef ) == OT_SINGLE ) ? sal_True : sal_False; + } + inline sal_Bool isMulti() { + return( ( m_type &~ 0xffdf ) == OT_MULTI ) ? sal_True : sal_False; + } + inline sal_Bool isOptional() { + return( ( m_type &~ 0xfeff ) == OT_OPTIONAL ) ? sal_True : sal_False; + } + +}; ///:~ Option + +class Exception +{ + rtl::OString m_sAsciiMessage; +public: + Exception(); + virtual ~Exception(){} + + Exception(char const* sAsciiMessage); + Exception(rtl::OString const& sAsciiMessage); + + virtual rtl::OUString message() const; + virtual char const* what() const; +}; + +class ValueNotFoundException : public Exception +{ +public: + ValueNotFoundException(); + ValueNotFoundException(char const* sExit); +}; + +//: GetOpt +class GetOpt { + + rtl::OString m_prgname; + rtl::OString m_vardelim; + std::vector< rtl::OString > m_cmdline; + std::vector< rtl::OString > m_param; + std::vector< rtl::OString > m_varvec; + std::vector< OptDsc* > m_optionset; + optHashMap m_opthash; + + //> private methods + void initialize( char* cmdLine[], char const * optSet[] ); + void createCmdLineOptions(); + sal_uInt32 getMaxNameLength(); + sal_uInt32 getMaxLegendLength(); + const rtl::OString optDsc2Str( OptDsc* optDsc , sFormat frm ); + void tokenize( const rtl::OString& opt, const rtl::OString& charSet, + std::vector< rtl::OString >& optLine, sal_Bool strip = sal_True ); + ///< private methods + + GetOpt(); + GetOpt( GetOpt& ); + GetOpt& operator = ( GetOpt& ); + +public: + + //> c'tor + GetOpt( char* cmdLine[], char const * optSet[], rtl::OString varDelim = + rtl::OString( "$" ) ) + : m_vardelim( varDelim ) { + + initialize( cmdLine, optSet ); + createCmdLineOptions(); + } ///< c'tor + + //> d'tor + ~GetOpt(); + ///< d'tor + + //> inline methods + inline std::vector< rtl::OString >* getCmdLine() { return &m_cmdline; } + inline optHashMap* getOptions() { return ( &m_opthash ); } + inline rtl::OString& getName() { return m_prgname; } + inline rtl::OString& getFirstParam() { return *(m_param.begin()); } + inline std::vector< rtl::OString >& getParams() { return m_param; } + rtl::OString& getOpt( const rtl::OString& opt ); + void rmvOpt( rtl::OString& opt ) { + m_opthash.erase( opt ); + } + inline std::vector< rtl::OString >& getOptVec( const rtl::OString& opt ) { + return m_opthash[ opt ]; + } + ///< inline methods + + + sal_Bool exist( rtl::OString& opt ); + sal_Bool hasParam( std::vector< rtl::OString >::iterator iter ); + sal_Bool hasVars( void ); + sal_Bool evaluateOpt( std::vector< rtl::OString >::iterator iter ); + OptDsc* getOptDsc( rtl::OString& opt ); + sal_Bool hasOpt( const rtl::OString& opt ) const; + ::osl::FileBase::RC getIniOptions( rtl::OString iniPth ); + void createOpt( rtl::OString& optdsc ); + void str2Opt( rtl::OString iOpts ); + void addOpt( rtl::OString& opt, sal_Bool evaluate = sal_True ); + void replVars( void ); + void showUsage( void ); + void printStatus( void ); + +}; ///:~ GetOpt +#endif diff --git a/cppunit/inc/testshl/log.hxx b/cppunit/inc/testshl/log.hxx new file mode 100644 index 000000000000..a732406745d9 --- /dev/null +++ b/cppunit/inc/testshl/log.hxx @@ -0,0 +1,136 @@ +/************************************************************************* + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: log.hxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: lla $ $Date: 2008-02-27 16:18:51 $ + * + * The Contents of this file are made available subject to + * the terms of GNU Lesser General Public License Version 2.1. + * + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2005 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + ************************************************************************* + + Source Code Control System - Header + + $Header: /zpool/svn/migration/cvs_rep_09_09_08/code/cppunit/inc/testshl/log.hxx,v 1.1 2008-02-27 16:18:51 lla Exp $ + + Source Code Control System - Update + +*************************************************************************/ +#ifndef __QADEV_REGSCAN_LOG_HXX__ +#define __QADEV_REGSCAN_LOG_HXX__ + +#include <time.h> + +#ifndef _RTL_USTRING_HXX_ +#include <rtl/ustring.hxx> +#endif + +#ifndef _RTL_STRBUF_HXX_ +#include <rtl/strbuf.hxx> +#endif + +#ifndef _SAL_TYPES_H_ +#include <sal/types.h> +#endif + +#ifndef _OSL_THREAD_H_ +#include <osl/thread.h> +#endif + +#ifndef _OSL_FILE_HXX_ +#include <osl/file.hxx> +#endif + +//!io #include <iostream> +#include <vector> + +// using namespace std; + + +/** + * Log derives the interface of the ::osl::File class ( is-a relation ). + * Its members (has-a relation) are the (full qualified)name of the log + * and an OStringBuffer which represents the content of the logfile. + * It provides the functionality of easy-to-use open and write logs + */ +//: Log +class Log { + + ::osl::File* m_logfile; // fileobject + rtl::OUString m_logurl; // url of log + rtl::OStringBuffer m_buf; // content of log + + Log(); + +public: + + //> c'tor + /** + * constructors argument is a full qualified UNC path + * @param OUString logfile ( full qualified UNC path ) + */ + Log( const rtl::OUString& logURL ) + : m_logfile( new ::osl::File( logURL )) + , m_logurl(logURL) + {} ///< c'tor + + //> d'tor + virtual ~Log() { + m_logfile->close(); + delete( m_logfile ); + } ///< d'tor + + //> inline methods + // returns a reference to name instance + inline rtl::OUString getLogURL() { return m_logurl; } + inline rtl::OString getName() { return rtl::OUStringToOString( + m_logurl, RTL_TEXTENCODING_ASCII_US ); } + ///< inline methods + + // open logfile for overwrite (default) or append + ::osl::FileBase::RC open( sal_Bool append = sal_False ); + ::osl::FileBase::RC close() { return m_logfile->close(); } + + + // write methods without (default) or with echo on display + ::osl::FileBase::RC write( const sal_Char* buf, sal_Bool v = sal_False ); + ::osl::FileBase::RC write( const rtl::OString& buf, + sal_Bool v = sal_False ); + // ::osl::FileBase::RC write( rtl::OStringBuffer const& buf, + // sal_Bool v = sal_False ); + ::osl::FileBase::RC write( const rtl::OUString& buf, + rtl_TextEncoding enc = RTL_TEXTENCODING_ASCII_US, + sal_Bool v = sal_False ); + +}; ///:~ Log + +Log &operator <<( Log &_aLog, const sal_Char * _sValue ); +Log &operator <<( Log &_aLog, rtl::OString const& _sValue ); +Log &operator <<( Log &_aLog, rtl::OUString const& _sValue ); +// Log &operator <<( Log &_aLog, rtl::OStringBuffer const& _sValue ); + +#endif diff --git a/cppunit/inc/testshl/tresstatewrapper.h b/cppunit/inc/testshl/tresstatewrapper.h new file mode 100644 index 000000000000..b408bcb71717 --- /dev/null +++ b/cppunit/inc/testshl/tresstatewrapper.h @@ -0,0 +1,71 @@ +/************************************************************************* + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: tresstatewrapper.h,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: lla $ $Date: 2008-02-27 16:19:45 $ + * + * The Contents of this file are made available subject to + * the terms of GNU Lesser General Public License Version 2.1. + * + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2005 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + ************************************************************************/ + +#ifndef TESTSTATEWRAPPER_H +#define TESTSTATEWRAPPER_H + +#ifdef _RTL_TRES_H_ +#error "This is old code, please remove the include of rtl/tres.h" +#endif + +#include <sal/types.h> +#include "cppunit/autoregister/registertestfunction.h" + +#ifdef __cplusplus +extern "C" { +#endif + +// typedef void* hTestResult; +typedef hTestResult rtlTestResult; + +// ----------------------------------------------------------------------------- +void c_rtl_tres_state_start(hTestResult _aResult, const sal_Char* _pName); +void c_rtl_tres_state_end(hTestResult _aResult, const sal_Char* _pName); + +// ----------------------------------------------------------------------------- +// the old test state function, which here convert all values for using with the +// new testshl tool + +sal_Bool SAL_CALL c_rtl_tres_state( + hTestResult pResult, + sal_Bool bSuccess, + char const * pTestMsg, + char const * pFuncName); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/cppunit/inc/testshl/tresstatewrapper.hxx b/cppunit/inc/testshl/tresstatewrapper.hxx new file mode 100644 index 000000000000..61a9f6d95b8d --- /dev/null +++ b/cppunit/inc/testshl/tresstatewrapper.hxx @@ -0,0 +1,65 @@ +/************************************************************************* + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: tresstatewrapper.hxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: lla $ $Date: 2008-02-27 16:20:33 $ + * + * The Contents of this file are made available subject to + * the terms of GNU Lesser General Public License Version 2.1. + * + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2005 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + ************************************************************************/ + +#ifndef teststatewrapper_hxx +#define teststatewrapper_hxx + +#include <cppunit/nocopy.hxx> +#include <sal/types.h> + +#include <cppunit/simpleheader.hxx> +#include <cppunit/autoregister/callbackfunc_fktptr.h> + +// This is a hack, because it's possible that the testshl directory doesn't exist. +#ifdef LOAD_TRESSTATEWRAPPER_LOCAL +#include "tresstatewrapper.h" +#else +#include <testshl/tresstatewrapper.h> +#endif + +// ----------------------------------------------------------------------------- +// helper class to mark the start off old test code +// the name is need in the test result generator +class rtl_tres_state_start : NOCOPY +{ + const sal_Char* m_pName; + hTestResult m_aResult; +public: + rtl_tres_state_start(hTestResult _aResult, const sal_Char* _pName); + ~rtl_tres_state_start(); +}; + +#endif + diff --git a/cppunit/inc/testshl/versionhelper.hxx b/cppunit/inc/testshl/versionhelper.hxx new file mode 100644 index 000000000000..ce6516397f1d --- /dev/null +++ b/cppunit/inc/testshl/versionhelper.hxx @@ -0,0 +1,92 @@ +/************************************************************************* + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: versionhelper.hxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: lla $ $Date: 2008-02-27 16:19:03 $ + * + * The Contents of this file are made available subject to + * the terms of GNU Lesser General Public License Version 2.1. + * + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2005 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + ************************************************************************/ + +#ifndef AUTOREGISTER_HXX +#define AUTOREGISTER_HXX + +#include <stdio.h> +#include <vector> +#include <ostream> +#include <iostream> + +#include <rtl/ustring.hxx> +#include <rtl/string.hxx> + +#include "dynamicregister.hxx" + +// ----------------------------------------------------------------------------- +// ---------------------------------- Version ---------------------------------- +// ----------------------------------------------------------------------------- +// extern "C" const struct VersionInfo *GetVersionInfo(); + +// this is a Hack, but at the moment, no change to handle this behaviour better. +struct VersionInfo +{ + const char* pTime; + const char* pDate; + const char* pUpd; + const char* pMinor; + const char* pBuild; + const char* pInpath; +}; +typedef const struct VersionInfo* (*FktGetVersionInfoPtr)(); + +// ----------------------------------------------------------------------------- +class VersionHelper : public DynamicLibraryHelper +{ + const VersionInfo *m_pInfo; + +public: + VersionHelper(rtl::OUString const& _sDLLName, GetOpt & _aOptions); +// void print(std::ostream& _aStream); + void printall(FILE*); + + rtl::OString getTime() const; + rtl::OString getDate() const; + rtl::OString getUpd() const; + rtl::OString getMinor() const; + rtl::OString getBuild() const; + rtl::OString getInpath() const; + + bool isOk() const; +}; + +/** insertion operator for easy output */ +// std::ostream &operator <<( std::ostream &stream, +// VersionHelper &version ); + + +#endif + diff --git a/cppunit/inc/testshl/winstuff.hxx b/cppunit/inc/testshl/winstuff.hxx new file mode 100644 index 000000000000..26dd5f9af344 --- /dev/null +++ b/cppunit/inc/testshl/winstuff.hxx @@ -0,0 +1,48 @@ +/************************************************************************* + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: winstuff.hxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: lla $ $Date: 2008-02-27 16:19:26 $ + * + * The Contents of this file are made available subject to + * the terms of GNU Lesser General Public License Version 2.1. + * + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2005 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + ************************************************************************/ + +#ifndef WINSTUFF_HXX +#define WINSTUFF_HXX + +#include <sal/types.h> + +// Isolated into own compilation unit, to avoid interference with +// windows headers +void WinDebugBreak(); +void WinSleep( sal_uInt32 sec ); +sal_uInt32 WinGetCurrentProcessId(); +void WinTerminateApp( sal_uInt32 dwPID, sal_uInt32 dwTimeout ); + +#endif diff --git a/cppunit/prj/build.lst b/cppunit/prj/build.lst new file mode 100644 index 000000000000..f904fbbe98df --- /dev/null +++ b/cppunit/prj/build.lst @@ -0,0 +1,6 @@ +c5t cppunit : sal NULL +c5t cppunit usr1 - all c5t_mkout NULL +c5t cppunit\inc nmake - all c5t_inc NULL +c5t cppunit\source\win32 nmake - w c5t_win c5t_inc NULL +c5t cppunit\source\cppunit nmake - all c5t_cpp c5t_inc NULL +c5t cppunit\source\result nmake - all c5t_res c5t_inc NULL diff --git a/cppunit/prj/d.lst b/cppunit/prj/d.lst new file mode 100644 index 000000000000..db62b92af2ce --- /dev/null +++ b/cppunit/prj/d.lst @@ -0,0 +1,23 @@ +mkdir: %_DEST%\inc%_EXT%\cppunit +mkdir: %_DEST%\inc%_EXT%\cppunit\portability +mkdir: %_DEST%\inc%_EXT%\cppunit\autoregister +mkdir: %_DEST%\inc%_EXT%\cppunit\extensions +mkdir: %_DEST%\inc%_EXT%\cppunit\result +mkdir: %_DEST%\inc%_EXT%\testshl + +..\inc\cppunit\*.h %_DEST%\inc%_EXT%\cppunit\*.h +..\inc\cppunit\*.hxx %_DEST%\inc%_EXT%\cppunit\*.hxx +..\inc\cppunit\autoregister\*.h %_DEST%\inc%_EXT%\cppunit\autoregister\*.h +..\inc\cppunit\extensions\*.h %_DEST%\inc%_EXT%\cppunit\extensions\*.h +..\inc\cppunit\portability\*.h %_DEST%\inc%_EXT%\cppunit\portability\*.h +..\inc\cppunit\result\*.h %_DEST%\inc%_EXT%\cppunit\result\*.h +..\inc\cppunit\result\*.hxx %_DEST%\inc%_EXT%\cppunit\result\*.hxx +..\inc\testshl\*.hxx %_DEST%\inc%_EXT%\testshl\*.hxx +..\inc\testshl\*.h %_DEST%\inc%_EXT%\testshl\*.h + + + +..\%__SRC%\lib\cppunit.lib %_DEST%\lib%_EXT%\cppunit.lib +..\%__SRC%\lib\c5t_*.lib %_DEST%\lib%_EXT%\c5t_*.lib +..\%__SRC%\lib\*.a %_DEST%\lib%_EXT%\*.a + diff --git a/cppunit/source/cppunit/Asserter.cpp b/cppunit/source/cppunit/Asserter.cpp new file mode 100644 index 000000000000..904ed7800b8a --- /dev/null +++ b/cppunit/source/cppunit/Asserter.cpp @@ -0,0 +1,81 @@ +#include <cppunit/Asserter.h> +#include <cppunit/NotEqualException.h> +#include <cppunit/stringhelper.hxx> + +namespace CppUnit +{ + + +namespace Asserter +{ + +void +fail( std::string const& message, + SourceLine const& sourceLine ) +{ + throw Exception( message, sourceLine ); +} + +void +failStub( std::string const& message, + SourceLine const& sourceLine ) +{ + throw StubException( message, sourceLine ); +} + + +void +failIf( bool shouldFail, + std::string const& message, + SourceLine const& location ) +{ + if ( shouldFail ) + { + fail( message, location ); + } +} + +// ----------------------------------------------------------------------------- +void +failIf( bool shouldFail, + rtl::OUString const& _suMessage, + SourceLine const& location ) +{ + if ( shouldFail ) + { + rtl::OString sMessage; + sMessage <<= _suMessage; + std::string message; + message = sMessage.getStr(); + fail( message, location ); + } +} +// ----------------------------------------------------------------------------- + +void +failNotEqual( std::string const& expected, + std::string const& actual, + SourceLine const& sourceLine, + std::string const& additionalMessage ) +{ + throw NotEqualException( expected, + actual, + sourceLine, + additionalMessage ); +} + + +void +failNotEqualIf( bool shouldFail, + std::string const& expected, + std::string const& actual, + SourceLine const& sourceLine, + std::string const& additionalMessage ) +{ + if ( shouldFail ) + failNotEqual( expected, actual, sourceLine, additionalMessage ); +} + + +} // namespace Asserter +} // namespace CppUnit diff --git a/cppunit/source/cppunit/Exception.cpp b/cppunit/source/cppunit/Exception.cpp new file mode 100644 index 000000000000..c6284139e37d --- /dev/null +++ b/cppunit/source/cppunit/Exception.cpp @@ -0,0 +1,134 @@ +#include "cppunit/Exception.h" + + +namespace CppUnit { + + +#ifdef CPPUNIT_ENABLE_SOURCELINE_DEPRECATED +/*! + * \deprecated Use SourceLine::isValid() instead. + */ +const std::string Exception::UNKNOWNFILENAME = "<unknown>"; + +/*! + * \deprecated Use SourceLine::isValid() instead. + */ +const long Exception::UNKNOWNLINENUMBER = -1; +#endif + + +/// Construct the exception +Exception::Exception( const Exception &other ) : + std::exception( other ), + m_message( other.m_message), + m_sourceLine(other.m_sourceLine) +{} + + +/*! + * \deprecated Use other constructor instead. + */ +Exception::Exception( std::string const& _message, + SourceLine const& _sourceLine ) : + m_message( _message ), + m_sourceLine( _sourceLine ) +{ +} + + +#ifdef CPPUNIT_ENABLE_SOURCELINE_DEPRECATED +/*! + * \deprecated Use other constructor instead. + */ +Exception::Exception( std::string const& message, + long lineNumber, + std::string const& fileName ) : + m_message( message ), + m_sourceLine( fileName, lineNumber ) +{ +} +#endif + + +/// Destruct the exception +Exception::~Exception () throw() +{ +} + + +/// Perform an assignment +Exception& +Exception::operator =( const Exception& other ) +{ +// Don't call superclass operator =(). VC++ STL implementation +// has a bug. It calls the destructor and copy constructor of +// std::exception() which reset the virtual table to std::exception. +// SuperClass::operator =(other); + + if ( &other != this ) + { + m_message = other.m_message; + m_sourceLine = other.m_sourceLine; + } + + return *this; +} + + +/// Return descriptive message +const char* +Exception::what() const throw() +{ + return m_message.c_str (); +} + +/// Location where the error occured +SourceLine +Exception::sourceLine() const +{ + return m_sourceLine; +} + + +#ifdef CPPUNIT_ENABLE_SOURCELINE_DEPRECATED +/// The line on which the error occurred +long +Exception::lineNumber() const +{ + return m_sourceLine.isValid() ? m_sourceLine.lineNumber() : + UNKNOWNLINENUMBER; +} + + +/// The file in which the error occurred +std::string +Exception::fileName() const +{ + return m_sourceLine.isValid() ? m_sourceLine.fileName() : + UNKNOWNFILENAME; +} +#endif + + +Exception * +Exception::clone() const +{ + return new Exception( *this ); +} + + +bool +Exception::isInstanceOf( const Type &exceptionType ) const +{ + return exceptionType == type(); +} + + +Exception::Type +Exception::type() +{ + return Type( "CppUnit::Exception" ); +} + + +} // namespace CppUnit diff --git a/cppunit/source/cppunit/NotEqualException.cpp b/cppunit/source/cppunit/NotEqualException.cpp new file mode 100644 index 000000000000..78168e50acf5 --- /dev/null +++ b/cppunit/source/cppunit/NotEqualException.cpp @@ -0,0 +1,111 @@ +#include <cppunit/NotEqualException.h> + +namespace CppUnit { + + +NotEqualException::NotEqualException( std::string const& _expected, + std::string const& _actual, + SourceLine const& _sourceLine , + std::string const& _additionalMessage ) : + Exception( "Expected: " + _expected + + ", but was: " + _actual + + "." + _additionalMessage , + _sourceLine), + m_expected( _expected ), + m_actual( _actual ), + m_additionalMessage( _additionalMessage ) +{ +} + + +#ifdef CPPUNIT_ENABLE_SOURCELINE_DEPRECATED +/*! + * \deprecated Use other constructor instead. + */ +NotEqualException::NotEqualException( std::string const& expected, + std::string const& actual, + long lineNumber, + std::string const& fileName ) : + Exception( "Expected: " + expected + ", but was: " + actual, + lineNumber, + fileName ), + m_expected( expected ), + m_actual( actual ) +{ +} +#endif + + +NotEqualException::NotEqualException( const NotEqualException &other ) : + Exception( other ), + m_expected( other.m_expected ), + m_actual( other.m_actual ), + m_additionalMessage( other.m_additionalMessage ) +{ +} + + +NotEqualException::~NotEqualException() throw() +{ +} + + +NotEqualException & +NotEqualException::operator =( const NotEqualException &other ) +{ + Exception::operator =( other ); + + if ( &other != this ) + { + m_expected = other.m_expected; + m_actual = other.m_actual; + m_additionalMessage = other.m_additionalMessage; + } + return *this; +} + + +Exception * +NotEqualException::clone() const +{ + return new NotEqualException( *this ); +} + + +bool +NotEqualException::isInstanceOf( const Type &exceptionType ) const +{ + return exceptionType == type() || + Exception::isInstanceOf( exceptionType ); +} + + +Exception::Type +NotEqualException::type() +{ + return Type( "CppUnit::NotEqualException" ); +} + + +std::string +NotEqualException::expectedValue() const +{ + return m_expected; +} + + +std::string +NotEqualException::actualValue() const +{ + return m_actual; +} + + +std::string +NotEqualException::additionalMessage() const +{ + return m_additionalMessage; +} + + +} // namespace CppUnit diff --git a/cppunit/source/cppunit/SourceLine.cpp b/cppunit/source/cppunit/SourceLine.cpp new file mode 100644 index 000000000000..768e22340c06 --- /dev/null +++ b/cppunit/source/cppunit/SourceLine.cpp @@ -0,0 +1,62 @@ +#include <cppunit/SourceLine.h> + + +namespace CppUnit +{ + +SourceLine::SourceLine() : + m_lineNumber( -1 ) +{ +} + + +SourceLine::SourceLine( const std::string &file, + int line ) : + m_fileName( file ), + m_lineNumber( line ) +{ +} + + +SourceLine::~SourceLine() +{ +} + + +bool +SourceLine::isValid() const +{ + return !m_fileName.empty(); +} + + +int +SourceLine::lineNumber() const +{ + return m_lineNumber; +} + + +std::string +SourceLine::fileName() const +{ + return m_fileName; +} + + +bool +SourceLine::operator ==( const SourceLine &other ) const +{ + return m_fileName == other.m_fileName && + m_lineNumber == other.m_lineNumber; +} + + +bool +SourceLine::operator !=( const SourceLine &other ) const +{ + return !( *this == other ); +} + + +} // namespace CppUnit diff --git a/cppunit/source/cppunit/TestAssert.cpp b/cppunit/source/cppunit/TestAssert.cpp new file mode 100644 index 000000000000..b5bee33e03c2 --- /dev/null +++ b/cppunit/source/cppunit/TestAssert.cpp @@ -0,0 +1,74 @@ +#ifdef HAVE_CMATH +# include <cmath> +#else +# include <math.h> +#endif + +#include <cppunit/TestAssert.h> +#include <cppunit/NotEqualException.h> + + +namespace CppUnit { + + +#ifdef CPPUNIT_ENABLE_SOURCELINE_DEPRECATED +/// Check for a failed general assertion +void +TestAssert::assertImplementation( bool condition, + std::string conditionExpression, + long lineNumber, + std::string fileName ) +{ + Asserter::failIf( condition, + conditionExpression, + SourceLine( fileName, lineNumber ) ); +} + + +/// Reports failed equality +void +TestAssert::assertNotEqualImplementation( std::string expected, + std::string actual, + long lineNumber, + std::string fileName ) +{ + Asserter::failNotEqual( expected, + actual, + SouceLine( fileName, lineNumber ), "" ); +} + + +/// Check for a failed equality assertion +void +TestAssert::assertEquals( double expected, + double actual, + double delta, + long lineNumber, + std::string fileName ) +{ + if (fabs (expected - actual) > delta) + assertNotEqualImplementation( assertion_traits<double>::toString(expected), + assertion_traits<double>::toString(actual), + lineNumber, + fileName ); +} + +#else // CPPUNIT_ENABLE_SOURCELINE_DEPRECATED + +void +TestAssert::assertDoubleEquals( double expected, + double actual, + double delta, + SourceLine sourceLine ) +{ + Asserter::failNotEqualIf( fabs( expected - actual ) > delta, + assertion_traits<double>::toString(expected), + assertion_traits<double>::toString(actual), + sourceLine ); +} + + +#endif + + +} diff --git a/cppunit/source/cppunit/TestCase.cpp b/cppunit/source/cppunit/TestCase.cpp new file mode 100644 index 000000000000..e27f45a7fc6f --- /dev/null +++ b/cppunit/source/cppunit/TestCase.cpp @@ -0,0 +1,211 @@ +#include <stdlib.h> +#include <cppunit/Portability.h> +#include <typeinfo> +#include <stdexcept> + +#include "cppunit/TestCase.h" +#include "cppunit/Exception.h" +// #include "cppunit/TestResult.h" + +#include <cppunit/autoregister/callbackfunc_fktptr.h> +#include <cppunit/tagvalues.hxx> +#include <cppunit/externcallbackfunc.hxx> + +namespace CppUnit { + +/// Create a default TestResult +//# CppUnit::TestResult* +//# TestCase::defaultResult() +//# { +//# return new TestResult; +//# } + + +/// Run the test and catch any exceptions that are triggered by it +//# void +//# TestCase::run( TestResult *result ) +//# { +//# result->startTest(this); +//# +//# try { +//# setUp(); +//# +//# try { +//# runTest(); +//# } +//# catch ( Exception &e ) { +//# Exception *copy = e.clone(); +//# result->addFailure( this, copy ); +//# } +//# catch ( std::exception &e ) { +//# result->addError( this, new Exception( e.what() ) ); +//# } +//# catch (...) { +//# Exception *e = new Exception( "caught unknown exception" ); +//# result->addError( this, e ); +//# } +//# +//# try { +//# tearDown(); +//# } +//# catch (...) { +//# result->addError( this, new Exception( "tearDown() failed" ) ); +//# } +//# } +//# catch (...) { +//# result->addError( this, new Exception( "setUp() failed" ) ); +//# } +//# +//# result->endTest( this ); +//# } +//# + +void +TestCase::run( hTestResult result ) +{ + Test* pTest = this; + + // if (signalCheck(pTest->getName()) == HAS_SIGNAL) + sal_Int32 nValue = (pCallbackFunc)(0 /* NULL */, TAG_TYPE, EXECUTION_CHECK, TAG_RESULT_PTR, result, TAG_NODENAME, pTest->getName().c_str(), TAG_DONE); + if (nValue == DO_NOT_EXECUTE) + { + return; + } + + // (pTestResult_StartTest)(result, pTest); + (pCallbackFunc)(0 /* NULL */, TAG_TYPE, RESULT_START, TAG_RESULT_PTR, result, TAG_TEST_PTR, pTest, TAG_DONE); + + try + { + setUp(); + + try + { + runTest(); + // (pTestResult_AddInfo)(result, pTest, "PASSED"); + (pCallbackFunc)(0 /* NULL */, TAG_TYPE, RESULT_ADD_INFO, TAG_RESULT_PTR, result, TAG_TEST_PTR, pTest, TAG_INFO, "PASSED", TAG_DONE); + } + catch ( StubException &) + { + (pCallbackFunc)(0 /* NULL */, TAG_TYPE, RESULT_ADD_INFO, TAG_RESULT_PTR, result, TAG_TEST_PTR, pTest, TAG_INFO, "STUB", TAG_DONE ); + } + catch ( Exception &e ) + { + Exception *copy = e.clone(); + // (pTestResult_AddFailure)( result, pTest, copy ); + (pCallbackFunc)(0 /* NULL */, TAG_TYPE, RESULT_ADD_FAILURE, TAG_RESULT_PTR, result, TAG_TEST_PTR, pTest, TAG_EXCEPTION, copy, TAG_DONE ); + } + catch ( std::exception &e ) + { + // (pTestResult_AddError)( result, pTest, new Exception( e.what() ) ); + (pCallbackFunc)( 0 /* NULL */, TAG_TYPE, RESULT_ADD_ERROR, TAG_RESULT_PTR, result, TAG_TEST_PTR, pTest, TAG_EXCEPTION, new Exception( e.what() ), TAG_DONE ); + } + catch (...) + { + Exception *e = new Exception( "caught unknown exception" ); + // (pTestResult_AddError)( result, pTest, e ); + (pCallbackFunc)( 0 /* NULL */, TAG_TYPE, RESULT_ADD_ERROR, TAG_RESULT_PTR, result, TAG_TEST_PTR, pTest, TAG_EXCEPTION, e, TAG_DONE ); + } + + try + { + tearDown(); + } + catch (...) + { + // (pTestResult_AddError)( result, pTest, new Exception( "tearDown() failed" ) ); + (pCallbackFunc)( 0 /* NULL */, TAG_TYPE, RESULT_ADD_ERROR, TAG_RESULT_PTR, result, TAG_TEST_PTR, pTest, TAG_EXCEPTION, new Exception( "tearDown() failed" ), TAG_DONE ); + } + } + catch (...) + { + // (pTestResult_AddError)( result, pTest, new Exception( "setUp() failed" ) ); + (pCallbackFunc)( 0 /* NULL */, TAG_TYPE, RESULT_ADD_ERROR, TAG_RESULT_PTR, result, TAG_TEST_PTR, pTest, TAG_EXCEPTION, new Exception( "setUp() failed" ), TAG_DONE ); + } + + // (pTestResult_EndTest)( result, pTest ); + (pCallbackFunc)( 0 /* NULL */, TAG_TYPE, RESULT_END, TAG_RESULT_PTR, result, TAG_TEST_PTR, pTest, TAG_DONE ); +} + +/// A default run method +//# TestResult * +//# TestCase::run() +//# { +//# TestResult *result = defaultResult(); +//# +//# run (result); +//# return result; +//# } + + +/// All the work for runTest is deferred to subclasses +void +TestCase::runTest() +{ +} + + +/** Constructs a test case. + * \param name the name of the TestCase. + **/ +TestCase::TestCase( std::string const& name ) + : m_name(name) +{ +} + + +/** Constructs a test case for a suite. + * This TestCase is intended for use by the TestCaller and should not + * be used by a test case for which run() is called. + **/ +TestCase::TestCase() + : m_name( "" ) +{ +} + + +/// Destructs a test case +TestCase::~TestCase() +{ +} + + +/// Returns a count of all the tests executed +int +TestCase::countTestCases() const +{ + return 1; +} + + +/// Returns the name of the test case +std::string +TestCase::getName() const +{ + return m_name; +} + + +/// Returns the name of the test case instance +std::string +TestCase::toString() const +{ + std::string className; + +#if CPPUNIT_USE_TYPEINFO_NAME + const std::type_info& thisClass = typeid( *this ); + className = thisClass.name(); +#else + className = "TestCase"; +#endif + + return className + "." + getName(); +} + + +} // namespace CppUnit + +// The following sets variables for GNU EMACS +// Local Variables: +// tab-width:4 +// End: diff --git a/cppunit/source/cppunit/TestFactoryRegistry.cpp b/cppunit/source/cppunit/TestFactoryRegistry.cpp new file mode 100644 index 000000000000..8950e9191e9b --- /dev/null +++ b/cppunit/source/cppunit/TestFactoryRegistry.cpp @@ -0,0 +1,290 @@ +#include <stdio.h> +#include <stdlib.h> +#include <cppunit/extensions/TestFactoryRegistry.h> +#include <cppunit/TestSuite.h> + +#include <set> +//!io #include <iostream> +#include <sstream> + +#if CPPUNIT_USE_TYPEINFO_NAME +# include "cppunit/extensions/TypeInfoHelper.h" +#endif + +#include <cppunit/externcallbackfunc.hxx> +#include <cppunit/tagvalues.hxx> + +#undef HELLOWORLD_DEBUGGER + +namespace CppUnit { + +/** (Implementation) This class manages all the TestFactoryRegistry. + * + * Responsible for the life-cycle of the TestFactoryRegistry. + * + * TestFactory registry must call wasDestroyed() to indicate that + * a given TestRegistry was destroyed, and needDestroy() to + * know if a given TestFactory need to be destroyed (was not already + * destroyed by another TestFactoryRegistry). + */ +class NamedRegistries +{ +public: + ~NamedRegistries(); + + static NamedRegistries &getInstance(); + + TestFactoryRegistry &getRegistry( std::string const& name ); + + void wasDestroyed( TestFactory *factory ); + + bool needDestroy( TestFactory *factory ); + + void testRegistries( hTestResult ); +private: + typedef std::map<std::string, TestFactoryRegistry *> MapRegistries; + // typedef std::pair<std::string, TestFactoryRegistry *> StringTestFactoryRegistry; + // typedef std::vector< StringTestFactoryRegistry > MapRegistries; + MapRegistries m_registries; + + typedef std::set<TestFactory *> Factories; + Factories m_factoriesToDestroy; + Factories m_destroyedFactories; +}; + + +NamedRegistries::~NamedRegistries() +{ +#ifdef HELLOWORLD_DEBUGGER + printf("~NamedRegistries.\n"); +#endif + MapRegistries::iterator it = m_registries.begin(); + while ( it != m_registries.end() ) + { + TestFactoryRegistry *registry = (it++)->second; + if ( needDestroy( registry ) ) + delete registry; + } +/* + for (MapRegistries::iterator it = m_registries.begin(); + it != m_registries.end(); + ++it) + { + StringTestFactoryRegistry stfr = *it; + TestFactoryRegistry *registry = stfr.second; + if ( needDestroy( registry ) ) + delete registry; + } +*/ +} + + +NamedRegistries & +NamedRegistries::getInstance() +{ + static NamedRegistries namedRegistries; + return namedRegistries; +} + + +TestFactoryRegistry & +NamedRegistries::getRegistry( std::string const& name ) +{ +#ifdef HELLOWORLD_DEBUGGER + printf("getRegistry '%s', ", name.c_str()); +#endif + MapRegistries::const_iterator foundIt = m_registries.find( name ); + if ( foundIt == m_registries.end() ) + { + TestFactoryRegistry *factory = new TestFactoryRegistry( name ); + // m_registries.insert( std::make_pair( name, factory ) ); + m_registries[name] = factory; + m_factoriesToDestroy.insert( factory ); + +#ifdef HELLOWORLD_DEBUGGER + printf("factory not found, create.\n"); +#endif + return *factory; + } +#ifdef HELLOWORLD_DEBUGGER + printf("factory found.\n"); +#endif + return *foundIt->second; +/* + // MapRegistries::const_iterator foundIt; + TestFactoryRegistry *pFound = NULL; + for (MapRegistries::const_iterator it = m_registries.begin(); + it != m_registries.end(); + ++it) + { + StringTestFactoryRegistry stfr = *it; + if (name == stfr.first) + { + pFound = stfr.second; + break; + } + } + + // MapRegistries::const_iterator foundIt = m_registries.find( name ); + if ( pFound != NULL ) + { + TestFactoryRegistry *factory = new TestFactoryRegistry( name ); + // m_registries.insert( std::make_pair( name, factory ) ); + StringTestFactoryRegistry stfr = std::make_pair(name, factory); + m_registries.push_back(stfr); + m_factoriesToDestroy.insert( factory ); + return *factory; + } + return *pFound; +*/ +} + + +void +NamedRegistries::wasDestroyed( TestFactory *factory ) +{ + m_factoriesToDestroy.erase( factory ); + m_destroyedFactories.insert( factory ); +} + + +bool +NamedRegistries::needDestroy( TestFactory *factory ) +{ + return m_destroyedFactories.count( factory ) == 0; +} + +void NamedRegistries::testRegistries( hTestResult _pResult) +{ + // initialise the test handling + (pCallbackFunc)(0 /* NULL */, TAG_TYPE, INIT_TEST, TAG_RESULT_PTR, _pResult, TAG_DONE); + + // Start signal based Check + for (MapRegistries::const_iterator it = m_registries.begin(); + it != m_registries.end(); + ++it) + { + std::string sName = (*it).first; + + CppUnit::Test* tp = CppUnit::TestFactoryRegistry::getRegistry(sName).makeTest(); + tp->run(_pResult); + } + + // release test handling + (pCallbackFunc)(0 /* NULL */, TAG_TYPE, RELEASE_TEST, TAG_RESULT_PTR, _pResult, TAG_DONE); + // start normal based tests, leave signal signed tests out. + + //! Allfunction in the inclusion list which has a flag, not found, has to call here. +} + +// ----------------------------------------------------------------------------- + +TestFactoryRegistry::TestFactoryRegistry( std::string const& name ) : + m_name( name ) +{ +} + + +TestFactoryRegistry::~TestFactoryRegistry() +{ + // The wasDestroyed() and needDestroy() is used to prevent + // a double destruction of a factory registry. + // registerFactory( "All Tests", getRegistry( "Unit Tests" ) ); + // => the TestFactoryRegistry "Unit Tests" is owned by both + // the "All Tests" registry and the NamedRegistries... + NamedRegistries::getInstance().wasDestroyed( this ); + + for ( Factories::iterator it = m_factories.begin(); it != m_factories.end(); ++it ) + { + TestFactory *factory = it->second; + if ( NamedRegistries::getInstance().needDestroy( factory ) ) + delete factory; + } +} + +// static +TestFactoryRegistry & +TestFactoryRegistry::getRegistry() +{ + return getRegistry( "All Tests" ); +} + +// static +TestFactoryRegistry & +TestFactoryRegistry::getRegistry( const std::string &name ) +{ + return NamedRegistries::getInstance().getRegistry( name ); +} + +// static +void TestFactoryRegistry::testRegistries( hTestResult _pResult ) +{ + NamedRegistries::getInstance().testRegistries( _pResult ); +} + + +void +TestFactoryRegistry::registerFactory( const std::string &name, + TestFactory *factory ) +{ +#ifdef HELLOWORLD_DEBUGGER + printf("registerFactory %s\n", name.c_str()); +#endif + m_factories[name] = factory; +#ifdef HELLOWORLD_DEBUGGER + printf("FactorySize: %d\n ", m_factories.size()); +#endif +} + + +void +TestFactoryRegistry::registerFactory( TestFactory *factory ) +{ + static int serialNumber = 1; + + std::string aStr("@Dummy@_"); + + sal_Char cBuf[20]; + sal_Char *pBuf = cBuf; + sprintf(pBuf, "%d", serialNumber++ ); + + aStr += std::string(pBuf); + + // LLA: this does not work within Solaris, could be a problem of the osl::Module::load? + // std::ostringstream ost; + // ost << "@Dummy@" << nValue; + // registerFactory( ost.str(), factory ); + +#ifdef HELLOWORLD_DEBUGGER + printf("aStr: %s\n", aStr.c_str()); +#endif + registerFactory( aStr, factory ); +} + + +Test * +TestFactoryRegistry::makeTest() +{ + TestSuite *suite = new TestSuite( m_name ); + addTestToSuite( suite ); + return suite; +} + + +void +TestFactoryRegistry::addTestToSuite( TestSuite *suite ) +{ +#ifdef HELLOWORLD_DEBUGGER + printf("addTestToSuite %s\n", suite->getName().c_str()); +#endif + for ( Factories::iterator it = m_factories.begin(); + it != m_factories.end(); + ++it ) + { + TestFactory *factory = (*it).second; + suite->addTest( factory->makeTest() ); + } +} + + +} // namespace CppUnit diff --git a/cppunit/source/cppunit/TestFailure.cpp b/cppunit/source/cppunit/TestFailure.cpp new file mode 100644 index 000000000000..2c0991b26a21 --- /dev/null +++ b/cppunit/source/cppunit/TestFailure.cpp @@ -0,0 +1,86 @@ +#include "cppunit/Exception.h" +#include "cppunit/Test.h" +#include "cppunit/TestFailure.h" + +namespace CppUnit { + +/// Constructs a TestFailure with the given test and exception. +TestFailure::TestFailure( Test *failed, + Exception *_thrownException, + ErrorType::num eError ) : + m_failedTest( failed ), + m_thrownException( _thrownException ), + m_eError( eError ) +{ +} + +/// Deletes the owned exception. +TestFailure::~TestFailure() +{ + delete m_thrownException; +} + +/// Gets the failed test. +Test * +TestFailure::failedTest() const +{ + return m_failedTest; +} + + +/// Gets the thrown exception. Never \c NULL. +Exception * +TestFailure::thrownException() const +{ + return m_thrownException; +} + + +/// Gets the failure location. +SourceLine +TestFailure::sourceLine() const +{ + return m_thrownException->sourceLine(); +} + + +/// Indicates if the failure is a failed assertion or an error. +bool +TestFailure::isError() const +{ + if (m_eError == ErrorType::ET_ERROR || + m_eError == ErrorType::ET_SIGNAL) + return true; + return false; +} + +ErrorType::num +TestFailure::getErrorType() const +{ + return m_eError; +} + + +/// Gets the name of the failed test. +std::string +TestFailure::failedTestName() const +{ + return m_failedTest->getName(); +} + + +/// Returns a short description of the failure. +std::string +TestFailure::toString() const +{ + return m_failedTest->toString() + ": " + m_thrownException->what(); +} + + +TestFailure * +TestFailure::clone() const +{ + return new TestFailure( m_failedTest, m_thrownException->clone(), m_eError ); +} + +} // namespace CppUnit diff --git a/cppunit/source/cppunit/TestSuite.cpp b/cppunit/source/cppunit/TestSuite.cpp new file mode 100644 index 000000000000..24429f02926b --- /dev/null +++ b/cppunit/source/cppunit/TestSuite.cpp @@ -0,0 +1,113 @@ +#include <stdlib.h> +#include "cppunit/TestSuite.h" +// #include "cppunit/TestResult.h" +#include <cppunit/tagvalues.hxx> +#include <cppunit/autoregister/callbackfunc_fktptr.h> +#include <cppunit/externcallbackfunc.hxx> + +namespace CppUnit { + +/// Default constructor +TestSuite::TestSuite( std::string const& name ) + : m_name( name ) +{ +} + + +/// Destructor +TestSuite::~TestSuite() +{ + deleteContents(); +} + + +/// Deletes all tests in the suite. +void +TestSuite::deleteContents() +{ + for ( std::vector<Test *>::iterator it = m_tests.begin(); + it != m_tests.end(); + ++it) + delete *it; + m_tests.clear(); +} + + +/// Runs the tests and collects their result in a TestResult. + +void +TestSuite::run( hTestResult result ) +{ + // (pTestResult_EnterNode)(result, getName().c_str()); + (pCallbackFunc)(0 /* NULL */, TAG_TYPE, RESULT_ENTER_NODE, TAG_RESULT_PTR, result, TAG_NODENAME, getName().c_str(), TAG_DONE); + for ( std::vector<Test *>::iterator it = m_tests.begin(); + it != m_tests.end(); + ++it ) + { + //# if ( result->shouldStop() ) + //# break; + // if ( pTestResult_ShouldStop(result) ) + if ( (pCallbackFunc)(0 /* NULL */, TAG_TYPE, RESULT_SHOULD_STOP, TAG_RESULT_PTR, result, TAG_DONE) ) + { + break; + } + Test *test = *it; + test->run( result ); + } + // (pTestResult_LeaveNode)(result, getName().c_str()); + (pCallbackFunc)(0 /* NULL */, TAG_TYPE, RESULT_LEAVE_NODE, TAG_RESULT_PTR, result, TAG_NODENAME, getName().c_str(), TAG_DONE); +} + + +/// Counts the number of test cases that will be run by this test. +int +TestSuite::countTestCases() const +{ + int count = 0; + + for ( std::vector<Test *>::const_iterator it = m_tests.begin(); + it != m_tests.end(); + ++it ) + count += (*it)->countTestCases(); + + return count; +} + + +/// Adds a test to the suite. +void +TestSuite::addTest( Test *test ) +{ + m_tests.push_back( test ); +} + + +/// Returns a string representation of the test suite. +std::string +TestSuite::toString() const +{ + return "suite " + getName(); +} + + +/// Returns the name of the test suite. +std::string +TestSuite::getName() const +{ + return m_name; +} + + +const std::vector<Test *> & +TestSuite::getTests() const +{ + return m_tests; +} + + +} // namespace CppUnit + +// The following sets variables for GNU EMACS +// Local Variables: +// tab-width:4 +// End: diff --git a/cppunit/source/cppunit/cmdlinebits.cxx b/cppunit/source/cppunit/cmdlinebits.cxx new file mode 100644 index 000000000000..48ecee48e43c --- /dev/null +++ b/cppunit/source/cppunit/cmdlinebits.cxx @@ -0,0 +1,149 @@ +/************************************************************************* + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: cmdlinebits.cxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: lla $ $Date: 2008-02-27 16:22:28 $ + * + * The Contents of this file are made available subject to + * the terms of GNU Lesser General Public License Version 2.1. + * + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2005 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_cppunit.hxx" + +#ifdef WNT +# define UNDER_WINDOWS_DEBUGGING +# include "testshl/winstuff.hxx" +#endif /* WNT */ + +#include <stdio.h> +#include <cppunit/cmdlinebits.hxx> +#include "cppunit/checkboom.hxx" + +#include <cppunit/autoregister/callbackstructure.h> +#include <osl/diagnose.h> +#include <rtl/tres.h> +#include <cppunit/stringhelper.hxx> + +extern CallbackStructure aGlobalStructure; + +sal_Bool isBit( CmdLineBits _nBits, CmdLineBits _nFlag ); + +// sal_Bool isBit( CmdLineBits _nBits, CmdLineBits _nFlag ) +// { +// return( ( _nBits & _nFlag ) == _nFlag ); +// } + +void CheckBoom(bool bCondition, std::string const& msg) +{ + (void) msg; // avoid warning + if ( isBit( aGlobalStructure.nBits, rtl_tres_Flag_BOOM ) ) + { + /* force an assertion on false state */ + if ( !bCondition ) { +#ifdef UNDER_WINDOWS_DEBUGGING + WinDebugBreak(); +#else + OSL_ENSURE( false, msg.c_str() ); +#endif + } + } +} + +void CheckBoom(bool bCondition, rtl::OUString const& msg) +{ + if ( isBit( aGlobalStructure.nBits, rtl_tres_Flag_BOOM ) ) + { + /* force an assertion on false state */ + rtl::OString sMessage; + sMessage <<= msg; + if ( !bCondition ) { +#ifdef UNDER_WINDOWS_DEBUGGING + WinDebugBreak(); +#else + OSL_ENSURE( false, sMessage.getStr() ); +#endif + } + } +} + +const char* getForwardString() +{ + return aGlobalStructure.psForward; +} + +// ----------------------------------------------------------------------------- +// ----------------------------- own printf method ----------------------------- +// ----------------------------------------------------------------------------- + +// bool isVerbose() +// { +// if ( isBit( aGlobalStructure.nBits, rtl_tres_Flag_VERBOSE ) ) +// { +// return true; +// } +// return false; +// } +// +// bool isQuiet() +// { +// if ( isBit( aGlobalStructure.nBits, rtl_tres_Flag_QUIET ) ) +// { +// return true; +// } +// return false; +// } +// +// void impl_t_print(const char* _pFormatStr, va_list &args) +// { +// if (! isQuiet()) +// { +// printf("# "); +// vprintf(_pFormatStr, args); +// } +// } +// +// void t_print(const char* _pFormatStr, ...) +// { +// va_list args; +// va_start( args, _pFormatStr ); +// impl_t_print(_pFormatStr, args); +// va_end( args ); +// } +// +// void t_print(T_Print_Params _eType, const char* _pFormatStr, ...) +// { +// if (_eType == T_VERBOSE && isVerbose()) +// { +// // if T_VERBOSE and we should be verbose, print info +// va_list args; +// va_start( args, _pFormatStr ); +// impl_t_print(_pFormatStr, args); +// va_end( args ); +// } +// } diff --git a/cppunit/source/cppunit/joblist.cxx b/cppunit/source/cppunit/joblist.cxx new file mode 100644 index 000000000000..df043bfe226a --- /dev/null +++ b/cppunit/source/cppunit/joblist.cxx @@ -0,0 +1,229 @@ +/************************************************************************* + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: joblist.cxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: lla $ $Date: 2008-02-27 16:22:52 $ + * + * The Contents of this file are made available subject to + * the terms of GNU Lesser General Public License Version 2.1. + * + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2005 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_cppunit.hxx" + +#include <stdlib.h> +#include <stdio.h> +#include <fstream> +#include <rtl/string.hxx> +#include "cppunit/joblist.hxx" + +#define C_SEPARATOR_LIST " \t,;:#" +JobList::JobList() + :ppsJobList(NULL) +{} + +// ----------------------------------------------------------------------------- +bool JobList::isInCurrentEnvironment(std::string const& _sString) +{ + int nSpace = 0; + std::string sSearchString = _sString; + bool bEnd = false; + // run through the hole given string, + std::string sEnv; + + do { + nSpace = sSearchString.find_first_of(C_SEPARATOR_LIST); + if (nSpace < 0) + { + sEnv = sSearchString; + bEnd = true; + } + else + { + sEnv = sSearchString.substr(0, nSpace); + sSearchString = sSearchString.substr(nSpace + 1); + } + if (sEnv.length() > 0) + { + // cout << sEnv << endl; +#ifdef LINUX + int nLinux = sEnv.find("unxlng"); + if (nLinux >= 0) + { + // found unxlng + return true; + } +#endif +#ifdef SOLARIS + int nSolaris = sEnv.find("unxsol"); + if (nSolaris >= 0) + { + // found unxsol + return true; + } +#endif +#ifdef WNT + int nWindows = sEnv.find("wnt"); + if (nWindows >= 0) + { + // found wnt + return true; + } +#endif + } + } while ( !bEnd ); + return false; +} + +std::string JobList::trim(std::string const& _sStringToTrim) +{ + rtl::OString sStr(_sStringToTrim.c_str()); + sStr = sStr.trim(); + return std::string(sStr.getStr()); +} + +// ----------------------------------------------------------------------------- +bool JobList::readfile(std::string const& _sFilename, JobType _nJobType) +{ + // StringList aJobList; + m_aJobList.clear(); + + std::ifstream in(_sFilename.c_str(), std::ios::in); + + if (!in) + { + // fprintf(stderr, "warning: Can't open job file: %s\n", _sFilename.c_str()); + return false; + } + else + { + if (_nJobType == JOB_EXCLUDE_LIST) + { + fprintf(stderr, "warning: There exist a job exclusion list file: %s\n", _sFilename.c_str()); + } + + // std::cout << "Check for signal" << std::endl; + std::string sLine; + while (std::getline(in, sLine)) + { + if (sLine.size() > 0) + { + char ch = sLine[0]; + if (ch != '#' && + isspace(ch) == 0) + { + sLine = trim(sLine); + + // m_aJobList.push_back( sLine ); + int nSpace = sLine.find_first_of(C_SEPARATOR_LIST); + if (nSpace < 0) + { + m_aJobList[sLine] = JOB_UNKNOWN; + } + else + { + // found a separator + std::string sTest = sLine.substr(0, nSpace); + std::string sRest = sLine.substr(nSpace + 1); + if (isInCurrentEnvironment(sRest)) + { + m_aJobList[sTest] = JOB_UNKNOWN; + } + } + } + } + } + + // inclusion list +/* + int nSize = m_aJobList.size(); + + ppsJobList = (char**) malloc((nSize + 1) * sizeof(char*)); + + int nIdx = 0; + StringList::const_iterator aItEnd = m_aJobList.end(); + for(StringList::const_iterator it = m_aJobList.begin(); + it != aItEnd; ++it) + { + std::string sValue = *it; + char* psTestFkt = (char*) malloc(sValue.size() + 1); + strcpy(psTestFkt, sValue.c_str()); + ppsJobList[nIdx] = psTestFkt; + ++nIdx; + } + + ppsJobList[nIdx] = NULL; +*/ + } + return true; +} + +// ----------------------------------------------------------------------------- +int JobList::getJobListEntry(std::string const& _sIndexName) +{ + if (m_aJobList.find(_sIndexName) != m_aJobList.end()) + { + return m_aJobList[_sIndexName]; + } + return JOB_NOT_FOUND; +} + +// ----------------------------------------------------------------------------- +void JobList::setJobListEntry(std::string const& _sIndexName, int _nValue) +{ + // if (m_aJobList.find(_sIndexName) == m_aJobList.end()) + // { + m_aJobList[_sIndexName] = _nValue; + // } + // else + // { + // fprintf(stderr, "error: test function '%s' already exist.\n", _sIndexName); + // } +} + +// ----------------------------------------------------------------------------- +JobList::~JobList() +{ + int nIdx = 0; + if (ppsJobList) + { + while(ppsJobList[nIdx] != NULL) + { + free(ppsJobList[nIdx]); + ++nIdx; + } + free(ppsJobList); + } +} +// ----------------------------------------------------------------------------- +/* + bool JobList::checkFilter(JobList m_aJobFilter, std::string const& _sNodeName, std::string const& _sName) + { + std::string sFilter = m_aJobFilter.m_aJobList.begin(); + } +*/ diff --git a/cppunit/source/cppunit/makefile.mk b/cppunit/source/cppunit/makefile.mk new file mode 100644 index 000000000000..914a23686329 --- /dev/null +++ b/cppunit/source/cppunit/makefile.mk @@ -0,0 +1,116 @@ +#************************************************************************* +# +# OpenOffice.org - a multi-platform office productivity suite +# +# $RCSfile: makefile.mk,v $ +# +# $Revision: 1.1 $ +# +# last change: $Author: lla $ $Date: 2008-02-27 16:23:44 $ +# +# The Contents of this file are made available subject to +# the terms of GNU Lesser General Public License Version 2.1. +# +# +# GNU Lesser General Public License Version 2.1 +# ============================================= +# Copyright 2005 by Sun Microsystems, Inc. +# 901 San Antonio Road, Palo Alto, CA 94303, USA +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License version 2.1, as published by the Free Software Foundation. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, +# MA 02111-1307 USA +# +#************************************************************************* + +PRJ=..$/.. +# PRJINC=..$/..$/inc$/pch + +PRJNAME=cppunit +TARGET=cppunit +LIBTARGET=NO +ENABLE_EXCEPTIONS=TRUE +# ENABLE_RTTI=TRUE + +# --- Settings ----------------------------------------------------- + +.INCLUDE : settings.mk + +# --- Files -------------------------------------------------------- + +# CXXFILES = \ +# querytemplate.cxx \ +# stringhelper.cxx + +# ENVCFLAGSCXX+=-DCPPUNIT_BUILD_DLL + +CPPUNIT_TESTSHL_SLOFILES = \ + $(SLO)$/SourceLine.obj \ + $(SLO)$/Exception.obj \ + $(SLO)$/NotEqualException.obj \ + $(SLO)$/TestFailure.obj \ + $(SLO)$/joblist.obj \ + $(SLO)$/t_print.obj \ + $(SLO)$/signaltest.obj + +CPPUNIT_STATIC_SOLFILES = \ + $(SLO)$/Asserter.obj \ + $(SLO)$/TestCase.obj \ + $(SLO)$/TestSuite.obj \ + $(SLO)$/TestAssert.obj \ + $(SLO)$/TestFactoryRegistry.obj \ + $(SLO)$/cmdlinebits.obj \ + $(SLO)$/tresregister.obj \ + $(SLO)$/tresstatewrapper.obj \ + $(SLO)$/registertestfunction.obj + + +SLOFILES = \ + $(CPPUNIT_TESTSHL_SLOFILES) \ + $(CPPUNIT_STATIC_SOLFILES) +#------------------------------------------------------------------------------- +# This is statically cppunit library +LIB1TARGET= $(LB)$/$(TARGET).lib +LIB1OBJFILES= \ + $(SLOFILES) + +.IF "$(GUI)"=="WNT" +.IF "$(COM)"=="GCC" +LIB1ARCHIV=$(LB)$/lib$(TARGET)$(DLLPOSTFIX).a +.ENDIF +.ENDIF + +.IF "$(GUI)" == "UNX" +LIB1ARCHIV=$(LB)$/lib$(TARGET)$(DLLPOSTFIX).a +.ENDIF + +#------------------------------------------------------------------------------- +TARGET2=c5t_no_regallfkt +LIB2TARGET= $(LB)$/$(TARGET2).lib +LIB2OBJFILES= \ + $(CPPUNIT_TESTSHL_SLOFILES) + +.IF "$(GUI)"=="WNT" +.IF "$(COM)"=="GCC" +LIB2ARCHIV=$(LB)$/lib$(TARGET2)$(DLLPOSTFIX).a +.ENDIF +.ENDIF + +.IF "$(GUI)" == "UNX" +LIB2ARCHIV=$(LB)$/lib$(TARGET2)$(DLLPOSTFIX).a +.ENDIF + +# --- Targets ------------------------------------------------------ + +.INCLUDE : target.mk + diff --git a/cppunit/source/cppunit/registertestfunction.cxx b/cppunit/source/cppunit/registertestfunction.cxx new file mode 100644 index 000000000000..dc07a6a73989 --- /dev/null +++ b/cppunit/source/cppunit/registertestfunction.cxx @@ -0,0 +1,65 @@ +/************************************************************************* + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: registertestfunction.cxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: lla $ $Date: 2008-02-27 16:22:12 $ + * + * The Contents of this file are made available subject to + * the terms of GNU Lesser General Public License Version 2.1. + * + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2005 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_cppunit.hxx" + +#include <stdlib.h> +#include <cppunit/simpleheader.hxx> +#include <cppunit/additionalfunc.hxx> + +extern "C" void SAL_CALL testAllRegisteredFunctions(hTestResult _pResult) +{ + CppUnit::TestFactoryRegistry::testRegistries(_pResult); + // CppUnit::Test* tp = CppUnit::TestFactoryRegistry::getRegistry("rtl_OUString").makeTest(); + // tp->run(pResult); +} + +// ----------------------------------------------------------------------------- +// ---------------------------- RegisterTestFunctions ---------------------------- +// ----------------------------------------------------------------------------- + +extern "C" void SAL_CALL RegisterTestFunctions(FktRegFuncPtr _pFunc) +{ + if (_pFunc) + { + (_pFunc)(&testAllRegisteredFunctions, ""); + } + else + { + // error, FktRegFuncPtr not given + } + RegisterAdditionalFunctions(_pFunc); +} diff --git a/cppunit/source/cppunit/signaltest.cxx b/cppunit/source/cppunit/signaltest.cxx new file mode 100644 index 000000000000..5697397e2976 --- /dev/null +++ b/cppunit/source/cppunit/signaltest.cxx @@ -0,0 +1,97 @@ +/************************************************************************* + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: signaltest.cxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: lla $ $Date: 2008-02-27 16:24:23 $ + * + * The Contents of this file are made available subject to + * the terms of GNU Lesser General Public License Version 2.1. + * + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2005 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_cppunit.hxx" + +#include <typeinfo> + +#include "cppunit/signaltest.h" + +namespace CppUnit +{ + +/** Constructs a test case for a suite. + * This TestCase is intended for use by the TestCaller and should not + * be used by a test case for which run() is called. + **/ +SignalTest::SignalTest(std::string const& _sName) + : m_sName( _sName ) +{ +} + + +/// Destructs a test case +SignalTest::~SignalTest() +{ +} + + +/// Returns a count of all the tests executed +int +SignalTest::countTestCases() const +{ + return 1; +} + +/// We never need to start this +void SignalTest::run(hTestResult) {} + + +/// Returns the name of the test case +std::string +SignalTest::getName() const +{ + return m_sName; +} + + +/// Returns the name of the test case instance +std::string +SignalTest::toString() const +{ + std::string className; + +#if CPPUNIT_USE_TYPEINFO_NAME + const std::type_info& thisClass = typeid( *this ); + className = thisClass.name(); +#else + className = "SignalTest"; +#endif + + return className + "." + getName(); +} + +} // namespace CppUnit diff --git a/cppunit/source/cppunit/t_print.cxx b/cppunit/source/cppunit/t_print.cxx new file mode 100644 index 000000000000..b37a9a2a72e3 --- /dev/null +++ b/cppunit/source/cppunit/t_print.cxx @@ -0,0 +1,103 @@ +/************************************************************************* + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: t_print.cxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: lla $ $Date: 2008-02-27 16:21:56 $ + * + * The Contents of this file are made available subject to + * the terms of GNU Lesser General Public License Version 2.1. + * + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2005 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_cppunit.hxx" + +#include <stdio.h> +#include <cppunit/cmdlinebits.hxx> +#include <rtl/tres.h> +#include <osl/mutex.hxx> + +extern CmdLineBits st_nBits; + +sal_Bool isBit( CmdLineBits _nBits, CmdLineBits _nFlag ) +{ + return( ( _nBits & _nFlag ) == _nFlag ); +} + +// ----------------------------------------------------------------------------- +// ----------------------------- own printf method ----------------------------- +// ----------------------------------------------------------------------------- + +bool isVerbose() +{ + if ( isBit( st_nBits, rtl_tres_Flag_VERBOSE ) ) + { + return true; + } + return false; +} + +bool isQuiet() +{ + if ( isBit( st_nBits, rtl_tres_Flag_QUIET ) ) + { + return true; + } + return false; +} + +// ::osl::Mutex m_aTPrintMutex; + +void impl_t_print(const char* _pFormatStr, va_list &args) +{ + if (! isQuiet()) + { + // ::osl::MutexGuard g(m_aTPrintMutex); + printf("# "); + vprintf(_pFormatStr, args); + } +} + +void t_print(const char* _pFormatStr, ...) +{ + va_list args; + va_start( args, _pFormatStr ); + impl_t_print(_pFormatStr, args); + va_end( args ); +} + +void t_print(T_Print_Params _eType, const char* _pFormatStr, ...) +{ + if (_eType == T_VERBOSE && isVerbose()) + { + // if T_VERBOSE and we should be verbose, print info + va_list args; + va_start( args, _pFormatStr ); + impl_t_print(_pFormatStr, args); + va_end( args ); + } +} diff --git a/cppunit/source/cppunit/tresregister.cxx b/cppunit/source/cppunit/tresregister.cxx new file mode 100644 index 000000000000..8ccf348c0160 --- /dev/null +++ b/cppunit/source/cppunit/tresregister.cxx @@ -0,0 +1,74 @@ +/************************************************************************* + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: tresregister.cxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: lla $ $Date: 2008-02-27 16:21:06 $ + * + * The Contents of this file are made available subject to + * the terms of GNU Lesser General Public License Version 2.1. + * + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2005 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_cppunit.hxx" + +#include <stdio.h> +#include <sal/types.h> +#include <cppunit/autoregister/registerfunc.h> +#include <cppunit/autoregister/callbackstructure.h> +#include <cppunit/cmdlinebits.hxx> + +//! is this global CallbackStructure need? +CallbackStructure aGlobalStructure; +CmdLineBits st_nBits; + +FktPtr_CallbackDispatch pCallbackFunc = NULL; + +// This function is called from the TestShl tool. +extern "C" void SAL_CALL registerAllTestFunction(CallbackStructure* _pCallback) +{ + aGlobalStructure = *_pCallback; + + st_nBits = aGlobalStructure.nBits; + + pCallbackFunc = _pCallback->aCallbackDispatch; + FktRegFuncPtr pFunc = _pCallback->aRegisterFunction; + if (pFunc) + { + RegisterTestFunctions(pFunc); + } + else + { + // error, should be echoed + fprintf(stderr, "error: Callback Structure doesn't contain a test function ptr.\n"); + } + + // all is done, copy the magic value + // this is only a simple internal invariant check, + // if the called registerAllTestFunctions Function do, what we want. + _pCallback->nMagic2 = _pCallback->nMagic; +} diff --git a/cppunit/source/cppunit/tresstatewrapper.cxx b/cppunit/source/cppunit/tresstatewrapper.cxx new file mode 100644 index 000000000000..a53716d35151 --- /dev/null +++ b/cppunit/source/cppunit/tresstatewrapper.cxx @@ -0,0 +1,173 @@ +/************************************************************************* + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: tresstatewrapper.cxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: lla $ $Date: 2008-02-27 16:23:55 $ + * + * The Contents of this file are made available subject to + * the terms of GNU Lesser General Public License Version 2.1. + * + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2005 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_cppunit.hxx" + +// this functions build the wrapper, to handle old function calls to rtl_tres_state +// IMPORTANT: Due to the fact that rtl_tres_state is in the sal.lib +// you have to rename rtl_tres_state to c_rtl_tres_state +// +// return c_rtl_tres_state +// ( +// hRtlTestResult, +// pData->length == 0 && +// ! *pData->buffer, +// "New OString containing no characters", +// "ctor_001" +// ) + +#include <stdlib.h> +#include <stdio.h> +#include <string.h> +#include "cppunit/Test.h" +#include "cppunit/autoregister/htestresult.h" +#include "cppunit/autoregister/callbackfunc_fktptr.h" +#include "cppunit/TestAssert.h" + +#define LOAD_TRESSTATEWRAPPER_LOCAL +#include "testshl/tresstatewrapper.hxx" +#undef LOAD_TRESSTATEWRAPPER_LOCAL + +#include "cppunit/tagvalues.hxx" +#include "cppunit/externcallbackfunc.hxx" + +// ----------------------------------------------------------------------------- +// Wrapper class for the CppUnit::Test, because the new TestResult +// expect a CppUnit::Test interface + +class WrappedTest : public CppUnit::Test +{ + std::string m_sName; +public: + WrappedTest(std::string const& _sName) + :m_sName(_sName){} + + virtual ~WrappedTest () {} + virtual void run (hTestResult /*pResult*/){} + virtual int countTestCases () const {return 1;} + virtual std::string getName () const {return m_sName;} + virtual std::string toString () const {return "WrappedTest";} +}; + +// ----------------------------------------------------------------------------- +rtl_tres_state_start::rtl_tres_state_start(hTestResult _aResult, const sal_Char* _pName) + :m_pName(_pName), + m_aResult(_aResult) +{ + // (pTestResult_EnterNode)(m_aResult, m_pName); + (pCallbackFunc)( 0 /* NULL */, TAG_TYPE, RESULT_ENTER_NODE, TAG_RESULT_PTR, m_aResult, TAG_NODENAME, m_pName, TAG_DONE); +} +rtl_tres_state_start::~rtl_tres_state_start() +{ + // (pTestResult_LeaveNode)(m_aResult, m_pName); + (pCallbackFunc)(0 /* NULL */, TAG_TYPE, RESULT_LEAVE_NODE, TAG_RESULT_PTR, m_aResult, TAG_NODENAME, m_pName, TAG_DONE); +} + +// --------------------------------- C-Wrapper --------------------------------- +typedef std::vector<rtl_tres_state_start*> rtl_tres_states; +rtl_tres_states m_StateStack; + +extern "C" void c_rtl_tres_state_start(hTestResult _aResult, const sal_Char* _pName) +{ + rtl_tres_state_start* pState = new rtl_tres_state_start(_aResult, _pName); + m_StateStack.push_back(pState); +} + +extern "C" void c_rtl_tres_state_end(hTestResult, const sal_Char*) +{ + rtl_tres_state_start* pState = m_StateStack.back(); + + delete pState; + m_StateStack.pop_back(); +} +// ----------------------------------------------------------------------------- +// ----------------------------------------------------------------------------- +// ----------------------------------------------------------------------------- + +// ----------------------------------------------------------------------------- +// ------------------------- Wrapper for rtl_tres_state ------------------------- +// ----------------------------------------------------------------------------- + +sal_Bool SAL_CALL c_rtl_tres_state( + hTestResult pResult, + sal_Bool bSuccess, + char const * pTestMsg, + char const * pFuncName) +{ + CppUnit::Test* pTest = new WrappedTest(pFuncName); + + sal_Int32 nValue = (pCallbackFunc)(0 /* NULL */, TAG_TYPE, EXECUTION_CHECK, TAG_RESULT_PTR, pResult, TAG_NODENAME, pTest->getName().c_str(), TAG_DONE); + if (nValue == DO_NOT_EXECUTE) + { + return false; + } + + // This code is copied from CppUnit::TestCase and less adapted, to work with the + // old test code. + // (pTestResult_StartTest)(pResult, pTest); + (pCallbackFunc)(0 /* NULL */, TAG_TYPE, RESULT_START, TAG_RESULT_PTR, pResult, TAG_TEST_PTR, pTest, TAG_DONE); + + try + { + CPPUNIT_ASSERT_MESSAGE( pTestMsg, bSuccess ? true : false ); + // (pTestResult_AddInfo)(pResult, pTest, "#PASSED#"); + (pCallbackFunc)(0 /* NULL */, TAG_TYPE, RESULT_ADD_INFO, TAG_RESULT_PTR, pResult, TAG_TEST_PTR, pTest, TAG_INFO, "PASSED", TAG_DONE); + } + catch ( CppUnit::Exception &e ) + { + CppUnit::Exception *copy = e.clone(); + // (pTestResult_AddFailure)( pResult, pTest, copy ); + (pCallbackFunc)( 0 /* NULL */, TAG_TYPE, RESULT_ADD_FAILURE, TAG_RESULT_PTR, pResult, TAG_TEST_PTR, pTest, TAG_EXCEPTION, copy, TAG_DONE ); + } + catch ( std::exception &e ) + { + //(pTestResult_AddError)( pResult, pTest, new CppUnit::Exception( e.what() ) ); + (pCallbackFunc)( 0 /* NULL */, TAG_TYPE, RESULT_ADD_ERROR, TAG_RESULT_PTR, pResult, TAG_TEST_PTR, pTest, TAG_EXCEPTION, new CppUnit::Exception( e.what() ), TAG_DONE ); + } + catch (...) + { + CppUnit::Exception *e = new CppUnit::Exception( "caught unknown exception" ); + // (pTestResult_AddError)( pResult, pTest, e ); + (pCallbackFunc)( 0 /* NULL */, TAG_TYPE, RESULT_ADD_ERROR, TAG_RESULT_PTR, pResult, TAG_TEST_PTR, pTest, TAG_EXCEPTION, e, TAG_DONE ); + } + + + // (pTestResult_EndTest)( pResult, pTest ); + (pCallbackFunc)( 0 /* NULL */, TAG_TYPE, RESULT_END, TAG_RESULT_PTR, pResult, TAG_TEST_PTR, pTest, TAG_DONE ); + + return bSuccess; +} + diff --git a/cppunit/source/result/SynchronizedObject.cpp b/cppunit/source/result/SynchronizedObject.cpp new file mode 100644 index 000000000000..80bd6a362c2d --- /dev/null +++ b/cppunit/source/result/SynchronizedObject.cpp @@ -0,0 +1,35 @@ +#include <cppunit/result/SynchronizedObject.h> + + +namespace CppUnit +{ + + + + +SynchronizedObject::SynchronizedObject( SynchronizationObject *syncObject ) + : m_syncObject( syncObject == 0 ? new SynchronizationObject() : + syncObject ) +{ +} + + +SynchronizedObject::~SynchronizedObject() +{ + delete m_syncObject; +} + + +/** Accept a new synchronization object for protection of this instance + * TestResult assumes ownership of the object + */ +void +SynchronizedObject::setSynchronizationObject( SynchronizationObject *syncObject ) +{ + delete m_syncObject; + m_syncObject = syncObject; +} + + +} // namespace CppUnit + diff --git a/cppunit/source/result/TestResult.cpp b/cppunit/source/result/TestResult.cpp new file mode 100644 index 000000000000..31fa4b707ded --- /dev/null +++ b/cppunit/source/result/TestResult.cpp @@ -0,0 +1,260 @@ +#include <cppunit/TestFailure.h> +#include <cppunit/result/TestListener.h> +#include <cppunit/result/TestResult.h> +#include <algorithm> +#include "cppunit/result/outputter.hxx" +#include <cppunit/Test.h> +#include <cppunit/cmdlinebits.hxx> + +namespace CppUnit { + +/// Construct a TestResult +TestResult::TestResult( GetOpt &_pOptions, SynchronizationObject *syncObject ) + : SynchronizedObject( syncObject ), + m_aOptionHelper(_pOptions), + m_nExitValue(0) +{ + reset(); +} + + +/// Destroys a test result +TestResult::~TestResult() +{ +} + + +/** Resets the result for a new run. + * + * Clear the previous run result. + */ +void +TestResult::reset() +{ + ExclusiveZone zone( m_syncObject ); + m_stop = false; +} + + +/** Adds an error to the list of errors. + * The passed in exception + * caused the error + */ +void +TestResult::addError( Test *test, + Exception *e, ErrorType::num _eType ) +{ + TestFailure aTestFailure( test, e, _eType ); + addFailure( aTestFailure ); +} + + +/** Adds a failure to the list of failures. The passed in exception + * caused the failure. + */ +void +TestResult::addFailure( Test *test, Exception *e ) +{ + TestFailure aTestFailure( test, e, ErrorType::ET_FAILURE ); + addFailure( aTestFailure ); +} + + +/** Called to add a failure to the list of failures. + */ +void +TestResult::addFailure( const TestFailure &failure ) +{ + ExclusiveZone zone( m_syncObject ); + + // LLA: + // this set the global returnvalue, due to the fact, there occurs a failure, we have to return a non zero value + // at the moment this seams to be a good place. + setExitValue(1); + + for ( TestListeners::iterator it = m_listeners.begin(); + it != m_listeners.end(); + ++it ) + { + TestListener *pListener = *it; + pListener->addFailure( failure ); + } +} + + +/// Informs the result that a test will be started. +void +TestResult::startTest( Test *test ) +{ + ExclusiveZone zone( m_syncObject ); + if (m_aOptionHelper.isVerbose()) + { + std::string aStr; + if (test) + { + aStr = getNodeName(); + aStr += "."; + aStr += test->getName(); + } + // fprintf(stderr, "Start test: %s\n", aStr.c_str()); + t_print( T_VERBOSE, "Start test: %s\n", aStr.c_str()); + } + + for ( TestListeners::iterator it = m_listeners.begin(); + it != m_listeners.end(); + ++it ) + { + TestListener *pListener = *it; + pListener->startTest( test ); + } +} + + +/// Informs the result that a test was completed. +void +TestResult::endTest( Test *test ) +{ + ExclusiveZone zone( m_syncObject ); + for ( TestListeners::iterator it = m_listeners.begin(); + it != m_listeners.end(); + ++it ) + { + TestListener *pListener = *it; + pListener->endTest( test ); + } +} + + +/// Returns whether testing should be stopped +bool +TestResult::shouldStop() const +{ + ExclusiveZone zone( m_syncObject ); + return m_stop; +} + + +/// Stop testing +void +TestResult::stop() +{ + ExclusiveZone zone( m_syncObject ); + m_stop = true; +} + + +void +TestResult::addListener( TestListener *listener ) +{ + ExclusiveZone zone( m_syncObject ); + m_listeners.push_back( listener ); +} + + +void +TestResult::removeListener ( TestListener *listener ) +{ + ExclusiveZone zone( m_syncObject ); +#if defined(_MSC_VER) && (_MSC_VER >=1400) + m_listeners.erase( remove( m_listeners.begin(), +#else + m_listeners.erase( std::remove( m_listeners.begin(), +#endif + m_listeners.end(), + listener ), + m_listeners.end()); +} + +void +TestResult::addInfo(Test *test, const char* _aStr) +{ + ExclusiveZone zone( m_syncObject ); + for ( TestListeners::iterator it = m_listeners.begin(); + it != m_listeners.end(); + ++it ) + { + TestListener *pListener = *it; + pListener->addInfo( test, _aStr ); + } +} + +// old: void +// old: TestResult::enterNode(const char* _aStr) +// old: { +// old: ExclusiveZone zone( m_syncObject ); +// old: for ( TestListeners::iterator it = m_listeners.begin(); +// old: it != m_listeners.end(); +// old: ++it ) +// old: { +// old: TestListener *pListener = *it; +// old: pListener->enterNode( _aStr ); +// old: } +// old: } +// old: +// old: void +// old: TestResult::leaveNode(const char* _aStr) +// old: { +// old: ExclusiveZone zone( m_syncObject ); +// old: +// old: for ( TestListeners::iterator it = m_listeners.begin(); +// old: it != m_listeners.end(); +// old: ++it ) +// old: { +// old: TestListener *pListener = *it; +// old: pListener->leaveNode( _aStr ); +// old: } +// old: } + +void TestResult::enterNode(const char* _sNode) +{ + ExclusiveZone zone( m_syncObject ); + m_aCurrentNodeNames.push_back(std::string(_sNode)); +} + +void TestResult::leaveNode(const char* /*_sNode*/) +{ + ExclusiveZone zone( m_syncObject ); + std::string sBack = m_aCurrentNodeNames.back(); + m_aCurrentNodeNames.pop_back(); + + // due to a -Wall warning, comment out. + // if (sBack != std::string(_sNode)) + // { + // volatile int dummy = 0; + // // problem?! + // } +} + +std::string TestResult::getNodeName() +{ + std::string sName; + for (std::vector<std::string>::const_iterator it = m_aCurrentNodeNames.begin(); + it != m_aCurrentNodeNames.end(); + ++it) + { + if (sName.size() != 0) + { + sName += "."; + } + sName += *it; + } + return sName; +} + +// ----------------------------------------------------------------------------- +bool TestResult::isAllowedToExecute(std::string const& _sName) +{ + return m_aOptionHelper.isAllowedToExecute(getNodeName(), _sName); +} +// ----------------------------------------------------------------------------- +bool TestResult::isOptionWhereAmI() +{ + return m_aOptionHelper.isOptionWhereAmI(); +} + +// ----------------------------------------------------------------------------- +void TestResult::print(Outputter&) +{ +} + +} // namespace CppUnit diff --git a/cppunit/source/result/TestResultCollector.cpp b/cppunit/source/result/TestResultCollector.cpp new file mode 100644 index 000000000000..d329e9e0b9dc --- /dev/null +++ b/cppunit/source/result/TestResultCollector.cpp @@ -0,0 +1,147 @@ +#include <cppunit/TestFailure.h> +#include <cppunit/result/TestResultCollector.h> + + +namespace CppUnit +{ + + +TestResultCollector::TestResultCollector( TestResult* _pResult, SynchronizationObject *syncObject ) + : TestSucessListener( syncObject ), + m_pResult(_pResult), + m_testErrors(0) +{ + reset(); +} + + +TestResultCollector::~TestResultCollector() +{ + TestFailures::iterator itFailure = m_failures.begin(); + while ( itFailure != m_failures.end() ) + { + TestFailureEnvelope *pEnvelope = *itFailure++; + TestFailure *pFailure = pEnvelope->getTestFailure(); + delete pFailure; + } +} + + +void +TestResultCollector::reset() +{ + TestSucessListener::reset(); + + ExclusiveZone zone( m_syncObject ); + m_testErrors = 0; + m_tests.clear(); + m_failures.clear(); +} + + +void +TestResultCollector::startTest( Test *test ) +{ + ExclusiveZone zone (m_syncObject); + + m_tests.push_back( new TestEnvelope(test, m_pResult->getNodeName()) ); +} + +void +TestResultCollector::endTest( Test * ) +{ + // ExclusiveZone zone (m_syncObject); + // Nothing! +} + + +void +TestResultCollector::addFailure( const TestFailure &failure ) +{ + TestSucessListener::addFailure( failure ); + + ExclusiveZone zone( m_syncObject ); + if ( failure.isError() ) + ++m_testErrors; + m_failures.push_back( new TestFailureEnvelope(failure.clone(), m_pResult->getNodeName()) ); +} + + +/// Gets the number of run tests. +int +TestResultCollector::runTests() const +{ + ExclusiveZone zone( m_syncObject ); + return m_tests.size(); +} + + +/// Gets the number of detected errors (uncaught exception). +int +TestResultCollector::testErrors() const +{ + ExclusiveZone zone( m_syncObject ); + return m_testErrors; +} + + +/// Gets the number of detected failures (failed assertion). +int +TestResultCollector::testFailures() const +{ + ExclusiveZone zone( m_syncObject ); + return m_failures.size() - m_testErrors; +} + + +/// Gets the total number of detected failures. +int +TestResultCollector::testFailuresTotal() const +{ + ExclusiveZone zone( m_syncObject ); + return m_failures.size(); +} + + +/// Returns a the list failures (random access collection). +const TestResultCollector::TestFailures & +TestResultCollector::failures() const +{ + ExclusiveZone zone( m_syncObject ); + return m_failures; +} + + +const TestResultCollector::Tests & +TestResultCollector::tests() const +{ + ExclusiveZone zone( m_syncObject ); + return m_tests; +} + +void TestResultCollector::addInfo(Test *_pTest, const char* _sInfo) +{ + ExclusiveZone zone( m_syncObject ); + m_aInfos.push_back(new TestInfo(_pTest, _sInfo)); +} + +std::string TestResultCollector::getInfo(Test *_pTest) +{ + for (TestInfos::const_iterator it = m_aInfos.begin(); + it != m_aInfos.end(); + ++it) + { + TestInfo *pInfo = *it; + Test *pTest = pInfo->getTest(); + if (pTest == _pTest) + { + std::string sInfo = pInfo->getString(); + return sInfo; + } + } + return std::string(); +} + + +} // namespace CppUnit + diff --git a/cppunit/source/result/TestSucessListener.cpp b/cppunit/source/result/TestSucessListener.cpp new file mode 100644 index 000000000000..27d23752715e --- /dev/null +++ b/cppunit/source/result/TestSucessListener.cpp @@ -0,0 +1,46 @@ +#include <cppunit/result/TestSucessListener.h> + + + +namespace CppUnit +{ + + +TestSucessListener::TestSucessListener( SynchronizationObject *syncObject ) + : SynchronizedObject( syncObject ) + , m_sucess( true ) +{ +} + + +TestSucessListener::~TestSucessListener() +{ +} + + +void +TestSucessListener::reset() +{ + ExclusiveZone zone( m_syncObject ); + m_sucess = true; +} + + +void +TestSucessListener::addFailure( const TestFailure & ) +{ + ExclusiveZone zone( m_syncObject ); + m_sucess = false; +} + + +bool +TestSucessListener::wasSuccessful() const +{ + ExclusiveZone zone( m_syncObject ); + return m_sucess; +} + + +} // namespace CppUnit + diff --git a/cppunit/source/result/TextTestResult.cpp b/cppunit/source/result/TextTestResult.cpp new file mode 100644 index 000000000000..4b5b520da5ac --- /dev/null +++ b/cppunit/source/result/TextTestResult.cpp @@ -0,0 +1,191 @@ +#include <cppunit/Exception.h> +#include <cppunit/NotEqualException.h> +#include <cppunit/Test.h> +#include <cppunit/TestFailure.h> +#include <cppunit/result/TextTestResult.h> +// #include <TextTestResult.h> +//!io #include <iostream> + +namespace CppUnit { + + +TextTestResult::TextTestResult(GetOpt& _aOptions) + :TestResult(_aOptions), + m_aResulter(this) +{ + addListener( &m_aResulter ); +} + + +void +TextTestResult::addFailure( const TestFailure &failure ) +{ + TestResult::addFailure( failure ); + // std::cerr << ( failure.isError() ? "E" : "F" ); + if (failure.isError()) + fprintf(stderr, "E"); + else + fprintf(stderr, "F"); +} + + +void +TextTestResult::startTest( Test *test ) +{ + TestResult::startTest (test); + // std::cerr << "."; + fprintf(stderr, "."); +} + +void TextTestResult::endTest( Test *test ) +{ + TestResult::endTest (test); +} + + +void +TextTestResult::printFailures( std::ostream &stream ) +{ + TestResultCollector::TestFailures::const_iterator itFailure = m_aResulter.failures().begin(); + int failureNumber = 1; + while ( itFailure != m_aResulter.failures().end() ) + { + stream << std::endl; + TestFailure *pFailure= (*itFailure++)->getTestFailure(); + printFailure( pFailure, failureNumber++, stream ); + } +} + + +void +TextTestResult::printFailure( TestFailure *failure, + int failureNumber, + std::ostream &stream ) +{ + printFailureListMark( failureNumber, stream ); + stream << ' '; + printFailureTestName( failure, stream ); + stream << ' '; + printFailureType( failure, stream ); + stream << ' '; + printFailureLocation( failure->sourceLine(), stream ); + stream << std::endl; + printFailureDetail( failure->thrownException(), stream ); + stream << std::endl; +} + + +void +TextTestResult::printFailureListMark( int failureNumber, + std::ostream &stream ) +{ + stream << failureNumber << ")"; +} + + +void +TextTestResult::printFailureTestName( TestFailure *failure, + std::ostream &stream ) +{ + Test* pTest = failure->failedTest(); + stream << "test: " << pTest->getName(); +} + + +void +TextTestResult::printFailureType( TestFailure *failure, + std::ostream &stream ) +{ + stream << "(" + << (failure->isError() ? "E" : "F") + << ")"; +} + + +void +TextTestResult::printFailureLocation( SourceLine sourceLine, + std::ostream &stream ) +{ + if ( !sourceLine.isValid() ) + return; + + stream << "line: " << sourceLine.lineNumber() + << ' ' << sourceLine.fileName(); +} + + +void +TextTestResult::printFailureDetail( Exception *thrownException, + std::ostream &stream ) +{ + if ( thrownException->isInstanceOf( NotEqualException::type() ) ) + { + NotEqualException *e = (NotEqualException*)thrownException; + stream << "expected: " << e->expectedValue() << std::endl + << "but was: " << e->actualValue(); + if ( !e->additionalMessage().empty() ) + { + stream << std::endl; + stream << "additional message:" << std::endl + << e->additionalMessage(); + } + } + else + { + stream << " \"" << thrownException->what() << "\""; + } +} + + +void +TextTestResult::print( std::ostream& stream ) +{ + printHeader( stream ); + stream << std::endl; + printFailures( stream ); +} + + +void +TextTestResult::printHeader( std::ostream &stream ) +{ + if (m_aResulter.wasSuccessful ()) + stream << std::endl << "OK (" << m_aResulter.runTests () << " tests)" + << std::endl; + else + { + stream << std::endl; + printFailureWarning( stream ); + printStatistics( stream ); + } +} + + +void +TextTestResult::printFailureWarning( std::ostream &stream ) +{ + stream << "!!!FAILURES!!!" << std::endl; +} + + +void +TextTestResult::printStatistics( std::ostream &stream ) +{ + stream << "Test Results:" << std::endl; + + stream << "Run: " << m_aResulter.runTests() + << " Failures: " << m_aResulter.testFailures() + << " Errors: " << m_aResulter.testErrors() + << std::endl; +} + + +std::ostream & +operator <<( std::ostream &stream, + TextTestResult &result ) +{ + result.print (stream); return stream; +} + + +} // namespace CppUnit diff --git a/cppunit/source/result/emacsTestResult.cxx b/cppunit/source/result/emacsTestResult.cxx new file mode 100644 index 000000000000..f52792b904f3 --- /dev/null +++ b/cppunit/source/result/emacsTestResult.cxx @@ -0,0 +1,198 @@ +/************************************************************************* + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: emacsTestResult.cxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: lla $ $Date: 2008-02-27 16:27:10 $ + * + * The Contents of this file are made available subject to + * the terms of GNU Lesser General Public License Version 2.1. + * + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2005 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_cppunit.hxx" + +#include <stdlib.h> + +#include <map> +#include <cppunit/Exception.h> +#include <cppunit/NotEqualException.h> +#include <cppunit/Test.h> +#include <cppunit/TestFailure.h> +#include <cppunit/result/emacsTestResult.hxx> +// #include <TextTestResult.h> +//!io #include <iostream> +#include <string> + +#include <rtl/string.hxx> +#include "cppunit/result/outputter.hxx" + +namespace CppUnit { + + emacsTestResult::emacsTestResult(GetOpt & _aOptions) + :TestResult(_aOptions), + m_aOptions(_aOptions), + m_aResulter(this) + { + addListener( &m_aResulter ); + } + + //# struct ltstr + //# { + //# bool operator()(const CppUnit::Test* p1, const CppUnit::Test* p2) const + //# { + //# return p1 < p2; + //# } + //# }; + //# typedef std::map<CppUnit::Test*, bool, ltstr> TestPtrList; + + void + emacsTestResult::print( Outputter& stream ) + { + printHeader( stream ); + // stream << std::endl; + // printFailures( stream ); + + // TestPtrList aFailedTests; + + for (TestResultCollector::TestFailures::const_iterator it2 = m_aResulter.failures().begin(); + it2 != m_aResulter.failures().end(); + ++it2) + { + TestFailureEnvelope *pEnvelop = *it2; + TestFailure *pFailure = pEnvelop->getTestFailure(); + std::string sNodeName = pEnvelop->getString(); + + // aFailedTests[ pFailure->failedTest() ] = true; + + printFailureLine(stream, pFailure, sNodeName); + } + + // only errors are from interest here + //# for (TestResultCollector::Tests::const_iterator it = m_aResulter.tests().begin(); + //# it != m_aResulter.tests().end(); + //# ++it) + //# { + //# TestEnvelope *pEnvelop = *it; + //# Test* pTest = pEnvelop->getTest(); + //# std::string sNodeName = pEnvelop->getString(); + //# + //# if (aFailedTests.find(pTest) == aFailedTests.end()) + //# { + //# std::string sInfo = m_aResulter.getInfo(pTest); + //# printTestLine(stream, pTest, sNodeName, sInfo); + //# } + //# } + stream << "Test #PASSED#" << Outputter::endl(); + } + + + void + emacsTestResult::printHeader( Outputter &stream ) + { + std::string sDate(m_aOptionHelper.createDateTag()); + stream << sDate << Outputter::endl(); + } + + void + emacsTestResult::printFailureLine( Outputter &stream, TestFailure *_pFailure, std::string const& _sNodeName) + { + std::string aName; + aName += _sNodeName; + aName += "."; + aName += _pFailure->failedTestName(); + + SourceLine aLine = _pFailure->sourceLine(); + sal_Int32 nLine = -1; + std::string sFilename; + if (aLine.isValid()) + { + nLine = aLine.lineNumber(); + sFilename = aLine.fileName(); + } + + Exception *pExp = _pFailure->thrownException(); + std::string sWhat; + if (pExp) + { + sWhat = pExp->what(); + } + + stream << sFilename; + stream << ":"; + stream << nLine; + stream << ":"; + + stream << aName; + stream << ";#FAILED#"; + // ErrorType::num eErr = _pFailure->getErrorType(); + //# if (isErr) + //# stream << "FAILED#;"; + //# else + //# stream << "ERROR#;"; + + stream << sWhat; + stream << Outputter::endl(); + } + + //# void + //# emacsTestResult::printTestLine( Outputter &stream, Test* _pTest, std::string const& _sNodeName, std::string const& _sInfo) + //# { + //# std::string aName; + //# aName += _sNodeName; + //# aName += "."; + //# aName += _pTest->getName(); + //# + //# stream << aName; + //# stream << ";"; + //# stream << _sInfo << "#"; + //# stream << "OK#"; + //# stream << std::endl; + //# } + + +//# void +//# emacsTestResult::printStatistics( Outputter &stream ) +//# { +//# stream << "Test Results:" << std::endl; +//# +//# stream << "Run: " << runTests() +//# << " Failures: " << testFailures() +//# << " Errors: " << testErrors() +//# << std::endl; +//# } + + + Outputter & + operator <<( Outputter &stream, + emacsTestResult &result ) + { + result.print (stream); return stream; + } + + +} // namespace CppUnit diff --git a/cppunit/source/result/log.cxx b/cppunit/source/result/log.cxx new file mode 100644 index 000000000000..57c98bc38aa5 --- /dev/null +++ b/cppunit/source/result/log.cxx @@ -0,0 +1,132 @@ +/************************************************************************* + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: log.cxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: lla $ $Date: 2008-02-27 16:25:31 $ + * + * The Contents of this file are made available subject to + * the terms of GNU Lesser General Public License Version 2.1. + * + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2005 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_cppunit.hxx" + +#ifndef __QADEV_REGSCAN_LOG_HXX__ +#include "testshl/log.hxx" +#endif + +// #include <hash_map> +// #include <list> +// #include <set> + +using namespace std; + +::osl::FileBase::RC Log::open( sal_Bool append ) { + + ::osl::FileBase::RC ret; + + if ( ! append ) { + ret = ::osl::File::remove( m_logurl ); + } + + if( m_logfile->open( OpenFlag_Write ) == ::osl::FileBase::E_NOENT ) { + ret = m_logfile->open( OpenFlag_Write | OpenFlag_Create ); + } + else { + ret = m_logfile->setPos( Pos_End, 0 ); + } + return ret; +} + +::osl::FileBase::RC Log::write( const sal_Char* buf, sal_Bool v ) { + sal_uInt64 uBytes=0; + sal_uInt32 len = 0; + const sal_Char* ptr = buf; + + if( ptr ) { + while( *ptr++ ) len++; + } + + if ( v ) { + // cout << buf << flush; + printf("%s", buf); + } + return m_logfile->write( buf, len , uBytes ); +} + +::osl::FileBase::RC Log::write( const rtl::OString& buf, sal_Bool v ) { + sal_uInt64 uBytes=0; + if ( v ) { + // cout << buf.getStr() << flush; + printf("%s", buf.getStr()); + } + return m_logfile->write( buf.getStr(), buf.getLength(), uBytes ); +} +/* +// LLA: due to a problem with sal/OUStingBuffer getLength() which isn't const, this +// is so not compilable. +::osl::FileBase::RC Log::write( rtl::OStringBuffer const& buf, sal_Bool v ) { + sal_uInt64 uBytes=0; + if ( v ) { + cout << buf.getStr() << flush; + } + return m_logfile->write( buf.getStr(), buf.getLength(), uBytes ); +} +*/ +::osl::FileBase::RC Log::write( const rtl::OUString& buf, + rtl_TextEncoding tenc, sal_Bool v ) { + sal_uInt64 uBytes=0; + if ( ! tenc ) { + tenc = RTL_TEXTENCODING_ASCII_US; + } + rtl::OStringBuffer osbuf( + rtl::OUStringToOString( buf, tenc ).getStr() ); + + if ( v ) { + // cout << osbuf.getStr() << flush; + printf("%s", osbuf.getStr()); + } + return m_logfile->write( osbuf.getStr(), osbuf.getLength(), uBytes ); +} + +Log &operator <<( Log &_aLog, const sal_Char * _sValue ) +{ + _aLog.write(_sValue); return _aLog; +} +Log &operator <<( Log &_aLog, rtl::OString const& _sValue ) +{ + _aLog.write(_sValue); return _aLog; +} +Log &operator <<( Log &_aLog, rtl::OUString const& _sValue ) +{ + _aLog.write(_sValue); return _aLog; +} +//! Log &operator <<( Log &_aLog, rtl::OStringBuffer const& _sValue ) +//! { +//! _aLog.write(_sValue); return _aLog; +//! } diff --git a/cppunit/source/result/makefile.mk b/cppunit/source/result/makefile.mk new file mode 100644 index 000000000000..a79032b4c609 --- /dev/null +++ b/cppunit/source/result/makefile.mk @@ -0,0 +1,89 @@ +#************************************************************************* +# +# OpenOffice.org - a multi-platform office productivity suite +# +# $RCSfile: makefile.mk,v $ +# +# $Revision: 1.1 $ +# +# last change: $Author: lla $ $Date: 2008-02-27 16:26:48 $ +# +# The Contents of this file are made available subject to +# the terms of GNU Lesser General Public License Version 2.1. +# +# +# GNU Lesser General Public License Version 2.1 +# ============================================= +# Copyright 2005 by Sun Microsystems, Inc. +# 901 San Antonio Road, Palo Alto, CA 94303, USA +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License version 2.1, as published by the Free Software Foundation. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, +# MA 02111-1307 USA +# +#************************************************************************* + +PRJ=..$/.. +# PRJINC=..$/.. + + +PRJNAME=cppunit +TARGET=c5t_testresult +LIBTARGET=NO +ENABLE_EXCEPTIONS=TRUE +# ENABLE_RTTI=TRUE + +# --- Settings ----------------------------------------------------- + +.INCLUDE : settings.mk + +# --- Files -------------------------------------------------------- + +# CXXFILES = \ +# querytemplate.cxx \ +# stringhelper.cxx + +# ENVCFLAGSCXX+=-DCPPUNIT_BUILD_DLL +SLOFILES = \ + $(SLO)$/SynchronizedObject.obj \ + $(SLO)$/TestResult.obj \ + $(SLO)$/TestResultCollector.obj \ + $(SLO)$/TestSucessListener.obj \ + $(SLO)$/emacsTestResult.obj \ + $(SLO)$/log.obj \ + $(SLO)$/optionhelper.obj \ + $(SLO)$/outputter.obj \ + $(SLO)$/signal.obj \ + $(SLO)$/testshlTestResult.obj \ + $(SLO)$/treswrapper.obj + +# currently unused +# $(SLO)$/TextTestResult.obj + +LIB1TARGET= $(LB)$/$(TARGET).lib +LIB1OBJFILES= $(SLOFILES) + +.IF "$(GUI)"=="WNT" +.IF "$(COM)"=="GCC" +LIB1ARCHIV=$(LB)$/lib$(TARGET)$(DLLPOSTFIX).a +.ENDIF +.ENDIF + +.IF "$(GUI)" == "UNX" +LIB1ARCHIV=$(LB)$/lib$(TARGET)$(DLLPOSTFIX).a +.ENDIF + +# --- Targets ------------------------------------------------------ + +.INCLUDE : target.mk + diff --git a/cppunit/source/result/optionhelper.cxx b/cppunit/source/result/optionhelper.cxx new file mode 100644 index 000000000000..ba1ef7163aaa --- /dev/null +++ b/cppunit/source/result/optionhelper.cxx @@ -0,0 +1,322 @@ +/************************************************************************* + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: optionhelper.cxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: lla $ $Date: 2008-02-27 16:25:08 $ + * + * The Contents of this file are made available subject to + * the terms of GNU Lesser General Public License Version 2.1. + * + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2005 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_cppunit.hxx" + +#include "cppunit/result/optionhelper.hxx" +// #include <sstream> +// #include <string> +#include <osl/time.h> +#include "cppunit/cmdlinebits.hxx" + +// ----------------------------------------------------------------------------- + +namespace +{ + void split( const rtl::OString& opt, + const rtl::OString& _sSeparator, + OStringList& optLine ) + { + optLine.clear(); + // const sal_Int32 cSetLen = cSet.getLength(); + sal_Int32 index = 0; + sal_Int32 oldIndex = 0; + + // sal_Int32 i; + // sal_Int32 j = 0; + while ( opt.getLength() > 0) + { + // for ( i = 0; i < cSetLen; i++ ) + // { + index = opt.indexOf( _sSeparator, oldIndex); + if( index != -1 ) + { + optLine.push_back( opt.copy( oldIndex, index - oldIndex ) ); + oldIndex = index + _sSeparator.getLength(); + } + // } + else // if (index == -1) + { + optLine.push_back( opt.copy( oldIndex ) ); + break; + } + } + } ///< split + + bool match(OStringList const& _aFilter, OStringList const& _aName) + { + OStringList::const_iterator aFilterIter = _aFilter.begin(); + OStringList::const_iterator aValueIter = _aName.begin(); + + bool bMatch = false; + + while (aFilterIter != _aFilter.end() && aValueIter != _aName.end()) + { + rtl::OString sFilter = *aFilterIter; + rtl::OString sName = *aValueIter; + + if (sFilter == sName) + { + bMatch = true; + ++aFilterIter; + ++aValueIter; + } + else if (sFilter == "*") + { + bMatch = true; + break; + } + else + { + // Filter does not match + bMatch = false; + break; + } + } + return bMatch; + } +} + +/* static */ +std::string OptionHelper::integerToAscii(sal_Int32 nValue) +{ + sal_Char cBuf[30]; + sal_Char *pBuf = cBuf; + sprintf(pBuf, "%d", static_cast<int>(nValue)); +//# std::ostringstream sBuf; +//# sBuf << nValue; +// rtl::OString sStr; +// sStr = rtl::OString::valueOf(nValue); + return std::string(pBuf); +} + +/* static */ +// if a given String is less then 2 char, add a "0" in front. +std::string OptionHelper::twoDigits(std::string const& _sValue) +{ + std::string sBack; + if (_sValue.length() == 0) + { + sBack = "00"; + } + else if (_sValue.length() == 1) + { + sBack = "0"; + sBack += _sValue; + } + else + { + sBack = _sValue; + } + return sBack; +} + + +std::string OptionHelper::createDateTag(std::string const& _sProjectId, std::string const& _sBuildId) +{ + TimeValue tmv_system; + TimeValue tmv_local; + oslDateTime dt; + osl_getSystemTime( &tmv_system ); + osl_getLocalTimeFromSystemTime(&tmv_system, &tmv_local); + osl_getDateTimeFromTimeValue( &tmv_local, &dt ); + + sal_Int32 nYear = dt.Year; + sal_Int32 nMonth = dt.Month; + sal_Int32 nDay = dt.Day; + + std::string sDate; + sDate = "# Current Time: "; + sDate += std::string(twoDigits(integerToAscii(dt.Hours))); + sDate += ":"; + sDate += std::string(twoDigits(integerToAscii(dt.Minutes))); + sDate += ":"; + sDate += std::string(twoDigits(integerToAscii(dt.Seconds))); + sDate += "\n"; + + sDate += "["; + + // sDate += rtl::OString::valueOf(nYear); + sDate.append(integerToAscii(nYear)); + sDate += "."; + if (nMonth < 10) + sDate += "0"; + // sDate += rtl::OString::valueOf(nMonth); + sDate.append(integerToAscii(nMonth)); + sDate += "."; + if (nDay < 10) + sDate += "0"; + // sDate += rtl::OString::valueOf(nDay); + sDate += std::string(integerToAscii(nDay)); + sDate += "/"; + sDate += _sProjectId; + sDate += "/"; + sDate += _sBuildId; + sDate += "]"; + + return sDate; +} + +//# rtl::OString createDateTag() +//# { +//# TimeValue tmv; +//# oslDateTime dt; +//# osl_getSystemTime( &tmv ); +//# osl_getDateTimeFromTimeValue( &tmv, &dt ); +//# +//# sal_Int32 nYear = dt.Year; +//# sal_Int32 nMonth = dt.Month; +//# sal_Int32 nDay = dt.Day; +//# +//# rtl::OString sDate("["); +//# sDate += rtl::OString::valueOf(nYear); +//# sDate += "."; +//# if (nMonth < 10) +//# sDate += "0"; +//# sDate += rtl::OString::valueOf(nMonth); +//# sDate += "."; +//# if (nDay < 10) +//# sDate += "0"; +//# sDate += rtl::OString::valueOf(nDay); +//# sDate += "//]"; +//# +//# return sDate; +//# } + +std::string OptionHelper::createDateTag() +{ + return createDateTag(m_sProjectId, m_sBuildId); +} + +bool OptionHelper::showErrors() +{ + bool bRetValue = true; // default, show all + if (m_aOption.hasOpt("-noerrors")) + { + bRetValue = false; + } + return bRetValue; +} + +bool OptionHelper::showTests() +{ + bool bRetValue = true; // default, show all + if (m_aOption.hasOpt("-onlyerrors")) + { + bRetValue = false; + } + return bRetValue; +} + +// Check which parameter is given for handle the jobs. +// If no parameter is given, all jobs (tests) will run through +void OptionHelper::handleJobs() +{ + // load job file, the file contains the functions which we only want to test. + if (m_aOption.hasOpt("-jobexclude")) + { + rtl::OString sJobFile = m_aOption.getOpt("-jobexclude"); + m_aJobExcludeList.readfile(sJobFile.getStr(), JOB_EXCLUDE_LIST); + } + + if (m_aOption.hasOpt("-jobonly")) + { + rtl::OString sJobFile = m_aOption.getOpt("-jobonly"); + m_aJobOnlyList.readfile(sJobFile.getStr(), JOB_ONLY_LIST); + } + + // + if (m_aOption.hasOpt("-jobfilter")) + { + rtl::OString sJobFilter = m_aOption.getOpt("-jobfilter"); + split(sJobFilter, ".", m_aJobFilter); + } +} + +// ----------------------------------------------------------------------------- +// Here will be decide, if a job/test will execute or not. +// therefore exist some lists, in which stay all jobs (positive list) or a list (negative list) which jobs should not execute +// or if only specific jobs should execute by a given filter + +bool OptionHelper::isAllowedToExecute(std::string const& _sNodeName, std::string const& _sName) +{ + std::string sJobName = _sNodeName + "." + _sName; + // t_print(T_VERBOSE, "Jobname %s\n", sJobName.c_str()); + if (isOnlyShowJobs()) // true, if parameter -onlyshowjob + { + m_aJobOnlyList.setJobListEntry(sJobName, JOB_ACCESS); + return false; + } + + if (m_aJobOnlyList.size()) // >0 if parameter -jobonly + { + if (m_aJobOnlyList.getJobListEntry(sJobName) != JOB_NOT_FOUND) + { + // job entry found, mark as accessed + m_aJobOnlyList.setJobListEntry(sJobName, JOB_ACCESS); + return true; + } + return false; + } + else if (m_aJobFilter.size() > 0) // >0 if parameter -jobfilter + { + OStringList aSplitName; + split(sJobName.c_str(), ".", aSplitName); + if (! match(m_aJobFilter, aSplitName)) + { + t_print(T_VERBOSE, "job: '%s' filtered by [-jobfilter]\n", sJobName.c_str()); + return false; + } + } + else if (m_aJobExcludeList.size() > 0) // >0 if parameter -jobexclude + { + if (m_aJobExcludeList.getJobListEntry(sJobName) != JOB_NOT_FOUND) + { + // job entry found, this job should not executed, so return false + t_print(T_VERBOSE, "job: '%s' filtered by [-jobexclude]\n", sJobName.c_str()); + return false; + } + // m_aJobOnlyList.setJobListEntry(sJobName, JOB_ACCESS); + return true; + } + else + { + //! not handled yet + } + + return true; +} + diff --git a/cppunit/source/result/outputter.cxx b/cppunit/source/result/outputter.cxx new file mode 100644 index 000000000000..b58ce46802c8 --- /dev/null +++ b/cppunit/source/result/outputter.cxx @@ -0,0 +1,111 @@ +/************************************************************************* + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: outputter.cxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: lla $ $Date: 2008-02-27 16:26:59 $ + * + * The Contents of this file are made available subject to + * the terms of GNU Lesser General Public License Version 2.1. + * + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2005 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_cppunit.hxx" + +// +#include <string> +#include <sal/types.h> +#include "cppunit/result/outputter.hxx" + +// ----------------------------------------------------------------------------- + +Outputter::~Outputter() +{ + // delete m_pLog; +} + +void Outputter::writeToAll(const sal_Char* _sCharStr) +{ + // std::cout << _sCharStr; + if (m_pStream) + { + *m_pStream << _sCharStr; + } + if (m_pLog.get()) + { + m_pLog->write(_sCharStr); + } +} + +void Outputter::write(const sal_Char* _sCharStr) +{ + writeToAll(_sCharStr); +} + +void Outputter::write(std::string const& _sStr) +{ + writeToAll(_sStr.c_str()); +} + +void Outputter::write(sal_Int32 _nValue) +{ + sal_Char cBuf[20]; + sal_Char* pBuf = cBuf; + sprintf(pBuf, "%d", SAL_STATIC_CAST(int, _nValue)); + writeToAll(pBuf); +} + +// ----------------------------------------------------------------------------- + +Outputter& operator <<( Outputter &_aStreamWrapper, const sal_Char* _sValue) +{ + _aStreamWrapper.write(_sValue); + return _aStreamWrapper; +} + +Outputter& operator <<( Outputter &_aStreamWrapper, std::string const& _sValue) +{ + _aStreamWrapper.write(_sValue); + return _aStreamWrapper; +} + +Outputter& operator <<( Outputter &_aStreamWrapper, sal_Int32 _nValue) +{ + _aStreamWrapper.write(_nValue); + return _aStreamWrapper; +} + +//# Outputter& operator <<( Outputter &_aStreamWrapper, double ) +//# { +//# return _aStreamWrapper; +//# } + +Outputter& operator <<( Outputter &_aStreamWrapper, Outputter::endl const&) +{ + _aStreamWrapper.write("\n"); + return _aStreamWrapper; +} diff --git a/cppunit/source/result/signal.cxx b/cppunit/source/result/signal.cxx new file mode 100644 index 000000000000..2b1a1c1af555 --- /dev/null +++ b/cppunit/source/result/signal.cxx @@ -0,0 +1,1003 @@ +/************************************************************************* + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: signal.cxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: lla $ $Date: 2008-02-27 16:27:23 $ + * + * The Contents of this file are made available subject to + * the terms of GNU Lesser General Public License Version 2.1. + * + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2005 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_cppunit.hxx" + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#if (defined UNX) || (defined OS2) +#include <signal.h> +#include <errno.h> +#endif + +#include <fstream> +#include <vector> +#include <hash_map> + +#include <rtl/tres.h> +#include <rtl/string.hxx> + +#include "testshl/autoregisterhelper.hxx" +#include "testshl/getopt.hxx" +#include "signal.hxx" +#include <cppunit/tagvalues.hxx> +#include <unistd.h> +#include "testshl/filehelper.hxx" +#include <cppunit/result/TestResult.h> +#include "cppunit/signaltest.h" +#include "cppunit/Exception.h" + +#ifdef WNT +#include "testshl/winstuff.hxx" +#endif + +// typedef std::vector<std::string> StringList; +// StringList sCurrentNodeName; +CppUnit::TestResult *pTestResult = NULL; +std::string sSignalFile; + +typedef std::hash_map< std::string, int > HashMap; +HashMap m_aSignalHash; +bool bSignalsCached = false; +bool bDoNotTouchSignalFile = false; + +// ----------------------------------------------------------------------------- + +// return 'true' if signalfile doesn't exist. +// else 'false' +bool existsSignalFile(std::string const& _sSignalFilename) +{ + FILE* pFile = fopen(_sSignalFilename.c_str(), "r"); + if (!pFile) + { + return false; + } + fprintf(stderr, "'%s' exists.\n", _sSignalFilename.c_str()); + fclose(pFile); + return true; +} + +// ----------------------------------------------------------------------------- +void createEmptySignalFile(std::string const& _sSignalFilename) +{ + FILE* pFile = fopen(_sSignalFilename.c_str(), "w"); + if (!pFile) + { + fprintf(stderr, "error: Could not create signal helper file %s for signal info.\n", _sSignalFilename.c_str()); + } + else + { + fprintf(pFile, "# This is an auto generated helper file for signal handling.\n"); + fprintf(pFile, "# An entry start by '#' is a comment.\n"); + fprintf(pFile, "# All other are test functions which have abort, before this line is removed.\n"); + fprintf(pFile, "# So you have to check this functions by hand.\n"); + + fclose(pFile); + } +} + +// ----------------------------------------------------------------------------- +/** get Current PID. +*/ +inline ::rtl::OUString getCurrentPID( ) +{ + //~ Get current PID and turn it into OUString; + sal_uInt32 nPID = 0; +#ifdef WNT + nPID = WinGetCurrentProcessId(); +#else + nPID = getpid(); +#endif + return ( ::rtl::OUString::valueOf( static_cast<long>(nPID ) ) ); +} +// ----------------------------------------------------------------------------- +static std::string integerToAscii(sal_uInt32 nValue) +{ + sal_Char cBuf[30]; + sal_Char *pBuf = cBuf; + sprintf(pBuf, "%d", static_cast<unsigned int>(nValue)); + return std::string(pBuf); +} +void my_sleep(int sec); + +// ----------------------------------------------------------------------------- +void setSignalFilename(GetOpt & opt) +{ + if (opt.hasOpt("-dntsf") || opt.hasOpt("-donottouchsignalfile")) + { + // special feature, for debugging, so the signal file will not manipulate. + // but create, if no one exist. + bDoNotTouchSignalFile = true; + } + + if (opt.hasOpt("-sf") || opt.hasOpt("-signalfile")) + { + if (opt.hasOpt("-sf")) + { + sSignalFile = opt.getOpt("-sf"); + } + else if (opt.hasOpt("-signalfile")) + { + sSignalFile = opt.getOpt("-signalfile"); + } + } + else + { + std::string sPath; + // std::string sPath(FileHelper::getTempPath()); + std::string sFilename("signalfile"); + std::string sFilenameExt(".txt"); + bool bCanQuitLoop = true; + do + { + +// #ifdef WNT +// sPath += "\\"; +// #endif +// #ifdef UNX +// sPath += "/"; +// #endif + sPath = sFilename; + // BUG: i72675 + // add "_12345" where 12345 is the current process ID + + TimeValue aTimeValue; + osl_getSystemTime(&aTimeValue); + + sPath += "_"; + sPath += integerToAscii(aTimeValue.Seconds); + // rtl::OUString suPID = getCurrentPID(); + // rtl::OString sPID = rtl::OUStringToOString(suPID, RTL_TEXTENCODING_ASCII_US); + // sPath += sPID.getStr(); + sPath += sFilenameExt; + bCanQuitLoop = true; + if (existsSignalFile(sPath)) + { + // there is already a signal file, wait a second, choose an other one. + my_sleep(1); + bCanQuitLoop = false; + } + } + while (!(bCanQuitLoop)); + + sSignalFile = sPath; + fprintf(stderr, "Use default signal file name '%s'\n", sSignalFile.c_str()); + } + + if (opt.hasOpt("-dnrmsf")) + { + fprintf(stderr, "'Don't remove signal file' (-dnrmsf) is set.\n"); + } + else + { + if (bDoNotTouchSignalFile == true) + { + fprintf(stderr, "warning: 'Don't touch signal file' parameter (-dntsf) is set, will not remove existing signal file.\n"); + } + else + { + // remove signalfile + createEmptySignalFile(sSignalFile); + } + } +} + +// ----------------------------------------------------------------------------- +bool doNotTouchSignalFile() { return bDoNotTouchSignalFile; } + +// ----------------------------------------------------------------------------- +std::string buildTestFunctionName(std::string const& _sName) +{ + std::string sName; + if (pTestResult) + { + sName = pTestResult->getNodeName(); + sName += "."; + } + +/* + for (StringList::const_iterator it = sCurrentNodeName.begin(); + it != sCurrentNodeName.end(); + ++it) + { + sName += *it; + sName += "."; + } +*/ + sName += _sName; + + return sName; +} +// ----------------------------------------------------------------------------- +// old: void executionPushName(std::string const& _sName) +// old: { +// old: sCurrentNodeName.push_back(_sName); +// old: } +// old: void executionPopName() +// old: { +// old: sCurrentNodeName.pop_back(); +// old: } +// old: + +// ----------------------------------------------------------------------------- +// ------------------------------ Signal Handling ------------------------------ +// ----------------------------------------------------------------------------- + +// std::string sLastTestFunctionName; + +std::string getSignalName(sal_Int32 nSignalNo); +// ----------------------------------------------------------------------------- + +std::string getSignalFilename() +{ + return sSignalFile; +} + +// ----------------------------------------------------------------------------- +// void storeNoSignal(std::string const& _sTestName) +// { + // sLastTestFunctionName = buildTestFunctionName(_sTestName); + // std::ofstream out(getSignalFilename().c_str(), std::ios::out); + // out << NO_SIGNAL << std::endl; // no signal! +// } + +void markSignalAsAlreadyDone(sal_Int32 _nSignalNo) +{ + // std::ofstream out(getSignalFilename().c_str(), std::ios::out | std::ios::app); + FILE *out = fopen(getSignalFilename().c_str(), "a"); + if (out != NULL) + { +//# out << "# the previous test function creates signal: " +//# << getSignalName(_nSignalNo) +//# << " (" +//# << _nSignalNo +//# << ")" << std::endl; +//# // out << sLastTestFunctionName << std::endl; // SIGNAL! + + fprintf(out, "# the previous test function creates signal: %s(%d)\n", getSignalName(_nSignalNo).c_str(), SAL_STATIC_CAST(int, _nSignalNo)); + // fprintf(out, "%s\n", sLastTestFunctionName ); + fclose(out); + } + else + { + fprintf(stderr, "error: Can't write signal info to file %s \n", getSignalFilename().c_str()); + } +} + +// ----------------------------------------------------------------------------- + +Signal hasSignaled(std::string const& _sTestName) +{ + // BACK: true: signal + // false: nothing + + if (bSignalsCached == true) + { + + if (m_aSignalHash.find(buildTestFunctionName(_sTestName)) != m_aSignalHash.end()) + { + return HAS_SIGNAL; + } + return NO_SIGNAL; + } + + std::ifstream in(getSignalFilename().c_str(), std::ios::in); + + // std::cout << "Check for signal" << std::endl; + std::string sLine, sLastLine; + while (std::getline(in, sLine)) + { + // std::cout << sTest << std::endl; + char ch = sLine[0]; + if (isspace(ch) == 0 && + sLine.size() > 0) + { + if (ch == '#') + { + if (sLastLine.size() > 0) + { + rtl::OString aStrLine(sLine.c_str()); + sal_Int32 nIdx = aStrLine.indexOf("(") + 1; + sal_Int32 nIdx2 = aStrLine.indexOf(")"); + sal_Int32 nSignalNo = 0; + if (nIdx > 0 && nIdx2 > 0) + { + rtl::OString sSignalNo = aStrLine.copy(nIdx, nIdx2 - nIdx); + nSignalNo = sSignalNo.toInt32(); + m_aSignalHash[sLastLine] = nSignalNo; + } + sLastLine.clear(); + } + } + else + { + // if (sTest == buildTestFunctionName(_sTestName)) + m_aSignalHash[sLine] = 1; + sLastLine = sLine; + // return HAS_SIGNAL; + } + } + } + + bSignalsCached = true; + return hasSignaled(_sTestName); + // return NO_SIGNAL; +} + +#ifdef UNX + +// ----------------------------------------------------------------------------- + +void release_signal_Handling(); + +//# void signalFunction(int value) +//# { +//# std::cout << "Signal caught: (" << value << "), please restart." << std::endl; +//# markSignalAsAlreadyDone(); +//# +//# release_signal_Handling(); +//# std::cout.flush(); +//# abort(); +//# } + +// ----------------------------------------------------------------------------- +extern "C" void SignalHandlerFunction(int _nSignalNo, siginfo_t *, void*) +{ + // std::cout << "Signal caught: " << getSignalName(_nSignalNo) << " (" << _nSignalNo << "), please restart." << std::endl; + fprintf(stderr, "Signal caught %s(%d)\n", getSignalName(_nSignalNo).c_str(), _nSignalNo); + markSignalAsAlreadyDone(_nSignalNo); + + release_signal_Handling(); + // std::cout.flush(); + abort(); +} + +// ----------------------------------------------------------------------------- +// This is a copy of the osl/signal.c code +#define ACT_IGNORE 1 +#define ACT_ABORT 2 +#define ACT_EXIT 3 +#define ACT_SYSTEM 4 +#define ACT_HIDE 5 + +extern "C" { +static struct SignalAction +{ + int Signal; + int Action; + void (*Handler)(int); +} Signals[] = +{ + { SIGHUP, ACT_IGNORE, NULL }, /* hangup */ + { SIGINT, ACT_EXIT, NULL }, /* interrupt (rubout) */ + { SIGQUIT, ACT_ABORT, NULL }, /* quit (ASCII FS) */ + { SIGILL, ACT_SYSTEM, NULL }, /* illegal instruction (not reset when caught) */ +/* changed from ACT_ABOUT to ACT_SYSTEM to try and get collector to run*/ + { SIGTRAP, ACT_ABORT, NULL }, /* trace trap (not reset when caught) */ +#if ( SIGIOT != SIGABRT ) + { SIGIOT, ACT_ABORT, NULL }, /* IOT instruction */ +#endif +// { SIGABRT, ACT_ABORT, NULL }, /* used by abort, replace SIGIOT in the future */ +#ifdef SIGEMT + { SIGEMT, ACT_SYSTEM, NULL }, /* EMT instruction */ +/* changed from ACT_ABORT to ACT_SYSTEM to remove handler*/ +/* SIGEMT may also be used by the profiler - so it is probably not a good + plan to have the new handler use this signal*/ +#endif + { SIGFPE, ACT_ABORT, NULL }, /* floating point exception */ + { SIGKILL, ACT_SYSTEM, NULL }, /* kill (cannot be caught or ignored) */ + { SIGBUS, ACT_ABORT, NULL }, /* bus error */ + { SIGSEGV, ACT_ABORT, NULL }, /* segmentation violation */ +#ifdef SIGSYS + { SIGSYS, ACT_ABORT, NULL }, /* bad argument to system call */ +#endif + { SIGPIPE, ACT_HIDE, NULL }, /* write on a pipe with no one to read it */ + { SIGALRM, ACT_EXIT, NULL }, /* alarm clock */ + { SIGTERM, ACT_EXIT, NULL }, /* software termination signal from kill */ + { SIGUSR1, ACT_SYSTEM, NULL }, /* user defined signal 1 */ + { SIGUSR2, ACT_SYSTEM, NULL }, /* user defined signal 2 */ + { SIGCHLD, ACT_SYSTEM, NULL }, /* child status change */ +#ifdef SIGPWR + { SIGPWR, ACT_IGNORE, NULL }, /* power-fail restart */ +#endif + { SIGWINCH, ACT_IGNORE, NULL }, /* window size change */ + { SIGURG, ACT_EXIT, NULL }, /* urgent socket condition */ +#ifdef SIGPOLL + { SIGPOLL, ACT_EXIT, NULL }, /* pollable event occured */ +#endif + { SIGSTOP, ACT_SYSTEM, NULL }, /* stop (cannot be caught or ignored) */ + { SIGTSTP, ACT_SYSTEM, NULL }, /* user stop requested from tty */ + { SIGCONT, ACT_SYSTEM, NULL }, /* stopped process has been continued */ + { SIGTTIN, ACT_SYSTEM, NULL }, /* background tty read attempted */ + { SIGTTOU, ACT_SYSTEM, NULL }, /* background tty write attempted */ + { SIGVTALRM, ACT_EXIT, NULL }, /* virtual timer expired */ + { SIGPROF, ACT_SYSTEM, NULL }, /* profiling timer expired */ +/*Change from ACT_EXIT to ACT_SYSTEM for SIGPROF is so that profiling signals do + not get taken by the new handler - the new handler does not pass on context + information which causes 'collect' to crash. This is a way of avoiding + what looks like a bug in the new handler*/ + { SIGXCPU, ACT_ABORT, NULL }, /* exceeded cpu limit */ + { SIGXFSZ, ACT_ABORT, NULL } /* exceeded file size limit */ +}; +} + +const int NoSignals = sizeof(Signals) / sizeof(struct SignalAction); + +#endif /* UNX */ + +// ----------------------------------------------------------------------------- +void init_signal_Handling(CppUnit::TestResult *_pResult) +{ + pTestResult = _pResult; +#ifdef UNX + +// signal(SIGSEGV, signalFunction); + // signal(SIGSEGV, signalFunction); + // signal(SIGFPE, signalFunction); + +// signal(1, signalFunction); + // struct sigaction action, oldaction; + // action.sa_sigaction = signalFunction2; + // action.sa_flags = SA_ONESHOT /* | SA_SIGINFO */; + + struct sigaction act; + struct sigaction oact; + + // act.sa_handler = SignalHandlerFunction; + act.sa_flags = SA_RESTART; + // act.sa_flags = SA_ONESHOT /* | SA_SIGINFO */; + act.sa_sigaction = SignalHandlerFunction; + + sigfillset(&(act.sa_mask)); + + /* Initialize the rest of the signals */ + for (int i = 0; i < NoSignals; i++) + { + if (Signals[i].Action != ACT_SYSTEM) + { + if (Signals[i].Action == ACT_HIDE) + { + struct sigaction ign; + + ign.sa_handler = SIG_IGN; + ign.sa_flags = 0; + sigemptyset(&ign.sa_mask); + + if (sigaction(Signals[i].Signal, &ign, &oact) == 0) + Signals[i].Handler = oact.sa_handler; + else + Signals[i].Handler = SIG_DFL; + } + else + if (sigaction(Signals[i].Signal, &act, &oact) == 0) + Signals[i].Handler = oact.sa_handler; + else + Signals[i].Handler = SIG_DFL; + } + } +#endif + + // ------------ signal helper file must exist ----------------- + FILE* pFile = fopen(getSignalFilename().c_str(), "r"); + if (!pFile) + { + createEmptySignalFile( getSignalFilename() ); + } + else + { + fclose(pFile); + } +} + +// ----------------------------------------------------------------------------- +void release_signal_Handling() +{ + // frees all signals +#ifdef UNX + int i; + struct sigaction act; + + act.sa_flags = 0; + sigemptyset(&(act.sa_mask)); + + /* Initialize the rest of the signals */ + for (i = NoSignals - 1; i >= 0; i--) + { + if (Signals[i].Action != ACT_SYSTEM) + { + act.sa_handler = Signals[i].Handler; + + sigaction(Signals[i].Signal, &act, NULL); + } + } +#endif +} + +// ----------------------------------------------------------------------------- +Signal signalCheck(CppUnit::TestResult* _pResult, std::string const& _sTestName) +{ + // BACK: HAS_SIGNAL: the test has already done and signaled + if (hasSignaled(_sTestName) == HAS_SIGNAL) + { + // std::cout << "The Test '" << buildTestFunctionName(_sTestName) << "' is marked as signaled." << std::endl; + std::string sTestFunctionName = buildTestFunctionName(_sTestName); + fprintf(stderr, "The Test '%s' is marked as signaled.\n", sTestFunctionName.c_str()); + if (_pResult) + { + CppUnit::SignalTest *pTest = new CppUnit::SignalTest(_sTestName); + + std::string sErrorText = "Function is marked as signaled: "; + sal_Int32 nSignalNo = m_aSignalHash[sTestFunctionName]; + sErrorText += getSignalName(nSignalNo); + sErrorText += " ("; + sErrorText += OptionHelper::integerToAscii(nSignalNo); + sErrorText += ")"; + + _pResult->addError(pTest, new CppUnit::SignalException(sErrorText), ErrorType::ET_SIGNAL); + } + return HAS_SIGNAL; + } + + // storeNoSignal(_sTestName); + return NO_SIGNAL; +} + +// ----------------------------------------------------------------------------- +bool copyFile(std::string const& _sFrom, std::string const& _sTo) +{ + bool bRetValue = false; + const int MAXBUFSIZE = 1024; + char buff[MAXBUFSIZE]; + FILE *in = fopen(_sFrom.c_str(), "r"); + if (in == NULL) + { + fprintf(stderr, "error: Can't open file %s for read to copy.\n", _sFrom.c_str()); + bRetValue = false; + } + else + { + FILE *out = fopen(_sTo.c_str(), "w"); + if (out == NULL) + { + fclose(in); + fprintf(stderr, "error: Can't open file %s for write to copy.\n", _sTo.c_str()); + bRetValue = false; + } + else + { + int nRealGot = 0; + while(!feof(in)) + { + nRealGot = fread(buff, sizeof(char), MAXBUFSIZE, in); + if (nRealGot > 0) + { + fwrite(buff, sizeof(char), nRealGot, out); + } + } + bRetValue = true; + fclose(out); + fclose(in); + } + } + return bRetValue; +} + +// ----------------------------------------------------------------------------- +void signalStartTest(std::string const& _sName) +{ + if (doNotTouchSignalFile()) return; + + // fprintf(stderr, "### signalStartTest!\n"); + // due to the fact, that functions are vicious, we write the name first. + // if it isn't vivious, than we removed it. + std::string sNewName = getSignalFilename(); + sNewName += ".bak"; + if (copyFile(getSignalFilename(), sNewName)) + { + // std::ofstream out(getSignalFilename().c_str(), std::ios::out | std::ios::app); + FILE *out = fopen(getSignalFilename().c_str(), "a"); + if (out != NULL) + { + // out << buildTestFunctionName(_sName) << std::endl; + fprintf(out, "%s\n", buildTestFunctionName(_sName).c_str()); + fclose(out); + } + else + { + fprintf(stderr, "error: Can't open file %s for append.\n", getSignalFilename().c_str()); + } + } + else + { + fprintf(stderr, "error: Can't copy signal helper from file %s to file %s, %d\n", getSignalFilename().c_str(), sNewName.c_str(), errno); + } +} + +// ----------------------------------------------------------------------------- +void signalEndTest() +{ + if (doNotTouchSignalFile()) return; + + // fprintf(stderr, "### signalEndTest!\n"); + if (0 != remove(getSignalFilename().c_str())) + { + fprintf(stderr, "error: Can't delete file %s\n", getSignalFilename().c_str()); + } + else + { + std::string sNewName = getSignalFilename(); + sNewName += ".bak"; + if (0 != rename(sNewName.c_str(), getSignalFilename().c_str())) + { + fprintf(stderr, "error: Can't rename file %s to file %s errno: %d\n", sNewName.c_str(), getSignalFilename().c_str(), errno); + } + } +} + +// ----------------------------------------------------------------------------- +void removeSignalFile(GetOpt & opt) +{ + // fprintf(stderr, "### remove signal file: '%s'\n", sSignalFile.c_str()); + if (opt.hasOpt("-dnrmsf")) + { + return; + } + if (bDoNotTouchSignalFile == true) + { + return; + } + remove(getSignalFilename().c_str()); +} + +// ----------------------------------------------------------------------------- + +sal_Int32 SignalHandlerA( TagHelper const& _aTagItems ) +{ + sal_Int32 nRetValue = 0; + TagData nTagType = _aTagItems.GetTagData(TAG_TYPE, 0); +// LLA: unused +// hTestResult hResult = (hTestResult) _aTagItems.GetTagData(TAG_RESULT_PTR, 0 /* NULL */ ); +// CppUnit::TestResult* pResult = (CppUnit::TestResult*)hResult; + + try + { + switch(nTagType) + { + // old: case SIGNAL_PUSH_NAME: + // old: { + // old: const char* sName = (const char*) _aTagItems.GetTagData(TAG_NODENAME); + // old: if (sName != NULL) + // old: signalPushName(sName); + // old: break; + // old: } + // old: + // old: case SIGNAL_POP_NAME: + // old: signalPopName(); + // old: break; + + // old: case SIGNAL_CHECK: + // old: { + // old: const char* sName = (const char*) _aTagItems.GetTagData(TAG_NODENAME); + // old: if (sName != NULL) + // old: { + // old: nRetValue = signalCheck(sName); + // old: } + // old: break; + // old: } + + // old: case INIT_SIGNAL_HANDLING: + // old: init_signal_Handling(); + // old: break; + // old: + // old: case RELEASE_SIGNAL_HANDLING: + // old: release_signal_Handling(); + // old: break; + + case SIGNAL_START_TEST: + { + // fprintf(stderr, "### SIGNAL_START_TEST!\n"); + const char* sName = (const char*) _aTagItems.GetTagData(TAG_NODENAME); + if (sName != NULL) + { + signalStartTest(sName); + } + break; + } + + case SIGNAL_END_TEST: + { + // fprintf(stderr, "### SIGNAL_END_TEST!\n"); + const char* sName = (const char*) _aTagItems.GetTagData(TAG_NODENAME); + if (sName != NULL) + { + signalEndTest(); + } + break; + } + + default: + fprintf(stderr, "error: SignalHandlerA: Can't handle the tag type %d\n", SAL_STATIC_CAST(int, nTagType)); + fflush(stderr); + // throw std::exception(/*std::string("Unknown TYPE_TAG Exception.")*/); + } + } + catch (std::exception &e) + { + fprintf(stderr, "error: SignalHandlerA: Exception caught: %s\n", e.what()); + fflush(stderr); + // throw e; + } + + return nRetValue; +} +// ----------------------------------------------------------------------------- +// This a little bit more abstract code, could be easier to modify or expand. + +sal_Int32 CheckExecution(CppUnit::TestResult* _pResult, std::string const& _sName) +{ + // more checks in the corresponding job lists + if (_pResult) + { + if (! _pResult->isAllowedToExecute(_sName)) + { + return DO_NOT_EXECUTE; + } + } + + // Check if the given test should be executed. + if (signalCheck(_pResult, _sName) == HAS_SIGNAL) + { + return DO_NOT_EXECUTE; + } + + return GO_EXECUTE; +} + +// ----------------------------------------------------------------------------- +sal_Int32 ExecutionA( TagHelper const& _aTagItems ) +{ + sal_Int32 nRetValue = 0; + TagData nTagType = _aTagItems.GetTagData(TAG_TYPE, 0); + hTestResult hResult = (hTestResult) _aTagItems.GetTagData(TAG_RESULT_PTR, 0 /* NULL */ ); + CppUnit::TestResult* pResult = (CppUnit::TestResult*)hResult; + + try + { + switch(nTagType) + { + case EXECUTION_CHECK: + { + const char* sName = (const char*) _aTagItems.GetTagData(TAG_NODENAME); + if (sName) + { + nRetValue = CheckExecution(pResult, sName); + if (nRetValue == GO_EXECUTE) + { + if (pResult && pResult->isOptionWhereAmI()) + { + printf("# This is: %s\n", buildTestFunctionName(sName).c_str()); + } + } + } + + break; + } + + // old: case EXECUTION_PUSH_NAME: + // old: { + // old: const char* sName = (const char*) _aTagItems.GetTagData(TAG_NODENAME); + // old: if (sName != NULL) + // old: executionPushName(sName); + // old: break; + // old: } + // old: + // old: case EXECUTION_POP_NAME: + // old: executionPopName(); + // old: break; + + case INIT_TEST: + init_signal_Handling(pResult); + break; + + case RELEASE_TEST: + release_signal_Handling(); + break; + + default: + fprintf(stderr, "ExceptionA: Can't handle the tag type %d\n", SAL_STATIC_CAST(int, nTagType)); + break; + } + } + catch (std::exception &e) + { + fprintf(stderr, "ExecutionA: exception caught: %s\n", e.what()); + fflush(stderr); + // throw e; + } + return nRetValue; +} + +// ----------------------------------------------------------------------------- +std::string getSignalName(sal_Int32 nSignalNo) +{ + std::string sValue; +#ifdef UNX + switch(nSignalNo) + { + case SIGHUP: + sValue = "SIGHUP"; + break; + + case SIGINT: + sValue = "SIGINT"; + break; + + case SIGQUIT: + sValue = "SIGQUIT"; + break; + + case SIGILL: + sValue = "SIGILL"; + break; + + case SIGTRAP: + sValue = "SIGTRAP"; + break; + +#if ( SIGIOT != SIGABRT ) + case SIGIOT: + sValue = "SIGIOT"; + break; +#endif +// case SIGABRT: +#ifdef SIGEMT + case SIGEMT: + sValue = "SIGEMT"; + break; +#endif + case SIGFPE: + sValue = "SIGFPE"; + break; + + case SIGKILL: + sValue = "SIGKILL"; + break; + + case SIGBUS: + sValue = "SIGBUS"; + break; + + case SIGSEGV: + sValue = "SIGSEGV"; + break; + +#ifdef SIGSYS + case SIGSYS: + sValue = "SIGSYS"; + break; +#endif + case SIGPIPE: + sValue = "SIGPIPE"; + break; + + case SIGALRM: + sValue = "SIGALRM"; + break; + + case SIGTERM: + sValue = "SIGTERM"; + break; + + case SIGUSR1: + sValue = "SIGUSR1"; + break; + + case SIGUSR2: + sValue = "SIGUSR2"; + break; + + case SIGCHLD: + sValue = "SIGCHLD"; + break; + +#ifdef SIGPWR + case SIGPWR: + sValue = "SIGPWR"; + break; +#endif + case SIGWINCH: + sValue = "SIGWINCH"; + break; + + case SIGURG: + sValue = "SIGURG"; + break; + +#ifdef SIGPOLL + case SIGPOLL: + sValue = "SIGPOLL"; + break; +#endif + case SIGSTOP: + sValue = "SIGSTOP"; + break; + + case SIGTSTP: + sValue = "SIGTSTP"; + break; + + case SIGCONT: + sValue = "SIGCONT"; + break; + + case SIGTTIN: + sValue = "SIGTTIN"; + break; + + case SIGTTOU: + sValue = "SIGTTOU"; + break; + + case SIGVTALRM: + sValue = "SIGVTALRM"; + break; + + case SIGPROF: + sValue = "SIGPROF"; + break; + + case SIGXCPU: + sValue = "SIGXCPU"; + break; + + case SIGXFSZ: + sValue = "SIGXFSZ"; + break; + + default: + sValue = "Unhandled Signal."; + } +#else + (void) nSignalNo; // unused +#endif + return sValue; +} + +// The following sets variables for GNU EMACS +// Local Variables: +// tab-width:4 +// End: diff --git a/cppunit/source/result/signal.hxx b/cppunit/source/result/signal.hxx new file mode 100644 index 000000000000..4e2564a8d4f3 --- /dev/null +++ b/cppunit/source/result/signal.hxx @@ -0,0 +1,47 @@ +/************************************************************************* + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: signal.hxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: lla $ $Date: 2008-02-27 16:27:34 $ + * + * The Contents of this file are made available subject to + * the terms of GNU Lesser General Public License Version 2.1. + * + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2005 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + ************************************************************************/ + +#ifndef SIGNAL_HXX +#define SIGNAL_HXX + +#include <sal/types.h> + +#define HAS_SIGNAL 1 +#define NO_SIGNAL 0 + +typedef sal_Int32 Signal; + +#endif + diff --git a/cppunit/source/result/testshlTestResult.cxx b/cppunit/source/result/testshlTestResult.cxx new file mode 100644 index 000000000000..4ffe65a82849 --- /dev/null +++ b/cppunit/source/result/testshlTestResult.cxx @@ -0,0 +1,433 @@ +/************************************************************************* + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: testshlTestResult.cxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: lla $ $Date: 2008-02-27 16:26:38 $ + * + * The Contents of this file are made available subject to + * the terms of GNU Lesser General Public License Version 2.1. + * + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2005 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_cppunit.hxx" + +#include <stdlib.h> + +#include <map> +#include <cppunit/Exception.h> +#include <cppunit/NotEqualException.h> +#include <cppunit/Test.h> +#include <cppunit/TestFailure.h> +#include <cppunit/result/testshlTestResult.h> +// #include <TextTestResult.h> +//!io #include <iostream> +#include <string> + +#include <rtl/string.hxx> +#include "cppunit/result/outputter.hxx" + +namespace CppUnit { + + testshlTestResult::testshlTestResult(GetOpt & _aOptions) + :TestResult(_aOptions), + m_aOptions(_aOptions), + // m_aOptionHelper(_aOptions), + m_aResulter(this) + { + addListener( &m_aResulter ); + } + + testshlTestResult::~testshlTestResult() + { + } + +//# void +//# testshlTestResult::addFailure( const TestFailure &failure ) +//# { +//# // TestResultCollector::addFailure( failure ); +//# // std::cerr << ( failure.isError() ? "E" : "F" ); +//# m_aResulter.addFailure(failure); +//# } +//# +//# +//# void +//# testshlTestResult::startTest( Test *test ) +//# { +//# // TestResultCollector::startTest (test); +//# m_aResulter.startTest(test); +//# // std::cerr << "."; +//# } +//# +//# void testshlTestResult::endTest( Test *test ) +//# { +//# } + +// ----------------------------------------------------------------------------- + +//# void +//# testshlTestResult::printFailures( Outputter &stream ) +//# { +//# TestFailures::const_iterator itFailure = failures().begin(); +//# int failureNumber = 1; +//# while ( itFailure != failures().end() ) +//# { +//# stream << std::endl; +//# printFailure( *itFailure++, failureNumber++, stream ); +//# } +//# } +//# +//# +//# void +//# testshlTestResult::printFailure( TestFailure *failure, +//# int failureNumber, +//# std::ostream &stream ) +//# { +//# printFailureListMark( failureNumber, stream ); +//# stream << ' '; +//# printFailureTestName( failure, stream ); +//# stream << ' '; +//# printFailureType( failure, stream ); +//# stream << ' '; +//# printFailureLocation( failure->sourceLine(), stream ); +//# stream << std::endl; +//# printFailureDetail( failure->thrownException(), stream ); +//# stream << std::endl; +//# } +//# +//# +//# void +//# testshlTestResult::printFailureListMark( int failureNumber, +//# std::ostream &stream ) +//# { +//# stream << failureNumber << ")"; +//# } +//# +//# +//# void +//# testshlTestResult::printFailureTestName( TestFailure *failure, +//# std::ostream &stream ) +//# { +//# Test* pTest = failure->failedTest(); +//# stream << "test: " << pTest->getName(); +//# } +//# +//# +//# void +//# testshlTestResult::printFailureType( TestFailure *failure, +//# std::ostream &stream ) +//# { +//# stream << "(" +//# << (failure->isError() ? "E" : "F") +//# << ")"; +//# } +//# +//# +//# void +//# testshlTestResult::printFailureLocation( SourceLine sourceLine, +//# std::ostream &stream ) +//# { +//# if ( !sourceLine.isValid() ) +//# return; +//# +//# stream << "line: " << sourceLine.lineNumber() +//# << ' ' << sourceLine.fileName(); +//# } +//# +//# +//# void +//# testshlTestResult::printFailureDetail( Exception *thrownException, +//# std::ostream &stream ) +//# { +//# if ( thrownException->isInstanceOf( NotEqualException::type() ) ) +//# { +//# NotEqualException *e = (NotEqualException*)thrownException; +//# stream << "expected: " << e->expectedValue() << std::endl +//# << "but was: " << e->actualValue(); +//# if ( !e->additionalMessage().empty() ) +//# { +//# stream << std::endl; +//# stream << "additional message:" << std::endl +//# << e->additionalMessage(); +//# } +//# } +//# else +//# { +//# stream << " \"" << thrownException->what() << "\""; +//# } +//# } + + +// LLA: output format: +// Header +// # -- BEGIN +// Error lines +// No error lines +// unknown lines +// # -- END +// Text 'Test #PASSED#' or 'Errors only' + +void +testshlTestResult::print( Outputter& stream ) +{ + printHeader( stream ); + // stream << std::endl; + // printFailures( stream ); + + bool bPassed = false; + if (isOnlyShowJobs()) + { + JobList jl(m_aOptionHelper.getJobOnlyList()); + HashMap aJobList = jl.getHashMap(); + printLines(stream, aJobList); + } + else + { + stream << "# -- BEGIN:" << Outputter::endl(); + + TestPtrList aFailedTests; + + // List of failures + printFailedTests(stream, aFailedTests); + + if (! m_aOptionHelper.getOptions().hasOpt("-onlyerrors")) + { + // List of well done tests + printTestLines(stream, aFailedTests); + + // List of unknown Tests + JobList jl(m_aOptionHelper.getJobOnlyList()); + HashMap aJobList = jl.getHashMap(); + printUnknownLines(stream, aJobList); + + bPassed = true; + } + stream << "# -- END:" << Outputter::endl(); + + if (bPassed) + { + stream << "Test #PASSED#" << Outputter::endl(); + } + + if (m_aOptionHelper.getOptions().hasOpt("-onlyerrors")) + { + stream << "Errors only." << Outputter::endl(); + } + } +} + +// ----------------------------------------------------------------------------- +void +testshlTestResult::printLines(Outputter &stream, HashMap & _aJobList) +{ + int nCount = _aJobList.size(); + if (nCount != 0) + { + for (HashMap::const_iterator it = _aJobList.begin(); + it != _aJobList.end(); + ++it) + { + std::string aKey = (*it).first; + if (_aJobList[aKey] == JOB_ACCESS) + { + stream << aKey; + stream << Outputter::endl(); + } + } + } +} + +void +testshlTestResult::printFailedTests(Outputter &stream, TestPtrList &aFailedTests) +{ + for (TestResultCollector::TestFailures::const_iterator it2 = m_aResulter.failures().begin(); + it2 != m_aResulter.failures().end(); + ++it2) + { + TestFailureEnvelope *pEnvelop = *it2; + TestFailure *pFailure = pEnvelop->getTestFailure(); + std::string sNodeName = pEnvelop->getString(); + + aFailedTests[ pFailure->failedTest() ] = true; + + printFailureLine(stream, pFailure, sNodeName); + } +} + +void +testshlTestResult::printTestLines(Outputter &stream, TestPtrList &aFailedTests) +{ + for (TestResultCollector::Tests::const_iterator it = m_aResulter.tests().begin(); + it != m_aResulter.tests().end(); + ++it) + { + TestEnvelope *pEnvelop = *it; + Test* pTest = pEnvelop->getTest(); + std::string sNodeName = pEnvelop->getString(); + + if (aFailedTests.find(pTest) == aFailedTests.end()) + { + std::string sInfo = m_aResulter.getInfo(pTest); + printTestLine(stream, pTest, sNodeName, sInfo); + } + } +} + +void +testshlTestResult::printUnknownLines(Outputter &stream, HashMap & _aJobList) +{ + int nCount = _aJobList.size(); + if (nCount != 0) + { + for (HashMap::const_iterator it = _aJobList.begin(); + it != _aJobList.end(); + ++it) + { + std::string aKey = (*it).first; + if (_aJobList[aKey] == JOB_UNKNOWN) + { + printUnknownLine(stream, aKey); + } + } + } +} + +void +testshlTestResult::printHeader( Outputter &stream ) +{ + std::string sDate(m_aOptionHelper.createDateTag()); + if (isOnlyShowJobs()) + { + stream << "# This is an automatically generated job file." << Outputter::endl(); + stream << "# "; + } + else + { + stream << sDate << Outputter::endl(); + } +} + +void +testshlTestResult::printFailureLine( Outputter &stream, TestFailure *_pFailure, std::string const& _sNodeName) +{ + std::string aName; + aName += _sNodeName; + aName += "."; + aName += _pFailure->failedTestName(); + + SourceLine aLine = _pFailure->sourceLine(); + sal_Int32 nLine = -1; + std::string sFilename; + if (aLine.isValid()) + { + nLine = aLine.lineNumber(); + sFilename = aLine.fileName(); + } + + Exception *pExp = _pFailure->thrownException(); + std::string sWhat; + if (pExp) + { + sWhat = pExp->what(); + } + + ErrorType::num eErr = _pFailure->getErrorType(); + + stream << aName; + stream << ";"; + + if (eErr == ErrorType::ET_FAILURE) + stream << "FAILED"; + + else if (eErr == ErrorType::ET_ERROR) + stream << "ERROR"; + + else if (eErr == ErrorType::ET_SIGNAL) + stream << "SIGNAL"; + + else + stream << "UNKNOWN"; + + stream << "#FAILED#"; + + stream << sWhat; + stream << Outputter::endl(); +} + +void +testshlTestResult::printTestLine( Outputter &stream, Test* _pTest, std::string const& _sNodeName, std::string const& _sInfo) +{ + std::string aName; + aName += _sNodeName; + aName += "."; + aName += _pTest->getName(); + + stream << aName; + stream << ";"; + stream << _sInfo << "#"; + if (_sInfo == "PASSED") + { + stream << "OK#"; + } + else + { + stream << "FAILED#"; + } + stream << Outputter::endl(); +} + +void +testshlTestResult::printUnknownLine( Outputter &stream, std::string const& _sTestName) +{ + stream << _sTestName; + stream << ";"; + stream << "UNKNOWN#"; + stream << "FAILED#"; + stream << Outputter::endl(); +} + +//# void +//# testshlTestResult::printStatistics( Outputter &stream ) +//# { +//# stream << "Test Results:" << std::endl; +//# +//# stream << "Run: " << runTests() +//# << " Failures: " << testFailures() +//# << " Errors: " << testErrors() +//# << std::endl; +//# } + + +Outputter & +operator <<( Outputter &stream, + testshlTestResult &result ) +{ + result.print (stream); return stream; +} + + +} // namespace CppUnit diff --git a/cppunit/source/result/treswrapper.cxx b/cppunit/source/result/treswrapper.cxx new file mode 100644 index 000000000000..782b263688e7 --- /dev/null +++ b/cppunit/source/result/treswrapper.cxx @@ -0,0 +1,266 @@ +/************************************************************************* + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: treswrapper.cxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: lla $ $Date: 2008-02-27 16:26:03 $ + * + * The Contents of this file are made available subject to + * the terms of GNU Lesser General Public License Version 2.1. + * + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2005 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_cppunit.hxx" + +#include <cstdarg> +#include <stdlib.h> +#include <stdio.h> + +#include <sal/types.h> +#include <cppunit/Test.h> +#include "cppunit/autoregister/htestresult.h" +#include "cppunit/autoregister/callbackfunc_fktptr.h" +#include "cppunit/result/callbackfunc.h" +#include "cppunit/result/TestResult.h" + +#include <cppunit/tagvalues.hxx> + +namespace +{ + void TestResult_startTest(hTestResult _pResult, hTest _pTest) + { + CppUnit::TestResult* pResult = (CppUnit::TestResult*)_pResult; + CppUnit::Test* pTest = (CppUnit::Test*)_pTest; + + std::string sName = pTest->getName(); + CallbackDispatch(0 /* NULL */, TAG_TYPE, SIGNAL_START_TEST, TAG_RESULT_PTR, _pResult, TAG_NODENAME, sName.c_str(), TAG_DONE); + + pResult->startTest(pTest); + } + + void TestResult_endTest( hTestResult _pResult, hTest _pTest ) + { + CppUnit::TestResult* pResult = (CppUnit::TestResult*)_pResult; + CppUnit::Test* pTest = (CppUnit::Test*)_pTest; + pResult->endTest(pTest); + + std::string sName = pTest->getName(); + CallbackDispatch(0 /* NULL */, TAG_TYPE, SIGNAL_END_TEST, TAG_RESULT_PTR, _pResult, TAG_NODENAME, sName.c_str(), TAG_DONE); + } + +// ----------------------------------------------------------------------------- + + void TestResult_addFailure( hTestResult _pResult, hTest _pTest, hException _pException ) + { + CppUnit::TestResult* pResult = (CppUnit::TestResult*)_pResult; + CppUnit::Test* pTest = (CppUnit::Test*)_pTest; + CppUnit::Exception* pException = (CppUnit::Exception*)_pException; + pResult->addFailure(pTest, pException); + } + + void TestResult_addError( hTestResult _pResult, hTest _pTest, hException _pException ) + { + CppUnit::TestResult* pResult = (CppUnit::TestResult*)_pResult; + CppUnit::Test* pTest = (CppUnit::Test*)_pTest; + CppUnit::Exception* pException = (CppUnit::Exception*)_pException; + pResult->addError(pTest, pException); + } + + sal_Int32 TestResult_shouldStop(hTestResult _pResult) + { + CppUnit::TestResult* pResult = (CppUnit::TestResult*)_pResult; + return pResult->shouldStop() == true ? 1 : 0; + } + +// ----------------------------------------------------------------------------- + void TestResult_addInfo( hTestResult _pResult, hTest _pTest, const char* _sInfo ) + { + CppUnit::TestResult* pResult = (CppUnit::TestResult*)_pResult; + CppUnit::Test* pTest = (CppUnit::Test*)_pTest; + // CppUnit::Exception* pException = (CppUnit::Exception*)_pException; + pResult->addInfo(pTest, _sInfo); + } +// ----------------------------------------------------------------------------- + void TestResult_enterNode( hTestResult _pResult, const char* _sNode ) + { + // signalPushName(getName()); + // CallbackDispatch(NULL, TAG_TYPE, EXECUTION_PUSH_NAME, TAG_RESULT_PTR, _pResult, TAG_NODENAME, _sNode, TAG_DONE); + + CppUnit::TestResult* pResult = (CppUnit::TestResult*)_pResult; + // CppUnit::Test* pTest = (CppUnit::Test*)_pTest; + // CppUnit::Exception* pException = (CppUnit::Exception*)_pException; + pResult->enterNode(_sNode); + } + void TestResult_leaveNode( hTestResult _pResult, const char* _sNode ) + { + CppUnit::TestResult* pResult = (CppUnit::TestResult*)_pResult; + // CppUnit::Test* pTest = (CppUnit::Test*)_pTest; + // CppUnit::Exception* pException = (CppUnit::Exception*)_pException; + pResult->leaveNode(_sNode); + + // CallbackDispatch(NULL, TAG_TYPE, EXECUTION_POP_NAME, TAG_RESULT_PTR, _pResult, TAG_DONE); + } + +// ----------------------------------------------------------------------------- + sal_Int32 TestResult_StarterA(TagHelper const& _aTagItems) + { + sal_Int32 nRetValue = 0; + TagData nTagType = _aTagItems.GetTagData(TAG_TYPE, 0); + hTestResult pResult = (hTestResult) _aTagItems.GetTagData(TAG_RESULT_PTR, 0 /* NULL */); + CppUnit::Test* pTest = (CppUnit::Test*) _aTagItems.GetTagData(TAG_TEST_PTR, 0 /* NULL */); + + try + { + switch(nTagType) + { + case RESULT_START: + TestResult_startTest(pResult, pTest); + break; + + case RESULT_END: + TestResult_endTest(pResult, pTest); + break; + + case RESULT_ADD_FAILURE: + { + hException pException = (hException) _aTagItems.GetTagData(TAG_EXCEPTION, 0); + TestResult_addFailure(pResult, pTest, pException); + break; + } + + case RESULT_ADD_ERROR: + { + hException pException = (hException) _aTagItems.GetTagData(TAG_EXCEPTION, 0); + TestResult_addError(pResult, pTest, pException); + break; + } + + case RESULT_ADD_INFO: + { + const char* pInfo = (const char* ) _aTagItems.GetTagData(TAG_INFO, 0); + TestResult_addInfo(pResult, pTest, pInfo); + break; + } + + case RESULT_ENTER_NODE: + { + const char* pNode = (const char* )_aTagItems.GetTagData(TAG_NODENAME, 0); + TestResult_enterNode(pResult, pNode); + break; + } + + case RESULT_LEAVE_NODE: + { + const char* pNode = (const char* ) _aTagItems.GetTagData(TAG_NODENAME, 0); + TestResult_leaveNode(pResult, pNode); + break; + } + + case RESULT_SHOULD_STOP: + nRetValue = TestResult_shouldStop(pResult); + break; + + default: + fprintf(stderr, "TestResult_StarterA: Can't handle the tag type %8x\n", SAL_STATIC_CAST(int, nTagType)); + fflush(stderr); + // throw std::exception(/*std::string("Unknown TYPE_TAG Exception.")*/); + } + } + catch (std::exception &e) + { + fprintf(stderr, "TestResult_StarterA: Exception caught: %s\n", e.what()); + // throw e; + } + + return nRetValue; + } +} // namespace anonymous + +// --------------------------------- Prototypes --------------------------------- + +sal_Int32 SignalHandlerA( TagHelper const& _aTagItems ); +sal_Int32 ExecutionA( TagHelper const& _aTagItems ); + +// ----------------------------------------------------------------------------- +sal_Int32 CallbackDispatch(int x, ...) +{ + (void) x; // avoid warning + + // The idea behind TagItems are from the Amiga OS. + // Due to the fact that the following code does not find my ok + // I decide to wrote a simple helper + // + // struct TagItem *tags = (struct TagItem *)&x + 1; + + TagHelper aTagItems; + + // the following code could also be in a #define, so other functions could + // use this, but at the moment this function a the only one. + + // FILL_TAGS(aTagItems, x); + std::va_list args; + va_start( args, x ); + Tag nTag; + do + { + nTag = va_arg(args, Tag); + if (nTag != TAG_DONE) + { + TagData nValue = va_arg(args, TagData); + // printf("Tag: %8x Value:%8x\n", nTag, nValue); + aTagItems.insert(nTag, nValue); + } + } while (nTag != TAG_DONE); + + va_end ( args ); + + // FILL_TAGS:END + + // printf(".\n"); + + sal_Int32 nRetValue = 0; + Tag nPreTag = aTagItems.GetTagData(TAG_TYPE); + if ( (nPreTag & TAG_RESULT) == TAG_RESULT) + { + nRetValue = TestResult_StarterA( aTagItems ); + } + else if ((nPreTag & TAG_SIGNAL) == TAG_SIGNAL) + { + nRetValue = SignalHandlerA(aTagItems); + } + else if (( nPreTag & TAG_EXECUTION) == TAG_EXECUTION) + { + nRetValue = ExecutionA(aTagItems); + } + else + { + fprintf(stderr, "CallbackDispatch: First tag is unknown %8x\n", SAL_STATIC_CAST(int, nPreTag)); + // unknown TAG_TYPE + } + return nRetValue; +} + diff --git a/cppunit/source/win32/makefile.mk b/cppunit/source/win32/makefile.mk new file mode 100644 index 000000000000..3af9bdc40ce5 --- /dev/null +++ b/cppunit/source/win32/makefile.mk @@ -0,0 +1,69 @@ +#************************************************************************* +# +# OpenOffice.org - a multi-platform office productivity suite +# +# $RCSfile: makefile.mk,v $ +# +# $Revision: 1.1 $ +# +# last change: $Author: lla $ $Date: 2008-02-27 16:24:46 $ +# +# The Contents of this file are made available subject to +# the terms of GNU Lesser General Public License Version 2.1. +# +# +# GNU Lesser General Public License Version 2.1 +# ============================================= +# Copyright 2005 by Sun Microsystems, Inc. +# 901 San Antonio Road, Palo Alto, CA 94303, USA +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License version 2.1, as published by the Free Software Foundation. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, +# MA 02111-1307 USA +# +#************************************************************************* +PRJ=..$/.. +PRJINC=.. + +PRJNAME=cppunit +TARGET=c5t_winstuff +LIBTARGET=NO +ENABLE_EXCEPTIONS=TRUE + +# --- Settings ----------------------------------------------------- +.INCLUDE : settings.mk + +# ------------------------------------------------------------------ + +SLOFILES = \ + $(SLO)$/winstuff.obj + +#------------------------------------------------------------------------------- +# This is a static lib +LIB1TARGET= $(LB)$/$(TARGET).lib +LIB1OBJFILES= \ + $(SLOFILES) + +.IF "$(GUI)"=="WNT" +.IF "$(COM)"=="GCC" +LIB2ARCHIV=$(LB)$/lib$(TARGET)$(DLLPOSTFIX).a +.ENDIF +.ENDIF + +.IF "$(GUI)" == "UNX" +LIB2ARCHIV=$(LB)$/lib$(TARGET)$(DLLPOSTFIX).a +.ENDIF + +# --- Targets ------------------------------------------------------ + +.INCLUDE : target.mk diff --git a/cppunit/source/win32/winstuff.cxx b/cppunit/source/win32/winstuff.cxx new file mode 100644 index 000000000000..89c685605d3a --- /dev/null +++ b/cppunit/source/win32/winstuff.cxx @@ -0,0 +1,135 @@ +/************************************************************************* + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: winstuff.cxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: lla $ $Date: 2008-02-27 16:24:35 $ + * + * The Contents of this file are made available subject to + * the terms of GNU Lesser General Public License Version 2.1. + * + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2005 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_cppunit.hxx" + +#include "testshl/winstuff.hxx" + +#if defined _MSC_VER +#pragma warning(push, 1) +#endif +#include <windows.h> +#if defined _MSC_VER +#pragma warning(pop) +#endif +#include <MAPIWin.h> + +void WinDebugBreak() +{ + // forward to WinAPI. Note that the whole story is simply to + // disentangle OOo headers from Windows headers (which are largely + // incompatible, due to name clashes and macro mess-ups) + DebugBreak(); +} + +void WinSleep( sal_uInt32 sec ) +{ + Sleep(sec * 1000); +} + +sal_uInt32 WinGetCurrentProcessId() +{ + return GetCurrentProcessId(); +} + +#define TA_FAILED 0 +#define TA_SUCCESS_CLEAN 1 +#define TA_SUCCESS_KILL 2 +#define TA_SUCCESS_16 3 + + // Declare Callback Enum Functions. +bool CALLBACK TerminateAppEnum( HWND hwnd, LPARAM lParam ); + +/*---------------------------------------------------------------- + DWORD WINAPI TerminateApp( DWORD dwPID, DWORD dwTimeout ) + + Purpose: + Shut down a 32-Bit Process (or 16-bit process under Windows 95) + + Parameters: + dwPID + Process ID of the process to shut down. + + dwTimeout + Wait time in milliseconds before shutting down the process. + + Return Value: + TA_FAILED - If the shutdown failed. + TA_SUCCESS_CLEAN - If the process was shutdown using WM_CLOSE. + TA_SUCCESS_KILL - if the process was shut down with + TerminateProcess(). + NOTE: See header for these defines. + ----------------------------------------------------------------*/ +void WinTerminateApp( sal_uInt32 dwPID, sal_uInt32 dwTimeout ) +{ + HANDLE hProc; + DWORD dwRet; + + // If we can't open the process with PROCESS_TERMINATE rights, + // then we give up immediately. + hProc = OpenProcess(SYNCHRONIZE|PROCESS_TERMINATE, false, + dwPID); + + if(hProc == NULL) + return; + + // TerminateAppEnum() posts WM_CLOSE to all windows whose PID + // matches your process's. + EnumWindows((WNDENUMPROC)TerminateAppEnum, (LPARAM) dwPID); + + // Wait on the handle. If it signals, great. If it times out, + // then you kill it. + if (WaitForSingleObject(hProc, dwTimeout) != WAIT_OBJECT_0) + dwRet= (TerminateProcess(hProc,0) ? TA_SUCCESS_KILL : TA_FAILED); + else + dwRet = TA_SUCCESS_CLEAN; + + CloseHandle(hProc); +} + +bool CALLBACK TerminateAppEnum( HWND hwnd, LPARAM lParam ) +{ + DWORD dwID; + + GetWindowThreadProcessId(hwnd, &dwID); + + if(dwID == (DWORD)lParam) + { + PostMessage(hwnd, WM_CLOSE, 0, 0); + } + + return true; +} |