applayerpluginsandutils/bookmarksupport/test/t_cbkmrkproperties.cpp
changeset 0 b16258d2340f
equal deleted inserted replaced
-1:000000000000 0:b16258d2340f
       
     1 // Copyright (c) 2005-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 "bkmrk.h"
       
    17 #include "bkmrkdb.h"
       
    18 #include "bkmrkfolder.h"
       
    19 #include "testutils.h"
       
    20 
       
    21 LOCAL_D CTestWrapper* gTestWrapper;
       
    22 
       
    23 _LIT(KFilename, "t_cbkmrkproperties.cpp");
       
    24 
       
    25 _LIT(KTxtFolder, "propertiesTEST folder");
       
    26 
       
    27 _LIT(KTxtDesc, "This is an extended property description");
       
    28 
       
    29 _LIT8(KDataIcon, "123456789");
       
    30 _LIT8(KAuthUri, "sip:user:pass@location.com:1666;transport=tcp;x=123;df=223?asd=b");
       
    31 _LIT8(KAuthName, "user");
       
    32 _LIT8(KAuthPassword, "pass");
       
    33 _LIT8(KAuthName2, "joe");
       
    34 _LIT8(KAuthPassword2, "pswd1234");
       
    35 
       
    36 const Bookmark::TAttachmentId KIconId = 0xFFFFFFFF;
       
    37 const TUint32 proxyId =	0x7CFFFFFF;
       
    38 const TUint32 napId =	0x6CFFF000;
       
    39 
       
    40 LOCAL_D void PropertiesTestsL()
       
    41 	{
       
    42 	CBookmarkDb* db = CBookmarkDb::NewL(Bookmark::EVisibilityDefault, NULL);
       
    43 	CleanupStack::PushL(db);
       
    44 	
       
    45 //	CBookmarkBase* item = static_cast<CBookmarkBase*>(&(db->CreateFolderL(KTxtFolder, db->RootL())));
       
    46 	CBookmarkFolder& folder = db->CreateFolderL(KTxtFolder, db->RootL());
       
    47 	
       
    48 	CBkmrkProperties& properties = folder.BkmrkPropertiesL();
       
    49 	
       
    50 	gTestWrapper->Next(_L("[Properties] description"));
       
    51 	properties.SetDescriptionL(KTxtDesc);
       
    52 	gTestWrapper->TEST(properties.Description().Compare(KTxtDesc) == 0);
       
    53 	
       
    54 	gTestWrapper->Next(_L("[Properties] icon"));
       
    55 	Bookmark::TAttachmentId iconId = KIconId;
       
    56 	TRAPD(err, properties.SetIconIdL(iconId));
       
    57 	gTestWrapper->TEST(err == KErrNotFound);
       
    58 	
       
    59 	iconId = db->CreateIconL(KDataIcon);
       
    60 	properties.SetIconIdL(iconId);
       
    61 	gTestWrapper->TEST(properties.IconId() == iconId);
       
    62 	
       
    63 	db->DeleteItemL(folder.Id(), ETrue);
       
    64 	
       
    65 	CleanupStack::PopAndDestroy(db);
       
    66 	}
       
    67 
       
    68 LOCAL_D void ExtendedPropertiesTestsL()
       
    69 	{
       
    70 	CBookmarkDb* db = CBookmarkDb::NewL(Bookmark::EVisibilityDefault, NULL);
       
    71 	CleanupStack::PushL(db);
       
    72 	
       
    73 	CBookmark& bookmark = db->CreateBookmarkL(db->RootL());
       
    74 	
       
    75 	CBkmrkExtendedProperties& properties = bookmark.BkmrkExtendedPropertiesL();
       
    76 	
       
    77 	gTestWrapper->Next(_L("[Properties] authentication"));
       
    78 	bookmark.SetUriL(KAuthUri);
       
    79 	gTestWrapper->TEST(properties.AuthenticationL().Name().Compare(KAuthName) == 0);
       
    80 	gTestWrapper->TEST(properties.AuthenticationL().Password().Compare(KAuthPassword) == 0);
       
    81 	gTestWrapper->TEST(properties.AuthenticationL().Method() == CAuthentication::EDigest);
       
    82 	
       
    83 	CAuthentication* auth = CAuthentication::NewL(KAuthName2, KAuthPassword2, CAuthentication::EBasic);
       
    84 	CleanupStack::PushL(auth);
       
    85 	properties.SetAuthenticationL(*auth);
       
    86 	gTestWrapper->TEST(properties.AuthenticationL().Name().Compare(KAuthName2) == 0);
       
    87 	gTestWrapper->TEST(properties.AuthenticationL().Password().Compare(KAuthPassword2) == 0);
       
    88 	gTestWrapper->TEST(properties.AuthenticationL().Method() == CAuthentication::EBasic);
       
    89 	CleanupStack::PopAndDestroy(auth);
       
    90 	
       
    91 	gTestWrapper->Next(_L("[Properties] proxy and nap"));
       
    92 	
       
    93 	gTestWrapper->TEST(properties.Proxy() != proxyId);
       
    94 	properties.SetProxyL(proxyId);
       
    95 	gTestWrapper->TEST(properties.Proxy() == proxyId);
       
    96 	
       
    97 	gTestWrapper->TEST(properties.Nap() != napId);
       
    98 	properties.SetNapL(napId);
       
    99 	gTestWrapper->TEST(properties.Nap() == napId);
       
   100 	
       
   101 	CleanupStack::PopAndDestroy(db);
       
   102 	}
       
   103 
       
   104 void DoPropertiesUnitL(CTestWrapper* aTest)
       
   105 	{
       
   106 	gTestWrapper = aTest;
       
   107 	gTestWrapper->SetFile(KFilename);
       
   108 	gTestWrapper->Next(_L("*** Extended properties tests ***"));
       
   109 	
       
   110 	PropertiesTestsL();
       
   111 	ExtendedPropertiesTestsL();
       
   112 	}