contentstorage/caclient/tsrc/t_caclient/src/t_caclient_localization.cpp
changeset 117 c63ee96dbe5f
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/contentstorage/caclient/tsrc/t_caclient/src/t_caclient_localization.cpp	Thu Sep 16 12:11:40 2010 +0100
@@ -0,0 +1,183 @@
+/*
+* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributors:
+* Nokia Corporation - initial contribution.
+*
+* Contributors:
+*
+* Description:  Main test class for hspluginmodel library.
+*
+*/
+#include "t_caclient.h"
+#include "caservice.h"
+#include "castorageproxy.h"
+#include "caquery.h"
+#include "calocalizationentry.h"
+#include "cainnerentry.h"
+
+#ifdef Q_OS_SYMBIAN
+//s60
+#include <e32base.h>
+//#include <>
+#include <W32STD.H>
+#include <APGTASK.H>
+
+
+// ---------------------------------------------------------------------------
+// ---------------------------------------------------------------------------
+//
+void TestCaClient::TestLocalizationEntryGetters()
+{
+    CCaLocalizationEntry *entry(0);
+    _LIT(AttributeName,"AttributeName");
+    _LIT(StringId,"StringId");
+    _LIT(TableName,"TableName");
+    _LIT(LocalizedString,"LocalizedString");
+   
+    QT_TRAP_THROWING(entry = CCaLocalizationEntry::NewL());
+
+    entry->SetRowId(1);
+    entry->SetTextId(2);
+    
+    TRAPD(err, 
+        entry->SetAttributeNameL(AttributeName);    
+        entry->SetStringIdL(StringId);
+        entry->SetTableNameL(TableName);
+        entry->SetLocalizedStringL(LocalizedString);
+    );
+    
+    QCOMPARE(err, KErrNone);
+    QCOMPARE(entry->GetRowId(), 1);
+    QCOMPARE(entry->GetTextId(), 2);
+    QCOMPARE(entry->GetAttributeName().Compare(AttributeName), 0);
+    QCOMPARE(entry->GetTableName().Compare(TableName), 0);
+    QCOMPARE(entry->GetStringId().Compare(StringId), 0);
+    QCOMPARE(entry->GetLocalizedString().Compare(LocalizedString), 0);
+
+    delete entry;
+}
+
+// ---------------------------------------------------------------------------
+// ---------------------------------------------------------------------------
+//
+void TestCaClient::TestLocalizationTApp()
+{
+	_LIT( KTestDbSource, "C:\\testing\\data\\t_caclient\\castorage.db" );  // normal db
+	_LIT( KTestDbDest, "C:\\castorage.db" );
+	
+	RFs fs;
+	User::LeaveIfError( fs.Connect() );
+	CFileMan* fileManager = CFileMan::NewL( fs );
+	
+	fileManager->Copy( KTestDbSource, KTestDbDest );
+
+	
+	CCaStorageProxy* proxy = CCaStorageProxy::NewL();
+	
+	
+	_LIT(BadLocTxt,"loc://emailTest_/haha");
+	_LIT(BadQmTxt,"loc://haha/haha");
+	
+	_LIT(GoodLocTxt,"loc://emailTest_/txt_applib_dblist_games");
+	_LIT(GoodLocKey,"txt_applib_dblist_games");
+	_LIT(GoodLocResult,"Games");
+	
+	
+	
+	CCaInnerEntry* entry = CCaInnerEntry::NewL();
+	
+	entry->SetTextL( GoodLocTxt );
+	CCaLocalizationEntry* locEntry = proxy->LocalizeTextL( entry );
+	QVERIFY( !locEntry->GetStringId().Compare( GoodLocKey ) );
+	QVERIFY( !entry->GetText().Compare( GoodLocResult ) );
+	delete locEntry; 
+		
+	entry->SetDescriptionL( BadLocTxt );
+	CCaLocalizationEntry* locEntry2 = proxy->LocalizeDescriptionL( entry );
+	QVERIFY( locEntry2 == NULL );
+    QVERIFY( !entry->GetDescription().Compare( BadLocTxt ) );
+    delete locEntry2;  
+    
+    entry->SetDescriptionL( GoodLocTxt );
+    CCaLocalizationEntry* locEntry3 = proxy->LocalizeDescriptionL( entry );
+    QVERIFY( !locEntry3->GetStringId().Compare( GoodLocKey ) );
+    QVERIFY( !entry->GetDescription().Compare( GoodLocResult ) );
+    delete locEntry3;
+    
+    delete fileManager;
+    fs.Close();
+}
+
+// ---------------------------------------------------------------------------
+// ---------------------------------------------------------------------------
+//
+void TestCaClient::TestCreateLocalizedItem()
+{
+    {
+        const CaEntry constItem;
+        QCOMPARE(constItem.role(), ItemEntryRole);
+
+        //create item
+        //check if proper entry returned
+        CaEntry item;
+        item.setText("testName",true);
+        item.setAttribute("attrName1", "attrVal1");
+        item.setEntryTypeName("test");
+        item.setFlags(RemovableEntryFlag);
+        item.setDescription("description",true);
+        CaIconDescription iconDescription;
+        iconDescription.setFilename("iconFileName");
+        iconDescription.setSkinId("iconSkinId");
+        iconDescription.setApplicationId("268458321");
+
+        item.setIconDescription(iconDescription);
+
+        QSharedPointer<CaService> service = CaService::instance();
+        QSharedPointer<CaEntry> resultItem = service->createEntry(item);
+        QCOMPARE(service->lastError(), NoErrorCode);
+        QVERIFY(!resultItem.isNull());
+        QCOMPARE(resultItem->role(), ItemEntryRole);
+        QCOMPARE(item.text(),resultItem->text());
+        QCOMPARE(item.description(),resultItem->description());
+        QCOMPARE(item.entryTypeName(),resultItem->entryTypeName());
+        QCOMPARE(QString("attrVal1"),resultItem->attribute("attrName1"));
+        QCOMPARE(item.flags(),resultItem->flags());
+        int itId =item.id();
+        int resItId =resultItem->id();
+        QVERIFY(itId != resItId);
+        QCOMPARE(iconDescription.filename(),resultItem->iconDescription().filename());
+        QCOMPARE(iconDescription.skinId(),resultItem->iconDescription().skinId());
+        QCOMPARE(iconDescription.applicationId(),resultItem->iconDescription().applicationId());
+
+        // entry from storage
+        QSharedPointer<CaEntry> storageItem1 = service->getEntry(resultItem->id());
+        QVERIFY(storageItem1);
+        QCOMPARE(QString("testName"),storageItem1->text());
+        QCOMPARE(QString("description"),storageItem1->description());
+        QCOMPARE(QString("test"),storageItem1->entryTypeName());
+        QCOMPARE(QString("attrVal1"),storageItem1->attribute("attrName1"));
+        EntryFlags flags = item.flags();
+        EntryFlags storageFlags = storageItem1->flags();
+        QCOMPARE(iconDescription.filename(),storageItem1->iconDescription().filename());
+        QCOMPARE(iconDescription.skinId(),storageItem1->iconDescription().skinId());
+        QCOMPARE(iconDescription.applicationId(),storageItem1->iconDescription().applicationId());
+        QVERIFY(storageItem1->iconDescription().id() > 0);
+
+        QCOMPARE(flags ,storageFlags);
+
+        //Cleanup
+        service->removeEntry(*resultItem);
+    }
+}
+
+
+
+
+
+#endif //Q_OS_SYMBIAN