1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
29 #include "sal/config.h"
30 #include "sal/precppunit.hxx"
36 #include "protectorfactory.hxx"
37 #include "osl/module.h"
38 #include "osl/module.hxx"
39 #include "osl/thread.h"
40 #include "rtl/process.h"
41 #include "rtl/string.h"
42 #include "rtl/string.hxx"
43 #include "rtl/textcvt.h"
44 #include "rtl/ustring.hxx"
46 #include "sal/types.h"
48 #include "cppunit/CompilerOutputter.h"
49 #include "cppunit/TestResult.h"
50 #include "cppunit/TestResultCollector.h"
51 #include "cppunit/TestRunner.h"
52 #include "cppunit/plugin/TestPlugIn.h"
53 #include "cppunit/plugin/PlugInParameters.h"
54 #include "cppunit/extensions/TestFactoryRegistry.h"
55 #include "cppunit/portability/Stream.h"
57 #include "boost/noncopyable.hpp"
63 << ("Usage: cppunittester (--protector <shared-library-path>"
64 " <function-symbol>)* <shared-library-path>")
66 std::exit(EXIT_FAILURE
);
69 rtl::OUString
getArgument(sal_Int32 index
) {
71 rtl_getAppCommandArg(index
, &arg
.pData
);
75 std::string
convertLazy(rtl::OUString
const & s16
) {
76 rtl::OString
s8(rtl::OUStringToOString(s16
, osl_getThreadTextEncoding()));
79 ((static_cast< sal_uInt32
>(s8
.getLength())
80 > (std::numeric_limits
< std::string::size_type
>::max
)())
81 ? (std::numeric_limits
< std::string::size_type
>::max
)()
82 : static_cast< std::string::size_type
>(s8
.getLength())));
85 //Allow the whole uniting testing framework to be run inside a "Protector"
86 //which knows about uno exceptions, so it can print the content of the
87 //exception before falling over and dying
88 class CPPUNIT_API ProtectedFixtureFunctor
: public CppUnit::Functor
, private boost::noncopyable
91 const std::string
&args
;
92 CppUnit::TestResult
&result
;
94 ProtectedFixtureFunctor(const std::string
&args_
, CppUnit::TestResult
&result_
)
101 CppUnit::TestRunner runner
;
102 runner
.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest());
103 CppUnit::TestResultCollector collector
;
104 result
.addListener(&collector
);
106 CppUnit::CompilerOutputter(&collector
, CppUnit::stdCErr()).write();
107 return collector
.wasSuccessful();
109 virtual bool operator()() const
116 extern "C" CppUnitTestPlugIn
117 *cppunitTest_qa_cppu_any(void),
118 *cppunitTest_qa_cppu_unotype(void),
119 *cppunitTest_qa_cppu_reference(void),
120 *cppunitTest_qa_cppu_recursion(void);
123 SAL_IMPLEMENT_MAIN() {
124 TestPlugInSignature plugs
[] = {
125 cppunitTest_qa_cppu_any
,
126 cppunitTest_qa_cppu_unotype
,
127 cppunitTest_qa_cppu_reference
,
128 cppunitTest_qa_cppu_recursion
,
131 CppUnit::TestResult result
;
134 for (TestPlugInSignature
*plug
= plugs
; *plug
!= NULL
; plug
++) {
135 CppUnitTestPlugIn
*iface
;
137 iface
->initialize(&CppUnit::TestFactoryRegistry::getRegistry(), CppUnit::PlugInParameters());
139 ProtectedFixtureFunctor
tests(args
, result
);
142 return ok
? EXIT_SUCCESS
: EXIT_FAILURE
;
145 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */