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/bootstrap.hxx"
41 #include "rtl/process.h"
42 #include "rtl/string.h"
43 #include "rtl/string.hxx"
44 #include "rtl/textcvt.h"
45 #include "rtl/uri.hxx"
46 #include "rtl/ustrbuf.hxx"
47 #include "rtl/ustring.hxx"
49 #include "sal/types.h"
51 #include "cppunit/CompilerOutputter.h"
52 #include "cppunit/TestResult.h"
53 #include "cppunit/TestResultCollector.h"
54 #include "cppunit/TestRunner.h"
55 #include "cppunit/plugin/TestPlugIn.h"
56 #include "cppunit/plugin/PlugInParameters.h"
57 #include "cppunit/extensions/TestFactoryRegistry.h"
58 #include "cppunit/portability/Stream.h"
60 #include "boost/noncopyable.hpp"
66 << ("Usage: cppunittester (--protector <shared-library-path>"
67 " <function-symbol>)* <shared-library-path>")
69 std::exit(EXIT_FAILURE
);
72 rtl::OUString
getArgument(sal_Int32 index
) {
74 rtl_getAppCommandArg(index
, &arg
.pData
);
78 std::string
convertLazy(rtl::OUString
const & s16
) {
79 rtl::OString
s8(rtl::OUStringToOString(s16
, osl_getThreadTextEncoding()));
82 ((static_cast< sal_uInt32
>(s8
.getLength())
83 > (std::numeric_limits
< std::string::size_type
>::max
)())
84 ? (std::numeric_limits
< std::string::size_type
>::max
)()
85 : static_cast< std::string::size_type
>(s8
.getLength())));
88 //Allow the whole uniting testing framework to be run inside a "Protector"
89 //which knows about uno exceptions, so it can print the content of the
90 //exception before falling over and dying
91 class CPPUNIT_API ProtectedFixtureFunctor
: public CppUnit::Functor
, private boost::noncopyable
94 const std::string
&args
;
95 CppUnit::TestResult
&result
;
97 ProtectedFixtureFunctor(const std::string
&args_
, CppUnit::TestResult
&result_
)
104 CppUnit::TestRunner runner
;
105 runner
.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest());
106 CppUnit::TestResultCollector collector
;
107 result
.addListener(&collector
);
109 CppUnit::CompilerOutputter(&collector
, CppUnit::stdCErr()).write();
110 return collector
.wasSuccessful();
112 virtual bool operator()() const
119 extern "C" CppUnitTestPlugIn
120 *cppunitTest_i18npool_breakiterator(void);
123 SAL_IMPLEMENT_MAIN() {
124 rtl::OUString
sServices(RTL_CONSTASCII_USTRINGPARAM("UNO_SERVICES"));
125 rtl::OUString
sTypes(RTL_CONSTASCII_USTRINGPARAM("UNO_TYPES"));
128 osl::Module::getUrlFromAddress((oslGenericFunction
)sal_main
, base
);
130 rtl::OUString sServicesValue
= rtl::Uri::convertRelToAbs(base
, rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("services.rdb")));
131 osl_setEnvironment(sServices
.pData
, sServicesValue
.pData
);
133 rtl::OUString sTypesValue
=
134 rtl::Uri::convertRelToAbs(base
, rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("types.rdb")))
135 + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(" "))
136 + rtl::Uri::convertRelToAbs(base
, rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("udkapi.rdb")));
137 osl_setEnvironment(sTypes
.pData
, sTypesValue
.pData
);
139 TestPlugInSignature plugs
[] = {
140 cppunitTest_i18npool_breakiterator
,
143 CppUnit::TestResult result
;
146 for (TestPlugInSignature
*plug
= plugs
; *plug
!= NULL
; plug
++) {
147 CppUnitTestPlugIn
*iface
;
149 iface
->initialize(&CppUnit::TestFactoryRegistry::getRegistry(), CppUnit::PlugInParameters());
151 ProtectedFixtureFunctor
tests(args
, result
);
154 return ok
? EXIT_SUCCESS
: EXIT_FAILURE
;
157 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */