|
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 |
|
19 #include "ut_logsduplicatelookup.h" |
|
20 #include "logsduplicatelookup.h" |
|
21 #include "logsevent.h" |
|
22 #include <QtTest/QtTest> |
|
23 |
|
24 QString testDir1key1 = "remote1/t1111"; |
|
25 QString testDir1key2 = "remote2/t1111"; |
|
26 |
|
27 QString testDir2key1 = "remote1/t2222"; |
|
28 |
|
29 QString testDir3key1 = "remote1/t3333"; |
|
30 QString testDir3key2 = "remote2/t3333"; |
|
31 QString testDir3key3 = "remote3/t3333"; |
|
32 |
|
33 |
|
34 void UT_LogsDuplicateLookup::initTestCase() |
|
35 { |
|
36 mLookup = new LogsDuplicateLookup(); |
|
37 } |
|
38 |
|
39 void UT_LogsDuplicateLookup::cleanupTestCase() |
|
40 { |
|
41 delete mLookup; |
|
42 mLookup = NULL; |
|
43 } |
|
44 |
|
45 void UT_LogsDuplicateLookup::init() |
|
46 { |
|
47 } |
|
48 |
|
49 void UT_LogsDuplicateLookup::cleanup() |
|
50 { |
|
51 } |
|
52 |
|
53 void UT_LogsDuplicateLookup::testConstructor() |
|
54 { |
|
55 QVERIFY( mLookup ); |
|
56 QCOMPARE( mLookup->mDirectionLookupTables.count(), 3 ); |
|
57 } |
|
58 |
|
59 void UT_LogsDuplicateLookup::testInvalidate() |
|
60 { |
|
61 createTestData(); |
|
62 LogsEvent ev1; |
|
63 mLookup->mDirectionLookupTables.at(1)->find(testDir2key1).value() = &ev1; |
|
64 LogsEvent ev2; |
|
65 mLookup->mDirectionLookupTables.at(2)->find(testDir3key2).value() = &ev2; |
|
66 mLookup->invalidate(); |
|
67 QVERIFY( mLookup->mDirectionLookupTables.at(0)->find(testDir1key1).value() == 0 ); |
|
68 QVERIFY( mLookup->mDirectionLookupTables.at(1)->find(testDir2key1).value() == 0 ); |
|
69 QVERIFY( mLookup->mDirectionLookupTables.at(2)->find(testDir3key2).value() == 0 ); |
|
70 |
|
71 } |
|
72 void UT_LogsDuplicateLookup::testCleanup() |
|
73 { |
|
74 createTestData(); |
|
75 |
|
76 // All expect one with value are cleared |
|
77 QCOMPARE( mLookup->mDirectionLookupTables.at(0)->count(), 2 ); |
|
78 QCOMPARE( mLookup->mDirectionLookupTables.at(1)->count(), 1 ); |
|
79 QCOMPARE( mLookup->mDirectionLookupTables.at(2)->count(), 3 ); |
|
80 |
|
81 LogsEvent ev1; |
|
82 mLookup->mDirectionLookupTables.at(2)->find(testDir3key2).value() = &ev1; |
|
83 mLookup->cleanup(); |
|
84 QCOMPARE( mLookup->mDirectionLookupTables.at(0)->count(), 0 ); |
|
85 QCOMPARE( mLookup->mDirectionLookupTables.at(1)->count(), 0 ); |
|
86 QCOMPARE( mLookup->mDirectionLookupTables.at(2)->count(), 1 ); |
|
87 QVERIFY( mLookup->mDirectionLookupTables.at(2)->find(testDir3key2).value() == &ev1 ); |
|
88 |
|
89 } |
|
90 void UT_LogsDuplicateLookup::testAddLookupEntry() |
|
91 { |
|
92 // Event does not have remote name |
|
93 LogsEvent ev; |
|
94 ev.setLogId(100); |
|
95 QVERIFY( mLookup->addLookupEntry(ev) == -1 ); |
|
96 |
|
97 // Event contains wrong direction |
|
98 ev.setRemoteParty("remote1"); |
|
99 ev.setNumber("1234"); |
|
100 QVERIFY( mLookup->addLookupEntry(ev) == -1 ); |
|
101 |
|
102 // No key yet for the event, key is generated from remote name and number |
|
103 ev.setDirection(LogsEvent::DirIn); |
|
104 QVERIFY( mLookup->addLookupEntry(ev) == 0 ); |
|
105 QVERIFY( mLookup->mDirectionLookupTables.at(LogsEvent::DirIn)->find( "remote1/t1234" ).value() == &ev ); |
|
106 |
|
107 // Several keys exists and value for matching key exists, value not changed |
|
108 createTestData(); |
|
109 QVERIFY( mLookup->addLookupEntry(ev) == 0 ); |
|
110 LogsEvent ev2; |
|
111 ev2.setDirection(LogsEvent::DirIn); |
|
112 ev2.setRemoteParty("remote1"); |
|
113 ev2.setNumber("1234"); |
|
114 ev2.setLogId(200); |
|
115 QVERIFY( mLookup->addLookupEntry(ev2) == 0 ); |
|
116 QVERIFY( mLookup->mDirectionLookupTables.at(LogsEvent::DirIn)->find( "remote1/t1234" ).value() == &ev ); |
|
117 |
|
118 // This direction entry does not exists, entry is added |
|
119 ev2.setDirection(LogsEvent::DirOut); |
|
120 QVERIFY( mLookup->addLookupEntry(ev2) == 0 ); |
|
121 QVERIFY( mLookup->mDirectionLookupTables.at(LogsEvent::DirOut)->find( "remote1/t1234" ).value() == &ev2 ); |
|
122 |
|
123 // Several keys exists and no value for matching key, value is set |
|
124 mLookup->mDirectionLookupTables.at(LogsEvent::DirIn)->find( "remote1/t1234" ).value() = 0; |
|
125 ev2.setDirection(LogsEvent::DirIn); |
|
126 QVERIFY( mLookup->addLookupEntry(ev2) == 0 ); |
|
127 QVERIFY( mLookup->mDirectionLookupTables.at(LogsEvent::DirIn)->find( "remote1/t1234" ).value() == &ev2 ); |
|
128 } |
|
129 void UT_LogsDuplicateLookup::testFindDuplicate() |
|
130 { |
|
131 // Not valid search term |
|
132 LogsEvent ev; |
|
133 ev.setLogId(100); |
|
134 QVERIFY( mLookup->findDuplicate(ev) == 0 ); |
|
135 |
|
136 createTestData(); |
|
137 LogsEvent ev1; |
|
138 mLookup->mDirectionLookupTables.at(2)->find(testDir3key2).value() = &ev1; |
|
139 LogsEvent ev2; |
|
140 mLookup->mDirectionLookupTables.at(2)->find(testDir3key3).value() = &ev2; |
|
141 LogsEvent searchTerm; |
|
142 searchTerm.setDirection(LogsEvent::DirIn); |
|
143 searchTerm.setRemoteParty("remote1"); |
|
144 searchTerm.setNumber("1111"); |
|
145 QVERIFY( mLookup->findDuplicate(searchTerm) == 0 ); |
|
146 |
|
147 searchTerm.setDirection(LogsEvent::DirMissed); |
|
148 searchTerm.setRemoteParty("remote2"); |
|
149 searchTerm.setNumber("3333"); |
|
150 QVERIFY( mLookup->findDuplicate(searchTerm) == &ev1 ); |
|
151 |
|
152 searchTerm.setRemoteParty("remote3"); |
|
153 QVERIFY( mLookup->findDuplicate(searchTerm) == &ev2 ); |
|
154 |
|
155 // Check that duplicate lookup works with international format also |
|
156 LogsEvent ev5; |
|
157 ev5.setDirection(LogsEvent::DirOut); |
|
158 ev5.setRemoteParty("remote2"); |
|
159 ev5.setNumber("+358504443333"); |
|
160 mLookup->addLookupEntry(ev5); |
|
161 LogsEvent searchTerm2; |
|
162 searchTerm2.setDirection(LogsEvent::DirOut); |
|
163 searchTerm2.setRemoteParty("remote2"); |
|
164 searchTerm2.setNumber("0504443333"); |
|
165 QVERIFY( mLookup->findDuplicate(searchTerm2) == &ev5 ); |
|
166 |
|
167 } |
|
168 |
|
169 void UT_LogsDuplicateLookup::createTestData() |
|
170 { |
|
171 foreach( LogsLookupHash* dir, mLookup->mDirectionLookupTables ){ |
|
172 dir->clear(); |
|
173 } |
|
174 mLookup->mDirectionLookupTables.at(0)->insert(testDir1key1, 0); |
|
175 mLookup->mDirectionLookupTables.at(0)->insert(testDir1key2, 0); |
|
176 |
|
177 mLookup->mDirectionLookupTables.at(1)->insert(testDir2key1, 0); |
|
178 |
|
179 mLookup->mDirectionLookupTables.at(2)->insert(testDir3key1, 0); |
|
180 mLookup->mDirectionLookupTables.at(2)->insert(testDir3key2, 0); |
|
181 mLookup->mDirectionLookupTables.at(2)->insert(testDir3key3, 0); |
|
182 } |