|
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 #include "ut_logscustomfilter.h" |
|
18 #include "logscustomfilter.h" |
|
19 #include "logsmodel.h" |
|
20 #include "logsevent.h" |
|
21 #include "logseventdata.h" |
|
22 #include <QStringListModel> |
|
23 |
|
24 #include <QtTest/QtTest> |
|
25 |
|
26 void UT_LogsCustomFilter::initTestCase() |
|
27 { |
|
28 mFilter = new LogsCustomFilter; |
|
29 } |
|
30 |
|
31 void UT_LogsCustomFilter::cleanupTestCase() |
|
32 { |
|
33 delete mFilter; |
|
34 mFilter = 0; |
|
35 } |
|
36 |
|
37 |
|
38 void UT_LogsCustomFilter::init() |
|
39 { |
|
40 |
|
41 } |
|
42 |
|
43 void UT_LogsCustomFilter::cleanup() |
|
44 { |
|
45 |
|
46 } |
|
47 |
|
48 void UT_LogsCustomFilter::testConstructor() |
|
49 { |
|
50 QVERIFY( mFilter ); |
|
51 } |
|
52 |
|
53 void UT_LogsCustomFilter::testFilterAcceptsRow() |
|
54 { |
|
55 // No source model |
|
56 QVERIFY( mFilter->filterAcceptsRow(0, QModelIndex()) == false ); |
|
57 |
|
58 LogsModel* logsModel = new LogsModel(LogsModel::LogsFullModel); |
|
59 mFilter->setSourceModel(logsModel); |
|
60 |
|
61 // No any events |
|
62 QVERIFY( mFilter->filterAcceptsRow(0, QModelIndex()) == false ); |
|
63 |
|
64 // No search term |
|
65 LogsEvent* event = new LogsEvent; |
|
66 logsModel->mEvents.append(event); |
|
67 QVERIFY( mFilter->filterAcceptsRow(0, QModelIndex()) == false ); |
|
68 |
|
69 // Search term but no matching event |
|
70 mFilter->setContactId(50); |
|
71 QVERIFY( mFilter->filterAcceptsRow(0, QModelIndex()) == false ); |
|
72 |
|
73 // Search term and matching event |
|
74 LogsEvent* event2 = new LogsEvent; |
|
75 LogsEventData* eventData = new LogsEventData; |
|
76 eventData->setContactLocalId(50); |
|
77 event2->setLogsEventData(eventData); |
|
78 logsModel->mEvents.append(event2); |
|
79 QVERIFY( mFilter->filterAcceptsRow(0, QModelIndex()) == false ); |
|
80 QVERIFY( mFilter->filterAcceptsRow(1, QModelIndex()) == true ); |
|
81 |
|
82 mFilter->setSourceModel(0); |
|
83 delete logsModel; |
|
84 } |
|
85 |
|
86 void UT_LogsCustomFilter::testClearEvents() |
|
87 { |
|
88 // No source model |
|
89 mFilter->setSourceModel(0); |
|
90 QVERIFY( !mFilter->clearEvents() ); |
|
91 |
|
92 // Wrong type of source model |
|
93 QStringListModel wrongModel; |
|
94 mFilter->setSourceModel(&wrongModel); |
|
95 QVERIFY( !mFilter->clearEvents() ); |
|
96 |
|
97 // Nothing to clear |
|
98 LogsModel* logsModel = new LogsModel(LogsModel::LogsFullModel); |
|
99 mFilter->setSourceModel(logsModel); |
|
100 QVERIFY( !mFilter->clearEvents() ); |
|
101 |
|
102 // Something to clear |
|
103 LogsEvent* event2 = new LogsEvent; |
|
104 LogsEventData* eventData = new LogsEventData; |
|
105 eventData->setContactLocalId(50); |
|
106 event2->setLogsEventData(eventData); |
|
107 logsModel->mEvents.append(event2); |
|
108 mFilter->setSourceModel(0); |
|
109 mFilter->setSourceModel(logsModel); |
|
110 QVERIFY( mFilter->clearEvents() ); |
|
111 } |
|
112 |
|
113 void UT_LogsCustomFilter::testMarkEventsSeen() |
|
114 { |
|
115 // No source model |
|
116 mFilter->setSourceModel(0); |
|
117 QVERIFY( !mFilter->markEventsSeen() ); |
|
118 |
|
119 // Wrong type of source model |
|
120 QStringListModel wrongModel; |
|
121 mFilter->setSourceModel(&wrongModel); |
|
122 QVERIFY( !mFilter->markEventsSeen() ); |
|
123 |
|
124 // Nothing to clear |
|
125 LogsModel* logsModel = new LogsModel(LogsModel::LogsFullModel); |
|
126 mFilter->setSourceModel(logsModel); |
|
127 QVERIFY( !mFilter->markEventsSeen() ); |
|
128 |
|
129 // Something to clear |
|
130 LogsEvent* event2 = new LogsEvent; |
|
131 LogsEventData* eventData = new LogsEventData; |
|
132 eventData->setContactLocalId(50); |
|
133 event2->setLogsEventData(eventData); |
|
134 logsModel->mEvents.append(event2); |
|
135 mFilter->setSourceModel(0); |
|
136 mFilter->setSourceModel(logsModel); |
|
137 QVERIFY( mFilter->markEventsSeen() ); |
|
138 |
|
139 // Clearing for the event already ongoing, don't try again |
|
140 event2->markedAsSeenLocally(true); |
|
141 QVERIFY( !mFilter->markEventsSeen() ); |
|
142 } |
|
143 |
|
144 |