|
1 // Copyright (c) 2009-2010 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 // |
|
15 |
|
16 #ifndef __E32CONSF_H__ |
|
17 #define __E32CONSF_H__ |
|
18 |
|
19 #include <e32std.h> |
|
20 #include <e32cons.h> |
|
21 #include <e32test.h> |
|
22 #include <f32file.h> |
|
23 |
|
24 #include <utf.h> |
|
25 |
|
26 class CConsoleFile: public CConsoleBase |
|
27 { |
|
28 public: |
|
29 static CConsoleFile* New(const TDesC& aLogFileName) |
|
30 { |
|
31 CConsoleFile* self = new CConsoleFile(); |
|
32 if (self) |
|
33 { |
|
34 if (self->Construct(aLogFileName)) |
|
35 { |
|
36 delete self; |
|
37 self = NULL; |
|
38 } |
|
39 } |
|
40 return self; |
|
41 } |
|
42 |
|
43 virtual ~CConsoleFile() |
|
44 { |
|
45 iFile.Close(); |
|
46 iFs.Close(); |
|
47 } |
|
48 |
|
49 private: |
|
50 CConsoleFile() |
|
51 :CConsoleBase() |
|
52 { |
|
53 } |
|
54 |
|
55 TInt Construct(const TDesC& aLogFileName) |
|
56 { |
|
57 TInt err=iFs.Connect(); |
|
58 if (!err) |
|
59 { |
|
60 (void)iFs.MkDirAll(aLogFileName); |
|
61 if (iFile.Replace(iFs, aLogFileName, EFileShareExclusive | EFileWrite)) |
|
62 { |
|
63 err=iFile.Create(iFs, aLogFileName, EFileShareExclusive | EFileWrite); |
|
64 } |
|
65 } |
|
66 return err; |
|
67 } |
|
68 |
|
69 void DoWriteL(const TDesC &aDes) |
|
70 { |
|
71 HBufC8* outBuf = CnvUtfConverter::ConvertFromUnicodeToUtf8L(aDes); |
|
72 (void)iFile.Write(*outBuf); |
|
73 delete outBuf; |
|
74 } |
|
75 |
|
76 private: // CConsoleBase |
|
77 virtual TInt Create(const TDesC& /*aTitle*/,TSize /*aSize*/) |
|
78 { |
|
79 return KErrNone; |
|
80 } |
|
81 |
|
82 virtual void Read(TRequestStatus& aStatus) |
|
83 { |
|
84 TRequestStatus* status = &aStatus; |
|
85 User::RequestComplete(status, (TInt)EKeyNull); |
|
86 } |
|
87 |
|
88 virtual void ReadCancel() |
|
89 { |
|
90 } |
|
91 |
|
92 virtual void Write(const TDesC &aDes) |
|
93 { |
|
94 // so that RTest::Title can be called before the TrapHandler has been created |
|
95 CTrapCleanup* tc = NULL; |
|
96 if (!User::TrapHandler()) |
|
97 { |
|
98 tc = CTrapCleanup::New(); |
|
99 } |
|
100 TRAP_IGNORE(DoWriteL(aDes)); |
|
101 delete tc; |
|
102 } |
|
103 |
|
104 virtual TPoint CursorPos() const |
|
105 { |
|
106 return TPoint(0,0); |
|
107 } |
|
108 |
|
109 virtual void SetCursorPosAbs(const TPoint& /*aPoint*/) |
|
110 { |
|
111 } |
|
112 |
|
113 virtual void SetCursorPosRel(const TPoint& /*aPoint*/) |
|
114 { |
|
115 } |
|
116 |
|
117 virtual void SetCursorHeight(TInt /*aPercentage*/) |
|
118 { |
|
119 } |
|
120 |
|
121 virtual void SetTitle(const TDesC& /*aTitle*/) |
|
122 { |
|
123 } |
|
124 |
|
125 virtual void ClearScreen() |
|
126 { |
|
127 } |
|
128 |
|
129 virtual void ClearToEndOfLine() |
|
130 { |
|
131 } |
|
132 |
|
133 virtual TSize ScreenSize() const |
|
134 { |
|
135 return TSize(0,0); |
|
136 } |
|
137 |
|
138 virtual TKeyCode KeyCode() const |
|
139 { |
|
140 return EKeyNull; |
|
141 } |
|
142 |
|
143 virtual TUint KeyModifiers() const |
|
144 { |
|
145 return 0; |
|
146 } |
|
147 |
|
148 private: |
|
149 RFs iFs; |
|
150 RFile iFile; |
|
151 }; |
|
152 |
|
153 void LogRTestToFile(RTest& aTest) |
|
154 { |
|
155 RProcess myProcess; |
|
156 TParsePtrC parsePtr(myProcess.FileName()); |
|
157 TFileName logFileName; |
|
158 logFileName.Format(_L("c:\\logs\\testexecute\\%S.htm"), &parsePtr.Name()); |
|
159 aTest.SetConsole(CConsoleFile::New(logFileName)); // SMH - Setting NULL console is OK |
|
160 } |
|
161 |
|
162 #endif // __E32CONSF_H__ |
|
163 |