First public contribution.
1 // Copyright (c) 2001-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.
16 #include "CUriUtilsTest.h"
21 #include "UriUtilsTests.h"
23 CUriUtilsTest* CUriUtilsTest::NewLC(CIpuTestHarness* aTestHarness)
25 CUriUtilsTest* self = new (ELeave) CUriUtilsTest(aTestHarness);
26 CleanupStack::PushL(self);
31 CUriUtilsTest* CUriUtilsTest::NewL(CIpuTestHarness* aTestHarness)
33 CUriUtilsTest* self = CUriUtilsTest::NewLC(aTestHarness);
34 CleanupStack::Pop(self);
38 CUriUtilsTest::CUriUtilsTest(CIpuTestHarness* aTestHarness)
39 : iTestHarness(aTestHarness)
43 void CUriUtilsTest::ConstructL()
47 CUriUtilsTest::~CUriUtilsTest()
51 void CUriUtilsTest::DoTestsL()
53 TestUriUtilsConvertToInternetFormL(KDisplayForm0, KInternetForm0);
54 TestUriUtilsConvertToDisplayFormDeprecatedL(KInternetForm0, KDisplayForm0);
55 TestUriUtilsConvertToDisplayFormL(KInternetForm0, KValidDisplayForm0);
57 TestUriUtilsConvertToInternetFormL(KDisplayForm1, KInternetForm1);
58 TestUriUtilsConvertToDisplayFormDeprecatedL(KInternetForm1, KDisplayForm1);
59 TestUriUtilsConvertToDisplayFormL(KInternetForm1, KValidDisplayForm1);
61 TestUriUtilsHasInvalidCharsL(KInvalidChars0, KInvalid0);
62 TestUriUtilsHasInvalidCharsL(KInvalidChars1, KInvalid0);
63 TestUriUtilsHasInvalidCharsL(KInvalidChars2, KInvalid0);
64 TestUriUtilsHasInvalidCharsL(KInvalidChars3, KInvalid0);
65 TestUriUtilsHasInvalidCharsL(KInvalidChars4, KInvalid0);
66 TestUriUtilsHasInvalidCharsL(KInvalidChars5, KInvalid0);
67 TestUriUtilsHasInvalidCharsL(KInvalidChars6, KInvalid0);
68 TestUriUtilsHasInvalidCharsL(KInvalidChars7, KInvalid0);
69 TestUriUtilsHasInvalidCharsL(KInvalidChars8, KInvalid0);
70 TestUriUtilsHasInvalidCharsL(KInvalidChars9, KInvalid0);
71 TestUriUtilsHasInvalidCharsL(KInvalidChars10, KInvalid0);
72 TestUriUtilsHasInvalidCharsL(KInvalidChars11, KInvalid0);
74 TestUriUtilsHasInvalidCharsL(KInvalidChars12, KInvalid1);
75 TestUriUtilsHasInvalidCharsL(KInvalidChars13, KInvalid1);
76 TestUriUtilsHasInvalidCharsL(KInvalidChars14, KInvalid1);
77 TestUriUtilsHasInvalidCharsL(KInvalidChars15, KInvalid1);
78 TestUriUtilsHasInvalidCharsL(KInvalidChars16, KInvalid1);
79 TestUriUtilsHasInvalidCharsL(KInvalidChars17, KInvalid1);
80 TestUriUtilsHasInvalidCharsL(KInvalidChars18, KInvalid1);
81 TestUriUtilsHasInvalidCharsL(KInvalidChars19, KInvalid1);
82 TestUriUtilsHasInvalidCharsL(KInvalidChars20, KInvalid1);
83 TestUriUtilsHasInvalidCharsL(KInvalidChars21, KInvalid1);
84 TestUriUtilsHasInvalidCharsL(KInvalidChars22, KInvalid1);
85 TestUriUtilsHasInvalidCharsL(KInvalidChars23, KInvalid1);
86 TestUriUtilsHasInvalidCharsL(KInvalidChars24, KInvalid1);
87 TestUriUtilsHasInvalidCharsL(KInvalidChars25, KInvalid1);
88 TestUriUtilsHasInvalidCharsL(KInvalidChars26, KInvalid1);
89 TestUriUtilsHasInvalidCharsL(KInvalidChars27, KInvalid1);
90 TestUriUtilsHasInvalidCharsL(KInvalidChars28, KInvalid1);
94 // Tests for 2.9.1.3 Host-Type checking
96 // All these are IPv6 tests
97 TestUriUtilsHostTypeL(KHostTypeIPv6Format1, UriUtils::EIPv6Host);
98 TestUriUtilsHostTypeL(KHostTypeIPv6Format2, UriUtils::EIPv6Host);
99 TestUriUtilsHostTypeL(KHostTypeIPv6Format3, UriUtils::EIPv6Host);
100 TestUriUtilsHostTypeL(KHostTypeIPv6Format4, UriUtils::EIPv6Host);
101 TestUriUtilsHostTypeL(KHostTypeIPv6Format5, UriUtils::EIPv6Host);
102 TestUriUtilsHostTypeL(KHostTypeIPv6Format6, UriUtils::EIPv6Host);
103 TestUriUtilsHostTypeL(KHostTypeIPv6Format7, UriUtils::EIPv6Host);
105 TestUriUtilsHostTypeL(KHostTypeIPv4Format, UriUtils::EIPv4Host);
107 // Invalid format IPv4 hosts should be considered Text hosts
108 TestUriUtilsHostTypeL(KHostTypeIPv4InvalidFormat1, UriUtils::ETextHost);
109 TestUriUtilsHostTypeL(KHostTypeIPv4InvalidFormat2, UriUtils::ETextHost);
111 TestUriUtilsHostTypeL(KHostTypeTextFormat1, UriUtils::ETextHost);
112 TestUriUtilsHostTypeL(KHostTypeTextFormat2, UriUtils::ETextHost);
117 void CUriUtilsTest::TestUriUtilsConvertToInternetFormDeprecatedL(const TDesC& aData, const TDesC& aExpected)
120 HBufC8* expectedBuf = HBufC8::NewLC(aExpected.Length());
121 TPtr8 expected8Bit = expectedBuf->Des();
122 expected8Bit.Copy(aExpected);
124 iTestHarness->StartTestL(_L("Test UriUtils ConvertToInternetForm (deprecated)"));
129 TRAPD(error, uri = UriUtils::ConvertToInternetFormL(parser));
130 if( error == KErrNone )
132 if( uri->Uri().UriDes().Compare(expected8Bit) != 0 )
134 error = KErrNotFound;
138 iTestHarness->EndTest(error);
140 CleanupStack::PopAndDestroy(expectedBuf); // expectedBuf
142 void CUriUtilsTest::TestUriUtilsConvertToInternetFormL(const TDesC& aData, const TDesC& aExpected)
145 HBufC8* expectedBuf = HBufC8::NewLC(aExpected.Length());
146 TPtr8 expected8Bit = expectedBuf->Des();
147 expected8Bit.Copy(aExpected);
149 iTestHarness->StartTestL(_L("Test UriUtils ConvertToInternetForm"));
152 TRAPD(error, uri = UriUtils::CreateUriL(aData));
153 if( error == KErrNone )
155 if( uri->Uri().UriDes().Compare(expected8Bit) != 0 )
157 error = KErrNotFound;
161 iTestHarness->EndTest(error);
163 CleanupStack::PopAndDestroy(expectedBuf); // expectedBuf
164 TestUriUtilsConvertToInternetFormDeprecatedL(aData, aExpected );
167 void CUriUtilsTest::TestUriUtilsConvertToDisplayFormDeprecatedL(const TDesC& aData, const TDesC& aExpected)
170 HBufC8* dataBuf = HBufC8::NewLC(aData.Length());
171 TPtr8 data8Bit = dataBuf->Des();
172 data8Bit.Copy(aData);
174 iTestHarness->StartTestL(_L("Test UriUtils ConvertToInternetForm (deprecated)"));
177 parser.Parse(data8Bit);
179 TRAPD(error, uri = UriUtils::ConvertToDisplayFormL(parser));
180 if( error == KErrNone )
182 if( uri->Uri().UriDes().Compare(aExpected) != 0 )
184 error = KErrNotFound;
188 iTestHarness->EndTest(error);
190 CleanupStack::PopAndDestroy(dataBuf); // dataBuf
193 void CUriUtilsTest::TestUriUtilsConvertToDisplayFormL(const TDesC& aData, const TDesC& aExpected)
196 HBufC8* dataBuf = HBufC8::NewLC(aData.Length());
197 TPtr8 data8Bit = dataBuf->Des();
198 data8Bit.Copy(aData);
200 iTestHarness->StartTestL(_L("Test UriUtils ConvertToInternetForm"));
203 parser.Parse(data8Bit);
205 TRAPD(error, uri = parser.DisplayFormL());
206 if( error == KErrNone )
208 if( uri->Compare(aExpected) != 0 )
210 error = KErrNotFound;
214 iTestHarness->EndTest(error);
216 CleanupStack::PopAndDestroy(dataBuf); // dataBuf
219 void CUriUtilsTest::TestUriUtilsHasInvalidCharsL(const TDesC16& aData, TBool aHasInvalidChars)
221 iTestHarness->StartTestL(_L("Test UriUtils HasInvalidChars (16-bit)"));
223 TBool invalid = UriUtils::HasInvalidChars(aData);
225 TInt error = KErrNone;
226 if( (!invalid && aHasInvalidChars) | (invalid && !aHasInvalidChars) )
228 error = KErrNotFound;
230 iTestHarness->EndTest(error);
233 void CUriUtilsTest::TestUriUtilsHasInvalidCharsL(const TDesC8& aData, TBool aHasInvalidChars)
235 iTestHarness->StartTestL(_L("Test UriUtils HasInvalidChars (8-bit)"));
237 TBool invalid = UriUtils::HasInvalidChars(aData);
239 TInt error = KErrNone;
240 if( (!invalid && aHasInvalidChars) | (invalid && !aHasInvalidChars) )
242 error = KErrNotFound;
244 iTestHarness->EndTest(error);
247 void CUriUtilsTest::TestUriUtilsHostTypeL(const TDesC8& aData, UriUtils::TUriHostType aHostType)
249 iTestHarness->StartTestL(_L("Test UriUtils HostType (8-bit)"));
251 UriUtils::TUriHostType hostType = UriUtils::HostType(aData);
253 TInt error = KErrNone;
254 if ( hostType != aHostType )
256 error = KErrNotFound;
258 iTestHarness->EndTest(error);
261 void CUriUtilsTest::TestUriUtilsHostTypeL(const TDesC16& aData, UriUtils::TUriHostType aHostType)
263 iTestHarness->StartTestL(_L("Test UriUtils HostType (16-bit)"));
265 UriUtils::TUriHostType hostType = UriUtils::HostType(aData);
267 TInt error = KErrNone;
268 if ( hostType != aHostType )
270 error = KErrNotFound;
272 iTestHarness->EndTest(error);