0
|
1 |
// Copyright (c) 2006-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".
|
|
7 |
//
|
|
8 |
// Initial Contributors:
|
|
9 |
// Nokia Corporation - initial contribution.
|
|
10 |
//
|
|
11 |
// Contributors:
|
|
12 |
//
|
|
13 |
// Description:
|
|
14 |
//
|
|
15 |
|
|
16 |
#include <f32file.h>
|
|
17 |
#include "tsu_mmf_mmruf_step.h"
|
|
18 |
|
|
19 |
|
|
20 |
// These directories contain files that RUF shouldn't recognise.
|
|
21 |
static const TText* const KDirPaths[] =
|
|
22 |
{
|
|
23 |
_S("c:\\recog\\common\\")
|
|
24 |
};
|
|
25 |
|
|
26 |
#define KDirPathsCount sizeof(KDirPaths) / sizeof(const TText*)
|
|
27 |
|
|
28 |
//
|
|
29 |
//
|
|
30 |
//
|
|
31 |
RMMRUFDirTestStep::RMMRUFDirTestStep()
|
|
32 |
{
|
|
33 |
iTestStepName = _L("MM-MMF-MMRUF-U-0400-HP");
|
|
34 |
}
|
|
35 |
|
|
36 |
//
|
|
37 |
//
|
|
38 |
//
|
|
39 |
RMMRUFDirTestStep::~RMMRUFDirTestStep()
|
|
40 |
{
|
|
41 |
Close();
|
|
42 |
}
|
|
43 |
|
|
44 |
//
|
|
45 |
//
|
|
46 |
//
|
|
47 |
RMMRUFDirTestStep* RMMRUFDirTestStep::NewL()
|
|
48 |
{
|
|
49 |
return new(ELeave) RMMRUFDirTestStep();
|
|
50 |
}
|
|
51 |
|
|
52 |
//
|
|
53 |
//
|
|
54 |
//
|
|
55 |
TVerdict RMMRUFDirTestStep::DoTestStepL()
|
|
56 |
{
|
|
57 |
TInt err;
|
|
58 |
TBool failed;
|
|
59 |
RAppArc appArc;
|
|
60 |
TVerdict verdict = EPass;
|
|
61 |
|
|
62 |
err = appArc.Connect();
|
|
63 |
if (err != KErrNone)
|
|
64 |
{
|
|
65 |
INFO_PRINTF2(_L("RAppArc.Connect() failed with: %d"), err);
|
|
66 |
return EInconclusive;
|
|
67 |
}
|
|
68 |
CleanupClosePushL(appArc);
|
|
69 |
|
|
70 |
for (TInt i = 0; i < KDirPathsCount; i++)
|
|
71 |
{
|
|
72 |
const TDesC& curDirectory = TPtrC(KDirPaths[i]);
|
|
73 |
INFO_PRINTF2(_L("Checking files in directory: %S"), &curDirectory);
|
|
74 |
|
|
75 |
TRAP(err, CheckFilesInDirectoryL(appArc, curDirectory, failed));
|
|
76 |
switch (err)
|
|
77 |
{
|
|
78 |
case KErrNone:
|
|
79 |
break;
|
|
80 |
|
|
81 |
case KErrPathNotFound:
|
|
82 |
// The test hasn't really failed.
|
|
83 |
INFO_PRINTF1(_L(" - This directory cannot be found"));
|
|
84 |
break;
|
|
85 |
|
|
86 |
default:
|
|
87 |
INFO_PRINTF2(_L("CheckFilesInDirectoryL left with %d"), err);
|
|
88 |
User::Leave(err);
|
|
89 |
}
|
|
90 |
|
|
91 |
if (failed)
|
|
92 |
{
|
|
93 |
// Even though a failure was seen, keep going until all files have been checked.
|
|
94 |
verdict = EFail;
|
|
95 |
}
|
|
96 |
}
|
|
97 |
|
|
98 |
CleanupStack::PopAndDestroy(&appArc);
|
|
99 |
return verdict;
|
|
100 |
}
|
|
101 |
|
|
102 |
//
|
|
103 |
//
|
|
104 |
//
|
|
105 |
void RMMRUFDirTestStep::CheckFilesInDirectoryL(RAppArc& aAppArc, const TDesC& aDirPath, TBool& aFailure)
|
|
106 |
{
|
|
107 |
CDir* pDir = NULL;
|
|
108 |
CDirScan* pDirScan = CDirScan::NewLC(aAppArc.FileServer());
|
|
109 |
pDirScan->SetScanDataL(aDirPath, KEntryAttNormal, CDirScan::EScanDownTree);
|
|
110 |
pDirScan->NextL(pDir);
|
|
111 |
CleanupStack::PushL(pDir);
|
|
112 |
|
|
113 |
TBuf<KMaxPath> path;
|
|
114 |
aFailure = EFalse;
|
|
115 |
TInt i;
|
|
116 |
for (i = 0; i < pDir->Count(); i++)
|
|
117 |
{
|
|
118 |
const TEntry& entry = (*pDir)[i];
|
|
119 |
|
|
120 |
path.Zero();
|
|
121 |
path.Append(aDirPath);
|
|
122 |
path.Append(entry.iName);
|
|
123 |
if (DoRecogniseL(path, aAppArc) != EPass)
|
|
124 |
{
|
|
125 |
// Even though this file was wrongly recognised
|
|
126 |
// keep checking the other files in the directory.
|
|
127 |
aFailure = ETrue;
|
|
128 |
}
|
|
129 |
}
|
|
130 |
INFO_PRINTF2(_L("Checked %d files"), i);
|
|
131 |
|
|
132 |
CleanupStack::PopAndDestroy(2, pDirScan);
|
|
133 |
}
|
|
134 |
|
|
135 |
//
|
|
136 |
// This function returns EPass if aFileName was not recognised
|
|
137 |
// as an audio or video mime-type, EFail otherwise.
|
|
138 |
//
|
|
139 |
TVerdict RMMRUFDirTestStep::DoRecogniseL(const TDesC& aFileName, RAppArc& aAppArc)
|
|
140 |
{
|
|
141 |
TDataType dataType;
|
|
142 |
RFile file;
|
|
143 |
_LIT8(KAudio, "audio/*");
|
|
144 |
_LIT8(KVideo, "video/*");
|
|
145 |
|
|
146 |
TInt err = file.Open(aAppArc.FileServer(), aFileName, EFileRead | EFileShareAny);
|
|
147 |
if (err != KErrNone)
|
|
148 |
{
|
|
149 |
INFO_PRINTF2(_L("RFile.Open() failed: %d"), err);
|
|
150 |
return EInconclusive;
|
|
151 |
}
|
|
152 |
|
|
153 |
err = aAppArc.Recognise(file, dataType);
|
|
154 |
file.Close();
|
|
155 |
if (err != KErrNone)
|
|
156 |
{
|
|
157 |
INFO_PRINTF2(_L("RAppArc.Recognise() failed: %d"), err);
|
|
158 |
return EInconclusive;
|
|
159 |
}
|
|
160 |
|
|
161 |
// Check that the mime-type is either zero length,
|
|
162 |
// or doesn't begin with "audio/" or "video/"
|
|
163 |
TPtrC8 mimeType = dataType.Des8();
|
|
164 |
if (mimeType.Length() > 0)
|
|
165 |
{
|
|
166 |
if (mimeType.MatchF(KAudio) != KErrNotFound)
|
|
167 |
{
|
|
168 |
TBuf<KMaxDataTypeLength> returned;
|
|
169 |
returned.Copy(dataType.Des());
|
|
170 |
INFO_PRINTF3(_L("File \"%S\" has been recognised as %S"), &aFileName, &returned);
|
|
171 |
return EFail; // It has been recognised.
|
|
172 |
}
|
|
173 |
|
|
174 |
if (mimeType.MatchF(KVideo) != KErrNotFound)
|
|
175 |
{
|
|
176 |
TBuf<KMaxDataTypeLength> returned;
|
|
177 |
returned.Copy(dataType.Des());
|
|
178 |
INFO_PRINTF3(_L("File \"%S\" has been recognised as %S"), &aFileName, &returned);
|
|
179 |
return EFail; // It has been recognised.
|
|
180 |
}
|
|
181 |
}
|
|
182 |
|
|
183 |
return EPass;
|
|
184 |
}
|