videocollection/mpxmyvideoscollection/tsrc/mpxmvcolltest/src/VCXMyVideosTestUtils.cpp
changeset 41 229f037ce963
parent 34 bbb98528c666
equal deleted inserted replaced
40:13331705e488 41:229f037ce963
    95     return error;
    95     return error;
    96     }
    96     }
    97 
    97 
    98 
    98 
    99 // -----------------------------------------------------------------------------
    99 // -----------------------------------------------------------------------------
   100 // CVCXMyVideosTestUtils::CreateVideoFilesL
   100 // CVCXMyVideosTestUtils::CreateVideoFileL
   101 // -----------------------------------------------------------------------------
   101 // -----------------------------------------------------------------------------
   102 //
   102 //
   103 void CVCXMyVideosTestUtils::CreateVideoFileL( TVcxTestVideoType aVideoType, TDesC& aFileName, TInt aSize )
   103 void CVCXMyVideosTestUtils::CreateVideoFileL( TVcxTestVideoType aVideoType, TDesC& aFileName, TInt aSize, TBool aUniqueName )
   104     {
   104     {
   105     VCXLOGLO1(">>>CVcxTestVideoCreator::CreateVideoL");
   105     VCXLOGLO1(">>>CVcxTestVideoCreator::CreateVideoL");
   106 
   106 
   107         // Resolve source filename
   107     // Resolve source filename
   108         TBuf<256> srcFileName;
   108     TBuf<256> srcFileName;
   109 
   109 
   110         GetVideoFile( srcFileName, aVideoType, _L("C") );
   110     GetVideoFile( srcFileName, aVideoType, _L("C") );
       
   111     if( !BaflUtils::FileExists(iFs, srcFileName) )
       
   112         {
       
   113         VCXLOGLO2("CVcxTestVideoCreator:: %S does not exist.", &srcFileName);
       
   114         GetVideoFile( srcFileName, aVideoType, _L("E") );
   111         if( !BaflUtils::FileExists(iFs, srcFileName) )
   115         if( !BaflUtils::FileExists(iFs, srcFileName) )
   112             {
   116             {
   113             VCXLOGLO2("CVcxTestVideoCreator:: %S does not exist.", &srcFileName);
   117             VCXLOGLO2("CVcxTestVideoCreator:: %S does not exist.", &srcFileName);
   114             GetVideoFile( srcFileName, aVideoType, _L("E") );
   118             VCXLOGLO2("CVcxTestVideoCreator:: test video file %S missing! PANIC.", &srcFileName);
   115             if( !BaflUtils::FileExists(iFs, srcFileName) )
   119             User::Panic(_L("Video files missing!"), KErrNotFound);
       
   120             }
       
   121         }
       
   122     
       
   123     BaflUtils::EnsurePathExistsL( iFs, aFileName.Left( aFileName.LocateReverse('\\') ) );
       
   124 
       
   125     HBufC* newFileName = HBufC::NewL( 256 );
       
   126     CleanupStack::PushL( newFileName );
       
   127     
       
   128     if(!aUniqueName)
       
   129     {
       
   130         newFileName->Des().Copy( aFileName );
       
   131         BaflUtils::DeleteFile( iFs, aFileName );
       
   132     }
       
   133     else
       
   134     {
       
   135         newFileName->Des().Copy( aFileName );
       
   136         TInt dotPos = aFileName.LocateReverse('.');
       
   137         int count = 0;
       
   138         while( BaflUtils::FileExists( iFs, *newFileName ) )
       
   139         {
       
   140             newFileName->Des().Copy( aFileName.Left( aFileName.LocateReverse('\\') ) );
       
   141             newFileName->Des().Copy( aFileName.Left( dotPos ) );
       
   142             newFileName->Des().Append( _L("_") );
       
   143             newFileName->Des().AppendNum( count++ );
       
   144             newFileName->Des().Append( aFileName.Right( aFileName.Length() - dotPos ) );
       
   145         }
       
   146     }
       
   147     
       
   148     VCXLOGLO2("CVcxTestVideoCreator:: aSize = %d", aSize);
       
   149     
       
   150     TInt64 wantedSize( 0 );
       
   151     
       
   152     // Check the size
       
   153     if( aSize == KVcxTestLargeFile3GB ) {
       
   154         wantedSize = 1024*1024*1024 * 3;
       
   155     }
       
   156     else {
       
   157         wantedSize = aSize;
       
   158     }
       
   159     
       
   160     //wantedSize = wantedSize == 0 ? wantedSize -1 : wantedSize;
       
   161     
       
   162     VCXLOGLO2("CVcxTestVideoCreator:: Wanted file size: %Ld", wantedSize);
       
   163 
       
   164     // Read source file into memory, won't work on huge files.
       
   165     RFile64 srcFile;
       
   166     VCXLOGLO2("CVcxTestVideoCreator:: Opening %S", &srcFileName);
       
   167     User::LeaveIfError( srcFile.Open( iFs, srcFileName, EFileRead ) );
       
   168     CleanupClosePushL( srcFile );
       
   169 
       
   170     TInt64 srcSize(0);
       
   171     VCXLOGLO2("CVcxTestVideoCreator:: Getting size of %S", &srcFileName);
       
   172     User::LeaveIfError( srcFile.Size( srcSize ) );
       
   173 
       
   174     HBufC8* data = HBufC8::NewL( srcSize );
       
   175     TPtr8 ptr( data->Des() );
       
   176     srcFile.Read( ptr, srcSize );
       
   177     CleanupStack::PopAndDestroy( &srcFile );
       
   178 
       
   179     CleanupStack::PushL( data );
       
   180 
       
   181     // Write new file.
       
   182     RFile64 dstFile;
       
   183     VCXLOGLO1("CVcxTestVideoCreator:: Replace");
       
   184     User::LeaveIfError( dstFile.Replace( iFs, *newFileName, EFileWrite ) );
       
   185     CleanupClosePushL(dstFile);
       
   186 
       
   187     if( wantedSize <= srcSize )
       
   188         {
       
   189         if( wantedSize == -1 )
       
   190             {
       
   191             VCXLOGLO2("CVcxTestVideoCreator:: Writing %Ld", srcSize);
       
   192             User::LeaveIfError( dstFile.Write( *data, srcSize ) );
       
   193             }
       
   194         else
       
   195             {
       
   196             VCXLOGLO2("CVcxTestVideoCreator:: Writing %Ld", wantedSize);
       
   197             User::LeaveIfError( dstFile.Write( *data, wantedSize ) );
       
   198             }
       
   199         }
       
   200     else
       
   201         {
       
   202         VCXLOGLO2("CVcxTestVideoCreator:: Writing %Ld", srcSize);
       
   203         User::LeaveIfError( dstFile.Write( *data, srcSize ) );
       
   204 
       
   205         const TInt KVcxTest200Kilos = 1024*200;
       
   206         HBufC8* buff = HBufC8::NewL( KVcxTest200Kilos );
       
   207         buff->Des().SetLength( KVcxTest200Kilos );
       
   208         CleanupStack::PushL( buff );
       
   209         TInt64 bytesToWrite = wantedSize - srcSize;
       
   210         while( bytesToWrite > 0 )
       
   211             {
       
   212             if( bytesToWrite >= KVcxTest200Kilos )
   116                 {
   213                 {
   117                 VCXLOGLO2("CVcxTestVideoCreator:: %S does not exist.", &srcFileName);
   214                 bytesToWrite -= KVcxTest200Kilos;
   118                 VCXLOGLO2("CVcxTestVideoCreator:: test video file %S missing! PANIC.", &srcFileName);
   215                 User::LeaveIfError( dstFile.Write( *buff ) );
   119                 User::Panic(_L("Video files missing!"), KErrNotFound);
       
   120                 }
       
   121             }
       
   122         
       
   123         BaflUtils::EnsurePathExistsL( iFs, aFileName.Left( aFileName.LocateReverse('\\') ) );
       
   124 
       
   125         BaflUtils::DeleteFile( iFs, aFileName );
       
   126         
       
   127         VCXLOGLO2("CVcxTestVideoCreator:: aSize = %d", aSize);
       
   128         
       
   129         TInt64 wantedSize( 0 );
       
   130         
       
   131         // Check the size
       
   132         if( aSize == KVcxTestLargeFile3GB ) {
       
   133             wantedSize = 1024*1024*1024 * 3;
       
   134         }
       
   135         else {
       
   136             wantedSize = aSize;
       
   137         }
       
   138         
       
   139         //wantedSize = wantedSize == 0 ? wantedSize -1 : wantedSize;
       
   140         
       
   141         VCXLOGLO2("CVcxTestVideoCreator:: Wanted file size: %Ld", wantedSize);
       
   142 
       
   143         // Read source file into memory, won't work on huge files.
       
   144         RFile64 srcFile;
       
   145         VCXLOGLO2("CVcxTestVideoCreator:: Opening %S", &srcFileName);
       
   146         User::LeaveIfError( srcFile.Open( iFs, srcFileName, EFileRead ) );
       
   147         CleanupClosePushL( srcFile );
       
   148 
       
   149         TInt64 srcSize(0);
       
   150         VCXLOGLO2("CVcxTestVideoCreator:: Getting size of %S", &srcFileName);
       
   151         User::LeaveIfError( srcFile.Size( srcSize ) );
       
   152 
       
   153         HBufC8* data = HBufC8::NewL( srcSize );
       
   154         TPtr8 ptr( data->Des() );
       
   155         srcFile.Read( ptr, srcSize );
       
   156         CleanupStack::PopAndDestroy( &srcFile );
       
   157 
       
   158         CleanupStack::PushL( data );
       
   159 
       
   160         // Write new file.
       
   161         RFile64 dstFile;
       
   162         VCXLOGLO1("CVcxTestVideoCreator:: Replace");
       
   163         User::LeaveIfError( dstFile.Replace( iFs, aFileName, EFileWrite ) );
       
   164         CleanupClosePushL(dstFile);
       
   165 
       
   166         if( wantedSize <= srcSize )
       
   167             {
       
   168             if( wantedSize == -1 )
       
   169                 {
       
   170                 VCXLOGLO2("CVcxTestVideoCreator:: Writing %Ld", srcSize);
       
   171                 User::LeaveIfError( dstFile.Write( *data, srcSize ) );
       
   172                 }
   216                 }
   173             else
   217             else
   174                 {
   218                 {
   175                 VCXLOGLO2("CVcxTestVideoCreator:: Writing %Ld", wantedSize);
   219                 User::LeaveIfError( dstFile.Write( *buff, bytesToWrite ) );
   176                 User::LeaveIfError( dstFile.Write( *data, wantedSize ) );
   220                 bytesToWrite = 0;
   177                 }
   221                 }
   178             }
   222             }
   179         else
   223         CleanupStack::PopAndDestroy( buff );
   180             {
   224         }
   181             VCXLOGLO2("CVcxTestVideoCreator:: Writing %Ld", srcSize);
   225 
   182             User::LeaveIfError( dstFile.Write( *data, srcSize ) );
   226     CleanupStack::PopAndDestroy( &dstFile );
   183 
   227     CleanupStack::PopAndDestroy( data );
   184             const TInt KVcxTest200Kilos = 1024*200;
   228     
   185             HBufC8* buff = HBufC8::NewL( KVcxTest200Kilos );
   229     CleanupStack::PopAndDestroy( newFileName );
   186             buff->Des().SetLength( KVcxTest200Kilos );
   230 
   187             CleanupStack::PushL( buff );
   231     VCXLOGLO1("<<<CVcxTestVideoCreator::CreateVideoL");
   188             TInt64 bytesToWrite = wantedSize - srcSize;
       
   189             while( bytesToWrite > 0 )
       
   190                 {
       
   191                 if( bytesToWrite >= KVcxTest200Kilos )
       
   192                     {
       
   193                     bytesToWrite -= KVcxTest200Kilos;
       
   194                     User::LeaveIfError( dstFile.Write( *buff ) );
       
   195                     }
       
   196                 else
       
   197                     {
       
   198                     User::LeaveIfError( dstFile.Write( *buff, bytesToWrite ) );
       
   199                     bytesToWrite = 0;
       
   200                     }
       
   201                 }
       
   202             CleanupStack::PopAndDestroy( buff );
       
   203             }
       
   204 
       
   205         CleanupStack::PopAndDestroy( &dstFile );
       
   206         CleanupStack::PopAndDestroy( data );
       
   207 
       
   208         VCXLOGLO1("<<<CVcxTestVideoCreator::CreateVideoL");
       
   209     }
   232     }
   210 
   233 
   211 
   234 
   212 // -----------------------------------------------------------------------------
   235 // -----------------------------------------------------------------------------
   213 // CVCXMyVideosTestUtils::CreateVideoFilesL
   236 // CVCXMyVideosTestUtils::CreateVideoFilesL