Bump version to 4.3-4
[LibreOffice.git] / smoketest / libtest.cxx
blob8a0b7242c46fba3026094f2b96b92798b96d1b53
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>
15 #include <sys/time.h>
16 #include <sal/types.h>
17 #include <LibreOfficeKit/LibreOfficeKit.hxx>
19 using namespace ::lok;
21 long getTimeMS()
23 struct timeval t;
24 gettimeofday(&t, NULL);
25 return t.tv_sec*1000 + t.tv_usec/1000;
28 static int help()
30 fprintf( stderr, "Usage: libtest <absolute-path-to-libreoffice-install> [path to load document] [path to save document].\n" );
31 return 1;
34 int main (int argc, char **argv)
36 long start, end;
38 start = getTimeMS();
40 if( argc < 2 ||
41 ( argc > 1 && ( !strcmp( argv[1], "--help" ) || !strcmp( argv[1], "-h" ) ) ) )
42 return help();
44 if (argv[1][0] != '/')
46 fprintf( stderr, "Absolute path required to libreoffice install\n" );
47 return 1;
50 Office *pOffice = lok_cpp_init( argv[1] );
51 if( !pOffice )
53 fprintf( stderr, "Failed to initialize\n" );
54 return -1;
57 end = getTimeMS();
58 fprintf( stderr, "init time: %ld ms\n", (end-start) );
59 start = end;
61 fprintf( stderr, "start to load document '%s'\n", argv[2] );
62 Document *pDocument = pOffice->documentLoad( argv[2] );
63 if( !pDocument )
65 char *pError = pOffice->getError();
66 fprintf( stderr, "failed to load document '%s': '%s'\n",
67 argv[2], pError );
68 free (pError);
69 return -1;
72 end = getTimeMS();
73 fprintf( stderr, "load time: %ld ms\n", (end-start) );
74 start = end;
76 if( argc > 3 )
78 const char *pFilter = NULL;
79 if( argc > 4 )
80 pFilter = argv[4];
81 fprintf( stderr, "save document as '%s' (%s)\n", argv[3], pFilter ? pFilter : "<null>" );
82 if( !pDocument->saveAs( argv[3], pFilter ) )
84 char *pError = pOffice->getError();
85 fprintf( stderr, "failed to save document '%s'\n", pError);
86 free (pError);
88 else
90 fprintf( stderr, "Save succeeded\n" );
91 end = getTimeMS();
92 fprintf( stderr, "save time: %ld ms\n", (end-start) );
95 fprintf( stderr, "all tests passed.\n" );
97 delete pDocument;
98 delete pOffice;
100 return 0;
103 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */