--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/activityfw/storage/server/tsrc/t_server/t_server.cpp Thu Sep 16 12:11:40 2010 +0100
@@ -0,0 +1,178 @@
+//Copyright (c) 2010 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:
+
+/////////////////////////////////////////////////////////////////////
+
+// INCLUDED FILES
+#include <QtTest/QtTest>
+#include <bautils.h>
+#include "t_server.h"
+#include "t_installer.h"
+#include "afserver.h"
+#include "afstorage.h"
+#include "afapplicationsmonitor.h"
+#include "afapplicationscollection.h"
+#include "afapplicationsengine.h"
+
+_LIT(KSisPackageFileName,"c:\\sapiapp_S60_3_X_v_1_0_0.sisx");
+_LIT(KSisAppFileName, "c:\\sys\\bin\\sapiapp.exe");
+const TUid KSisAppUid(TUid::Uid(0xe6bc1167));
+
+
+void T_Server::testStorage()
+{
+ _LIT(KDbName, "activity.db");
+ _LIT(KDbDrive, "c:");
+
+ RFs fileSession;
+ CleanupClosePushL(fileSession);
+ fileSession.Connect();
+
+ //remove database if exists
+ RBuf path;
+ CleanupClosePushL( path );
+ path.CreateL(256);
+ User::LeaveIfError(fileSession.PrivatePath(path ));
+ path.Append(KDbName);
+ path.Insert(0, KDbDrive);
+ BaflUtils::EnsurePathExistsL(fileSession, path);
+ if(BaflUtils::FileExists(fileSession, path)) {
+ fileSession.Delete(path);
+ }
+ CleanupStack::PopAndDestroy(&path);
+
+
+ //create storage when database doesnt exists
+ CAfStorage* storage = CAfStorage::NewL(fileSession);
+ delete storage;
+
+ //create storage when database already exists
+ storage = CAfStorage::NewL(fileSession);
+ delete storage;
+
+ CleanupStack::PopAndDestroy(&fileSession);
+}
+
+void T_Server::testMonitor()
+{
+ TInt errNo;
+ RApaLsSession session;
+ QVERIFY(KErrNone == session.Connect());
+ CAfApplicationsMonitor *monitor = CAfApplicationsMonitor::NewL(session, *this);
+ CleanupStack::PushL(monitor);
+ T_Installer *installer = T_Installer::NewL();
+ CleanupStack::PushL(installer);
+
+ //install application. sis file
+ mAppChanged = false;
+
+ TRAP(errNo, installer->InstallL(KSisPackageFileName));
+ if (KErrNone == errNo) {
+ if(!mAppChanged) {
+ QTimer::singleShot(5000, &mLoop, SLOT(quit()));
+ mLoop.exec();
+ }
+ QVERIFY(mAppChanged);
+ }
+
+ //uninstall application
+ mAppChanged = false;
+ TRAP(errNo, installer->UninstallL(installer->GetComponentIdL(KSisAppFileName)));
+ if (KErrNone == errNo) {
+ if(!mAppChanged) {
+ QTimer::singleShot(5000, &mLoop, SLOT(quit()));
+ mLoop.exec();
+ }
+ QVERIFY(mAppChanged);
+ }
+ CleanupStack::PopAndDestroy(installer);
+ CleanupStack::PopAndDestroy(monitor);
+ session.Close();
+}
+
+void T_Server::testCollection()
+{
+ TInt errNo, offset;
+ RApaLsSession session;
+ QVERIFY(KErrNone == session.Connect());
+
+ CAfApplicationsCollection *collection = CAfApplicationsCollection::NewL(session, this);
+ CleanupStack::PushL(collection);
+
+ CAfApplicationsMonitor *monitor = CAfApplicationsMonitor::NewL(session, *collection);
+ CleanupStack::PushL(monitor);
+
+ T_Installer *installer = T_Installer::NewL();
+ CleanupStack::PushL(installer);
+
+ //install application. sis file
+ mAppChanged = false;
+ TRAP(errNo, installer->InstallL(KSisPackageFileName));
+ if(KErrNone == errNo) {
+ if(!mAppChanged) {
+ QTimer::singleShot(10000, &mLoop, SLOT(quit()));
+ mLoop.exec();
+ }
+ QVERIFY(mAppChanged);
+ }
+
+ //uninstall application
+ mAppChanged = false;
+ TRAP(errNo, installer->UninstallL(installer->GetComponentIdL(KSisAppFileName)));
+ if(KErrNone == errNo) {
+ if(!mAppChanged) {
+ QTimer::singleShot(10000, &mLoop, SLOT(quit()));
+ mLoop.exec();
+ }
+ QVERIFY(mAppChanged);
+ TArray<TUid> removedApps(collection->removedApplications());
+ for (offset =0; offset < removedApps.Count(); ++offset) {
+ if (removedApps[offset] == KSisAppUid) {
+ break;
+ }
+ }
+ QVERIFY(offset < removedApps.Count());
+ }
+ CleanupStack::PopAndDestroy(installer);
+ CleanupStack::PopAndDestroy(monitor);
+ CleanupStack::PopAndDestroy(collection);
+ session.Close();
+}
+
+void T_Server::testEngine()
+{
+ RApaLsSession appSession;
+ CleanupClosePushL(appSession);
+ QVERIFY(KErrNone == appSession.Connect());
+ RFs fsSession;
+ CleanupClosePushL(fsSession);
+ QVERIFY(KErrNone == fsSession.Connect());
+ CAfStorage* storage = CAfStorage::NewL(fsSession);
+ CAfApplicationsEngine *engine = CAfApplicationsEngine::NewL(appSession, *storage);
+ QVERIFY(0 != engine);
+ delete engine;
+ delete storage;
+ CleanupStack::PopAndDestroy(&fsSession);
+ CleanupStack::PopAndDestroy(&appSession);
+}
+
+void T_Server::applicationsChanged()
+{
+ mAppChanged = true;
+ if (mLoop.isRunning()) {
+ mLoop.quit();
+ }
+}
+
+QTEST_MAIN(T_Server)