installationservices/swinstallationfw/test/tusif/source/testexes/siftestintegrationlockfile.cpp
branchRCL_3
changeset 25 7333d7932ef7
equal deleted inserted replaced
24:5cc91383ab1e 25:7333d7932ef7
       
     1 /*
       
     2 * Copyright (c) 2008-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 * sifintegrationlockfile.cpp
       
    16 * This executable is used to lock a file in order to simulate errors while deleting files
       
    17 *
       
    18 */
       
    19 
       
    20 
       
    21 #include <e32base.h>
       
    22 #include <e32cons.h>
       
    23 #include <bacline.h>
       
    24 #include <f32file.h>
       
    25 
       
    26 LOCAL_C void mainL();
       
    27 
       
    28 TInt E32Main() // main function called by E32
       
    29 	{
       
    30 	__UHEAP_MARK;
       
    31 	CTrapCleanup* cleanup=CTrapCleanup::New(); // get clean-up stack
       
    32 	TRAPD(error,mainL()); // Run main method
       
    33 	__ASSERT_ALWAYS(!error, User::Panic(_L("SifIntegrationTest"),error));
       
    34 	delete cleanup; // destroy clean-up stack
       
    35 	__UHEAP_MARKEND;
       
    36 	return 0; // and return
       
    37 	}
       
    38 
       
    39 LOCAL_C void mainL()
       
    40 	{
       
    41 	CCommandLineArguments* cmdLine = CCommandLineArguments::NewLC();
       
    42 	CConsoleBase* console = Console::NewL(_L("Siftestintegrationlockfile"),TSize(KConsFullScreen,KConsFullScreen));
       
    43 	CleanupStack::PushL(console);
       
    44 	TInt argTotal(cmdLine->Count());
       
    45 	if (argTotal < 2  || argTotal > 3)
       
    46 		{
       
    47 		console->Printf(_L("Incorrect arguments specified: expected 1, received %d"), argTotal - 1);
       
    48 		User::Leave(KErrArgument);
       
    49 		}
       
    50 		
       
    51 	TPtrC filename(cmdLine->Arg(1));
       
    52 	_LIT(KDoLockFileParam, " lockfile");
       
    53 	if (argTotal == 2)
       
    54 		{
       
    55 		RBuf params;
       
    56 		params.CreateL(filename.Length() + KDoLockFileParam().Length());
       
    57 		params.CleanupClosePushL();
       
    58 		params.Append(cmdLine->Arg(1));
       
    59 		params.Append(KDoLockFileParam());
       
    60 		// Since this executable is used by TEF, we wish to lock the file after the launched process has exited, so we spawn this process again with a different set of parameters
       
    61 		RProcess newInstance;
       
    62 		User::LeaveIfError(newInstance.Create(_L("Siftestintegrationlockfile"), params));
       
    63 		CleanupClosePushL(newInstance);
       
    64 		newInstance.Resume();
       
    65 		TRequestStatus status;		
       
    66 		newInstance.Rendezvous(status);
       
    67 		User::WaitForRequest(status);
       
    68 		User::LeaveIfError(status.Int());
       
    69 		CleanupStack::PopAndDestroy(2, &params); // newInstance
       
    70 		}
       
    71 	else
       
    72 		{
       
    73 		// This is the execution for locking the file, invoked using the branch above
       
    74 		console->Printf(_L("Locking file %S for read"), &filename);	
       
    75 		RFs fs;
       
    76 		User::LeaveIfError(fs.Connect());
       
    77 		CleanupClosePushL(fs);
       
    78 	
       
    79 		RFile file;
       
    80 		User::LeaveIfError(file.Open(fs, filename, EFileShareReadersOnly|EFileRead));
       
    81 		CleanupClosePushL(file);
       
    82 		// Signal the invoker only here, so that the file will definitely get locked before TEF proceeds to the next step
       
    83 		RProcess::Rendezvous(KErrNone);		
       
    84 		
       
    85 		User::After(10*1000*1000); // Wait for 10 seconds
       
    86 	
       
    87 		CleanupStack::PopAndDestroy(2 , &fs); // file
       
    88 		}
       
    89 	CleanupStack::PopAndDestroy(2, cmdLine); // console,
       
    90     }
       
    91 
       
    92 // End of file