diff options
author | Christoph Lutz <christoph.lutz@cib.de> | 2013-11-05 23:34:37 +0100 |
---|---|---|
committer | Michael Meeks <michael.meeks@collabora.com> | 2013-11-07 11:50:00 +0000 |
commit | 49112ec909ef465ecb1aa2786a283b57034e6af4 (patch) | |
tree | 87940088328b4ad1e96d74f9996972a82e926c4c | |
parent | 67311738157bced7b49e94b24845091995edb142 (diff) |
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
-rw-r--r-- | desktop/source/lib/init.cxx | 48 | ||||
-rw-r--r-- | smoketest/libtest.cxx | 30 |
2 files changed, 64 insertions, 14 deletions
diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx index 5d7e8c0b38a0..6c6b9f51ad27 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 4b9d1b3c884d..ffacd188307e 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: */ |