|
1 // Copyright (c) 2007-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 #ifndef __TESTSCRIPTS_H__ |
|
17 #define __TESTSCRIPTS_H__ |
|
18 |
|
19 #include <e32std.h> |
|
20 #include <e32base.h> |
|
21 #include <f32file.h> |
|
22 #include "httptestutils.h" |
|
23 |
|
24 class CScriptSection; |
|
25 class CScriptSectionItem; |
|
26 |
|
27 _LIT(KScriptPanic, "HTTPTESTSCR"); |
|
28 _LIT(KScriptSectionStart, "["); |
|
29 _LIT(KScriptCRLF, "\r\n"); |
|
30 _LIT(KScriptLF, "\n"); |
|
31 _LIT(KScriptCR, "\r"); |
|
32 _LIT(KScriptItemEnd, "="); |
|
33 _LIT(KDefaults, "Defaults"); |
|
34 _LIT(KDefault1, "Def"); |
|
35 _LIT(KDefault2, "Default"); |
|
36 _LIT(KScriptsSection, "Scripts"); |
|
37 |
|
38 //##ModelId=3C4C4C40007E |
|
39 class CScriptFile : public CBase |
|
40 { |
|
41 public: |
|
42 //##ModelId=3C4C4C400222 |
|
43 IMPORT_C static CScriptFile* NewL(CHTTPTestUtils& aTestUtils, const TDesC& aComponent, const TDesC& aScriptFile); |
|
44 //##ModelId=3C4C4C400237 |
|
45 IMPORT_C static CScriptFile* NewL(CHTTPTestUtils& aTestUtils, const TDesC& aComponent); |
|
46 //##ModelId=3C4C4C400205 |
|
47 IMPORT_C static CScriptFile* NewLC(CHTTPTestUtils& aTestUtils, const TDesC& aComponent, const TDesC& aScriptFile); |
|
48 //##ModelId=3C4C4C400218 |
|
49 IMPORT_C static CScriptFile* NewLC(CHTTPTestUtils& aTestUtils, const TDesC& aComponent); |
|
50 //##ModelId=3C4C4C400204 |
|
51 IMPORT_C ~CScriptFile(); |
|
52 |
|
53 //##ModelId=3C4C4C4001E6 |
|
54 IMPORT_C const TDesC& ItemValue(const TDesC& aSection, const TDesC& aItem, const TDesC& aDefault); |
|
55 //##ModelId=3C4C4C4001F1 |
|
56 IMPORT_C TInt ItemValue(const TDesC& aSection, const TDesC& aItem, const TInt aDefault); |
|
57 |
|
58 //##ModelId=3C4C4C4001C9 |
|
59 IMPORT_C static HBufC* ItemValueLC(CHTTPTestUtils& aTestUtils, const TDesC& aComponent, const TDesC& aScript, const TDesC& aSection, const TDesC& aItem, const TDesC& aDefault); |
|
60 //##ModelId=3C4C4C4001AB |
|
61 IMPORT_C static TInt ItemValueL(CHTTPTestUtils& aTestUtils, const TDesC& aComponent, const TDesC& aScript, const TDesC& aSection, const TDesC& aItem, const TInt aDefault); |
|
62 |
|
63 //##ModelId=3C4C4C4001A0 |
|
64 IMPORT_C void ReadScriptL(const TDesC& aScript); |
|
65 |
|
66 //##ModelId=3C4C4C400198 |
|
67 inline CArrayPtrFlat<CScriptSection>& Sections() const; |
|
68 |
|
69 //##ModelId=3C4C4C40018D |
|
70 IMPORT_C CScriptSection* Section(const TDesC& aSectionName); //return NULL if section not found |
|
71 //##ModelId=3C4C4C400183 |
|
72 inline CScriptSection& SectionL(const TDesC& aSectionName); //leaves with KErrNotFound if section not found |
|
73 //##ModelId=3C4C4C400196 |
|
74 inline CScriptSection& Section(TInt aIndex) const {return *iSections->At(aIndex);} |
|
75 |
|
76 //##ModelId=3C4C4C400164 |
|
77 IMPORT_C static TInt GetNextWord(TLex& aInput, TChar aDelimiter, TInt& aOutput); |
|
78 //##ModelId=3C4C4C400178 |
|
79 IMPORT_C static TInt GetNextWord(TLex& aInput, TChar aDelimiter, TPtrC& aOutput); |
|
80 //##ModelId=3C4C4C400150 |
|
81 IMPORT_C static void ReplaceL(const TDesC& aOld, const TDesC& aNew, HBufC*& rString); |
|
82 //##ModelId=3C4C4C40013D |
|
83 IMPORT_C static HBufC* ReplaceLC(const TDesC& aOld, const TDesC& aNew, const TDesC& aOldString); |
|
84 |
|
85 protected: |
|
86 //##ModelId=3C4C4C400134 |
|
87 CScriptFile(CHTTPTestUtils& aTestUtils); |
|
88 //##ModelId=3C4C4C400132 |
|
89 void ConstructL(const TDesC& aComponent); |
|
90 |
|
91 //##ModelId=3C4C4C4000C6 |
|
92 CArrayPtrFlat<CScriptSection>* iSections; |
|
93 //##ModelId=3C4C4C4000B0 |
|
94 CScriptSection* iLastSection; |
|
95 //##ModelId=3C4C4C40009E |
|
96 CHTTPTestUtils& iTestUtils; |
|
97 //##ModelId=3C4C4C400095 |
|
98 HBufC* iComponent; |
|
99 |
|
100 //##ModelId=3C4C4C40011F |
|
101 TPtrC ParseValue(const TDesC& aText, const TLex& aInput, TInt aCurrentItemStart) const; |
|
102 //##ModelId=3C4C4C40010B |
|
103 void ParseAndSetItemValueL(const TDesC& aText, const TLex& aInput, TInt aCurrentItemStart, CScriptSectionItem*& arCurrentItem); |
|
104 //##ModelId=3C4C4C4000F6 |
|
105 void FoundNewItemL(const TDesC& aText, TLex& arInput, TInt& arCurrentItemStart, CScriptSection& aSection, CScriptSectionItem*& arCurrentItem); |
|
106 //##ModelId=3C4C4C4000EC |
|
107 void CopyInDefaultsL(CScriptSection& aSection, const TDesC& aDefaultFile); |
|
108 |
|
109 //##ModelId=3C4C4C4000E3 |
|
110 HBufC* ReadFileLC(const TDesC& aScript) const; |
|
111 //##ModelId=3C4C4C4000CF |
|
112 HBufC8* ReadFileL(const TDesC& aFile) const; |
|
113 |
|
114 void ParseScriptSectionsL(const TDesC& aScript, TInt aInsertIndex); |
|
115 void ParseEmbeddedScriptsL(CScriptSection& aSection, TInt aInsertIndex); |
|
116 }; |
|
117 |
|
118 //##ModelId=3C4C4C4302C7 |
|
119 class CScriptSection : public CBase |
|
120 { |
|
121 friend class CScriptFile; |
|
122 |
|
123 public: |
|
124 //##ModelId=3C4C4C4303C1 |
|
125 IMPORT_C static CScriptSection* NewLC(const TDesC& aSectionName); |
|
126 //##ModelId=3C4C4C4303CC |
|
127 IMPORT_C static CScriptSection* NewLC(const TDesC& aSectionName, CScriptSection& aDefaults); |
|
128 //##ModelId=3C4C4C4303B8 |
|
129 IMPORT_C ~CScriptSection(); |
|
130 |
|
131 //##ModelId=3C4C4C4303B7 |
|
132 inline const TDesC& SectionName() const; |
|
133 |
|
134 //##ModelId=3C4C4C4303A4 |
|
135 IMPORT_C CScriptSectionItem* Item(const TDesC& aItem); //return NULL if the item does not exist |
|
136 //##ModelId=3C4C4C43039A |
|
137 inline CScriptSectionItem& ItemL(const TDesC& aItem); //leaves with KErrNotFound if the item does not exist |
|
138 |
|
139 //##ModelId=3C4C4C430385 |
|
140 IMPORT_C const TDesC& ItemValue(const TDesC& aItem, const TDesC& aDefault); |
|
141 //##ModelId=3C4C4C43038F |
|
142 IMPORT_C TInt ItemValue(const TDesC& aItem, TInt aDefault); |
|
143 |
|
144 //##ModelId=3C4C4C430371 |
|
145 IMPORT_C CScriptSectionItem& AddItemL(const TDesC& aItem, const TDesC& aValue); |
|
146 //##ModelId=3C4C4C430367 |
|
147 IMPORT_C void AddItemIfNotExistL(const TDesC& aItem, const TDesC& aValue); |
|
148 //##ModelId=3C4C4C430353 |
|
149 IMPORT_C CScriptSectionItem& ReplaceItemL(const TDesC& aItem, const TDesC& aValue); |
|
150 //##ModelId=3C4C4C430349 |
|
151 IMPORT_C void DeleteItemsL(const TDesC& aItem); |
|
152 |
|
153 //##ModelId=3C4C4C430341 |
|
154 inline CArrayPtrFlat<CScriptSectionItem>& Items() const {return *iItems;} |
|
155 //##ModelId=3C4C4C4303AD |
|
156 inline CScriptSectionItem& Item(TInt aIndex) const {return *iItems->At(aIndex);} |
|
157 |
|
158 //##ModelId=3C4C4C43033F |
|
159 inline void SetDefaultsL(CScriptSection& aDefaults); |
|
160 //##ModelId=3C4C4C430336 |
|
161 inline CScriptSection* Defaults() const {return iDefaults;} |
|
162 |
|
163 //##ModelId=3C4C4C430335 |
|
164 IMPORT_C CScriptSection* CopyLC(); |
|
165 |
|
166 private: |
|
167 //##ModelId=3C4C4C43032B |
|
168 void ConstructL(const TDesC& aSectionName); |
|
169 //##ModelId=3C4C4C430322 |
|
170 CScriptSection(); |
|
171 //##ModelId=3C4C4C430319 |
|
172 CArrayPtrFlat<CScriptSectionItem>* iItems; |
|
173 //##ModelId=3C4C4C4302FB |
|
174 HBufC* iSectionName; |
|
175 //##ModelId=3C4C4C4302EF |
|
176 CScriptSectionItem* iLastItem; |
|
177 //##ModelId=3C4C4C4302DE |
|
178 CScriptSection* iDefaults; |
|
179 }; |
|
180 |
|
181 //##ModelId=3C4C4C3F022B |
|
182 class CScriptSectionItem : public CBase |
|
183 { |
|
184 friend class CScriptSection; |
|
185 friend class CScriptItem; |
|
186 |
|
187 public: |
|
188 //##ModelId=3C4C4C3F027C |
|
189 IMPORT_C static CScriptSectionItem* NewLC(CScriptSection& aParent, const TDesC& aItem, const TDesC& aValue); |
|
190 //##ModelId=3C4C4C3F027B |
|
191 inline CScriptSectionItem* CopyLC(); |
|
192 |
|
193 //##ModelId=3C4C4C3F0273 |
|
194 IMPORT_C ~CScriptSectionItem(); |
|
195 //##ModelId=3C4C4C3F0255 |
|
196 HBufC* iValue; |
|
197 //##ModelId=3C4C4C3F0272 |
|
198 inline const TDesC& Item() const; |
|
199 //##ModelId=3C4C4C3F0271 |
|
200 inline const TDesC& Value() const; |
|
201 |
|
202 //##ModelId=3C4C4C3F024B |
|
203 CScriptSection& iParent; |
|
204 |
|
205 private: |
|
206 //##ModelId=3C4C4C3F0268 |
|
207 CScriptSectionItem(CScriptSection& aParent); |
|
208 //##ModelId=3C4C4C3F025D |
|
209 void ConstructL(const TDesC& aItem, const TDesC& aValue); |
|
210 //##ModelId=3C4C4C3F0242 |
|
211 HBufC* iItem; |
|
212 }; |
|
213 |
|
214 #include "TestScripts.inl" |
|
215 |
|
216 #endif // __TESTSCRIPTS_H__ |
|
217 |