phonesettings/cpphonesettingsplugins/telephonyplugin/tsrc/ut_cptelephonypluginview/ut_cptelephonypluginview.cpp
changeset 78 baacf668fe89
parent 46 bc5a64e5bc3c
equal deleted inserted replaced
76:cfea66083b62 78:baacf668fe89
    22 #include <cpsettingformitemdata.h>
    22 #include <cpsettingformitemdata.h>
    23 #include <smcmockclassincludes.h>
    23 #include <smcmockclassincludes.h>
    24 #include <hbdataform.h>
    24 #include <hbdataform.h>
    25 #include <hbdataformmodel.h>
    25 #include <hbdataformmodel.h>
    26 #include "cptelephonypluginview.h"
    26 #include "cptelephonypluginview.h"
       
    27 #include <cppluginloader.h>
    27 
    28 
    28 
    29 
    29 class DummyPlugin : public CpPluginInterface
    30 class DummyPlugin : public CpPluginInterface
    30 {
    31 {
    31 public:
    32 public:
    41 
    42 
    42 /*!
    43 /*!
    43   UT_CpTelephonyPluginView::UT_CpTelephonyPluginView
    44   UT_CpTelephonyPluginView::UT_CpTelephonyPluginView
    44  */
    45  */
    45 UT_CpTelephonyPluginView::UT_CpTelephonyPluginView() 
    46 UT_CpTelephonyPluginView::UT_CpTelephonyPluginView() 
    46     : m_callspluginview(NULL)
       
    47 {
    47 {
    48 
       
    49 }
    48 }
    50 
    49 
    51 /*!
    50 /*!
    52   UT_CpTelephonyPluginView::~UT_CpTelephonyPluginView
    51   UT_CpTelephonyPluginView::~UT_CpTelephonyPluginView
    53  */
    52  */
    54 UT_CpTelephonyPluginView::~UT_CpTelephonyPluginView()
    53 UT_CpTelephonyPluginView::~UT_CpTelephonyPluginView()
    55 {
    54 {
    56     delete m_callspluginview;
       
    57 }
    55 }
    58 
       
    59 
    56 
    60 
    57 
    61 /*!
    58 /*!
    62   UT_CpTelephonyPluginView::init
    59   UT_CpTelephonyPluginView::init
    63  */
    60  */
    64 void UT_CpTelephonyPluginView::init()
    61 void UT_CpTelephonyPluginView::init()
    65 {
    62 {
    66     initialize();
    63     initialize();
       
    64 }
    67 
    65 
    68     CpPluginInterface *nullPlugin=0;
       
    69     DummyPlugin *ret = new DummyPlugin;
       
    70 
       
    71     QList<CpSettingFormItemData*> list;
       
    72     list.append(new CpSettingFormItemData);
       
    73     expect("CpPluginLoader::loadCpPluginInterface").
       
    74             with(QString("cpcallsplugin")).returns(ret);
       
    75     expect("DummyPlugin::createSettingFormItemData").returns(list);
       
    76     expect("CpPluginLoader::loadCpPluginInterface").
       
    77             with(QString("cpdivertplugin")).returns(nullPlugin);
       
    78     
       
    79     m_callspluginview = new CpTelephonyPluginView;
       
    80     QVERIFY( verify() );
       
    81 
       
    82 }
       
    83 
    66 
    84 /*!
    67 /*!
    85   UT_CpTelephonyPluginView::cleanup
    68   UT_CpTelephonyPluginView::cleanup
    86  */
    69  */
    87 void UT_CpTelephonyPluginView::cleanup()
    70 void UT_CpTelephonyPluginView::cleanup()
    88 {
    71 {
    89     reset();
    72     reset();
    90     
       
    91     delete m_callspluginview;
       
    92     m_callspluginview = NULL;
       
    93 }
    73 }
       
    74 
    94 
    75 
    95 /*!
    76 /*!
    96   UT_CpTelephonyPluginView::t_memleak
    77   UT_CpTelephonyPluginView::t_memleak
    97  */
    78  */
    98 void UT_CpTelephonyPluginView::t_memleak()
    79 void UT_CpTelephonyPluginView::t_memleak()
    99 {
    80 {
   100     QList<CpSettingFormItemData*> list;
    81     QList<CpSettingFormItemData*> list;
   101     list.append(new CpSettingFormItemData);
    82     list.append(new CpSettingFormItemData);
   102     DummyPlugin *ret = new DummyPlugin;
    83     DummyPlugin *ret = new DummyPlugin;
   103     expect("CpPluginLoader::loadCpPluginInterface").
    84 
   104             with(QString("cpcallsplugin")).returns(ret);
    85     HbDataForm *form = new HbDataForm;
   105     expect("DummyPlugin::createSettingFormItemData").returns(list);
    86     EXPECT(HbView, widget).returns(form);
   106     
    87 
   107     ret = new DummyPlugin;
    88     EXPECT(CpPluginLoader, loadCpPluginInterface).
   108     expect("CpPluginLoader::loadCpPluginInterface").
    89         with(QString("cpcallsplugin")).returns(ret); // Ownership change.
   109             with(QString("cpdivertplugin")).returns(ret);
    90     EXPECT(DummyPlugin, createSettingFormItemData).returns(list);
   110     expect("DummyPlugin::createSettingFormItemData").returns(list);
    91 
   111     
    92     // For clarity, create a new pointer instead of using the existing one. 
   112     
    93     DummyPlugin *dummy = new DummyPlugin;
       
    94     EXPECT(CpPluginLoader, loadCpPluginInterface).
       
    95         with(QString("cpdivertplugin")).returns(dummy); // Ownership change.
       
    96     EXPECT(DummyPlugin, createSettingFormItemData).returns(list);
       
    97 
       
    98     QModelIndex index;
       
    99     EXPECT(HbDataFormModel, indexFromItem).returns<QModelIndex>(index);
       
   100 
   113     CpTelephonyPluginView *tmp = new CpTelephonyPluginView;
   101     CpTelephonyPluginView *tmp = new CpTelephonyPluginView;
   114     QVERIFY( verify() );
   102     QVERIFY(verify());
   115     delete tmp;
   103     delete tmp;
       
   104     delete form;
       
   105 
       
   106     // Test constructor that doesn't call any other functions.
       
   107     EXPECT(HbView, widget).returns<QGraphicsWidget *>(0);
       
   108     CpTelephonyPluginView *tmp2 = new CpTelephonyPluginView;
       
   109     QVERIFY(verify());
       
   110     delete tmp2;
   116 }
   111 }
   117 
   112 
   118 
   113 
       
   114 void UT_CpTelephonyPluginView::t_construct2()
       
   115 {
       
   116     QVariantList list;
       
   117     list.append("blah");
       
   118     list.append("blaah");
       
   119 
       
   120     // Test constructor that doesn't call any other functions.
       
   121     EXPECT(HbView, widget).returns<QGraphicsWidget *>(0);
       
   122     CpTelephonyPluginView *tmp = new CpTelephonyPluginView(list);
       
   123     QVERIFY(verify());
       
   124     delete tmp;
       
   125 
       
   126     // Do the "real" test.
       
   127     QModelIndex index;
       
   128     HbDataForm *form = new HbDataForm;
       
   129     EXPECT(HbView, widget).returns(form);
       
   130 
       
   131     DummyPlugin *dummy = new DummyPlugin;
       
   132     EXPECT(CpPluginLoader, loadCpPluginInterface).
       
   133         with(QString("blaah")).returns(dummy); // Ownership change.
       
   134     QList<CpSettingFormItemData*> list2;
       
   135     list2.append(new CpSettingFormItemData);
       
   136     EXPECT(DummyPlugin, createSettingFormItemData).returns(list2);
       
   137 
       
   138     EXPECT(HbDataFormModel, indexFromItem).returns<QModelIndex>(index);
       
   139     CpTelephonyPluginView *tmp2 = new CpTelephonyPluginView(list);
       
   140     QVERIFY(verify());
       
   141     delete form;
       
   142     delete tmp2;
       
   143 }
       
   144 
   119 
   145 
   120 QTEST_MAIN_S60UI(UT_CpTelephonyPluginView)
   146 QTEST_MAIN_S60UI(UT_CpTelephonyPluginView)