9
|
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_logsremovestates.h"
|
|
18 |
#include "logsremovestates.h"
|
|
19 |
#include "logclient_stubs_helper.h"
|
|
20 |
#include "logsmodel.h"
|
|
21 |
#include <logcli.h>
|
|
22 |
#include <logview.h>
|
|
23 |
|
|
24 |
#include <QtTest/QtTest>
|
|
25 |
|
|
26 |
void UT_LogsRemoveStates::initTestCase()
|
|
27 |
{
|
|
28 |
int rfsDummy = 0;
|
|
29 |
mLogClient = CLogClient::NewL( *((RFs*)&rfsDummy) );
|
|
30 |
}
|
|
31 |
|
|
32 |
void UT_LogsRemoveStates::cleanupTestCase()
|
|
33 |
{
|
|
34 |
delete mLogClient;
|
|
35 |
}
|
|
36 |
|
|
37 |
|
|
38 |
void UT_LogsRemoveStates::init()
|
|
39 |
{
|
|
40 |
reset();
|
|
41 |
|
|
42 |
mCurrentState = 0;
|
|
43 |
mIndex = 0;
|
|
44 |
mLogView = 0;
|
|
45 |
mLogViewEvent = 0;
|
|
46 |
mIsRecentView = true;
|
|
47 |
|
|
48 |
mLogView = CLogViewRecent::NewL(*mLogClient);
|
|
49 |
mLogViewEvent = 0;
|
|
50 |
mDuplicatesView = CLogViewDuplicate::NewL(*mLogClient);
|
|
51 |
}
|
|
52 |
|
|
53 |
void UT_LogsRemoveStates::cleanup()
|
|
54 |
{
|
|
55 |
delete mLogView;
|
|
56 |
mLogView = 0;
|
|
57 |
delete mLogViewEvent;
|
|
58 |
mLogViewEvent = 0;
|
|
59 |
delete mDuplicatesView;
|
|
60 |
mDuplicatesView = 0;
|
|
61 |
}
|
|
62 |
|
|
63 |
void UT_LogsRemoveStates::reset()
|
|
64 |
{
|
|
65 |
mRemoveCompleted = false;
|
|
66 |
mClearType = -1;
|
|
67 |
mRemovedEvents.clear();
|
|
68 |
}
|
|
69 |
|
|
70 |
void UT_LogsRemoveStates::testClearAll()
|
|
71 |
{
|
|
72 |
LogsRemoveStateClearAll state(*this, *this);
|
|
73 |
mClearType = LogsModel::TypeLogsClearAll;
|
|
74 |
QVERIFY( state.enterL() );
|
|
75 |
QCOMPARE( LogClientStubsHelper::lastCalledFunc(), QString("ClearLog") );
|
|
76 |
|
|
77 |
mClearType = LogsModel::TypeLogsClearMissed;
|
|
78 |
QVERIFY( state.enterL() );
|
|
79 |
QCOMPARE( LogClientStubsHelper::lastCalledFunc(), QString("ClearLogRecentList") );
|
|
80 |
|
|
81 |
QVERIFY( !state.continueL() );
|
|
82 |
}
|
|
83 |
|
|
84 |
void UT_LogsRemoveStates::testInit()
|
|
85 |
{
|
|
86 |
LogsRemoveStateInit state(*this, *this);
|
|
87 |
|
|
88 |
// Nothing happens when no recent view exists
|
|
89 |
mIsRecentView = false;
|
|
90 |
QVERIFY( !state.enterL() );
|
|
91 |
|
|
92 |
// Recent view exists and is getting initialized
|
|
93 |
mIndex = 4;
|
|
94 |
mIsRecentView = true;
|
|
95 |
QVERIFY( state.enterL() );
|
|
96 |
QCOMPARE( mIndex, 0 );
|
|
97 |
|
|
98 |
QVERIFY( !state.continueL() );
|
|
99 |
}
|
|
100 |
|
|
101 |
void UT_LogsRemoveStates::testDelete()
|
|
102 |
{
|
|
103 |
LogsRemoveStateDelete state(*this, *this);
|
|
104 |
|
|
105 |
// Nothing to delete
|
|
106 |
QVERIFY( !state.enterL() );
|
|
107 |
|
|
108 |
// Delete several
|
|
109 |
mRemovedEvents.append(1);
|
|
110 |
mRemovedEvents.append(3);
|
|
111 |
mRemovedEvents.append(4);
|
|
112 |
|
|
113 |
QVERIFY( state.enterL() );
|
|
114 |
QCOMPARE( state.mRemoveIndex, 1 );
|
|
115 |
QVERIFY( state.continueL() );
|
|
116 |
QCOMPARE( state.mRemoveIndex, 2 );
|
|
117 |
QVERIFY( state.continueL() );
|
|
118 |
QCOMPARE( state.mRemoveIndex, 3 );
|
|
119 |
QVERIFY( !state.continueL() );
|
|
120 |
}
|
|
121 |
|
|
122 |
void UT_LogsRemoveStates::testDeleteDuplicates()
|
|
123 |
{
|
|
124 |
LogsRemoveStateDeleteDuplicates state(*this, *this);
|
|
125 |
|
|
126 |
// More than one id, duplicate deletion not supported
|
|
127 |
mRemovedEvents.append(1);
|
|
128 |
mRemovedEvents.append(3);
|
|
129 |
QVERIFY( !state.enterL() );
|
|
130 |
|
|
131 |
// Dbview iterator is not at correct location
|
|
132 |
mRemovedEvents.clear();
|
|
133 |
mRemovedEvents.append(99);
|
|
134 |
const_cast<CLogEvent&>( mLogView->Event() ).SetId( 100 );
|
|
135 |
QVERIFY( !state.enterL() );
|
|
136 |
|
|
137 |
// No duplicates
|
|
138 |
LogClientStubsHelper::setStubAsyncCallPossible(false);
|
|
139 |
LogClientStubsHelper::setViewCount(0); // effective also for duplicates view
|
|
140 |
const_cast<CLogEvent&>( mLogView->Event() ).SetId( 99 );
|
|
141 |
QVERIFY( !state.enterL() );
|
|
142 |
|
|
143 |
// Duplicates
|
|
144 |
LogClientStubsHelper::setStubAsyncCallPossible(true);
|
|
145 |
LogClientStubsHelper::setViewCount(3); // effective also for duplicates view
|
|
146 |
QVERIFY( state.enterL() );
|
|
147 |
QVERIFY( !state.mDeleting );
|
|
148 |
QCOMPARE( state.mDeleteDuplicateIds.count(), 0 );
|
|
149 |
|
|
150 |
QVERIFY( state.continueL() );
|
|
151 |
QVERIFY( !state.mDeleting );
|
|
152 |
QCOMPARE( state.mDeleteDuplicateIds.count(), 0 );
|
|
153 |
QVERIFY( state.continueL() );
|
|
154 |
QVERIFY( !state.mDeleting );
|
|
155 |
QCOMPARE( state.mDeleteDuplicateIds.count(), 1 );
|
|
156 |
QVERIFY( state.continueL() );
|
|
157 |
QVERIFY( !state.mDeleting );
|
|
158 |
QCOMPARE( state.mDeleteDuplicateIds.count(), 2 );
|
|
159 |
QVERIFY( state.continueL() );
|
|
160 |
QVERIFY( !state.mDeleting );
|
|
161 |
QCOMPARE( state.mDeleteDuplicateIds.count(), 3 );
|
|
162 |
|
|
163 |
QVERIFY( state.continueL() );
|
|
164 |
QVERIFY( state.mDeleting );
|
|
165 |
QCOMPARE( state.mDeleteDuplicateIds.count(), 2 );
|
|
166 |
QVERIFY( state.continueL() );
|
|
167 |
QVERIFY( state.mDeleting );
|
|
168 |
QCOMPARE( state.mDeleteDuplicateIds.count(), 1 );
|
|
169 |
QVERIFY( state.continueL() );
|
|
170 |
QVERIFY( state.mDeleting );
|
|
171 |
QCOMPARE( state.mDeleteDuplicateIds.count(), 0 );
|
|
172 |
QVERIFY( !state.continueL() );
|
|
173 |
|
|
174 |
}
|
|
175 |
|
|
176 |
void UT_LogsRemoveStates::testDone()
|
|
177 |
{
|
|
178 |
LogsRemoveStateDone state(*this, *this);
|
|
179 |
QVERIFY( !mRemoveCompleted );
|
|
180 |
QVERIFY( !state.enterL() );
|
|
181 |
QVERIFY( mRemoveCompleted );
|
|
182 |
}
|
|
183 |
|
|
184 |
// ----------------------------------------------------------------------------
|
|
185 |
// From LogsStateBaseContext
|
|
186 |
// ----------------------------------------------------------------------------
|
|
187 |
//
|
|
188 |
void UT_LogsRemoveStates::setCurrentState(const LogsStateBase& state)
|
|
189 |
{
|
|
190 |
mCurrentState = &state;
|
|
191 |
}
|
|
192 |
|
|
193 |
CLogView& UT_LogsRemoveStates::logView()
|
|
194 |
{
|
|
195 |
if ( mIsRecentView ){
|
|
196 |
return *mLogView;
|
|
197 |
}
|
|
198 |
return *mLogViewEvent;
|
|
199 |
}
|
|
200 |
|
|
201 |
CLogViewDuplicate& UT_LogsRemoveStates::duplicatesView()
|
|
202 |
{
|
|
203 |
return *mDuplicatesView;
|
|
204 |
}
|
|
205 |
|
|
206 |
int& UT_LogsRemoveStates::index()
|
|
207 |
{
|
|
208 |
return mIndex;
|
|
209 |
}
|
|
210 |
|
|
211 |
TRequestStatus& UT_LogsRemoveStates::reqStatus()
|
|
212 |
{
|
|
213 |
return mReqStatus;
|
|
214 |
}
|
|
215 |
|
|
216 |
|
|
217 |
int UT_LogsRemoveStates::currentEventId()
|
|
218 |
{
|
|
219 |
if ( !mRemovedEvents.isEmpty() ){
|
|
220 |
return mRemovedEvents.at(0);
|
|
221 |
}
|
|
222 |
return mCurrentEventId;
|
|
223 |
}
|
|
224 |
|
|
225 |
CLogClient& UT_LogsRemoveStates::logClient()
|
|
226 |
{
|
|
227 |
return *mLogClient;
|
|
228 |
}
|
|
229 |
|
|
230 |
bool UT_LogsRemoveStates::isRecentView()
|
|
231 |
{
|
|
232 |
return mIsRecentView;
|
|
233 |
}
|
|
234 |
|
|
235 |
|
|
236 |
// ----------------------------------------------------------------------------
|
|
237 |
// From LogsRemoveStateContext
|
|
238 |
// ----------------------------------------------------------------------------
|
|
239 |
//
|
|
240 |
|
|
241 |
LogsRemoveObserver& UT_LogsRemoveStates::observer()
|
|
242 |
{
|
|
243 |
return *this;
|
|
244 |
}
|
|
245 |
QList<int>& UT_LogsRemoveStates::removedEvents()
|
|
246 |
{
|
|
247 |
return mRemovedEvents;
|
|
248 |
}
|
|
249 |
int UT_LogsRemoveStates::clearType()
|
|
250 |
{
|
|
251 |
return mClearType;
|
|
252 |
}
|
|
253 |
|
|
254 |
// ----------------------------------------------------------------------------
|
|
255 |
// From LogsRemoveObserver
|
|
256 |
// ----------------------------------------------------------------------------
|
|
257 |
//
|
|
258 |
void UT_LogsRemoveStates::removeCompleted()
|
|
259 |
{
|
|
260 |
mRemoveCompleted = true;
|
|
261 |
}
|
|
262 |
void UT_LogsRemoveStates::logsRemoveErrorOccured(int err)
|
|
263 |
{
|
|
264 |
mError = err;
|
|
265 |
}
|