installationservices/swi/test/tpathsubst/setsubst.cpp
changeset 0 ba25891c3a9e
equal deleted inserted replaced
-1:000000000000 0:ba25891c3a9e
       
     1 /*
       
     2 * Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of the License "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: 
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 /**
       
    20  @file
       
    21 */
       
    22 
       
    23 
       
    24 #include <e32test.h>
       
    25 #include <f32file.h>
       
    26 
       
    27 static RTest test(_L("setsubst"));
       
    28 
       
    29 GLDEF_C TInt E32Main()
       
    30 /**
       
    31 	setsubst drive-letter: subst-path
       
    32  */
       
    33     {
       
    34 	CTrapCleanup* cleanup = CTrapCleanup::New();
       
    35 	test(cleanup != 0);
       
    36 	
       
    37 	__UHEAP_MARK;
       
    38 
       
    39 	test.Title();
       
    40 	test.Start(_L(" @SYMTestCaseID API-SEC-SETSUBST-0001 Starting tests..."));
       
    41 
       
    42 	// read in the command line args
       
    43 	const TInt KCmdLineBufLen = 64;
       
    44 	test(User::CommandLineLength() <= KCmdLineBufLen);
       
    45 
       
    46 	TBuf<KCmdLineBufLen> cmdLine;
       
    47 	User::CommandLine(cmdLine);
       
    48 	TLex l(cmdLine);
       
    49 
       
    50 	// extract the drive number
       
    51 	TPtrC token = l.NextToken();
       
    52 	test(token.Length() == 2);
       
    53 	test(TChar(token[0]).IsAlpha());
       
    54 	test(token[1] == ':');
       
    55 	TInt drvNum;
       
    56 	TChar drvCh = token[0];
       
    57 	test(RFs::CharToDrive(drvCh, drvNum) == KErrNone);
       
    58 
       
    59 	// extract the replacement path
       
    60 	token.Set(l.NextToken());
       
    61 	TInt dirLen = token.Length();
       
    62 	test(	dirLen == 0
       
    63 		||	(	dirLen >= 3
       
    64 			&&	TChar(token[0]).IsAlpha()
       
    65 			&&	token[1] == ':'
       
    66 			&&	token[2] == '\\' ) );
       
    67 	
       
    68 	// do the substitution
       
    69 	RFs fs;
       
    70 	test(fs.Connect() == KErrNone);
       
    71 
       
    72 	test(fs.SetSubst(token, drvNum) == KErrNone);
       
    73 
       
    74 	fs.Close();
       
    75 
       
    76 	test.End();
       
    77 	test.Close();
       
    78 
       
    79 	__UHEAP_MARKEND;
       
    80 	delete cleanup;
       
    81 	
       
    82 	return KErrNone;
       
    83 	}