sl@0: // Copyright (c) 2001-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // sl@0: sl@0: #include "CUriUtilsTest.h" sl@0: sl@0: #include sl@0: #include sl@0: sl@0: #include "UriUtilsTests.h" sl@0: sl@0: CUriUtilsTest* CUriUtilsTest::NewLC(CIpuTestHarness* aTestHarness) sl@0: { sl@0: CUriUtilsTest* self = new (ELeave) CUriUtilsTest(aTestHarness); sl@0: CleanupStack::PushL(self); sl@0: self->ConstructL(); sl@0: return self; sl@0: } sl@0: sl@0: CUriUtilsTest* CUriUtilsTest::NewL(CIpuTestHarness* aTestHarness) sl@0: { sl@0: CUriUtilsTest* self = CUriUtilsTest::NewLC(aTestHarness); sl@0: CleanupStack::Pop(self); sl@0: return self; sl@0: } sl@0: sl@0: CUriUtilsTest::CUriUtilsTest(CIpuTestHarness* aTestHarness) sl@0: : iTestHarness(aTestHarness) sl@0: { sl@0: } sl@0: sl@0: void CUriUtilsTest::ConstructL() sl@0: { sl@0: } sl@0: sl@0: CUriUtilsTest::~CUriUtilsTest() sl@0: { sl@0: } sl@0: sl@0: void CUriUtilsTest::DoTestsL() sl@0: { sl@0: TestUriUtilsConvertToInternetFormL(KDisplayForm0, KInternetForm0); sl@0: TestUriUtilsConvertToDisplayFormDeprecatedL(KInternetForm0, KDisplayForm0); sl@0: TestUriUtilsConvertToDisplayFormL(KInternetForm0, KValidDisplayForm0); sl@0: sl@0: TestUriUtilsConvertToInternetFormL(KDisplayForm1, KInternetForm1); sl@0: TestUriUtilsConvertToDisplayFormDeprecatedL(KInternetForm1, KDisplayForm1); sl@0: TestUriUtilsConvertToDisplayFormL(KInternetForm1, KValidDisplayForm1); sl@0: sl@0: TestUriUtilsHasInvalidCharsL(KInvalidChars0, KInvalid0); sl@0: TestUriUtilsHasInvalidCharsL(KInvalidChars1, KInvalid0); sl@0: TestUriUtilsHasInvalidCharsL(KInvalidChars2, KInvalid0); sl@0: TestUriUtilsHasInvalidCharsL(KInvalidChars3, KInvalid0); sl@0: TestUriUtilsHasInvalidCharsL(KInvalidChars4, KInvalid0); sl@0: TestUriUtilsHasInvalidCharsL(KInvalidChars5, KInvalid0); sl@0: TestUriUtilsHasInvalidCharsL(KInvalidChars6, KInvalid0); sl@0: TestUriUtilsHasInvalidCharsL(KInvalidChars7, KInvalid0); sl@0: TestUriUtilsHasInvalidCharsL(KInvalidChars8, KInvalid0); sl@0: TestUriUtilsHasInvalidCharsL(KInvalidChars9, KInvalid0); sl@0: TestUriUtilsHasInvalidCharsL(KInvalidChars10, KInvalid0); sl@0: TestUriUtilsHasInvalidCharsL(KInvalidChars11, KInvalid0); sl@0: sl@0: TestUriUtilsHasInvalidCharsL(KInvalidChars12, KInvalid1); sl@0: TestUriUtilsHasInvalidCharsL(KInvalidChars13, KInvalid1); sl@0: TestUriUtilsHasInvalidCharsL(KInvalidChars14, KInvalid1); sl@0: TestUriUtilsHasInvalidCharsL(KInvalidChars15, KInvalid1); sl@0: TestUriUtilsHasInvalidCharsL(KInvalidChars16, KInvalid1); sl@0: TestUriUtilsHasInvalidCharsL(KInvalidChars17, KInvalid1); sl@0: TestUriUtilsHasInvalidCharsL(KInvalidChars18, KInvalid1); sl@0: TestUriUtilsHasInvalidCharsL(KInvalidChars19, KInvalid1); sl@0: TestUriUtilsHasInvalidCharsL(KInvalidChars20, KInvalid1); sl@0: TestUriUtilsHasInvalidCharsL(KInvalidChars21, KInvalid1); sl@0: TestUriUtilsHasInvalidCharsL(KInvalidChars22, KInvalid1); sl@0: TestUriUtilsHasInvalidCharsL(KInvalidChars23, KInvalid1); sl@0: TestUriUtilsHasInvalidCharsL(KInvalidChars24, KInvalid1); sl@0: TestUriUtilsHasInvalidCharsL(KInvalidChars25, KInvalid1); sl@0: TestUriUtilsHasInvalidCharsL(KInvalidChars26, KInvalid1); sl@0: TestUriUtilsHasInvalidCharsL(KInvalidChars27, KInvalid1); sl@0: TestUriUtilsHasInvalidCharsL(KInvalidChars28, KInvalid1); sl@0: sl@0: sl@0: // sl@0: // Tests for 2.9.1.3 Host-Type checking sl@0: sl@0: // All these are IPv6 tests sl@0: TestUriUtilsHostTypeL(KHostTypeIPv6Format1, UriUtils::EIPv6Host); sl@0: TestUriUtilsHostTypeL(KHostTypeIPv6Format2, UriUtils::EIPv6Host); sl@0: TestUriUtilsHostTypeL(KHostTypeIPv6Format3, UriUtils::EIPv6Host); sl@0: TestUriUtilsHostTypeL(KHostTypeIPv6Format4, UriUtils::EIPv6Host); sl@0: TestUriUtilsHostTypeL(KHostTypeIPv6Format5, UriUtils::EIPv6Host); sl@0: TestUriUtilsHostTypeL(KHostTypeIPv6Format6, UriUtils::EIPv6Host); sl@0: TestUriUtilsHostTypeL(KHostTypeIPv6Format7, UriUtils::EIPv6Host); sl@0: sl@0: TestUriUtilsHostTypeL(KHostTypeIPv4Format, UriUtils::EIPv4Host); sl@0: sl@0: // Invalid format IPv4 hosts should be considered Text hosts sl@0: TestUriUtilsHostTypeL(KHostTypeIPv4InvalidFormat1, UriUtils::ETextHost); sl@0: TestUriUtilsHostTypeL(KHostTypeIPv4InvalidFormat2, UriUtils::ETextHost); sl@0: sl@0: TestUriUtilsHostTypeL(KHostTypeTextFormat1, UriUtils::ETextHost); sl@0: TestUriUtilsHostTypeL(KHostTypeTextFormat2, UriUtils::ETextHost); sl@0: // sl@0: // sl@0: } sl@0: sl@0: void CUriUtilsTest::TestUriUtilsConvertToInternetFormDeprecatedL(const TDesC& aData, const TDesC& aExpected) sl@0: { sl@0: // Make 8-bit copy sl@0: HBufC8* expectedBuf = HBufC8::NewLC(aExpected.Length()); sl@0: TPtr8 expected8Bit = expectedBuf->Des(); sl@0: expected8Bit.Copy(aExpected); sl@0: sl@0: iTestHarness->StartTestL(_L("Test UriUtils ConvertToInternetForm (deprecated)")); sl@0: sl@0: TUriParser16 parser; sl@0: parser.Parse(aData); sl@0: CUri8* uri = NULL; sl@0: TRAPD(error, uri = UriUtils::ConvertToInternetFormL(parser)); sl@0: if( error == KErrNone ) sl@0: { sl@0: if( uri->Uri().UriDes().Compare(expected8Bit) != 0 ) sl@0: { sl@0: error = KErrNotFound; sl@0: } sl@0: delete uri; sl@0: } sl@0: iTestHarness->EndTest(error); sl@0: sl@0: CleanupStack::PopAndDestroy(expectedBuf); // expectedBuf sl@0: } sl@0: void CUriUtilsTest::TestUriUtilsConvertToInternetFormL(const TDesC& aData, const TDesC& aExpected) sl@0: { sl@0: // Make 8-bit copy sl@0: HBufC8* expectedBuf = HBufC8::NewLC(aExpected.Length()); sl@0: TPtr8 expected8Bit = expectedBuf->Des(); sl@0: expected8Bit.Copy(aExpected); sl@0: sl@0: iTestHarness->StartTestL(_L("Test UriUtils ConvertToInternetForm")); sl@0: sl@0: CUri8* uri = NULL; sl@0: TRAPD(error, uri = UriUtils::CreateUriL(aData)); sl@0: if( error == KErrNone ) sl@0: { sl@0: if( uri->Uri().UriDes().Compare(expected8Bit) != 0 ) sl@0: { sl@0: error = KErrNotFound; sl@0: } sl@0: delete uri; sl@0: } sl@0: iTestHarness->EndTest(error); sl@0: sl@0: CleanupStack::PopAndDestroy(expectedBuf); // expectedBuf sl@0: TestUriUtilsConvertToInternetFormDeprecatedL(aData, aExpected ); sl@0: } sl@0: sl@0: void CUriUtilsTest::TestUriUtilsConvertToDisplayFormDeprecatedL(const TDesC& aData, const TDesC& aExpected) sl@0: { sl@0: // Make 8-bit copy sl@0: HBufC8* dataBuf = HBufC8::NewLC(aData.Length()); sl@0: TPtr8 data8Bit = dataBuf->Des(); sl@0: data8Bit.Copy(aData); sl@0: sl@0: iTestHarness->StartTestL(_L("Test UriUtils ConvertToInternetForm (deprecated)")); sl@0: sl@0: TUriParser8 parser; sl@0: parser.Parse(data8Bit); sl@0: CUri16* uri = NULL; sl@0: TRAPD(error, uri = UriUtils::ConvertToDisplayFormL(parser)); sl@0: if( error == KErrNone ) sl@0: { sl@0: if( uri->Uri().UriDes().Compare(aExpected) != 0 ) sl@0: { sl@0: error = KErrNotFound; sl@0: } sl@0: delete uri; sl@0: } sl@0: iTestHarness->EndTest(error); sl@0: sl@0: CleanupStack::PopAndDestroy(dataBuf); // dataBuf sl@0: } sl@0: sl@0: void CUriUtilsTest::TestUriUtilsConvertToDisplayFormL(const TDesC& aData, const TDesC& aExpected) sl@0: { sl@0: // Make 8-bit copy sl@0: HBufC8* dataBuf = HBufC8::NewLC(aData.Length()); sl@0: TPtr8 data8Bit = dataBuf->Des(); sl@0: data8Bit.Copy(aData); sl@0: sl@0: iTestHarness->StartTestL(_L("Test UriUtils ConvertToInternetForm")); sl@0: sl@0: TUriParser8 parser; sl@0: parser.Parse(data8Bit); sl@0: HBufC* uri = NULL; sl@0: TRAPD(error, uri = parser.DisplayFormL()); sl@0: if( error == KErrNone ) sl@0: { sl@0: if( uri->Compare(aExpected) != 0 ) sl@0: { sl@0: error = KErrNotFound; sl@0: } sl@0: delete uri; sl@0: } sl@0: iTestHarness->EndTest(error); sl@0: sl@0: CleanupStack::PopAndDestroy(dataBuf); // dataBuf sl@0: } sl@0: sl@0: void CUriUtilsTest::TestUriUtilsHasInvalidCharsL(const TDesC16& aData, TBool aHasInvalidChars) sl@0: { sl@0: iTestHarness->StartTestL(_L("Test UriUtils HasInvalidChars (16-bit)")); sl@0: sl@0: TBool invalid = UriUtils::HasInvalidChars(aData); sl@0: sl@0: TInt error = KErrNone; sl@0: if( (!invalid && aHasInvalidChars) | (invalid && !aHasInvalidChars) ) sl@0: { sl@0: error = KErrNotFound; sl@0: } sl@0: iTestHarness->EndTest(error); sl@0: } sl@0: sl@0: void CUriUtilsTest::TestUriUtilsHasInvalidCharsL(const TDesC8& aData, TBool aHasInvalidChars) sl@0: { sl@0: iTestHarness->StartTestL(_L("Test UriUtils HasInvalidChars (8-bit)")); sl@0: sl@0: TBool invalid = UriUtils::HasInvalidChars(aData); sl@0: sl@0: TInt error = KErrNone; sl@0: if( (!invalid && aHasInvalidChars) | (invalid && !aHasInvalidChars) ) sl@0: { sl@0: error = KErrNotFound; sl@0: } sl@0: iTestHarness->EndTest(error); sl@0: } sl@0: sl@0: void CUriUtilsTest::TestUriUtilsHostTypeL(const TDesC8& aData, UriUtils::TUriHostType aHostType) sl@0: { sl@0: iTestHarness->StartTestL(_L("Test UriUtils HostType (8-bit)")); sl@0: sl@0: UriUtils::TUriHostType hostType = UriUtils::HostType(aData); sl@0: sl@0: TInt error = KErrNone; sl@0: if ( hostType != aHostType ) sl@0: { sl@0: error = KErrNotFound; sl@0: } sl@0: iTestHarness->EndTest(error); sl@0: } sl@0: sl@0: void CUriUtilsTest::TestUriUtilsHostTypeL(const TDesC16& aData, UriUtils::TUriHostType aHostType) sl@0: { sl@0: iTestHarness->StartTestL(_L("Test UriUtils HostType (16-bit)")); sl@0: sl@0: UriUtils::TUriHostType hostType = UriUtils::HostType(aData); sl@0: sl@0: TInt error = KErrNone; sl@0: if ( hostType != aHostType ) sl@0: { sl@0: error = KErrNotFound; sl@0: } sl@0: iTestHarness->EndTest(error); sl@0: }