searchui/stateproviders/searchstateprovider/tsrc/t_searchstateprovider/src/t_searchprogressivestate.cpp
changeset 2 208a4ba3894c
parent 0 ccd0fd43f247
child 3 6832643895f7
equal deleted inserted replaced
0:ccd0fd43f247 2:208a4ba3894c
    17 #include "t_searchstateprovider.h"
    17 #include "t_searchstateprovider.h"
    18 #include "searchprogressivestate.h"
    18 #include "searchprogressivestate.h"
    19 #include <qsignalspy.h>
    19 #include <qsignalspy.h>
    20 #include "indevicehandler.h"
    20 #include "indevicehandler.h"
    21 #include <qstandarditemmodel.h>
    21 #include <qstandarditemmodel.h>
       
    22 #include <fbs.h>
       
    23 #include <AknsUtils.h>
       
    24 #include <bitdev.h> 
       
    25 #include <bitstd.h>
       
    26 #include <qbitmap.h>
       
    27 #include <fbs.h>
       
    28 #include <AknInternalIconUtils.h>
       
    29 #include <AknIconUtils.h> 
       
    30 #include <apgcli.h>
       
    31 #include <hbsearchpanel.h>
       
    32 
    22 // ---------------------------------------------------------------------------
    33 // ---------------------------------------------------------------------------
    23 // ---------------------------------------------------------------------------
    34 // ---------------------------------------------------------------------------
    24 //
    35 //
    25 
    36 
    26 void SearchStateProviderTest::testProgressiveStateConstruction()
    37 void SearchStateProviderTest::testProgressiveStateConstruction()
    27     {
    38     {
    28   // HbMainWindow* wind = mainWindow();
    39     // HbMainWindow* wind = mainWindow();
    29 
    40 
    30     SearchProgressiveState* progressiveState = new SearchProgressiveState();
    41     SearchProgressiveState* progressiveState = new SearchProgressiveState();
    31 
    42 
    32     QVERIFY(progressiveState != NULL);
    43     QVERIFY(progressiveState != NULL);
    33     QVERIFY(progressiveState->mView);
    44     QVERIFY(progressiveState->mView);
    34     QVERIFY(progressiveState->mListView);
    45     QVERIFY(progressiveState->mListView);
    35     QVERIFY(progressiveState->mDocumentLoader);
    46     QVERIFY(progressiveState->mDocumentLoader);
    36     QVERIFY(progressiveState->mSearchPanel);
    47     QVERIFY(progressiveState->mSearchPanel);
    37     QVERIFY(progressiveState->mModel);
    48     QVERIFY(progressiveState->mModel);
    38     QVERIFY(progressiveState->mSearchHandler);
    49     //QVERIFY(progressiveState->mSearchHandler);
    39 
    50 
    40     delete progressiveState;
    51     delete progressiveState;
    41 
    52 
    42     
    53     //  delete wind;
    43   //  delete wind;
       
    44     }
    54     }
    45 // ---------------------------------------------------------------------------
    55 // ---------------------------------------------------------------------------
    46 // ---------------------------------------------------------------------------
    56 // ---------------------------------------------------------------------------
    47 //
    57 //
    48 
    58 
    49 void SearchStateProviderTest::testProgressiveStateOnEntryAndExitSignalled()
    59 void SearchStateProviderTest::testProgressiveStateOnEntryAndExitSignalled()
    50     {
    60     {
    51 //    HbMainWindow* wind = mainWindow();
    61     //    HbMainWindow* wind = mainWindow();
    52 
    62 
    53     SearchProgressiveState* progressiveState = new SearchProgressiveState();
    63     SearchProgressiveState* progressiveState = new SearchProgressiveState();
    54 
    64 
    55     QEvent *event = new QEvent(QEvent::None);
    65     QEvent *event = new QEvent(QEvent::None);
    56     progressiveState->onEntry(event);
    66     progressiveState->onEntry(event);
    57 
    67 
    58     progressiveState->onExit(event);
    68     progressiveState->onExit(event);
    59 
    69 
    60     delete progressiveState;
    70     delete progressiveState;
    61     
    71 
    62   //  delete wind;
    72     //  delete wind;
    63     }
    73     }
    64 // ---------------------------------------------------------------------------
    74 // ---------------------------------------------------------------------------
    65 // ---------------------------------------------------------------------------
    75 // ---------------------------------------------------------------------------
    66 //
    76 //
    67 
    77 
    68 void SearchStateProviderTest::testonSearchComplete()
       
    69     {
       
    70 //    HbMainWindow* wind = mainWindow();
       
    71     SearchProgressiveState* progressiveState = new SearchProgressiveState();
       
    72     QEvent *event = new QEvent(QEvent::None);
       
    73     progressiveState->onEntry(event);
       
    74     progressiveState->onSearchComplete(-1, 0);
       
    75     QCOMPARE(progressiveState->mResultcount,0);
       
    76     progressiveState->onSearchComplete(0, -1);
       
    77     QCOMPARE(progressiveState->mResultcount,0);
       
    78     progressiveState->onSearchComplete(0, 10);
       
    79     QCOMPARE(progressiveState->mResultcount,10);
       
    80     delete progressiveState;
       
    81   //  delete wind;
       
    82     }
       
    83 // ---------------------------------------------------------------------------
       
    84 // ---------------------------------------------------------------------------
       
    85 //
       
    86 
    78 
    87 void SearchStateProviderTest::testonAsyncSearchComplete()
    79 void SearchStateProviderTest::testonAsyncSearchComplete()
    88     {
    80     {
    89   //  HbMainWindow* wind = mainWindow();
    81     //  HbMainWindow* wind = mainWindow();
    90     SearchProgressiveState* progressiveState = new SearchProgressiveState();
    82     SearchProgressiveState* progressiveState = new SearchProgressiveState();
    91     QEvent *event = new QEvent(QEvent::None);
    83     QEvent *event = new QEvent(QEvent::None);
    92     progressiveState->onEntry(event);
    84     progressiveState->onEntry(event);
    93 
    85     progressiveState->mSearchHandler
       
    86             = progressiveState->mSearchHandlerList.at(1);
    94     progressiveState->onAsyncSearchComplete(-1, 10);
    87     progressiveState->onAsyncSearchComplete(-1, 10);
    95     QCOMPARE(progressiveState->mResultcount,0);
    88     QCOMPARE(progressiveState->mResultcount,0);
    96 
    89 
    97     progressiveState->onAsyncSearchComplete(0, -1);
    90     progressiveState->onAsyncSearchComplete(0, -1);
    98     QCOMPARE(progressiveState->mResultcount,0);
    91     QCOMPARE(progressiveState->mResultcount,0);
    99 
    92     progressiveState->mSearchHandler->searchAsync("a", "_aggregate");
   100     progressiveState->onAsyncSearchComplete(0, 10);
    93     QTest::qWait(100);
   101     QCOMPARE(progressiveState->mResultcount,10);
    94     //QCOMPARE(progressiveState->mResultcount,10);
   102 
    95 
   103     delete progressiveState;
    96     delete progressiveState;
   104   //  delete wind;
    97     //  delete wind;
   105     }
    98     }
   106 // ---------------------------------------------------------------------------
    99 // ---------------------------------------------------------------------------
   107 // ---------------------------------------------------------------------------
   100 // ---------------------------------------------------------------------------
   108 //
   101 //
   109 void SearchStateProviderTest::testonGetDocumentComplete()
   102 void SearchStateProviderTest::testonGetDocumentComplete()
   110     {
   103     {
   111 //    HbMainWindow* wind = mainWindow();
   104     //    HbMainWindow* wind = mainWindow();
   112     SearchProgressiveState* progressiveState = new SearchProgressiveState();
   105     SearchProgressiveState* progressiveState = new SearchProgressiveState();
   113     QEvent *event = new QEvent(QEvent::None);
   106     QEvent *event = new QEvent(QEvent::None);
   114     progressiveState->onEntry(event);
   107 
   115 
   108     progressiveState->mSelectedCategory.insert(1, true);
       
   109     progressiveState->onEntry(event);
       
   110     // progressiveState->mSearchHandler = progressiveState->mSearchHandlerList.at(1);
   116     progressiveState->onGetDocumentComplete(0, NULL);
   111     progressiveState->onGetDocumentComplete(0, NULL);
   117     QCOMPARE(progressiveState->mModel->rowCount(),0);
   112     QCOMPARE(progressiveState->mModel->rowCount(),0);
   118 
   113 
   119     progressiveState->onGetDocumentComplete(-1, NULL);
   114     progressiveState->onGetDocumentComplete(-1, NULL);
   120     QCOMPARE(progressiveState->mModel->rowCount(),0);
   115     QCOMPARE(progressiveState->mModel->rowCount(),0);
   121 
   116     progressiveState->startNewSearch("a");
   122     delete progressiveState;
   117     QTest::qWait(2000);
   123   //  delete wind;
   118     int i =progressiveState->mModel->rowCount();
       
   119     QVERIFY(progressiveState->mModel->rowCount());
       
   120     delete progressiveState;
       
   121     //  delete wind;
   124     }
   122     }
   125 // ---------------------------------------------------------------------------
   123 // ---------------------------------------------------------------------------
   126 // ---------------------------------------------------------------------------
   124 // ---------------------------------------------------------------------------
   127 //
   125 //
   128 void SearchStateProviderTest::testgetSettingCategory()
   126 void SearchStateProviderTest::testgetSettingCategory()
   129     {
   127     {
   130 //    HbMainWindow* wind = mainWindow();
   128     //    HbMainWindow* wind = mainWindow();
   131     SearchProgressiveState* progressiveState = new SearchProgressiveState();
   129     SearchProgressiveState* progressiveState = new SearchProgressiveState();
   132     QEvent *event = new QEvent(QEvent::None);
   130     QEvent *event = new QEvent(QEvent::None);
   133     progressiveState->onEntry(event);
   131     progressiveState->onEntry(event);
       
   132 
   134     progressiveState->getSettingCategory(3, true);
   133     progressiveState->getSettingCategory(3, true);
   135     QCOMPARE(progressiveState->mSelectedCategory.count(),1);
   134     QCOMPARE(progressiveState->mSelectedCategory.count(),1);
   136     delete progressiveState;
   135     delete progressiveState;
   137  //   delete wind;
   136     //   delete wind;
   138     }
   137     }
   139 // ---------------------------------------------------------------------------
   138 // ---------------------------------------------------------------------------
   140 // ---------------------------------------------------------------------------
   139 // ---------------------------------------------------------------------------
   141 //
   140 //
   142 void SearchStateProviderTest::testopenResultitem()
   141 void SearchStateProviderTest::testopenResultitem()
   143     {
   142     {
   144 //    HbMainWindow* wind = mainWindow();
   143     //    HbMainWindow* wind = mainWindow();
   145      SearchProgressiveState* progressiveState = new SearchProgressiveState();
   144     SearchProgressiveState* progressiveState = new SearchProgressiveState();
   146     QEvent *event = new QEvent(QEvent::None);
   145     QEvent *event = new QEvent(QEvent::None);
   147     progressiveState->onEntry(event);
   146 
   148     progressiveState->mSelectedCategory.insert(1, true);
   147     progressiveState->mSelectedCategory.insert(1, true);
       
   148     progressiveState->onEntry(event);
   149     progressiveState->startNewSearch("a");
   149     progressiveState->startNewSearch("a");
   150     QTest::qWait(200);
   150     QTest::qWait(100);
       
   151     progressiveState->cancelSearch();
   151     //code for getting the model index from model
   152     //code for getting the model index from model
   152     QModelIndex index = progressiveState->mModel->index(1, 0, QModelIndex());
   153     QModelIndex index = progressiveState->mModel->index(0, 0);
   153     progressiveState->openResultitem(index);
   154     progressiveState->openResultitem(index);
   154     delete progressiveState;
   155     delete progressiveState;
   155  /*//   delete wind;
   156     //   delete wind;    
   156 
   157     }
   157        {
       
   158         SearchProgressiveState* progressiveState =
       
   159                 new SearchProgressiveState();
       
   160         QEvent *event = new QEvent(QEvent::None);
       
   161         progressiveState->onEntry(event);
       
   162         progressiveState->mSelectedCategory.insert(3, true);
       
   163         progressiveState->startNewSearch("a");
       
   164         QTest::qWait(200);
       
   165         //code for getting the model index from model
       
   166         QModelIndex index = progressiveState->mModel->index(1, 0,
       
   167                 QModelIndex());
       
   168         progressiveState->openResultitem(index);
       
   169 
       
   170         //to do
       
   171         delete progressiveState;
       
   172         }
       
   173 */    }
       
   174 // ---------------------------------------------------------------------------
   158 // ---------------------------------------------------------------------------
   175 // ---------------------------------------------------------------------------
   159 // ---------------------------------------------------------------------------
   176 //
   160 //
   177 void SearchStateProviderTest::testcreateSuggestionLink()
   161 void SearchStateProviderTest::testcreateSuggestionLink()
   178     {
   162     {
   179     SearchProgressiveState* progressiveState = new SearchProgressiveState();
   163     SearchProgressiveState* progressiveState = new SearchProgressiveState();
   180     QEvent *event = new QEvent(QEvent::None);
   164     QEvent *event = new QEvent(QEvent::None);
   181     progressiveState->onEntry(event);
   165     progressiveState->onEntry(event);
   182 
   166 
   183     progressiveState->createSuggestionLink(true);
   167     progressiveState->createSuggestionLink(true);
   184     //    QModelIndex index = progressiveState->mModel->index(0, 0, QModelIndex());
   168     QCOMPARE(progressiveState->mModel->rowCount(), 0);
   185     //  progressiveState->openResultitem(index);
   169     progressiveState->createSuggestionLink(false);
   186 
   170     QCOMPARE(progressiveState->mModel->rowCount(), 1);
   187     //progressiveState->createSuggestionLink(false);
       
   188     //QCOMPARE(progressiveState->mModel->rowCount(),0);
       
   189 
       
   190     delete progressiveState;
   171     delete progressiveState;
   191     }
   172     }
   192 // ---------------------------------------------------------------------------
   173 // ---------------------------------------------------------------------------
   193 // ---------------------------------------------------------------------------
   174 // ---------------------------------------------------------------------------
   194 //
   175 //
   234 //
   215 //
   235 void SearchStateProviderTest::teststartNewSearch()
   216 void SearchStateProviderTest::teststartNewSearch()
   236     {
   217     {
   237     SearchProgressiveState* progressiveState = new SearchProgressiveState();
   218     SearchProgressiveState* progressiveState = new SearchProgressiveState();
   238     QEvent *event = new QEvent(QEvent::None);
   219     QEvent *event = new QEvent(QEvent::None);
   239     progressiveState->onEntry(event);
   220     progressiveState->mSelectedCategory.insert(1, true);
   240     progressiveState->mSelectedCategory.insert(6, true);
   221     progressiveState->onEntry(event);
   241     progressiveState->startNewSearch("sample");
   222     progressiveState->startNewSearch("a");
   242     delete progressiveState;
   223     delete progressiveState;
   243     }
   224     }
   244 // ---------------------------------------------------------------------------
   225 
   245 // ---------------------------------------------------------------------------
       
   246 //
       
   247 void SearchStateProviderTest::testsetHistory()
       
   248     {
       
   249     SearchProgressiveState* progressiveState = new SearchProgressiveState();
       
   250     QEvent *event = new QEvent(QEvent::None);
       
   251     progressiveState->onEntry(event);
       
   252     QSignalSpy spy(progressiveState, SIGNAL(historyState()));
       
   253   //  progressiveState->setHistory();
       
   254     QCOMPARE(spy.count(), 1);
       
   255     delete progressiveState;
       
   256     }
       
   257 // ---------------------------------------------------------------------------
   226 // ---------------------------------------------------------------------------
   258 // ---------------------------------------------------------------------------
   227 // ---------------------------------------------------------------------------
   259 //
   228 //
   260 void SearchStateProviderTest::testsetSettings()
   229 void SearchStateProviderTest::testsetSettings()
   261     {
   230     {
   265     QSignalSpy spy(progressiveState, SIGNAL(settingsState()));
   234     QSignalSpy spy(progressiveState, SIGNAL(settingsState()));
   266     progressiveState->setSettings();
   235     progressiveState->setSettings();
   267     QCOMPARE(spy.count(), 1);
   236     QCOMPARE(spy.count(), 1);
   268     delete progressiveState;
   237     delete progressiveState;
   269     }
   238     }
   270 // ---------------------------------------------------------------------------
       
   271 // ---------------------------------------------------------------------------
       
   272 //
       
   273 void SearchStateProviderTest::testaboutToCloseView()
       
   274     {
       
   275     SearchProgressiveState* progressiveState = new SearchProgressiveState();
       
   276     QEvent *event = new QEvent(QEvent::None);
       
   277     progressiveState->onEntry(event);
       
   278     //progressiveState->aboutToCloseView();
       
   279     delete progressiveState;
       
   280     }
       
   281 
   239 
   282 void SearchStateProviderTest::test_CustomizeGoButton()
   240 void SearchStateProviderTest::test_CustomizeGoButton()
   283     {
   241     {
   284 
   242     SearchProgressiveState* progressiveState = new SearchProgressiveState();
   285     SearchProgressiveState* progressiveState = new SearchProgressiveState();
   243     QEvent *event = new QEvent(QEvent::None);
       
   244     progressiveState->onEntry(event);
   286     progressiveState->_customizeGoButton(true);
   245     progressiveState->_customizeGoButton(true);
       
   246     QVERIFY(!(progressiveState->mSearchPanel->isProgressive()));
   287     progressiveState->_customizeGoButton(false);
   247     progressiveState->_customizeGoButton(false);
   288     //QEvent *event = new QEvent(QEvent::None);
   248     QVERIFY(progressiveState->mSearchPanel->isProgressive());
   289     // progressiveState->onEntry(event);
   249     delete progressiveState;
   290     // progressiveState->aboutToCloseView();
   250     }
   291     delete progressiveState;
   251 
   292 
   252 void SearchStateProviderTest::testgetAppIconFromAppId()
   293     }
   253     {
   294 
   254 
       
   255     SearchProgressiveState* progressiveState = new SearchProgressiveState();
       
   256     QEvent *event = new QEvent(QEvent::None);
       
   257     progressiveState->onEntry(event);
       
   258     for (int i = 0; i < progressiveState->mIconArray.count(); i++)
       
   259         {
       
   260         QVERIFY(!(progressiveState->mIconArray.at(i).isNull()));
       
   261         }
       
   262     progressiveState->mIconArray.clear();
       
   263     delete progressiveState;
       
   264     }
       
   265 
       
   266 // ---------------------------------------------------------------------------
       
   267 // ---------------------------------------------------------------------------
       
   268 //
       
   269 void SearchStateProviderTest::testsettingsaction()
       
   270     {
       
   271     SearchProgressiveState* progressiveState = new SearchProgressiveState();
       
   272     QEvent *event = new QEvent(QEvent::None);
       
   273     progressiveState->onEntry(event);
       
   274     progressiveState->getSettingCategory(5, true);
       
   275     progressiveState->mOriginalString = "a";
       
   276     progressiveState->settingsaction(false);
       
   277     QCOMPARE(progressiveState->mResultcount, 0);
       
   278     progressiveState->settingsaction(true);
       
   279     QTest::qWait(50);
       
   280     progressiveState->cancelSearch();
       
   281     QCOMPARE(progressiveState->mResultcount, 0);
       
   282     delete progressiveState;
       
   283     }
       
   284 // ---------------------------------------------------------------------------
       
   285 //SearchStateProviderTest::testcancelsearch()
       
   286 // ---------------------------------------------------------------------------
       
   287 //
       
   288 void SearchStateProviderTest::testcancelsearch()
       
   289     {
       
   290     SearchProgressiveState* progressiveState = new SearchProgressiveState();
       
   291     QEvent *event = new QEvent(QEvent::None);
       
   292     progressiveState->onEntry(event);
       
   293     progressiveState->getSettingCategory(5, true);
       
   294     progressiveState->startNewSearch("a");
       
   295     progressiveState->cancelSearch();
       
   296     delete progressiveState;
       
   297 
       
   298     }
       
   299 void SearchStateProviderTest::testhandleokanderror()
       
   300     {
       
   301     SearchProgressiveState* progressiveState = new SearchProgressiveState();
       
   302     QEvent *event = new QEvent(QEvent::None);
       
   303     progressiveState->onEntry(event);
       
   304     QVariant var;
       
   305     progressiveState->handleOk(var);
       
   306     int ret = 0;
       
   307     progressiveState->handleError(ret, QString());
       
   308     delete progressiveState;
       
   309     }
       
   310 void SearchStateProviderTest::testTDisplayMode2Format()
       
   311     {
       
   312     SearchProgressiveState* progressiveState = new SearchProgressiveState();
       
   313     QEvent *event = new QEvent(QEvent::None);
       
   314     progressiveState->onEntry(event);
       
   315     TDisplayMode mode = EGray2;
       
   316     progressiveState->TDisplayMode2Format(mode);
       
   317     mode = EColor256;
       
   318     progressiveState->TDisplayMode2Format(mode);
       
   319     mode = EGray256;
       
   320     progressiveState->TDisplayMode2Format(mode);
       
   321     mode = EColor4K;
       
   322     progressiveState->TDisplayMode2Format(mode);
       
   323     mode = EColor64K;
       
   324     progressiveState->TDisplayMode2Format(mode);
       
   325     mode = EColor16M;
       
   326     progressiveState->TDisplayMode2Format(mode);
       
   327     mode = EColor16MU;
       
   328     progressiveState->TDisplayMode2Format(mode);
       
   329     mode = EColor16MA;
       
   330     progressiveState->TDisplayMode2Format(mode);
       
   331     mode = EColor16MAP;
       
   332     progressiveState->TDisplayMode2Format(mode);
       
   333     mode = ENone;
       
   334     progressiveState->TDisplayMode2Format(mode);
       
   335 
       
   336     delete progressiveState;
       
   337     }
       
   338 void SearchStateProviderTest::testsetSelectedCategories()
       
   339     {
       
   340     SearchProgressiveState* progressiveState = new SearchProgressiveState();
       
   341     QEvent *event = new QEvent(QEvent::None);
       
   342     progressiveState->onEntry(event);
       
   343     progressiveState->getSettingCategory(0, true);
       
   344     progressiveState->getSettingCategory(1, true);
       
   345     progressiveState->getSettingCategory(2, true);
       
   346     progressiveState->getSettingCategory(3, true);
       
   347     progressiveState->getSettingCategory(4, true);
       
   348     progressiveState->getSettingCategory(5, true);
       
   349     progressiveState->getSettingCategory(6, true);
       
   350     progressiveState->getSettingCategory(7, true);
       
   351     progressiveState->setSelectedCategories();
       
   352     delete progressiveState;
       
   353     }
       
   354 
       
   355 void SearchStateProviderTest::testfilterdoc()
       
   356     {
       
   357     
       
   358         SearchProgressiveState* progressiveState = new SearchProgressiveState();
       
   359         QEvent *event = new QEvent(QEvent::None);
       
   360         progressiveState->onEntry(event);
       
   361         progressiveState->filterDoc(NULL,"Name");
       
   362         delete progressiveState;  
       
   363     
       
   364     }