desktop/Library_libreoffice.mk | 10 +++--- desktop/source/lib/init.cxx | 66 +++++++++++++++++++++++++++------------- smoketest/Executable_libtest.mk | 1 smoketest/libtest.cxx | 54 ++++++++++++++++++++++++++++++-- 4 files changed, 103 insertions(+), 28 deletions(-)
New commits: commit b9bbd847876cd7b23861c862af510da8244aef18 Author: Michael Meeks <[email protected]> Date: Thu Nov 7 11:46:08 2013 +0000 liblibo: improve the libtest sample app. Add command-line help, validate arguments more, better error reporting. Change-Id: Ia092895d0d116b003bb6c2a252f68ae9b6ba6d35 diff --git a/smoketest/libtest.cxx b/smoketest/libtest.cxx index ffacd18..39a0098 100644 --- a/smoketest/libtest.cxx +++ b/smoketest/libtest.cxx @@ -8,6 +8,7 @@ */ #include <stdio.h> +#include <string.h> #include <malloc.h> #include <assert.h> #include <math.h> @@ -16,17 +17,35 @@ long getTimeMS(); +static int help() +{ + fprintf( stderr, "Usage: libtest <absolute-path-to-libreoffice-install> [path to load document] [path to save document].\n" ); + return 1; +} + int main (int argc, char **argv) { long start, end; start = getTimeMS(); - if( argc < 2 ) - return -1; + if( argc < 2 || + ( argc > 1 && ( !strcmp( argv[1], "--help" ) || !strcmp( argv[1], "-h" ) ) ) ) + return help(); + + if (argv[1][0] != '/') + { + fprintf( stderr, "Absolute path required to libreoffice install\n" ); + return 1; + } + LibLibreOffice *pOffice = lo_init( argv[1] ); if( !pOffice ) + { + fprintf( stderr, "Failed to initialize\n" ); return -1; + } + // This separate init is lame I think. if( !pOffice->initialize( argv[1] ) ) { @@ -80,7 +99,8 @@ int main (int argc, char **argv) return 0; } -long getTimeMS() { +long getTimeMS() +{ struct timespec t; clock_gettime(CLOCK_MONOTONIC, &t); long ms = round(t.tv_nsec / 1.0e6) + t.tv_sec * 1000; commit 3c608eb38150f3b11919adf6eca6eff0fdfdb0cd Author: Michael Meeks <[email protected]> Date: Thu Nov 7 11:37:19 2013 +0000 liblibo: share crude URL absolutization, and clean. Change-Id: I559eac8626a011644f68f8391631447f15c643eb diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx index 6c6b9f5..d26d5b8 100644 --- a/desktop/source/lib/init.cxx +++ b/desktop/source/lib/init.cxx @@ -135,24 +135,33 @@ static OUString getUString( const char *str ) RTL_TEXTENCODING_UTF8 ); } +// Try to convert a relative URL to an absolute one +static OUString getAbsoluteURL( const char *pURL ) +{ + OUString aURL( getUString( pURL ) ); + OUString sAbsoluteDocUrl, sWorkingDir, sDocPathUrl; + + // FIXME: this would appear to kill non-file URLs. + osl_getProcessWorkingDir(&sWorkingDir.pData); + osl::FileBase::getFileURLFromSystemPath( aURL, sDocPathUrl ); + osl::FileBase::getAbsoluteFileURL(sWorkingDir, sDocPathUrl, sAbsoluteDocUrl); + + return sAbsoluteDocUrl; +} + LODocument * LibLibreOffice_Impl::documentLoad( const char *docUrl ) { - OUString sUrl = getUString( docUrl ); - OUString sAbsoluteDocUrl, sWorkingDir, sDocPathUrl; + OUString aURL = getAbsoluteURL( docUrl ); uno::Reference < css::frame::XDesktop2 > xComponentLoader = css::frame::Desktop::create(xContext); - osl_getProcessWorkingDir(&sWorkingDir.pData); - osl::FileBase::getFileURLFromSystemPath( sUrl, sDocPathUrl ); - osl::FileBase::getAbsoluteFileURL(sWorkingDir, sDocPathUrl, sAbsoluteDocUrl); - maLastExceptionMsg = ""; try { uno::Reference < css::lang::XComponent > xComponent = xComponentLoader->loadComponentFromURL( - sAbsoluteDocUrl, OUString("_blank"), 0, + aURL, OUString("_blank"), 0, uno::Sequence < css::beans::PropertyValue >()); if( xComponentLoader.is() ) return new LibLODocument_Impl( xComponent ); @@ -168,12 +177,7 @@ bool LibLODocument_Impl::saveAs (const char *url, const char *format) { OUString sFormat = getUString( format ); - OUString sUrl = getUString( url ); - OUString sAbsoluteDocUrl, sWorkingDir, sDocPathUrl; - - osl_getProcessWorkingDir(&sWorkingDir.pData); - osl::FileBase::getFileURLFromSystemPath( sUrl, sDocPathUrl ); - osl::FileBase::getAbsoluteFileURL(sWorkingDir, sDocPathUrl, sAbsoluteDocUrl); + OUString aURL = getAbsoluteURL( url ); try { uno::Reference< frame::XModel > xDocument( mxComponent, uno::UNO_QUERY_THROW ); @@ -205,10 +209,10 @@ bool LibLODocument_Impl::saveAs (const char *url, const char *format) if( ! format ) { // sniff from the extension - sal_Int32 idx = sUrl.lastIndexOf( "." ); + sal_Int32 idx = aURL.lastIndexOf( "." ); if( idx > 0 ) { - sFormat = sUrl.copy( idx + 1 ); + sFormat = aURL.copy( idx + 1 ); } else { @@ -239,7 +243,7 @@ bool LibLODocument_Impl::saveAs (const char *url, const char *format) aSeq[1].Value <<= aFilterName; uno::Reference< frame::XStorable > xStorable( mxComponent, uno::UNO_QUERY_THROW ); - xStorable->storeToURL( sAbsoluteDocUrl, aSeq ); + xStorable->storeToURL( aURL, aSeq ); return true; } catch (const uno::Exception &ex) { commit d324745fe95c7f0fad56f146e1e33f994a0d5de6 Author: Michael Meeks <[email protected]> Date: Thu Nov 7 11:36:44 2013 +0000 liblibo: make liblibreoffice static as it should be. The whole purpose of this tiny library is to break dependencies, so requiring it in our library path is a bit silly. Change-Id: Ie0e000b97db87afd57f693e19341eadf97323335 diff --git a/desktop/Library_libreoffice.mk b/desktop/Library_libreoffice.mk index dbe3e81..b35c75d 100644 --- a/desktop/Library_libreoffice.mk +++ b/desktop/Library_libreoffice.mk @@ -7,25 +7,25 @@ # file, You can obtain one at http://mozilla.org/MPL/2.0/. # -$(eval $(call gb_Library_Library,libreoffice)) +$(eval $(call gb_StaticLibrary_StaticLibrary,libreoffice)) -$(eval $(call gb_Library_set_include,libreoffice,\ +$(eval $(call gb_StaticLibrary_set_include,libreoffice,\ $$(INCLUDE) \ -I$(SRCDIR)/desktop/inc \ )) -$(eval $(call gb_Library_add_libs,libreoffice,\ +$(eval $(call gb_StaticLibrary_add_libs,libreoffice,\ $(if $(filter $(OS),LINUX), \ -ldl \ -lpthread \ ) \ )) -$(eval $(call gb_Library_use_libraries,libreoffice,\ +$(eval $(call gb_StaticLibrary_use_libraries,libreoffice,\ $(gb_UWINAPI) \ )) -$(eval $(call gb_Library_add_exception_objects,libreoffice,\ +$(eval $(call gb_StaticLibrary_add_exception_objects,libreoffice,\ desktop/source/lib/shim \ )) diff --git a/smoketest/Executable_libtest.mk b/smoketest/Executable_libtest.mk index 14bf342..3d8ec63 100644 --- a/smoketest/Executable_libtest.mk +++ b/smoketest/Executable_libtest.mk @@ -20,6 +20,7 @@ $(eval $(call gb_Executable_use_libraries,libtest,\ )) $(eval $(call gb_Executable_add_libs,libtest,\ + -ldl \ -pthread \ )) commit 49112ec909ef465ecb1aa2786a283b57034e6af4 Author: Christoph Lutz <[email protected]> Date: Tue Nov 5 23:34:37 2013 +0100 liblibo: fixes and improvements for liblibreoffice fixes for liblibreoffice-Impl (init.cxx): determine outputfilter from file suffix if no filter is provided; ensure that url provided to XStorable.storeToUrl is really an url; improved error handling small improvements in somektest/libtest.cxx: output times required for init, load and save. Change-Id: Ic8b2c0d34cbeae3250c43cac02690e6ec1954ed7 diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx index 5d7e8c0..6c6b9f5 100644 --- a/desktop/source/lib/init.cxx +++ b/desktop/source/lib/init.cxx @@ -166,19 +166,23 @@ LibLibreOffice_Impl::documentLoad( const char *docUrl ) bool LibLODocument_Impl::saveAs (const char *url, const char *format) { - OUString sURL = getUString( url ); OUString sFormat = getUString( format ); + OUString sUrl = getUString( url ); + OUString sAbsoluteDocUrl, sWorkingDir, sDocPathUrl; + + osl_getProcessWorkingDir(&sWorkingDir.pData); + osl::FileBase::getFileURLFromSystemPath( sUrl, sDocPathUrl ); + osl::FileBase::getAbsoluteFileURL(sWorkingDir, sDocPathUrl, sAbsoluteDocUrl); + try { uno::Reference< frame::XModel > xDocument( mxComponent, uno::UNO_QUERY_THROW ); uno::Sequence< beans::PropertyValue > aSeq = xDocument->getArgs(); - OUString aFilterName, aDocumentService; + OUString aDocumentService; for( sal_Int32 i = 0; i < aSeq.getLength(); ++i ) { - if( aSeq[i].Name == "FilterName" ) - aSeq[i].Value >>= aFilterName; - else if( aSeq[i].Name == "DocumentService" ) + if( aSeq[i].Name == "DocumentService" ) aSeq[i].Value >>= aDocumentService; OUString aValue; aSeq[i].Value >>= aValue; @@ -198,17 +202,35 @@ bool LibLODocument_Impl::saveAs (const char *url, const char *format) else // for the sake of argument only writer documents ... pMap = (const ExtensionMap *)aWriterExtensionMap; - if( format ) + if( ! format ) + { + // sniff from the extension + sal_Int32 idx = sUrl.lastIndexOf( "." ); + if( idx > 0 ) + { + sFormat = sUrl.copy( idx + 1 ); + } + else + { + gImpl->maLastExceptionMsg = "input filename without a suffix"; + return false; + } + } + + OUString aFilterName; + for( sal_Int32 i = 0; pMap[i].extn; i++ ) { - for( sal_Int32 i = 0; pMap[i].extn; i++ ) + if( sFormat.equalsIgnoreAsciiCaseAscii( pMap[i].extn ) ) { - if( sFormat.equalsIgnoreAsciiCaseAscii( pMap[i].extn ) ) - { - aFilterName = getUString( pMap[i].filterName ); - break; - } + aFilterName = getUString( pMap[i].filterName ); + break; } } + if( ! aFilterName.getLength() ) + { + gImpl->maLastExceptionMsg = "no output filter found for provided suffix"; + return false; + } aSeq.realloc(2); aSeq[0].Name = "Overwrite"; @@ -217,7 +239,7 @@ bool LibLODocument_Impl::saveAs (const char *url, const char *format) aSeq[1].Value <<= aFilterName; uno::Reference< frame::XStorable > xStorable( mxComponent, uno::UNO_QUERY_THROW ); - xStorable->storeToURL( sURL, aSeq ); + xStorable->storeToURL( sAbsoluteDocUrl, aSeq ); return true; } catch (const uno::Exception &ex) { diff --git a/smoketest/libtest.cxx b/smoketest/libtest.cxx index 4b9d1b3..ffacd18 100644 --- a/smoketest/libtest.cxx +++ b/smoketest/libtest.cxx @@ -10,10 +10,18 @@ #include <stdio.h> #include <malloc.h> #include <assert.h> +#include <math.h> +#include <time.h> #include <liblibreoffice.hxx> +long getTimeMS(); + int main (int argc, char **argv) { + long start, end; + + start = getTimeMS(); + if( argc < 2 ) return -1; LibLibreOffice *pOffice = lo_init( argv[1] ); @@ -25,6 +33,11 @@ int main (int argc, char **argv) fprintf( stderr, "failed to initialize\n" ); return -1; } + + end = getTimeMS(); + fprintf( stderr, "init time: %ld ms\n", (end-start) ); + start = end; + fprintf( stderr, "start to load document '%s'\n", argv[2] ); LODocument *pDocument = pOffice->documentLoad( argv[2] ); if( !pDocument ) @@ -36,6 +49,10 @@ int main (int argc, char **argv) return -1; } + end = getTimeMS(); + fprintf( stderr, "load time: %ld ms\n", (end-start) ); + start = end; + if( argc > 3 ) { const char *pFilter = NULL; @@ -49,9 +66,13 @@ int main (int argc, char **argv) free (pError); } else + { fprintf( stderr, "Save succeeded\n" ); + end = getTimeMS(); + fprintf( stderr, "save time: %ld ms\n", (end-start) ); + } } - fprintf( stderr, "all tests passed." ); + fprintf( stderr, "all tests passed.\n" ); delete pDocument; delete pOffice; @@ -59,4 +80,11 @@ int main (int argc, char **argv) return 0; } +long getTimeMS() { + struct timespec t; + clock_gettime(CLOCK_MONOTONIC, &t); + long ms = round(t.tv_nsec / 1.0e6) + t.tv_sec * 1000; + return ms; +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ _______________________________________________ Libreoffice-commits mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
