sl@0
|
1 |
// Copyright (c) 2001-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
2 |
// All rights reserved.
|
sl@0
|
3 |
// This component and the accompanying materials are made available
|
sl@0
|
4 |
// under the terms of "Eclipse Public License v1.0"
|
sl@0
|
5 |
// which accompanies this distribution, and is available
|
sl@0
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
7 |
//
|
sl@0
|
8 |
// Initial Contributors:
|
sl@0
|
9 |
// Nokia Corporation - initial contribution.
|
sl@0
|
10 |
//
|
sl@0
|
11 |
// Contributors:
|
sl@0
|
12 |
//
|
sl@0
|
13 |
// Description:
|
sl@0
|
14 |
//
|
sl@0
|
15 |
|
sl@0
|
16 |
#include "CUriUtilsTest.h"
|
sl@0
|
17 |
|
sl@0
|
18 |
#include <e32base.h>
|
sl@0
|
19 |
#include <uriutils.h>
|
sl@0
|
20 |
|
sl@0
|
21 |
#include "UriUtilsTests.h"
|
sl@0
|
22 |
|
sl@0
|
23 |
CUriUtilsTest* CUriUtilsTest::NewLC(CIpuTestHarness* aTestHarness)
|
sl@0
|
24 |
{
|
sl@0
|
25 |
CUriUtilsTest* self = new (ELeave) CUriUtilsTest(aTestHarness);
|
sl@0
|
26 |
CleanupStack::PushL(self);
|
sl@0
|
27 |
self->ConstructL();
|
sl@0
|
28 |
return self;
|
sl@0
|
29 |
}
|
sl@0
|
30 |
|
sl@0
|
31 |
CUriUtilsTest* CUriUtilsTest::NewL(CIpuTestHarness* aTestHarness)
|
sl@0
|
32 |
{
|
sl@0
|
33 |
CUriUtilsTest* self = CUriUtilsTest::NewLC(aTestHarness);
|
sl@0
|
34 |
CleanupStack::Pop(self);
|
sl@0
|
35 |
return self;
|
sl@0
|
36 |
}
|
sl@0
|
37 |
|
sl@0
|
38 |
CUriUtilsTest::CUriUtilsTest(CIpuTestHarness* aTestHarness)
|
sl@0
|
39 |
: iTestHarness(aTestHarness)
|
sl@0
|
40 |
{
|
sl@0
|
41 |
}
|
sl@0
|
42 |
|
sl@0
|
43 |
void CUriUtilsTest::ConstructL()
|
sl@0
|
44 |
{
|
sl@0
|
45 |
}
|
sl@0
|
46 |
|
sl@0
|
47 |
CUriUtilsTest::~CUriUtilsTest()
|
sl@0
|
48 |
{
|
sl@0
|
49 |
}
|
sl@0
|
50 |
|
sl@0
|
51 |
void CUriUtilsTest::DoTestsL()
|
sl@0
|
52 |
{
|
sl@0
|
53 |
TestUriUtilsConvertToInternetFormL(KDisplayForm0, KInternetForm0);
|
sl@0
|
54 |
TestUriUtilsConvertToDisplayFormDeprecatedL(KInternetForm0, KDisplayForm0);
|
sl@0
|
55 |
TestUriUtilsConvertToDisplayFormL(KInternetForm0, KValidDisplayForm0);
|
sl@0
|
56 |
|
sl@0
|
57 |
TestUriUtilsConvertToInternetFormL(KDisplayForm1, KInternetForm1);
|
sl@0
|
58 |
TestUriUtilsConvertToDisplayFormDeprecatedL(KInternetForm1, KDisplayForm1);
|
sl@0
|
59 |
TestUriUtilsConvertToDisplayFormL(KInternetForm1, KValidDisplayForm1);
|
sl@0
|
60 |
|
sl@0
|
61 |
TestUriUtilsHasInvalidCharsL(KInvalidChars0, KInvalid0);
|
sl@0
|
62 |
TestUriUtilsHasInvalidCharsL(KInvalidChars1, KInvalid0);
|
sl@0
|
63 |
TestUriUtilsHasInvalidCharsL(KInvalidChars2, KInvalid0);
|
sl@0
|
64 |
TestUriUtilsHasInvalidCharsL(KInvalidChars3, KInvalid0);
|
sl@0
|
65 |
TestUriUtilsHasInvalidCharsL(KInvalidChars4, KInvalid0);
|
sl@0
|
66 |
TestUriUtilsHasInvalidCharsL(KInvalidChars5, KInvalid0);
|
sl@0
|
67 |
TestUriUtilsHasInvalidCharsL(KInvalidChars6, KInvalid0);
|
sl@0
|
68 |
TestUriUtilsHasInvalidCharsL(KInvalidChars7, KInvalid0);
|
sl@0
|
69 |
TestUriUtilsHasInvalidCharsL(KInvalidChars8, KInvalid0);
|
sl@0
|
70 |
TestUriUtilsHasInvalidCharsL(KInvalidChars9, KInvalid0);
|
sl@0
|
71 |
TestUriUtilsHasInvalidCharsL(KInvalidChars10, KInvalid0);
|
sl@0
|
72 |
TestUriUtilsHasInvalidCharsL(KInvalidChars11, KInvalid0);
|
sl@0
|
73 |
|
sl@0
|
74 |
TestUriUtilsHasInvalidCharsL(KInvalidChars12, KInvalid1);
|
sl@0
|
75 |
TestUriUtilsHasInvalidCharsL(KInvalidChars13, KInvalid1);
|
sl@0
|
76 |
TestUriUtilsHasInvalidCharsL(KInvalidChars14, KInvalid1);
|
sl@0
|
77 |
TestUriUtilsHasInvalidCharsL(KInvalidChars15, KInvalid1);
|
sl@0
|
78 |
TestUriUtilsHasInvalidCharsL(KInvalidChars16, KInvalid1);
|
sl@0
|
79 |
TestUriUtilsHasInvalidCharsL(KInvalidChars17, KInvalid1);
|
sl@0
|
80 |
TestUriUtilsHasInvalidCharsL(KInvalidChars18, KInvalid1);
|
sl@0
|
81 |
TestUriUtilsHasInvalidCharsL(KInvalidChars19, KInvalid1);
|
sl@0
|
82 |
TestUriUtilsHasInvalidCharsL(KInvalidChars20, KInvalid1);
|
sl@0
|
83 |
TestUriUtilsHasInvalidCharsL(KInvalidChars21, KInvalid1);
|
sl@0
|
84 |
TestUriUtilsHasInvalidCharsL(KInvalidChars22, KInvalid1);
|
sl@0
|
85 |
TestUriUtilsHasInvalidCharsL(KInvalidChars23, KInvalid1);
|
sl@0
|
86 |
TestUriUtilsHasInvalidCharsL(KInvalidChars24, KInvalid1);
|
sl@0
|
87 |
TestUriUtilsHasInvalidCharsL(KInvalidChars25, KInvalid1);
|
sl@0
|
88 |
TestUriUtilsHasInvalidCharsL(KInvalidChars26, KInvalid1);
|
sl@0
|
89 |
TestUriUtilsHasInvalidCharsL(KInvalidChars27, KInvalid1);
|
sl@0
|
90 |
TestUriUtilsHasInvalidCharsL(KInvalidChars28, KInvalid1);
|
sl@0
|
91 |
|
sl@0
|
92 |
|
sl@0
|
93 |
//
|
sl@0
|
94 |
// Tests for 2.9.1.3 Host-Type checking
|
sl@0
|
95 |
|
sl@0
|
96 |
// All these are IPv6 tests
|
sl@0
|
97 |
TestUriUtilsHostTypeL(KHostTypeIPv6Format1, UriUtils::EIPv6Host);
|
sl@0
|
98 |
TestUriUtilsHostTypeL(KHostTypeIPv6Format2, UriUtils::EIPv6Host);
|
sl@0
|
99 |
TestUriUtilsHostTypeL(KHostTypeIPv6Format3, UriUtils::EIPv6Host);
|
sl@0
|
100 |
TestUriUtilsHostTypeL(KHostTypeIPv6Format4, UriUtils::EIPv6Host);
|
sl@0
|
101 |
TestUriUtilsHostTypeL(KHostTypeIPv6Format5, UriUtils::EIPv6Host);
|
sl@0
|
102 |
TestUriUtilsHostTypeL(KHostTypeIPv6Format6, UriUtils::EIPv6Host);
|
sl@0
|
103 |
TestUriUtilsHostTypeL(KHostTypeIPv6Format7, UriUtils::EIPv6Host);
|
sl@0
|
104 |
|
sl@0
|
105 |
TestUriUtilsHostTypeL(KHostTypeIPv4Format, UriUtils::EIPv4Host);
|
sl@0
|
106 |
|
sl@0
|
107 |
// Invalid format IPv4 hosts should be considered Text hosts
|
sl@0
|
108 |
TestUriUtilsHostTypeL(KHostTypeIPv4InvalidFormat1, UriUtils::ETextHost);
|
sl@0
|
109 |
TestUriUtilsHostTypeL(KHostTypeIPv4InvalidFormat2, UriUtils::ETextHost);
|
sl@0
|
110 |
|
sl@0
|
111 |
TestUriUtilsHostTypeL(KHostTypeTextFormat1, UriUtils::ETextHost);
|
sl@0
|
112 |
TestUriUtilsHostTypeL(KHostTypeTextFormat2, UriUtils::ETextHost);
|
sl@0
|
113 |
//
|
sl@0
|
114 |
//
|
sl@0
|
115 |
}
|
sl@0
|
116 |
|
sl@0
|
117 |
void CUriUtilsTest::TestUriUtilsConvertToInternetFormDeprecatedL(const TDesC& aData, const TDesC& aExpected)
|
sl@0
|
118 |
{
|
sl@0
|
119 |
// Make 8-bit copy
|
sl@0
|
120 |
HBufC8* expectedBuf = HBufC8::NewLC(aExpected.Length());
|
sl@0
|
121 |
TPtr8 expected8Bit = expectedBuf->Des();
|
sl@0
|
122 |
expected8Bit.Copy(aExpected);
|
sl@0
|
123 |
|
sl@0
|
124 |
iTestHarness->StartTestL(_L("Test UriUtils ConvertToInternetForm (deprecated)"));
|
sl@0
|
125 |
|
sl@0
|
126 |
TUriParser16 parser;
|
sl@0
|
127 |
parser.Parse(aData);
|
sl@0
|
128 |
CUri8* uri = NULL;
|
sl@0
|
129 |
TRAPD(error, uri = UriUtils::ConvertToInternetFormL(parser));
|
sl@0
|
130 |
if( error == KErrNone )
|
sl@0
|
131 |
{
|
sl@0
|
132 |
if( uri->Uri().UriDes().Compare(expected8Bit) != 0 )
|
sl@0
|
133 |
{
|
sl@0
|
134 |
error = KErrNotFound;
|
sl@0
|
135 |
}
|
sl@0
|
136 |
delete uri;
|
sl@0
|
137 |
}
|
sl@0
|
138 |
iTestHarness->EndTest(error);
|
sl@0
|
139 |
|
sl@0
|
140 |
CleanupStack::PopAndDestroy(expectedBuf); // expectedBuf
|
sl@0
|
141 |
}
|
sl@0
|
142 |
void CUriUtilsTest::TestUriUtilsConvertToInternetFormL(const TDesC& aData, const TDesC& aExpected)
|
sl@0
|
143 |
{
|
sl@0
|
144 |
// Make 8-bit copy
|
sl@0
|
145 |
HBufC8* expectedBuf = HBufC8::NewLC(aExpected.Length());
|
sl@0
|
146 |
TPtr8 expected8Bit = expectedBuf->Des();
|
sl@0
|
147 |
expected8Bit.Copy(aExpected);
|
sl@0
|
148 |
|
sl@0
|
149 |
iTestHarness->StartTestL(_L("Test UriUtils ConvertToInternetForm"));
|
sl@0
|
150 |
|
sl@0
|
151 |
CUri8* uri = NULL;
|
sl@0
|
152 |
TRAPD(error, uri = UriUtils::CreateUriL(aData));
|
sl@0
|
153 |
if( error == KErrNone )
|
sl@0
|
154 |
{
|
sl@0
|
155 |
if( uri->Uri().UriDes().Compare(expected8Bit) != 0 )
|
sl@0
|
156 |
{
|
sl@0
|
157 |
error = KErrNotFound;
|
sl@0
|
158 |
}
|
sl@0
|
159 |
delete uri;
|
sl@0
|
160 |
}
|
sl@0
|
161 |
iTestHarness->EndTest(error);
|
sl@0
|
162 |
|
sl@0
|
163 |
CleanupStack::PopAndDestroy(expectedBuf); // expectedBuf
|
sl@0
|
164 |
TestUriUtilsConvertToInternetFormDeprecatedL(aData, aExpected );
|
sl@0
|
165 |
}
|
sl@0
|
166 |
|
sl@0
|
167 |
void CUriUtilsTest::TestUriUtilsConvertToDisplayFormDeprecatedL(const TDesC& aData, const TDesC& aExpected)
|
sl@0
|
168 |
{
|
sl@0
|
169 |
// Make 8-bit copy
|
sl@0
|
170 |
HBufC8* dataBuf = HBufC8::NewLC(aData.Length());
|
sl@0
|
171 |
TPtr8 data8Bit = dataBuf->Des();
|
sl@0
|
172 |
data8Bit.Copy(aData);
|
sl@0
|
173 |
|
sl@0
|
174 |
iTestHarness->StartTestL(_L("Test UriUtils ConvertToInternetForm (deprecated)"));
|
sl@0
|
175 |
|
sl@0
|
176 |
TUriParser8 parser;
|
sl@0
|
177 |
parser.Parse(data8Bit);
|
sl@0
|
178 |
CUri16* uri = NULL;
|
sl@0
|
179 |
TRAPD(error, uri = UriUtils::ConvertToDisplayFormL(parser));
|
sl@0
|
180 |
if( error == KErrNone )
|
sl@0
|
181 |
{
|
sl@0
|
182 |
if( uri->Uri().UriDes().Compare(aExpected) != 0 )
|
sl@0
|
183 |
{
|
sl@0
|
184 |
error = KErrNotFound;
|
sl@0
|
185 |
}
|
sl@0
|
186 |
delete uri;
|
sl@0
|
187 |
}
|
sl@0
|
188 |
iTestHarness->EndTest(error);
|
sl@0
|
189 |
|
sl@0
|
190 |
CleanupStack::PopAndDestroy(dataBuf); // dataBuf
|
sl@0
|
191 |
}
|
sl@0
|
192 |
|
sl@0
|
193 |
void CUriUtilsTest::TestUriUtilsConvertToDisplayFormL(const TDesC& aData, const TDesC& aExpected)
|
sl@0
|
194 |
{
|
sl@0
|
195 |
// Make 8-bit copy
|
sl@0
|
196 |
HBufC8* dataBuf = HBufC8::NewLC(aData.Length());
|
sl@0
|
197 |
TPtr8 data8Bit = dataBuf->Des();
|
sl@0
|
198 |
data8Bit.Copy(aData);
|
sl@0
|
199 |
|
sl@0
|
200 |
iTestHarness->StartTestL(_L("Test UriUtils ConvertToInternetForm"));
|
sl@0
|
201 |
|
sl@0
|
202 |
TUriParser8 parser;
|
sl@0
|
203 |
parser.Parse(data8Bit);
|
sl@0
|
204 |
HBufC* uri = NULL;
|
sl@0
|
205 |
TRAPD(error, uri = parser.DisplayFormL());
|
sl@0
|
206 |
if( error == KErrNone )
|
sl@0
|
207 |
{
|
sl@0
|
208 |
if( uri->Compare(aExpected) != 0 )
|
sl@0
|
209 |
{
|
sl@0
|
210 |
error = KErrNotFound;
|
sl@0
|
211 |
}
|
sl@0
|
212 |
delete uri;
|
sl@0
|
213 |
}
|
sl@0
|
214 |
iTestHarness->EndTest(error);
|
sl@0
|
215 |
|
sl@0
|
216 |
CleanupStack::PopAndDestroy(dataBuf); // dataBuf
|
sl@0
|
217 |
}
|
sl@0
|
218 |
|
sl@0
|
219 |
void CUriUtilsTest::TestUriUtilsHasInvalidCharsL(const TDesC16& aData, TBool aHasInvalidChars)
|
sl@0
|
220 |
{
|
sl@0
|
221 |
iTestHarness->StartTestL(_L("Test UriUtils HasInvalidChars (16-bit)"));
|
sl@0
|
222 |
|
sl@0
|
223 |
TBool invalid = UriUtils::HasInvalidChars(aData);
|
sl@0
|
224 |
|
sl@0
|
225 |
TInt error = KErrNone;
|
sl@0
|
226 |
if( (!invalid && aHasInvalidChars) | (invalid && !aHasInvalidChars) )
|
sl@0
|
227 |
{
|
sl@0
|
228 |
error = KErrNotFound;
|
sl@0
|
229 |
}
|
sl@0
|
230 |
iTestHarness->EndTest(error);
|
sl@0
|
231 |
}
|
sl@0
|
232 |
|
sl@0
|
233 |
void CUriUtilsTest::TestUriUtilsHasInvalidCharsL(const TDesC8& aData, TBool aHasInvalidChars)
|
sl@0
|
234 |
{
|
sl@0
|
235 |
iTestHarness->StartTestL(_L("Test UriUtils HasInvalidChars (8-bit)"));
|
sl@0
|
236 |
|
sl@0
|
237 |
TBool invalid = UriUtils::HasInvalidChars(aData);
|
sl@0
|
238 |
|
sl@0
|
239 |
TInt error = KErrNone;
|
sl@0
|
240 |
if( (!invalid && aHasInvalidChars) | (invalid && !aHasInvalidChars) )
|
sl@0
|
241 |
{
|
sl@0
|
242 |
error = KErrNotFound;
|
sl@0
|
243 |
}
|
sl@0
|
244 |
iTestHarness->EndTest(error);
|
sl@0
|
245 |
}
|
sl@0
|
246 |
|
sl@0
|
247 |
void CUriUtilsTest::TestUriUtilsHostTypeL(const TDesC8& aData, UriUtils::TUriHostType aHostType)
|
sl@0
|
248 |
{
|
sl@0
|
249 |
iTestHarness->StartTestL(_L("Test UriUtils HostType (8-bit)"));
|
sl@0
|
250 |
|
sl@0
|
251 |
UriUtils::TUriHostType hostType = UriUtils::HostType(aData);
|
sl@0
|
252 |
|
sl@0
|
253 |
TInt error = KErrNone;
|
sl@0
|
254 |
if ( hostType != aHostType )
|
sl@0
|
255 |
{
|
sl@0
|
256 |
error = KErrNotFound;
|
sl@0
|
257 |
}
|
sl@0
|
258 |
iTestHarness->EndTest(error);
|
sl@0
|
259 |
}
|
sl@0
|
260 |
|
sl@0
|
261 |
void CUriUtilsTest::TestUriUtilsHostTypeL(const TDesC16& aData, UriUtils::TUriHostType aHostType)
|
sl@0
|
262 |
{
|
sl@0
|
263 |
iTestHarness->StartTestL(_L("Test UriUtils HostType (16-bit)"));
|
sl@0
|
264 |
|
sl@0
|
265 |
UriUtils::TUriHostType hostType = UriUtils::HostType(aData);
|
sl@0
|
266 |
|
sl@0
|
267 |
TInt error = KErrNone;
|
sl@0
|
268 |
if ( hostType != aHostType )
|
sl@0
|
269 |
{
|
sl@0
|
270 |
error = KErrNotFound;
|
sl@0
|
271 |
}
|
sl@0
|
272 |
iTestHarness->EndTest(error);
|
sl@0
|
273 |
}
|