|
1 // Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // This tests the various options for the ORG property |
|
15 // This includes |
|
16 // 1) ORG:company;department |
|
17 // 2) ORG:Company; |
|
18 // 3) ORG:;Department |
|
19 // |
|
20 // |
|
21 |
|
22 #include <e32test.h> |
|
23 #include <e32debug.h> |
|
24 #include <f32file.h> |
|
25 #include <s32file.h> |
|
26 #include "T_UTILS.H" |
|
27 |
|
28 LOCAL_D CCntTest* CntTest=NULL; |
|
29 LOCAL_D const TPtrC KDatabaseFileName=_L("C:VOrgDb.cdb"); |
|
30 LOCAL_D RTest test(_L("T_VExportORG")); |
|
31 |
|
32 _LIT8(KOrg1, "ORG:Symbian;PIM\r\n"); |
|
33 //_LIT8(KOrg2, "ORG\r\n"); |
|
34 _LIT8(KOrg3, "ORG:Symbian;\r\n"); |
|
35 _LIT8(KOrg4, "ORG:;PIM\r\n"); |
|
36 |
|
37 _LIT(KVImportFileName, "C:\\vOrgImport.vcf"); |
|
38 _LIT(KVExportFileName, "C:\\vOrgExport.vcf"); |
|
39 _LIT8(KBegin,"BEGIN:VCARD\r\n"); |
|
40 _LIT8(KEnd,"END:VCARD\r\n"); |
|
41 _LIT8(KVersion, "VERSION:2.1\r\n"); |
|
42 _LIT8(KName, "N:Surname;FirstName;;;\r\n"); |
|
43 |
|
44 void createVcardFileL(const TDesC8& aOrgLine, RFs& aFileSession) |
|
45 { |
|
46 RFile file; |
|
47 User::LeaveIfError(file.Replace(aFileSession, KVImportFileName, EFileWrite|EFileShareAny)); |
|
48 CleanupClosePushL(file); |
|
49 |
|
50 file.Write(KBegin); |
|
51 file.Write(KVersion); |
|
52 file.Write(KName); |
|
53 file.Write(aOrgLine); |
|
54 file.Write(KEnd); |
|
55 |
|
56 file.Flush(); |
|
57 CleanupStack::PopAndDestroy(); //file.Close() |
|
58 |
|
59 } |
|
60 |
|
61 void versitDeleteVcardFilesL(RFs& aFileSession) |
|
62 { |
|
63 aFileSession.Delete(KVImportFileName); |
|
64 aFileSession.Delete(KVExportFileName); |
|
65 } |
|
66 |
|
67 void EmptyDatabase() |
|
68 { |
|
69 TContactItemId theid; |
|
70 TContactIter iter(*CntTest->Db()); |
|
71 theid=iter.FirstL(); |
|
72 while(theid!=KNullContactId ) |
|
73 { |
|
74 CntTest->Db()->DeleteContactL(theid); |
|
75 theid=iter.NextL(); |
|
76 } |
|
77 } |
|
78 |
|
79 void versitImportContactL(RFs& aFileSession) |
|
80 { |
|
81 RFileReadStream readStream; |
|
82 |
|
83 //Import vOrgImport.vcf |
|
84 User::LeaveIfError(readStream.Open(aFileSession,KVImportFileName, EFileRead)); |
|
85 CleanupClosePushL(readStream); |
|
86 |
|
87 TBool success=EFalse; |
|
88 CArrayPtr<CContactItem>* contactItems=CntTest->Db()->ImportContactsL(TUid::Uid(KUidVCardConvDefaultImpl), |
|
89 readStream, success, |
|
90 CContactDatabase::EImportSingleContact+CContactDatabase::ETTFormat); |
|
91 |
|
92 |
|
93 //Should be the only contact in the database at this point |
|
94 TInt count = CntTest->Db()->CountL(); |
|
95 test(count == 1); |
|
96 |
|
97 //Store the id of the new contact - we need this later |
|
98 TContactItemId contactId = (*contactItems)[0]->Id(); |
|
99 CntTest->Db()->SetCurrentItem(contactId); |
|
100 |
|
101 readStream.Close(); |
|
102 CleanupStack::PopAndDestroy(); //readStream.Close() |
|
103 contactItems->ResetAndDestroy(); |
|
104 delete contactItems; |
|
105 |
|
106 } |
|
107 |
|
108 void versitExportContactL(RFs& aFileSession) |
|
109 { |
|
110 RFileWriteStream writeStream; |
|
111 User::LeaveIfError(writeStream.Replace(aFileSession,KVExportFileName,EFileWrite)); |
|
112 CleanupClosePushL(writeStream); |
|
113 |
|
114 CContactIdArray* idArray = CContactIdArray::NewLC(); |
|
115 TInt count = CntTest->Db()->CountL(); |
|
116 test(count == 1); |
|
117 TContactItemId contactId = CntTest->Db()->GetCurrentItem(); |
|
118 |
|
119 idArray->InsertL(0, contactId); |
|
120 |
|
121 CntTest->Db()->ExportSelectedContactsL(TUid::Uid(KUidVCardConvDefaultImpl), *idArray, writeStream,0); |
|
122 writeStream.Close(); |
|
123 |
|
124 CleanupStack::PopAndDestroy(2); //idArray, writeStream |
|
125 |
|
126 |
|
127 } |
|
128 |
|
129 TBool versitCheckExportFilesL(const TDesC8& aOrgLine, RFs& aFileSession) |
|
130 { |
|
131 RFile fileHandle; |
|
132 TBool patternFound = EFalse; |
|
133 fileHandle.Open(aFileSession, KVExportFileName, EFileRead|EFileStreamText); |
|
134 CleanupClosePushL(fileHandle); |
|
135 |
|
136 // TFileText exportedfile; //Bug in TFileText so not used at the moment |
|
137 // exportedfile.Set(fileHandle); |
|
138 // exportedfile.Seek(ESeekStart); |
|
139 TBuf8<256> line; |
|
140 |
|
141 while(fileHandle.Read(line) == KErrNone && line.Length() != 0) |
|
142 { |
|
143 if (line.Find(aOrgLine) != KErrNotFound) |
|
144 { |
|
145 patternFound = ETrue; |
|
146 break; |
|
147 } |
|
148 } |
|
149 |
|
150 CleanupStack::PopAndDestroy(&fileHandle); |
|
151 return patternFound; |
|
152 } |
|
153 |
|
154 |
|
155 void testExportOrgL(const TDesC8& aOrgLine) |
|
156 { |
|
157 RFs fsSession; |
|
158 TBool success = EFalse; |
|
159 User::LeaveIfError(fsSession.Connect()); |
|
160 CleanupClosePushL(fsSession); |
|
161 |
|
162 createVcardFileL(aOrgLine,fsSession); |
|
163 versitImportContactL(fsSession); |
|
164 versitExportContactL(fsSession); |
|
165 EmptyDatabase(); |
|
166 |
|
167 success = versitCheckExportFilesL(aOrgLine,fsSession); |
|
168 |
|
169 versitDeleteVcardFilesL(fsSession); |
|
170 fsSession.Close(); |
|
171 CleanupStack::PopAndDestroy(&fsSession); //fsSession.Close() |
|
172 RDebug::RawPrint(aOrgLine); |
|
173 if(success == EFalse) |
|
174 { RDebug::RawPrint(aOrgLine); |
|
175 User::Leave(KErrNotFound); |
|
176 } |
|
177 } |
|
178 |
|
179 /** |
|
180 |
|
181 @SYMTestCaseID PIM-T-VEXPORTORG-0001 |
|
182 |
|
183 */ |
|
184 |
|
185 void testOrgL() |
|
186 { |
|
187 test.Start(_L("@SYMTESTCaseID:PIM-T-VEXPORTORG-0001 Test Versit export of ORG line")); |
|
188 |
|
189 |
|
190 CntTest->CreateDatabaseL(); |
|
191 |
|
192 test.Next(_L("ORG:Company;Dept")); |
|
193 |
|
194 testExportOrgL(KOrg1); |
|
195 |
|
196 //test.Next(_L("ORG")); |
|
197 |
|
198 //testExportOrgL(KOrg2); |
|
199 |
|
200 test.Next(_L("ORG:Company")); |
|
201 |
|
202 testExportOrgL(KOrg3); |
|
203 |
|
204 test.Next(_L("ORG:;Dept")); |
|
205 |
|
206 testExportOrgL(KOrg4); |
|
207 |
|
208 |
|
209 CntTest->CloseDatabase(); |
|
210 |
|
211 CntTest->DeleteDatabaseL(); |
|
212 } |
|
213 |
|
214 GLDEF_C TInt E32Main() |
|
215 { |
|
216 __UHEAP_MARK; |
|
217 CntTest = new CCntTest; |
|
218 if (!CntTest) |
|
219 { |
|
220 return KErrNoMemory; |
|
221 } |
|
222 |
|
223 TRAPD(err, CntTest->ConstructL(test,KDatabaseFileName) ); |
|
224 test(err == KErrNone); |
|
225 |
|
226 TRAP(err,testOrgL() ); |
|
227 test(err == KErrNone); |
|
228 |
|
229 CntTest->EndTestLib(err); |
|
230 |
|
231 __UHEAP_MARKEND; |
|
232 return KErrNone; |
|
233 } |