filemanager/tsrc/unit/ut_fmoprationserviceapi/src/ut_fmoprationserviceapi.cpp
changeset 47 12b82dc0e8db
equal deleted inserted replaced
40:4167eb56f30d 47:12b82dc0e8db
       
     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  *       test application for qt file manager operation service public apis.
       
    16  */
       
    17 
       
    18 #include "ut_fmoprationserviceapi.h"
       
    19 #include "testviewmanager.h"
       
    20 #include "fmoperationservice.h"
       
    21 #include "fmviewmanager.h"
       
    22 #include <QtTest/QtTest>
       
    23 #include <hbmainwindow.h>
       
    24 #include <QFile>
       
    25 #include <QtAlgorithms>
       
    26 
       
    27 /*!
       
    28  \class TestFmOperationService
       
    29  \brief describe the test case's goal, like: \n
       
    30  class name: FmOperationService \n
       
    31  class's description: The header file of the operation service of file manager \n
       
    32  type of test case: unit api test\n 
       
    33  test cases' number totally: \n
       
    34  */
       
    35 
       
    36 /*!
       
    37  Description of test data 
       
    38  */
       
    39 void TestFmOperationService::initTestCase()
       
    40 {
       
    41     mMainWindow = new HbMainWindow();
       
    42     TestViewManager::CreateTestViewManager(mMainWindow);   
       
    43     mOperationService = TestViewManager::viewManager()->operationService();
       
    44     QVERIFY (mOperationService != 0);
       
    45     
       
    46     connect(mOperationService, SIGNAL(notifyFinish( FmOperationBase*)),
       
    47             this, SLOT(onNotifyFinish( FmOperationBase*)));
       
    48     connect(mOperationService, SIGNAL(notifyError( FmOperationBase*, int, QString)), 
       
    49             this, SLOT(onNotifyError( FmOperationBase*, int, QString)));
       
    50     connect(mOperationService, SIGNAL(notifyCanceled( FmOperationBase* )),
       
    51             this, SLOT(onNotifyCanceled( FmOperationBase* )));
       
    52     
       
    53     // initialize public test data here
       
    54     mPath = Drive_C + QString("data") + QDir::separator() 
       
    55             + QString( "dataforfmoperation" ) + QDir::separator();
       
    56     mDataPath = Drive_C + QString("data") + QDir::separator() + QString( "dataforfmoperation" )
       
    57             + QDir::separator() + QString( "data" ) + QDir::separator();
       
    58     mDataMultiCopyPath = mDataPath + QString("multifilesforcopy") + QDir::separator();
       
    59     mDataMultiMovePath = mDataPath + QString("multifilesformove") + QDir::separator();
       
    60 }
       
    61 
       
    62 /*!
       
    63  Descrition of what you will do in this function
       
    64  */
       
    65 void TestFmOperationService::cleanupTestCase()
       
    66 {
       
    67 //  mOperationService and mMainWindow are deleted in RemoveViewManager() too.
       
    68     TestViewManager::RemoveViewManager();    
       
    69     // release all test data
       
    70 }
       
    71 
       
    72 /*!
       
    73  Test Case Description:\n 
       
    74  1. Fucntion Name: explicit FmOperationService( QObject *parent );  \n
       
    75  2. Case Descrition: test the constructor function. \n
       
    76  3. Input Parameters:  \n &nbsp;&nbsp;
       
    77  <1> parent = 0;\n &nbsp;&nbsp;
       
    78  <2> parent = new QObject(); \n
       
    79  4. Expected result: \n &nbsp;&nbsp;
       
    80  <1> no crash \n &nbsp;&nbsp;
       
    81  <2> no crash \n
       
    82  */
       
    83 void TestFmOperationService::testConstructor()
       
    84 {
       
    85     FmOperationService *testOperationService = new FmOperationService(0);
       
    86     QVERIFY (testOperationService != 0);
       
    87     delete testOperationService;
       
    88 }
       
    89 
       
    90 /*!
       
    91  Test Case Description:\n 
       
    92  1. Fucntion Name: int asyncViewDriveDetails( const QString driverName );  \n
       
    93  2. Case Descrition:  \n
       
    94  3. Input Parameters:  \n &nbsp;&nbsp;
       
    95  <1> driverName = QString(XX);\n &nbsp;&nbsp;
       
    96  <2> driverName = QString(); \n
       
    97  4. Expected result: \n &nbsp;&nbsp;
       
    98  <1> no crash \n &nbsp;&nbsp;
       
    99  <2> no crash \n
       
   100  */
       
   101 void TestFmOperationService::testAsyncViewDriveDetails()
       
   102 {
       
   103 //blocked, because of the UI problem.
       
   104 }
       
   105 
       
   106 /*!
       
   107  Test Case Description:\n 
       
   108  1. Fucntion Name:  \n &nbsp;&nbsp;
       
   109     int asyncCopy( const QStringList &sourceList, const QString &targetPath ); \n
       
   110  2. Case Descrition:  \n
       
   111  3. Input Parameters:  \n &nbsp;&nbsp;
       
   112  <1> sourceList = QString(XX), targetPath = QString(XX)\n
       
   113  4. Expected result: \n &nbsp;&nbsp;
       
   114  <1> the file is copied to the target path. \n
       
   115  */
       
   116 void TestFmOperationService::testAsyncCopySingleFile()
       
   117 {
       
   118     QStringList sourceData;
       
   119     sourceData.append(mDataPath + "dataforcopy.txt");
       
   120     // make sure the copy file is not available in the target path.
       
   121     QFile checkFile(mPath + "dataforcopy.txt");
       
   122     if(checkFile.exists()){
       
   123         checkFile.remove();
       
   124     }   
       
   125     //test the asyncCopy() function.
       
   126     int retInfo = mOperationService->asyncCopy(sourceData, mPath);
       
   127     
       
   128     mTestEventLoop.exec();
       
   129     QVERIFY( checkFile.exists() );
       
   130 }
       
   131 
       
   132 /*!
       
   133  Test Case Description:\n 
       
   134  1. Fucntion Name:  \n &nbsp;&nbsp;
       
   135     int asyncCopy( const QStringList &sourceList, const QString &targetPath ); \n
       
   136  2. Case Descrition:  \n
       
   137  3. Input Parameters:  \n &nbsp;&nbsp;
       
   138  <1> sourceList = QString(XX), targetPath = QString(XX)\n
       
   139  4. Expected result: \n &nbsp;&nbsp;
       
   140  <1> All the files are copied to the target path. \n
       
   141  */
       
   142 void TestFmOperationService::testAsyncCopyMultiFiles()
       
   143 {
       
   144     QStringList sourceDataMultiCopy;
       
   145     sourceDataMultiCopy.append(mDataMultiCopyPath  + "copydata1.txt");
       
   146     sourceDataMultiCopy.append(mDataMultiCopyPath  + "copydata2.txt");
       
   147     sourceDataMultiCopy.append(mDataMultiCopyPath  + "copydata3.txt");
       
   148     // make sure the copy file is not available in the target path.
       
   149     QFile checkFile1(mPath + "copydata1.txt");
       
   150     QFile checkFile2(mPath + "copydata2.txt");
       
   151     QFile checkFile3(mPath + "copydata3.txt");
       
   152     if(checkFile1.exists()){
       
   153         checkFile1.remove();
       
   154     }   
       
   155     if(checkFile2.exists()){
       
   156         checkFile2.remove();
       
   157     } 
       
   158     if(checkFile3.exists()){
       
   159         checkFile3.remove();
       
   160     } 
       
   161     //test the asyncCopy() function.
       
   162     int retInfo = mOperationService->asyncCopy(sourceDataMultiCopy, mPath);
       
   163     
       
   164     mTestEventLoop.exec();
       
   165     QVERIFY( checkFile1.exists() );
       
   166     QVERIFY( checkFile2.exists() );
       
   167     QVERIFY( checkFile3.exists() );
       
   168 }
       
   169 
       
   170 /*!
       
   171  Test Case Description:\n 
       
   172  1. Fucntion Name:  \n &nbsp;&nbsp;
       
   173     int asyncCopy( const QStringList &sourceList, const QString &targetPath ); \n
       
   174  2. Case Descrition:  \n
       
   175  3. Input Parameters:  \n &nbsp;&nbsp;
       
   176  <1> sourceList = QString(XX), targetPath = QString(XX)\n
       
   177  4. Expected result: \n &nbsp;&nbsp;
       
   178  <1> the folder included its content is copied to the target path. \n
       
   179  */
       
   180 void TestFmOperationService::testAsyncCopyFolder()
       
   181 {
       
   182     QStringList sourceDataFolder;
       
   183     sourceDataFolder.append( mDataPath + "multifilesforcopy" );
       
   184     // make sure the copy file is not available in the target path.
       
   185     QStringList folderNeedRemove;
       
   186     folderNeedRemove.append(mPath + "multifilesforcopy");
       
   187     QDir checkDir(mPath + "multifilesforcopy");
       
   188     if(checkDir.exists()){
       
   189         mOperationService->asyncRemove(folderNeedRemove);
       
   190         mTestEventLoop.exec();
       
   191     }   
       
   192     //test the asyncCopy() function.
       
   193     int retInfo = mOperationService->asyncCopy(sourceDataFolder, mPath);
       
   194     
       
   195     mTestEventLoop.exec();
       
   196     QVERIFY( checkDir.exists() );
       
   197 }
       
   198 
       
   199 /*!
       
   200  Test Case Description:\n 
       
   201  1. Fucntion Name:  \n &nbsp;&nbsp;
       
   202     int asyncCopy( const QStringList &sourceList, const QString &targetPath ); \n
       
   203  2. Case Descrition:  \n
       
   204  3. Input Parameters:  \n &nbsp;&nbsp;
       
   205  <1> sourceList = QString(), targetPath = QString(XX)\n
       
   206  4. Expected result: \n &nbsp;&nbsp;
       
   207  <1> no crash \n
       
   208  */
       
   209 void TestFmOperationService::testAsyncCopyEmpty()
       
   210 {
       
   211     QStringList sourceDataEmpty;
       
   212     sourceDataEmpty.append(QString());
       
   213     int retInfo = mOperationService->asyncCopy(sourceDataEmpty, mPath);
       
   214     
       
   215     mTestEventLoop.exec();
       
   216 }
       
   217 
       
   218 /*!
       
   219  Test Case Description:\n 
       
   220  1. Fucntion Name:  \n &nbsp;&nbsp;
       
   221     int asyncMove( const QStringList &sourceList, const QString &targetPath ); \n
       
   222  2. Case Descrition:  \n
       
   223  3. Input Parameters:  \n &nbsp;&nbsp;
       
   224  <1> sourceList = QString(XX), targetPath = QString(XX)\n
       
   225  4. Expected result: \n &nbsp;&nbsp;
       
   226  <1> the file is moved to the target path. \n
       
   227  */
       
   228 void TestFmOperationService::testAsyncMoveSingleFile()
       
   229 {
       
   230     QStringList sourceDataSingleMove;
       
   231     sourceDataSingleMove.append(mDataPath + "dataformove.txt");
       
   232     // make sure the copy file is not available in the target path.
       
   233     QFile checkFile(mPath + "dataformove.txt");
       
   234     if(checkFile.exists()){
       
   235         checkFile.remove();
       
   236     }   
       
   237     //test the asyncCopy() function.
       
   238     int retInfo = mOperationService->asyncMove(sourceDataSingleMove, mPath);
       
   239     
       
   240     mTestEventLoop.exec();
       
   241     QVERIFY( checkFile.exists() );
       
   242     QFile checkSourceData(mDataPath + "dataformove.txt");
       
   243     QVERIFY( !checkSourceData.exists() );
       
   244 }
       
   245 
       
   246 /*!
       
   247  Test Case Description:\n 
       
   248  1. Fucntion Name:  \n &nbsp;&nbsp;
       
   249     int asyncMove( const QStringList &sourceList, const QString &targetPath ); \n
       
   250  2. Case Descrition:  \n
       
   251  3. Input Parameters:  \n &nbsp;&nbsp;
       
   252  <1> sourceList = QString(XX), targetPath = QString(XX)\n
       
   253  4. Expected result: \n &nbsp;&nbsp;
       
   254  <1> All the filea are moved to the target path. \n
       
   255  */
       
   256 void TestFmOperationService::testAsyncMoveMultiFiles()
       
   257 {
       
   258     QStringList sourceDataMultiMove;
       
   259     sourceDataMultiMove.append(mDataMultiMovePath + "movedata1.txt");
       
   260     sourceDataMultiMove.append(mDataMultiMovePath + "movedata2.txt");
       
   261     // make sure the copy file is not available in the target path.
       
   262     QFile checkFile1(mPath + "movedata1.txt");
       
   263     QFile checkFile2(mPath + "movedata2.txt");
       
   264     if(checkFile1.exists()){
       
   265         checkFile1.remove();
       
   266     }   
       
   267     if(checkFile2.exists()){
       
   268         checkFile2.remove();
       
   269     }   
       
   270     //test the asyncCopy() function.
       
   271     int retInfo = mOperationService->asyncMove(sourceDataMultiMove, mPath);    
       
   272     mTestEventLoop.exec();
       
   273     //verify the files are copied to the target path.
       
   274     QVERIFY( checkFile1.exists() );
       
   275     QVERIFY( checkFile2.exists() );
       
   276     //verify the files are not in the orignal path yet.
       
   277     QFile checkSourceData1(mDataMultiMovePath + "movedata1.txt");
       
   278     QFile checkSourceData2(mDataMultiMovePath + "movedata2.txt");
       
   279     QVERIFY( !checkSourceData1.exists() );
       
   280     QVERIFY( !checkSourceData2.exists() );
       
   281 }
       
   282 
       
   283 /*!
       
   284  Test Case Description:\n 
       
   285  1. Fucntion Name:  \n &nbsp;&nbsp;
       
   286     int asyncMove( const QStringList &sourceList, const QString &targetPath ); \n
       
   287  2. Case Descrition:  \n
       
   288  3. Input Parameters:  \n &nbsp;&nbsp;
       
   289  <1> sourceList = QString(XX), targetPath = QString(XX)\n
       
   290  4. Expected result: \n &nbsp;&nbsp;
       
   291  <1> The folder is moved to the target path. \n
       
   292  */
       
   293 void TestFmOperationService::testAsyncMoveFolder()
       
   294 {
       
   295     QStringList sourceDataFolder;
       
   296     sourceDataFolder.append( mDataPath + "multifilesforMove" );
       
   297     // make sure the copy file is not available in the target path.
       
   298     QStringList folderNeedRemove;
       
   299     folderNeedRemove.append(mPath + "multifilesforMove");
       
   300     QDir checkDir(mPath + "multifilesforMove");
       
   301     if(checkDir.exists()){
       
   302         mOperationService->asyncRemove(folderNeedRemove);
       
   303         mTestEventLoop.exec();
       
   304     }   
       
   305     //test the asyncMove() function.
       
   306     int retInfo = mOperationService->asyncMove(sourceDataFolder, mPath);    
       
   307     mTestEventLoop.exec();
       
   308     
       
   309     QVERIFY( checkDir.exists() );
       
   310 }
       
   311 
       
   312 /*!
       
   313  Test Case Description:\n 
       
   314  1. Fucntion Name:  \n &nbsp;&nbsp;
       
   315     int asyncMove( const QStringList &sourceList, const QString &targetPath ); \n
       
   316  2. Case Descrition:  \n
       
   317  3. Input Parameters:  \n &nbsp;&nbsp;
       
   318  <1> sourceList = QString(), targetPath = QString(XX)\n
       
   319  4. Expected result: \n &nbsp;&nbsp;
       
   320  <1> no crash \n
       
   321  */
       
   322 void TestFmOperationService::testAsyncMoveEmpty()
       
   323 {
       
   324     QStringList sourceDataEmpty;
       
   325     sourceDataEmpty.append(QString());
       
   326     int retInfo = mOperationService->asyncMove(sourceDataEmpty, mPath);
       
   327     
       
   328     mTestEventLoop.exec();
       
   329 }
       
   330 
       
   331 /*!
       
   332  Test Case Description:\n 
       
   333  1. Fucntion Name:  \n &nbsp;&nbsp;
       
   334     int asyncRemove( const QStringList &pathList ); \n
       
   335  2. Case Descrition:  \n
       
   336  3. Input Parameters:  \n &nbsp;&nbsp;
       
   337     <1> pathList = QStringList(XX);\n 
       
   338  4. Expected result: \n &nbsp;&nbsp;
       
   339     <1> The file is removed. \n 
       
   340  */
       
   341 void TestFmOperationService::testAsyncRemoveSingleFile()
       
   342 {
       
   343     QStringList sourceData;
       
   344     sourceData.append(mPath + "dataforcopy.txt");
       
   345     // make sure the copy file is available in the target path.
       
   346     QFile checkFile(mPath + "dataforcopy.txt");
       
   347     if(checkFile.exists()){
       
   348     //test the asyncRemove() function.
       
   349         int retInfo = mOperationService->asyncRemove(sourceData);    
       
   350         mTestEventLoop.exec();
       
   351     }   
       
   352     QVERIFY( !checkFile.exists() );
       
   353 }
       
   354 
       
   355 /*!
       
   356  Test Case Description:\n 
       
   357  1. Fucntion Name:  \n &nbsp;&nbsp;
       
   358     int asyncRemove( const QStringList &pathList ); \n
       
   359  2. Case Descrition:  \n
       
   360  3. Input Parameters:  \n &nbsp;&nbsp;
       
   361     <1> pathList = QStringList(XX);\n 
       
   362  4. Expected result: \n &nbsp;&nbsp;
       
   363     <1> All the files are removed. \n 
       
   364  */
       
   365 void TestFmOperationService::testAsyncRemoveMultiFiles()
       
   366 {
       
   367     QStringList multiRemoveData;
       
   368     multiRemoveData.append(mPath + "copydata1.txt");
       
   369     multiRemoveData.append(mPath + "copydata2.txt");
       
   370     multiRemoveData.append(mPath + "movedata1.txt");
       
   371     // make sure the copy file is available in the target path.
       
   372     QFile checkFile1(mPath + "copydata1.txt");
       
   373     QFile checkFile2(mPath + "copydata2.txt");
       
   374     QFile checkFile3(mPath + "movedata1.txt");
       
   375     if(checkFile1.exists() && checkFile2.exists() && checkFile3.exists()){
       
   376     //test the asyncRemove() function.
       
   377         int retInfo = mOperationService->asyncRemove(multiRemoveData);    
       
   378         mTestEventLoop.exec();
       
   379     }   
       
   380     QVERIFY( !checkFile1.exists() );
       
   381     QVERIFY( !checkFile2.exists() );
       
   382     QVERIFY( !checkFile3.exists() );
       
   383 }
       
   384 
       
   385 /*!
       
   386  Test Case Description:\n 
       
   387  1. Fucntion Name:  \n &nbsp;&nbsp;
       
   388     int asyncRemove( const QStringList &pathList ); \n
       
   389  2. Case Descrition:  \n
       
   390  3. Input Parameters:  \n &nbsp;&nbsp;
       
   391     <1> pathList = QStringList(XX);\n 
       
   392  4. Expected result: \n &nbsp;&nbsp;
       
   393     <1> The specified folder is removed. \n 
       
   394  */
       
   395 void TestFmOperationService::testAsyncRemoveFolder()
       
   396 {
       
   397     QStringList sourceDataFolder;
       
   398     sourceDataFolder.append( mDataPath + "multifilesforMove" );
       
   399     // make sure the copy file is not available in the target path.
       
   400     QStringList folderRemoveData;
       
   401     folderRemoveData.append(mPath + "multifilesforMove");
       
   402     QDir checkDir(mPath + "multifilesforMove");
       
   403     
       
   404     if(checkDir.exists()){
       
   405         mOperationService->asyncRemove(folderRemoveData);
       
   406         mTestEventLoop.exec();
       
   407     }
       
   408     //verify the folder is removed.
       
   409     QVERIFY( !checkDir.exists() );
       
   410 }
       
   411 
       
   412 void TestFmOperationService::testAsyncBackup()
       
   413 {
       
   414     // not implemented yet.
       
   415 }
       
   416 
       
   417 void TestFmOperationService::onNotifyFinish(FmOperationBase* operationBase)
       
   418 {
       
   419     mTestEventLoop.exit();
       
   420 }
       
   421 void TestFmOperationService::onNotifyError(FmOperationBase* operationBase,
       
   422         int error, QString errString)
       
   423 {
       
   424     mTestEventLoop.exit();
       
   425 }
       
   426 void TestFmOperationService::onNotifyCanceled(FmOperationBase* operationBase)
       
   427 {
       
   428     mTestEventLoop.exit();
       
   429 }
       
   430 
       
   431 QTEST_MAIN(TestFmOperationService)