|
1 /* |
|
2 * Copyright (c) 2002-2004 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 |
|
21 // disable "identifier was truncated to '255' characters in the browser information" warning |
|
22 #pragma warning (disable:4786) |
|
23 |
|
24 #include "MakeLayConvTest.h" |
|
25 #include "LayoutCompilerErr.h" |
|
26 #include "LayoutParse.h" |
|
27 #include "Lay2Cdl.h" |
|
28 #include "CodeGenConsts.h" |
|
29 #include <fstream> |
|
30 #include <algorithm> |
|
31 #include <iostream> |
|
32 using namespace std; |
|
33 using namespace CdlCompilerToolkit; |
|
34 |
|
35 typedef LayoutProcessArgsErr<MakeLayoutConvTest> MakeLayoutConvTestArgsErr; |
|
36 |
|
37 |
|
38 |
|
39 int MakeLayoutConvTest::Process(const vector<string>& args) |
|
40 { |
|
41 if (args.size() != 4) |
|
42 throw MakeLayoutConvTestArgsErr(); |
|
43 |
|
44 string cdlName = args[2]; |
|
45 CCdlTkCdlFileParser parser(cdlName); |
|
46 auto_ptr<CCdlTkInterface> iface(parser.LoadAndParse(true)); |
|
47 |
|
48 string layoutName = args[3]; |
|
49 auto_ptr<TLayParseLayout> layoutParse = TLayParseLayout::Parse(layoutName); |
|
50 |
|
51 MakeLayoutConvTest process(*iface, *layoutParse); |
|
52 process.RunProcess(); |
|
53 |
|
54 return 0; |
|
55 } |
|
56 |
|
57 void MakeLayoutConvTest::ShowHelp(ostream& stream) |
|
58 { |
|
59 stream << "MakeLayConvTest <cdlName> <layoutName>" << endl; |
|
60 stream << " Creates layout conversion test code." << endl; |
|
61 } |
|
62 |
|
63 MakeLayoutConvTest::MakeLayoutConvTest(CCdlTkInterface& aInterface, TLayout& aLayout) |
|
64 : iInterface(aInterface), iLayout(aLayout) |
|
65 { |
|
66 } |
|
67 |
|
68 MakeLayoutConvTest::~MakeLayoutConvTest() |
|
69 { |
|
70 } |
|
71 |
|
72 void MakeLayoutConvTest::RunProcess() |
|
73 { |
|
74 InitFiles(); |
|
75 |
|
76 for (TLayout::iterator pTab = iLayout.begin(); pTab != iLayout.end(); ++pTab) |
|
77 { |
|
78 AddTableToTest(**pTab); |
|
79 } |
|
80 |
|
81 CompleteFiles(); |
|
82 WriteTestFiles(); |
|
83 } |
|
84 |
|
85 void MakeLayoutConvTest::AddTableToTest(TLayoutTable& aTable) |
|
86 { |
|
87 for (TLayoutTable::iterator pLine = aTable.begin(); pLine != aTable.end(); ++pLine) |
|
88 { |
|
89 TLayoutLine& line = **pLine; |
|
90 AddLineToTest(line); |
|
91 } |
|
92 |
|
93 } |
|
94 |
|
95 void MakeLayoutConvTest::AddLineToTest(TLayoutLine& aLine) |
|
96 { |
|
97 string apiName = LayoutToCdl::LineApiName(aLine); |
|
98 const CCdlTkFunctionApi* api = FindApi(apiName); |
|
99 if (!api) |
|
100 return; |
|
101 |
|
102 AddTest(aLine, *api); |
|
103 if (aLine["B"].size() > 1) |
|
104 { |
|
105 apiName = KFuncMultiline + apiName; |
|
106 api = FindApi(apiName); |
|
107 if (api) |
|
108 { |
|
109 AddTest(aLine, *api); |
|
110 } |
|
111 } |
|
112 } |
|
113 |
|
114 void MakeLayoutConvTest::AddTest(TLayoutLine& aLine, const CCdlTkFunctionApi& aApi) |
|
115 { |
|
116 AddTestToOldH(aLine, aApi); |
|
117 AddTestToOldCpp(aLine, aApi); |
|
118 AddTestFunc(aLine, aApi); |
|
119 } |
|
120 |
|
121 const CCdlTkFunctionApi* MakeLayoutConvTest::FindApi(const string& aName) |
|
122 { |
|
123 return &iInterface.ApiList().Find(aName)->AsFunc(); |
|
124 } |
|
125 |
|
126 void MakeLayoutConvTest::WriteTestFiles() |
|
127 { |
|
128 WriteTestFile("OldLayout.h", iOldH); |
|
129 WriteTestFile("OldLayout.cpp", iOldCpp); |
|
130 WriteTestFile("TestLayout.cpp", iFuncs + iTests); |
|
131 } |
|
132 |
|
133 void MakeLayoutConvTest::WriteTestFile(const string& aFileName, const string& iContent) |
|
134 { |
|
135 CCdlTkFileCleanup tempFile; |
|
136 ofstream stream; |
|
137 CdlTkUtil::OpenTempOutput(stream, tempFile); |
|
138 stream << iContent; |
|
139 stream.close(); |
|
140 CdlTkUtil::ExportFileIfWritable(tempFile, CdlTkUtil::ResolvePath(CdlTkUtil::OutputPath(), aFileName)); |
|
141 } |
|
142 |
|
143 void MakeLayoutConvTest::AddTestToOldH(TLayoutLine& aLine, const CCdlTkFunctionApi& aApi) |
|
144 { |
|
145 string f = OldFuncSig(aLine, aApi) + ";\n"; |
|
146 CdlTkUtil::AppendString(iOldH, f); |
|
147 } |
|
148 |
|
149 const string KOldFunc = "\ |
|
150 $TYPE Old_$NAME$PARAMLIST\n\ |
|
151 \t{\n\ |
|
152 \treturn $LAGNAME$PARAMS;\n\ |
|
153 \t}\n\n"; |
|
154 |
|
155 void MakeLayoutConvTest::AddTestToOldCpp(TLayoutLine& aLine, const CCdlTkFunctionApi& aApi) |
|
156 { |
|
157 string lagName = "AKN_LAYOUT_WINDOW_" + aApi.Name(); |
|
158 if (aApi.ReturnType() == KTypeTextLineLayout) |
|
159 lagName = "AKN_LAYOUT_TEXT_" + aApi.Name(); |
|
160 else if (aApi.ReturnType() == KTypeMultiLineTextLayout) |
|
161 lagName = "AKN_LAYOUT_MULTILINE_TEXT_" + aApi.Name().substr(KFuncMultiline.length()); // remove "Multiline_" |
|
162 |
|
163 string params = aApi.ParamNameList(); |
|
164 if (!params.empty()) |
|
165 params = string("(") + params + ")"; |
|
166 |
|
167 CdlTkUtil::CReplaceSet rep; |
|
168 rep.Add("$TYPE", aApi.ReturnType()); |
|
169 rep.Add("$NAME", aApi.Name()); |
|
170 rep.Add("$PARAMLIST", aApi.ParamsTypeAndNameList()); |
|
171 rep.Add("$LAGNAME", lagName); |
|
172 rep.Add("$PARAMS", params); |
|
173 CdlTkUtil::AppendString(iOldCpp, CdlTkUtil::MultiReplace(rep, KOldFunc)); |
|
174 } |
|
175 |
|
176 const string KTestFunc = "\ |
|
177 void Test_$NAME(const AknLayout::CInstance& aInst)\n\ |
|
178 \t{\n\ |
|
179 $PARENT\ |
|
180 $LOOPS_START\ |
|
181 $INDENTCheckLayout(aInst.$NAME($PARAMS), Old_$NAME($PARAMS));\n\ |
|
182 $LOOPS_END\ |
|
183 \t}\n\n"; |
|
184 |
|
185 const string KTestLoop = "$INDENTfor (" + KTypeInt + " $PARAM_NAME = 0; $PARAM_NAME < $MAX; $PARAM_NAME++)\n$INDENT\t{\n"; |
|
186 |
|
187 void MakeLayoutConvTest::AddTestFunc(TLayoutLine& aLine, const CCdlTkFunctionApi& aApi) |
|
188 { |
|
189 string testCall = string("\tTest_") + aApi.Name() + "(aInst);\n"; |
|
190 CdlTkUtil::AppendString(iTests, testCall); |
|
191 string indent = "\t"; |
|
192 |
|
193 string loopStart; |
|
194 string loopEnd; |
|
195 const CCdlTkApiParams& params = aApi.Params(); |
|
196 for (CCdlTkApiParams::const_iterator pParam = params.begin(); pParam != params.end(); ++pParam) |
|
197 { |
|
198 if (pParam->Type() == KTypeInt) |
|
199 { |
|
200 string paramName = pParam->Name(); |
|
201 int max = 0; |
|
202 for (TLayoutLine::iterator pVal = aLine.begin(); pVal != aLine.end(); ++pVal) |
|
203 { |
|
204 if (pVal->second.ParamName() == paramName) |
|
205 { |
|
206 max = pVal->second.size(); |
|
207 break; |
|
208 } |
|
209 } |
|
210 |
|
211 CdlTkUtil::CReplaceSet rep; |
|
212 rep.Add("$PARAM_NAME", paramName); |
|
213 rep.Add("$MAX", CdlTkUtil::IntToString(max)); |
|
214 rep.Add("$INDENT", indent); |
|
215 CdlTkUtil::AppendString(loopStart, CdlTkUtil::MultiReplace(rep, KTestLoop)); |
|
216 indent += "\t"; |
|
217 loopEnd = indent + "}\n" + loopEnd; |
|
218 } |
|
219 } |
|
220 |
|
221 CdlTkUtil::CReplaceSet rep; |
|
222 rep.Add("$NAME", aApi.Name()); |
|
223 rep.Add("$LOOPS_START", loopStart); |
|
224 rep.Add("$PARAMS", aApi.ParamNameList()); |
|
225 rep.Add("$LOOPS_END", loopEnd); |
|
226 rep.Add("$INDENT", indent); |
|
227 rep.Add("$PARENT", aLine.iNeedsP ? "\tTRect aParentRect(0,0,176,208);\n" : ""); |
|
228 CdlTkUtil::AppendString(iFuncs, CdlTkUtil::MultiReplace(rep, KTestFunc)); |
|
229 } |
|
230 |
|
231 const string KOldFuncName = "Old_$NAME"; |
|
232 const string KFuncSig = "$TYPE $NAME$PARAMS"; |
|
233 |
|
234 string MakeLayoutConvTest::OldFuncSig(TLayoutLine& aLine, const CCdlTkFunctionApi& aApi) |
|
235 { |
|
236 string type = aApi.ReturnType(); |
|
237 string name = CdlTkUtil::Replace("$NAME", aApi.Name(), KOldFuncName); |
|
238 string params = aApi.ParamsTypeAndNameList(); |
|
239 |
|
240 CdlTkUtil::CReplaceSet rep; |
|
241 rep.Add("$TYPE", type); |
|
242 rep.Add("$NAME", name); |
|
243 rep.Add("$PARAMS", params); |
|
244 return CdlTkUtil::MultiReplace(rep, KFuncSig); |
|
245 } |
|
246 |
|
247 void MakeLayoutConvTest::InitFiles() |
|
248 { |
|
249 iOldH = ""; |
|
250 |
|
251 iOldCpp = "\ |
|
252 #include <e32std.h>\n\ |
|
253 #include <OldLayout.lag>\n\ |
|
254 #include \"OldLayout.h\"\n\n"; |
|
255 |
|
256 iFuncs = "\ |
|
257 #include \"LayTestUtils.h\"\n\ |
|
258 #include \"OldLayout.h\"\n\n"; |
|
259 |
|
260 iTests = "\ |
|
261 void RunTests(const AknLayout::CInstance& aInst)\n\ |
|
262 \t{\n"; |
|
263 |
|
264 } |
|
265 |
|
266 void MakeLayoutConvTest::CompleteFiles() |
|
267 { |
|
268 iTests += "\t}\n"; |
|
269 } |
|
270 |
|
271 |