contentstorage/castorage/tsrc/t_castorage/src/castoragetestproperties.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:
       
    15 *
       
    16 */
       
    17 /*
       
    18  * castoragetestproperties.cpp
       
    19  *
       
    20  *  Created on: 2009-08-17
       
    21  *      Author: michal.wojcik
       
    22  */
       
    23 
       
    24 #include "castoragetest.h"
       
    25 #include "castoragefactory.h"
       
    26 #include "castorage.h"
       
    27 #include "cainnerentry.h"
       
    28 #include "casqlquery.h"
       
    29 #include "casqlitestorage.h"
       
    30 #include "castoragetestsqlcommands.h"
       
    31 #include "casqlcommands.h"
       
    32 #include "cadef.h"
       
    33 
       
    34 // ============================ MEMBER FUNCTIONS ===============================
       
    35 
       
    36 // ---------------------------------------------------------------------------
       
    37 //
       
    38 // ---------------------------------------------------------------------------
       
    39 //
       
    40 void CCAStorageTest::testPropertyGetDbVersion()
       
    41 {
       
    42     TInt err(KErrGeneral);
       
    43 
       
    44     __UHEAP_MARK;
       
    45 
       
    46     _LIT(KProperty, "Version");
       
    47     _LIT(KPropertyValue, "00001");
       
    48     _LIT(KPropertyValue2, "00002");
       
    49     TRAP(err,
       
    50          // set db version property - 00001
       
    51          mStorage->SetDBPropertyL(KProperty, KPropertyValue);
       
    52 
       
    53          TBuf<20> propertyValue;
       
    54          mStorage->DbPropertyL(KProperty, propertyValue);
       
    55 
       
    56     if (!propertyValue.CompareC(KPropertyValue)) {
       
    57     err = KErrNone;
       
    58 }
       
    59 
       
    60 // set db version property - 00002
       
    61 mStorage->SetDBPropertyL(KProperty, KPropertyValue2);
       
    62 
       
    63 TBuf<20> propertyValue2;
       
    64 mStorage->DbPropertyL(KProperty, propertyValue2);
       
    65 
       
    66 // check results
       
    67 if (err == KErrNone) {
       
    68     if (!propertyValue2.CompareC(KPropertyValue2)) {
       
    69             err = KErrNone;
       
    70         } else {
       
    71             err = KErrGeneral;
       
    72         }
       
    73     }
       
    74         );
       
    75     __UHEAP_MARKEND;
       
    76 
       
    77     QCOMPARE(err, KErrNone);
       
    78 }
       
    79 
       
    80 void CCAStorageTest::testPropertyGetLanguage()
       
    81 {
       
    82     TInt err(KErrGeneral);
       
    83 
       
    84     __UHEAP_MARK;
       
    85 
       
    86     _LIT(KProperty, "Language");
       
    87     _LIT(KPropertyValue, "en_GB");
       
    88     _LIT(KPropertyValue2, "pl_PL");
       
    89 
       
    90     TRAP(err,
       
    91          // set lanquage property - en_GB
       
    92          mStorage->SetDBPropertyL(KProperty, KPropertyValue);
       
    93 
       
    94          TBuf<20> propertyValue;
       
    95          mStorage->DbPropertyL(KProperty, propertyValue);
       
    96 
       
    97     if (!propertyValue.CompareC(KPropertyValue)) {
       
    98     err = KErrNone;
       
    99 }
       
   100 
       
   101 // set lanquage property - pl_PL
       
   102 mStorage->SetDBPropertyL(KProperty, KPropertyValue2);
       
   103 
       
   104 TBuf<20> propertyValue2;
       
   105 mStorage->DbPropertyL(KProperty, propertyValue2);
       
   106 
       
   107 // check results
       
   108 if (err == KErrNone) {
       
   109     if (!propertyValue2.CompareC(KPropertyValue2)) {
       
   110             err = KErrNone;
       
   111         } else {
       
   112             err = KErrGeneral;
       
   113         }
       
   114     }
       
   115         );
       
   116     __UHEAP_MARKEND;
       
   117 
       
   118     QCOMPARE(err, KErrNone);
       
   119 }
       
   120 
       
   121 void CCAStorageTest::testLoadDBFromROM()
       
   122 {
       
   123     TInt err(KErrGeneral);
       
   124 
       
   125     delete mStorage;
       
   126     mStorage = NULL;
       
   127 
       
   128     //we copy corrupted db
       
   129     QFile corruptedfile("c:/testing/data/t_castorage/corruptedcastoragedb");
       
   130     QFile file("c:/castorage.db");
       
   131     bool ok = corruptedfile.open(QIODevice::ReadOnly);
       
   132     ok = file.open(QIODevice::ReadWrite) && ok;
       
   133     ok = file.remove() && ok;
       
   134     ok = corruptedfile.copy("c:/castorage.db") && ok;
       
   135     QCOMPARE(ok, true);
       
   136 
       
   137     corruptedfile.close();
       
   138     file.close();
       
   139 
       
   140     TRAP(err,
       
   141          mStorage = CaStorageFactory::NewDatabaseL();
       
   142         );
       
   143 
       
   144 
       
   145     CCaSqLiteStorage *storage = dynamic_cast<CCaSqLiteStorage *>(mStorage);
       
   146     storage->iPrivatePathZDriveDb.Copy(_L("c:\\testing\\data\\t_castorage\\castorage.db"));
       
   147     TRAP(err,
       
   148          mStorage->LoadDataBaseFromRomL();
       
   149         );
       
   150     QCOMPARE(err, KErrNone);
       
   151     testGetEntriesById();// to check that db is accesible
       
   152 }
       
   153 
       
   154 // not stable to use due to impossibilty to dynamically load db to rom
       
   155 /*void CCAStorageTest::testBadDBVersion()
       
   156 {
       
   157     TInt err(KErrGeneral);
       
   158        
       
   159     delete mStorage;
       
   160     mStorage = NULL;
       
   161     
       
   162     //we copy db with bad version db
       
   163     QFile badversionfile("c:/testing/data/t_castorage/versioncastoragedb");
       
   164     QFile file("c:/castorage.db");
       
   165     bool ok = badversionfile.open(QIODevice::ReadOnly);
       
   166     ok = file.open(QIODevice::ReadWrite) && ok;
       
   167     ok = file.remove() && ok;
       
   168     ok = badversionfile.copy("c:/castorage.db") && ok;
       
   169     QCOMPARE(ok, true);
       
   170     badversionfile.close();
       
   171     file.close();
       
   172 
       
   173     //we would like to copy good db to rom
       
   174     //but we can only assume that it is already there
       
   175     QFile goodversionfile("c:/testing/data/t_castorage/castorage.db");
       
   176     QFile file2("z:/castorage.db");
       
   177     ok = goodversionfile.open(QIODevice::ReadOnly);
       
   178     ok = file2.open(QIODevice::ReadWrite) && ok;
       
   179     ok = file2.remove() && ok;
       
   180     ok = goodversionfile.copy("z:/castorage.db") && ok;
       
   181     QCOMPARE(ok, true);
       
   182     badversionfile.close();
       
   183     file2.close();
       
   184    
       
   185 
       
   186     TRAP(err,
       
   187          mStorage = CaStorageFactory::NewDatabaseL();
       
   188         );
       
   189     
       
   190     //check id good version was loaded instead
       
   191     CCaSqLiteStorage* castorage = dynamic_cast<CCaSqLiteStorage *>(mStorage);
       
   192     TBuf<KCaMaxAttrNameLen> versionValue;
       
   193     castorage->DbPropertyL(KCaDbPropVersion, versionValue);
       
   194     TInt res = versionValue.CompareC( KCaDbVersion );
       
   195     QVERIFY(res == 0);
       
   196 }*/
       
   197