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