diff options
author | Jan Holesovsky <kendy@suse.cz> | 2011-03-23 16:59:59 +0100 |
---|---|---|
committer | Jan Holesovsky <kendy@suse.cz> | 2011-03-23 16:59:59 +0100 |
commit | 4be7cca60bc7cc0a066b7384d56624266dc0dfcf (patch) | |
tree | 990b1fda00fca6f26ff74fd29552687b4e3c37ed /sal/cppunittester/cppunittester.cxx | |
parent | 79a6c0f8a28b43c36c3b02dc5e116f2d17e92ef0 (diff) | |
parent | a24842b43a687808376f69d4bdbb45fcddde73c4 (diff) |
Merge commit 'ooo/DEV300_m103'
Conflicts:
codemaker/source/bonobowrappermaker/corbaoptions.cxx
codemaker/source/cppumaker/cppuoptions.cxx
codemaker/source/cunomaker/cunooptions.cxx
codemaker/source/idlmaker/idloptions.cxx
codemaker/source/javamaker/javaoptions.cxx
cppu/source/typelib/typelib.cxx
idlc/source/options.cxx
offapi/com/sun/star/util/PathSubstitution.idl
offapi/drafts/com/sun/star/form/ListEntryEvent.idl
offapi/drafts/com/sun/star/form/XBindableValue.idl
offapi/drafts/com/sun/star/form/XListEntryListener.idl
offapi/drafts/com/sun/star/form/XListEntrySink.idl
offapi/drafts/com/sun/star/form/XListEntrySource.idl
offapi/drafts/com/sun/star/form/XValueBinding.idl
registry/tools/checksingleton.cxx
registry/tools/options.hxx
registry/tools/regcompare.cxx
registry/tools/regmerge.cxx
sal/cppunittester/cppunittester.cxx
sal/osl/unx/socket.c
sal/osl/w32/diagnose.c
sal/prj/d.lst
sal/rtl/source/alloc_fini.cxx
sal/rtl/source/alloc_global.c
sal/rtl/source/makefile.mk
Diffstat (limited to 'sal/cppunittester/cppunittester.cxx')
-rw-r--r-- | sal/cppunittester/cppunittester.cxx | 95 |
1 files changed, 77 insertions, 18 deletions
diff --git a/sal/cppunittester/cppunittester.cxx b/sal/cppunittester/cppunittester.cxx index 87d250114eb9..dd3d724298e3 100644 --- a/sal/cppunittester/cppunittester.cxx +++ b/sal/cppunittester/cppunittester.cxx @@ -29,13 +29,27 @@ #include "precompiled_sal.hxx" #include "sal/config.h" -#include <cstdlib> -#include <iostream> - #ifdef WNT #include <windows.h> #endif +#include <cstdlib> +#include <iostream> +#include <limits> +#include <string> + +#include "cppunittester/protectorfactory.hxx" +#include "osl/module.h" +#include "osl/module.hxx" +#include "osl/thread.h" +#include "rtl/process.h" +#include "rtl/string.h" +#include "rtl/string.hxx" +#include "rtl/textcvt.h" +#include "rtl/ustring.hxx" +#include "sal/main.h" +#include "sal/types.h" + #include "cppunit/CompilerOutputter.h" #include "cppunit/TestResult.h" #include "cppunit/TestResultCollector.h" @@ -43,15 +57,36 @@ #include "cppunit/extensions/TestFactoryRegistry.h" #include "cppunit/plugin/PlugInManager.h" #include "cppunit/portability/Stream.h" -#include "osl/thread.h" -#include "rtl/process.h" -#include "rtl/string.hxx" -#include "rtl/ustring.hxx" -#include "sal/main.h" -SAL_IMPLEMENT_MAIN() -{ +namespace { + +void usageFailure() { + std::cerr + << ("Usage: cppunittester (--protector <shared-library-path>" + " <function-symbol>)* <shared-library-path>") + << std::endl; + std::exit(EXIT_FAILURE); +} + +rtl::OUString getArgument(sal_Int32 index) { + rtl::OUString arg; + rtl_getAppCommandArg(index, &arg.pData); + return arg; +} + +std::string convertLazy(rtl::OUString const & s16) { + rtl::OString s8(rtl::OUStringToOString(s16, osl_getThreadTextEncoding())); + return std::string( + s8.getStr(), + ((static_cast< sal_uInt32 >(s8.getLength()) + > std::numeric_limits< std::string::size_type >::max()) + ? std::numeric_limits< std::string::size_type >::max() + : static_cast< std::string::size_type >(s8.getLength()))); +} +} + +SAL_IMPLEMENT_MAIN() { #ifdef WNT //Disable Dr-Watson in order to crash simply without popup dialogs under //windows @@ -59,31 +94,55 @@ SAL_IMPLEMENT_MAIN() SetErrorMode(SEM_NOGPFAULTERRORBOX|dwMode); #endif - sal_uInt32 nCommandArgs = rtl_getAppCommandArgCount(); - if (nCommandArgs < 1) - { - std::cerr << "Usage: cppunittester <shared-library-path>" << std::endl; - return EXIT_FAILURE; + CppUnit::TestResult result; + sal_uInt32 index = 0; + for (; index < rtl_getAppCommandArgCount(); index += 3) { + if (!getArgument(index).equalsAsciiL( + RTL_CONSTASCII_STRINGPARAM("--protector"))) + { + break; + } + if (rtl_getAppCommandArgCount() - index < 3) { + usageFailure(); + } + rtl::OUString lib(getArgument(index + 1)); + rtl::OUString sym(getArgument(index + 2)); + oslGenericFunction fn = (new osl::Module(lib, SAL_LOADMODULE_GLOBAL)) + ->getFunctionSymbol(sym); + CppUnit::Protector * p = fn == 0 + ? 0 + : (*reinterpret_cast< cppunittester::ProtectorFactory * >(fn))(); + if (p == 0) { + std::cerr + << "Failure instantiating protector \"" << convertLazy(lib) + << "\", \"" << convertLazy(sym) << '"' << std::endl; + std::exit(EXIT_FAILURE); + } + result.pushProtector(p); + } + if (rtl_getAppCommandArgCount() - index < 1) { + usageFailure(); } + std::string testlib; { rtl::OUString path; - rtl_getAppCommandArg(0, &path.pData); + rtl_getAppCommandArg(index, &path.pData); testlib = rtl::OUStringToOString(path, osl_getThreadTextEncoding()).getStr(); } std::string args = testlib; - for (sal_uInt32 i = 1; i < nCommandArgs; ++i) + for (sal_uInt32 i = index + 1; i < rtl_getAppCommandArgCount(); ++i) { rtl::OUString arg; rtl_getAppCommandArg(i, &arg.pData); args += ' '; args += rtl::OUStringToOString(arg, osl_getThreadTextEncoding()).getStr(); } + CppUnit::PlugInManager manager; manager.load(testlib, args); CppUnit::TestRunner runner; runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest()); - CppUnit::TestResult result; CppUnit::TestResultCollector collector; result.addListener(&collector); runner.run(result); |