0
|
1 |
// Copyright (c) 1996-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 the License "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 |
// f32test\math\t_gen32.cpp
|
|
15 |
// Generates files to be used in testing whether arithmetic in TReal32 gives
|
|
16 |
// exactly the same results using the MSDEV complier as on the rack.
|
|
17 |
//
|
|
18 |
//
|
|
19 |
|
|
20 |
#include <f32file.h>
|
|
21 |
#include <e32svr.h>
|
|
22 |
#include "t_math.h"
|
|
23 |
#include "../server/t_server.h"
|
|
24 |
|
|
25 |
#if defined(__VC32__)
|
|
26 |
//
|
|
27 |
// Some symbols generated by the VC++ compiler for floating point stuff.
|
|
28 |
//
|
|
29 |
extern "C" {
|
|
30 |
GLDEF_D TInt _adj_fdiv_m32;
|
|
31 |
}
|
|
32 |
#endif
|
|
33 |
|
|
34 |
GLDEF_D RTest test(_L("T_GEN32"));
|
|
35 |
|
|
36 |
LOCAL_D RFile f;
|
|
37 |
LOCAL_D const TFileName fileName32 = _L("T_REAL32.H");
|
|
38 |
|
|
39 |
LOCAL_D const TFileName pathName = _L("C:\\E32-MATH\\");
|
|
40 |
LOCAL_D TBuf<0x100> buf;
|
|
41 |
LOCAL_D TBuf8<0x100> buf8;
|
|
42 |
|
|
43 |
// Data for tests from T_R32DTA.cpp
|
|
44 |
GLREF_D TReal32 addInput[];
|
|
45 |
GLREF_D TReal32 subInput[];
|
|
46 |
GLREF_D TReal32 multInput[];
|
|
47 |
GLREF_D TReal32 divInput[];
|
|
48 |
//GLREF_D TApprox32 subApprox[];
|
|
49 |
GLREF_D TReal32 unaryInput[];
|
|
50 |
GLREF_D TReal32 incDecInput[];
|
|
51 |
GLREF_D TInt sizeAdd;
|
|
52 |
GLREF_D TInt sizeSub;
|
|
53 |
GLREF_D TInt sizeMult;
|
|
54 |
GLREF_D TInt sizeDiv;
|
|
55 |
//GLREF_D TInt sizeSubApprox;
|
|
56 |
GLREF_D TInt sizeUnary;
|
|
57 |
GLREF_D TInt sizeIncDec;
|
|
58 |
|
|
59 |
LOCAL_C void appendStart()
|
|
60 |
{
|
|
61 |
f.Write(_L8("// Generated by \\E32\\TMATH\\T_GEN32.MAK\n\n"));
|
|
62 |
f.Write(_L8("#include <e32std.h>\n\n"));
|
|
63 |
f.Write(_L8("#if defined(__WINS__)\n#include \"t_vals.hwg\"\n"));
|
|
64 |
f.Write(_L8("#else\n#include \"t_vals.hag\"\n#endif\n"));
|
|
65 |
}
|
|
66 |
|
|
67 |
LOCAL_C void appendArrayName32(TPtrC aName)
|
|
68 |
{
|
|
69 |
buf=_L("");
|
|
70 |
buf.AppendFormat(_L("const TInt32x %S[] = \n{\n"),&aName);
|
|
71 |
buf8.Copy(buf);
|
|
72 |
f.Write(buf8);
|
|
73 |
}
|
|
74 |
|
|
75 |
LOCAL_C void appendValue32(TReal32* aVal)
|
|
76 |
{
|
|
77 |
buf=_L("");
|
|
78 |
buf.AppendFormat(_L(" TInt32x(0x%x),\n"),*(TUint32*)aVal);
|
|
79 |
buf8.Copy(buf);
|
|
80 |
f.Write(buf8);
|
|
81 |
}
|
|
82 |
|
|
83 |
LOCAL_C void appendArrayTerm()
|
|
84 |
{
|
|
85 |
buf8=_L8("};\n\n");
|
|
86 |
f.Write(buf8);
|
|
87 |
}
|
|
88 |
|
|
89 |
LOCAL_C void createAddArray()
|
|
90 |
//
|
|
91 |
// Writes an array of results of additions to the header file
|
|
92 |
//
|
|
93 |
{
|
|
94 |
TInt ii;
|
|
95 |
TReal32 ff;
|
|
96 |
|
|
97 |
appendArrayName32(_L("addArray"));
|
|
98 |
for (ii=0; ii<sizeAdd-1; ii++)
|
|
99 |
{
|
|
100 |
ff=addInput[ii]+addInput[ii+1];
|
|
101 |
appendValue32(&ff);
|
|
102 |
}
|
|
103 |
appendArrayTerm();
|
|
104 |
}
|
|
105 |
|
|
106 |
LOCAL_C void createSubArray()
|
|
107 |
//
|
|
108 |
// Writes an array of results of subtractions to the header file
|
|
109 |
//
|
|
110 |
{
|
|
111 |
TInt ii;
|
|
112 |
TReal32 ff;
|
|
113 |
|
|
114 |
appendArrayName32(_L("subArray"));
|
|
115 |
for (ii=0; ii<sizeSub-1; ii++)
|
|
116 |
{
|
|
117 |
ff=subInput[ii]-subInput[ii+1];
|
|
118 |
appendValue32(&ff);
|
|
119 |
}
|
|
120 |
appendArrayTerm();
|
|
121 |
|
|
122 |
/*
|
|
123 |
appendArrayName32(_L("subApproxArray"));
|
|
124 |
for (ii=0; ii<sizeSubApprox; ii++)
|
|
125 |
{
|
|
126 |
ff=subApprox[ii].f-subApprox[ii].g;
|
|
127 |
appendValue32(&ff);
|
|
128 |
}
|
|
129 |
appendArrayTerm();
|
|
130 |
*/
|
|
131 |
}
|
|
132 |
|
|
133 |
LOCAL_C void createMultArray()
|
|
134 |
//
|
|
135 |
// Writes an array of results of multiplications to the header file
|
|
136 |
//
|
|
137 |
{
|
|
138 |
TInt ii;
|
|
139 |
TReal32 ff;
|
|
140 |
|
|
141 |
appendArrayName32(_L("multArray"));
|
|
142 |
for (ii=0; ii<sizeMult-1; ii++)
|
|
143 |
{
|
|
144 |
ff=multInput[ii]*multInput[ii+1];
|
|
145 |
appendValue32(&ff);
|
|
146 |
}
|
|
147 |
appendArrayTerm();
|
|
148 |
}
|
|
149 |
|
|
150 |
LOCAL_C void createDivArray()
|
|
151 |
//
|
|
152 |
// Writes an array of results of divisions to the header file
|
|
153 |
//
|
|
154 |
{
|
|
155 |
TInt ii;
|
|
156 |
TReal32 ff;
|
|
157 |
|
|
158 |
appendArrayName32(_L("divArray"));
|
|
159 |
for (ii=0; ii<sizeDiv-1; ii++)
|
|
160 |
{
|
|
161 |
if (divInput[ii+1]!=0)
|
|
162 |
{
|
|
163 |
ff=divInput[ii]/divInput[ii+1];
|
|
164 |
appendValue32(&ff);
|
|
165 |
}
|
|
166 |
}
|
|
167 |
appendArrayTerm();
|
|
168 |
}
|
|
169 |
|
|
170 |
LOCAL_C void createUnaryArray()
|
|
171 |
//
|
|
172 |
// Writes an array of results of unary operations to the header file
|
|
173 |
//
|
|
174 |
{
|
|
175 |
TReal32 f;
|
|
176 |
|
|
177 |
appendArrayName32(_L("unaryArray"));
|
|
178 |
for (TInt ii=0; ii<sizeUnary; ii++)
|
|
179 |
{
|
|
180 |
f=-unaryInput[ii];
|
|
181 |
appendValue32(&f);
|
|
182 |
}
|
|
183 |
appendArrayTerm();
|
|
184 |
}
|
|
185 |
|
|
186 |
LOCAL_C void createIncDecArrays()
|
|
187 |
//
|
|
188 |
// Writes an array of results of pre and post increment and decrement operations to the
|
|
189 |
// header file
|
|
190 |
//
|
|
191 |
{
|
|
192 |
TInt ii;
|
|
193 |
TReal32 f;
|
|
194 |
|
|
195 |
appendArrayName32(_L("preIncArray1"));
|
|
196 |
for (ii=0; ii<sizeIncDec; ii++)
|
|
197 |
{
|
|
198 |
f=incDecInput[ii];
|
|
199 |
++f;
|
|
200 |
appendValue32(&f);
|
|
201 |
}
|
|
202 |
appendArrayTerm();
|
|
203 |
|
|
204 |
appendArrayName32(_L("preIncArray2"));
|
|
205 |
for (ii=0; ii<sizeIncDec; ii++)
|
|
206 |
{
|
|
207 |
f=incDecInput[ii];
|
|
208 |
++f;
|
|
209 |
++f;
|
|
210 |
appendValue32(&f);
|
|
211 |
}
|
|
212 |
appendArrayTerm();
|
|
213 |
|
|
214 |
appendArrayName32(_L("preDecArray1"));
|
|
215 |
for (ii=0; ii<sizeIncDec; ii++)
|
|
216 |
{
|
|
217 |
f=incDecInput[ii];
|
|
218 |
--f;
|
|
219 |
appendValue32(&f);
|
|
220 |
}
|
|
221 |
appendArrayTerm();
|
|
222 |
|
|
223 |
appendArrayName32(_L("preDecArray2"));
|
|
224 |
for (ii=0; ii<sizeIncDec; ii++)
|
|
225 |
{
|
|
226 |
f=incDecInput[ii];
|
|
227 |
--f;
|
|
228 |
--f;
|
|
229 |
appendValue32(&f);
|
|
230 |
}
|
|
231 |
appendArrayTerm();
|
|
232 |
|
|
233 |
appendArrayName32(_L("postIncArray1"));
|
|
234 |
for (ii=0; ii<sizeIncDec; ii++)
|
|
235 |
{
|
|
236 |
f=incDecInput[ii];
|
|
237 |
f++;
|
|
238 |
appendValue32(&f);
|
|
239 |
}
|
|
240 |
appendArrayTerm();
|
|
241 |
|
|
242 |
appendArrayName32(_L("postIncArray2"));
|
|
243 |
for (ii=0; ii<sizeIncDec; ii++)
|
|
244 |
{
|
|
245 |
f=incDecInput[ii];
|
|
246 |
f++;
|
|
247 |
f++;
|
|
248 |
appendValue32(&f);
|
|
249 |
}
|
|
250 |
appendArrayTerm();
|
|
251 |
|
|
252 |
appendArrayName32(_L("postDecArray1"));
|
|
253 |
for (ii=0; ii<sizeIncDec; ii++)
|
|
254 |
{
|
|
255 |
f=incDecInput[ii];
|
|
256 |
f--;
|
|
257 |
appendValue32(&f);
|
|
258 |
}
|
|
259 |
appendArrayTerm();
|
|
260 |
|
|
261 |
appendArrayName32(_L("postDecArray2"));
|
|
262 |
for (ii=0; ii<sizeIncDec; ii++)
|
|
263 |
{
|
|
264 |
f=incDecInput[ii];
|
|
265 |
f--;
|
|
266 |
f--;
|
|
267 |
appendValue32(&f);
|
|
268 |
}
|
|
269 |
appendArrayTerm();
|
|
270 |
}
|
|
271 |
|
|
272 |
LOCAL_C void createArrays()
|
|
273 |
//
|
|
274 |
// Create and append to header file all arrays required for T_R32.CPP tests
|
|
275 |
//
|
|
276 |
{
|
|
277 |
createAddArray();
|
|
278 |
createSubArray();
|
|
279 |
createMultArray();
|
|
280 |
createDivArray();
|
|
281 |
createUnaryArray();
|
|
282 |
createIncDecArrays();
|
|
283 |
}
|
|
284 |
|
|
285 |
GLDEF_C void CallTestsL(void)
|
|
286 |
//
|
|
287 |
// Generate TReal32s (and special values if required) and write to header files
|
|
288 |
//
|
|
289 |
{
|
|
290 |
|
|
291 |
test.Title();
|
|
292 |
|
|
293 |
TFileName msg;
|
|
294 |
msg=_L("Generating Maths constants to header files:\n ");
|
|
295 |
msg+=pathName;
|
|
296 |
msg+=fileName32;
|
|
297 |
test.Start(msg);
|
|
298 |
|
|
299 |
test.Next(_L("Making directory"));
|
|
300 |
TInt r=TheFs.MkDirAll(pathName);
|
|
301 |
test(r==KErrNone || r==KErrAlreadyExists);
|
|
302 |
test(TheFs.SetSessionPath(pathName)==KErrNone);
|
|
303 |
|
|
304 |
test(f.Replace(TheFs,fileName32,EFileWrite)==KErrNone);
|
|
305 |
test.Next(_L("Generating TReal32s"));
|
|
306 |
appendStart();
|
|
307 |
createArrays();
|
|
308 |
f.Close();
|
|
309 |
|
|
310 |
test.End();
|
|
311 |
|
|
312 |
return;
|
|
313 |
}
|