|
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 testscriptparser.cpp |
|
18 @internalComponent |
|
19 */ |
|
20 |
|
21 #include <e32base.h> |
|
22 #include "testscriptparser.h" |
|
23 #include "testlog.h" |
|
24 |
|
25 |
|
26 CTestScriptParser* CTestScriptParser::FactoryLC( TDesC& aFile, CTestLog* aLog) |
|
27 { |
|
28 CTestScriptParser* p = NULL; |
|
29 |
|
30 p = new(ELeave) CTestScriptParser(aFile, aLog); |
|
31 |
|
32 CleanupStack::PushL(p); |
|
33 return p; |
|
34 } |
|
35 |
|
36 |
|
37 CTestScriptParser::CTestScriptParser(TDesC& aFile, CTestLog* aLog) : |
|
38 iFile(aFile), |
|
39 iLog(aLog), |
|
40 iPtr(NULL, 0) |
|
41 { |
|
42 } |
|
43 |
|
44 /** |
|
45 */ |
|
46 void CTestScriptParser::OpenScriptFileL() |
|
47 { |
|
48 // Connect to file server |
|
49 // |
|
50 TAutoClose<RFs> fs; |
|
51 User::LeaveIfError(fs.iObj.Connect()); |
|
52 fs.PushL(); |
|
53 |
|
54 // Open file |
|
55 // |
|
56 TAutoClose<RFile> file; |
|
57 TInt size; |
|
58 User::LeaveIfError(file.iObj.Open(fs.iObj, iFile, EFileStreamText | EFileRead)); |
|
59 file.PushL(); |
|
60 |
|
61 |
|
62 // Get file size and read in |
|
63 // |
|
64 User::LeaveIfError(file.iObj.Size(size)); |
|
65 TText* data = (TText*)User::AllocL(size); |
|
66 iPtr.Set(data, TUint(size)/sizeof(TText), TUint(size)/sizeof(TText)); |
|
67 TPtr8 dest((TUint8*)data, 0, size); |
|
68 User::LeaveIfError(file.iObj.Read(dest)); |
|
69 TUint8* ptr = (TUint8*)data; |
|
70 |
|
71 // |
|
72 // This is orderred as FEFF assuming the processor is Little Endian |
|
73 // The data in the file is FFFE. PRR 28/9/98 |
|
74 // |
|
75 if(size>=(TInt)sizeof(TText) && iPtr[0]==0xFEFF) |
|
76 { |
|
77 // UNICODE Text file so lose the FFFE |
|
78 Mem::Copy(ptr, ptr+sizeof(TText), size-sizeof(TText)); |
|
79 iPtr.Set(data, TUint(size)/sizeof(TText)-1, TUint(size)/sizeof(TText)-1); |
|
80 } |
|
81 else if(size) |
|
82 { |
|
83 // NON-UNICODE so convert to UNICODE |
|
84 TText* newdata = (TText*)User::AllocL(size*sizeof(TText)); |
|
85 iPtr.Set(newdata, size, size); |
|
86 TInt i; |
|
87 for(i=0 ; i<size ; ++i) |
|
88 { |
|
89 iPtr[i]=ptr[i]; |
|
90 } |
|
91 delete data; |
|
92 } |
|
93 |
|
94 iLex.Assign(iPtr); |
|
95 |
|
96 file.Pop(); |
|
97 fs.Pop(); |
|
98 } |
|
99 |
|
100 /** |
|
101 */ |
|
102 TBool CTestScriptParser::GetNextTestStepL(TScriptAction &runAction, TDes ¶ms) |
|
103 { |
|
104 TBuf<256> stepAction; |
|
105 stepAction.Append(iLex.NextToken()); |
|
106 runAction = ENoAction; |
|
107 |
|
108 if (stepAction.Compare(_L("//")) == 0) |
|
109 { |
|
110 runAction = ENoAction; |
|
111 } |
|
112 else if (stepAction.Compare(_L("RUN_PROGRAM")) == 0) |
|
113 { |
|
114 // Parse the input file and get the command line |
|
115 runAction = ERunProgram; |
|
116 } |
|
117 else if (stepAction.Compare(_L("RUN_TEST_STEP")) == 0) |
|
118 { |
|
119 runAction = ERunTestStep; |
|
120 } |
|
121 else if ((stepAction.Compare(_L("PRINT")) == 0) || |
|
122 (stepAction.Compare(_L("START_TESTCASE")) == 0) || |
|
123 (stepAction.Compare(_L("END_TESTCASE")) == 0)) |
|
124 { |
|
125 runAction = EPrint; |
|
126 } |
|
127 else if (stepAction.Compare(_L("LOAD_SUITE")) == 0) |
|
128 { |
|
129 runAction = ELoadTestSuite; |
|
130 } |
|
131 |
|
132 // Skip past any leading white spaces |
|
133 iLex.SkipSpace(); |
|
134 iLex.Mark(); |
|
135 |
|
136 while(!iLex.Eos()) |
|
137 { |
|
138 TChar peek = iLex.Peek(); |
|
139 |
|
140 // Line is terminated with a carriage return or line feed |
|
141 if((peek == '\n') || (peek == '\r')) |
|
142 { |
|
143 break; |
|
144 } |
|
145 else |
|
146 { |
|
147 iLex.Inc(); |
|
148 } |
|
149 } |
|
150 |
|
151 params.Append(iLex.MarkedToken()); |
|
152 |
|
153 return iLex.Eos(); |
|
154 } |
|
155 |
|
156 |
|
157 void CTestScriptParser::Exit(TInt aErr) |
|
158 { |
|
159 iLog->Msg(_L("Error: Script file [%S] could not be opened"), &iFile); |
|
160 User::Leave(aErr); |
|
161 } |
|
162 |
|
163 |
|
164 //EOF |