Update contrib.
1 // Copyright (c) 2002-2009 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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // This file contains the test steps for Unit Test Suite 22 : LogFile.cpp
21 // Test system includes
22 #include <testframework.h>
24 // Specific includes for this test suite
25 #include "TSU_MmTsthSuite22.h"
27 // Specific includes for these test steps
28 #include "TSU_MmTsth22.h"
29 #include "TestFrameworkServer/LogFile.h"
31 // --------------------------------------------
33 // Unit Test Suite 22 : LogFile.cpp
39 // Open an existing file log
40 // Write to an open file log
42 // Open and close a file server session
45 RTestMmTsthU2201* RTestMmTsthU2201::NewL()
47 RTestMmTsthU2201* self = new(ELeave) RTestMmTsthU2201;
51 // Each test step initialises its own name.
52 RTestMmTsthU2201::RTestMmTsthU2201()
54 iTestStepName = _L("MM-TSTH-U-2201");
58 TVerdict RTestMmTsthU2201::OpenL()
60 // ensure the directory for our test log exists
62 // parse the filenames
63 _LIT(KDefault,"C:\\");
64 _LIT(KLogPath, "C:\\Logs\\TestResults\\TestFrameworkTemp\\");
66 TInt returnCode = fullFileName.Set(KLogPath, &KDefault, NULL);
67 if (returnCode != KErrNone)
69 ERR_PRINTF3(_L("Preamble : failed to set file name %S, error %d"),
70 &fullFileName.FullName(), returnCode);
71 return iTestStepResult = EFail;
75 returnCode=fileSystem.Connect();
76 if (returnCode != KErrNone)
78 ERR_PRINTF2(_L("Preamble : failed to connect to file server, error %d"),
81 return iTestStepResult = EFail;
84 returnCode = fileSystem.MkDir(fullFileName.DriveAndPath());
85 if (returnCode != KErrNone && returnCode != KErrAlreadyExists)
87 ERR_PRINTF3(_L("Preamble : failed to make directory %S, error %d"),
88 &fullFileName.FullName(), returnCode);
90 return iTestStepResult = EFail;
94 return iTestStepResult = EPass;
98 void RTestMmTsthU2201::Close()
100 // clean up the test directory we created in the preamble
102 // parse the filenames
103 _LIT(KDefault,"C:\\");
104 _LIT(KLogPath, "C:\\Logs\\TestResults\\TestFrameworkTemp\\");
106 TInt returnCode = fullFileName.Set(KLogPath, &KDefault, NULL);
107 if (returnCode != KErrNone)
109 ERR_PRINTF3(_L("RTestMmTsthU2201::Close() failed to set file name %S, error %d"),
110 &fullFileName.FullName(), returnCode);
115 returnCode=fileSystem.Connect();
116 if (returnCode != KErrNone)
118 ERR_PRINTF2(_L("RTestMmTsthU2201::Close() failed to connect to file server, error %d"),
124 returnCode = fileSystem.RmDir(fullFileName.DriveAndPath());
125 if (returnCode != KErrNone)
127 ERR_PRINTF3(_L("RTestMmTsthU2201::Close() failed to remove directory %S, error %d"),
128 &fullFileName.FullName(), returnCode);
135 TVerdict RTestMmTsthU2201::DoTestStepL()
137 INFO_PRINTF1(_L("Unit test for CFileLogger"));
139 TVerdict currentVerdict = EPass;
141 // create a CFileLogger
142 CFileLogger* theFileLogger = new CFileLogger();
145 ERR_PRINTF1(_L("Failed to create a CFileLogger"));
146 return iTestStepResult = EFail;
149 // directory path as created in the Preamble
150 _LIT(KLogName, "CFileLoggerTest");
151 _LIT(KLogPath, "C:\\Logs\\TestResults\\TestFrameworkTemp");
152 _LIT(KDefault, "C:\\.htm");
154 // ensure the path exists
156 parseLogName.Set(KLogName, NULL, NULL);
158 TFileName logFilePath;
159 logFilePath = KLogPath;
161 if(parseLogName.PathPresent())
162 logFilePath.Append(parseLogName.Path());
164 logFilePath.Append(_L("\\"));
166 // overwrite extension if supplied with .htm
167 TParse logFileFullName;
168 TInt returnCode = logFileFullName.Set(KDefault, &logFilePath, &KLogName());
169 if (returnCode == KErrNone)
171 TInt ret = theFileLogger->Connect();
174 theFileLogger->CreateLog(logFilePath, logFileFullName.NameAndExt());
178 ERR_PRINTF1(_L("CFileLogger could not connect to file server"));
179 delete theFileLogger;
180 return iTestStepResult = EFail;
184 _LIT(KFileLogTestString, "CFileLoggerTest Verification");
185 _LIT8(KFileLogTestString8, "CFileLoggerTest Verification");
188 theFileLogger->WriteLog(KFileLogTestString);
192 returnCode=fileSystem.Connect();
193 if (returnCode != KErrNone)
195 ERR_PRINTF2(_L("Failed to connect to file server, error %d"),
197 theFileLogger->Close();
198 delete theFileLogger;
199 return iTestStepResult = EFail;
203 logFile.Format(_L("%S\\%S.htm"), &KLogPath(), &KLogName());
205 returnCode = theFile.Open(fileSystem, logFile, EFileRead | EFileStreamText | EFileShareAny);
207 // NB :- We're reading in 8-bit, so need to compare against an 8-bit string literal
209 returnCode = theFile.Size(fileSize);
210 TPtr8 theString(REINTERPRET_CAST(TUint8*,User::AllocLC(fileSize)), 0, fileSize);
211 theFile.Read(theString, fileSize);
213 returnCode = theString.Find(KFileLogTestString8());
215 // see if our string is present. if it is, we've passed.
216 if(returnCode == KErrNotFound)
218 ERR_PRINTF1(_L("Test string not found in test log file!"));
219 currentVerdict = EFail;
223 INFO_PRINTF2(_L("Read string %S found in test file"), &KFileLogTestString());
226 // close file logger session
227 theFileLogger->Close();
230 fileSystem.Delete(logFile);
232 delete(theFileLogger);
233 CleanupStack::PopAndDestroy(); // theString
235 return iTestStepResult = currentVerdict; // should be EPass if we've got here