contentstorage/castorage/tsrc/t_castorage/src/castorageapiutils.cpp
changeset 117 c63ee96dbe5f
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/contentstorage/castorage/tsrc/t_castorage/src/castorageapiutils.cpp	Thu Sep 16 12:11:40 2010 +0100
@@ -0,0 +1,108 @@
+/*
+ * 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:
+ *
+ */
+
+#include "castoragetest.h"
+#include "castoragefactory.h"
+#include "castorage.h"
+#include <f32file.h>
+#include <XQConversions>
+
+// constants
+const QString srcDbFileName("c:/testing/data/t_castorage/castorage.db");
+const QString dstDbFileName("c:/castorage.db");
+
+
+// ============================ MEMBER FUNCTIONS ===============================
+
+
+void CCAStorageTest::initTestCase()
+{
+    QFile leftOverDbFile(dstDbFileName);
+    leftOverDbFile.open(QIODevice::ReadWrite);
+    leftOverDbFile.remove();
+
+}
+
+void CCAStorageTest::cleanupTestCase()
+{
+    QFile leftOverDbFile(dstDbFileName);
+    leftOverDbFile.open(QIODevice::ReadWrite);
+    leftOverDbFile.remove();
+}
+
+// -----------------------------------------------------------------------------
+//
+void CCAStorageTest::init()
+{
+    RestoreDatabase();
+
+    TRAPD(err,
+          mStorage = CaStorageFactory::NewDatabaseL();
+         );
+
+    QCOMPARE(err, KErrNone);
+}
+// -----------------------------------------------------------------------------
+//
+void CCAStorageTest::cleanup()
+{
+    delete mStorage;
+    mStorage = NULL;
+}
+
+// -----------------------------------------------------------------------------
+//
+void CCAStorageTest::RestoreDatabase()
+{
+    QFile leftOverDbFile(dstDbFileName);
+    leftOverDbFile.open(QIODevice::ReadWrite);
+    leftOverDbFile.remove();
+    leftOverDbFile.close();
+
+    QFile srcDbFile(srcDbFileName);
+    srcDbFile.open(QIODevice::ReadWrite);
+    srcDbFile.copy(dstDbFileName);
+    QTest::qWait(1000);
+}
+
+// -----------------------------------------------------------------------------
+//
+void CCAStorageTest::CopyFile(const TDesC &aSorcePath,
+                              const TDesC &aDestinationPath)
+{
+    RFs fs;
+    User::LeaveIfError(fs.Connect());
+
+    CFileMan *fileMan = CFileMan::NewL(fs);
+    CleanupStack::PushL(fileMan);
+
+    TInt error = fileMan->Copy(aSorcePath, aDestinationPath);
+
+    CleanupStack::PopAndDestroy(fileMan);
+
+    fs.Close();
+}
+
+
+QString CCAStorageTest::descToQString(const TDesC &descriptor)
+{
+    return XQConversions::s60DescToQString(descriptor);
+}
+
+
+
+QTEST_MAIN(CCAStorageTest);