|
sl@0
|
1 |
// Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
sl@0
|
2 |
// All rights reserved.
|
|
sl@0
|
3 |
// This component and the accompanying materials are made available
|
|
sl@0
|
4 |
// under the terms of "Eclipse Public License v1.0"
|
|
sl@0
|
5 |
// which accompanies this distribution, and is available
|
|
sl@0
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
sl@0
|
7 |
//
|
|
sl@0
|
8 |
// Initial Contributors:
|
|
sl@0
|
9 |
// Nokia Corporation - initial contribution.
|
|
sl@0
|
10 |
//
|
|
sl@0
|
11 |
// Contributors:
|
|
sl@0
|
12 |
//
|
|
sl@0
|
13 |
// Description:
|
|
sl@0
|
14 |
// Name : twideapisBlocks.cpp
|
|
sl@0
|
15 |
// This material, including documentation and any related
|
|
sl@0
|
16 |
// computer programs, is protected by copyright controlled by
|
|
sl@0
|
17 |
// Nokia Corporation. All rights are reserved. Copying,
|
|
sl@0
|
18 |
// including reproducing, storing, adapting or translating, any
|
|
sl@0
|
19 |
// or all of this material requires the prior written consent of
|
|
sl@0
|
20 |
// Nokia Corporation. This material also contains confidential
|
|
sl@0
|
21 |
// information which may not be disclosed to others without the
|
|
sl@0
|
22 |
// prior written consent of Nokia Corporation.
|
|
sl@0
|
23 |
//
|
|
sl@0
|
24 |
|
|
sl@0
|
25 |
|
|
sl@0
|
26 |
|
|
sl@0
|
27 |
// INCLUDE FILES
|
|
sl@0
|
28 |
#include "twideapis.h"
|
|
sl@0
|
29 |
|
|
sl@0
|
30 |
// -----------------------------------------------------------------------------
|
|
sl@0
|
31 |
//Function Name : wfdopen_ivalm
|
|
sl@0
|
32 |
//API Tested : wfdopen
|
|
sl@0
|
33 |
//TestCase Description: testing the behaviour of wfdopen for invalid modes
|
|
sl@0
|
34 |
// initialized to NULL.
|
|
sl@0
|
35 |
// -----------------------------------------------------------------------------
|
|
sl@0
|
36 |
|
|
sl@0
|
37 |
TInt CTestWideApi::wfdopen_ivalm()
|
|
sl@0
|
38 |
{
|
|
sl@0
|
39 |
TPtrC nameRead;
|
|
sl@0
|
40 |
_LIT( KString, "Parameter1" );
|
|
sl@0
|
41 |
TBool res = GetStringFromConfig(ConfigSection(), KString, nameRead);
|
|
sl@0
|
42 |
if(!res)
|
|
sl@0
|
43 |
{
|
|
sl@0
|
44 |
_LIT(Kerr , "Failed to read string") ;
|
|
sl@0
|
45 |
INFO_PRINTF1(Kerr) ;
|
|
sl@0
|
46 |
return KErrGeneral ;
|
|
sl@0
|
47 |
}
|
|
sl@0
|
48 |
int ret_wmkdir = wmkdir(L"C:\\ggg" , S_IWUSR);
|
|
sl@0
|
49 |
if((errno == EEXIST) || (!ret_wmkdir))
|
|
sl@0
|
50 |
{
|
|
sl@0
|
51 |
TBuf8<100> buf;
|
|
sl@0
|
52 |
|
|
sl@0
|
53 |
int wfd;
|
|
sl@0
|
54 |
buf.Copy(nameRead);
|
|
sl@0
|
55 |
char* filemode = (char*) buf.Ptr();
|
|
sl@0
|
56 |
filemode[buf.Length()]='\0';
|
|
sl@0
|
57 |
wchar_t *dmode = (wchar_t *)malloc(30*sizeof(wchar_t));
|
|
sl@0
|
58 |
if(dmode==NULL)
|
|
sl@0
|
59 |
{
|
|
sl@0
|
60 |
wrmdir(L"C:\\ggg");
|
|
sl@0
|
61 |
return KErrNoMemory;
|
|
sl@0
|
62 |
}
|
|
sl@0
|
63 |
size_t siz = mbstowcs(dmode, filemode, 30);
|
|
sl@0
|
64 |
wunlink(L"C:\\ggg\\lll.txt");
|
|
sl@0
|
65 |
if((wfd=wopen(L"C:\\ggg\\lll.txt", O_WRONLY | O_CREAT | O_TRUNC, 0777))<0)
|
|
sl@0
|
66 |
{
|
|
sl@0
|
67 |
_LIT(Kopen,"Failed to open file");
|
|
sl@0
|
68 |
INFO_PRINTF1(Kopen);
|
|
sl@0
|
69 |
wrmdir(L"C:\\ggg");
|
|
sl@0
|
70 |
free(dmode) ;
|
|
sl@0
|
71 |
return KErrGeneral;
|
|
sl@0
|
72 |
}
|
|
sl@0
|
73 |
else
|
|
sl@0
|
74 |
{
|
|
sl@0
|
75 |
FILE *fp =wfdopen(wfd ,dmode);
|
|
sl@0
|
76 |
if(NULL == fp)
|
|
sl@0
|
77 |
{
|
|
sl@0
|
78 |
_LIT(Kopen,"wfdopen failed");
|
|
sl@0
|
79 |
INFO_PRINTF1(Kopen);
|
|
sl@0
|
80 |
close(wfd);
|
|
sl@0
|
81 |
wunlink(L"C:\\ggg\\lll.txt");
|
|
sl@0
|
82 |
wrmdir(L"C:\\ggg");
|
|
sl@0
|
83 |
free(dmode) ;
|
|
sl@0
|
84 |
return KErrNone;
|
|
sl@0
|
85 |
}
|
|
sl@0
|
86 |
else
|
|
sl@0
|
87 |
{
|
|
sl@0
|
88 |
wunlink(L"C:\\ggg\\lll.txt");
|
|
sl@0
|
89 |
wrmdir(L"C:\\ggg");
|
|
sl@0
|
90 |
free(dmode) ;
|
|
sl@0
|
91 |
return KErrGeneral;
|
|
sl@0
|
92 |
}
|
|
sl@0
|
93 |
}
|
|
sl@0
|
94 |
}
|
|
sl@0
|
95 |
else
|
|
sl@0
|
96 |
{
|
|
sl@0
|
97 |
_LIT(Kerr , "Failed to make dir") ;
|
|
sl@0
|
98 |
INFO_PRINTF1(Kerr) ;
|
|
sl@0
|
99 |
wunlink(L"C:\\ggg\\lll.txt");
|
|
sl@0
|
100 |
wrmdir(L"C:\\ggg");
|
|
sl@0
|
101 |
return KErrGeneral ;
|
|
sl@0
|
102 |
}
|
|
sl@0
|
103 |
}
|
|
sl@0
|
104 |
|
|
sl@0
|
105 |
|
|
sl@0
|
106 |
// -----------------------------------------------------------------------------
|
|
sl@0
|
107 |
//Function Name : wfdopen_val
|
|
sl@0
|
108 |
//API Tested : wfdopen
|
|
sl@0
|
109 |
//TestCase Description: testing the behaviour of wfdopen for valid arguments
|
|
sl@0
|
110 |
// initialized to NULL.
|
|
sl@0
|
111 |
// -----------------------------------------------------------------------------
|
|
sl@0
|
112 |
TInt CTestWideApi::wfdopen_val()
|
|
sl@0
|
113 |
{
|
|
sl@0
|
114 |
TPtrC nameRead;
|
|
sl@0
|
115 |
wchar_t *pathName = NULL;
|
|
sl@0
|
116 |
_LIT( KString, "Parameter1" );
|
|
sl@0
|
117 |
TBool res = GetStringFromConfig(ConfigSection(), KString, nameRead);
|
|
sl@0
|
118 |
if(!res)
|
|
sl@0
|
119 |
{
|
|
sl@0
|
120 |
_LIT(Kerr , "Failed to read string") ;
|
|
sl@0
|
121 |
INFO_PRINTF1(Kerr) ;
|
|
sl@0
|
122 |
return KErrGeneral ;
|
|
sl@0
|
123 |
}
|
|
sl@0
|
124 |
int ret_wmkdir = wmkdir(L"C:\\ggg" , S_IWUSR);
|
|
sl@0
|
125 |
if((errno == EEXIST) || (!ret_wmkdir))
|
|
sl@0
|
126 |
{
|
|
sl@0
|
127 |
TBuf8<100> buf;
|
|
sl@0
|
128 |
int wfd;
|
|
sl@0
|
129 |
FILE *fp;
|
|
sl@0
|
130 |
buf.Copy(nameRead);
|
|
sl@0
|
131 |
char* filename = (char*) buf.Ptr();
|
|
sl@0
|
132 |
filename[buf.Length()]='\0';
|
|
sl@0
|
133 |
pathName = (wchar_t *)malloc(30*sizeof(wchar_t));
|
|
sl@0
|
134 |
if(pathName==NULL)
|
|
sl@0
|
135 |
{
|
|
sl@0
|
136 |
wrmdir(L"C:\\ggg");
|
|
sl@0
|
137 |
return KErrNoMemory;
|
|
sl@0
|
138 |
}
|
|
sl@0
|
139 |
size_t siz = mbstowcs(pathName, filename, 30);
|
|
sl@0
|
140 |
wunlink(pathName) ;
|
|
sl@0
|
141 |
if((wfd=wopen(pathName, O_WRONLY | O_CREAT | O_TRUNC, 0666))<0)
|
|
sl@0
|
142 |
{
|
|
sl@0
|
143 |
_LIT(Kopen,"Failed to open file");
|
|
sl@0
|
144 |
INFO_PRINTF1(Kopen);
|
|
sl@0
|
145 |
wrmdir(L"C:\\ggg");
|
|
sl@0
|
146 |
free(pathName);
|
|
sl@0
|
147 |
return KErrGeneral;
|
|
sl@0
|
148 |
}
|
|
sl@0
|
149 |
else
|
|
sl@0
|
150 |
{
|
|
sl@0
|
151 |
if(NULL == (fp =wfdopen(wfd ,L"w")))
|
|
sl@0
|
152 |
{
|
|
sl@0
|
153 |
_LIT(Kopen,"wfdopen failed");
|
|
sl@0
|
154 |
INFO_PRINTF1(Kopen);
|
|
sl@0
|
155 |
wrmdir(L"C:\\ggg");
|
|
sl@0
|
156 |
free(pathName);
|
|
sl@0
|
157 |
return KErrGeneral;
|
|
sl@0
|
158 |
}
|
|
sl@0
|
159 |
char *buffer="Writing to the file";
|
|
sl@0
|
160 |
size_t size=strlen(buffer);
|
|
sl@0
|
161 |
if(size!=(fwrite(buffer,1,size,fp)))
|
|
sl@0
|
162 |
{
|
|
sl@0
|
163 |
_LIT(Kopen,"fwrite failed");
|
|
sl@0
|
164 |
INFO_PRINTF1(Kopen);
|
|
sl@0
|
165 |
wrmdir(L"C:\\ggg");
|
|
sl@0
|
166 |
free(pathName);
|
|
sl@0
|
167 |
return KErrGeneral;
|
|
sl@0
|
168 |
}
|
|
sl@0
|
169 |
}
|
|
sl@0
|
170 |
fclose(fp);
|
|
sl@0
|
171 |
wunlink(pathName);
|
|
sl@0
|
172 |
wrmdir(L"C:\\ggg");
|
|
sl@0
|
173 |
free(pathName);
|
|
sl@0
|
174 |
return KErrNone;
|
|
sl@0
|
175 |
}
|
|
sl@0
|
176 |
else
|
|
sl@0
|
177 |
{
|
|
sl@0
|
178 |
_LIT(Kerr , "Failed to make dir") ;
|
|
sl@0
|
179 |
INFO_PRINTF1(Kerr) ;
|
|
sl@0
|
180 |
wrmdir(L"C:\\ggg");
|
|
sl@0
|
181 |
return KErrGeneral ;
|
|
sl@0
|
182 |
}
|
|
sl@0
|
183 |
}
|
|
sl@0
|
184 |
|
|
sl@0
|
185 |
TInt CTestWideApi::wfdopen_ivalm1()
|
|
sl@0
|
186 |
{
|
|
sl@0
|
187 |
int wfd;
|
|
sl@0
|
188 |
int ret_wmkdir = wmkdir(L"C:\\ggg" , S_IWUSR);
|
|
sl@0
|
189 |
if(ret_wmkdir)
|
|
sl@0
|
190 |
{
|
|
sl@0
|
191 |
_LIT(Kerr , "Failed to make dir") ;
|
|
sl@0
|
192 |
INFO_PRINTF1(Kerr) ;
|
|
sl@0
|
193 |
return KErrGeneral ;
|
|
sl@0
|
194 |
}
|
|
sl@0
|
195 |
if((wfd=wopen(L"C:\\ggg\\lll.txt", O_WRONLY | O_CREAT | O_TRUNC, 0777))<0)
|
|
sl@0
|
196 |
{
|
|
sl@0
|
197 |
_LIT(Kopen,"Failed to open file");
|
|
sl@0
|
198 |
INFO_PRINTF1(Kopen);
|
|
sl@0
|
199 |
wrmdir(L"C:\\ggg");
|
|
sl@0
|
200 |
return KErrGeneral;
|
|
sl@0
|
201 |
}
|
|
sl@0
|
202 |
FILE *fp =wfdopen(wfd ,NULL);
|
|
sl@0
|
203 |
if(NULL != fp)
|
|
sl@0
|
204 |
{
|
|
sl@0
|
205 |
wunlink(L"C:\\ggg\\lll.txt");
|
|
sl@0
|
206 |
wrmdir(L"C:\\ggg");
|
|
sl@0
|
207 |
return KErrGeneral;
|
|
sl@0
|
208 |
}
|
|
sl@0
|
209 |
close(wfd);
|
|
sl@0
|
210 |
wunlink(L"C:\\ggg\\lll.txt");
|
|
sl@0
|
211 |
wrmdir(L"C:\\ggg");
|
|
sl@0
|
212 |
return KErrNone;
|
|
sl@0
|
213 |
}
|
|
sl@0
|
214 |
|
|
sl@0
|
215 |
|
|
sl@0
|
216 |
// -----------------------------------------------------------------------------
|
|
sl@0
|
217 |
//Function Name : wfreopen_valm
|
|
sl@0
|
218 |
//API Tested : wfreopen
|
|
sl@0
|
219 |
//TestCase Description: testing the behaviour of wfreopen for different modes
|
|
sl@0
|
220 |
// initialized to NULL.
|
|
sl@0
|
221 |
// -----------------------------------------------------------------------------
|
|
sl@0
|
222 |
TInt CTestWideApi::wfreopen_valm()
|
|
sl@0
|
223 |
{
|
|
sl@0
|
224 |
TPtrC nameRead;
|
|
sl@0
|
225 |
_LIT( KString, "Parameter1" );
|
|
sl@0
|
226 |
TBool res = GetStringFromConfig(ConfigSection(), KString, nameRead);
|
|
sl@0
|
227 |
if(!res)
|
|
sl@0
|
228 |
{
|
|
sl@0
|
229 |
_LIT(Kerr , "Failed to read string") ;
|
|
sl@0
|
230 |
INFO_PRINTF1(Kerr) ;
|
|
sl@0
|
231 |
return KErrGeneral ;
|
|
sl@0
|
232 |
}
|
|
sl@0
|
233 |
int ret_wmkdir = wmkdir(L"C:\\ggg" , S_IWUSR);
|
|
sl@0
|
234 |
if((errno == EEXIST) || (!ret_wmkdir))
|
|
sl@0
|
235 |
{
|
|
sl@0
|
236 |
TBuf8<100> buf;
|
|
sl@0
|
237 |
|
|
sl@0
|
238 |
FILE *fp;
|
|
sl@0
|
239 |
buf.Copy(nameRead);
|
|
sl@0
|
240 |
char* filename = (char*) buf.Ptr();
|
|
sl@0
|
241 |
filename[buf.Length()]='\0';
|
|
sl@0
|
242 |
wchar_t *pathName = (wchar_t *)malloc(30*sizeof(wchar_t));
|
|
sl@0
|
243 |
if(pathName==NULL)
|
|
sl@0
|
244 |
{
|
|
sl@0
|
245 |
wrmdir(L"C:\\ggg");
|
|
sl@0
|
246 |
return KErrNoMemory;
|
|
sl@0
|
247 |
}
|
|
sl@0
|
248 |
size_t siz = mbstowcs(pathName, filename, 30);
|
|
sl@0
|
249 |
wunlink(pathName) ;
|
|
sl@0
|
250 |
if((fp=wfreopen(pathName ,L"w+",stdout))==NULL)
|
|
sl@0
|
251 |
{
|
|
sl@0
|
252 |
_LIT(Kropen , " Failed to reopen file " ) ;
|
|
sl@0
|
253 |
INFO_PRINTF1(Kropen) ;
|
|
sl@0
|
254 |
wrmdir(L"C:\\ggg");
|
|
sl@0
|
255 |
free(pathName);
|
|
sl@0
|
256 |
return KErrGeneral;
|
|
sl@0
|
257 |
}
|
|
sl@0
|
258 |
else
|
|
sl@0
|
259 |
{
|
|
sl@0
|
260 |
int j=printf("Output Redirected to file now");
|
|
sl@0
|
261 |
long i=ftell(fp);
|
|
sl@0
|
262 |
if(i!=j)
|
|
sl@0
|
263 |
{
|
|
sl@0
|
264 |
fclose(fp);
|
|
sl@0
|
265 |
wunlink(pathName);
|
|
sl@0
|
266 |
wrmdir(L"C:\\ggg");
|
|
sl@0
|
267 |
free(pathName);
|
|
sl@0
|
268 |
return KErrGeneral;
|
|
sl@0
|
269 |
}
|
|
sl@0
|
270 |
fclose(fp);
|
|
sl@0
|
271 |
wunlink(pathName);
|
|
sl@0
|
272 |
wrmdir(L"C:\\ggg");
|
|
sl@0
|
273 |
free(pathName);
|
|
sl@0
|
274 |
return KErrNone;
|
|
sl@0
|
275 |
}
|
|
sl@0
|
276 |
}
|
|
sl@0
|
277 |
else
|
|
sl@0
|
278 |
{
|
|
sl@0
|
279 |
_LIT(Kerr , "Failed to make dir") ;
|
|
sl@0
|
280 |
INFO_PRINTF1(Kerr) ;
|
|
sl@0
|
281 |
return KErrGeneral ;
|
|
sl@0
|
282 |
}
|
|
sl@0
|
283 |
}
|
|
sl@0
|
284 |
|
|
sl@0
|
285 |
// -----------------------------------------------------------------------------
|
|
sl@0
|
286 |
//Function Name : wfreopen_val
|
|
sl@0
|
287 |
//API Tested : wfreopen
|
|
sl@0
|
288 |
//TestCase Description: testing the behaviour of wfreopen for valid arguments
|
|
sl@0
|
289 |
// initialized to NULL.
|
|
sl@0
|
290 |
// -----------------------------------------------------------------------------
|
|
sl@0
|
291 |
|
|
sl@0
|
292 |
TInt CTestWideApi::wfreopen_val()
|
|
sl@0
|
293 |
{
|
|
sl@0
|
294 |
TPtrC nameRead;
|
|
sl@0
|
295 |
_LIT( KString, "Parameter1" );
|
|
sl@0
|
296 |
TBool res = GetStringFromConfig(ConfigSection(), KString, nameRead);
|
|
sl@0
|
297 |
if(!res)
|
|
sl@0
|
298 |
{
|
|
sl@0
|
299 |
_LIT(Kerr , "Failed to read string") ;
|
|
sl@0
|
300 |
INFO_PRINTF1(Kerr) ;
|
|
sl@0
|
301 |
return KErrGeneral ;
|
|
sl@0
|
302 |
}
|
|
sl@0
|
303 |
int ret_wmkdir = wmkdir(L"C:\\ggg" , S_IWUSR);
|
|
sl@0
|
304 |
if((errno == EEXIST) || (!ret_wmkdir))
|
|
sl@0
|
305 |
{
|
|
sl@0
|
306 |
TBuf8<100> buf;
|
|
sl@0
|
307 |
int wfd;
|
|
sl@0
|
308 |
FILE *fp;
|
|
sl@0
|
309 |
buf.Copy(nameRead);
|
|
sl@0
|
310 |
char c = 'z';
|
|
sl@0
|
311 |
char* filename = (char*) buf.Ptr();
|
|
sl@0
|
312 |
filename[buf.Length()]='\0';
|
|
sl@0
|
313 |
wchar_t *pathName = (wchar_t *)malloc(30*sizeof(wchar_t));
|
|
sl@0
|
314 |
if(pathName==NULL)
|
|
sl@0
|
315 |
{
|
|
sl@0
|
316 |
wrmdir(L"C:\\ggg");
|
|
sl@0
|
317 |
return KErrNoMemory;
|
|
sl@0
|
318 |
}
|
|
sl@0
|
319 |
size_t siz = mbstowcs(pathName, filename, 30);
|
|
sl@0
|
320 |
wunlink(pathName) ;
|
|
sl@0
|
321 |
if((wfd=wopen(pathName, O_WRONLY | O_CREAT | O_TRUNC, 0666))<0)
|
|
sl@0
|
322 |
{
|
|
sl@0
|
323 |
_LIT(Kopen,"Failed to open file");
|
|
sl@0
|
324 |
INFO_PRINTF1(Kopen);
|
|
sl@0
|
325 |
wrmdir(L"C:\\ggg");
|
|
sl@0
|
326 |
free(pathName);
|
|
sl@0
|
327 |
return KErrGeneral;
|
|
sl@0
|
328 |
}
|
|
sl@0
|
329 |
else
|
|
sl@0
|
330 |
{
|
|
sl@0
|
331 |
write(wfd,&c,1);
|
|
sl@0
|
332 |
}
|
|
sl@0
|
333 |
close(wfd);
|
|
sl@0
|
334 |
if((fp=wfreopen(pathName ,L"r",stdin))==NULL)
|
|
sl@0
|
335 |
{
|
|
sl@0
|
336 |
_LIT(Kropen , " Failed to reopen file " ) ;
|
|
sl@0
|
337 |
INFO_PRINTF1(Kropen) ;
|
|
sl@0
|
338 |
wrmdir(L"C:\\ggg");
|
|
sl@0
|
339 |
free(pathName);
|
|
sl@0
|
340 |
return KErrGeneral;
|
|
sl@0
|
341 |
}
|
|
sl@0
|
342 |
char * filen="C:\\tem.txt";
|
|
sl@0
|
343 |
unlink(filen);
|
|
sl@0
|
344 |
int fd=open(filen, O_WRONLY | O_CREAT | O_TRUNC, 0666);
|
|
sl@0
|
345 |
if(fd<0)
|
|
sl@0
|
346 |
{
|
|
sl@0
|
347 |
_LIT(Kopen,"Failed to open file");
|
|
sl@0
|
348 |
INFO_PRINTF1(Kopen);
|
|
sl@0
|
349 |
wrmdir(L"C:\\ggg");
|
|
sl@0
|
350 |
free(pathName);
|
|
sl@0
|
351 |
return KErrGeneral ;
|
|
sl@0
|
352 |
}
|
|
sl@0
|
353 |
else
|
|
sl@0
|
354 |
{
|
|
sl@0
|
355 |
write(fd,&c,1);
|
|
sl@0
|
356 |
}
|
|
sl@0
|
357 |
close(fd);
|
|
sl@0
|
358 |
fclose(fp);
|
|
sl@0
|
359 |
unlink(filen);
|
|
sl@0
|
360 |
wunlink(pathName);
|
|
sl@0
|
361 |
wrmdir(L"C:\\ggg");
|
|
sl@0
|
362 |
free(pathName);
|
|
sl@0
|
363 |
return KErrNone ;
|
|
sl@0
|
364 |
}
|
|
sl@0
|
365 |
else
|
|
sl@0
|
366 |
{
|
|
sl@0
|
367 |
_LIT(Kerr , "Failed to make dir") ;
|
|
sl@0
|
368 |
INFO_PRINTF1(Kerr) ;
|
|
sl@0
|
369 |
return KErrGeneral ;
|
|
sl@0
|
370 |
}
|
|
sl@0
|
371 |
}
|
|
sl@0
|
372 |
|
|
sl@0
|
373 |
|
|
sl@0
|
374 |
|
|
sl@0
|
375 |
// -----------------------------------------------------------------------------
|
|
sl@0
|
376 |
//Function Name : wfreopen_valinv
|
|
sl@0
|
377 |
//API Tested : wfreopen
|
|
sl@0
|
378 |
//TestCase Description: testing the behaviour of wfreopen for invalid filename
|
|
sl@0
|
379 |
// initialized to NULL.
|
|
sl@0
|
380 |
// -----------------------------------------------------------------------------
|
|
sl@0
|
381 |
|
|
sl@0
|
382 |
|
|
sl@0
|
383 |
TInt CTestWideApi::wfreopen_valinv()
|
|
sl@0
|
384 |
{
|
|
sl@0
|
385 |
TPtrC nameRead;
|
|
sl@0
|
386 |
_LIT( KString, "Parameter1" );
|
|
sl@0
|
387 |
TBool res = GetStringFromConfig(ConfigSection(), KString, nameRead);
|
|
sl@0
|
388 |
if(!res)
|
|
sl@0
|
389 |
{
|
|
sl@0
|
390 |
_LIT(Kerr , "Failed to read string") ;
|
|
sl@0
|
391 |
INFO_PRINTF1(Kerr) ;
|
|
sl@0
|
392 |
return KErrGeneral ;
|
|
sl@0
|
393 |
}
|
|
sl@0
|
394 |
int ret_wmkdir = wmkdir(L"C:\\ggg" , S_IWUSR);
|
|
sl@0
|
395 |
if((errno == EEXIST) || (!ret_wmkdir))
|
|
sl@0
|
396 |
{
|
|
sl@0
|
397 |
TBuf8<100> buf;
|
|
sl@0
|
398 |
buf.Copy(nameRead);
|
|
sl@0
|
399 |
char* filename = (char*) buf.Ptr();
|
|
sl@0
|
400 |
filename[buf.Length()]='\0';
|
|
sl@0
|
401 |
wchar_t *pathName = (wchar_t *)malloc(30*sizeof(wchar_t));
|
|
sl@0
|
402 |
if(pathName==NULL)
|
|
sl@0
|
403 |
{
|
|
sl@0
|
404 |
wrmdir(L"C:\\ggg");
|
|
sl@0
|
405 |
return KErrNoMemory;
|
|
sl@0
|
406 |
}
|
|
sl@0
|
407 |
size_t siz = mbstowcs(pathName, filename, 30);
|
|
sl@0
|
408 |
wunlink(pathName) ;
|
|
sl@0
|
409 |
FILE *fp = wfreopen(pathName ,L"w",stdout);
|
|
sl@0
|
410 |
if(fp == NULL)
|
|
sl@0
|
411 |
{
|
|
sl@0
|
412 |
_LIT(Kropen , " Failed to reopen file " ) ;
|
|
sl@0
|
413 |
INFO_PRINTF1(Kropen) ;
|
|
sl@0
|
414 |
wrmdir(L"C:\\ggg");
|
|
sl@0
|
415 |
free(pathName);
|
|
sl@0
|
416 |
return KErrNone;
|
|
sl@0
|
417 |
}
|
|
sl@0
|
418 |
else
|
|
sl@0
|
419 |
{
|
|
sl@0
|
420 |
wrmdir(L"C:\\ggg");
|
|
sl@0
|
421 |
free(pathName);
|
|
sl@0
|
422 |
return KErrGeneral;
|
|
sl@0
|
423 |
}
|
|
sl@0
|
424 |
}
|
|
sl@0
|
425 |
else
|
|
sl@0
|
426 |
{
|
|
sl@0
|
427 |
_LIT(Kerr , "Failed to make dir") ;
|
|
sl@0
|
428 |
INFO_PRINTF1(Kerr) ;
|
|
sl@0
|
429 |
return KErrGeneral ;
|
|
sl@0
|
430 |
}
|
|
sl@0
|
431 |
}
|
|
sl@0
|
432 |
|
|
sl@0
|
433 |
//-----------------------------------------------------------------------------
|
|
sl@0
|
434 |
//Function Name :wremoveTest1
|
|
sl@0
|
435 |
//API Tested :wremove
|
|
sl@0
|
436 |
//TestCase Description: creates a directory and 2 files inside the dir and tries
|
|
sl@0
|
437 |
// to delete the files using wremove API, it should return 0 on successful
|
|
sl@0
|
438 |
// deletion of the files and then the directory and -1 on failure.
|
|
sl@0
|
439 |
//-----------------------------------------------------------------------------
|
|
sl@0
|
440 |
|
|
sl@0
|
441 |
TInt CTestWideApi::wremove_val1()
|
|
sl@0
|
442 |
{
|
|
sl@0
|
443 |
wchar_t *dirName = L"C:\\wremoveDir";
|
|
sl@0
|
444 |
wchar_t *fileName1 = L"C:\\wremoveDir\\file1.txt";
|
|
sl@0
|
445 |
wchar_t *fileName2 = L"C:\\wremoveDir\\file2.txt";
|
|
sl@0
|
446 |
TInt ret = -1;
|
|
sl@0
|
447 |
errno = 0;
|
|
sl@0
|
448 |
if(wmkdir(dirName ,S_IWUSR) < 0)
|
|
sl@0
|
449 |
{
|
|
sl@0
|
450 |
INFO_PRINTF1(_L("Failed to create the parent directory"));
|
|
sl@0
|
451 |
return KErrGeneral ;
|
|
sl@0
|
452 |
}
|
|
sl@0
|
453 |
FILE *fp = wfopen(fileName1, (wchar_t *)"w");
|
|
sl@0
|
454 |
if(fp == NULL)
|
|
sl@0
|
455 |
{
|
|
sl@0
|
456 |
INFO_PRINTF1(_L("Failed to create the child directory"));
|
|
sl@0
|
457 |
return KErrGeneral ;
|
|
sl@0
|
458 |
}
|
|
sl@0
|
459 |
fclose(fp);
|
|
sl@0
|
460 |
|
|
sl@0
|
461 |
fp = wfopen(fileName2, (wchar_t *)"w");
|
|
sl@0
|
462 |
if(fp == NULL)
|
|
sl@0
|
463 |
{
|
|
sl@0
|
464 |
INFO_PRINTF1(_L("Failed to create the child directory"));
|
|
sl@0
|
465 |
return KErrGeneral ;
|
|
sl@0
|
466 |
}
|
|
sl@0
|
467 |
fclose(fp);
|
|
sl@0
|
468 |
ret = wremove(fileName1);
|
|
sl@0
|
469 |
if(ret != 0)
|
|
sl@0
|
470 |
{
|
|
sl@0
|
471 |
INFO_PRINTF1(_L("wremove failed"));
|
|
sl@0
|
472 |
wunlink(fileName1);
|
|
sl@0
|
473 |
return KErrGeneral;
|
|
sl@0
|
474 |
}
|
|
sl@0
|
475 |
ret = wremove(fileName2);
|
|
sl@0
|
476 |
if(ret != 0)
|
|
sl@0
|
477 |
{
|
|
sl@0
|
478 |
INFO_PRINTF1(_L("wremove failed"));
|
|
sl@0
|
479 |
wunlink(fileName2);
|
|
sl@0
|
480 |
return KErrGeneral;
|
|
sl@0
|
481 |
}
|
|
sl@0
|
482 |
ret = wremove(dirName);
|
|
sl@0
|
483 |
if(ret != 0)
|
|
sl@0
|
484 |
{
|
|
sl@0
|
485 |
INFO_PRINTF1(_L("wremove failed"));
|
|
sl@0
|
486 |
return KErrGeneral;
|
|
sl@0
|
487 |
}
|
|
sl@0
|
488 |
return KErrNone ;
|
|
sl@0
|
489 |
}
|
|
sl@0
|
490 |
|
|
sl@0
|
491 |
|
|
sl@0
|
492 |
//-----------------------------------------------------------------------------
|
|
sl@0
|
493 |
//Function Name :wremoveTest2
|
|
sl@0
|
494 |
//API Tested :wremove
|
|
sl@0
|
495 |
//TestCase Description: creates a directory and tries to delete the file that
|
|
sl@0
|
496 |
// doesnot exist in the dir using wremove API, it should return -1 and set the
|
|
sl@0
|
497 |
// error number correspondingly.
|
|
sl@0
|
498 |
//-----------------------------------------------------------------------------
|
|
sl@0
|
499 |
|
|
sl@0
|
500 |
TInt CTestWideApi :: wremove_val2()
|
|
sl@0
|
501 |
{
|
|
sl@0
|
502 |
wchar_t *dirName = L"C:\\wremoveDir1";
|
|
sl@0
|
503 |
wchar_t *fileName1 = L"C:\\wremoveDir1\\file1.txt"; //file doesnot exist
|
|
sl@0
|
504 |
TInt ret = -1;
|
|
sl@0
|
505 |
errno = 0;
|
|
sl@0
|
506 |
if(wmkdir(dirName ,S_IWUSR) < 0)
|
|
sl@0
|
507 |
{
|
|
sl@0
|
508 |
INFO_PRINTF1(_L("Failed to create the parent directory"));
|
|
sl@0
|
509 |
return KErrGeneral ;
|
|
sl@0
|
510 |
}
|
|
sl@0
|
511 |
ret = wremove(fileName1);
|
|
sl@0
|
512 |
if(ret != -1 && errno == 0)
|
|
sl@0
|
513 |
{
|
|
sl@0
|
514 |
INFO_PRINTF1(_L("wremove failed"));
|
|
sl@0
|
515 |
return KErrGeneral;
|
|
sl@0
|
516 |
}
|
|
sl@0
|
517 |
ret = wremove(dirName);
|
|
sl@0
|
518 |
if(ret != 0)
|
|
sl@0
|
519 |
{
|
|
sl@0
|
520 |
INFO_PRINTF1(_L("wremove failed"));
|
|
sl@0
|
521 |
return KErrGeneral;
|
|
sl@0
|
522 |
}
|
|
sl@0
|
523 |
return KErrNone ;
|
|
sl@0
|
524 |
}
|
|
sl@0
|
525 |
|
|
sl@0
|
526 |
|
|
sl@0
|
527 |
//-----------------------------------------------------------------------------
|
|
sl@0
|
528 |
//Function Name :wremoveTest3
|
|
sl@0
|
529 |
//API Tested :wremove
|
|
sl@0
|
530 |
//TestCase Description: creates a directory and tries to delete the dir using
|
|
sl@0
|
531 |
// wremove API, it should return -1 and set the error number correspondingly.
|
|
sl@0
|
532 |
//-----------------------------------------------------------------------------
|
|
sl@0
|
533 |
|
|
sl@0
|
534 |
TInt CTestWideApi::wremove_val3()
|
|
sl@0
|
535 |
{
|
|
sl@0
|
536 |
TInt nameRead;
|
|
sl@0
|
537 |
TInt retnVal;
|
|
sl@0
|
538 |
int retn = KErrGeneral;
|
|
sl@0
|
539 |
_LIT( Klen, "Parameter1" );
|
|
sl@0
|
540 |
|
|
sl@0
|
541 |
TBool res = GetIntFromConfig(ConfigSection(), Klen, nameRead);
|
|
sl@0
|
542 |
if(!res)
|
|
sl@0
|
543 |
{
|
|
sl@0
|
544 |
_LIT(Kerr , "Failed to read the value") ;
|
|
sl@0
|
545 |
INFO_PRINTF1(Kerr) ;
|
|
sl@0
|
546 |
return KErrGeneral ;
|
|
sl@0
|
547 |
}
|
|
sl@0
|
548 |
_LIT( Klen2, "Parameter2" );
|
|
sl@0
|
549 |
res = GetIntFromConfig(ConfigSection(), Klen2, retnVal);
|
|
sl@0
|
550 |
if(!res)
|
|
sl@0
|
551 |
{
|
|
sl@0
|
552 |
_LIT(Kerr , "Failed to read the value") ;
|
|
sl@0
|
553 |
INFO_PRINTF1(Kerr) ;
|
|
sl@0
|
554 |
return KErrGeneral ;
|
|
sl@0
|
555 |
}
|
|
sl@0
|
556 |
wchar_t* dirName = L"C:\\wremoveDir3";
|
|
sl@0
|
557 |
int ret1 = wmkdir(dirName, S_IWUSR);
|
|
sl@0
|
558 |
if(!ret1)
|
|
sl@0
|
559 |
{
|
|
sl@0
|
560 |
int ret = wremove(dirName);
|
|
sl@0
|
561 |
if(!ret && !retnVal)
|
|
sl@0
|
562 |
{
|
|
sl@0
|
563 |
INFO_PRINTF1( _L("Passed..."));
|
|
sl@0
|
564 |
retn = KErrNone;
|
|
sl@0
|
565 |
}
|
|
sl@0
|
566 |
else if(ret && retnVal)
|
|
sl@0
|
567 |
{
|
|
sl@0
|
568 |
INFO_PRINTF1( _L("Passed..."));
|
|
sl@0
|
569 |
retn = KErrNone;
|
|
sl@0
|
570 |
}
|
|
sl@0
|
571 |
else
|
|
sl@0
|
572 |
{
|
|
sl@0
|
573 |
INFO_PRINTF1( _L("Failed..."));
|
|
sl@0
|
574 |
}
|
|
sl@0
|
575 |
}
|
|
sl@0
|
576 |
else
|
|
sl@0
|
577 |
{
|
|
sl@0
|
578 |
if(retnVal)
|
|
sl@0
|
579 |
{
|
|
sl@0
|
580 |
INFO_PRINTF1( _L("Passed..."));
|
|
sl@0
|
581 |
retn = KErrNone;
|
|
sl@0
|
582 |
}
|
|
sl@0
|
583 |
else
|
|
sl@0
|
584 |
{
|
|
sl@0
|
585 |
INFO_PRINTF1( _L("Failed..."));
|
|
sl@0
|
586 |
}
|
|
sl@0
|
587 |
}
|
|
sl@0
|
588 |
return retn;
|
|
sl@0
|
589 |
}
|
|
sl@0
|
590 |
|
|
sl@0
|
591 |
|
|
sl@0
|
592 |
//-----------------------------------------------------------------------------
|
|
sl@0
|
593 |
//Function Name :wremove_null
|
|
sl@0
|
594 |
//API Tested :wremove
|
|
sl@0
|
595 |
//TestCase Description: tests the behaviour of wremove with NULL as the argument.
|
|
sl@0
|
596 |
//-----------------------------------------------------------------------------
|
|
sl@0
|
597 |
|
|
sl@0
|
598 |
TInt CTestWideApi :: wremove_null()
|
|
sl@0
|
599 |
{
|
|
sl@0
|
600 |
int ret = wremove(NULL);
|
|
sl@0
|
601 |
if(ret < 0)
|
|
sl@0
|
602 |
{
|
|
sl@0
|
603 |
return KErrNone ;
|
|
sl@0
|
604 |
}
|
|
sl@0
|
605 |
return KErrGeneral;
|
|
sl@0
|
606 |
}
|
|
sl@0
|
607 |
|
|
sl@0
|
608 |
|
|
sl@0
|
609 |
/*
|
|
sl@0
|
610 |
-------------------------------------------------------------------------------
|
|
sl@0
|
611 |
Function Name : CTestWideApi::getws_val
|
|
sl@0
|
612 |
API Tested : getws
|
|
sl@0
|
613 |
TestCase Description: The test case takes a wide character string from standard
|
|
sl@0
|
614 |
input.
|
|
sl@0
|
615 |
-------------------------------------------------------------------------------
|
|
sl@0
|
616 |
*/
|
|
sl@0
|
617 |
TInt CTestWideApi::getws_val()
|
|
sl@0
|
618 |
{
|
|
sl@0
|
619 |
FILE* stdop = freopen("c:\\stdop","w+",stdout);
|
|
sl@0
|
620 |
FILE* stdip = freopen("c:\\stdip","w+",stdin);
|
|
sl@0
|
621 |
wchar_t* buf = (wchar_t*)malloc(sizeof(wchar_t)*50);
|
|
sl@0
|
622 |
if(buf==NULL)
|
|
sl@0
|
623 |
{
|
|
sl@0
|
624 |
fclose(stdin);
|
|
sl@0
|
625 |
fclose(stdop);
|
|
sl@0
|
626 |
remove("c:\\stdop");
|
|
sl@0
|
627 |
remove("c:\\stdip");
|
|
sl@0
|
628 |
return KErrNoMemory;
|
|
sl@0
|
629 |
}
|
|
sl@0
|
630 |
wchar_t s[100];
|
|
sl@0
|
631 |
TInt ret = KErrNone;
|
|
sl@0
|
632 |
size_t size = fwrite("sushma\n", 1, 6, stdip);
|
|
sl@0
|
633 |
fclose(stdip);
|
|
sl@0
|
634 |
stdip = freopen("c:\\stdip","r", stdin);
|
|
sl@0
|
635 |
getws(s); // read a line (from stdin)
|
|
sl@0
|
636 |
putws(s);
|
|
sl@0
|
637 |
fclose(stdop);
|
|
sl@0
|
638 |
stdop = freopen("c:\\stdop","r", stdout);
|
|
sl@0
|
639 |
//size = fread(buf, 1, 6, stdop);
|
|
sl@0
|
640 |
fgetws(buf,7,stdop);
|
|
sl@0
|
641 |
if(wcsncmp(s, buf,6))
|
|
sl@0
|
642 |
{
|
|
sl@0
|
643 |
ret = KErrGeneral;
|
|
sl@0
|
644 |
}
|
|
sl@0
|
645 |
fclose(stdin);
|
|
sl@0
|
646 |
fclose(stdop);
|
|
sl@0
|
647 |
remove("c:\\stdop");
|
|
sl@0
|
648 |
remove("c:\\stdip");
|
|
sl@0
|
649 |
free(buf);
|
|
sl@0
|
650 |
return ret;
|
|
sl@0
|
651 |
}
|
|
sl@0
|
652 |
|
|
sl@0
|
653 |
/*
|
|
sl@0
|
654 |
-------------------------------------------------------------------------------
|
|
sl@0
|
655 |
Function Name : CTestWideApi::getws_null
|
|
sl@0
|
656 |
API Tested : getws
|
|
sl@0
|
657 |
TestCase Description: The test case to test getws for NULL argument
|
|
sl@0
|
658 |
-------------------------------------------------------------------------------
|
|
sl@0
|
659 |
*/
|
|
sl@0
|
660 |
TInt CTestWideApi::getws_null()
|
|
sl@0
|
661 |
{
|
|
sl@0
|
662 |
INFO_PRINTF1(_L("getws_nullL"));
|
|
sl@0
|
663 |
wchar_t* ret = getws(NULL); // read a line (from stdin)
|
|
sl@0
|
664 |
if(!ret)
|
|
sl@0
|
665 |
{
|
|
sl@0
|
666 |
return KErrNone;
|
|
sl@0
|
667 |
}
|
|
sl@0
|
668 |
else
|
|
sl@0
|
669 |
{
|
|
sl@0
|
670 |
return KErrGeneral;
|
|
sl@0
|
671 |
}
|
|
sl@0
|
672 |
}
|
|
sl@0
|
673 |
|
|
sl@0
|
674 |
/*
|
|
sl@0
|
675 |
-------------------------------------------------------------------------------
|
|
sl@0
|
676 |
Function Name : CTestWideApi::putws_val1
|
|
sl@0
|
677 |
API Tested : putws
|
|
sl@0
|
678 |
TestCase Description: The testcase funtion will write a fixed lenth wide char string
|
|
sl@0
|
679 |
to the stdout.
|
|
sl@0
|
680 |
-------------------------------------------------------------------------------
|
|
sl@0
|
681 |
*/
|
|
sl@0
|
682 |
TInt CTestWideApi::putws_val1()
|
|
sl@0
|
683 |
{
|
|
sl@0
|
684 |
INFO_PRINTF1(_L("putws"));
|
|
sl@0
|
685 |
wchar_t buf[12];
|
|
sl@0
|
686 |
FILE* stdop = freopen("c:\\stdop","w+",stdout);
|
|
sl@0
|
687 |
FILE* op;
|
|
sl@0
|
688 |
putws(L"Hello World");
|
|
sl@0
|
689 |
fclose(stdop);
|
|
sl@0
|
690 |
op = freopen("c:\\stdop","r",stdout);
|
|
sl@0
|
691 |
fgetws(buf, 12, op);
|
|
sl@0
|
692 |
fclose(stdop);
|
|
sl@0
|
693 |
remove("c:\\stdop");
|
|
sl@0
|
694 |
if(!(wcsncmp(L"Hello World", buf, 11)))
|
|
sl@0
|
695 |
{
|
|
sl@0
|
696 |
return KErrNone;
|
|
sl@0
|
697 |
}
|
|
sl@0
|
698 |
else
|
|
sl@0
|
699 |
{
|
|
sl@0
|
700 |
return KErrGeneral;
|
|
sl@0
|
701 |
}
|
|
sl@0
|
702 |
}
|
|
sl@0
|
703 |
|
|
sl@0
|
704 |
/*
|
|
sl@0
|
705 |
-------------------------------------------------------------------------------
|
|
sl@0
|
706 |
Function Name : CTestWideApi::putws_val2L
|
|
sl@0
|
707 |
API Tested : putws
|
|
sl@0
|
708 |
TestCase Description: The testcase function will write a wide string to the screen
|
|
sl@0
|
709 |
which has a null terminator in the middle of the string.
|
|
sl@0
|
710 |
-------------------------------------------------------------------------------
|
|
sl@0
|
711 |
*/
|
|
sl@0
|
712 |
TInt CTestWideApi::putws_val2()
|
|
sl@0
|
713 |
{
|
|
sl@0
|
714 |
INFO_PRINTF1(_L("putws2"));
|
|
sl@0
|
715 |
wchar_t buf[10];
|
|
sl@0
|
716 |
FILE* stdop = freopen("c:\\stdop","w+",stdout);
|
|
sl@0
|
717 |
putws(L"Hel\0lo World");
|
|
sl@0
|
718 |
fclose(stdop);
|
|
sl@0
|
719 |
stdop = freopen("c:\\stdop","r",stdout);
|
|
sl@0
|
720 |
fgetws(buf, 4, stdop);
|
|
sl@0
|
721 |
fclose(stdop);
|
|
sl@0
|
722 |
remove("c:\\stdop");
|
|
sl@0
|
723 |
if(!wcsncmp(L"Hel", buf, 4))
|
|
sl@0
|
724 |
{
|
|
sl@0
|
725 |
return KErrNone;
|
|
sl@0
|
726 |
}
|
|
sl@0
|
727 |
else
|
|
sl@0
|
728 |
{
|
|
sl@0
|
729 |
return KErrGeneral;
|
|
sl@0
|
730 |
}
|
|
sl@0
|
731 |
}
|
|
sl@0
|
732 |
|
|
sl@0
|
733 |
/*
|
|
sl@0
|
734 |
-------------------------------------------------------------------------------
|
|
sl@0
|
735 |
Function Name : CTestWideApi::putws_nullL
|
|
sl@0
|
736 |
API Tested : putws
|
|
sl@0
|
737 |
TestCase Description: The testcase funtion tests the behaviour of putws for NULL
|
|
sl@0
|
738 |
argument.
|
|
sl@0
|
739 |
-------------------------------------------------------------------------------
|
|
sl@0
|
740 |
*/
|
|
sl@0
|
741 |
TInt CTestWideApi::putws_null()
|
|
sl@0
|
742 |
{
|
|
sl@0
|
743 |
INFO_PRINTF1(_L("putws1"));
|
|
sl@0
|
744 |
int ret = putws(NULL);
|
|
sl@0
|
745 |
if(ret>0)
|
|
sl@0
|
746 |
{
|
|
sl@0
|
747 |
return KErrGeneral;
|
|
sl@0
|
748 |
}
|
|
sl@0
|
749 |
else
|
|
sl@0
|
750 |
{
|
|
sl@0
|
751 |
return KErrNone;
|
|
sl@0
|
752 |
}
|
|
sl@0
|
753 |
}
|
|
sl@0
|
754 |
|
|
sl@0
|
755 |
|
|
sl@0
|
756 |
//-----------------------------------------------------------------------------
|
|
sl@0
|
757 |
//Function Name :wpopen_1L
|
|
sl@0
|
758 |
//API Tested :wpopen
|
|
sl@0
|
759 |
//TestCase Description: tests the behaviour of wpopen with NULL as the command.
|
|
sl@0
|
760 |
//-----------------------------------------------------------------------------
|
|
sl@0
|
761 |
|
|
sl@0
|
762 |
TInt CTestWideApi :: wpopen_1()
|
|
sl@0
|
763 |
{
|
|
sl@0
|
764 |
FILE *fp;
|
|
sl@0
|
765 |
fp=wpopen(NULL,L"r");
|
|
sl@0
|
766 |
if (fp == NULL && errno == ENOENT)
|
|
sl@0
|
767 |
{
|
|
sl@0
|
768 |
INFO_PRINTF1(_L("wpopen success"));
|
|
sl@0
|
769 |
return KErrNone;
|
|
sl@0
|
770 |
}
|
|
sl@0
|
771 |
return KErrGeneral;
|
|
sl@0
|
772 |
}
|
|
sl@0
|
773 |
|
|
sl@0
|
774 |
|
|
sl@0
|
775 |
|
|
sl@0
|
776 |
TInt CTestWideApi::wfreopen1()
|
|
sl@0
|
777 |
{
|
|
sl@0
|
778 |
char* filename = "c:\\ggg1.txt";
|
|
sl@0
|
779 |
wchar_t *pathName = (wchar_t *)malloc(30*sizeof(wchar_t));
|
|
sl@0
|
780 |
if(pathName==NULL)
|
|
sl@0
|
781 |
{
|
|
sl@0
|
782 |
return KErrNoMemory;
|
|
sl@0
|
783 |
}
|
|
sl@0
|
784 |
size_t siz = mbstowcs(pathName, filename, 30);
|
|
sl@0
|
785 |
FILE *fp = wfreopen(pathName ,NULL,stdout);
|
|
sl@0
|
786 |
free(pathName) ;
|
|
sl@0
|
787 |
if(fp == NULL)
|
|
sl@0
|
788 |
{
|
|
sl@0
|
789 |
INFO_PRINTF1(_L("wfreopen success"));
|
|
sl@0
|
790 |
return KErrNone;
|
|
sl@0
|
791 |
}
|
|
sl@0
|
792 |
|
|
sl@0
|
793 |
return KErrGeneral;
|
|
sl@0
|
794 |
}
|
|
sl@0
|
795 |
TInt CTestWideApi::wfreopen2()
|
|
sl@0
|
796 |
{
|
|
sl@0
|
797 |
char* filename = "c:\\ggg.txt";
|
|
sl@0
|
798 |
wchar_t *pathName = (wchar_t *)malloc(30*sizeof(wchar_t));
|
|
sl@0
|
799 |
if(pathName==NULL)
|
|
sl@0
|
800 |
{
|
|
sl@0
|
801 |
return KErrNoMemory;
|
|
sl@0
|
802 |
}
|
|
sl@0
|
803 |
size_t siz = mbstowcs(pathName, filename, 30);
|
|
sl@0
|
804 |
FILE *fp = wfreopen(pathName ,L"x",stdout);
|
|
sl@0
|
805 |
free(pathName) ;
|
|
sl@0
|
806 |
if(fp == NULL)
|
|
sl@0
|
807 |
{
|
|
sl@0
|
808 |
INFO_PRINTF1(_L("wfreopen success"));
|
|
sl@0
|
809 |
return KErrNone;
|
|
sl@0
|
810 |
}
|
|
sl@0
|
811 |
|
|
sl@0
|
812 |
return KErrGeneral;
|
|
sl@0
|
813 |
}
|
|
sl@0
|
814 |
TInt CTestWideApi::wfreopen3()
|
|
sl@0
|
815 |
{
|
|
sl@0
|
816 |
|
|
sl@0
|
817 |
FILE *fp1 = wfreopen(NULL ,L"w",stdout);
|
|
sl@0
|
818 |
if(fp1 == NULL)
|
|
sl@0
|
819 |
{
|
|
sl@0
|
820 |
INFO_PRINTF1(_L("wfreopen success"));
|
|
sl@0
|
821 |
return KErrNone;
|
|
sl@0
|
822 |
}
|
|
sl@0
|
823 |
|
|
sl@0
|
824 |
return KErrGeneral;
|
|
sl@0
|
825 |
}
|
|
sl@0
|
826 |
TInt CTestWideApi::wfreopen4()
|
|
sl@0
|
827 |
{
|
|
sl@0
|
828 |
|
|
sl@0
|
829 |
wchar_t *fileName1 = L"C:\\myfile1.txt";
|
|
sl@0
|
830 |
FILE *fp = wfopen(fileName1, (wchar_t *)"w");
|
|
sl@0
|
831 |
if(fp == NULL)
|
|
sl@0
|
832 |
{
|
|
sl@0
|
833 |
INFO_PRINTF1(_L("Failed to create the child directory"));
|
|
sl@0
|
834 |
return KErrGeneral ;
|
|
sl@0
|
835 |
}
|
|
sl@0
|
836 |
|
|
sl@0
|
837 |
FILE *fp1 = wfreopen(NULL ,L"w",fp);
|
|
sl@0
|
838 |
if(fp1 != NULL)
|
|
sl@0
|
839 |
{
|
|
sl@0
|
840 |
INFO_PRINTF1(_L("wfreopen success"));
|
|
sl@0
|
841 |
return KErrNone;
|
|
sl@0
|
842 |
}
|
|
sl@0
|
843 |
|
|
sl@0
|
844 |
return KErrGeneral;
|
|
sl@0
|
845 |
}
|
|
sl@0
|
846 |
// End of File
|