logsui/logsapp/tsrc/ut_logsapp/src/ut_logsservicehandler.cpp
changeset 6 41c0a814d878
parent 0 4a5361db8937
child 8 6c9acdc6adc0
equal deleted inserted replaced
4:e52d42f9500c 6:41c0a814d878
    16 */
    16 */
    17 
    17 
    18 //USER
    18 //USER
    19 #include "ut_logsservicehandler.h"
    19 #include "ut_logsservicehandler.h"
    20 #include "logsservicehandler.h"
    20 #include "logsservicehandler.h"
       
    21 #include "logsservicehandlerold.h"
    21 #include "qthighway_stub_helper.h"
    22 #include "qthighway_stub_helper.h"
    22 #include "ut_logsviewmanager.h"
    23 #include "ut_logsviewmanager.h"
    23 #include "logsviewmanager.h"
    24 #include "logsviewmanager.h"
    24 #include "logsmainwindow.h"
    25 #include "logsmainwindow.h"
    25 #include "logscomponentrepository.h"
    26 #include "logscomponentrepository.h"
    26 #include "logsmatchesview.h"
    27 #include "logsmatchesview.h"
       
    28 #include "logsdefs.h"
    27 
    29 
    28 //SYSTEM
    30 //SYSTEM
    29 #include <QtTest/QtTest>
    31 #include <QtTest/QtTest>
    30 
    32 
    31 Q_DECLARE_METATYPE(LogsServices::LogsView)
    33 Q_DECLARE_METATYPE(LogsServices::LogsView)
    41 
    43 
    42 void UT_LogsServiceHandler::init()
    44 void UT_LogsServiceHandler::init()
    43 {
    45 {
    44     mMainWindow =  new LogsMainWindow();
    46     mMainWindow =  new LogsMainWindow();
    45     mService = new LogsServiceHandler(*mMainWindow);
    47     mService = new LogsServiceHandler(*mMainWindow);
       
    48     mServiceOld = new LogsServiceHandlerOld(*mMainWindow);
    46     
    49     
    47     mLogsViewManager = new LogsViewManager(*mMainWindow, *mService);
    50     mLogsViewManager = new LogsViewManager(*mMainWindow, *mService, *mServiceOld);
    48     
    51     
    49 }
    52 }
    50 
    53 
    51 void UT_LogsServiceHandler::cleanup()
    54 void UT_LogsServiceHandler::cleanup()
    52 {
    55 {
    53     delete mService;
    56     delete mService;
    54     mService = 0;
    57     mService = 0;
       
    58     delete mServiceOld;
       
    59     mServiceOld = 0;
    55     delete mMainWindow;
    60     delete mMainWindow;
    56     mMainWindow = 0;
    61     mMainWindow = 0;
    57     delete mLogsViewManager;
    62     delete mLogsViewManager;
    58     mLogsViewManager = 0;
    63     mLogsViewManager = 0;
    59     
    64     
    63 void UT_LogsServiceHandler::testConstructor()
    68 void UT_LogsServiceHandler::testConstructor()
    64 {
    69 {
    65     QVERIFY( mService );
    70     QVERIFY( mService );
    66     QVERIFY( !mService->mIsAppStartedUsingService );
    71     QVERIFY( !mService->mIsAppStartedUsingService );
    67     QVERIFY( !mService->isStartedUsingService() );
    72     QVERIFY( !mService->isStartedUsingService() );
       
    73 
       
    74     QVERIFY( mServiceOld );
       
    75     QVERIFY( !mServiceOld->mIsAppStartedUsingService );
       
    76     QVERIFY( !mServiceOld->isStartedUsingService() );
       
    77 
    68     
    78     
    69     QtHighwayStubHelper::setIsService(true);
    79     QtHighwayStubHelper::setIsService(true);
    70     LogsServiceHandler serviceHandler(*mMainWindow);
    80     LogsServiceHandler serviceHandler(*mMainWindow);
    71     QVERIFY( serviceHandler.mIsAppStartedUsingService );
    81     QVERIFY( serviceHandler.mIsAppStartedUsingService );
    72     QVERIFY( serviceHandler.isStartedUsingService() );
    82     QVERIFY( serviceHandler.isStartedUsingService() );
    73     
    83     
       
    84     LogsServiceHandlerOld serviceHandlerOld(*mMainWindow);
       
    85     QVERIFY( serviceHandlerOld.mIsAppStartedUsingService );
       
    86     QVERIFY( serviceHandlerOld.isStartedUsingService() );
    74 }
    87 }
    75 
    88 
    76 void UT_LogsServiceHandler::testStart()
    89 void UT_LogsServiceHandler::testStart()
    77 {
    90 {
    78     qRegisterMetaType< LogsServices::LogsView >("LogsServices::LogsView");
    91     qRegisterMetaType< LogsServices::LogsView >("LogsServices::LogsView");
    79     QSignalSpy spy(mService, SIGNAL(activateView(LogsServices::LogsView, bool)));
    92     QSignalSpy spy(mServiceOld, SIGNAL(activateView(LogsServices::LogsView, bool)));
    80      
    93      
    81     // Wrong view
    94     // Wrong view
    82     QVERIFY( mService->start( 9999, true ) != 0 );
    95     QVERIFY( mServiceOld->start( 9999, true ) != 0 );
    83     QVERIFY( spy.count() == 0 );
    96     QVERIFY( spy.count() == 0 );
    84 
    97 
    85     // Correct view
    98     // Correct view
    86     mService->mMainWindow.mForeground = false;
    99     mServiceOld->mMainWindow.mForeground = false;
    87     QVERIFY( mService->start( (int)LogsServices::ViewReceived, true  ) == 0 );
   100     QVERIFY( mServiceOld->start( (int)LogsServices::ViewReceived, true  ) == 0 );
    88     QVERIFY( spy.count() == 1 );
   101     QVERIFY( spy.count() == 1 );
    89     LogsServices::LogsView view = 
   102     LogsServices::LogsView view = 
    90         qvariant_cast< LogsServices::LogsView >(spy.at(0).at(0));
   103         qvariant_cast< LogsServices::LogsView >(spy.at(0).at(0));
    91     QVERIFY( view == LogsServices::ViewReceived );
   104     QVERIFY( view == LogsServices::ViewReceived );
    92     QVERIFY( mService->currentlyActivatedView() == LogsServices::ViewReceived  );
   105     QVERIFY( mServiceOld->mMainWindow.mForeground );  
    93     QVERIFY( mService->mMainWindow.mForeground );  
       
    94 }
   106 }
    95 
   107 
    96 void UT_LogsServiceHandler::testStartWithNum()
   108 void UT_LogsServiceHandler::testStartWithNum()
    97 {
   109 {
    98     qRegisterMetaType< LogsServices::LogsView >("LogsServices::LogsView");
   110     qRegisterMetaType< LogsServices::LogsView >("LogsServices::LogsView");
    99     QSignalSpy spy2(mService, SIGNAL(activateView(QString)));
   111     QSignalSpy spy2(mServiceOld, SIGNAL(activateView(QString)));
   100 
   112 
   101     mService->mMainWindow.mForeground = false;
   113     mServiceOld->mMainWindow.mForeground = false;
   102     QVERIFY( mService->startWithNum( (int)LogsServices::ViewReceived, true,
   114     QVERIFY( mServiceOld->startWithNum( (int)LogsServices::ViewReceived, true,
   103             QString("+123456")  ) == 0 );
   115             QString("+123456")  ) == 0 );
   104     QVERIFY( spy2.count() == 1 );
   116     QVERIFY( spy2.count() == 1 );
   105     QVERIFY( spy2.at(0).at(0).toString() == QString("+123456"));
   117     QVERIFY( spy2.at(0).at(0).toString() == QString("+123456"));
   106     QVERIFY( mService->mMainWindow.mForeground );  
   118     QVERIFY( mServiceOld->mMainWindow.mForeground );  
   107 }
   119 }
       
   120 
       
   121 void UT_LogsServiceHandler::testShow()
       
   122 {
       
   123     qRegisterMetaType< LogsServices::LogsView >("LogsServices::LogsView");
       
   124     QSignalSpy spy(mService, SIGNAL(activateView(LogsServices::LogsView, bool)));
       
   125     QSignalSpy spy2(mService, SIGNAL(activateView(QString)));
       
   126     QVariantMap map;
       
   127 
       
   128     // Wrong view
       
   129     map.insert(logsViewIndexParam, QVariant(9999));
       
   130     QVERIFY( mService->show(map) != 0 );
       
   131     QVERIFY( spy.count() == 0 );
       
   132     QVERIFY( spy2.count() == 0 );
       
   133     
       
   134     // Correct view, dialpad text is empty
       
   135     map.clear();
       
   136     map.insert(logsViewIndexParam, QVariant((int)LogsServices::ViewReceived));
       
   137     mService->mMainWindow.mForeground = false;
       
   138     QVERIFY( mService->show(map) == 0 );
       
   139     QVERIFY( spy.count() == 1 );
       
   140     QVERIFY( spy2.count() == 0 );
       
   141     LogsServices::LogsView view = 
       
   142             qvariant_cast< LogsServices::LogsView >(spy.at(0).at(0));
       
   143     QVERIFY( view == LogsServices::ViewReceived );
       
   144     QVERIFY( mServiceOld->mMainWindow.mForeground );
       
   145     
       
   146     // Correct view, dialpad text not empty
       
   147     spy.clear();
       
   148     map.clear();
       
   149     map.insert(logsViewIndexParam, QVariant((int)LogsServices::ViewReceived));
       
   150     map.insert(logsDialpadTextParam, QVariant(QString("+123456")));
       
   151     mService->mMainWindow.mForeground = false;
       
   152     QVERIFY( mService->show(map) == 0 );
       
   153     QVERIFY( spy.count() == 0 );
       
   154     QVERIFY( spy2.count() == 1 );
       
   155     QVERIFY( spy2.at(0).at(0).toString() == QString("+123456"));
       
   156     QVERIFY( mServiceOld->mMainWindow.mForeground );
       
   157     
       
   158     // Some completly dummy parameters or no params at all
       
   159     spy.clear();
       
   160     spy2.clear();
       
   161     map.clear();
       
   162     map.insert("dummy_param", QVariant(666));
       
   163     mService->mMainWindow.mForeground = false;
       
   164     QVERIFY( mService->show(map) == 0 );
       
   165     QVERIFY( spy.count() == 1 );
       
   166     QVERIFY( spy2.count() == 0 );
       
   167     view = qvariant_cast< LogsServices::LogsView >(spy.at(0).at(0));
       
   168     QVERIFY( view == LogsServices::ViewAll );
       
   169     QVERIFY( mServiceOld->mMainWindow.mForeground );
       
   170 }