logsui/logsapp/tsrc/ut_logsapp/src/ut_logsmainwindow.cpp
changeset 19 e4c884866116
parent 16 c5af8598d22c
child 18 acd4e87b24b4
equal deleted inserted replaced
16:c5af8598d22c 19:e4c884866116
    23 
    23 
    24 //SYSTEM
    24 //SYSTEM
    25 #include <QtTest/QtTest>
    25 #include <QtTest/QtTest>
    26 #include <hbmainwindow.h>
    26 #include <hbmainwindow.h>
    27 #include <QKeyEvent>
    27 #include <QKeyEvent>
       
    28 #include <xqkeycapture.h>
    28 
    29 
    29 void UT_LogsMainWindow::initTestCase()
    30 void UT_LogsMainWindow::initTestCase()
    30 {
    31 {
    31 
    32 
    32 }
    33 }
    59     // Handled
    60     // Handled
    60     QKeyEvent event2( QEvent::KeyPress, Qt::Key_Yes, Qt::NoModifier);
    61     QKeyEvent event2( QEvent::KeyPress, Qt::Key_Yes, Qt::NoModifier);
    61     mMainWindow->keyPressEvent( &event2 );
    62     mMainWindow->keyPressEvent( &event2 );
    62     QVERIFY( spy.count() == 1 );
    63     QVERIFY( spy.count() == 1 );
    63     
    64     
       
    65     // Handled
       
    66     spy.clear();
       
    67     QKeyEvent event3( QEvent::KeyPress, Qt::Key_Enter, Qt::NoModifier);
       
    68     mMainWindow->keyPressEvent( &event3 );
       
    69     QVERIFY( spy.count() == 1 );
    64 }
    70 }
    65 
    71 
    66 void UT_LogsMainWindow::testSendAppToBackground()
    72 void UT_LogsMainWindow::testSendAppToBackground()
    67 {
    73 {
    68     QtHighwayStubHelper::reset();
    74     QtHighwayStubHelper::reset();
    85  
    91  
    86 void UT_LogsMainWindow::testEventFilter()
    92 void UT_LogsMainWindow::testEventFilter()
    87 {    
    93 {    
    88     QSignalSpy spy( mMainWindow, SIGNAL(localeChanged()) );
    94     QSignalSpy spy( mMainWindow, SIGNAL(localeChanged()) );
    89     QSignalSpy foregroundSpy( mMainWindow, SIGNAL(appGainedForeground()) );
    95     QSignalSpy foregroundSpy( mMainWindow, SIGNAL(appGainedForeground()) );
       
    96     QVERIFY( !mMainWindow->mKeyCapture->mKeys.contains(Qt::Key_Yes) );
    90 
    97 
    91     //Event we are not interested in
    98     //Event we are not interested in
    92     QEvent event(QEvent::Show);
    99     QEvent event(QEvent::Show);
    93     QVERIFY( !mMainWindow->eventFilter(this, &event) );
   100     QVERIFY( !mMainWindow->eventFilter(this, &event) );
    94     QVERIFY( !mMainWindow->isForeground() );
   101     QVERIFY( !mMainWindow->isForeground() );
    95     QVERIFY( !mMainWindow->mLocaleChanged );
   102     QVERIFY( !mMainWindow->mLocaleChanged );
    96     QCOMPARE( foregroundSpy.count(), 0 );
   103     QCOMPARE( foregroundSpy.count(), 0 );
       
   104     QVERIFY( !mMainWindow->mKeyCapture->mKeys.contains(Qt::Key_Yes) );
    97    
   105    
    98     //Coming foreground, locale not changed
   106     //Coming foreground, locale not changed
    99     QEvent eventFg(QEvent::ApplicationActivate);
   107     QEvent eventFg(QEvent::ApplicationActivate);
   100     QVERIFY( !mMainWindow->eventFilter(this, &eventFg) );
   108     QVERIFY( !mMainWindow->eventFilter(this, &eventFg) );
   101     QVERIFY( mMainWindow->isForeground() );
   109     QVERIFY( mMainWindow->isForeground() );
   102     QVERIFY( !mMainWindow->mLocaleChanged );
   110     QVERIFY( !mMainWindow->mLocaleChanged );
   103     QCOMPARE( foregroundSpy.count(), 1 );
   111     QCOMPARE( foregroundSpy.count(), 1 );
       
   112     QVERIFY( mMainWindow->mKeyCapture->mKeys.contains(Qt::Key_Yes) );
   104     foregroundSpy.clear();
   113     foregroundSpy.clear();
   105     
   114     
   106     //LocaleChange event on FG
   115     //LocaleChange event on FG
   107     QEvent eventLocale(QEvent::LocaleChange);
   116     QEvent eventLocale(QEvent::LocaleChange);
   108     QVERIFY( !mMainWindow->eventFilter(this, &eventLocale) );
   117     QVERIFY( !mMainWindow->eventFilter(this, &eventLocale) );
   109     QVERIFY( mMainWindow->isForeground() );
   118     QVERIFY( mMainWindow->isForeground() );
   110     QVERIFY( !mMainWindow->mLocaleChanged );
   119     QVERIFY( !mMainWindow->mLocaleChanged );
   111     QVERIFY( spy.count() == 1 );
   120     QVERIFY( spy.count() == 1 );
       
   121     QVERIFY( mMainWindow->mKeyCapture->mKeys.contains(Qt::Key_Yes) );
   112     QCOMPARE( foregroundSpy.count(), 0 );
   122     QCOMPARE( foregroundSpy.count(), 0 );
   113     spy.clear();
   123     spy.clear();
   114     
   124     
   115     //Going background
   125     //Going background partially, surface check is not reliable at the moment so 
       
   126     // don't care about that, just handle as full foreground loosing
       
   127     HbStubHelper::createWindowSurface();
   116     QEvent eventBg(QEvent::ApplicationDeactivate);
   128     QEvent eventBg(QEvent::ApplicationDeactivate);
   117     QVERIFY( !mMainWindow->eventFilter(this, &eventBg) );
   129     QVERIFY( !mMainWindow->eventFilter(this, &eventBg) );
   118     QVERIFY( !mMainWindow->isForeground() );
   130     QVERIFY( !mMainWindow->isForeground() );
   119     QVERIFY( !mMainWindow->mLocaleChanged );
   131     QVERIFY( !mMainWindow->mLocaleChanged );
       
   132     QVERIFY( !mMainWindow->mKeyCapture->mKeys.contains(Qt::Key_Yes) );
   120     QCOMPARE( foregroundSpy.count(), 0 );
   133     QCOMPARE( foregroundSpy.count(), 0 );
   121     
   134     
       
   135     //Going background fully
       
   136     HbStubHelper::reset();
       
   137     QVERIFY( !mMainWindow->eventFilter(this, &eventBg) );
       
   138     QVERIFY( !mMainWindow->isForeground() );
       
   139     QVERIFY( !mMainWindow->mLocaleChanged );
       
   140     QVERIFY( !mMainWindow->mKeyCapture->mKeys.contains(Qt::Key_Yes) );
       
   141     QCOMPARE( foregroundSpy.count(), 0 );
       
   142         
   122     //LocaleChange event on BG
   143     //LocaleChange event on BG
   123     QVERIFY( !mMainWindow->eventFilter(this, &eventLocale) );
   144     QVERIFY( !mMainWindow->eventFilter(this, &eventLocale) );
   124     QVERIFY( !mMainWindow->isForeground() );
   145     QVERIFY( !mMainWindow->isForeground() );
   125     QVERIFY( mMainWindow->mLocaleChanged );
   146     QVERIFY( mMainWindow->mLocaleChanged );
       
   147     QVERIFY( !mMainWindow->mKeyCapture->mKeys.contains(Qt::Key_Yes) );
   126     QVERIFY( spy.count() == 0 );
   148     QVERIFY( spy.count() == 0 );
   127 
   149 
   128     //Coming foreground after locale cange event
   150     //Coming foreground after locale cange event
   129     QVERIFY( !mMainWindow->eventFilter(this, &eventFg) );
   151     QVERIFY( !mMainWindow->eventFilter(this, &eventFg) );
   130     QVERIFY( mMainWindow->isForeground() );
   152     QVERIFY( mMainWindow->isForeground() );
   131     QVERIFY( !mMainWindow->mLocaleChanged );
   153     QVERIFY( !mMainWindow->mLocaleChanged );
       
   154     QVERIFY( mMainWindow->mKeyCapture->mKeys.contains(Qt::Key_Yes) );
   132     QVERIFY( spy.count() == 1 );
   155     QVERIFY( spy.count() == 1 );
   133 }
   156 }