From a7eb227cfcd783ffdccdcec9b56451fb54c26eb6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lubo=C5=A1=20Lu=C5=88=C3=A1k?= Date: Mon, 2 Apr 2012 18:59:53 +0200 Subject: [PATCH] fix crude command line arguments handling --- sal/qa/osl/security/osl_Security.cxx | 78 ++++++++++++++++------------ 1 file changed, 44 insertions(+), 34 deletions(-) diff --git a/sal/qa/osl/security/osl_Security.cxx b/sal/qa/osl/security/osl_Security.cxx index 223c5f95c93b..92b9fe465ebe 100644 --- a/sal/qa/osl/security/osl_Security.cxx +++ b/sal/qa/osl/security/osl_Security.cxx @@ -38,6 +38,7 @@ #endif #include #include +#include #include using namespace osl; @@ -353,7 +354,7 @@ class MyTestPlugInImpl: public CPPUNIT_NS::TestPlugInDefaultImpl void MyTestPlugInImpl::initialize( CPPUNIT_NS::TestFactoryRegistry *, - const CPPUNIT_NS::PlugInParameters & parameters) + const CPPUNIT_NS::PlugInParameters & ) { /// start message t_print("#Initializing ...\n" ); @@ -633,44 +634,53 @@ void MyTestPlugInImpl::initialize( CPPUNIT_NS::TestFactoryRegistry *, t_print("Administrator.\n" ); /// get and display forwarded text if available. - aStringForward = ::rtl::OUString::createFromAscii( parameters.getCommandLine().c_str() ); - if ( !aStringForward.isEmpty() && aStringForward.indexOf( (sal_Unicode)' ' ) != -1 ) + rtl::OUString args[ 3 ]; + int argsCount = 0; + sal_uInt32 n = rtl_getAppCommandArgCount(); + // skip first, that's the module name + for (sal_uInt32 i = 1; i < n; ++i) { - sal_Int32 nFirstSpacePoint = aStringForward.indexOf( (sal_Unicode)' ' );; - sal_Int32 nLastSpacePoint = aStringForward.lastIndexOf( (sal_Unicode)' ' );; - if ( nFirstSpacePoint == nLastSpacePoint ) - /// only forwarded two parameters, username and password. + rtl::OUString arg; + rtl_getAppCommandArg(i, &arg.pData); + if( !arg.isEmpty() && arg[ 0 ] == '-' ) + continue; + if( argsCount >= 3 ) { - aLogonUser = aStringForward.copy( 0, nFirstSpacePoint ); - t_print("\n#Forwarded username: "); - printUString( aLogonUser); - - aLogonPasswd = aStringForward.copy( nFirstSpacePoint +1, aStringForward.getLength( ) - 1 ); - t_print("#Forwarded password: "); - for (int i = nFirstSpacePoint+1; i <= aStringForward.getLength()-1; ++i) - t_print("*"); - t_print("\n" ); - } - else - /// forwarded three parameters, username, password and fileserver. - { - aLogonUser = aStringForward.copy( 0, nFirstSpacePoint ); - t_print("#Forwarded username: "); - printUString( aLogonUser); - - aLogonPasswd = aStringForward.copy( nFirstSpacePoint +1, nLastSpacePoint ); - t_print("#Forwarded password: "); - for (int i = nFirstSpacePoint+1; i <= nLastSpacePoint; ++i) - t_print("*"); - t_print("\n" ); - - aFileServer = aStringForward.copy( nLastSpacePoint +1, aStringForward.getLength( ) - 1 ); - t_print("#Forwarded FileServer: "); - printUString( aFileServer ); - + SAL_WARN( "sal", "Too many test arguments" ); + continue; } + args[ argsCount++ ] = arg; } + /// only forwarded two parameters, username and password. + if( argsCount == 2 ) + { + aLogonUser = args[ 0 ]; + t_print("\n#Forwarded username: "); + printUString( aLogonUser); + aLogonPasswd = args[ 1 ]; + t_print("#Forwarded password: "); + for (int i = 0; i < aLogonPasswd.getLength(); ++i) + t_print("*"); + t_print("\n" ); + } + else if( argsCount == 3 ) + /// forwarded three parameters, username, password and fileserver. + { + aLogonUser = args[ 0 ]; + t_print("#Forwarded username: "); + printUString( aLogonUser); + + aLogonPasswd = args[ 1 ]; + t_print("#Forwarded password: "); + for (int i = 0; i < aLogonPasswd.getLength(); ++i) + t_print("*"); + t_print("\n" ); + + aFileServer = args[ 2 ]; + t_print("#Forwarded FileServer: "); + printUString( aFileServer ); + } t_print("#\n#Initialization Done.\n" ); }