1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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 */
9
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 <liblibreoffice.hxx>
17
18long getTimeMS()
19{
20 struct timeval t;
21 gettimeofday(&t, NULL);
22 return t.tv_sec*1000 + t.tv_usec/1000;
23}
24
25static int help()
26{
27 fprintf( stderr, "Usage: libtest <absolute-path-to-libreoffice-install> [path to load document] [path to save document].\n" );
28 return 1;
29}
30
31int main (int argc, char **argv)
32{
33 long start, end;
34
35 start = getTimeMS();
36
37 if( argc < 2 ||
38 ( argc > 1 && ( !strcmp( argv[1], "--help" ) || !strcmp( argv[1], "-h" ) ) ) )
39 return help();
40
41 if (argv[1][0] != '/')
42 {
43 fprintf( stderr, "Absolute path required to libreoffice install\n" );
44 return 1;
45 }
46
47 LibLibreOffice *pOffice = lo_cpp_init( argv[1] );
48 if( !pOffice )
49 {
50 fprintf( stderr, "Failed to initialize\n" );
51 return -1;
52 }
53
54 // This separate init is lame I think.
55 if( !pOffice->initialize( argv[1] ) )
56 {
57 fprintf( stderr, "failed to initialize\n" );
58 return -1;
59 }
60
61 end = getTimeMS();
62 fprintf( stderr, "init time: %ld ms\n", (end-start) );
63 start = end;
64
65 fprintf( stderr, "start to load document '%s'\n", argv[2] );
66 LODocument *pDocument = pOffice->documentLoad( argv[2] );
67 if( !pDocument )
68 {
69 char *pError = pOffice->getError();
70 fprintf( stderr, "failed to load document '%s': '%s'\n",
71 argv[2], pError );
72 free (pError);
73 return -1;
74 }
75
76 end = getTimeMS();
77 fprintf( stderr, "load time: %ld ms\n", (end-start) );
78 start = end;
79
80 if( argc > 3 )
81 {
82 const char *pFilter = NULL;
83 if( argc > 4 )
84 pFilter = argv[4];
85 fprintf( stderr, "save document as '%s' (%s)\n", argv[3], pFilter ? pFilter : "<null>" );
86 if( !pDocument->saveAs( argv[3], pFilter ) )
87 {
88 char *pError = pOffice->getError();
89 fprintf( stderr, "failed to save document '%s'\n", pError);
90 free (pError);
91 }
92 else
93 {
94 fprintf( stderr, "Save succeeded\n" );
95 end = getTimeMS();
96 fprintf( stderr, "save time: %ld ms\n", (end-start) );
97 }
98 }
99 fprintf( stderr, "all tests passed.\n" );
100
101 delete pDocument;
102 delete pOffice;
103
104 return 0;
105}
106
107/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
108