contentstorage/casrv/calocalizerscanner/tsrc/t_calocalizerscanner/src/t_calocalizerscanner.cpp
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/contentstorage/casrv/calocalizerscanner/tsrc/t_calocalizerscanner/src/t_calocalizerscanner.cpp Thu Sep 16 12:11:40 2010 +0100
@@ -0,0 +1,173 @@
+/*
+* 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.
+*
+*/
+
+//s60
+#include <e32base.h>
+#include <W32STD.H>
+#include "cadef.h"
+
+#include "t_calocalizerscanner.h"
+
+//local
+#include "calocalizerscannerproxy.h"
+#include "castorageproxy.h"
+#include "cainnerquery.h"
+#include "cainnerentry.h"
+
+#include <XQConversions>
+
+/*
+Test must be compiled with flag
+test database "./data/castorage.db " must be exported to KDBSource
+*/
+
+ _LIT(KDBSource, "C:\\testing\\data\\localizer\\castorage.db");
+ _LIT(KDBDest, "c:\\castorage.db");
+ _LIT(KTextForeign, "TestString");
+ _LIT(KTextLocal, "Recently added");
+ const TUid KLocalizerScannerPluginUid = {0x20028709};
+// ---------------------------------------------------------------------------
+//
+void TestCaLocalizerScanner::initTestCase()
+{
+ iFs.Connect();
+
+ QT_TRAP_THROWING(
+ //copy prepared database
+ iFileManager = CFileMan::NewL(iFs);
+ iFileManager->Copy(KDBSource, KDBDest);
+ iStorageProxy = CCaStorageProxy::NewL();
+ );
+}
+// ---------------------------------------------------------------------------
+// ---------------------------------------------------------------------------
+//
+void TestCaLocalizerScanner::cleanupTestCase()
+ {
+ iFileManager->Delete(KDBDest);
+ delete iFileManager;
+ delete iStorageProxy;
+ }
+/// TESTS
+
+/*void TestCaLocalizerScanner::TestLoadTranslator()
+ {
+ CCaLocalizerScannerProxy* localizerProxy;
+ localizerProxy = new CCaLocalizerScannerProxy(iStorageProxy);
+ localizerProxy->loadTranslator(QString("filename"));
+ }*/
+
+void TestCaLocalizerScanner::TestLoadLocalizerPlugin()
+ {
+ TPluginParams params;
+ params.storageProxy = iStorageProxy;
+ QScopedPointer<CCaSrvPlugin> plug;
+ TRAP_IGNORE(plug.reset(LoadPluginL( KLocalizerScannerPluginUid, params)));
+ QVERIFY2(plug, "plugin not loaded");
+ }
+
+void TestCaLocalizerScanner::TestInitializeScannerProxy()
+ {
+ TRAP_IGNORE(
+ TestInitializeScannerProxyTrapped();
+ );
+ }
+// ---------------------------------------------------------------------------
+// ---------------------------------------------------------------------------
+//
+void TestCaLocalizerScanner::TestInitializeScannerProxyTrapped()
+ {
+ CCaLocalizerScannerProxy* localizerProxy;
+ CCaInnerEntry* entry;
+ // 2 is entryId of downloaded collection.
+ //In the test database EN_TEXT of downl. col. is 'TestString'
+ // after localization on english epoc it should be 'Downloaded'
+ entry = GetEntryById(2);
+ //iStorageProxy->SetDBPropertyL( KCaDbPropLanguage, KCaDbPropLanguage );
+ QVERIFY2(entry->GetText().CompareC(KTextForeign) == 0, "wrong database");
+ //do the localization
+ // localizerProxy = CCaLocalizerScannerProxy::NewL(iStorageProxy);
+ TPluginParams params;
+ params.storageProxy = iStorageProxy;
+ CCaSrvPlugin* plug = LoadPluginL( KLocalizerScannerPluginUid, params);
+
+ entry = GetEntryById(2);
+ qDebug() << "entry->GetText()";
+ qDebug() << XQConversions::s60DescToQString(entry->GetText()).toLatin1();
+ QVERIFY2(entry->GetText().CompareC(KTextLocal) == 0,
+ "localization went wrong");
+ delete plug;
+ }
+
+// ***************************************** helper functions
+
+CCaInnerEntry* TestCaLocalizerScanner::GetEntryById(TInt aId)
+ {
+ QScopedPointer<CCaInnerQuery> query;
+ CCaInnerEntry* entry(0);
+ QT_TRAP_THROWING(query.reset(CCaInnerQuery::NewL()));
+ TRAP_IGNORE(
+ RArray<TInt> array;
+ CleanupClosePushL(array);
+ array.Append(aId); // entry
+ RPointerArray<CCaInnerEntry> resultArray;
+ CleanupClosePushL(resultArray);
+ query->SetIdsL(array);
+ iStorageProxy->GetEntriesL(query.data(), resultArray);
+ if (resultArray.Count())
+ {
+ entry = resultArray[0];
+ resultArray.Remove(0);
+ }
+ CleanupStack::PopAndDestroy(&resultArray);
+ CleanupStack::Pop(&array);
+ );
+ return entry;
+ }
+
+
+CCaSrvPlugin* TestCaLocalizerScanner::LoadPluginL( TUid aImplUid, TPluginParams aPluginParams )
+ {
+ CCaSrvPlugin* plug = NULL;
+
+ RImplInfoPtrArray infoArray;
+
+ // Note that a special cleanup function is required to reset and destroy
+ // all items in the array, and then close it.
+ CleanupClosePushL( infoArray );
+ CCaSrvPlugin::ListAllImplementationsL( infoArray );
+
+ // Loop through each info for each implementation
+ // and create and use each in turn
+ for( TInt i = 0; i < infoArray.Count(); i++ )
+ {
+ // Slice off first sub-section in the data section
+ TUid current_plugin = infoArray[i]->ImplementationUid();
+ if ( current_plugin == aImplUid )
+ {
+ plug = CCaSrvPlugin::NewL( current_plugin, &aPluginParams );
+ break;
+ }
+ }
+ CleanupStack::PopAndDestroy( &infoArray );
+
+ return plug;
+ }
+//#endif //Q_OS_SYMBIAN
+
+QTEST_MAIN(TestCaLocalizerScanner)
+