cid#1607171 Data race condition
[LibreOffice.git] / shell / source / win32 / workbench / TestSysShExec.cxx
blob2dd1ba2460423b4b3b8e35a92fadb77260f62e0b
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 .
20 #include <com/sun/star/lang/XComponent.hpp>
21 #include <com/sun/star/registry/XSimpleRegistry.hpp>
23 #include <com/sun/star/system/XSystemShellExecute.hpp>
24 #include <cppuhelper/servicefactory.hxx>
26 #include <osl/file.hxx>
27 #include <rtl/ustring.hxx>
28 #include <sal/types.h>
29 #include <osl/diagnose.h>
31 #include <stdio.h>
33 #include <windows.h>
36 // namespaces
39 using namespace ::cppu ;
40 using namespace ::com::sun::star::uno ;
41 using namespace ::com::sun::star::lang ;
42 using namespace std ;
43 using namespace com::sun::star::system;
45 #define RDB_SYSPATH "D:\\Projects\\gsl\\shell\\wntmsci7\\bin\\applicat.rdb"
48 // global variables
51 Reference< XMultiServiceFactory > g_xFactory;
54 // main
57 // int SAL_CALL main(int nArgc, char* Argv[], char* Env[] )
58 int SAL_CALL main(int nArgc, char* Argv[], char* )
61 // get the global service-manager
64 if ( nArgc < 4 )
65 return 0;
67 // Get global factory for uno services.
68 OUString rdbName = OUString( RDB_SYSPATH );
69 Reference< XMultiServiceFactory > g_xFactory( createRegistryServiceFactory( rdbName ) );
71 // Print a message if an error occurred.
72 if ( g_xFactory.is() == sal_False )
74 OSL_FAIL("Can't create RegistryServiceFactory");
75 return(-1);
78 printf("Creating RegistryServiceFactory successful\n");
81 // try to get an Interface to a XFilePicker Service
84 Reference< XSystemShellExecute > xSysShExec(
85 g_xFactory->createInstance("com.sun.star.system.SystemShellExecute"), UNO_QUERY );
87 if ( !xSysShExec.is() )
89 OSL_FAIL( "Error creating SystemShellExecute Service" );
90 return(-1);
93 //"c:\\winnt\\notepad.exe"
94 OUString cmd = OUString::createFromAscii( Argv[1] );
95 OUString param = OUString::createFromAscii( Argv[2] ); //c:\\winnt\\iis5.log
97 try
99 xSysShExec->execute( cmd, param, atoi( Argv[3] ) );
101 catch( SystemShellExecuteException& )
103 OSL_FAIL( "Error executing system command" );
105 catch( IllegalArgumentException& )
107 OSL_FAIL( "Invalid parameter" );
111 // shutdown
114 // Cast factory to XComponent
115 Reference< XComponent > xComponent( g_xFactory, UNO_QUERY );
117 // Print a message if an error occurred.
118 if ( xComponent.is() == sal_False )
120 OSL_FAIL("Error shutting down");
123 // Dispose and clear factory
124 xComponent->dispose();
125 g_xFactory.clear();
127 printf("Test successful\n");
129 return 0;
132 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */