contentstorage/casrv/calocalizerscanner/tsrc/t_calocalizerscanner/src/t_calocalizerscanner.cpp
changeset 117 c63ee96dbe5f
equal deleted inserted replaced
115:3ab5c078b490 117:c63ee96dbe5f
       
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Main test class for hspluginmodel library.
       
    15 *
       
    16 */
       
    17 
       
    18 //s60
       
    19 #include <e32base.h>
       
    20 #include <W32STD.H>
       
    21 #include "cadef.h"
       
    22 
       
    23 #include "t_calocalizerscanner.h"
       
    24 
       
    25 //local
       
    26 #include "calocalizerscannerproxy.h"
       
    27 #include "castorageproxy.h"
       
    28 #include "cainnerquery.h"
       
    29 #include "cainnerentry.h"
       
    30 
       
    31 #include <XQConversions>
       
    32 
       
    33 /*
       
    34 Test must be compiled with flag
       
    35 test database "./data/castorage.db " must be exported to KDBSource
       
    36 */
       
    37 
       
    38     _LIT(KDBSource, "C:\\testing\\data\\localizer\\castorage.db");
       
    39     _LIT(KDBDest, "c:\\castorage.db");
       
    40     _LIT(KTextForeign, "TestString");
       
    41     _LIT(KTextLocal, "Recently added");
       
    42     const TUid KLocalizerScannerPluginUid = {0x20028709};
       
    43 // ---------------------------------------------------------------------------
       
    44 //
       
    45 void TestCaLocalizerScanner::initTestCase()
       
    46 {
       
    47     iFs.Connect();
       
    48 
       
    49     QT_TRAP_THROWING(
       
    50         //copy prepared database
       
    51         iFileManager = CFileMan::NewL(iFs);
       
    52         iFileManager->Copy(KDBSource, KDBDest);
       
    53         iStorageProxy = CCaStorageProxy::NewL();
       
    54     );
       
    55 }
       
    56 // ---------------------------------------------------------------------------
       
    57 // ---------------------------------------------------------------------------
       
    58 //
       
    59 void TestCaLocalizerScanner::cleanupTestCase()
       
    60     {
       
    61     iFileManager->Delete(KDBDest);
       
    62     delete iFileManager;
       
    63     delete iStorageProxy;
       
    64     }
       
    65 /// TESTS
       
    66 
       
    67 /*void TestCaLocalizerScanner::TestLoadTranslator()
       
    68     {
       
    69     CCaLocalizerScannerProxy* localizerProxy;
       
    70     localizerProxy = new CCaLocalizerScannerProxy(iStorageProxy);
       
    71     localizerProxy->loadTranslator(QString("filename"));
       
    72     }*/
       
    73 
       
    74 void TestCaLocalizerScanner::TestLoadLocalizerPlugin()
       
    75     {
       
    76     TPluginParams params;
       
    77     params.storageProxy = iStorageProxy;
       
    78     QScopedPointer<CCaSrvPlugin> plug;
       
    79     TRAP_IGNORE(plug.reset(LoadPluginL( KLocalizerScannerPluginUid, params)));
       
    80     QVERIFY2(plug, "plugin not loaded");
       
    81     }
       
    82 
       
    83 void TestCaLocalizerScanner::TestInitializeScannerProxy()
       
    84     {
       
    85     TRAP_IGNORE(
       
    86             TestInitializeScannerProxyTrapped();
       
    87             );
       
    88     }
       
    89 // ---------------------------------------------------------------------------
       
    90 // ---------------------------------------------------------------------------
       
    91 //
       
    92 void TestCaLocalizerScanner::TestInitializeScannerProxyTrapped()
       
    93     {
       
    94     CCaLocalizerScannerProxy* localizerProxy;
       
    95     CCaInnerEntry* entry;
       
    96     // 2 is entryId of downloaded collection.
       
    97     //In the test database EN_TEXT of downl. col. is 'TestString'
       
    98     // after localization on english epoc it should be 'Downloaded'
       
    99     entry = GetEntryById(2);
       
   100     //iStorageProxy->SetDBPropertyL( KCaDbPropLanguage, KCaDbPropLanguage );
       
   101     QVERIFY2(entry->GetText().CompareC(KTextForeign) == 0, "wrong database");
       
   102     //do the localization
       
   103     // localizerProxy = CCaLocalizerScannerProxy::NewL(iStorageProxy);
       
   104     TPluginParams params;
       
   105     params.storageProxy = iStorageProxy;
       
   106     CCaSrvPlugin* plug = LoadPluginL( KLocalizerScannerPluginUid, params);
       
   107 
       
   108     entry = GetEntryById(2);
       
   109     qDebug() << "entry->GetText()";
       
   110     qDebug() << XQConversions::s60DescToQString(entry->GetText()).toLatin1();
       
   111     QVERIFY2(entry->GetText().CompareC(KTextLocal) == 0,
       
   112             "localization went wrong");
       
   113     delete plug;
       
   114     }
       
   115 
       
   116 // ***************************************** helper functions
       
   117 
       
   118 CCaInnerEntry* TestCaLocalizerScanner::GetEntryById(TInt aId)
       
   119     {
       
   120     QScopedPointer<CCaInnerQuery> query;
       
   121     CCaInnerEntry* entry(0);
       
   122     QT_TRAP_THROWING(query.reset(CCaInnerQuery::NewL()));
       
   123     TRAP_IGNORE(
       
   124             RArray<TInt> array;
       
   125             CleanupClosePushL(array);
       
   126             array.Append(aId); // entry
       
   127             RPointerArray<CCaInnerEntry> resultArray;
       
   128             CleanupClosePushL(resultArray);
       
   129             query->SetIdsL(array);
       
   130             iStorageProxy->GetEntriesL(query.data(), resultArray);
       
   131             if (resultArray.Count())
       
   132                 {
       
   133                 entry = resultArray[0];
       
   134                 resultArray.Remove(0);
       
   135                 }
       
   136             CleanupStack::PopAndDestroy(&resultArray);
       
   137             CleanupStack::Pop(&array);
       
   138     );
       
   139     return entry;
       
   140     }
       
   141 
       
   142 
       
   143 CCaSrvPlugin* TestCaLocalizerScanner::LoadPluginL( TUid aImplUid, TPluginParams aPluginParams )
       
   144     {
       
   145     CCaSrvPlugin* plug = NULL;
       
   146 
       
   147     RImplInfoPtrArray infoArray;
       
   148 
       
   149     // Note that a special cleanup function is required to reset and destroy
       
   150     // all items in the array, and then close it.
       
   151     CleanupClosePushL( infoArray );
       
   152     CCaSrvPlugin::ListAllImplementationsL( infoArray );
       
   153 
       
   154     // Loop through each info for each implementation
       
   155     // and create and use each in turn
       
   156     for( TInt i = 0; i < infoArray.Count(); i++ )
       
   157         {
       
   158         // Slice off first sub-section in the data section
       
   159         TUid current_plugin = infoArray[i]->ImplementationUid();
       
   160         if ( current_plugin == aImplUid )
       
   161             {
       
   162             plug = CCaSrvPlugin::NewL( current_plugin, &aPluginParams );
       
   163             break;
       
   164             }
       
   165         }
       
   166     CleanupStack::PopAndDestroy( &infoArray );
       
   167 
       
   168     return plug;
       
   169     }
       
   170 //#endif //Q_OS_SYMBIAN
       
   171 
       
   172 QTEST_MAIN(TestCaLocalizerScanner)
       
   173