summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Meeks <michael.meeks@suse.com>2013-03-05 13:16:36 +0000
committerMichael Meeks <michael.meeks@suse.com>2013-03-12 15:35:33 +0000
commit8887de72c184bec6225a952ec90433ae1b7a5b26 (patch)
treef3d90d221b5eba49aa14ff713c7d11216935b233
parent6ea685090806a2a2f39b8d5ec6a749eaf9b1856e (diff)
liblibo: create initial liblibreoffice.
bootstrap libreoffice, start a dummy test-harness: can't use CppUnit or link to any URE / LibreOffice libraries. Change-Id: I855b640557f93959749e966a2d8e5e577fd84574
-rw-r--r--Repository.mk1
-rw-r--r--desktop/Library_libreoffice.mk25
-rw-r--r--desktop/Library_sofficeapp.mk5
-rw-r--r--desktop/Module_desktop.mk1
-rw-r--r--desktop/inc/liblibreoffice.h38
-rw-r--r--desktop/source/lib/init.cxx139
-rw-r--r--desktop/source/lib/shim.cxx52
-rw-r--r--smoketest/CppunitTest_liblibreoffice.mk45
-rw-r--r--smoketest/Module_smoketest.mk4
-rw-r--r--smoketest/libtest.cxx54
10 files changed, 364 insertions, 0 deletions
diff --git a/Repository.mk b/Repository.mk
index a7b17060dfa7..e3ea69b0d7fc 100644
--- a/Repository.mk
+++ b/Repository.mk
@@ -472,6 +472,7 @@ $(eval $(call gb_Helper_register_libraries,PLAINLIBS_OOO, \
hsqldb \
index_data \
java_uno_accessbridge \
+ libreoffice \
localedata_en \
localedata_es \
localedata_euro \
diff --git a/desktop/Library_libreoffice.mk b/desktop/Library_libreoffice.mk
new file mode 100644
index 000000000000..a40bbd74f987
--- /dev/null
+++ b/desktop/Library_libreoffice.mk
@@ -0,0 +1,25 @@
+# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*-
+#
+# This file is part of the LibreOffice project.
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+
+$(eval $(call gb_Library_Library,libreoffice))
+
+$(eval $(call gb_Library_set_include,libreoffice,\
+ $$(INCLUDE) \
+ -I$(SRCDIR)/desktop/inc \
+))
+
+$(eval $(call gb_Library_use_libraries,libreoffice,\
+ $(gb_UWINAPI) \
+))
+
+$(eval $(call gb_Library_add_exception_objects,libreoffice,\
+ desktop/source/lib/shim \
+))
+
+# vim: set noet sw=4 ts=4:
diff --git a/desktop/Library_sofficeapp.mk b/desktop/Library_sofficeapp.mk
index 2a635b5953c9..5ae66d259d30 100644
--- a/desktop/Library_sofficeapp.mk
+++ b/desktop/Library_sofficeapp.mk
@@ -90,6 +90,11 @@ $(eval $(call gb_Library_add_exception_objects,sofficeapp,\
desktop/source/migration/migration \
))
+# liblibreoffice bits
+$(eval $(call gb_Library_add_exception_objects,sofficeapp,\
+ desktop/source/lib/init \
+))
+
ifeq ($(ENABLE_TELEPATHY),TRUE)
$(eval $(call gb_Library_use_libraries,sofficeapp,tubes))
endif
diff --git a/desktop/Module_desktop.mk b/desktop/Module_desktop.mk
index 538553ac7dd1..d97bff3f1b1c 100644
--- a/desktop/Module_desktop.mk
+++ b/desktop/Module_desktop.mk
@@ -33,6 +33,7 @@ $(eval $(call gb_Module_add_targets,desktop,\
AllLangResTarget_dkt \
Library_deployment \
Library_deploymentmisc \
+ Library_libreoffice \
Library_offacc \
Library_sofficeapp \
Library_spl \
diff --git a/desktop/inc/liblibreoffice.h b/desktop/inc/liblibreoffice.h
new file mode 100644
index 000000000000..dde50cec88e1
--- /dev/null
+++ b/desktop/inc/liblibreoffice.h
@@ -0,0 +1,38 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+/*
+ * A simple C API to setup and use libreoffice
+ */
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef struct {
+ int errno;
+ char *message;
+} LOError;
+
+typedef int loboolean;
+typedef struct _LODocument LODocument;
+
+loboolean lo_initialize (const char *install_path);
+
+void lo_error_free (LOError *error);
+LOError *lo_error_new (int errno, const char *message);
+
+LODocument *lo_document_load (const char *url, LOError **opt_error);
+loboolean lo_document_save (const char *url, LOError **opt_error);
+
+#ifdef __cplusplus
+} /* extern "C" */
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
+
diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx
new file mode 100644
index 000000000000..5aab66bd42d2
--- /dev/null
+++ b/desktop/source/lib/init.cxx
@@ -0,0 +1,139 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include <stdio.h>
+
+#include <liblibreoffice.h>
+#include <tools/errinf.hxx>
+#include <osl/file.hxx>
+#include <rtl/strbuf.hxx>
+#include <rtl/bootstrap.hxx>
+#include <cppuhelper/bootstrap.hxx>
+#include <comphelper/processfactory.hxx>
+
+#include <com/sun/star/lang/Locale.hpp>
+#include <com/sun/star/lang/XComponent.hpp>
+#include <com/sun/star/lang/XMultiServiceFactory.hpp>
+#include <com/sun/star/ucb/XContentProvider.hpp>
+#include <com/sun/star/ucb/XUniversalContentBroker.hpp>
+
+#include <vcl/svapp.hxx>
+#include <tools/resmgr.hxx>
+#include <vcl/graphicfilter.hxx>
+#include <unotools/syslocaleoptions.hxx>
+
+using namespace ::com::sun::star;
+
+// Wonder global state ...
+static uno::Reference<css::uno::XComponentContext> xContext;
+static uno::Reference<css::lang::XMultiServiceFactory> xSFactory;
+static uno::Reference<css::lang::XMultiComponentFactory> xFactory;
+
+SAL_DLLPUBLIC_EXPORT void
+lo_error_free( LOError * )
+{
+}
+
+SAL_DLLPUBLIC_EXPORT LOError *
+lo_error_new( int, const char * )
+{
+ return NULL;
+}
+
+SAL_DLLPUBLIC_EXPORT LODocument *
+lo_document_load( const char *, LOError ** )
+{
+ return NULL;
+}
+
+SAL_DLLPUBLIC_EXPORT loboolean
+lo_document_save( const char *, LOError ** )
+{
+ return 1;
+}
+
+static void
+force_c_locale( void )
+{
+ // force locale (and resource files loaded) to en-US
+ css::lang::Locale aLocale( "en", "US", "");
+ ResMgr::SetDefaultLocale( aLocale );
+ SvtSysLocaleOptions aLocalOptions;
+ OUString aLangISO( "en-US" );
+ aLocalOptions.SetLocaleConfigString( aLangISO );
+ aLocalOptions.SetUILocaleConfigString( aLangISO );
+}
+
+static void
+aBasicErrorFunc( const OUString &rErr, const OUString &rAction )
+{
+ OStringBuffer aErr( "Unexpected dialog: " );
+ aErr.append( OUStringToOString( rAction, RTL_TEXTENCODING_ASCII_US ) );
+ aErr.append( " Error: " );
+ aErr.append( OUStringToOString( rErr, RTL_TEXTENCODING_ASCII_US ) );
+ fprintf( stderr, "Unexpected basic error dialog '%s'\n", aErr.getStr() );
+}
+
+static void
+initialize_uno( const rtl::OUString &aUserProfileURL )
+{
+ // set UserInstallation to user profile dir in test/user-template
+ rtl::Bootstrap aDefaultVars;
+ aDefaultVars.set(rtl::OUString("UserInstallation"), aUserProfileURL );
+
+ xContext = comphelper::getProcessComponentContext();
+ xFactory = xContext->getServiceManager();
+ xSFactory = uno::Reference<lang::XMultiServiceFactory>(xFactory, uno::UNO_QUERY_THROW);
+}
+
+SAL_DLLPUBLIC_EXPORT loboolean
+lo_initialize( const char *app_path )
+{
+ static bool bInitialized = false;
+ if( bInitialized )
+ return true;
+
+ if( !app_path )
+ return false;
+
+ OUString aAppPath( app_path, strlen( app_path ), RTL_TEXTENCODING_UTF8 );
+ OUString aAppURL;
+ if( osl::FileBase::getFileURLFromSystemPath( aAppPath, aAppURL ) !=
+ osl::FileBase::E_None )
+ return false;
+
+ try {
+ initialize_uno( aAppURL + "../registry" );
+ force_c_locale();
+ InitVCL();
+ if (Application::IsHeadlessModeRequested())
+ Application::EnableHeadlessMode(true);
+
+ ErrorHandler::RegisterDisplay( aBasicErrorFunc );
+
+ fprintf (stderr, "do nothing yet");
+ bInitialized = true;
+ } catch (css::uno::Exception & e) {
+ fprintf( stderr, "bootstrapping exception '%s'\n",
+ OUStringToOString( e.Message, RTL_TEXTENCODING_UTF8 ).getStr() );
+ }
+ return bInitialized;
+}
+
+extern "C" {
+ SAL_DLLPUBLIC_EXPORT LibLibreOffice *liblibreoffice_hook(void);
+}
+
+LibLibreOffice *liblibreoffice_hook(void)
+{
+ return new LibLibreOffice();
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
+
diff --git a/desktop/source/lib/shim.cxx b/desktop/source/lib/shim.cxx
new file mode 100644
index 000000000000..c57803e588fa
--- /dev/null
+++ b/desktop/source/lib/shim.cxx
@@ -0,0 +1,52 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#ifdef LINUX
+
+#include <sal/types.h>
+#include <liblibreoffice.h>
+
+#include <dlfcn.h>
+#ifdef AIX
+# include <sys/ldr.h>
+#endif
+
+#define TARGET_LIB SAL_MODULENAME( "sofficeapp" )
+
+extern "C" {
+ typedef LibLibreOffice *(HookFunction)(void);
+};
+
+extern LibLibreOffice *lo_init( const char *install_path )
+{
+ if( !install_path )
+ return NULL;
+ char *impl_lib = malloc( strlen (install_path) + sizeof( TARGET_LIB ) + 2 );
+ strcpy( imp_lib, install_path );
+ strcat( imp_lib, "/" );
+ strcat( imp_lib, TARGET_LIB );
+ void *dlhandle = dlopen( imp_lib, RTLD_LAZY );
+ if( !dlhandle )
+ {
+ fprintf( stderr, "failed to open library '%s'\n", imp_lib );
+ return NULL;
+ }
+ free( imp_lib );
+
+ HookFunction *pSym = dlsym( dlhandle, "liblibreoffice_hook" );
+ if( !pSym ) {
+ fprintf( stderr, "failed to find hook in library '%s'\n", imp_lib );
+ return NULL;
+ }
+ return pSym();
+}
+
+#endif // LINUX - port me !
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/smoketest/CppunitTest_liblibreoffice.mk b/smoketest/CppunitTest_liblibreoffice.mk
new file mode 100644
index 000000000000..2cd345633d33
--- /dev/null
+++ b/smoketest/CppunitTest_liblibreoffice.mk
@@ -0,0 +1,45 @@
+# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*-
+#
+# This file is part of the LibreOffice project.
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+
+$(eval $(call gb_CppunitTest_CppunitTest,liblibreoffice))
+
+$(eval $(call gb_CppunitTest_abort_on_assertion,liblibreoffice))
+
+$(eval $(call gb_CppunitTest_add_exception_objects,liblibreoffice,\
+ smoketest/libtest \
+))
+
+$(eval $(call gb_CppunitTest_use_external,liblibreoffice,boost_headers))
+
+$(eval $(call gb_CppunitTest_use_api,liblibreoffice,\
+ offapi \
+ udkapi \
+))
+
+$(eval $(call gb_CppunitTest_use_libraries,liblibreoffice,\
+ cppu \
+ cppuhelper \
+ libreoffice \
+ sal \
+ unotest \
+))
+
+ifeq ($(OS),MACOSX)
+liblibreoffice_SOFFICE_INST := path:$(DEVINSTALLDIR)/opt/LibreOffice.app/Contents/MacOS
+else
+liblibreoffice_SOFFICE_INST := path:$(DEVINSTALLDIR)/opt/program
+endif
+
+$(eval $(call gb_CppunitTest_use_ure,liblibreoffice))
+
+$(eval $(call gb_CppunitTest_add_arguments,liblibreoffice,\
+ -env:arg-soffice=$(liblibreoffice_SOFFICE_INST) \
+))
+
+# vim: set noet sw=4 ts=4:
diff --git a/smoketest/Module_smoketest.mk b/smoketest/Module_smoketest.mk
index 9de8a445ae9e..9a2aa72f9fc3 100644
--- a/smoketest/Module_smoketest.mk
+++ b/smoketest/Module_smoketest.mk
@@ -42,6 +42,10 @@ $(eval $(call gb_Module_add_targets,smoketest,\
))
endif
+$(eval $(call gb_Module_add_check_targets,smoketest,\
+ CppunitTest_liblibreoffice \
+))
+
$(eval $(call gb_Module_add_subsequentcheck_targets,smoketest,\
CppunitTest_smoketest \
))
diff --git a/smoketest/libtest.cxx b/smoketest/libtest.cxx
new file mode 100644
index 000000000000..39ab01bb2cf6
--- /dev/null
+++ b/smoketest/libtest.cxx
@@ -0,0 +1,54 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+// yuck / FIXME ...
+#include "../desktop/inc/liblibreoffice.h"
+
+#include <sal/types.h>
+#include <rtl/ustring.hxx>
+#include <rtl/bootstrap.hxx>
+#include "cppunit/TestAssert.h"
+#include "cppunit/TestFixture.h"
+#include "cppunit/extensions/HelperMacros.h"
+#include "cppunit/plugin/TestPlugIn.h"
+
+class Test: public CppUnit::TestFixture {
+public:
+ virtual void setUp();
+ virtual void tearDown();
+
+private:
+ CPPUNIT_TEST_SUITE(Test);
+ CPPUNIT_TEST(test);
+ CPPUNIT_TEST_SUITE_END();
+
+ void test();
+};
+
+void Test::setUp()
+{
+}
+void Test::tearDown()
+{
+}
+
+void Test::test()
+{
+ rtl::OUString aArgSoffice;
+ rtl::Bootstrap::get( rtl::OUString( "arg-soffice" ), aArgSoffice );
+ OString aInstall = OUStringToOString( aArgSoffice, RTL_TEXTENCODING_UTF8 );
+ fprintf( stderr, "liblibreoffice test: '%s'\n", aInstall.getStr() );
+ lo_initialize( aInstall.getStr() );
+}
+
+CPPUNIT_TEST_SUITE_REGISTRATION(Test);
+
+CPPUNIT_PLUGIN_IMPLEMENT();
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */