Linux x86 build fix
[LibreOffice.git] / smoketest / libtest.cxx
blob60ee19e6235727058c6d883d2ea5ddbd07ad12e5
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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/.
8 */
10 #include <stdio.h>
11 #include <string.h>
12 #include <malloc.h>
13 #include <assert.h>
14 #include <math.h>
16 #include <LibreOfficeKit/LibreOfficeKitInit.h>
17 #include <LibreOfficeKit/LibreOfficeKit.hxx>
21 #ifdef _WIN32
22 //#include <Windows.h> // come from LibreOfficeKitInit.h
23 long getTimeMS()
25 return GetTickCount();
28 bool IsAbsolutePath(char *pPath)
30 if (pPath[1] != ':')
32 fprintf( stderr, "Absolute path required to libreoffice install\n" );
33 return false;
36 return true;
39 #else
40 #include <sys/time.h>
41 #include <sal/types.h>
42 long getTimeMS()
44 struct timeval t;
45 gettimeofday(&t, NULL);
46 return t.tv_sec*1000 + t.tv_usec/1000;
49 bool IsAbsolutePath(char *pPath)
51 if (pPath[0] != '/')
53 fprintf( stderr, "Absolute path required to libreoffice install\n" );
54 return false;
57 return true;
59 #endif
62 using namespace ::lok;
65 static int help()
67 fprintf( stderr, "Usage: libtest <absolute-path-to-libreoffice-install> [path to load document] [path to save document].\n" );
68 return 1;
71 int main (int argc, char **argv)
73 long start, end;
75 start = getTimeMS();
77 if( argc < 2 ||
78 ( argc > 1 && ( !strcmp( argv[1], "--help" ) || !strcmp( argv[1], "-h" ) ) ) )
79 return help();
82 if( !IsAbsolutePath(argv[1]) )
83 return 1;
85 // coverity[tainted_string] - build time test tool
86 char *install_path = argv[1];
88 if( argc > 4 )
90 fprintf( stderr, "testing preinit\n");
91 char *imp_lib;
92 void *dlhandle;
93 dlhandle = lok_dlopen( install_path, &imp_lib );
94 if( !dlhandle )
96 fprintf( stderr, "Failed to link '%s'\n", lok_dlerror() );
97 return -1;
99 LokHookPreInit *preinit = (LokHookPreInit *) lok_dlsym( dlhandle, "lok_preinit" );
100 if( !preinit )
102 fprintf( stderr, "Failed to find pre-init symbol: %s\n", lok_dlerror() );
103 return -1;
105 preinit( install_path, NULL );
108 Office *pOffice = lok_cpp_init( install_path );
109 if( !pOffice )
111 fprintf( stderr, "Failed to initialize\n" );
112 return -1;
115 end = getTimeMS();
116 fprintf( stderr, "init time: %ld ms\n", (end-start) );
117 start = end;
119 fprintf( stderr, "start to load document '%s'\n", argv[2] );
120 Document *pDocument = pOffice->documentLoad( argv[2] );
121 if( !pDocument )
123 char *pError = pOffice->getError();
124 fprintf( stderr, "failed to load document '%s': '%s'\n",
125 argv[2], pError );
126 free (pError);
127 return -1;
130 end = getTimeMS();
131 fprintf( stderr, "load time: %ld ms\n", (end-start) );
132 start = end;
134 if( argc > 3 )
136 const char *pFilter = NULL;
137 if( argc > 4 )
138 pFilter = argv[4];
139 fprintf( stderr, "save document as '%s' (%s)\n", argv[3], pFilter ? pFilter : "<null>" );
140 if( !pDocument->saveAs( argv[3], pFilter ) )
142 char *pError = pOffice->getError();
143 fprintf( stderr, "failed to save document '%s'\n", pError);
144 free (pError);
146 else
148 fprintf( stderr, "Save succeeded\n" );
149 end = getTimeMS();
150 fprintf( stderr, "save time: %ld ms\n", (end-start) );
153 fprintf( stderr, "all tests passed.\n" );
155 delete pDocument;
156 delete pOffice;
158 return 0;
161 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */