activityfw/storage/server/tsrc/t_server/t_server.cpp
changeset 117 c63ee96dbe5f
equal deleted inserted replaced
115:3ab5c078b490 117:c63ee96dbe5f
       
     1 //Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
       
     2 //All rights reserved.
       
     3 //This component and the accompanying materials are made available
       
     4 //under the terms of "Eclipse Public License v1.0"
       
     5 //which accompanies this distribution, and is available
       
     6 //at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 
       
     8 //Initial Contributors:
       
     9 //Nokia Corporation - initial contribution.
       
    10 
       
    11 //Contributors:
       
    12 
       
    13 //Description:
       
    14 
       
    15 /////////////////////////////////////////////////////////////////////
       
    16 
       
    17 // INCLUDED FILES
       
    18 #include <QtTest/QtTest>
       
    19 #include <bautils.h>
       
    20 #include "t_server.h"
       
    21 #include "t_installer.h"
       
    22 #include "afserver.h"
       
    23 #include "afstorage.h"
       
    24 #include "afapplicationsmonitor.h"
       
    25 #include "afapplicationscollection.h"
       
    26 #include "afapplicationsengine.h"
       
    27 
       
    28 _LIT(KSisPackageFileName,"c:\\sapiapp_S60_3_X_v_1_0_0.sisx");
       
    29 _LIT(KSisAppFileName, "c:\\sys\\bin\\sapiapp.exe");
       
    30 const TUid KSisAppUid(TUid::Uid(0xe6bc1167));
       
    31 
       
    32 
       
    33 void T_Server::testStorage()
       
    34 {
       
    35     _LIT(KDbName, "activity.db");
       
    36     _LIT(KDbDrive, "c:");
       
    37     
       
    38     RFs fileSession;
       
    39     CleanupClosePushL(fileSession);
       
    40     fileSession.Connect();
       
    41     
       
    42     //remove database if exists
       
    43     RBuf path;
       
    44     CleanupClosePushL( path );
       
    45     path.CreateL(256);
       
    46     User::LeaveIfError(fileSession.PrivatePath(path ));
       
    47     path.Append(KDbName);
       
    48     path.Insert(0, KDbDrive);
       
    49     BaflUtils::EnsurePathExistsL(fileSession, path);
       
    50     if(BaflUtils::FileExists(fileSession, path)) {
       
    51         fileSession.Delete(path);
       
    52     }
       
    53     CleanupStack::PopAndDestroy(&path);
       
    54     
       
    55     
       
    56     //create storage when database doesnt exists
       
    57     CAfStorage* storage = CAfStorage::NewL(fileSession);
       
    58     delete storage;
       
    59     
       
    60     //create storage when database already exists
       
    61     storage = CAfStorage::NewL(fileSession);
       
    62     delete storage;
       
    63     
       
    64     CleanupStack::PopAndDestroy(&fileSession);
       
    65 }
       
    66 
       
    67 void T_Server::testMonitor()
       
    68 {
       
    69     TInt errNo;
       
    70     RApaLsSession session;
       
    71     QVERIFY(KErrNone == session.Connect());
       
    72     CAfApplicationsMonitor *monitor = CAfApplicationsMonitor::NewL(session, *this);
       
    73     CleanupStack::PushL(monitor);
       
    74     T_Installer *installer = T_Installer::NewL();
       
    75     CleanupStack::PushL(installer);
       
    76     
       
    77     //install application. sis file
       
    78     mAppChanged = false;
       
    79     
       
    80     TRAP(errNo, installer->InstallL(KSisPackageFileName));
       
    81     if (KErrNone == errNo) {
       
    82         if(!mAppChanged) {
       
    83             QTimer::singleShot(5000, &mLoop, SLOT(quit()));
       
    84             mLoop.exec();
       
    85         }
       
    86         QVERIFY(mAppChanged);
       
    87     }
       
    88     
       
    89     //uninstall application
       
    90     mAppChanged = false;
       
    91     TRAP(errNo, installer->UninstallL(installer->GetComponentIdL(KSisAppFileName)));
       
    92     if (KErrNone == errNo) {
       
    93         if(!mAppChanged) {
       
    94             QTimer::singleShot(5000, &mLoop, SLOT(quit()));
       
    95             mLoop.exec();
       
    96         }
       
    97         QVERIFY(mAppChanged);
       
    98     }
       
    99     CleanupStack::PopAndDestroy(installer);
       
   100     CleanupStack::PopAndDestroy(monitor);
       
   101     session.Close();
       
   102 }
       
   103 
       
   104 void T_Server::testCollection()
       
   105 {
       
   106     TInt errNo, offset;
       
   107     RApaLsSession session;
       
   108     QVERIFY(KErrNone == session.Connect());
       
   109     
       
   110     CAfApplicationsCollection *collection = CAfApplicationsCollection::NewL(session, this);
       
   111     CleanupStack::PushL(collection);
       
   112     
       
   113     CAfApplicationsMonitor *monitor = CAfApplicationsMonitor::NewL(session, *collection);
       
   114     CleanupStack::PushL(monitor);
       
   115     
       
   116     T_Installer *installer = T_Installer::NewL();
       
   117     CleanupStack::PushL(installer);
       
   118     
       
   119     //install application. sis file
       
   120     mAppChanged = false;
       
   121     TRAP(errNo, installer->InstallL(KSisPackageFileName));
       
   122     if(KErrNone == errNo) {
       
   123         if(!mAppChanged) {
       
   124             QTimer::singleShot(10000, &mLoop, SLOT(quit()));
       
   125             mLoop.exec();
       
   126         }
       
   127         QVERIFY(mAppChanged);
       
   128     }
       
   129     
       
   130     //uninstall application
       
   131     mAppChanged = false;
       
   132     TRAP(errNo, installer->UninstallL(installer->GetComponentIdL(KSisAppFileName)));
       
   133     if(KErrNone == errNo) {
       
   134         if(!mAppChanged) {
       
   135             QTimer::singleShot(10000, &mLoop, SLOT(quit()));
       
   136             mLoop.exec();
       
   137         }
       
   138         QVERIFY(mAppChanged);
       
   139         TArray<TUid> removedApps(collection->removedApplications());
       
   140         for (offset =0; offset < removedApps.Count(); ++offset) {
       
   141             if (removedApps[offset] == KSisAppUid) {
       
   142                 break;
       
   143             }
       
   144         }
       
   145         QVERIFY(offset < removedApps.Count());
       
   146     }
       
   147     CleanupStack::PopAndDestroy(installer);
       
   148     CleanupStack::PopAndDestroy(monitor);
       
   149     CleanupStack::PopAndDestroy(collection);
       
   150     session.Close();
       
   151 }
       
   152 
       
   153 void T_Server::testEngine()
       
   154 {
       
   155     RApaLsSession appSession;
       
   156     CleanupClosePushL(appSession);
       
   157     QVERIFY(KErrNone == appSession.Connect());
       
   158     RFs fsSession;
       
   159     CleanupClosePushL(fsSession);
       
   160     QVERIFY(KErrNone == fsSession.Connect());
       
   161     CAfStorage* storage = CAfStorage::NewL(fsSession);
       
   162     CAfApplicationsEngine *engine = CAfApplicationsEngine::NewL(appSession, *storage);
       
   163     QVERIFY(0 != engine);
       
   164     delete engine;
       
   165     delete storage; 
       
   166     CleanupStack::PopAndDestroy(&fsSession);
       
   167     CleanupStack::PopAndDestroy(&appSession);
       
   168 }
       
   169 
       
   170 void T_Server::applicationsChanged()
       
   171 {
       
   172     mAppChanged = true;
       
   173     if (mLoop.isRunning()) {
       
   174         mLoop.quit();
       
   175     }
       
   176 }
       
   177 
       
   178 QTEST_MAIN(T_Server)