1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/persistentdata/loggingservices/eventlogger/test/src/t_logapi_helper.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,121 @@
1.4 +// Copyright (c) 2008-2010 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +//
1.18 +
1.19 +
1.20 +#include <f32file.h>
1.21 +#include <e32std.h>
1.22 +#include <e32test.h>
1.23 +#include <s32file.h>
1.24 +#include <numberconversion.h>
1.25 +#include "t_logutil.h"
1.26 +
1.27 +_LIT(KSeparator, ";"); // Invalid filepath char used to separate filenames
1.28 +
1.29 +RTest TheTest(_L("t_logapi_helper"));
1.30 +
1.31 +/*
1.32 +This method helps to do operations on files and folders, like copy, delete, rename, create directory (MkDir)
1.33 +This process has a capabilities to write in all files of the system.
1.34 +-param: anOld: source file
1.35 +-param: aNew : destination file
1.36 +-param: aCode: The operation to do.
1.37 +*/
1.38 +void OperationOnFilesAndFolders(const TDesC& anOld, const TDesC& aNew, TInt aCode)
1.39 + {
1.40 + RFs fs;
1.41 + TInt err = fs.Connect();
1.42 + TEST2(err, KErrNone);
1.43 +
1.44 + CFileMan* fileMan = NULL;
1.45 + TRAP(err, fileMan = CFileMan::NewL(fs));
1.46 + TEST2(err, KErrNone);
1.47 +
1.48 + switch(aCode)
1.49 + {
1.50 + case 0:
1.51 + TheTest.Printf(_L("Copying source file: %S %S\r\n"), &anOld, &aNew);
1.52 + err = fileMan->Copy(anOld, aNew);
1.53 + TEST2(err, KErrNone);
1.54 + break;
1.55 +
1.56 + case 1:
1.57 + TheTest.Printf(_L("Renaming file: %S %S\r\n"), &anOld, &aNew);
1.58 + err = fileMan->Rename(anOld, aNew);
1.59 + TEST2(err, KErrNone);
1.60 + break;
1.61 +
1.62 + case 2:
1.63 + TheTest.Printf(_L("Deleting file: %S\r\n"), &anOld);
1.64 + err = fileMan->Attribs(anOld, 0, KEntryAttReadOnly, 0, CFileMan::EOverWrite);
1.65 + if(err == KErrNone)
1.66 + {
1.67 + err = fileMan->Delete(anOld);
1.68 + }
1.69 + TEST(err == KErrNone || err == KErrNotFound);
1.70 + break;
1.71 + case 3:
1.72 + TheTest.Printf(_L("Creating folder: %S\r\n"), &anOld);
1.73 + err = fs.MkDir(anOld);
1.74 + TEST(err == KErrNone || err == KErrAlreadyExists);
1.75 + break;
1.76 + default:
1.77 + break;
1.78 + }
1.79 + delete fileMan;
1.80 + fs.Close();
1.81 + }
1.82 +
1.83 +TInt E32Main()
1.84 + {
1.85 + CTrapCleanup* tc = CTrapCleanup::New();
1.86 + TheTest(tc != NULL);
1.87 +
1.88 + __UHEAP_MARK;
1.89 +
1.90 + TheTest.Start(_L("Start: t_logapi_helper process started... "));
1.91 + TheTest.Title();
1.92 +
1.93 + TBuf<100> args;
1.94 + User::CommandLine(args);
1.95 + TInt cmdLength = User::CommandLineLength();
1.96 +
1.97 + TInt pos = args.Find(KSeparator);
1.98 + TBuf<50> oldName(args.Mid(0,pos));
1.99 + TInt oldNameLength = oldName.Length();
1.100 + TInt remainderLength = cmdLength - oldNameLength;
1.101 +
1.102 + TBuf<50> remainder(args.Mid(pos+1, remainderLength-1));
1.103 + pos = remainder.Find(KSeparator);
1.104 +
1.105 + TDigitType digitType;
1.106 + TInt length;
1.107 + TBuf<50> newName(remainder.Mid(0, pos));
1.108 + TBuf<1> code = remainder.Mid(pos+1, 1);
1.109 + TInt numberLength = code.Length();
1.110 +
1.111 + TInt operationMode = NumberConversion::ConvertFirstNumber(code, length, digitType);
1.112 +
1.113 + OperationOnFilesAndFolders(oldName, newName, operationMode);
1.114 +
1.115 + TheTest.End();
1.116 + TheTest.Close();
1.117 +
1.118 + __UHEAP_MARKEND;
1.119 +
1.120 + delete tc;
1.121 +
1.122 + return 0;
1.123 + }
1.124 +