1 /* |
|
2 * Copyright (c) 2010 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: mylocations database manager unit test cases |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <QtTest/QtTest> |
|
19 #include <QtGui> |
|
20 #include <QString> |
|
21 |
|
22 #include <mylocationsdatabasemanager.h> |
|
23 #include <locationservicedefines.h> |
|
24 #include <EPos_CPosLandmark.h> |
|
25 #include <lbsposition.h> |
|
26 |
|
27 |
|
28 //Lookup db test interface class |
|
29 class CMyLocationsDatabaseManagerTest: public QObject |
|
30 { |
|
31 Q_OBJECT |
|
32 |
|
33 private slots: |
|
34 |
|
35 void testCase1(); |
|
36 void testCase2(); |
|
37 void testCase3(); |
|
38 void testCase4(); |
|
39 }; |
|
40 |
|
41 |
|
42 //Tests basic construction and destruction |
|
43 void CMyLocationsDatabaseManagerTest::testCase1() |
|
44 { |
|
45 // tests just new and delete operation. |
|
46 CMyLocationsDatabaseManager* dbm = new CMyLocationsDatabaseManager(); |
|
47 QVERIFY( dbm != NULL ); |
|
48 delete dbm; |
|
49 dbm = NULL; |
|
50 |
|
51 // tests ConstructL() |
|
52 dbm = new CMyLocationsDatabaseManager(); |
|
53 dbm->ConstructL(); |
|
54 QVERIFY( dbm->iLocationAppLookupDb != NULL ); |
|
55 delete dbm; |
|
56 } |
|
57 |
|
58 //Tests UpdateDatabaseL() |
|
59 void CMyLocationsDatabaseManagerTest::testCase2() |
|
60 { |
|
61 // tests just new and delete operation. |
|
62 CMyLocationsDatabaseManager* dbm = new CMyLocationsDatabaseManager(); |
|
63 QVERIFY( dbm != NULL ); |
|
64 dbm->ConstructL(); |
|
65 |
|
66 CPosLandmark* lm = CPosLandmark::NewL(); |
|
67 lm->SetLandmarkNameL(_L("John")); |
|
68 lm->SetPositionFieldL( EPositionFieldStreet, _L("MG Road") ); |
|
69 TLocality loc( TCoordinate( 0.1, 0.2 ), 0 ); |
|
70 lm->SetPositionL(loc); |
|
71 |
|
72 // test add |
|
73 dbm->UpdateDatabaseL( lm, 1, ESourceContactsPref, EEntryAdded ); |
|
74 QLookupItem item; |
|
75 item.mSourceType = ESourceContactsPref; |
|
76 item.mSourceUid = 1; |
|
77 bool flag = dbm->iLocationAppLookupDb->findEntryBySourceIdAndType( item ); |
|
78 QVERIFY( flag == true ); |
|
79 QVERIFY( item.mStreet == "MG Road" ); |
|
80 |
|
81 // test modify |
|
82 lm->SetPositionFieldL( EPositionFieldStreet, _L("Brigade Road") ); |
|
83 dbm->UpdateDatabaseL( lm, 1, ESourceContactsPref, EEntryModified ); |
|
84 flag = dbm->iLocationAppLookupDb->findEntryBySourceIdAndType( item ); |
|
85 QVERIFY( flag == true ); |
|
86 QVERIFY( item.mStreet == "Brigade Road" ); |
|
87 |
|
88 dbm->UpdateDatabaseL( lm, 1, ESourceContactsPref, EEntryModified ); |
|
89 flag = dbm->iLocationAppLookupDb->findEntryBySourceIdAndType( item ); |
|
90 QVERIFY( flag == true ); |
|
91 QVERIFY( item.mStreet == "Brigade Road" ); |
|
92 |
|
93 // test delete |
|
94 dbm->UpdateDatabaseL( NULL, 1, ESourceContactsPref, EEntryDeleted ); |
|
95 flag = dbm->iLocationAppLookupDb->findEntryBySourceIdAndType( item ); |
|
96 QVERIFY( flag == false ); |
|
97 |
|
98 // check invalid |
|
99 dbm->UpdateDatabaseL( NULL, 1, ESourceContactsPref, EEntryUnknown ); |
|
100 flag = dbm->iLocationAppLookupDb->findEntryBySourceIdAndType( item ); |
|
101 QVERIFY( flag == false ); |
|
102 |
|
103 delete lm; |
|
104 delete dbm; |
|
105 } |
|
106 |
|
107 //Tests GetLandmarkFullAddress() and FillLookupItemAddressDetails() |
|
108 void CMyLocationsDatabaseManagerTest::testCase3() |
|
109 { |
|
110 CMyLocationsDatabaseManager* dbm = new CMyLocationsDatabaseManager(); |
|
111 dbm->ConstructL(); |
|
112 QVERIFY( dbm->iLocationAppLookupDb != NULL ); |
|
113 |
|
114 QLookupItem item; |
|
115 |
|
116 CPosLandmark* lm = CPosLandmark::NewL(); |
|
117 TBuf<255> buff; |
|
118 dbm->GetLandmarkFullAddress( buff, lm ); |
|
119 QString str1 = QString( (QChar*)buff.Ptr(), buff.Length()); |
|
120 QVERIFY( str1 == "" ); |
|
121 |
|
122 dbm->FillLookupItemAddressDetails( lm, item ); |
|
123 QVERIFY( item.mName == "" ); |
|
124 QVERIFY( item.mStreet == "" ); |
|
125 QVERIFY( item.mPostalCode == "" ); |
|
126 QVERIFY( item.mCity == "" ); |
|
127 QVERIFY( item.mState == "" ); |
|
128 QVERIFY( item.mCountry == "" ); |
|
129 |
|
130 lm->SetLandmarkNameL( _L("name") ); |
|
131 lm->SetPositionFieldL( EPositionFieldCountry, _L("india") ); |
|
132 dbm->GetLandmarkFullAddress( buff, lm ); |
|
133 str1 = QString( (QChar*)buff.Ptr(), buff.Length()); |
|
134 QVERIFY( str1 == "india" ); |
|
135 dbm->FillLookupItemAddressDetails( lm, item ); |
|
136 QVERIFY( item.mName == "name" ); |
|
137 QVERIFY( item.mCountry == "india" ); |
|
138 |
|
139 lm->SetPositionFieldL( EPositionFieldState, _L("kar") ); |
|
140 dbm->GetLandmarkFullAddress( buff, lm ); |
|
141 str1 = QString( (QChar*)buff.Ptr(), buff.Length()); |
|
142 QVERIFY( str1 == "kar, india" ); |
|
143 dbm->FillLookupItemAddressDetails( lm, item ); |
|
144 QVERIFY( item.mState == "kar" ); |
|
145 |
|
146 lm->SetPositionFieldL( EPositionFieldCity, _L("blr") ); |
|
147 dbm->GetLandmarkFullAddress( buff, lm ); |
|
148 str1 = QString( (QChar*)buff.Ptr(), buff.Length()); |
|
149 QVERIFY( str1 == "blr, kar, india" ); |
|
150 dbm->FillLookupItemAddressDetails( lm, item ); |
|
151 QVERIFY( item.mCity == "blr" ); |
|
152 |
|
153 lm->SetPositionFieldL( EPositionFieldPostalCode, _L("postalcode") ); |
|
154 lm->SetPositionFieldL( EPositionFieldStreet, _L("mg road") ); |
|
155 dbm->GetLandmarkFullAddress( buff, lm ); |
|
156 str1 = QString( (QChar*)buff.Ptr(), buff.Length()); |
|
157 QVERIFY( str1 == "mg road, blr, kar, india" ); |
|
158 dbm->FillLookupItemAddressDetails( lm, item ); |
|
159 QVERIFY( item.mPostalCode == "postalcode" ); |
|
160 QVERIFY( item.mStreet == "mg road" ); |
|
161 |
|
162 lm->SetLandmarkNameL(_L("")); |
|
163 lm->SetPositionFieldL( EPositionFieldStreet, _L("") ); |
|
164 lm->SetPositionFieldL( EPositionFieldPostalCode, _L("") ); |
|
165 lm->SetPositionFieldL( EPositionFieldCity, _L("") ); |
|
166 lm->SetPositionFieldL( EPositionFieldState, _L("") ); |
|
167 lm->SetPositionFieldL( EPositionFieldCountry, _L("") ); |
|
168 dbm->GetLandmarkFullAddress( buff, lm ); |
|
169 str1 = QString( (QChar*)buff.Ptr(), buff.Length()); |
|
170 dbm->FillLookupItemAddressDetails( lm, item ); |
|
171 QVERIFY( str1 == "" ); |
|
172 QVERIFY( item.mName == "" ); |
|
173 QVERIFY( item.mStreet == "" ); |
|
174 QVERIFY( item.mPostalCode == "" ); |
|
175 QVERIFY( item.mCity == "" ); |
|
176 QVERIFY( item.mState == "" ); |
|
177 QVERIFY( item.mCountry == "" ); |
|
178 |
|
179 delete lm; |
|
180 delete dbm; |
|
181 } |
|
182 |
|
183 //Tests UpdateMapTilePath() |
|
184 void CMyLocationsDatabaseManagerTest::testCase4() |
|
185 { |
|
186 // tests just new and delete operation. |
|
187 CMyLocationsDatabaseManager* dbm = new CMyLocationsDatabaseManager(); |
|
188 dbm->ConstructL(); |
|
189 QVERIFY( dbm->iLocationAppLookupDb != NULL ); |
|
190 |
|
191 QLookupItem item; |
|
192 item.mSourceType = ESourceCalendar; |
|
193 item.mSourceUid = 1; |
|
194 dbm->iLocationAppLookupDb->createEntry( item ); |
|
195 dbm->UpdateMapTilePath( item.mSourceUid, item.mSourceType, _L("maptile.png") ); |
|
196 dbm->iLocationAppLookupDb->findEntryBySourceIdAndType( item ); |
|
197 |
|
198 QVERIFY( item.mMapTilePath == "maptile.png" ); |
|
199 |
|
200 dbm->iLocationAppLookupDb->deleteEntryBySourceIdAndType( item ); |
|
201 delete dbm; |
|
202 } |
|
203 |
|
204 QTEST_MAIN(CMyLocationsDatabaseManagerTest) |
|
205 #include "ut_mylocationsdatabasemanager.moc" |
|
206 |
|
207 |
|