homescreenapp/stateplugins/hsapplibrarystateplugin/tsrc/t_collectionsstate/src/t_collectionsstate.cpp
changeset 97 66b5fe3c07fd
parent 90 3ac3aaebaee5
child 98 e6f74eb7f69f
equal deleted inserted replaced
95:32e56106abf2 97:66b5fe3c07fd
    33 #include "hsmenumodewrapper.h"
    33 #include "hsmenumodewrapper.h"
    34 #include "hsmenuevent.h"
    34 #include "hsmenuevent.h"
    35 #include "hsmenueventtransition.h"
    35 #include "hsmenueventtransition.h"
    36 #include "hscollectionstate.h"
    36 #include "hscollectionstate.h"
    37 #include "hsmainwindow.h"
    37 #include "hsmainwindow.h"
       
    38 #include "hsscene.h"
    38 
    39 
    39 #include "t_hsaddtohomescreenmockstate.h"
    40 #include "t_hsaddtohomescreenmockstate.h"
    40 #include "t_hsmockmodel.h"
    41 #include "t_hsmockmodel.h"
    41 #include "t_collectionsstate.h"
    42 #include "t_collectionsstate.h"
    42 
    43 
    43 Q_DECLARE_METATYPE(Hs::HsSortAttribute)
    44 Q_DECLARE_METATYPE(Hs::HsSortAttribute)
    44 
    45 
    45 
    46 
       
    47 // ---------------------------------------------------------------------------
       
    48 //
       
    49 // ---------------------------------------------------------------------------
       
    50 //
    46 class HsMainWindowMock : public HsMainWindow
    51 class HsMainWindowMock : public HsMainWindow
    47 {
    52 {
    48     virtual void setCurrentView(HbView *view);
    53     virtual void setCurrentView(HbView *view);
    49 
    54 
    50 };
    55 };
    51 
    56 
       
    57 // ---------------------------------------------------------------------------
       
    58 //
       
    59 // ---------------------------------------------------------------------------
       
    60 //
    52 void HsMainWindowMock::setCurrentView(HbView *view)
    61 void HsMainWindowMock::setCurrentView(HbView *view)
    53 {
    62 {
    54     Q_UNUSED(view);
    63     Q_UNUSED(view);
    55     // do nothing
    64     // do nothing
    56 }
    65 }
    57 
    66 
       
    67 // ---------------------------------------------------------------------------
       
    68 //
       
    69 // ---------------------------------------------------------------------------
       
    70 //
    58 void MenuStatesTest::init()
    71 void MenuStatesTest::init()
    59 {
    72 {
    60 }
    73 }
    61 
    74 
       
    75 // ---------------------------------------------------------------------------
       
    76 //
       
    77 // ---------------------------------------------------------------------------
       
    78 //
    62 void MenuStatesTest::cleanup()
    79 void MenuStatesTest::cleanup()
    63 {
    80 {
    64     qApp->processEvents();
    81     qApp->processEvents();
    65 }
    82 }
    66 
    83 
    67 
    84 // ---------------------------------------------------------------------------
    68 // ---------------------------------------------------------------------------
    85 //
    69 // ---------------------------------------------------------------------------
    86 // ---------------------------------------------------------------------------
    70 //
    87 //
    71 void MenuStatesTest::construction()
    88 void MenuStatesTest::construction()
    72 {
    89 {
    73 #ifdef Q_OS_SYMBIAN
    90 #ifdef Q_OS_SYMBIAN
   100 #endif//UT_MEMORY_CHECK
   117 #endif//UT_MEMORY_CHECK
   101 #endif//Q_OS_SYMBIAN
   118 #endif//Q_OS_SYMBIAN
   102 }
   119 }
   103 
   120 
   104 // ---------------------------------------------------------------------------
   121 // ---------------------------------------------------------------------------
       
   122 //
   105 // ---------------------------------------------------------------------------
   123 // ---------------------------------------------------------------------------
   106 //
   124 //
   107 void MenuStatesTest::listItemActivated()
   125 void MenuStatesTest::listItemActivated()
   108 {
   126 {
   109 #ifdef Q_OS_SYMBIAN
   127 #ifdef Q_OS_SYMBIAN
   163 #endif//UT_MEMORY_CHECK
   181 #endif//UT_MEMORY_CHECK
   164 #endif//Q_OS_SYMBIAN
   182 #endif//Q_OS_SYMBIAN
   165 }
   183 }
   166 
   184 
   167 // ---------------------------------------------------------------------------
   185 // ---------------------------------------------------------------------------
       
   186 //
   168 // ---------------------------------------------------------------------------
   187 // ---------------------------------------------------------------------------
   169 //
   188 //
   170 void MenuStatesTest::listItemLongPressed()
   189 void MenuStatesTest::listItemLongPressed()
   171 {
   190 {
   172 #ifdef Q_OS_SYMBIAN
   191 #ifdef Q_OS_SYMBIAN
   174 #ifdef UT_MEMORY_CHECK
   193 #ifdef UT_MEMORY_CHECK
   175     __UHEAP_MARK;
   194     __UHEAP_MARK;
   176 #endif//UT_MEMORY_CHECK
   195 #endif//UT_MEMORY_CHECK
   177 #endif//Q_OS_SYMBIAN
   196 #endif//Q_OS_SYMBIAN
   178     {
   197     {
   179         QScopedPointer<HbMainWindow> wind(new HbMainWindow);
   198         HsMenuViewBuilder builder;
   180 
   199         HsMenuModeWrapper menuMode;
   181         HsMenuViewBuilder builder;
   200         HsMainWindowMock mainWindow;
   182         HsMenuModeWrapper menuMode;
       
   183         HsMainWindow mainWindow;
       
   184 
   201 
   185 
   202 
   186         QScopedPointer<QStateMachine> machine(new QStateMachine(0));
   203         QScopedPointer<QStateMachine> machine(new QStateMachine(0));
   187         QState *parent(new QState(machine.data()));
   204         QState *parent(new QState(machine.data()));
   188 
   205 
   190                                      QDateTime::currentDateTime().
   207                                      QDateTime::currentDateTime().
   191                                      toString("ddmmyyyy_hh_mm_ss_zzz"));
   208                                      toString("ddmmyyyy_hh_mm_ss_zzz"));
   192         const int collectionId = HsMenuService::createCollection(collectionName);
   209         const int collectionId = HsMenuService::createCollection(collectionName);
   193 
   210 
   194         HsMenuItemModel *appsModel = HsMenuService::getAllApplicationsModel();
   211         HsMenuItemModel *appsModel = HsMenuService::getAllApplicationsModel();
       
   212         QVERIFY(appsModel!=NULL);
   195         QList<int> list;
   213         QList<int> list;
   196         list << appsModel->data(appsModel->index(0),CaItemModel::IdRole).toInt();
   214         list << appsModel->data(appsModel->index(0),CaItemModel::IdRole).toInt();
   197         HsMenuService::addApplicationsToCollection(list,collectionId);
   215         HsMenuService::addApplicationsToCollection(list,collectionId);
   198         delete appsModel;
   216         delete appsModel;
   199 
   217 
   200         HsCollectionState *collectionState = new HsCollectionState(builder, menuMode,
   218         HsCollectionState *collectionState = new HsCollectionState(builder, menuMode,
   201                 mainWindow, parent);
   219                 mainWindow, parent);
       
   220         QVERIFY(collectionState!=NULL);
   202         collectionState->mCollectionId = collectionId;
   221         collectionState->mCollectionId = collectionId;
   203         collectionState->mCollectionType = "collection";
   222         collectionState->mCollectionType = "collection";
   204 
   223 
   205         collectionState->stateEntered();
   224         collectionState->stateEntered();
   206 
   225 
   242             for (int i=0; i<list.count(); i++) {
   261             for (int i=0; i<list.count(); i++) {
   243                 HsMenuService::removeApplicationFromCollection(list[i],collectionId);
   262                 HsMenuService::removeApplicationFromCollection(list[i],collectionId);
   244             }
   263             }
   245         }
   264         }
   246         HsMenuService::removeCollection(collectionId);
   265         HsMenuService::removeCollection(collectionId);
   247         wind->removeView(builder.currentView());
   266     }
   248 
   267 #ifdef Q_OS_SYMBIAN
   249     }
   268 #ifdef UT_MEMORY_CHECK
   250 #ifdef Q_OS_SYMBIAN
   269     __UHEAP_MARKEND;
   251 #ifdef UT_MEMORY_CHECK
   270 #endif//UT_MEMORY_CHECK
   252     __UHEAP_MARKEND;
   271 #endif//Q_OS_SYMBIAN
   253 #endif//UT_MEMORY_CHECK
   272 }
   254 #endif//Q_OS_SYMBIAN
   273 
   255 }
   274 // ---------------------------------------------------------------------------
   256 
   275 //
   257 
       
   258 // ---------------------------------------------------------------------------
       
   259 // ---------------------------------------------------------------------------
   276 // ---------------------------------------------------------------------------
   260 //
   277 //
   261 void MenuStatesTest::contextMenuAction()
   278 void MenuStatesTest::contextMenuAction()
   262 {
   279 {
   263 #ifdef Q_OS_SYMBIAN
   280 #ifdef Q_OS_SYMBIAN
   265 #ifdef UT_MEMORY_CHECK
   282 #ifdef UT_MEMORY_CHECK
   266     __UHEAP_MARK;
   283     __UHEAP_MARK;
   267 #endif//UT_MEMORY_CHECK
   284 #endif//UT_MEMORY_CHECK
   268 #endif//Q_OS_SYMBIAN
   285 #endif//Q_OS_SYMBIAN
   269     {
   286     {
       
   287         //QScopedPointer<HbMainWindow> window(new HbMainWindow);
       
   288         //HsScene::setInstance( new HsScene(window.data()) );
       
   289 
   270         HsMenuViewBuilder builder;
   290         HsMenuViewBuilder builder;
   271         HsMenuModeWrapper menuMode;
   291         HsMenuModeWrapper menuMode;
   272         HsMainWindowMock mainWindow;
   292         HsMainWindowMock mainWindow;
   273 
   293 
   274         QScopedPointer<QStateMachine> machine(new QStateMachine(0));
   294         QScopedPointer<QStateMachine> machine(new QStateMachine(0));
   334     __UHEAP_MARKEND;
   354     __UHEAP_MARKEND;
   335 #endif//UT_MEMORY_CHECK
   355 #endif//UT_MEMORY_CHECK
   336 #endif//Q_OS_SYMBIAN
   356 #endif//Q_OS_SYMBIAN
   337 }
   357 }
   338 
   358 
   339 
   359 // ---------------------------------------------------------------------------
   340 
   360 //
   341 // ---------------------------------------------------------------------------
       
   342 // ---------------------------------------------------------------------------
   361 // ---------------------------------------------------------------------------
   343 //
   362 //
   344 void MenuStatesTest::contextMenuConstruct()
   363 void MenuStatesTest::contextMenuConstruct()
   345 {
   364 {
   346 #ifdef Q_OS_SYMBIAN
   365 #ifdef Q_OS_SYMBIAN
   384     __UHEAP_MARKEND;
   403     __UHEAP_MARKEND;
   385 #endif//UT_MEMORY_CHECK
   404 #endif//UT_MEMORY_CHECK
   386 #endif//Q_OS_SYMBIAN
   405 #endif//Q_OS_SYMBIAN
   387 }
   406 }
   388 
   407 
   389 
   408 // ---------------------------------------------------------------------------
   390 // ---------------------------------------------------------------------------
   409 //
   391 // ---------------------------------------------------------------------------
   410 // ---------------------------------------------------------------------------
   392 //
   411 //
   393 void MenuStatesTest::contextMenuConstructNonEmptyCollection()
   412 void MenuStatesTest::contextMenuConstructNonEmptyCollection()
   394 {
   413 {
   395 #ifdef Q_OS_SYMBIAN
   414 #ifdef Q_OS_SYMBIAN
   435     __UHEAP_MARKEND;
   454     __UHEAP_MARKEND;
   436 #endif//UT_MEMORY_CHECK
   455 #endif//UT_MEMORY_CHECK
   437 #endif//Q_OS_SYMBIAN
   456 #endif//Q_OS_SYMBIAN
   438 }
   457 }
   439 
   458 
   440 
   459 // ---------------------------------------------------------------------------
       
   460 //
       
   461 // ---------------------------------------------------------------------------
       
   462 //
   441 void MenuStatesTest::addAppsAction()
   463 void MenuStatesTest::addAppsAction()
   442 {
   464 {
   443 #ifdef Q_OS_SYMBIAN
   465 #ifdef Q_OS_SYMBIAN
   444     User::ResetInactivityTime();//it should help for Viewserver11 panic
   466     User::ResetInactivityTime();//it should help for Viewserver11 panic
   445 #ifdef UT_MEMORY_CHECK
   467 #ifdef UT_MEMORY_CHECK
   496     __UHEAP_MARKEND;
   518     __UHEAP_MARKEND;
   497 #endif//UT_MEMORY_CHECK
   519 #endif//UT_MEMORY_CHECK
   498 #endif//Q_OS_SYMBIAN
   520 #endif//Q_OS_SYMBIAN
   499 }
   521 }
   500 
   522 
       
   523 // ---------------------------------------------------------------------------
       
   524 //
       
   525 // ---------------------------------------------------------------------------
       
   526 //
   501 void MenuStatesTest::renameAction()
   527 void MenuStatesTest::renameAction()
   502 {
   528 {
   503 #ifdef Q_OS_SYMBIAN
   529 #ifdef Q_OS_SYMBIAN
   504     User::ResetInactivityTime();//it should help for Viewserver11 panic
   530     User::ResetInactivityTime();//it should help for Viewserver11 panic
   505 #ifdef UT_MEMORY_CHECK
   531 #ifdef UT_MEMORY_CHECK
   555     __UHEAP_MARKEND;
   581     __UHEAP_MARKEND;
   556 #endif//UT_MEMORY_CHECK
   582 #endif//UT_MEMORY_CHECK
   557 #endif//Q_OS_SYMBIAN
   583 #endif//Q_OS_SYMBIAN
   558 }
   584 }
   559 
   585 
   560 
   586 // ---------------------------------------------------------------------------
       
   587 //
       
   588 // ---------------------------------------------------------------------------
       
   589 //
   561 void MenuStatesTest::deleteAppsAction()
   590 void MenuStatesTest::deleteAppsAction()
   562 {
   591 {
   563 #ifdef Q_OS_SYMBIAN
   592 #ifdef Q_OS_SYMBIAN
   564     User::ResetInactivityTime();//it should help for Viewserver11 panic
   593     User::ResetInactivityTime();//it should help for Viewserver11 panic
   565 #ifdef UT_MEMORY_CHECK
   594 #ifdef UT_MEMORY_CHECK
   614     __UHEAP_MARKEND;
   643     __UHEAP_MARKEND;
   615 #endif//UT_MEMORY_CHECK
   644 #endif//UT_MEMORY_CHECK
   616 #endif//Q_OS_SYMBIAN
   645 #endif//Q_OS_SYMBIAN
   617 }
   646 }
   618 
   647 
       
   648 // ---------------------------------------------------------------------------
       
   649 //
       
   650 // ---------------------------------------------------------------------------
       
   651 //
   619 void MenuStatesTest::updateLabel()
   652 void MenuStatesTest::updateLabel()
   620 {
   653 {
   621 #ifdef Q_OS_SYMBIAN
   654 #ifdef Q_OS_SYMBIAN
   622     User::ResetInactivityTime();//it should help for Viewserver11 panic
   655     User::ResetInactivityTime();//it should help for Viewserver11 panic
   623 #ifdef UT_MEMORY_CHECK
   656 #ifdef UT_MEMORY_CHECK
   648         collectionState->mModel =
   681         collectionState->mModel =
   649             static_cast<HsMenuItemModel *>(
   682             static_cast<HsMenuItemModel *>(
   650                 HsMenuService::getCollectionModel(collectionState->mCollectionId,
   683                 HsMenuService::getCollectionModel(collectionState->mCollectionId,
   651                         collectionState->mSortAttribute));
   684                         collectionState->mSortAttribute));
   652 
   685 
   653         const QString label1 = collectionState->mModel->root().data(
   686         const QString newName(collectionName +
   654                                    Qt::DisplayRole).toString();
       
   655 
       
   656         const QString newName(label1 +
       
   657                               QDateTime::currentDateTime().
   687                               QDateTime::currentDateTime().
   658                               toString("ddmmyyyy_hh_mm_ss_zzz"));
   688                               toString("ddmmyyyy_hh_mm_ss_zzz"));
   659 
   689 
   660         const bool renamed = HsMenuService::renameCollection(
   690         const bool renamed = HsMenuService::renameCollection(
   661                                  collectionState->mCollectionId, newName);
   691                                  collectionState->mCollectionId, newName);
   664 
   694 
   665         QTest::qWait(3000);
   695         QTest::qWait(3000);
   666 
   696 
   667         collectionState->updateLabel();
   697         collectionState->updateLabel();
   668 
   698 
   669         const QString label2 = builder.currentViewLabel()->heading();
   699         const QString label = builder.currentViewLabel()->heading();
   670 
   700 
   671         QCOMPARE(label2, newName);
   701         //now label is different than collection name but should contain this name
   672 
   702         QVERIFY(label.contains(newName));
   673         QVERIFY(HsMenuService::renameCollection(collectionState->mCollectionId, label1));
   703 
   674 
   704         QVERIFY(HsMenuService::renameCollection(collectionState->mCollectionId, collectionName));
   675         // cleanup
   705 
   676         HsMenuService::removeCollection(collectionId);
   706         // cleanup
   677     }
   707         HsMenuService::removeCollection(collectionId);
   678 #ifdef UT_MEMORY_CHECK
   708     }
   679     __UHEAP_MARKEND;
   709 #ifdef UT_MEMORY_CHECK
   680 #endif//UT_MEMORY_CHECK
   710     __UHEAP_MARKEND;
   681 }
   711 #endif//UT_MEMORY_CHECK
   682 
   712 }
   683 // ---------------------------------------------------------------------------
   713 
       
   714 // ---------------------------------------------------------------------------
       
   715 //
   684 // ---------------------------------------------------------------------------
   716 // ---------------------------------------------------------------------------
   685 //
   717 //
   686 void MenuStatesTest::addElementToHomeScreen()
   718 void MenuStatesTest::addElementToHomeScreen()
   687 {
   719 {
   688 #ifdef Q_OS_SYMBIAN
   720 #ifdef Q_OS_SYMBIAN
   758 #endif//UT_MEMORY_CHECK
   790 #endif//UT_MEMORY_CHECK
   759 #endif//Q_OS_SYMBIAN
   791 #endif//Q_OS_SYMBIAN
   760 }
   792 }
   761 
   793 
   762 // ---------------------------------------------------------------------------
   794 // ---------------------------------------------------------------------------
       
   795 //
   763 // ---------------------------------------------------------------------------
   796 // ---------------------------------------------------------------------------
   764 //
   797 //
   765 void MenuStatesTest::addCollectionShortcutToHomeScreenAction()
   798 void MenuStatesTest::addCollectionShortcutToHomeScreenAction()
   766 {
   799 {
   767 #ifdef Q_OS_SYMBIAN
   800 #ifdef Q_OS_SYMBIAN
   820 #endif//UT_MEMORY_CHECK
   853 #endif//UT_MEMORY_CHECK
   821 #endif//Q_OS_SYMBIAN
   854 #endif//Q_OS_SYMBIAN
   822 }
   855 }
   823 
   856 
   824 // ---------------------------------------------------------------------------
   857 // ---------------------------------------------------------------------------
       
   858 //
   825 // ---------------------------------------------------------------------------
   859 // ---------------------------------------------------------------------------
   826 //
   860 //
   827 void MenuStatesTest::latestOnTopMenuAction()
   861 void MenuStatesTest::latestOnTopMenuAction()
   828 {
   862 {
   829 #ifdef Q_OS_SYMBIAN
   863 #ifdef Q_OS_SYMBIAN
   876 #endif//UT_MEMORY_CHECK
   910 #endif//UT_MEMORY_CHECK
   877 #endif//Q_OS_SYMBIAN
   911 #endif//Q_OS_SYMBIAN
   878 }
   912 }
   879 
   913 
   880 // ---------------------------------------------------------------------------
   914 // ---------------------------------------------------------------------------
       
   915 //
   881 // ---------------------------------------------------------------------------
   916 // ---------------------------------------------------------------------------
   882 //
   917 //
   883 void MenuStatesTest::oldestOnTopMenuAction()
   918 void MenuStatesTest::oldestOnTopMenuAction()
   884 {
   919 {
   885 #ifdef Q_OS_SYMBIAN
   920 #ifdef Q_OS_SYMBIAN
   935 #endif//UT_MEMORY_CHECK
   970 #endif//UT_MEMORY_CHECK
   936 #endif//Q_OS_SYMBIAN
   971 #endif//Q_OS_SYMBIAN
   937 }
   972 }
   938 
   973 
   939 // ---------------------------------------------------------------------------
   974 // ---------------------------------------------------------------------------
       
   975 //
   940 // ---------------------------------------------------------------------------
   976 // ---------------------------------------------------------------------------
   941 //
   977 //
   942 void MenuStatesTest::createArrangeCollection()
   978 void MenuStatesTest::createArrangeCollection()
   943 {
   979 {
   944 #ifdef Q_OS_SYMBIAN
   980 #ifdef Q_OS_SYMBIAN
   990 #endif//UT_MEMORY_CHECK
  1026 #endif//UT_MEMORY_CHECK
   991 #endif//Q_OS_SYMBIAN
  1027 #endif//Q_OS_SYMBIAN
   992 }
  1028 }
   993 
  1029 
   994 // ---------------------------------------------------------------------------
  1030 // ---------------------------------------------------------------------------
       
  1031 //
   995 // ---------------------------------------------------------------------------
  1032 // ---------------------------------------------------------------------------
   996 //
  1033 //
   997 #ifdef Q_OS_SYMBIAN
  1034 #ifdef Q_OS_SYMBIAN
   998 void MenuStatesTest::openTaskSwitcher()
  1035 void MenuStatesTest::openTaskSwitcher()
   999 {
  1036 {
  1019 #endif//UT_MEMORY_CHECK
  1056 #endif//UT_MEMORY_CHECK
  1020 #endif//Q_OS_SYMBIAN
  1057 #endif//Q_OS_SYMBIAN
  1021 }
  1058 }
  1022 #endif//Q_OS_SYMBIAN
  1059 #endif//Q_OS_SYMBIAN
  1023 
  1060 
  1024 
  1061 // ---------------------------------------------------------------------------
  1025 // ---------------------------------------------------------------------------
  1062 //
  1026 // ---------------------------------------------------------------------------
  1063 // ---------------------------------------------------------------------------
  1027 //
  1064 //
  1028 void MenuStatesTest::disableSearchAction()
  1065 void MenuStatesTest::disableSearchAction()
  1029 {
  1066 {
  1030 #ifdef Q_OS_SYMBIAN
  1067 #ifdef Q_OS_SYMBIAN