kerneltest/f32test/server/t_fman.cpp
branchRCL_3
changeset 43 c1f20ce4abcf
parent 42 a179b74831c9
child 44 3e88ff8f41d5
equal deleted inserted replaced
42:a179b74831c9 43:c1f20ce4abcf
    51 MFileManObserver::TControl CFileManObserver::NotifyFileManEnded()
    51 MFileManObserver::TControl CFileManObserver::NotifyFileManEnded()
    52 //
    52 //
    53 // Called back after each FMan tick
    53 // Called back after each FMan tick
    54 //
    54 //
    55 	{
    55 	{
       
    56     (void) MFileManObserver::NotifyFileManEnded();
    56 	TInt lastError=iFileMan->GetLastError();
    57 	TInt lastError=iFileMan->GetLastError();
    57 	if (lastError!=KErrNone && lastError!=KErrBadName)
    58 	if (lastError!=KErrNone && lastError!=KErrBadName)
    58 		{
    59 		{
    59 		TFileName fileName=iFileMan->CurrentEntry().iName;
    60 		TFileName fileName=iFileMan->CurrentEntry().iName;
    60 		if (gAsynch==EFalse)
    61 		if (gAsynch==EFalse)
  3106 	TControl NotifyFileManEnded();
  3107 	TControl NotifyFileManEnded();
  3107 private:
  3108 private:
  3108 	CFileMan* iFileMan;
  3109 	CFileMan* iFileMan;
  3109 	};
  3110 	};
  3110 
  3111 
  3111 
       
  3112 CFileManObserverOverWrite::CFileManObserverOverWrite(CFileMan* aFileMan)
  3112 CFileManObserverOverWrite::CFileManObserverOverWrite(CFileMan* aFileMan)
  3113 //
  3113 //
  3114 // Constructor
  3114 // Constructor
  3115 //
  3115 //
  3116 	{
  3116 	{
  3134 			test.Printf(_L("     %S already exists\n"),&fileName);
  3134 			test.Printf(_L("     %S already exists\n"),&fileName);
  3135 			}
  3135 			}
  3136 		}
  3136 		}
  3137 	return(MFileManObserver::EContinue);
  3137 	return(MFileManObserver::EContinue);
  3138 	}
  3138 	}
       
  3139 
       
  3140 class CFileManObserverBytesCopied : public CBase, public MFileManObserver
       
  3141     {
       
  3142 public:
       
  3143     CFileManObserverBytesCopied(CFileMan* aFileMan);
       
  3144     TControl NotifyFileManEnded();
       
  3145     TControl NotifyFileManOperation();
       
  3146     TInt iBytesToBeCopied;
       
  3147 private:
       
  3148     CFileMan* iFileMan;
       
  3149     TInt iBytesCopied;
       
  3150     };
       
  3151 
       
  3152 CFileManObserverBytesCopied::CFileManObserverBytesCopied(CFileMan* aFileMan)
       
  3153 //
       
  3154 // Constructor
       
  3155 //
       
  3156     {
       
  3157     __DECLARE_NAME(_S("CFileManObserverBytesCopied"));
       
  3158     iFileMan=aFileMan;
       
  3159     iBytesCopied=0;
       
  3160     }
       
  3161 
       
  3162 MFileManObserver::TControl CFileManObserverBytesCopied::NotifyFileManOperation()
       
  3163 //
       
  3164 // Observer for testBytesCopied tests
       
  3165 //
       
  3166     {
       
  3167     TFileName target;
       
  3168     iFileMan->GetCurrentTarget(target);
       
  3169     TInt match = target.MatchF(_L("?:\\bytesTransferred"));
       
  3170     if(match != 0)
       
  3171         {
       
  3172         RDebug::Print(_L("CFileManObserverBytesCopied::NotifyFileManOperation - target %s, match %d"),target.PtrZ(),match);
       
  3173         return MFileManObserver::EAbort;
       
  3174         }
       
  3175     
       
  3176     iBytesCopied += iFileMan->BytesTransferredByCopyStep();
       
  3177     return(MFileManObserver::EContinue);
       
  3178     }
       
  3179 
       
  3180 MFileManObserver::TControl CFileManObserverBytesCopied::NotifyFileManEnded()
       
  3181 //
       
  3182 // Observer for testBytesCopied  tests
       
  3183 //
       
  3184     {
       
  3185     if(iBytesCopied!=iBytesToBeCopied)
       
  3186         return (MFileManObserver::EAbort);
       
  3187     
       
  3188     return(MFileManObserver::EContinue);
       
  3189     }
       
  3190 
       
  3191 
  3139 
  3192 
  3140 LOCAL_C void TestOverWrite()
  3193 LOCAL_C void TestOverWrite()
  3141 //
  3194 //
  3142 // Test overwrite for copy and rename
  3195 // Test overwrite for copy and rename
  3143 //
  3196 //
  3924 #endif
  3977 #endif
  3925 
  3978 
  3926 	MakeDir(_L("C:\\F32-TST\\TFMAN\\DRIVEMOVE\\"));
  3979 	MakeDir(_L("C:\\F32-TST\\TFMAN\\DRIVEMOVE\\"));
  3927 	TInt r=gFileMan->Move(_L("C:\\F32-TST\\TFMAN\\DRIVEMOVE\\*"),trgDrive,CFileMan::ERecurse);
  3980 	TInt r=gFileMan->Move(_L("C:\\F32-TST\\TFMAN\\DRIVEMOVE\\*"),trgDrive,CFileMan::ERecurse);
  3928 	test.Printf(_L("TestMoveEmptyDirectory(),gFileMan->Move(),r=%d\n"),r);
  3981 	test.Printf(_L("TestMoveEmptyDirectory(),gFileMan->Move(),r=%d\n"),r);
  3929 	test (r==KErrNotFound);
  3982 	test_Value(r, r == KErrNotFound);
  3930 	}
  3983 	}
  3931 
  3984 
  3932 LOCAL_C void TestCopyAndRename()
  3985 LOCAL_C void TestCopyAndRename()
  3933 //
  3986 //
  3934 // Rename while copying files and directories
  3987 // Rename while copying files and directories
  4303 		} // End of OOM loop
  4356 		} // End of OOM loop
  4304 		
  4357 		
  4305 	// cleanup
  4358 	// cleanup
  4306 	RmDir(_L("C:\\TestDEF130678\\"));	
  4359 	RmDir(_L("C:\\TestDEF130678\\"));	
  4307 	}
  4360 	}
       
  4361 
       
  4362 void TestBytesTransferredByCopyStep()
       
  4363     {
       
  4364     //
       
  4365     // Test BytesCopied
       
  4366     //
       
  4367     test.Next(_L("TestBytesTransferredByCopyStep"));
       
  4368     (void)gFileMan->Delete(_L("\\bytesTransferred"));
       
  4369     
       
  4370     RFile tempFile;
       
  4371     TFileName tempname;
       
  4372     TInt r = tempFile.Temp(TheFs,_L("\\"),tempname,EFileWrite);
       
  4373     test_KErrNone(r);
       
  4374     r = tempFile.SetSize(50);
       
  4375     test_KErrNone(r);
       
  4376     tempFile.Flush();
       
  4377     tempFile.Close();
       
  4378 
       
  4379     CFileManObserverBytesCopied* fManObserver=new(ELeave) CFileManObserverBytesCopied(gFileMan);
       
  4380     CleanupStack::PushL(fManObserver);
       
  4381     gFileMan->SetObserver(fManObserver);
       
  4382     fManObserver->iBytesToBeCopied=50;
       
  4383     
       
  4384     if (!gAsynch)
       
  4385         {
       
  4386         r=gFileMan->Copy(tempname,_L("\\bytesTransferred"),CFileMan::EOverWrite);
       
  4387         test_KErrNone(r);
       
  4388         }
       
  4389     else
       
  4390         {
       
  4391         TInt r=gFileMan->Copy(tempname,_L("\\bytesTransferred"),CFileMan::EOverWrite,gStat);
       
  4392         test_KErrNone(r);
       
  4393         WaitForSuccess();
       
  4394         }
       
  4395     
       
  4396     (void)gFileMan->Delete(_L("\\bytesTransferred"));
       
  4397     (void)TheFs.Delete(tempname);
       
  4398     CleanupStack::PopAndDestroy();
       
  4399     }
       
  4400 
       
  4401 void TestGetMoreErrorInfo()
       
  4402     {
       
  4403     //
       
  4404      // Test GetMoreErrorInfo
       
  4405      //
       
  4406      test.Next(_L("TestGetMoreErrorInfo"));
       
  4407 
       
  4408      CFileManObserver* fManObserver=new(ELeave) CFileManObserver(gFileMan);
       
  4409      CleanupStack::PushL(fManObserver);
       
  4410      gFileMan->SetObserver(fManObserver);
       
  4411      
       
  4412      if (!gAsynch)
       
  4413          {
       
  4414          TInt r=gFileMan->Copy(_L("\\SRC"),_L("\\TRG"),0);
       
  4415          if(r!=KErrNone) //correct behaviour
       
  4416              {
       
  4417              TFileManError error = gFileMan->GetMoreInfoAboutError();
       
  4418              test_Equal((TFileManError)ENoFilesProcessed,error);
       
  4419              }
       
  4420          else { test_Equal(!KErrNone,r); }
       
  4421          }
       
  4422      else
       
  4423          {
       
  4424          TInt r=gFileMan->Copy(_L("\\SRC"),_L("\\TRG"),0,gStat);
       
  4425          if(r!=KErrNone) //correct behaviour
       
  4426              {
       
  4427              TFileManError error = gFileMan->GetMoreInfoAboutError();
       
  4428              test_Equal((TFileManError)ENoFilesProcessed,error);
       
  4429              }
       
  4430          else { test_Equal(!KErrNone,r); }
       
  4431          }
       
  4432     CleanupStack::PopAndDestroy();
       
  4433     }
  4308 
  4434 
  4309 GLDEF_C void CallTestsL()
  4435 GLDEF_C void CallTestsL()
  4310 //
  4436 //
  4311 // Do tests
  4437 // Do tests
  4312 //
  4438 //
  4399 	TestMove();
  4525 	TestMove();
  4400 	TestCopyAndRename();
  4526 	TestCopyAndRename();
  4401 	TestCopyAllCancel();
  4527 	TestCopyAllCancel();
  4402 	
  4528 	
  4403 	TestDEF130678(); // Test CFileMan::Move does not leak any memory
  4529 	TestDEF130678(); // Test CFileMan::Move does not leak any memory
       
  4530 	TestBytesTransferredByCopyStep();
       
  4531 	TestGetMoreErrorInfo();
  4404 #ifndef __WINS__
  4532 #ifndef __WINS__
  4405 	RThread t;
  4533 	RThread t;
  4406 	TThreadStackInfo stack;
  4534 	TThreadStackInfo stack;
  4407 	test_KErrNone(t.StackInfo(stack));
  4535 	test_KErrNone(t.StackInfo(stack));
  4408 	TestStackUsage(0, stack);
  4536 	TestStackUsage(0, stack);
  4409 #endif
  4537 #endif
  4410 
  4538 
       
  4539 	
  4411 	Cleanup();
  4540 	Cleanup();
  4412 	DeleteTestDirectory();
  4541 	DeleteTestDirectory();
  4413 	test_KErrNone(TheFs.RmDir(_L("\\F32-TST\\")));
  4542 	test_KErrNone(TheFs.RmDir(_L("\\F32-TST\\")));
  4414 	}
  4543 	}
  4415 
  4544