LibreOffice Module shell (master) 1
TestSysShExec.cxx
Go to the documentation of this file.
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 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#include <com/sun/star/lang/XComponent.hpp>
21#include <com/sun/star/registry/XSimpleRegistry.hpp>
22
23#include <com/sun/star/system/XSystemShellExecute.hpp>
24#include <cppuhelper/servicefactory.hxx>
25
26#include <osl/file.hxx>
27#include <rtl/ustring.hxx>
28#include <sal/types.h>
29#include <osl/diagnose.h>
30
31#include <stdio.h>
32
33#include <windows.h>
34
35
36// namespaces
37
38
39using namespace ::cppu ;
40using namespace ::com::sun::star::uno ;
41using namespace ::com::sun::star::lang ;
42using namespace std ;
43using namespace com::sun::star::system;
44
45#define RDB_SYSPATH "D:\\Projects\\gsl\\shell\\wntmsci7\\bin\\applicat.rdb"
46
47
48// global variables
49
50
51Reference< XMultiServiceFactory > g_xFactory;
52
53
54// main
55
56
57// int SAL_CALL main(int nArgc, char* Argv[], char* Env[] )
58int SAL_CALL main(int nArgc, char* Argv[], char* )
59{
60
61 // get the global service-manager
62
63
64 if ( nArgc < 4 )
65 return 0;
66
67 // Get global factory for uno services.
68 OUString rdbName = OUString( RDB_SYSPATH );
69 Reference< XMultiServiceFactory > g_xFactory( createRegistryServiceFactory( rdbName ) );
70
71 // Print a message if an error occurred.
72 if ( g_xFactory.is() == sal_False )
73 {
74 OSL_FAIL("Can't create RegistryServiceFactory");
75 return(-1);
76 }
77
78 printf("Creating RegistryServiceFactory successful\n");
79
80
81 // try to get an Interface to a XFilePicker Service
82
83
84 Reference< XSystemShellExecute > xSysShExec(
85 g_xFactory->createInstance("com.sun.star.system.SystemShellExecute"), UNO_QUERY );
86
87 if ( !xSysShExec.is() )
88 {
89 OSL_FAIL( "Error creating SystemShellExecute Service" );
90 return(-1);
91 }
92
93 //"c:\\winnt\\notepad.exe"
94 OUString cmd = OUString::createFromAscii( Argv[1] );
95 OUString param = OUString::createFromAscii( Argv[2] ); //c:\\winnt\\iis5.log
96
97 try
98 {
99 xSysShExec->execute( cmd, param, atoi( Argv[3] ) );
100 }
101 catch( SystemShellExecuteException& )
102 {
103 OSL_FAIL( "Error executing system command" );
104 }
105 catch( IllegalArgumentException& )
106 {
107 OSL_FAIL( "Invalid parameter" );
108 }
109
110
111 // shutdown
112
113
114 // Cast factory to XComponent
115 Reference< XComponent > xComponent( g_xFactory, UNO_QUERY );
116
117 // Print a message if an error occurred.
118 if ( xComponent.is() == sal_False )
119 {
120 OSL_FAIL("Error shutting down");
121 }
122
123 // Dispose and clear factory
124 xComponent->dispose();
125 g_xFactory.clear();
126
127 printf("Test successful\n");
128
129 return 0;
130}
131
132/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Reference< XMultiServiceFactory > g_xFactory
int SAL_CALL main(int nArgc, char *Argv[], char *)
#define RDB_SYSPATH
SAL_DLLPUBLIC_EXPORT css::uno::Reference< css::lang::XMultiServiceFactory > SAL_CALL createRegistryServiceFactory(OUString const &, OUString const &, sal_Bool, OUString const &)
#define sal_False