diff options
author | Michael Meeks <michael.meeks@collabora.com> | 2013-11-07 11:46:08 +0000 |
---|---|---|
committer | Michael Meeks <michael.meeks@collabora.com> | 2013-11-07 11:50:01 +0000 |
commit | b9bbd847876cd7b23861c862af510da8244aef18 (patch) | |
tree | c2dce7518e4a0a9e9087671c44d825e815d20e39 | |
parent | 3c608eb38150f3b11919adf6eca6eff0fdfdb0cd (diff) |
liblibo: improve the libtest sample app.
Add command-line help, validate arguments more, better error reporting.
Change-Id: Ia092895d0d116b003bb6c2a252f68ae9b6ba6d35
-rw-r--r-- | smoketest/libtest.cxx | 26 |
1 files changed, 23 insertions, 3 deletions
diff --git a/smoketest/libtest.cxx b/smoketest/libtest.cxx index ffacd188307e..39a009806490 100644 --- a/smoketest/libtest.cxx +++ b/smoketest/libtest.cxx @@ -8,6 +8,7 @@ */ #include <stdio.h> +#include <string.h> #include <malloc.h> #include <assert.h> #include <math.h> @@ -16,17 +17,35 @@ long getTimeMS(); +static int help() +{ + fprintf( stderr, "Usage: libtest <absolute-path-to-libreoffice-install> [path to load document] [path to save document].\n" ); + return 1; +} + int main (int argc, char **argv) { long start, end; start = getTimeMS(); - if( argc < 2 ) - return -1; + if( argc < 2 || + ( argc > 1 && ( !strcmp( argv[1], "--help" ) || !strcmp( argv[1], "-h" ) ) ) ) + return help(); + + if (argv[1][0] != '/') + { + fprintf( stderr, "Absolute path required to libreoffice install\n" ); + return 1; + } + LibLibreOffice *pOffice = lo_init( argv[1] ); if( !pOffice ) + { + fprintf( stderr, "Failed to initialize\n" ); return -1; + } + // This separate init is lame I think. if( !pOffice->initialize( argv[1] ) ) { @@ -80,7 +99,8 @@ int main (int argc, char **argv) return 0; } -long getTimeMS() { +long getTimeMS() +{ struct timespec t; clock_gettime(CLOCK_MONOTONIC, &t); long ms = round(t.tv_nsec / 1.0e6) + t.tv_sec * 1000; |