1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
16 #include <LibreOfficeKit/LibreOfficeKitInit.h>
17 #include <LibreOfficeKit/LibreOfficeKit.hxx>
21 //#include <Windows.h> // come from LibreOfficeKitInit.h
24 return GetTickCount();
27 bool IsAbsolutePath(char const *pPath
)
31 fprintf( stderr
, "Absolute path required to libreoffice install\n" );
40 #include <sal/types.h>
44 gettimeofday(&t
, nullptr);
45 return t
.tv_sec
*1000 + t
.tv_usec
/1000;
48 bool IsAbsolutePath(char const *pPath
)
52 fprintf( stderr
, "Absolute path required to libreoffice install\n" );
61 using namespace ::lok
;
66 fprintf( stderr
, "Usage: libtest <absolute-path-to-libreoffice-install> [path to load document] [path to save document].\n" );
70 int main (int argc
, char **argv
)
77 ( argc
> 1 && ( !strcmp( argv
[1], "--help" ) || !strcmp( argv
[1], "-h" ) ) ) )
81 if( !IsAbsolutePath(argv
[1]) )
84 // coverity[tainted_string] - build time test tool
85 char *install_path
= argv
[1];
89 fprintf( stderr
, "testing preinit\n");
92 dlhandle
= lok_dlopen( install_path
, &imp_lib
);
95 fprintf( stderr
, "Failed to link '%s'\n", lok_dlerror() );
98 LokHookPreInit
*preinit
= reinterpret_cast<LokHookPreInit
*>(lok_dlsym( dlhandle
, "lok_preinit" ));
101 fprintf( stderr
, "Failed to find pre-init symbol: %s\n", lok_dlerror() );
104 preinit(install_path
, nullptr);
107 Office
*pOffice
= lok_cpp_init( install_path
);
110 fprintf( stderr
, "Failed to initialize\n" );
115 fprintf( stderr
, "init time: %ld ms\n", (end
-start
) );
118 fprintf( stderr
, "start to load document '%s'\n", argv
[2] );
119 Document
*pDocument
= pOffice
->documentLoad( argv
[2] );
122 char *pError
= pOffice
->getError();
123 fprintf( stderr
, "failed to load document '%s': '%s'\n",
130 fprintf( stderr
, "load time: %ld ms\n", (end
-start
) );
135 const char *pFilter
= nullptr;
138 fprintf( stderr
, "save document as '%s' (%s)\n", argv
[3], pFilter
? pFilter
: "<null>" );
139 if( !pDocument
->saveAs( argv
[3], pFilter
) )
141 char *pError
= pOffice
->getError();
142 fprintf( stderr
, "failed to save document '%s'\n", pError
);
147 fprintf( stderr
, "Save succeeded\n" );
149 fprintf( stderr
, "save time: %ld ms\n", (end
-start
) );
152 fprintf( stderr
, "all tests passed.\n" );
160 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */