|
1 // Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 |
|
17 #include <f32file.h> |
|
18 #include <e32std.h> |
|
19 #include <e32test.h> |
|
20 #include <s32file.h> |
|
21 #include <numberconversion.h> |
|
22 |
|
23 |
|
24 RTest TheTest(_L("t_logapi_helper")); |
|
25 |
|
26 _LIT(KSeparator, ";"); // Invalid filepath char used to separate filenames |
|
27 |
|
28 ////////////////////////////////////////////////////////////////////////////////////////// |
|
29 //Tests macros and functions. |
|
30 //If (!aValue) then the test will be panicked, the test data files will be deleted. |
|
31 static void Check(TInt aValue, TInt aLine) |
|
32 { |
|
33 if(!aValue) |
|
34 { |
|
35 TheTest.Printf(_L("*** Boolean expression evaluated to false\r\n")); |
|
36 TheTest(EFalse, aLine); |
|
37 } |
|
38 } |
|
39 //If (aValue != aExpected) then the test will be panicked, the test data files will be deleted. |
|
40 static void Check(TInt aValue, TInt aExpected, TInt aLine) |
|
41 { |
|
42 if(aValue != aExpected) |
|
43 { |
|
44 TheTest.Printf(_L("*** Expected error: %d, got: %d\r\n"), aExpected, aValue); |
|
45 TheTest(EFalse, aLine); |
|
46 } |
|
47 } |
|
48 //Use these to test conditions. |
|
49 #define TEST(arg) Check((arg), __LINE__) |
|
50 #define TEST2(aValue, aExpected) Check(aValue, aExpected, __LINE__) |
|
51 |
|
52 /* |
|
53 This method helps to do operations on files and folders, like copy, delete, rename, create directory (MkDir) |
|
54 This process has a capabilities to write in all files of the system. |
|
55 -param: anOld: source file |
|
56 -param: aNew : destination file |
|
57 -param: aCode: The operation to do. |
|
58 */ |
|
59 void OperationOnFilesAndFolders(const TDesC& anOld, const TDesC& aNew, TInt aCode) |
|
60 { |
|
61 RFs fs; |
|
62 TInt err = fs.Connect(); |
|
63 TEST2(err, KErrNone); |
|
64 |
|
65 CFileMan* fileMan = NULL; |
|
66 TRAP(err, fileMan = CFileMan::NewL(fs)); |
|
67 TEST2(err, KErrNone); |
|
68 |
|
69 switch(aCode) |
|
70 { |
|
71 case 0: |
|
72 TheTest.Printf(_L("Copying source file: %S %S\r\n"), &anOld, &aNew); |
|
73 err = fileMan->Copy(anOld, aNew); |
|
74 TEST2(err, KErrNone); |
|
75 break; |
|
76 |
|
77 case 1: |
|
78 TheTest.Printf(_L("Renaming file: %S %S\r\n"), &anOld, &aNew); |
|
79 err = fileMan->Rename(anOld, aNew); |
|
80 TEST2(err, KErrNone); |
|
81 break; |
|
82 |
|
83 case 2: |
|
84 TheTest.Printf(_L("Deleting file: %S\r\n"), &anOld); |
|
85 err = fileMan->Attribs(anOld, 0, KEntryAttReadOnly, 0, CFileMan::EOverWrite); |
|
86 if(err == KErrNone) |
|
87 { |
|
88 err = fileMan->Delete(anOld); |
|
89 } |
|
90 TEST(err == KErrNone || err == KErrNotFound); |
|
91 break; |
|
92 case 3: |
|
93 TheTest.Printf(_L("Creating folder: %S\r\n"), &anOld); |
|
94 err = fs.MkDir(anOld); |
|
95 TEST(err == KErrNone || err == KErrAlreadyExists); |
|
96 break; |
|
97 default: |
|
98 break; |
|
99 } |
|
100 delete fileMan; |
|
101 fs.Close(); |
|
102 } |
|
103 |
|
104 TInt E32Main() |
|
105 { |
|
106 CTrapCleanup* tc = CTrapCleanup::New(); |
|
107 TheTest(tc != NULL); |
|
108 |
|
109 __UHEAP_MARK; |
|
110 |
|
111 TheTest.Start(_L("Start: t_logapi_helper process started... ")); |
|
112 TheTest.Title(); |
|
113 |
|
114 TBuf<100> args; |
|
115 User::CommandLine(args); |
|
116 TInt cmdLength = User::CommandLineLength(); |
|
117 |
|
118 TInt pos = args.Find(KSeparator); |
|
119 TBuf<50> oldName(args.Mid(0,pos)); |
|
120 TInt oldNameLength = oldName.Length(); |
|
121 TInt remainderLength = cmdLength - oldNameLength; |
|
122 |
|
123 TBuf<50> remainder(args.Mid(pos+1, remainderLength-1)); |
|
124 pos = remainder.Find(KSeparator); |
|
125 |
|
126 TDigitType digitType; |
|
127 TInt length; |
|
128 TBuf<50> newName(remainder.Mid(0, pos)); |
|
129 TBuf<1> code = remainder.Mid(pos+1, 1); |
|
130 TInt numberLength = code.Length(); |
|
131 |
|
132 TInt operationMode = NumberConversion::ConvertFirstNumber(code, length, digitType); |
|
133 |
|
134 OperationOnFilesAndFolders(oldName, newName, operationMode); |
|
135 |
|
136 TheTest.End(); |
|
137 TheTest.Close(); |
|
138 |
|
139 __UHEAP_MARKEND; |
|
140 |
|
141 delete tc; |
|
142 |
|
143 return 0; |
|
144 } |
|
145 |