9 * Initial Contributors: |
9 * Initial Contributors: |
10 * Nokia Corporation - initial contribution. |
10 * Nokia Corporation - initial contribution. |
11 * |
11 * |
12 * Contributors: |
12 * Contributors: |
13 * |
13 * |
14 * Description: Unit test class for testing CPcsKeyMap |
14 * Description: Unit test class for testing 12-key predictive search table |
15 * |
15 * |
16 */ |
16 */ |
17 |
17 |
18 // INTERNAL INCLUDES |
18 // INTERNAL INCLUDES |
19 #include "t_cpplpredictivesearchtable.h" |
19 #include "t_cpplpredictivesearchtable.h" |
20 #include "pltables.h" |
20 #include "pltables.h" |
21 #include "dbsqlconstants.h" |
21 #include "dbsqlconstants.h" |
22 #include "cpcskeymap.h" // USE_ORBIT_KEYMAP macro |
22 #include "c12keykeymap.h" |
|
23 #include "c12keypredictivesearchtable.h" |
|
24 #include "cqwertypredictivesearchtable.h" |
|
25 #include "cpredictivesearchsettingstable.h" |
|
26 #include "cpredictivesearchsynchronizer.h" |
|
27 #include "t_predictivesearchtabledefs.h" |
|
28 #include "predictivesearchlog.h" |
23 |
29 |
24 // SYSTEM INCLUDES |
30 // SYSTEM INCLUDES |
25 #include <digia/eunit/eunitmacros.h> |
31 #include <digia/eunit/eunitmacros.h> |
26 #include <f32file.h> // added for setup2L() |
32 #include <f32file.h> // CFileMan |
27 |
33 |
28 // Used to create HbKeymapFactory singleton to get rid of resource leak |
34 // Used to create HbKeymapFactory singleton to get rid of resource leak |
29 #include <QLocale> |
35 #include <QLocale> |
30 #include <hbinputkeymapfactory.h> |
36 #include <hbinputkeymapfactory.h> |
31 |
37 |
32 |
38 |
33 // Database file |
39 // Must have same value as KMaxTokenLength in c12keypredictivesearchtable.cpp |
34 _LIT(KDBFile, "c:\\unittest.db"); |
40 const TInt KMaxTokenLength = 15; |
35 |
|
36 _LIT(KDBFileWithoutPredSearch, "c:\\contacts_without_pred_search_tables.db"); |
|
37 |
|
38 const TContactItemId KTestContactId = 20; |
|
39 const TContactItemId KTestContactId2 = 85; |
|
40 const TContactItemId KTestContactId3 = 7001; |
|
41 const TContactItemId KTestContactId4 = 56030; |
|
42 |
|
43 _LIT(KTestFirstName, "123"); |
|
44 _LIT(KTestLastName, "45678"); |
|
45 |
|
46 // Must have same value as KMaxDigits in cpplpredictivesearchtable.cpp |
|
47 const TInt KMaxDigits = 15; |
|
48 |
41 |
49 |
42 |
50 const TInt KTableCount = 12; |
43 const TInt KTableCount = 12; |
51 |
44 |
52 // Must have same value as KConversionError in cpplpredictivesearchtable.cpp |
45 // Must have same value as KConversionError in cpplpredictivesearchtable.cpp |
53 const quint64 KConversionError = 0xeeeeeeeeeeeeeee; |
46 const quint64 KConversionError = 0xeeeeeeeeeeeeeee; |
54 |
47 |
|
48 |
|
49 |
55 |
50 |
56 // ----------------------------------------------------------------------------- |
51 // ----------------------------------------------------------------------------- |
57 // UT_CPplPredictiveSearchTable::NewL |
52 // UT_CPplPredictiveSearchTable::NewL |
58 // ----------------------------------------------------------------------------- |
53 // ----------------------------------------------------------------------------- |
59 // |
54 // |
133 // Ignore error |
128 // Ignore error |
134 RSqlDatabase::Delete(KDBFile); |
129 RSqlDatabase::Delete(KDBFile); |
135 // If this causes KErrAlreadyExists, iDB won't be fully constructed |
130 // If this causes KErrAlreadyExists, iDB won't be fully constructed |
136 iDB.Create(KDBFile); |
131 iDB.Create(KDBFile); |
137 |
132 |
138 iTable = CPplPredictiveSearchTable::NewL(iDB); |
133 iTable = C12keyPredictiveSearchTable::NewL(iDB); |
|
134 iPredSearchQwertyTable = CQwertyPredictiveSearchTable::NewL(iDB); |
|
135 iPredSearchSettingsTable = CPredictiveSearchSettingsTable::NewL(iDB); |
139 // Create (empty) predictive search tables to DB |
136 // Create (empty) predictive search tables to DB |
140 iTable->CreateTableL(); |
137 iTable->CreateTableL(); |
|
138 iPredSearchQwertyTable->CreateTableL(); |
|
139 iPredSearchSettingsTable->CreateTableL(); |
|
140 |
|
141 iPredictiveSearchSynchronizer = |
|
142 CPredictiveSearchSynchronizer::NewL(iDB, |
|
143 *iTable, |
|
144 *iPredSearchQwertyTable, |
|
145 *iPredSearchSettingsTable); |
|
146 #if defined(USE_ORBIT_KEYMAP) |
|
147 HbKeymapFactory::instance(); |
|
148 #endif |
141 } |
149 } |
142 |
150 |
143 // ----------------------------------------------------------------------------- |
151 // ----------------------------------------------------------------------------- |
144 // UT_CPplPredictiveSearchTable::Setup2L |
152 // UT_CPplPredictiveSearchTable::SetupSyncL |
145 // For synchronize tables test case |
153 // For synchronize tables test case |
146 // ----------------------------------------------------------------------------- |
154 // ----------------------------------------------------------------------------- |
147 // |
155 // |
148 void UT_CPplPredictiveSearchTable::Setup2L() |
156 void UT_CPplPredictiveSearchTable::SetupSyncL() |
|
157 { |
|
158 UseSpecificDbL(KDBFileWithoutPredSearch); |
|
159 } |
|
160 |
|
161 // ----------------------------------------------------------------------------- |
|
162 // UT_CPplPredictiveSearchTable::SetupSyncJust12keyExistsL |
|
163 // For synchronize tables test case |
|
164 // ----------------------------------------------------------------------------- |
|
165 // |
|
166 void UT_CPplPredictiveSearchTable::SetupSyncJust12keyExistsL() |
|
167 { |
|
168 UseSpecificDbL(KDBFile12keyButNoQwerty); |
|
169 } |
|
170 |
|
171 // ----------------------------------------------------------------------------- |
|
172 // UT_CPplPredictiveSearchTable::SetupLanguageChangesL |
|
173 // For UT_LanguageChangesL case |
|
174 // ----------------------------------------------------------------------------- |
|
175 // |
|
176 void UT_CPplPredictiveSearchTable::SetupLanguageChangesL() |
|
177 { |
|
178 UseSpecificDbL(KDBFileOtherLanguage); |
|
179 } |
|
180 |
|
181 // ----------------------------------------------------------------------------- |
|
182 // UT_CPplPredictiveSearchTable::UseSpecificDbL |
|
183 // ----------------------------------------------------------------------------- |
|
184 // |
|
185 void UT_CPplPredictiveSearchTable::UseSpecificDbL(const TDesC& aDbFile) |
149 { |
186 { |
150 // Copy an existing DB file that does not contain predictive search tables |
187 // Copy an existing DB file that does not contain predictive search tables |
151 // to a DB file that will be used in test. |
188 // to a DB file that will be used in test. |
152 RFs fs; |
189 RFs fs; |
153 User::LeaveIfError(fs.Connect()); |
190 User::LeaveIfError(fs.Connect()); |
154 CFileMan* fm = CFileMan::NewL(fs); |
191 CFileMan* fm = CFileMan::NewL(fs); |
155 CleanupStack::PushL(fm); |
192 CleanupStack::PushL(fm); |
156 |
193 |
157 _LIT(KSourceFile, "c:\\Copy of contacts_without_pred_search_tables.db"); |
194 User::LeaveIfError(fm->Copy(aDbFile, KDBFile)); |
158 User::LeaveIfError(fm->Copy(KSourceFile, KDBFileWithoutPredSearch)); |
|
159 CleanupStack::PopAndDestroy(fm); |
195 CleanupStack::PopAndDestroy(fm); |
160 fs.Close(); |
196 fs.Close(); |
161 |
197 |
162 |
198 |
163 User::LeaveIfError(iDB.Open(KDBFileWithoutPredSearch)); |
199 User::LeaveIfError(iDB.Open(KDBFile)); |
164 iTable = CPplPredictiveSearchTable::NewL(iDB); |
200 |
|
201 iTable = C12keyPredictiveSearchTable::NewL(iDB); |
|
202 iPredSearchQwertyTable = CQwertyPredictiveSearchTable::NewL(iDB); |
|
203 iPredSearchSettingsTable = CPredictiveSearchSettingsTable::NewL(iDB); |
|
204 |
|
205 iPredictiveSearchSynchronizer = |
|
206 CPredictiveSearchSynchronizer::NewL(iDB, |
|
207 *iTable, |
|
208 *iPredSearchQwertyTable, |
|
209 *iPredSearchSettingsTable); |
165 } |
210 } |
166 |
211 |
167 // ----------------------------------------------------------------------------- |
212 // ----------------------------------------------------------------------------- |
168 // UT_CPplPredictiveSearchTable::Teardown |
213 // UT_CPplPredictiveSearchTable::Teardown |
169 // ----------------------------------------------------------------------------- |
214 // ----------------------------------------------------------------------------- |
170 // |
215 // |
171 void UT_CPplPredictiveSearchTable::Teardown() |
216 void UT_CPplPredictiveSearchTable::Teardown() |
172 { |
217 { |
|
218 delete iPredictiveSearchSynchronizer; |
|
219 iPredictiveSearchSynchronizer = NULL; |
|
220 |
173 delete iTable; |
221 delete iTable; |
174 iTable = NULL; |
222 iTable = NULL; |
|
223 |
|
224 delete iPredSearchQwertyTable; |
|
225 iPredSearchQwertyTable = NULL; |
|
226 |
|
227 delete iPredSearchSettingsTable; |
|
228 iPredSearchSettingsTable = NULL; |
175 |
229 |
176 iDB.Close(); // Must close DB before it can be deleted |
230 iDB.Close(); // Must close DB before it can be deleted |
177 RSqlDatabase::Delete(KDBFile); |
231 RSqlDatabase::Delete(KDBFile); |
178 } |
232 } |
179 |
233 |
180 |
234 |
181 // TEST CASES |
235 // TEST CASES |
182 |
236 |
183 // Dummy case to see if the first case always results a resource leak |
237 // Dummy case to see if the first case always results a resource leak (2 heap cells) |
184 void UT_CPplPredictiveSearchTable::UT_DummyL() |
238 void UT_CPplPredictiveSearchTable::UT_DummyL() |
185 { |
239 { |
186 // The first test case that writes to tables, seems to cause resource leak |
240 // The first test case that writes to tables, seems to cause resource leak |
187 // if the DB file did not have predictive search tables already. |
241 // if the DB file did not have predictive search tables already. |
188 AddContactL(KTestFirstName, KNullDesC, KTestContactId); |
242 AddContactL(KTestFirstName, KNullDesC, KTestContactId); |
237 |
291 |
238 |
292 |
239 AddContactL(KNullDesC, _L(" 22 22 2 2 222222"), ++id); |
293 AddContactL(KNullDesC, _L(" 22 22 2 2 222222"), ++id); |
240 // Adds contact to table 2 |
294 // Adds contact to table 2 |
241 CheckItemCountL(0, 4, 4, 0, 0, 3, 2, 1, 1); |
295 CheckItemCountL(0, 4, 4, 0, 0, 3, 2, 1, 1); |
|
296 } |
|
297 |
|
298 // ----------------------------------------------------------------------------- |
|
299 // UT_CPplPredictiveSearchTable::UT_CreateInDbWithHashAndStarL |
|
300 // ----------------------------------------------------------------------------- |
|
301 // |
|
302 void UT_CPplPredictiveSearchTable::UT_CreateInDbWithHashAndStarL() |
|
303 { |
|
304 AddContactL(_L(" # * +"), _L(" +*# **"), KTestContactId); |
|
305 AddContactL(_L("*"), _L("+355"), KTestContactId2); |
|
306 CheckItemCountL(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 1); |
242 } |
307 } |
243 |
308 |
244 // ----------------------------------------------------------------------------- |
309 // ----------------------------------------------------------------------------- |
245 // UT_CPplPredictiveSearchTable::UT_UpdateLL |
310 // UT_CPplPredictiveSearchTable::UT_UpdateLL |
246 // Update an existing contact |
311 // Update an existing contact |
627 // Predictive search table exists in the database. |
691 // Predictive search table exists in the database. |
628 // ----------------------------------------------------------------------------- |
692 // ----------------------------------------------------------------------------- |
629 // |
693 // |
630 void UT_CPplPredictiveSearchTable::UT_CheckIfTableExists2L() |
694 void UT_CPplPredictiveSearchTable::UT_CheckIfTableExists2L() |
631 { |
695 { |
632 TInt err = CPplContactItemManager_DoesPredSearchTableExistL(); |
696 EUNIT_ASSERT_EQUALS(ETrue, |
633 EUNIT_ASSERT_EQUALS(KErrNone, err); |
697 iPredictiveSearchSynchronizer->CheckIfPredSearchTableExistsL(KSqlContactPredSearchTable0)); |
634 } |
698 } |
635 |
699 |
636 |
700 |
637 // IMPORTANT NOTE: |
701 // IMPORTANT NOTE: |
638 // If this case fails or a resource leak is reported on it, make sure |
702 // If this case fails or a resource leak is reported on it, make sure |
639 // KDBFileWithoutPredSearch file exists, and it does not contain the predictive |
703 // KDBFileWithoutPredSearch file exists, and it does not contain the predictive |
640 // search tables! |
704 // search tables! |
641 // If Orbit keymap is used, this test case leaks resources, |
705 // If Orbit keymap is used, this test case leaks resources, |
642 // otherwise it does not leak. |
706 // otherwise it does not leak. |
643 |
|
644 /* Create DB and other tables, except pred search table. Add some contacts to DB |
|
645 but do not write them to (non-existing) pred search table. |
|
646 |
|
647 Or just create DB and all tables, then add contacts, and delete pred.search |
|
648 tables. |
|
649 Close database and open it, to see that pred search tables are created. */ |
|
650 void UT_CPplPredictiveSearchTable::UT_SynchronizeTableL() |
707 void UT_CPplPredictiveSearchTable::UT_SynchronizeTableL() |
651 { |
708 { |
652 ///////// copied from CPplContactItemManager::SynchronizePredSearchTableL //////// |
709 iPredictiveSearchSynchronizer->SynchronizeTablesL(); |
653 iTable->CreateTableL(); |
710 } |
654 _LIT(KSelectAllContactsFormat, "SELECT %S,%S,%S FROM %S;"); |
711 |
655 TInt bufSize = KSelectAllContactsFormat().Length() + |
712 void UT_CPplPredictiveSearchTable::UT_SynchronizeTableJust12keyExistsL() |
656 KContactId().Length() + |
713 { |
657 KContactFirstName().Length() + |
714 iPredictiveSearchSynchronizer->SynchronizeTablesL(); |
658 KContactCompanyName().Length() + |
715 } |
659 KSqlContactTableName().Length(); |
|
660 HBufC* sqlStatement = HBufC::NewLC(bufSize); |
|
661 sqlStatement->Des().AppendFormat(KSelectAllContactsFormat, |
|
662 &KContactId, |
|
663 &KContactFirstName, |
|
664 &KContactLastName, |
|
665 &KSqlContactTableName); |
|
666 |
|
667 RSqlStatement stmnt; |
|
668 CleanupClosePushL(stmnt); |
|
669 stmnt.PrepareL(iDB, *sqlStatement); |
|
670 |
|
671 const TInt KContactIdIndex = 0; |
|
672 const TInt KFirstNameIndex = 1; |
|
673 const TInt KLastNameIndex = 2; |
|
674 TInt err(KErrNone); |
|
675 while ((err = stmnt.Next()) == KSqlAtRow) |
|
676 { |
|
677 TInt id = KUidContactCardValue; |
|
678 TUid uid; |
|
679 uid.iUid = id; |
|
680 CContactItem* contact = CContactItem::NewLC(uid); |
|
681 contact->SetId(stmnt.ColumnInt(KContactIdIndex)); |
|
682 |
|
683 // If first name exists, write it to contact item |
|
684 TPtrC firstName; |
|
685 if (stmnt.ColumnText(KFirstNameIndex, firstName) == KErrNone) |
|
686 { |
|
687 CContactItemField* field = |
|
688 CContactItemField::NewLC(KStorageTypeText, KUidContactFieldGivenName); |
|
689 CContactTextField* textfield = field->TextStorage(); |
|
690 textfield->SetTextL(firstName); |
|
691 contact->AddFieldL(*field); // Takes ownership |
|
692 CleanupStack::Pop(field); |
|
693 } |
|
694 |
|
695 TPtrC lastName; |
|
696 if (stmnt.ColumnText(KLastNameIndex, lastName) == KErrNone) |
|
697 { |
|
698 CContactItemField* field = |
|
699 CContactItemField::NewLC(KStorageTypeText, KUidContactFieldFamilyName); |
|
700 CContactTextField* textfield = field->TextStorage(); |
|
701 textfield->SetTextL(lastName); |
|
702 contact->AddFieldL(*field); // Takes ownership |
|
703 CleanupStack::Pop(field); |
|
704 } |
|
705 iTable->CreateInDbL(*contact); |
|
706 CleanupStack::PopAndDestroy(contact); |
|
707 } |
|
708 |
|
709 // Leave if we didn't complete going through the results properly |
|
710 if (err != KSqlAtEnd) |
|
711 { |
|
712 User::Leave(err); |
|
713 } |
|
714 CleanupStack::PopAndDestroy(&stmnt); |
|
715 CleanupStack::PopAndDestroy(sqlStatement); |
|
716 ///////// end - copied from CPplContactItemManager::SynchronizePredSearchTableL ////////// |
|
717 |
|
718 |
|
719 delete iTable; |
|
720 iTable = NULL; |
|
721 iDB.Close(); // Must close DB before it can be deleted |
|
722 |
|
723 RSqlDatabase::Delete(KDBFileWithoutPredSearch); |
|
724 } |
|
725 |
716 |
726 void UT_CPplPredictiveSearchTable::UT_DeleteTablesL() |
717 void UT_CPplPredictiveSearchTable::UT_DeleteTablesL() |
727 { |
718 { |
728 // Delete tables |
719 // Delete tables |
729 CPplContactItemManager_DeletePredSearchTablesL(); |
720 iPredictiveSearchSynchronizer->DeletePredSearchTablesL(); |
730 |
|
731 |
721 |
732 // Check tables have been deleted |
722 // Check tables have been deleted |
733 TInt err = CPplContactItemManager_DoesPredSearchTableExistL(); |
723 EUNIT_ASSERT_EQUALS(EFalse, |
734 EUNIT_ASSERT_EQUALS(-311, err); |
724 iPredictiveSearchSynchronizer->CheckIfPredSearchTableExistsL(KSqlContactPredSearchTable0)); |
735 |
|
736 |
725 |
737 // Try to delete tables when they do not exist |
726 // Try to delete tables when they do not exist |
738 CPplContactItemManager_DeletePredSearchTablesL(); |
727 iPredictiveSearchSynchronizer->DeletePredSearchTablesL(); |
|
728 } |
|
729 |
|
730 void UT_CPplPredictiveSearchTable::UT_LanguageChangesL() |
|
731 { |
|
732 iPredictiveSearchSynchronizer->SynchronizeTablesL(); |
739 } |
733 } |
740 |
734 |
741 void UT_CPplPredictiveSearchTable::UT_TokenizeNamesL() |
735 void UT_CPplPredictiveSearchTable::UT_TokenizeNamesL() |
742 { |
736 { |
743 _LIT(KFirstNames, "99 12345 234567 987 99"); |
737 _LIT(KFirstNames, "99 12345 234567 987 99"); |
744 _LIT(KLastNames, "12355 987 402"); |
738 _LIT(KLastNames, "12355 987 402"); |
745 HBufC* fn = KFirstNames().AllocLC(); |
739 HBufC* fn = KFirstNames().AllocLC(); |
746 HBufC* ln = KLastNames().AllocLC(); |
740 HBufC* ln = KLastNames().AllocLC(); |
|
741 QStringList emptyList; |
747 |
742 |
748 // This constant must have same value as declared in cpplpredictivesearchtable.cpp |
743 // This constant must have same value as declared in cpplpredictivesearchtable.cpp |
749 const TInt KMaxTokens = 4; |
744 const TInt KMaxTokens = 4; |
750 QStringList tokens = iTable->GetNumericTokens(fn, ln); |
745 QStringList tokens = iTable->GetTokens(emptyList, fn, ln); |
751 EUNIT_ASSERT_EQUALS(KMaxTokens, tokens.count()); |
746 EUNIT_ASSERT_EQUALS(KMaxTokens, tokens.count()); |
752 tokens.clear(); |
747 tokens.clear(); |
753 |
748 |
754 tokens = iTable->GetNumericTokens(NULL, ln); |
749 tokens = iTable->GetTokens(emptyList, NULL, ln); |
755 EUNIT_ASSERT_EQUALS(3, tokens.count()); |
750 EUNIT_ASSERT_EQUALS(3, tokens.count()); |
756 tokens.clear(); |
751 tokens.clear(); |
757 |
752 |
758 tokens = iTable->GetNumericTokens(fn, NULL); |
753 tokens = iTable->GetTokens(emptyList, fn, NULL); |
759 EUNIT_ASSERT_EQUALS(4, tokens.count()); |
754 EUNIT_ASSERT_EQUALS(4, tokens.count()); |
760 tokens.clear(); |
755 tokens.clear(); |
761 |
756 |
762 tokens = iTable->GetNumericTokens(NULL, NULL); |
757 tokens = iTable->GetTokens(emptyList, NULL, NULL); |
763 EUNIT_ASSERT_EQUALS(0, tokens.count()); |
758 EUNIT_ASSERT_EQUALS(0, tokens.count()); |
|
759 tokens.clear(); |
|
760 |
|
761 QStringList mailList; |
|
762 mailList << "mail.addr1"; |
|
763 mailList << "mail.addr2"; |
|
764 tokens = iTable->GetTokens(mailList, NULL, NULL); |
|
765 EUNIT_ASSERT_EQUALS(2, tokens.count()); |
|
766 tokens.clear(); |
|
767 |
|
768 tokens = iTable->GetTokens(mailList, fn, ln); |
|
769 EUNIT_ASSERT_EQUALS(4, tokens.count()); |
764 tokens.clear(); |
770 tokens.clear(); |
765 |
771 |
766 CleanupStack::PopAndDestroy(ln); |
772 CleanupStack::PopAndDestroy(ln); |
767 CleanupStack::PopAndDestroy(fn); |
773 CleanupStack::PopAndDestroy(fn); |
768 } |
774 } |
1050 |
1056 |
1051 // RDebug::Print(_L("UT_CPplPredictiveSearchTable::ConvertToNbrL result 0x%lx"), nbrValue); |
1057 // RDebug::Print(_L("UT_CPplPredictiveSearchTable::ConvertToNbrL result 0x%lx"), nbrValue); |
1052 return nbrValue; |
1058 return nbrValue; |
1053 } |
1059 } |
1054 |
1060 |
1055 // This function has code copied from CPplContactItemManager::DoesPredSearchTableExistL |
|
1056 TInt UT_CPplPredictiveSearchTable::CPplContactItemManager_DoesPredSearchTableExistL() |
|
1057 { |
|
1058 // SQLite does not have SHOW TABLES command, so try to search from |
|
1059 // predictive search table. |
|
1060 _LIT(KCheckIfTableExistsFormat, "SELECT %S FROM %S;"); |
|
1061 TInt bufSize = KCheckIfTableExistsFormat().Length() + |
|
1062 KPredSearchContactId().Length() + |
|
1063 KSqlContactPredSearchTable11().Length(); |
|
1064 HBufC* sqlStatement = HBufC::NewLC(bufSize); |
|
1065 sqlStatement->Des().AppendFormat(KCheckIfTableExistsFormat, |
|
1066 &KPredSearchContactId, |
|
1067 &KSqlContactPredSearchTable0); |
|
1068 |
|
1069 RSqlStatement stmnt; |
|
1070 CleanupClosePushL(stmnt); |
|
1071 // If table does not exist, leaves with -311 |
|
1072 // If table exists, does not leave |
|
1073 TRAPD(err, stmnt.PrepareL(iDB, *sqlStatement)); |
|
1074 CleanupStack::PopAndDestroy(&stmnt); |
|
1075 CleanupStack::PopAndDestroy(sqlStatement); |
|
1076 return err; |
|
1077 } |
|
1078 |
|
1079 // This function has code copied from CPplContactItemManager::DeletePredSearchTablesL |
|
1080 void UT_CPplPredictiveSearchTable::CPplContactItemManager_DeletePredSearchTablesL() |
|
1081 { |
|
1082 const TDesC* KTableNames[KTableCount] = |
|
1083 { |
|
1084 &KSqlContactPredSearchTable0, |
|
1085 &KSqlContactPredSearchTable1, |
|
1086 &KSqlContactPredSearchTable2, |
|
1087 &KSqlContactPredSearchTable3, |
|
1088 &KSqlContactPredSearchTable4, |
|
1089 &KSqlContactPredSearchTable5, |
|
1090 &KSqlContactPredSearchTable6, |
|
1091 &KSqlContactPredSearchTable7, |
|
1092 &KSqlContactPredSearchTable8, |
|
1093 &KSqlContactPredSearchTable9, |
|
1094 &KSqlContactPredSearchTable10, |
|
1095 &KSqlContactPredSearchTable11 |
|
1096 }; |
|
1097 |
|
1098 // IF EXISTS suppresses error that would occur if table does not exist |
|
1099 _LIT(KDropTable, "DROP TABLE IF EXISTS %S;"); |
|
1100 for (TInt i = 0; i < KTableCount; ++i) |
|
1101 { |
|
1102 HBufC* dropTableCommand = HBufC::NewLC(KDropTable().Length() + |
|
1103 // All table names are of same length |
|
1104 KTableNames[i]->Length()); |
|
1105 TPtr ptr = dropTableCommand->Des(); |
|
1106 ptr.Format(KDropTable, KTableNames[i]); |
|
1107 |
|
1108 User::LeaveIfError(iDB.Exec(*dropTableCommand)); |
|
1109 CleanupStack::PopAndDestroy(dropTableCommand); |
|
1110 } |
|
1111 } |
|
1112 |
|
1113 |
1061 |
1114 // TEST TABLE |
1062 // TEST TABLE |
1115 |
1063 |
1116 EUNIT_BEGIN_TEST_TABLE( |
1064 EUNIT_BEGIN_TEST_TABLE( |
1117 UT_CPplPredictiveSearchTable, |
1065 UT_CPplPredictiveSearchTable, |
1189 SetupL, UT_DeleteNonexistingContactL, Teardown ) |
1144 SetupL, UT_DeleteNonexistingContactL, Teardown ) |
1190 |
1145 |
1191 EUNIT_TEST( |
1146 EUNIT_TEST( |
1192 "Check if predictive search table exists (table does not exist)", |
1147 "Check if predictive search table exists (table does not exist)", |
1193 "UT_CPplPredictiveSearchTable", |
1148 "UT_CPplPredictiveSearchTable", |
1194 "", |
1149 "DoesPredSearchTableExistL", |
1195 "FUNCTIONALITY", |
1150 "FUNCTIONALITY", |
1196 SetupL, UT_CheckIfTableExistsL, Teardown ) |
1151 SetupL, UT_CheckIfTableExistsL, Teardown ) |
1197 |
1152 |
1198 EUNIT_TEST( |
1153 EUNIT_TEST( |
1199 "Check if predictive search table exists (table exists)", |
1154 "Check if predictive search table exists (table exists)", |
1200 "UT_CPplPredictiveSearchTable", |
1155 "UT_CPplPredictiveSearchTable", |
1201 "", |
1156 "DoesPredSearchTableExistL", |
1202 "FUNCTIONALITY", |
1157 "FUNCTIONALITY", |
1203 SetupL, UT_CheckIfTableExists2L, Teardown ) |
1158 SetupL, UT_CheckIfTableExists2L, Teardown ) |
1204 |
1159 |
1205 EUNIT_TEST( |
1160 EUNIT_TEST( |
1206 "Synchronize table", |
1161 "Synchronize DB w/o pred.search tables", |
1207 "UT_CPplPredictiveSearchTable", |
1162 "UT_CPplPredictiveSearchTable", |
1208 "", |
1163 "CreatePredSearchTablesL", |
1209 "FUNCTIONALITY", |
1164 "FUNCTIONALITY", |
1210 Setup2L, UT_SynchronizeTableL, Teardown ) |
1165 SetupSyncL, UT_SynchronizeTableL, Teardown ) |
|
1166 |
|
1167 EUNIT_TEST( |
|
1168 "Synchronize DB with 12-key, but w/o QWERTY tables", |
|
1169 "UT_CPplPredictiveSearchTable", |
|
1170 "CreatePredSearchTablesL", |
|
1171 "FUNCTIONALITY", |
|
1172 SetupSyncJust12keyExistsL, UT_SynchronizeTableJust12keyExistsL, Teardown ) |
1211 |
1173 |
1212 EUNIT_TEST( |
1174 EUNIT_TEST( |
1213 "Delete predictive search tables", |
1175 "Delete predictive search tables", |
1214 "UT_CPplPredictiveSearchTable", |
1176 "UT_CPplPredictiveSearchTable", |
1215 "CPplContactItemManager::DeletePredSearchTablesL", |
1177 "DeletePredSearchTablesL", |
1216 "FUNCTIONALITY", |
1178 "FUNCTIONALITY", |
1217 SetupL, UT_DeleteTablesL, Teardown ) |
1179 SetupL, UT_DeleteTablesL, Teardown ) |
1218 |
1180 |
1219 EUNIT_TEST( |
1181 EUNIT_TEST( |
|
1182 "Language changes: re-create QWERTY tables", |
|
1183 "UT_CPplPredictiveSearchTable", |
|
1184 "DeletePredSearchTablesL", |
|
1185 "FUNCTIONALITY", |
|
1186 SetupLanguageChangesL, UT_LanguageChangesL, Teardown ) |
|
1187 |
|
1188 EUNIT_TEST( |
1220 "Tokenize names", |
1189 "Tokenize names", |
1221 "UT_CPplPredictiveSearchTable", |
1190 "UT_CPplPredictiveSearchTable", |
1222 "TokenizeNames", |
1191 "TokenizeNames", |
1223 "FUNCTIONALITY", |
1192 "FUNCTIONALITY", |
1224 SetupL, UT_TokenizeNamesL, Teardown ) |
1193 SetupL, UT_TokenizeNamesL, Teardown ) |