|
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 #include <utf.h> |
|
21 |
|
22 _LIT( KResultDirectory, "\\sut\\" ); |
|
23 _LIT8( KDateAndTimeFormat, "%02d.%02d.%04d @ %02d:%02d:%02d" ); |
|
24 |
|
25 // ----------------------------------------------------------------------------- |
|
26 // |
|
27 // ----------------------------------------------------------------------------- |
|
28 // |
|
29 CSymbianUnitTestFileOutputWriter* CSymbianUnitTestFileOutputWriter::NewLC( |
|
30 const TDesC& aFileName ) |
|
31 { |
|
32 CSymbianUnitTestFileOutputWriter* self = |
|
33 new( ELeave )CSymbianUnitTestFileOutputWriter(); |
|
34 CleanupStack::PushL( self ); |
|
35 self->ConstructL( aFileName ); |
|
36 return self; |
|
37 } |
|
38 |
|
39 // ----------------------------------------------------------------------------- |
|
40 // |
|
41 // ----------------------------------------------------------------------------- |
|
42 // |
|
43 CSymbianUnitTestFileOutputWriter* CSymbianUnitTestFileOutputWriter::NewL( |
|
44 const TDesC& aFileName ) |
|
45 { |
|
46 CSymbianUnitTestFileOutputWriter* self = |
|
47 CSymbianUnitTestFileOutputWriter::NewLC( aFileName ); |
|
48 CleanupStack::Pop( self ); |
|
49 return self; |
|
50 } |
|
51 |
|
52 // ----------------------------------------------------------------------------- |
|
53 // |
|
54 // ----------------------------------------------------------------------------- |
|
55 // |
|
56 void CSymbianUnitTestFileOutputWriter::ConstructL( const TDesC& aFileName ) |
|
57 { |
|
58 User::LeaveIfError( iRFs.Connect() ); |
|
59 TInt err = iRFs.MkDir( KResultDirectory ); |
|
60 if ( err == KErrNoMemory ) |
|
61 { |
|
62 // Ignore the other errors. The directory may already exist. |
|
63 User::Leave( err ); |
|
64 } |
|
65 User::LeaveIfError( iRFs.SetSessionPath( KResultDirectory ) ); |
|
66 User::LeaveIfError( iFile.Replace( iRFs, aFileName, EFileWrite ) ); |
|
67 } |
|
68 |
|
69 // ----------------------------------------------------------------------------- |
|
70 // |
|
71 // ----------------------------------------------------------------------------- |
|
72 // |
|
73 CSymbianUnitTestFileOutputWriter::CSymbianUnitTestFileOutputWriter() |
|
74 { |
|
75 } |
|
76 |
|
77 // ----------------------------------------------------------------------------- |
|
78 // |
|
79 // ----------------------------------------------------------------------------- |
|
80 // |
|
81 CSymbianUnitTestFileOutputWriter::~CSymbianUnitTestFileOutputWriter() |
|
82 { |
|
83 iFile.Close(); |
|
84 iRFs.Close(); |
|
85 } |
|
86 |
|
87 // ----------------------------------------------------------------------------- |
|
88 // |
|
89 // ----------------------------------------------------------------------------- |
|
90 // |
|
91 void CSymbianUnitTestFileOutputWriter::WriteDateAndTimeL() |
|
92 { |
|
93 TTime time; |
|
94 time.HomeTime(); |
|
95 TDateTime dateTime( time.DateTime() ); |
|
96 HBufC8* buf = HBufC8::NewLC( KDateAndTimeFormat().Length() ); |
|
97 buf->Des().Format( KDateAndTimeFormat(), dateTime.Day()+1, |
|
98 dateTime.Month()+1, dateTime.Year(), dateTime.Hour(), |
|
99 dateTime.Minute(), dateTime.Second() ); |
|
100 User::LeaveIfError( iFile.Write( *buf ) ); |
|
101 CleanupStack::PopAndDestroy( buf ); |
|
102 } |
|
103 |
|
104 // ----------------------------------------------------------------------------- |
|
105 // |
|
106 // ----------------------------------------------------------------------------- |
|
107 // |
|
108 void CSymbianUnitTestFileOutputWriter::WriteL( const TDesC8& aValue ) |
|
109 { |
|
110 User::LeaveIfError( iFile.Write( aValue ) ); |
|
111 } |
|
112 |
|
113 // ----------------------------------------------------------------------------- |
|
114 // |
|
115 // ----------------------------------------------------------------------------- |
|
116 // |
|
117 void CSymbianUnitTestFileOutputWriter::WriteL( const TDesC& aValue ) |
|
118 { |
|
119 HBufC8* value = CnvUtfConverter::ConvertFromUnicodeToUtf8L(aValue); |
|
120 CleanupStack::PushL(value); |
|
121 User::LeaveIfError( iFile.Write( *value ) ); |
|
122 CleanupStack::PopAndDestroy( value ); |
|
123 } |
|
124 |
|
125 // ----------------------------------------------------------------------------- |
|
126 // |
|
127 // ----------------------------------------------------------------------------- |
|
128 // |
|
129 void CSymbianUnitTestFileOutputWriter::WriteL( |
|
130 const TDesC8& aFormat, |
|
131 TInt aValue ) |
|
132 { |
|
133 const TInt KIntAsTextMaxLength( 20 ); |
|
134 HBufC8* buf = HBufC8::NewLC( aFormat.Length() + KIntAsTextMaxLength ); |
|
135 buf->Des().Format( aFormat, aValue ); |
|
136 User::LeaveIfError( iFile.Write( *buf ) ); |
|
137 CleanupStack::PopAndDestroy( buf ); |
|
138 } |