|
1 /*! |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <QtGui> |
|
19 #include <QtTest/QtTest> |
|
20 #include <hbapplication.h> |
|
21 #include <hbtextitem.h> |
|
22 #include <hbiconitem.h> |
|
23 |
|
24 #include "bubbletest.h" |
|
25 #include "bubbleparticipantlistmodel.h" |
|
26 |
|
27 class ut_BubbleParticipantListModel : public QObject |
|
28 { |
|
29 Q_OBJECT |
|
30 |
|
31 private slots: |
|
32 void initTestCase(); |
|
33 void cleanupTestCase(); |
|
34 void cleanupTest(); |
|
35 |
|
36 void test_addParticipant(); |
|
37 void test_removeParticipant(); |
|
38 void test_bubbleId(); |
|
39 void test_dataModel(); |
|
40 void test_reset(); |
|
41 |
|
42 private: |
|
43 BubbleParticipantListModel *mModel; |
|
44 }; |
|
45 |
|
46 void ut_BubbleParticipantListModel::initTestCase() |
|
47 { |
|
48 mModel = new BubbleParticipantListModel(); |
|
49 } |
|
50 |
|
51 void ut_BubbleParticipantListModel::cleanupTestCase() |
|
52 { |
|
53 delete mModel; |
|
54 } |
|
55 |
|
56 void ut_BubbleParticipantListModel::cleanupTest() |
|
57 { |
|
58 mModel->reset(); |
|
59 } |
|
60 |
|
61 void ut_BubbleParticipantListModel::test_addParticipant() |
|
62 { |
|
63 QSignalSpy spyDataChanged(mModel, SIGNAL(dataChanged(QModelIndex,QModelIndex))); |
|
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); |
|
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); |
|
101 } |
|
102 |
|
103 void ut_BubbleParticipantListModel::test_bubbleId() |
|
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 |
|
109 QVERIFY(mModel->bubbleId(1)==2); |
|
110 QVERIFY(mModel->bubbleId(4)==-1); |
|
111 } |
|
112 |
|
113 void ut_BubbleParticipantListModel::test_dataModel() |
|
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 |
|
119 QModelIndex index = mModel->index(1,0); |
|
120 |
|
121 QVERIFY(index.data(Qt::DecorationRole).toInt()==9); |
|
122 QVERIFY(index.data(Qt::DisplayRole).toString()=="Bubble-2"); |
|
123 QVERIFY(index.data(Qt::StatusTipRole).toBool()==false); |
|
124 QVERIFY(index.data(Qt::UserRole).isNull()); |
|
125 |
|
126 index = mModel->index(2,0); |
|
127 QVERIFY(index.data(Qt::StatusTipRole).toBool()==true); |
|
128 |
|
129 index = mModel->index(4,0); |
|
130 QVERIFY(index.data(Qt::DisplayRole).isNull()); |
|
131 } |
|
132 |
|
133 void ut_BubbleParticipantListModel::test_reset() |
|
134 { |
|
135 mModel->reset(); |
|
136 QVERIFY(mModel->rowCount()==0); |
|
137 } |
|
138 |
|
139 BUBBLE_TEST_MAIN(ut_BubbleParticipantListModel) |
|
140 #include "ut_bubblepartlistmodel.moc" |