phoneuis/bubblemanager2/tsrc/unit/ut_bubblepartlistmodel/ut_bubblepartlistmodel.cpp
changeset 22 6bb1b21d2484
parent 21 92ab7f8d0eab
child 51 f39ed5e045e0
equal deleted inserted replaced
21:92ab7f8d0eab 22:6bb1b21d2484
    29     Q_OBJECT
    29     Q_OBJECT
    30 
    30 
    31 private slots:
    31 private slots:
    32     void initTestCase();
    32     void initTestCase();
    33     void cleanupTestCase();
    33     void cleanupTestCase();
       
    34     void cleanupTest();
    34     
    35     
    35     void test_addParticipant();
    36     void test_addParticipant();
       
    37     void test_removeParticipant();
    36     void test_bubbleId();
    38     void test_bubbleId();
    37     void test_dataModel();
    39     void test_dataModel();
    38     void test_reset();
    40     void test_reset();
    39 
    41 
    40 private:
    42 private:
    49 void ut_BubbleParticipantListModel::cleanupTestCase()
    51 void ut_BubbleParticipantListModel::cleanupTestCase()
    50 {
    52 {
    51     delete mModel;
    53     delete mModel;
    52 }
    54 }
    53 
    55 
       
    56 void ut_BubbleParticipantListModel::cleanupTest()
       
    57 {
       
    58     mModel->reset();
       
    59 }
       
    60 
    54 void ut_BubbleParticipantListModel::test_addParticipant()
    61 void ut_BubbleParticipantListModel::test_addParticipant()
    55 {
    62 {
    56     mModel->addParticipant(1,"Bubble-1",8);
    63     QSignalSpy spyDataChanged(mModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)));
    57     mModel->addParticipant(2,"Bubble-2",9);
       
    58     mModel->addParticipant(3,"Bubble-3",10);
       
    59 
    64 
       
    65     mModel->addParticipant(1,"Bubble-1",8,true);
       
    66     mModel->addParticipant(2,"Bubble-2",9,false);
       
    67     mModel->addParticipant(3,"Bubble-3",10,true);
    60     QVERIFY(mModel->rowCount()==3);
    68     QVERIFY(mModel->rowCount()==3);
       
    69     QVERIFY(spyDataChanged.count()==0);
       
    70 
       
    71     // name changed
       
    72     mModel->addParticipant(2,"Bubble-Two",9,false);
       
    73     QVERIFY(mModel->rowCount()==3);
       
    74     QVERIFY(spyDataChanged.count()==1);
       
    75 
       
    76     // state changed
       
    77     mModel->addParticipant(2,"Bubble-Two",11,false);
       
    78     QVERIFY(mModel->rowCount()==3);
       
    79     QVERIFY(spyDataChanged.count()==2);
       
    80 
       
    81     // ciphering changed
       
    82     mModel->addParticipant(2,"Bubble-Two",11,true);
       
    83     QVERIFY(mModel->rowCount()==3);
       
    84     QVERIFY(spyDataChanged.count()==3);
       
    85 }
       
    86 
       
    87 void ut_BubbleParticipantListModel::test_removeParticipant()
       
    88 {
       
    89     mModel->addParticipant(1,"Bubble-1",8,true);
       
    90     mModel->addParticipant(2,"Bubble-2",9,false);
       
    91     mModel->addParticipant(3,"Bubble-3",10,true);
       
    92 
       
    93     mModel->removeParticipant(2);
       
    94     QVERIFY(mModel->rowCount()==2);
       
    95 
       
    96     mModel->removeParticipant(3);
       
    97     QVERIFY(mModel->rowCount()==1);
       
    98 
       
    99     mModel->addParticipant(2,"Bubble-2",9,false);
       
   100     QVERIFY(mModel->rowCount()==2);
    61 }
   101 }
    62 
   102 
    63 void ut_BubbleParticipantListModel::test_bubbleId()
   103 void ut_BubbleParticipantListModel::test_bubbleId()
    64 {
   104 {
       
   105     mModel->addParticipant(1,"Bubble-1",8,true);
       
   106     mModel->addParticipant(2,"Bubble-2",9,false);
       
   107     mModel->addParticipant(3,"Bubble-3",10,true);
       
   108 
    65     QVERIFY(mModel->bubbleId(1)==2);
   109     QVERIFY(mModel->bubbleId(1)==2);
    66     QVERIFY(mModel->bubbleId(4)==-1);
   110     QVERIFY(mModel->bubbleId(4)==-1);
    67 }
   111 }
    68 
   112 
    69 void ut_BubbleParticipantListModel::test_dataModel()
   113 void ut_BubbleParticipantListModel::test_dataModel()
    70 {
   114 {
       
   115     mModel->addParticipant(1,"Bubble-1",8,true);
       
   116     mModel->addParticipant(2,"Bubble-2",9,false);
       
   117     mModel->addParticipant(3,"Bubble-3",10,true);
       
   118 
    71     QModelIndex index = mModel->index(1,0);
   119     QModelIndex index = mModel->index(1,0);
    72 
   120 
    73     QVERIFY(index.data(Qt::DecorationRole).toInt()==9);
   121     QVERIFY(index.data(Qt::DecorationRole).toInt()==9);
    74     QVERIFY(index.data(Qt::DisplayRole).toString()=="Bubble-2");
   122     QVERIFY(index.data(Qt::DisplayRole).toString()=="Bubble-2");
       
   123     QVERIFY(index.data(Qt::StatusTipRole).toBool()==false);
    75     QVERIFY(index.data(Qt::UserRole).isNull());
   124     QVERIFY(index.data(Qt::UserRole).isNull());
       
   125 
       
   126     index = mModel->index(2,0);
       
   127     QVERIFY(index.data(Qt::StatusTipRole).toBool()==true);
    76 
   128 
    77     index = mModel->index(4,0);
   129     index = mModel->index(4,0);
    78     QVERIFY(index.data(Qt::DisplayRole).isNull());
   130     QVERIFY(index.data(Qt::DisplayRole).isNull());
    79 }
   131 }
    80 
   132