applayerpluginsandutils/bookmarksupport/test/t_cbookmarkbase.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 "bkmrkfolder.h"
       
    18 #include "bkmrkdb.h"
       
    19 #include "testutils.h"
       
    20 
       
    21 LOCAL_D CTestWrapper* gTestWrapper;
       
    22 
       
    23 _LIT(KFilename, "t_cbookmarkbase.cpp");
       
    24 
       
    25 _LIT(KTxtNewFolder, "New Folder 1");
       
    26 
       
    27 _LIT(KTxtItem1, "Bookmark Item 1");
       
    28 
       
    29 const Bookmark::TItemId KItemId = 0x00000123;
       
    30 
       
    31 LOCAL_D void GeneralTestsL()
       
    32 	{
       
    33 	CBookmarkDb* db = CBookmarkDb::NewL(Bookmark::EVisibilityManager, NULL);
       
    34 	CleanupStack::PushL(db);
       
    35 	CBookmark& bookmark = db->CreateBookmarkL(db->RootL());
       
    36 
       
    37 	gTestWrapper->Next(_L("[CBookmarkBase tests] id"));
       
    38 	gTestWrapper->TEST(bookmark.Id() != KItemId);
       
    39 	bookmark.SetId(KItemId);
       
    40 	gTestWrapper->TEST(bookmark.Id() == KItemId);
       
    41 
       
    42 	gTestWrapper->Next(_L("[CBookmarkBase tests] reference counting"));
       
    43 	gTestWrapper->TEST(bookmark.RefCount() == 0);
       
    44 	bookmark.IncRefCount();
       
    45 	gTestWrapper->TEST(bookmark.RefCount() == 1);
       
    46 	bookmark.DecRefCount();
       
    47 	gTestWrapper->TEST(bookmark.RefCount() == 0);
       
    48 	bookmark.IncRefCount();
       
    49 	bookmark.IncRefCount();
       
    50 	bookmark.IncRefCount();
       
    51 	gTestWrapper->TEST(bookmark.RefCount() == 3);
       
    52 	bookmark.DecRefCount();
       
    53 	bookmark.DecRefCount();
       
    54 	bookmark.DecRefCount();
       
    55 	gTestWrapper->TEST(bookmark.RefCount() == 0);
       
    56 	
       
    57 	gTestWrapper->Next(_L("[CBookmarkBase tests] parent"));
       
    58 	CBookmarkFolder& folder = db->CreateFolderL(KTxtNewFolder, db->RootL());
       
    59 	gTestWrapper->TEST(bookmark.Parent()->Id() == db->RootL().Id());
       
    60 	bookmark.SetParentL(folder);
       
    61 	gTestWrapper->TEST(bookmark.Parent()->Id() == folder.Id());
       
    62 	bookmark.SetParentL(db->RootL());
       
    63 	gTestWrapper->TEST(bookmark.Parent()->Id() == db->RootL().Id());
       
    64 
       
    65 	gTestWrapper->Next(_L("[CBookmarkBase tests] title"));
       
    66 	bookmark.SetTitleL(KTxtItem1);
       
    67 	gTestWrapper->TEST(bookmark.Title().Compare(KTxtItem1) == 0);
       
    68 
       
    69 	gTestWrapper->Next(_L("[CBookmarkBase tests] public and writable"));
       
    70 	gTestWrapper->TEST(bookmark.IsPublic());
       
    71 	
       
    72 	TInt err = KErrNone;
       
    73 	gTestWrapper->TEST(bookmark.IsPublic());
       
    74 	
       
    75 	gTestWrapper->TEST(bookmark.IsWritable());
       
    76 	bookmark.SetWritableL(EFalse);
       
    77 	gTestWrapper->TEST(!bookmark.IsWritable());
       
    78 	// test that write operations work as application is WriteDeviceData
       
    79 	TRAP(err, bookmark.SetTitleL(KTxtItem1));
       
    80 	gTestWrapper->TEST(err == KErrNone);
       
    81 	TRAP(err, bookmark.SetPublicL(ETrue));
       
    82 	gTestWrapper->TEST(err == KErrNone);
       
    83 	bookmark.SetWritableL(ETrue);
       
    84 	
       
    85 	gTestWrapper->Next(_L("[CBookmarkBase tests] handle"));
       
    86 	gTestWrapper->TEST(bookmark.RefCount() == 0);
       
    87 	RBkFolder root = db->RootL().OpenFolder();
       
    88 	CleanupClosePushL(root);
       
    89 	RBkNode handle = root.OpenItemL(0);
       
    90 	CleanupClosePushL(handle);
       
    91 	
       
    92 	gTestWrapper->TEST(bookmark.RefCount() == 1);
       
    93 	gTestWrapper->TEST(handle.Type() == bookmark.Type());
       
    94 	gTestWrapper->TEST(handle.Title() == bookmark.Title());
       
    95 	
       
    96 	CleanupStack::PopAndDestroy(&handle);
       
    97 	CleanupStack::PopAndDestroy(&root);
       
    98 
       
    99 	CleanupStack::PopAndDestroy(db);
       
   100 	}
       
   101 
       
   102 void DoCBookmarkBaseUnitL(CTestWrapper* aTest)
       
   103 	{
       
   104 	gTestWrapper = aTest;
       
   105 	gTestWrapper->SetFile(KFilename);
       
   106 	gTestWrapper->Next(_L("*** CBookmarkBase tests ***"));
       
   107 
       
   108 	GeneralTestsL();
       
   109 	}