phoneplugins/infowidgetplugin/tsrc/ut_infowidgetsathandlerprivate/src/ut_infowidgetsathandlerprivate.cpp
changeset 46 bc5a64e5bc3c
parent 45 6b911d05207e
equal deleted inserted replaced
45:6b911d05207e 46:bc5a64e5bc3c
    15 *
    15 *
    16 */
    16 */
    17 
    17 
    18 #include "ut_infowidgetsathandlerprivate.h"
    18 #include "ut_infowidgetsathandlerprivate.h"
    19 #define private public
    19 #define private public
    20 #include "infowidgetsathandlerprivate.h"
    20 #include "infowidgetsathandler_p.h"
    21 #include "infowidgetsathandler.h"
    21 #include "infowidgetsathandler.h"
    22 #include "infowidgetlogging.h"
    22 #include "infowidgetlogging.h"
    23 #include "qtestmains60.h"
    23 #include "qtestmains60.h"
       
    24 
       
    25 static struct ActiveObjectControl {
       
    26     enum TOperation {
       
    27         EUndefined = 0, 
       
    28         ECallRunL, 
       
    29         ECallDoCancel,
       
    30         EExitSequence
       
    31     } operation;
       
    32     int iStatus; 
       
    33     CActive* object; 
       
    34 } m_activeObjectControl; 
       
    35 
       
    36  
       
    37 void CActive::SetActive(){
       
    38     if (m_activeObjectControl.object) 
       
    39     {
       
    40     switch (m_activeObjectControl.operation) {
       
    41         case ActiveObjectControl::ECallRunL: 
       
    42             m_activeObjectControl.operation = ActiveObjectControl::EExitSequence;
       
    43             m_activeObjectControl.object->iStatus = 
       
    44                     m_activeObjectControl.iStatus;
       
    45             m_activeObjectControl.object->RunL(); 
       
    46             break;
       
    47         case ActiveObjectControl::ECallDoCancel: 
       
    48             m_activeObjectControl.operation = ActiveObjectControl::EExitSequence;
       
    49             m_activeObjectControl.object->iStatus = 
       
    50                     m_activeObjectControl.iStatus;
       
    51             m_activeObjectControl.object->DoCancel(); 
       
    52             break;
       
    53             
       
    54         default: 
       
    55             break; 
       
    56         }
       
    57     
       
    58     // Reset, causes infinite loop otherwise 
       
    59     m_activeObjectControl.operation = ActiveObjectControl::EUndefined; 
       
    60     m_activeObjectControl.object = NULL; 
       
    61     }
       
    62 } 
    24 
    63 
    25 void SimulateLeaveL()
    64 void SimulateLeaveL()
    26 {
    65 {
    27     User::Leave(KErrGeneral);
    66     User::Leave(KErrGeneral);
    28 }
    67 }
    59 }
    98 }
    60 
    99 
    61 /*!
   100 /*!
    62   UT_InfoWidgetSatHandlerPrivate ::UT_InfoWidgetSatHandlerPrivate 
   101   UT_InfoWidgetSatHandlerPrivate ::UT_InfoWidgetSatHandlerPrivate 
    63  */
   102  */
    64 UT_InfoWidgetSatHandlerPrivate::UT_InfoWidgetSatHandlerPrivate () //:
   103 UT_InfoWidgetSatHandlerPrivate::UT_InfoWidgetSatHandlerPrivate () 
    65 {
   104 {
    66     DPRINT << "IN";
   105     DPRINT << "IN";
    67     
   106     
    68     m_satHandler = 0;
   107     m_satHandlerPrivate = 0;
    69     m_iwSatHandler = 0;
   108     m_iwSatHandler = 0;
    70     
   109     
    71     DPRINT << "OUT";
   110     DPRINT << "OUT";
    72 }
   111 }
    73 
   112 
    76  */
   115  */
    77 UT_InfoWidgetSatHandlerPrivate::~UT_InfoWidgetSatHandlerPrivate ()
   116 UT_InfoWidgetSatHandlerPrivate::~UT_InfoWidgetSatHandlerPrivate ()
    78 {
   117 {
    79     DPRINT << "IN";
   118     DPRINT << "IN";
    80     
   119     
    81     delete m_satHandler;
   120     delete m_satHandlerPrivate;
    82     delete m_iwSatHandler;
   121     delete m_iwSatHandler;
    83     
   122     
    84     DPRINT << "OUT";
   123     DPRINT << "OUT";
    85 }
   124 }
    86 
   125 
    91 {
   130 {
    92     DPRINT << "IN";
   131     DPRINT << "IN";
    93     
   132     
    94     initialize();
   133     initialize();
    95     m_iwSatHandler = new InfoWidgetSatHandler;
   134     m_iwSatHandler = new InfoWidgetSatHandler;
    96     m_satHandler =  new InfoWidgetSatHandlerPrivate( m_iwSatHandler, m_satService);
   135     m_satHandlerPrivate =  new InfoWidgetSatHandlerPrivate( m_iwSatHandler, m_satService);
    97     
   136     
    98     QVERIFY(verify());
   137     QVERIFY(verify());
    99 
   138 
   100     DPRINT << "OUT";
   139     DPRINT << "OUT";
   101 }
   140 }
   106 void UT_InfoWidgetSatHandlerPrivate::cleanup()
   145 void UT_InfoWidgetSatHandlerPrivate::cleanup()
   107 {
   146 {
   108     DPRINT << "IN";
   147     DPRINT << "IN";
   109     
   148     
   110     reset();
   149     reset();
   111     delete m_satHandler;
   150     delete m_satHandlerPrivate;
   112     delete m_iwSatHandler;
   151     delete m_iwSatHandler;
   113 
   152 
   114     DPRINT << "OUT";
   153     DPRINT << "OUT";
   115 }
   154 }
   116 
   155 
   121 {
   160 {
   122     DPRINT << "IN";
   161     DPRINT << "IN";
   123     
   162     
   124     expect("RSatSession::ConnectL");
   163     expect("RSatSession::ConnectL");
   125     expect("RSatService::OpenL");
   164     expect("RSatService::OpenL");
   126     m_satHandler->connect();
   165     m_satHandlerPrivate->connect();
   127      
   166      
   128     expect("RSatSession::ConnectL")
   167     expect("RSatSession::ConnectL")
   129         .willOnce(invokeWithoutArguments(SimulateLeaveL));
   168         .willOnce(invokeWithoutArguments(SimulateLeaveL));
   130     m_satHandler->connect();
   169     m_satHandlerPrivate->connect();
   131     
   170     
   132     expect("RSatService::OpenL")
   171     expect("RSatService::OpenL")
   133         .willOnce(invokeWithoutArguments(SimulateLeaveL));
   172         .willOnce(invokeWithoutArguments(SimulateLeaveL));
   134     m_satHandler->connect();
   173     m_satHandlerPrivate->connect();
   135 
   174 
   136     QVERIFY(verify());
   175     QVERIFY(verify());
   137 
   176 
   138     DPRINT << "OUT";
   177     DPRINT << "OUT";
   139 }
   178 }
   143  */
   182  */
   144 void UT_InfoWidgetSatHandlerPrivate::t_disconnect()
   183 void UT_InfoWidgetSatHandlerPrivate::t_disconnect()
   145 {
   184 {
   146     DPRINT << "IN";
   185     DPRINT << "IN";
   147     
   186     
   148     m_satHandler->disconnect();
   187     m_satHandlerPrivate->disconnect();
   149     QVERIFY(verify());
   188     QVERIFY(verify());
   150 
   189 
   151     DPRINT << "OUT";
   190     DPRINT << "OUT";
   152 }
   191 }
   153 
   192 
   160     
   199     
   161     int i = KErrGeneral;
   200     int i = KErrGeneral;
   162     expect("RSatService::NotifySetupIdleModeTextChange").returns(i);
   201     expect("RSatService::NotifySetupIdleModeTextChange").returns(i);
   163     expect("RSatService::GetSetupIdleModeTextL")
   202     expect("RSatService::GetSetupIdleModeTextL")
   164         .willOnce(invoke(FillData));
   203         .willOnce(invoke(FillData));
   165     m_satHandler->startObserving();
   204     m_satHandlerPrivate->startObserving();
   166     
   205     
   167     expect("RSatService::NotifySetupIdleModeTextChange").returns(i);
   206     expect("RSatService::NotifySetupIdleModeTextChange").returns(i);
   168     expect("RSatService::GetSetupIdleModeTextL")
   207     expect("RSatService::GetSetupIdleModeTextL")
   169         .willOnce(invoke(FillDataNoIcon));
   208         .willOnce(invoke(FillDataNoIcon));
   170     m_satHandler->startObserving();
   209     m_satHandlerPrivate->startObserving();
   171     
   210     
   172     expect("RSatService::NotifySetupIdleModeTextChange").returns(i);
   211     expect("RSatService::NotifySetupIdleModeTextChange").returns(i);
   173     expect("RSatService::GetSetupIdleModeTextL")
   212     expect("RSatService::GetSetupIdleModeTextL")
   174         .willOnce(invoke(FillDataSelfExplIcon));
   213         .willOnce(invoke(FillDataSelfExplIcon));
   175     m_satHandler->startObserving();
   214     m_satHandlerPrivate->startObserving();
   176     
   215     
   177     expect("RSatService::GetSetupIdleModeTextL")
   216     expect("RSatService::GetSetupIdleModeTextL")
   178         .willOnce(invokeWithoutArguments(SimulateLeaveL));
   217         .willOnce(invokeWithoutArguments(SimulateLeaveL));
   179     m_satHandler->startObserving();
   218     m_satHandlerPrivate->startObserving();
   180     
   219     
   181     QVERIFY(verify());
   220     QVERIFY(verify());
   182 
   221 
   183     DPRINT << "OUT";
   222     DPRINT << "OUT";
   184 }
   223 }
   186 /*!
   225 /*!
   187   UT_InfoWidgetSatHandlerPrivate::t_runL
   226   UT_InfoWidgetSatHandlerPrivate::t_runL
   188  */
   227  */
   189 void UT_InfoWidgetSatHandlerPrivate::t_runL()
   228 void UT_InfoWidgetSatHandlerPrivate::t_runL()
   190 {
   229 {
   191     DPRINT << "IN";
   230     DPRINT;
   192     
       
   193     int i = 1;
       
   194     expect("RSatService::GetSetupIdleModeTextL")
   231     expect("RSatService::GetSetupIdleModeTextL")
   195           .willOnce(invoke(FillData));
   232           .willOnce(invoke(FillData));
   196     expect("RSatService::NotifySetupIdleModeTextChange").returns(i);
   233     expect("RSatService::NotifySetupIdleModeTextChange").returns(KErrNone);
   197     m_satHandler->RunL();
   234     
   198     
   235     TRequestStatus& status(m_satHandlerPrivate->iStatus);
   199     m_satHandler->iStatus = KErrGeneral;
   236     expect("RSatService::NotifySetupIdleModeTextChange").with(status);
   200     expect("RSatService::NotifySetupIdleModeTextChange").returns(i);
   237     
   201     m_satHandler->RunL();
   238     // Test RunL sequence with iStatus == KErrNone  
   202         
   239     m_activeObjectControl.operation = ActiveObjectControl::ECallRunL; 
   203     QVERIFY(verify());
   240     m_activeObjectControl.iStatus = KErrNone; 
   204 
   241     m_activeObjectControl.object = m_satHandlerPrivate; 
   205     DPRINT << "OUT";
   242     m_satHandlerPrivate->startObserving();
       
   243     
       
   244     // Test RunL sequence with iStatus == KErrGeneral
       
   245     m_activeObjectControl.operation = ActiveObjectControl::ECallRunL; 
       
   246     m_activeObjectControl.iStatus = KErrGeneral; 
       
   247     m_activeObjectControl.object = m_satHandlerPrivate; 
       
   248     m_satHandlerPrivate->startObserving();
       
   249     QVERIFY(verify());
   206 }
   250 }
   207 
   251 
   208 /*!
   252 /*!
   209   UT_InfoWidgetSatHandlerPrivate::t_doCancel
   253   UT_InfoWidgetSatHandlerPrivate::t_doCancel
   210  */
   254  */
   211 void UT_InfoWidgetSatHandlerPrivate::t_doCancel()
   255 void UT_InfoWidgetSatHandlerPrivate::t_doCancel()
   212 {    
   256 {    
   213     DPRINT << "IN";
   257     DPRINT << "IN";
   214 
   258 
   215     m_satHandler->DoCancel();
   259     m_activeObjectControl.operation = ActiveObjectControl::ECallDoCancel; 
       
   260     m_activeObjectControl.iStatus = KErrNone; 
       
   261     m_activeObjectControl.object = m_satHandlerPrivate; 
       
   262     m_satHandlerPrivate->startObserving();
       
   263     
   216     QVERIFY(verify());
   264     QVERIFY(verify());
   217 
   265 
   218     DPRINT << "OUT";
   266     DPRINT << "OUT";
   219 }
   267 }
   220 
   268