testexecfw/symbianunittestfw/sutfw/sutfwcore/sutfwoutput/src/symbianunittestfileoutputwriter.cpp
changeset 0 3e07fef1e154
child 1 bbd31066657e
equal deleted inserted replaced
-1:000000000000 0:3e07fef1e154
       
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  
       
    15 *
       
    16 */
       
    17 
       
    18 #include "symbianunittestfileoutputwriter.h"
       
    19 #include "symbianunittestuicallback.h"
       
    20 
       
    21 _LIT( KResultDirectory, "\\sut\\" );
       
    22 _LIT8( KDateAndTimeFormat, "%02d.%02d.%04d @ %02d:%02d:%02d" );
       
    23 
       
    24 // -----------------------------------------------------------------------------
       
    25 //
       
    26 // -----------------------------------------------------------------------------
       
    27 //
       
    28 CSymbianUnitTestFileOutputWriter* CSymbianUnitTestFileOutputWriter::NewLC( 
       
    29     const TDesC& aFileName )
       
    30     {
       
    31     CSymbianUnitTestFileOutputWriter* self = 
       
    32         new( ELeave )CSymbianUnitTestFileOutputWriter();
       
    33     CleanupStack::PushL( self );
       
    34     self->ConstructL( aFileName );
       
    35     return self;
       
    36     }
       
    37 
       
    38 // -----------------------------------------------------------------------------
       
    39 //
       
    40 // -----------------------------------------------------------------------------
       
    41 //
       
    42 CSymbianUnitTestFileOutputWriter* CSymbianUnitTestFileOutputWriter::NewL( 
       
    43     const TDesC& aFileName )
       
    44     {
       
    45     CSymbianUnitTestFileOutputWriter* self = 
       
    46         CSymbianUnitTestFileOutputWriter::NewLC( aFileName );
       
    47     CleanupStack::Pop( self );
       
    48     return self;
       
    49     }
       
    50 
       
    51 // -----------------------------------------------------------------------------
       
    52 //
       
    53 // -----------------------------------------------------------------------------
       
    54 //
       
    55 void CSymbianUnitTestFileOutputWriter::ConstructL( const TDesC& aFileName )
       
    56     {
       
    57     User::LeaveIfError( iRFs.Connect() );
       
    58     TInt err = iRFs.MkDir( KResultDirectory );
       
    59     if ( err == KErrNoMemory )
       
    60         {
       
    61         // Ignore the other errors. The directory may already exist.
       
    62         User::Leave( err );
       
    63         }
       
    64     User::LeaveIfError( iRFs.SetSessionPath( KResultDirectory ) );
       
    65     User::LeaveIfError( iFile.Replace( iRFs, aFileName, EFileWrite ) );
       
    66     }
       
    67 
       
    68 // -----------------------------------------------------------------------------
       
    69 //
       
    70 // -----------------------------------------------------------------------------
       
    71 //
       
    72 CSymbianUnitTestFileOutputWriter::CSymbianUnitTestFileOutputWriter()
       
    73     {
       
    74     }
       
    75 
       
    76 // -----------------------------------------------------------------------------
       
    77 //
       
    78 // -----------------------------------------------------------------------------
       
    79 //
       
    80 CSymbianUnitTestFileOutputWriter::~CSymbianUnitTestFileOutputWriter()
       
    81     {
       
    82     iFile.Close();
       
    83     iRFs.Close();
       
    84     }
       
    85 
       
    86 // -----------------------------------------------------------------------------
       
    87 //
       
    88 // -----------------------------------------------------------------------------
       
    89 //
       
    90 void CSymbianUnitTestFileOutputWriter::WriteDateAndTimeL()
       
    91     {
       
    92     TTime time;
       
    93     time.HomeTime();   
       
    94     TDateTime dateTime( time.DateTime() );
       
    95     HBufC8* buf = HBufC8::NewLC( KDateAndTimeFormat().Length() );
       
    96     buf->Des().Format( KDateAndTimeFormat(), dateTime.Day()+1, 
       
    97                        dateTime.Month()+1, dateTime.Year(), dateTime.Hour(), 
       
    98                        dateTime.Minute(), dateTime.Second() );
       
    99     User::LeaveIfError( iFile.Write( *buf ) );
       
   100     CleanupStack::PopAndDestroy( buf );
       
   101     }
       
   102 
       
   103 // -----------------------------------------------------------------------------
       
   104 //
       
   105 // -----------------------------------------------------------------------------
       
   106 //
       
   107 void CSymbianUnitTestFileOutputWriter::WriteL( const TDesC8& aValue )
       
   108     {
       
   109     User::LeaveIfError( iFile.Write( aValue ) );
       
   110     }
       
   111 
       
   112 // -----------------------------------------------------------------------------
       
   113 //
       
   114 // -----------------------------------------------------------------------------
       
   115 //
       
   116 void CSymbianUnitTestFileOutputWriter::WriteL( 
       
   117     const TDesC8& aFormat, 
       
   118     TInt aValue )
       
   119     {
       
   120     const TInt KIntAsTextMaxLength( 20 );
       
   121     HBufC8* buf = HBufC8::NewLC( aFormat.Length() + KIntAsTextMaxLength );
       
   122     buf->Des().Format( aFormat, aValue );
       
   123     User::LeaveIfError( iFile.Write( *buf ) );
       
   124     CleanupStack::PopAndDestroy( buf );
       
   125     }