|
1 // Copyright (c) 1999-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 TEST_SCRIPTS_H_ |
|
17 #define TEST_SCRIPTS_H_ |
|
18 |
|
19 #include <e32std.h> |
|
20 #include <e32base.h> |
|
21 #include <f32file.h> |
|
22 #include "msvtestutilsbase.h" |
|
23 |
|
24 class CScriptSection; |
|
25 class CScriptSectionItem; |
|
26 |
|
27 _LIT(KScriptPanic, "MSG-TEST-SCRIPT"); |
|
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 |
|
37 class CScriptFile : public CBase |
|
38 { |
|
39 public: |
|
40 IMPORT_C static CScriptFile* NewLC(CTestUtils& aTestUtils, const TDesC& aComponent, const TDesC& aScriptFile); |
|
41 IMPORT_C static CScriptFile* NewLC(CTestUtils& aTestUtils, const TDesC& aComponent); |
|
42 IMPORT_C ~CScriptFile(); |
|
43 |
|
44 IMPORT_C const TDesC& ItemValue(const TDesC& aSection, const TDesC& aItem, const TDesC& aDefault); |
|
45 IMPORT_C TInt ItemValue(const TDesC& aSection, const TDesC& aItem, const TInt aDefault); |
|
46 |
|
47 IMPORT_C static HBufC* ItemValueLC(CTestUtils& aTestUtils, const TDesC& aComponent, const TDesC& aScript, const TDesC& aSection, const TDesC& aItem, const TDesC& aDefault); |
|
48 IMPORT_C static TInt ItemValueL(CTestUtils& aTestUtils, const TDesC& aComponent, const TDesC& aScript, const TDesC& aSection, const TDesC& aItem, const TInt aDefault); |
|
49 |
|
50 IMPORT_C void ReadScriptL(const TDesC& aScript); |
|
51 |
|
52 inline CArrayPtrFlat<CScriptSection>& Sections() const; |
|
53 |
|
54 IMPORT_C CScriptSection* Section(const TDesC& aSectionName); //return NULL if section not found |
|
55 inline CScriptSection& SectionL(const TDesC& aSectionName); //leaves with KErrNotFound if section not found |
|
56 inline CScriptSection& Section(TInt aIndex) const {return *iSections->At(aIndex);} |
|
57 |
|
58 IMPORT_C static TInt GetNextWord(TLex& aInput, TChar aDelimiter, TInt& aOutput); |
|
59 IMPORT_C static TInt GetNextWord(TLex& aInput, TChar aDelimiter, TPtrC& aOutput); |
|
60 IMPORT_C static void ReplaceL(const TDesC& aOld, const TDesC& aNew, HBufC*& rString); |
|
61 IMPORT_C static HBufC* ReplaceLC(const TDesC& aOld, const TDesC& aNew, const TDesC& aOldString); |
|
62 |
|
63 protected: |
|
64 CScriptFile(CTestUtils& aTestUtils); |
|
65 void ConstructL(const TDesC& aComponent); |
|
66 |
|
67 CArrayPtrFlat<CScriptSection>* iSections; |
|
68 CScriptSection* iLastSection; |
|
69 CTestUtils& iTestUtils; |
|
70 HBufC* iComponent; |
|
71 |
|
72 TPtrC ParseValue(const TDesC& aText, const TLex& aInput, TInt aCurrentItemStart) const; |
|
73 void ParseAndSetItemValueL(const TDesC& aText, const TLex& aInput, TInt aCurrentItemStart, CScriptSectionItem*& arCurrentItem); |
|
74 void FoundNewItemL(const TDesC& aText, TLex& arInput, TInt& arCurrentItemStart, CScriptSection& aSection, CScriptSectionItem*& arCurrentItem); |
|
75 void CopyInDefaultsL(CScriptSection& aSection, const TDesC& aDefaultFile); |
|
76 |
|
77 HBufC* ReadFileLC(const TDesC& aScript) const; |
|
78 HBufC8* ReadFileL(const TDesC& aFile) const; |
|
79 }; |
|
80 |
|
81 class CScriptSection : public CBase |
|
82 { |
|
83 friend class CScriptFile; |
|
84 |
|
85 public: |
|
86 IMPORT_C static CScriptSection* NewLC(const TDesC& aSectionName); |
|
87 IMPORT_C static CScriptSection* NewLC(const TDesC& aSectionName, CScriptSection& aDefaults); |
|
88 IMPORT_C ~CScriptSection(); |
|
89 |
|
90 inline const TDesC& SectionName() const; |
|
91 |
|
92 IMPORT_C CScriptSectionItem* Item(const TDesC& aItem); //return NULL if the item does not exist |
|
93 inline CScriptSectionItem& ItemL(const TDesC& aItem); //leaves with KErrNotFound if the item does not exist |
|
94 |
|
95 IMPORT_C const TDesC& ItemValue(const TDesC& aItem, const TDesC& aDefault); |
|
96 IMPORT_C TInt ItemValue(const TDesC& aItem, TInt aDefault); |
|
97 |
|
98 IMPORT_C CScriptSectionItem& AddItemL(const TDesC& aItem, const TDesC& aValue); |
|
99 IMPORT_C void AddItemIfNotExistL(const TDesC& aItem, const TDesC& aValue); |
|
100 IMPORT_C CScriptSectionItem& ReplaceItemL(const TDesC& aItem, const TDesC& aValue); |
|
101 IMPORT_C void DeleteItemsL(const TDesC& aItem); |
|
102 |
|
103 inline CArrayPtrFlat<CScriptSectionItem>& Items() const {return *iItems;} |
|
104 inline CScriptSectionItem& Item(TInt aIndex) const {return *iItems->At(aIndex);} |
|
105 |
|
106 inline void SetDefaultsL(CScriptSection& aDefaults); |
|
107 inline CScriptSection* Defaults() const {return iDefaults;} |
|
108 |
|
109 IMPORT_C CScriptSection* CopyLC(); |
|
110 |
|
111 private: |
|
112 void ConstructL(const TDesC& aSectionName); |
|
113 CScriptSection(); |
|
114 CArrayPtrFlat<CScriptSectionItem>* iItems; |
|
115 HBufC* iSectionName; |
|
116 CScriptSectionItem* iLastItem; |
|
117 CScriptSection* iDefaults; |
|
118 }; |
|
119 |
|
120 class CScriptSectionItem : public CBase |
|
121 { |
|
122 friend class CScriptSection; |
|
123 friend class CScriptItem; |
|
124 |
|
125 public: |
|
126 IMPORT_C static CScriptSectionItem* NewLC(CScriptSection& aParent, const TDesC& aItem, const TDesC& aValue); |
|
127 inline CScriptSectionItem* CopyLC(); |
|
128 |
|
129 IMPORT_C ~CScriptSectionItem(); |
|
130 HBufC* iValue; |
|
131 inline const TDesC& Item() const; |
|
132 inline const TDesC& Value() const; |
|
133 |
|
134 CScriptSection& iParent; |
|
135 |
|
136 private: |
|
137 CScriptSectionItem(CScriptSection& aParent); |
|
138 void ConstructL(const TDesC& aItem, const TDesC& aValue); |
|
139 HBufC* iItem; |
|
140 }; |
|
141 |
|
142 #include "msgtestscripts.inl" |
|
143 |
|
144 #endif |