Version 5.4.3.2, tag libreoffice-5.4.3.2
[LibreOffice.git] / vcl / workben / commonfuzzer.hxx
blob59c0ae265f532a1825f2f051aa627ab94b56a0b2
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 <sal/main.h>
11 #include <tools/extendapplicationenvironment.hxx>
13 #include <cppuhelper/bootstrap.hxx>
14 #include <comphelper/processfactory.hxx>
16 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
17 #include <com/sun/star/uno/XComponentContext.hpp>
18 #include <unotools/configmgr.hxx>
19 #include <rtl/bootstrap.hxx>
20 #include <rtl/strbuf.hxx>
21 #include <osl/file.hxx>
22 #include <vcl/print.hxx>
23 #include <vcl/svapp.hxx>
24 #include <vcl/wmf.hxx>
25 #include <unistd.h>
26 #include <stdlib.h>
27 #include "headless/svpgdi.hxx"
28 #include "unx/fontmanager.hxx"
29 #include "unx/glyphcache.hxx"
31 using namespace ::com::sun::star::uno;
32 using namespace ::com::sun::star::lang;
33 using namespace cppu;
35 namespace
37 OUString getExecutableDir()
39 OUString uri;
40 if (osl_getExecutableFile(&uri.pData) != osl_Process_E_None) {
41 abort();
43 sal_Int32 lastDirSeperatorPos = uri.lastIndexOf('/');
44 if (lastDirSeperatorPos >= 0) {
45 uri = uri.copy(0, lastDirSeperatorPos + 1);
47 return uri;
50 void setFontConfigConf(const OUString &execdir)
52 osl::File aFontConfig("file:///tmp/wmffuzzerfonts.conf");
53 if (aFontConfig.open(osl_File_OpenFlag_Create | osl_File_OpenFlag_Write) == osl::File::E_None)
55 OUString path;
56 osl::FileBase::getSystemPathFromFileURL(execdir, path);
57 OString sFontDir = OUStringToOString(path, osl_getThreadTextEncoding());
59 rtl::OStringBuffer aBuffer("<?xml version=\"1.0\"?>\n<fontconfig><dir>");
60 aBuffer.append(sFontDir);
61 aBuffer.append("</dir><cachedir>/tmp/cache/fontconfig</cachedir></fontconfig>");
62 rtl::OString aConf = aBuffer.makeStringAndClear();
63 sal_uInt64 aBytesWritten;
64 aFontConfig.write(aConf.getStr(), aConf.getLength(), aBytesWritten);
65 assert(aBytesWritten == aConf.getLength());
67 setenv("FONTCONFIG_FILE", "/tmp/wmffuzzerfonts.conf", 0);
71 extern "C"
73 __attribute__((weak)) void __lsan_disable();
74 __attribute__((weak)) void __lsan_enable();
77 void CommonInitialize(int *argc, char ***argv)
79 setenv("SAL_USE_VCLPLUGIN", "svp", 1);
80 setenv("JPEGMEM", "768M", 1);
81 setenv("SAL_WMF_COMPLEXCLIP_VIA_REGION", "1", 1);
82 setenv("SAL_DISABLE_PRINTERLIST", "1", 1);
83 setenv("SAL_NO_FONT_LOOKUP", "1", 1);
85 osl_setCommandArgs(*argc, *argv);
87 OUString sExecDir = getExecutableDir();
88 rtl::Bootstrap::set("BRAND_BASE_DIR", sExecDir);
89 setFontConfigConf(sExecDir);
91 tools::extendApplicationEnvironment();
93 Reference< XComponentContext > xContext = defaultBootstrap_InitialComponentContext();
94 Reference< XMultiServiceFactory > xServiceManager( xContext->getServiceManager(), UNO_QUERY );
95 if( !xServiceManager.is() )
96 Application::Abort( "Failed to bootstrap" );
97 comphelper::setProcessServiceFactory( xServiceManager );
98 utl::ConfigManager::EnableAvoidConfig();
99 InitVCL();
101 //we don't have a de-init, so inside this leak disabled region...
102 //get the font info
103 psp::PrintFontManager::get();
104 //get the printer info
105 Printer::GetPrinterQueues();
108 void TypicalFuzzerInitialize(int *argc, char ***argv)
110 if (__lsan_disable)
111 __lsan_disable();
113 CommonInitialize(argc, argv);
115 if (__lsan_enable)
116 __lsan_enable();
119 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */