|
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 // User includes |
|
19 #include "TestFSReadFile.h" |
|
20 |
|
21 // System includes |
|
22 #include <e32base.h> |
|
23 |
|
24 |
|
25 // Literal constants |
|
26 _LIT(KFileName, "filename"); |
|
27 |
|
28 CTestFSReadFile::CTestFSReadFile() |
|
29 /** |
|
30 Constructor |
|
31 */ |
|
32 { |
|
33 // Call base class method to set up the human readable name for logging |
|
34 SetTestStepName(KTestFSReadFile); |
|
35 } |
|
36 |
|
37 CTestFSReadFile::~CTestFSReadFile() |
|
38 /** |
|
39 Destructor |
|
40 */ |
|
41 { |
|
42 } |
|
43 |
|
44 TVerdict CTestFSReadFile::doTestStepL() |
|
45 /** |
|
46 This is implementation of the pure virtual function of CTestStep. |
|
47 It reads data from a file. |
|
48 @return TVerdict - the test result |
|
49 */ |
|
50 { |
|
51 TInt err = 0; |
|
52 TPtrC fileName; |
|
53 |
|
54 INFO_PRINTF1(_L("In test step ReadFile")); |
|
55 |
|
56 //Getting the file name from ini file |
|
57 if(!GetStringFromConfig(ConfigSection(), KFileName ,fileName)) |
|
58 { |
|
59 ERR_PRINTF1(_L("File Name not specified")); |
|
60 SetTestStepResult(EFail); |
|
61 } |
|
62 else |
|
63 { |
|
64 INFO_PRINTF2(_L("File to be opened is= %S "),&fileName); |
|
65 } |
|
66 |
|
67 if(TestStepResult() == EPass) |
|
68 { |
|
69 RFs fileSession; |
|
70 //Connecting to the file server |
|
71 TRAP(err, fileSession.Connect()) |
|
72 if ( err != KErrNone) |
|
73 { |
|
74 ERR_PRINTF1(_L("Failed to connect to the file server")); |
|
75 SetTestStepError(err); |
|
76 } |
|
77 else |
|
78 { |
|
79 RFile file; |
|
80 |
|
81 CleanupClosePushL(fileSession); |
|
82 //Opening the file |
|
83 err = file.Open(fileSession,fileName,EFileRead); |
|
84 if ( err != KErrNone) |
|
85 { |
|
86 ERR_PRINTF1(_L("Error in Opening file")); |
|
87 SetTestStepError(err); |
|
88 } |
|
89 else |
|
90 { |
|
91 CleanupClosePushL(file); |
|
92 TInt fileSize = 0; |
|
93 err = file.Size(fileSize); |
|
94 if(err == KErrNone) |
|
95 { |
|
96 HBufC8 *data = HBufC8::NewLC(fileSize); |
|
97 TPtr8 ptr = data->Des(); |
|
98 // RaiseInstrumentationEventNotificationL(MTestInstrumentation::EPointFilestoreReadFileStart); |
|
99 err = file.Read(ptr); |
|
100 // RaiseInstrumentationEventNotificationL(MTestInstrumentation::EPointFilestoreReadFileStop); |
|
101 if(err != KErrNone) |
|
102 { |
|
103 ERR_PRINTF1(_L("Error in reading the file")); |
|
104 SetTestStepError(err); |
|
105 } |
|
106 else |
|
107 { |
|
108 INFO_PRINTF1(_L("Read File passed with no error code")); |
|
109 SetTestStepResult(EPass); |
|
110 } |
|
111 CleanupStack::PopAndDestroy(data); |
|
112 } |
|
113 else |
|
114 { |
|
115 ERR_PRINTF1(_L("Error in finding size of the file")); |
|
116 SetTestStepError(err); |
|
117 } |
|
118 file.Close(); |
|
119 CleanupStack::PopAndDestroy(&file); |
|
120 |
|
121 } |
|
122 CleanupStack::PopAndDestroy(&fileSession); |
|
123 } |
|
124 } |
|
125 return TestStepResult(); |
|
126 } |