From 46bd39b0d33dc142f01dfba50ed71d55197818b2 Mon Sep 17 00:00:00 2001 From: Tor Lillqvist Date: Mon, 1 Aug 2011 00:59:09 +0300 Subject: Add statically linked cppu unit test for iOS --- cppu/qa/cppu_cppunittester_all.cxx | 146 +++++++++++++++++++++++++++++++++++++ cppu/qa/makefile.mk | 16 ++-- cppu/qa/test_any.cxx | 4 + cppu/qa/test_recursion.cxx | 5 ++ cppu/qa/test_reference.cxx | 4 + cppu/qa/test_unotype.cxx | 4 + 6 files changed, 174 insertions(+), 5 deletions(-) create mode 100644 cppu/qa/cppu_cppunittester_all.cxx (limited to 'cppu/qa') diff --git a/cppu/qa/cppu_cppunittester_all.cxx b/cppu/qa/cppu_cppunittester_all.cxx new file mode 100644 index 000000000000..e77c046bf8da --- /dev/null +++ b/cppu/qa/cppu_cppunittester_all.cxx @@ -0,0 +1,146 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* +* +* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +* +* Copyright 2000, 2010 Oracle and/or its affiliates. +* +* OpenOffice.org - a multi-platform office productivity suite +* +* This file is part of OpenOffice.org. +* +* OpenOffice.org is free software: you can redistribute it and/or modify +* it under the terms of the GNU Lesser General Public License version 3 +* only, as published by the Free Software Foundation. +* +* OpenOffice.org 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 version 3 for more details +* (a copy is included in the LICENSE file that accompanied this code). +* +* You should have received a copy of the GNU Lesser General Public License +* version 3 along with OpenOffice.org. If not, see +* +* for a copy of the LGPLv3 License. +* +************************************************************************/ + +#include "precompiled_cppu.hxx" + +#include "sal/config.h" + +#include +#include +#include +#include +#include "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" +#include "cppunit/TestRunner.h" +#include "cppunit/plugin/TestPlugIn.h" +#include "cppunit/plugin/PlugInParameters.h" +#include "cppunit/extensions/TestFactoryRegistry.h" +#include "cppunit/portability/Stream.h" + +#include "boost/noncopyable.hpp" + +namespace { + +void usageFailure() { + std::cerr + << ("Usage: cppunittester (--protector " + " )* ") + << 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()))); +} + +//Allow the whole uniting testing framework to be run inside a "Protector" +//which knows about uno exceptions, so it can print the content of the +//exception before falling over and dying +class CPPUNIT_API ProtectedFixtureFunctor : public CppUnit::Functor, private boost::noncopyable +{ +private: + const std::string &args; + CppUnit::TestResult &result; +public: + ProtectedFixtureFunctor(const std::string &args_, CppUnit::TestResult &result_) + : args(args_) + , result(result_) + { + } + bool run() const + { + CppUnit::TestRunner runner; + runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest()); + CppUnit::TestResultCollector collector; + result.addListener(&collector); + runner.run(result); + CppUnit::CompilerOutputter(&collector, CppUnit::stdCErr()).write(); + return collector.wasSuccessful(); + } + virtual bool operator()() const + { + return run(); + } +}; +} + +extern "C" CppUnitTestPlugIn + *cppunitTest_qa_cppu_any(void), + *cppunitTest_qa_cppu_unotype(void), + *cppunitTest_qa_cppu_reference(void), + *cppunitTest_qa_cppu_recursion(void); + + +SAL_IMPLEMENT_MAIN() { + TestPlugInSignature plugs[] = { + cppunitTest_qa_cppu_any, + cppunitTest_qa_cppu_unotype, + cppunitTest_qa_cppu_reference, + cppunitTest_qa_cppu_recursion, + NULL + }; + CppUnit::TestResult result; + std::string args; + bool ok = false; + for (TestPlugInSignature *plug = plugs; *plug != NULL; plug++) { + CppUnitTestPlugIn *iface; + iface = (*plug)(); + iface->initialize(&CppUnit::TestFactoryRegistry::getRegistry(), CppUnit::PlugInParameters()); + } + ProtectedFixtureFunctor tests(args, result); + ok = tests.run(); + + return ok ? EXIT_SUCCESS : EXIT_FAILURE; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/cppu/qa/makefile.mk b/cppu/qa/makefile.mk index 6d9d87935753..86cd144a408d 100644 --- a/cppu/qa/makefile.mk +++ b/cppu/qa/makefile.mk @@ -33,13 +33,12 @@ ENABLE_EXCEPTIONS := TRUE .INCLUDE: settings.mk -.IF "$(CROSS_COMPILING)"=="YES" -all: - @echo Nothing done when cross-compiling -.ENDIF - CFLAGSCXX+=$(CPPUNIT_CFLAGS) +.IF "$(OS)" == "IOS" +CFLAGSCXX += -x objective-c++ -fobjc-abi-version=2 -fobjc-legacy-dispatch -D__IPHONE_OS_VERSION_MIN_REQUIRED=40300 +.ENDIF + DLLPRE=# no leading "lib" on .so files INCPRE+=$(MISC)$/$(TARGET)$/inc @@ -74,6 +73,13 @@ DEF4NAME = $(SHL4TARGET) SLOFILES = $(SHL1OBJS) $(SHL2OBJS) $(SHL3OBJS) $(SHL4OBJS) +.IF "$(OS)" == "IOS" +APP5OBJS = $(OBJ)/cppu_cppunittester_all.obj $(SHL1OBJS) $(SHL2OBJS) $(SHL3OBJS) $(SHL4OBJS) +APP5RPATH = NONE +APP5STDLIBS = $(CPPUNITLIB) $(CPPULIB) $(SALLIB) +APP5TARGET = cppu_cppunittester_all +.ENDIF + .INCLUDE: target.mk $(SHL1OBJS): $(MISC)$/$(TARGET).cppumaker.flag diff --git a/cppu/qa/test_any.cxx b/cppu/qa/test_any.cxx index 71afe9b31a5a..4c7f58d9bd43 100644 --- a/cppu/qa/test_any.cxx +++ b/cppu/qa/test_any.cxx @@ -29,6 +29,10 @@ // MARKER(update_precomp.py): autogen include statement, do not remove #include "precompiled_cppu.hxx" +#ifdef IOS +#define CPPUNIT_PLUGIN_EXPORTED_NAME cppunitTest_qa_cppu_any +#endif + #include "sal/config.h" #include // wntmsci10 does not like diff --git a/cppu/qa/test_recursion.cxx b/cppu/qa/test_recursion.cxx index 81ee1f0664fa..da7d389099bc 100644 --- a/cppu/qa/test_recursion.cxx +++ b/cppu/qa/test_recursion.cxx @@ -27,6 +27,11 @@ ************************************************************************/ #include "precompiled_cppu.hxx" + +#ifdef IOS +#define CPPUNIT_PLUGIN_EXPORTED_NAME cppunitTest_qa_cppu_recursion +#endif + #include "sal/config.h" #include diff --git a/cppu/qa/test_reference.cxx b/cppu/qa/test_reference.cxx index fbf7011deb67..8bc21a02ebe3 100644 --- a/cppu/qa/test_reference.cxx +++ b/cppu/qa/test_reference.cxx @@ -29,6 +29,10 @@ // MARKER(update_precomp.py): autogen include statement, do not remove #include "precompiled_cppu.hxx" +#ifdef IOS +#define CPPUNIT_PLUGIN_EXPORTED_NAME cppunitTest_qa_cppu_reference +#endif + #include "sal/config.h" #include diff --git a/cppu/qa/test_unotype.cxx b/cppu/qa/test_unotype.cxx index f85944ff1021..4173bf8a3534 100644 --- a/cppu/qa/test_unotype.cxx +++ b/cppu/qa/test_unotype.cxx @@ -29,6 +29,10 @@ // MARKER(update_precomp.py): autogen include statement, do not remove #include "precompiled_cppu.hxx" +#ifdef IOS +#define CPPUNIT_PLUGIN_EXPORTED_NAME cppunitTest_qa_cppu_unotype +#endif + #include "sal/config.h" #include -- cgit