|
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 @file |
|
18 @test |
|
19 @internalComponent - Internal Symbian test code |
|
20 */ |
|
21 |
|
22 #include <e32base.h> |
|
23 #include <f32file.h> |
|
24 #include <s32file.h> |
|
25 #include "ssmcletestapp.h" |
|
26 #include "ssmdebug.h" |
|
27 |
|
28 void XSsmCleTestApp::WriteStartTimeL(RFs aFs, const TDesC& aLogPrefix) |
|
29 { |
|
30 TBuf<KTestCommandLineMaxLength> logFileName; |
|
31 logFileName.Format(_L("%Stime"), &aLogPrefix); |
|
32 TTime now; |
|
33 now.UniversalTime(); |
|
34 TUint32 high = 0; |
|
35 TUint32 low = 0; |
|
36 high = I64HIGH(now.Int64()); |
|
37 low = I64LOW(now.Int64()); |
|
38 RFileWriteStream ws; |
|
39 User::LeaveIfError(ws.Replace(aFs, logFileName, EFileWrite)); |
|
40 ws.PushL(); |
|
41 ws.WriteUint32L(high); |
|
42 ws.WriteUint32L(low); |
|
43 ws.CommitL(); |
|
44 CleanupStack::PopAndDestroy(); // ws |
|
45 } |
|
46 |
|
47 void XSsmCleTestApp::WriteResultL(RFs aFs, const TDesC& aLogPrefix, const TCleTestFailHow& aFailHow) |
|
48 { |
|
49 TBuf<KTestCommandLineMaxLength> logFileName, logFileNameExitReason; |
|
50 TInt result, err; |
|
51 RFileWriteStream fileWriteStream; |
|
52 |
|
53 //For Getting the Exit Reason |
|
54 if(aFailHow == EBadRendezvous) |
|
55 { |
|
56 //This is done because for BadRendezvous Case, we need to do 2 things: |
|
57 //1. Write the constant KErrBadRendezvousTest as the Exit Reason for the process in a separate file. |
|
58 //2. Write the EBadRendezvous value to a separate file, hence separate close and pop operations required. |
|
59 logFileNameExitReason.Format(_L("%Sreason"), &aLogPrefix); |
|
60 result = KErrBadRendezvousTest; |
|
61 err =fileWriteStream.Replace(aFs, logFileNameExitReason, EFileWrite); |
|
62 CleanupClosePushL(fileWriteStream); |
|
63 User::LeaveIfError(err); |
|
64 fileWriteStream.WriteUint32L(result); |
|
65 fileWriteStream.CommitL(); |
|
66 CleanupStack::PopAndDestroy(); // fileWriteStream |
|
67 } |
|
68 |
|
69 logFileName.Format(_L("%Sresult"), &aLogPrefix); |
|
70 result = aFailHow; |
|
71 err =fileWriteStream.Replace(aFs, logFileName, EFileWrite); |
|
72 CleanupClosePushL(fileWriteStream); |
|
73 User::LeaveIfError(err); |
|
74 fileWriteStream.WriteUint32L(result); |
|
75 fileWriteStream.CommitL(); |
|
76 CleanupStack::PopAndDestroy(); // fileWriteStream |
|
77 } |
|
78 |
|
79 TInt XSsmCleTestApp::GetRunCountL(RFs aFs, const TDesC& aLogPrefix) |
|
80 { |
|
81 TBuf<KTestCommandLineMaxLength> logFileName; |
|
82 logFileName.Format(_L("%Scount"), &aLogPrefix); |
|
83 |
|
84 RFileReadStream file; |
|
85 TInt err = 0; |
|
86 err = file.Open(aFs, logFileName, EFileRead); |
|
87 TInt result = 0; |
|
88 if (err != KErrNotFound && err != KErrPathNotFound) |
|
89 { |
|
90 file.PushL(); |
|
91 User::LeaveIfError(err); |
|
92 result = file.ReadInt32L(); |
|
93 file.Close(); |
|
94 CleanupStack::PopAndDestroy(); //file |
|
95 } |
|
96 return result; |
|
97 } |
|
98 |
|
99 TInt XSsmCleTestApp::IncrementRunCountL(RFs aFs, const TDesC& aLogPrefix) |
|
100 { |
|
101 TInt runcount = GetRunCountL(aFs, aLogPrefix); |
|
102 TBuf<KTestCommandLineMaxLength> logFileName; |
|
103 logFileName.Format(_L("%Scount"), &aLogPrefix); |
|
104 |
|
105 runcount++; |
|
106 |
|
107 RFileWriteStream file; |
|
108 User::LeaveIfError(file.Replace(aFs, logFileName, EFileWrite)); |
|
109 file.PushL(); |
|
110 file.WriteInt32L(runcount); |
|
111 file.Close(); |
|
112 |
|
113 CleanupStack::PopAndDestroy();//file |
|
114 return runcount; |
|
115 } |
|
116 |
|
117 void XSsmCleTestApp::GetCommandLineArgsL(TSsmCleTestAppArgs& aArgStruct) |
|
118 { |
|
119 DEBUGPRINT1A("Parsing commandline argument"); |
|
120 TBuf<KTestCommandLineMaxLength> commandLine; |
|
121 commandLine.SetLength(0); |
|
122 if(User::CommandLineLength() > commandLine.MaxLength()) |
|
123 { |
|
124 User::Leave(KErrTooBig); |
|
125 } |
|
126 User::CommandLine(commandLine); |
|
127 |
|
128 DEBUGPRINT3(_L("ssmcletestapp.cpp %d: Argument string: %S"), __LINE__, &commandLine); |
|
129 aArgStruct.iWaitTime = 0; |
|
130 aArgStruct.iSucceedOnRun = 0; |
|
131 aArgStruct.iFailHow = EDontFail; |
|
132 |
|
133 TLex cmdLnLex(commandLine); |
|
134 |
|
135 if (cmdLnLex.Eos()) // If there aren't any arguments, that is an error |
|
136 { |
|
137 DEBUGPRINT1A("Argument error"); |
|
138 User::Leave(KErrArgument); |
|
139 } |
|
140 else |
|
141 { |
|
142 TPtrC token(cmdLnLex.NextToken()); |
|
143 aArgStruct.iLogPrefix.SetLength(0); |
|
144 aArgStruct.iLogPrefix.Format(_L("%S%S"), &KTestAppLogFileLoc, &token); |
|
145 DEBUGPRINT4(_L("ssmcletestapp.cpp %d: Log file prefix (length: %d): %S"), __LINE__, aArgStruct.iLogPrefix.Length(), &(aArgStruct.iLogPrefix)); |
|
146 } |
|
147 |
|
148 if(!cmdLnLex.Eos()) // If there was only one argument, we are finished and there was no timeout requested. |
|
149 { |
|
150 TPtrC token(cmdLnLex.NextToken()); |
|
151 TLex timeoutLex(token); |
|
152 User::LeaveIfError(timeoutLex.Val(aArgStruct.iWaitTime)); // If Val() returns an error the second argument wasn't an integer, which it should have been |
|
153 } |
|
154 DEBUGPRINT2A("Wait time: %d", aArgStruct.iWaitTime); |
|
155 |
|
156 if(!cmdLnLex.Eos()) // If we've run out of arguments, we are finished and there was no failed runs requested. |
|
157 { |
|
158 TPtrC token(cmdLnLex.NextToken()); |
|
159 TLex timeoutLex(token); |
|
160 User::LeaveIfError(timeoutLex.Val(aArgStruct.iSucceedOnRun)); // If Val() returns an error the third argument wasn't an integer, which it should have been |
|
161 } |
|
162 DEBUGPRINT2A("Times to fail: %d", aArgStruct.iSucceedOnRun); |
|
163 |
|
164 if(!cmdLnLex.Eos()) // If we've run out of arguments, we are finished and there was no failure mode requested. |
|
165 { |
|
166 TInt temp; |
|
167 TPtrC token(cmdLnLex.NextToken()); |
|
168 TLex timeoutLex(token); |
|
169 User::LeaveIfError(timeoutLex.Val(temp)); // If Val() returns an error the third argument wasn't an integer, which it should have been |
|
170 aArgStruct.iFailHow = static_cast<TCleTestFailHow>(temp); |
|
171 } |
|
172 DEBUGPRINT2A("Failure mode: %d", aArgStruct.iFailHow); |
|
173 } |