--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/contentstorage/castorage/tsrc/t_castorage/src/castoragetestproperties.cpp Thu Sep 16 12:11:40 2010 +0100
@@ -0,0 +1,197 @@
+/*
+* 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:
+*
+*/
+/*
+ * castoragetestproperties.cpp
+ *
+ * Created on: 2009-08-17
+ * Author: michal.wojcik
+ */
+
+#include "castoragetest.h"
+#include "castoragefactory.h"
+#include "castorage.h"
+#include "cainnerentry.h"
+#include "casqlquery.h"
+#include "casqlitestorage.h"
+#include "castoragetestsqlcommands.h"
+#include "casqlcommands.h"
+#include "cadef.h"
+
+// ============================ MEMBER FUNCTIONS ===============================
+
+// ---------------------------------------------------------------------------
+//
+// ---------------------------------------------------------------------------
+//
+void CCAStorageTest::testPropertyGetDbVersion()
+{
+ TInt err(KErrGeneral);
+
+ __UHEAP_MARK;
+
+ _LIT(KProperty, "Version");
+ _LIT(KPropertyValue, "00001");
+ _LIT(KPropertyValue2, "00002");
+ TRAP(err,
+ // set db version property - 00001
+ mStorage->SetDBPropertyL(KProperty, KPropertyValue);
+
+ TBuf<20> propertyValue;
+ mStorage->DbPropertyL(KProperty, propertyValue);
+
+ if (!propertyValue.CompareC(KPropertyValue)) {
+ err = KErrNone;
+}
+
+// set db version property - 00002
+mStorage->SetDBPropertyL(KProperty, KPropertyValue2);
+
+TBuf<20> propertyValue2;
+mStorage->DbPropertyL(KProperty, propertyValue2);
+
+// check results
+if (err == KErrNone) {
+ if (!propertyValue2.CompareC(KPropertyValue2)) {
+ err = KErrNone;
+ } else {
+ err = KErrGeneral;
+ }
+ }
+ );
+ __UHEAP_MARKEND;
+
+ QCOMPARE(err, KErrNone);
+}
+
+void CCAStorageTest::testPropertyGetLanguage()
+{
+ TInt err(KErrGeneral);
+
+ __UHEAP_MARK;
+
+ _LIT(KProperty, "Language");
+ _LIT(KPropertyValue, "en_GB");
+ _LIT(KPropertyValue2, "pl_PL");
+
+ TRAP(err,
+ // set lanquage property - en_GB
+ mStorage->SetDBPropertyL(KProperty, KPropertyValue);
+
+ TBuf<20> propertyValue;
+ mStorage->DbPropertyL(KProperty, propertyValue);
+
+ if (!propertyValue.CompareC(KPropertyValue)) {
+ err = KErrNone;
+}
+
+// set lanquage property - pl_PL
+mStorage->SetDBPropertyL(KProperty, KPropertyValue2);
+
+TBuf<20> propertyValue2;
+mStorage->DbPropertyL(KProperty, propertyValue2);
+
+// check results
+if (err == KErrNone) {
+ if (!propertyValue2.CompareC(KPropertyValue2)) {
+ err = KErrNone;
+ } else {
+ err = KErrGeneral;
+ }
+ }
+ );
+ __UHEAP_MARKEND;
+
+ QCOMPARE(err, KErrNone);
+}
+
+void CCAStorageTest::testLoadDBFromROM()
+{
+ TInt err(KErrGeneral);
+
+ delete mStorage;
+ mStorage = NULL;
+
+ //we copy corrupted db
+ QFile corruptedfile("c:/testing/data/t_castorage/corruptedcastoragedb");
+ QFile file("c:/castorage.db");
+ bool ok = corruptedfile.open(QIODevice::ReadOnly);
+ ok = file.open(QIODevice::ReadWrite) && ok;
+ ok = file.remove() && ok;
+ ok = corruptedfile.copy("c:/castorage.db") && ok;
+ QCOMPARE(ok, true);
+
+ corruptedfile.close();
+ file.close();
+
+ TRAP(err,
+ mStorage = CaStorageFactory::NewDatabaseL();
+ );
+
+
+ CCaSqLiteStorage *storage = dynamic_cast<CCaSqLiteStorage *>(mStorage);
+ storage->iPrivatePathZDriveDb.Copy(_L("c:\\testing\\data\\t_castorage\\castorage.db"));
+ TRAP(err,
+ mStorage->LoadDataBaseFromRomL();
+ );
+ QCOMPARE(err, KErrNone);
+ testGetEntriesById();// to check that db is accesible
+}
+
+// not stable to use due to impossibilty to dynamically load db to rom
+/*void CCAStorageTest::testBadDBVersion()
+{
+ TInt err(KErrGeneral);
+
+ delete mStorage;
+ mStorage = NULL;
+
+ //we copy db with bad version db
+ QFile badversionfile("c:/testing/data/t_castorage/versioncastoragedb");
+ QFile file("c:/castorage.db");
+ bool ok = badversionfile.open(QIODevice::ReadOnly);
+ ok = file.open(QIODevice::ReadWrite) && ok;
+ ok = file.remove() && ok;
+ ok = badversionfile.copy("c:/castorage.db") && ok;
+ QCOMPARE(ok, true);
+ badversionfile.close();
+ file.close();
+
+ //we would like to copy good db to rom
+ //but we can only assume that it is already there
+ QFile goodversionfile("c:/testing/data/t_castorage/castorage.db");
+ QFile file2("z:/castorage.db");
+ ok = goodversionfile.open(QIODevice::ReadOnly);
+ ok = file2.open(QIODevice::ReadWrite) && ok;
+ ok = file2.remove() && ok;
+ ok = goodversionfile.copy("z:/castorage.db") && ok;
+ QCOMPARE(ok, true);
+ badversionfile.close();
+ file2.close();
+
+
+ TRAP(err,
+ mStorage = CaStorageFactory::NewDatabaseL();
+ );
+
+ //check id good version was loaded instead
+ CCaSqLiteStorage* castorage = dynamic_cast<CCaSqLiteStorage *>(mStorage);
+ TBuf<KCaMaxAttrNameLen> versionValue;
+ castorage->DbPropertyL(KCaDbPropVersion, versionValue);
+ TInt res = versionValue.CompareC( KCaDbVersion );
+ QVERIFY(res == 0);
+}*/
+