applayerpluginsandutils/bookmarksupport/test/t_cbookmark.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 "testutils.h"
       
    19 
       
    20 LOCAL_D CTestWrapper* gTestWrapper;
       
    21 
       
    22 _LIT(KFilename, "t_cbookmark.cpp");
       
    23 
       
    24 _LIT(KTxtBookmark1, "Bookmark 1");
       
    25 
       
    26 _LIT8(KTxtUri, "http://lon-xcom.intra/duff/index.html");
       
    27 
       
    28 const TInt KOneSecond = 1000000;
       
    29 const TUint32 proxyId =	0x7C123456;
       
    30 
       
    31 LOCAL_D void GeneralTestsL()
       
    32 	{
       
    33 	CBookmarkDb* db = CBookmarkDb::NewL(Bookmark::EVisibilityDefault, NULL);
       
    34 	CleanupStack::PushL(db);
       
    35 	CBookmark& bookmark = db->CreateBookmarkL(db->RootL());
       
    36 	
       
    37 	gTestWrapper->Next(_L("[CBookmark tests] type"));
       
    38 	gTestWrapper->TEST(bookmark.Type() == Bookmark::ETypeBookmark);
       
    39 	
       
    40 	gTestWrapper->Next(_L("[CBookmark tests] title"));
       
    41 	bookmark.SetTitleL(KTxtBookmark1);
       
    42 	gTestWrapper->TEST(bookmark.Title() == KTxtBookmark1);
       
    43                                        
       
    44 	gTestWrapper->Next(_L("[CBookmark tests] home page flag"));
       
    45 	gTestWrapper->TEST(bookmark.IsHomePage() == EFalse);
       
    46 	db->SetHome(&bookmark);	
       
    47 	gTestWrapper->TEST(bookmark.IsHomePage());
       
    48 	                                                   
       
    49 	gTestWrapper->Next(_L("[CBookmark tests] handle"));
       
    50 	RBkBookmark handle = bookmark.OpenBookmark();
       
    51 	CleanupClosePushL(handle);
       
    52 	gTestWrapper->TEST(handle.Type() == bookmark.Type());
       
    53 	gTestWrapper->TEST(handle.Title() == bookmark.Title());
       
    54 	CleanupStack::PopAndDestroy(&handle);
       
    55 	
       
    56 	CleanupStack::PopAndDestroy(db);
       
    57 	}
       
    58 
       
    59 LOCAL_D void TimeTestsL()
       
    60 	{
       
    61 	CBookmarkDb* db = CBookmarkDb::NewL(Bookmark::EVisibilityDefault, NULL);
       
    62 	CleanupStack::PushL(db);
       
    63 	CBookmark& bookmark = db->CreateBookmarkL(db->RootL());
       
    64 	
       
    65 	gTestWrapper->Next(_L("[CBookmark tests] time - update visited"));
       
    66 	TTime initalTime;
       
    67 	initalTime.UniversalTime();
       
    68 	User::After(KOneSecond);
       
    69 	bookmark.UpdateVisited();
       
    70 	TTime time1Sec = bookmark.LastVisited();
       
    71 	gTestWrapper->TEST(time1Sec > initalTime);
       
    72 	
       
    73 	gTestWrapper->Next(_L("[CBookmark tests] time - set last visited"));
       
    74 	bookmark.SetLastVisited(initalTime);
       
    75 	TTime newTime = bookmark.LastVisited();
       
    76 	gTestWrapper->TEST(newTime < time1Sec);
       
    77 	
       
    78 	CleanupStack::PopAndDestroy(db);
       
    79 	}
       
    80 
       
    81 LOCAL_D void UriTestsL()
       
    82 	{
       
    83 	CBookmarkDb* db = CBookmarkDb::NewL(Bookmark::EVisibilityDefault, NULL);
       
    84 	CleanupStack::PushL(db);
       
    85 	CBookmark& bookmark = db->CreateBookmarkL(db->RootL());
       
    86 	
       
    87 	gTestWrapper->Next(_L("[CBookmark tests] URI"));
       
    88 	bookmark.SetUriL(KTxtUri);
       
    89 	gTestWrapper->TEST(bookmark.Uri().Compare(KTxtUri) == 0);
       
    90 	
       
    91 	CleanupStack::PopAndDestroy(db);
       
    92 	}
       
    93 
       
    94 LOCAL_D void ExtendedPropertyTestsL()
       
    95 	{
       
    96 	CBookmarkDb* db = CBookmarkDb::NewL(Bookmark::EVisibilityDefault, NULL);
       
    97 	CleanupStack::PushL(db);
       
    98 	
       
    99 	CBookmark& bookmark = db->CreateBookmarkL(db->RootL());
       
   100 	CBkmrkExtendedProperties& properties = bookmark.BkmrkExtendedPropertiesL();
       
   101 	gTestWrapper->TEST(properties.Proxy() != proxyId);
       
   102 	properties.SetProxyL(proxyId);
       
   103 	gTestWrapper->TEST(properties.Proxy() == proxyId);
       
   104 		
       
   105 	CleanupStack::PopAndDestroy(db);
       
   106 	}
       
   107 
       
   108 void DoCBookmarkUnitL(CTestWrapper* aTest)
       
   109 	{
       
   110 	gTestWrapper = aTest;
       
   111 	gTestWrapper->SetFile(KFilename);
       
   112 	gTestWrapper->Next(_L("*** CBookmark tests ***"));
       
   113 	
       
   114 	GeneralTestsL();
       
   115 	TimeTestsL();
       
   116 	UriTestsL();
       
   117 	ExtendedPropertyTestsL();
       
   118 	}