Make the README.cross a bit more copy&paste proof
[LibreOffice.git] / cppu / qa / cppu_cppunittester_all.cxx
blobbf2a680e63b8b7e8097187938aa35188bbd267eb
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 "precompiled_cppu.hxx"
30 #include "sal/config.h"
31 #include "sal/precppunit.hxx"
33 #include <cstdlib>
34 #include <iostream>
35 #include <limits>
36 #include <string>
37 #include "protectorfactory.hxx"
38 #include "osl/module.h"
39 #include "osl/module.hxx"
40 #include "osl/thread.h"
41 #include "rtl/process.h"
42 #include "rtl/string.h"
43 #include "rtl/string.hxx"
44 #include "rtl/textcvt.h"
45 #include "rtl/ustring.hxx"
46 #include "sal/main.h"
47 #include "sal/types.h"
49 #include "cppunit/CompilerOutputter.h"
50 #include "cppunit/TestResult.h"
51 #include "cppunit/TestResultCollector.h"
52 #include "cppunit/TestRunner.h"
53 #include "cppunit/plugin/TestPlugIn.h"
54 #include "cppunit/plugin/PlugInParameters.h"
55 #include "cppunit/extensions/TestFactoryRegistry.h"
56 #include "cppunit/portability/Stream.h"
58 #include "boost/noncopyable.hpp"
60 namespace {
62 void usageFailure() {
63 std::cerr
64 << ("Usage: cppunittester (--protector <shared-library-path>"
65 " <function-symbol>)* <shared-library-path>")
66 << std::endl;
67 std::exit(EXIT_FAILURE);
70 rtl::OUString getArgument(sal_Int32 index) {
71 rtl::OUString arg;
72 rtl_getAppCommandArg(index, &arg.pData);
73 return arg;
76 std::string convertLazy(rtl::OUString const & s16) {
77 rtl::OString s8(rtl::OUStringToOString(s16, osl_getThreadTextEncoding()));
78 return std::string(
79 s8.getStr(),
80 ((static_cast< sal_uInt32 >(s8.getLength())
81 > (std::numeric_limits< std::string::size_type >::max)())
82 ? (std::numeric_limits< std::string::size_type >::max)()
83 : static_cast< std::string::size_type >(s8.getLength())));
86 //Allow the whole uniting testing framework to be run inside a "Protector"
87 //which knows about uno exceptions, so it can print the content of the
88 //exception before falling over and dying
89 class CPPUNIT_API ProtectedFixtureFunctor : public CppUnit::Functor, private boost::noncopyable
91 private:
92 const std::string &args;
93 CppUnit::TestResult &result;
94 public:
95 ProtectedFixtureFunctor(const std::string &args_, CppUnit::TestResult &result_)
96 : args(args_)
97 , result(result_)
100 bool run() const
102 CppUnit::TestRunner runner;
103 runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest());
104 CppUnit::TestResultCollector collector;
105 result.addListener(&collector);
106 runner.run(result);
107 CppUnit::CompilerOutputter(&collector, CppUnit::stdCErr()).write();
108 return collector.wasSuccessful();
110 virtual bool operator()() const
112 return run();
117 extern "C" CppUnitTestPlugIn
118 *cppunitTest_qa_cppu_any(void),
119 *cppunitTest_qa_cppu_unotype(void),
120 *cppunitTest_qa_cppu_reference(void),
121 *cppunitTest_qa_cppu_recursion(void);
124 SAL_IMPLEMENT_MAIN() {
125 TestPlugInSignature plugs[] = {
126 cppunitTest_qa_cppu_any,
127 cppunitTest_qa_cppu_unotype,
128 cppunitTest_qa_cppu_reference,
129 cppunitTest_qa_cppu_recursion,
130 NULL
132 CppUnit::TestResult result;
133 std::string args;
134 bool ok = false;
135 for (TestPlugInSignature *plug = plugs; *plug != NULL; plug++) {
136 CppUnitTestPlugIn *iface;
137 iface = (*plug)();
138 iface->initialize(&CppUnit::TestFactoryRegistry::getRegistry(), CppUnit::PlugInParameters());
140 ProtectedFixtureFunctor tests(args, result);
141 ok = tests.run();
143 return ok ? EXIT_SUCCESS : EXIT_FAILURE;
146 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */