cid#1607171 Data race condition
[LibreOffice.git] / sdext / source / pdfimport / test / pdf2xml.cxx
blob3592baef2e577459f43142a05f41dc8d40543946
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/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include "outputwrap.hxx"
22 #include <contentsink.hxx>
23 #include <pdfihelper.hxx>
24 #include <wrapper.hxx>
25 #include <pdfparse.hxx>
26 #include "../pdfiadaptor.hxx"
28 #include <sal/main.h>
29 #include <osl/process.h>
30 #include <rtl/ref.hxx>
31 #include <sal/log.hxx>
32 #include <unotest/bootstrapfixturebase.hxx>
33 #include <comphelper/processfactory.hxx>
34 #include <cppuhelper/bootstrap.hxx>
35 #include <comphelper/diagnose_ex.hxx>
37 using namespace ::pdfi;
38 using namespace ::com::sun::star;
40 SAL_IMPLEMENT_MAIN_WITH_ARGS(argc, argv)
42 if( argc < 4 )
43 return 1;
45 int nRet = 0;
47 try
49 OUString aBaseURL, aTmpURL, aSrcURL, aDstURL;
51 TreeVisitorFactorySharedPtr pTreeFactory;
52 if( rtl_str_compare(argv[1], "-writer") == 0 )
53 pTreeFactory = createWriterTreeVisitorFactory();
54 else if( rtl_str_compare(argv[1], "-draw") == 0 )
55 pTreeFactory = createDrawTreeVisitorFactory();
56 else if( rtl_str_compare(argv[1], "-impress") == 0 )
57 pTreeFactory = createImpressTreeVisitorFactory();
58 else
59 return 1;
61 osl_getProcessWorkingDir(&aBaseURL.pData);
62 osl_getFileURLFromSystemPath( OUString::createFromAscii(argv[2]).pData,
63 &aTmpURL.pData );
64 osl_getAbsoluteFileURL(aBaseURL.pData,aTmpURL.pData,&aSrcURL.pData);
66 osl_getFileURLFromSystemPath( OUString::createFromAscii(argv[3]).pData,
67 &aTmpURL.pData );
68 osl_getAbsoluteFileURL(aBaseURL.pData,aTmpURL.pData,&aDstURL.pData);
70 // bootstrap UNO
71 uno::Reference< uno::XComponentContext > xContext(
72 cppu::defaultBootstrap_InitialComponentContext() );
73 uno::Reference<lang::XMultiComponentFactory> xFactory(xContext->getServiceManager());
74 uno::Reference<lang::XMultiServiceFactory> xSM(xFactory, uno::UNO_QUERY_THROW);
75 comphelper::setProcessServiceFactory(xSM);
77 test::BootstrapFixtureBase aEnv;
78 aEnv.setUp();
80 rtl::Reference<pdfi::PDFIRawAdaptor> xAdaptor( new pdfi::PDFIRawAdaptor(OUString(), aEnv.getComponentContext()) );
81 xAdaptor->setTreeVisitorFactory(pTreeFactory);
82 nRet = xAdaptor->odfConvert(aSrcURL, new OutputWrap(aDstURL), nullptr) ? 0 : 1;
84 catch (const uno::Exception&)
86 TOOLS_WARN_EXCEPTION("vcl.app", "Fatal");
87 return 1;
89 catch (const std::exception& e)
91 SAL_WARN("vcl.app", "Fatal: " << e.what());
92 return 1;
95 return nRet;
98 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */