|
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 // Create a communications database |
|
20 |
|
21 #include <e32test.h> |
|
22 #include <f32file.h> |
|
23 #include <commdb.h> |
|
24 #include <cdblen.h> |
|
25 #include <cdbpreftable.h> |
|
26 #include <faxdefn.h> |
|
27 #include <d32comm.h> |
|
28 #include <cdbtemp.h> |
|
29 |
|
30 |
|
31 _LIT(KEditorMess,"Database Editor"); |
|
32 LOCAL_C RTest test(KEditorMess); |
|
33 LOCAL_C CCommsDatabase* theDb; |
|
34 |
|
35 |
|
36 // |
|
37 // The Dial Out ISP table will have 3 records, plus |
|
38 // two extra records that are read only |
|
39 // |
|
40 |
|
41 |
|
42 LOCAL_C CreateDialInISPTable() |
|
43 { |
|
44 TUint32 id; |
|
45 |
|
46 CCommsDbTableView* theView; |
|
47 |
|
48 theView = theDb->OpenTableLC(TPtrC(DIAL_IN_ISP) ); |
|
49 |
|
50 // |
|
51 // Record #1 |
|
52 // |
|
53 theView->InsertRecord( id ); |
|
54 theView->WriteTextL( TPtrC(COMMDB_NAME), _L("Record #1") ) ; |
|
55 //Just write the columns that can't be null |
|
56 theView->WriteTextL( TPtrC(ISP_IF_NAME), _L("PPP") ) ; |
|
57 theView->WriteBoolL( TPtrC(ISP_IP_ADDR_FROM_SERVER), ETrue ) ; |
|
58 theView->WriteBoolL( TPtrC(ISP_IP_DNS_ADDR_FROM_SERVER), ETrue ) ; |
|
59 theView->WriteBoolL( TPtrC(ISP_IP6_DNS_ADDR_FROM_SERVER), ETrue ) ; |
|
60 |
|
61 theView->PutRecordChanges(); |
|
62 |
|
63 // |
|
64 // Record #2 |
|
65 // |
|
66 theView->InsertRecord( id ); |
|
67 theView->WriteTextL( TPtrC(COMMDB_NAME), _L("Record #2") ) ; |
|
68 //Just write the columns that can't be null |
|
69 theView->WriteTextL( TPtrC(ISP_IF_NAME), _L("PPP") ) ; |
|
70 theView->WriteBoolL( TPtrC(ISP_IP_ADDR_FROM_SERVER), ETrue ) ; |
|
71 theView->WriteBoolL( TPtrC(ISP_IP_DNS_ADDR_FROM_SERVER), ETrue ) ; |
|
72 theView->WriteBoolL( TPtrC(ISP_IP6_DNS_ADDR_FROM_SERVER), ETrue ) ; |
|
73 theView->PutRecordChanges(); |
|
74 |
|
75 |
|
76 // |
|
77 // Record #3 |
|
78 // |
|
79 theView->InsertRecord( id ); |
|
80 theView->WriteTextL( TPtrC(COMMDB_NAME), _L("Record #3") ) ; |
|
81 //Just write the columns that can't be null |
|
82 theView->WriteTextL( TPtrC(ISP_IF_NAME), _L("SLIP") ) ; |
|
83 theView->WriteBoolL( TPtrC(ISP_IP_ADDR_FROM_SERVER), ETrue ) ; |
|
84 theView->WriteBoolL( TPtrC(ISP_IP_DNS_ADDR_FROM_SERVER), ETrue ) ; |
|
85 theView->WriteBoolL( TPtrC(ISP6_IP_ADDR_FROM_SERVER), ETrue ) ; |
|
86 theView->WriteBoolL( TPtrC(ISP6_IP_DNS_ADDR_FROM_SERVER), ETrue ) ; |
|
87 theView->PutRecordChanges(); |
|
88 |
|
89 // |
|
90 // Record #4 ( Read Only ) |
|
91 // |
|
92 theView->InsertRecord( id ); |
|
93 theView->WriteTextL( TPtrC(COMMDB_NAME), _L("Record #4 (Read Only)") ) ; |
|
94 //Just write the columns that can't be null |
|
95 theView->WriteTextL( TPtrC(ISP_IF_NAME), _L("SLIP") ) ; |
|
96 theView->WriteBoolL( TPtrC(ISP_IP_ADDR_FROM_SERVER), ETrue ) ; |
|
97 theView->WriteBoolL( TPtrC(ISP_IP_DNS_ADDR_FROM_SERVER), ETrue ) ; |
|
98 theView->WriteBoolL( TPtrC(ISP6_IP_ADDR_FROM_SERVER), ETrue ) ; |
|
99 theView->WriteBoolL( TPtrC(ISP6_IP_DNS_ADDR_FROM_SERVER), ETrue ) ; |
|
100 theView->PutRecordChanges(EFalse, ETrue); |
|
101 |
|
102 // |
|
103 // Record #5 ( Read Only ) |
|
104 // |
|
105 theView->InsertRecord( id ); |
|
106 theView->WriteTextL( TPtrC(COMMDB_NAME), _L("Record #5 (Read Only)") ) ; |
|
107 //Just write the columns that can't be null |
|
108 theView->WriteTextL( TPtrC(ISP_IF_NAME), _L("PPP") ) ; |
|
109 theView->WriteBoolL( TPtrC(ISP_IP_ADDR_FROM_SERVER), ETrue ) ; |
|
110 theView->WriteBoolL( TPtrC(ISP_IP_DNS_ADDR_FROM_SERVER), ETrue ) ; |
|
111 theView->WriteBoolL( TPtrC(ISP_IP6_DNS_ADDR_FROM_SERVER), ETrue ) ; |
|
112 theView->PutRecordChanges(EFalse, ETrue); |
|
113 |
|
114 CleanupStack::PopAndDestroy( theView ); |
|
115 } |
|
116 |
|
117 |
|
118 |
|
119 // |
|
120 // The Dial Out ISP table will have 3 records |
|
121 // |
|
122 |
|
123 LOCAL_C CreateDialOutISPTable() |
|
124 { |
|
125 TUint32 id; |
|
126 |
|
127 CCommsDbTableView* theView; |
|
128 |
|
129 theView = theDb->OpenTableLC(TPtrC(DIAL_OUT_ISP) ); |
|
130 |
|
131 // |
|
132 // Record #1 |
|
133 // |
|
134 theView->InsertRecord( id ); |
|
135 |
|
136 theView->WriteTextL( TPtrC(COMMDB_NAME), _L("Record #1") ) ; |
|
137 theView->WriteTextL( TPtrC(ISP_DESCRIPTION), _L("Isp #1") ); |
|
138 theView->WriteUintL( TPtrC(ISP_TYPE),EIspTypeWAPOnly); |
|
139 theView->WriteBoolL( TPtrC(ISP_DISPLAY_PCT), ETrue); |
|
140 |
|
141 //Must write to these columns as they cannot hold null values |
|
142 theView->WriteBoolL(TPtrC(ISP_DIAL_RESOLUTION),ETrue); |
|
143 theView->WriteBoolL(TPtrC(ISP_USE_LOGIN_SCRIPT),ETrue); |
|
144 theView->WriteBoolL(TPtrC(ISP_PROMPT_FOR_LOGIN),EFalse); |
|
145 theView->WriteTextL(TPtrC(ISP_IF_NAME), _L("PPP") ); |
|
146 theView->WriteBoolL(TPtrC(ISP_IF_PROMPT_FOR_AUTH),EFalse); |
|
147 theView->WriteBoolL(TPtrC(ISP_IP_ADDR_FROM_SERVER),ETrue); |
|
148 theView->WriteBoolL(TPtrC(ISP_IP_DNS_ADDR_FROM_SERVER),ETrue); |
|
149 theView->WriteBoolL(TPtrC(ISP_IP6_DNS_ADDR_FROM_SERVER),ETrue); |
|
150 theView->WriteTextL(TPtrC(ISP_IF_CALLBACK_INFO), _L8("Call me back") ); |
|
151 theView->PutRecordChanges(); |
|
152 |
|
153 |
|
154 // |
|
155 // Record #2 |
|
156 // |
|
157 theView->InsertRecord( id ); |
|
158 |
|
159 theView->WriteTextL( TPtrC(COMMDB_NAME), _L("Record #2") ) ; |
|
160 theView->WriteUintL( TPtrC(ISP_TYPE),EIspTypeInternetAndWAP); |
|
161 |
|
162 //Must write to these columns as they cannot hold null values |
|
163 theView->WriteBoolL(TPtrC(ISP_DIAL_RESOLUTION),ETrue); |
|
164 theView->WriteBoolL(TPtrC(ISP_USE_LOGIN_SCRIPT),ETrue); |
|
165 theView->WriteBoolL(TPtrC(ISP_PROMPT_FOR_LOGIN),EFalse); |
|
166 theView->WriteTextL(TPtrC(ISP_IF_NAME), _L("PPP") ); |
|
167 theView->WriteBoolL(TPtrC(ISP_IF_PROMPT_FOR_AUTH),EFalse); |
|
168 theView->WriteBoolL(TPtrC(ISP_IP_ADDR_FROM_SERVER),ETrue); |
|
169 theView->WriteBoolL(TPtrC(ISP_IP_DNS_ADDR_FROM_SERVER),ETrue); |
|
170 theView->WriteBoolL(TPtrC(ISP_IP6_DNS_ADDR_FROM_SERVER),ETrue); |
|
171 theView->WriteTextL(TPtrC(ISP_IF_CALLBACK_INFO), _L8("Call me back tomorrow") ); |
|
172 |
|
173 theView->PutRecordChanges(); |
|
174 |
|
175 // |
|
176 // Record #3 |
|
177 // |
|
178 theView->InsertRecord( id ); |
|
179 |
|
180 theView->WriteTextL( TPtrC(COMMDB_NAME), _L("Record #3") ) ; |
|
181 theView->WriteUintL( TPtrC(ISP_TYPE),EIspTypeInternetAndWAP); |
|
182 |
|
183 //Must write to these columns as they cannot hold null values |
|
184 theView->WriteBoolL(TPtrC(ISP_DIAL_RESOLUTION),ETrue); |
|
185 theView->WriteBoolL(TPtrC(ISP_USE_LOGIN_SCRIPT),ETrue); |
|
186 theView->WriteBoolL(TPtrC(ISP_PROMPT_FOR_LOGIN),ETrue); |
|
187 theView->WriteTextL(TPtrC(ISP_IF_NAME), _L("PPP") ); |
|
188 theView->WriteBoolL(TPtrC(ISP_IF_PROMPT_FOR_AUTH),EFalse); |
|
189 theView->WriteBoolL(TPtrC(ISP_IP_ADDR_FROM_SERVER),ETrue); |
|
190 theView->WriteBoolL(TPtrC(ISP_IP_DNS_ADDR_FROM_SERVER),ETrue); |
|
191 theView->WriteBoolL(TPtrC(ISP_IP6_DNS_ADDR_FROM_SERVER),ETrue); |
|
192 theView->WriteTextL(TPtrC(ISP_IF_CALLBACK_INFO), _L8("Call me back") ); |
|
193 |
|
194 theView->PutRecordChanges(); |
|
195 |
|
196 CleanupStack::PopAndDestroy( theView ); |
|
197 |
|
198 } |
|
199 |
|
200 |
|
201 LOCAL_C void MainL() |
|
202 { |
|
203 RFs fs; |
|
204 test(fs.Connect()==KErrNone); |
|
205 |
|
206 TUint dummy; |
|
207 |
|
208 test.Printf(_L("Creating CommDb Unit test database #1") ); |
|
209 |
|
210 _LIT(KSvDbFileName,"C:\\private\\100012a5\\DBS[10004e1d]CDBV3.DAT"); |
|
211 |
|
212 if(fs.Att(KSvDbFileName,dummy)==KErrNone) |
|
213 { |
|
214 _LIT(KDbaseMess,"\nExisting Database File detected\n - Overwrite? [y/n]\n\n"); |
|
215 test.Printf(KDbaseMess); |
|
216 TKeyCode key; |
|
217 key=test.Getch(); |
|
218 if((key=='y')||(key=='Y')) |
|
219 { |
|
220 // Instantiate Database Server |
|
221 RDbs rDbs; |
|
222 User::LeaveIfError(rDbs.Connect()); |
|
223 CleanupClosePushL(rDbs); |
|
224 _LIT(KCommDb,"c:cdbv3.dat"); |
|
225 const TUid KCommsDbFileUid = {0x10004e1d}; |
|
226 test(rDbs.DeleteDatabase(KCommDb, KCommsDbFileUid)==KErrNone); |
|
227 CleanupStack::PopAndDestroy(&rDbs); |
|
228 } |
|
229 else |
|
230 User::Leave(KErrNone); |
|
231 } |
|
232 fs.Close(); |
|
233 |
|
234 //Create a blank database |
|
235 theDb=CCommsDatabase::NewL(EFalse); |
|
236 CleanupStack::PushL(theDb); |
|
237 test(theDb->BeginTransaction()==KErrNone); |
|
238 |
|
239 |
|
240 CreateDialOutISPTable(); |
|
241 CreateDialInISPTable(); |
|
242 |
|
243 |
|
244 theDb->CommitTransaction(); |
|
245 CleanupStack::PopAndDestroy(); |
|
246 } |
|
247 |
|
248 GLDEF_C TInt E32Main() |
|
249 { |
|
250 __UHEAP_MARK; |
|
251 |
|
252 CTrapCleanup* cleanup=CTrapCleanup::New(); |
|
253 |
|
254 test.Title(); |
|
255 TRAPD(error,MainL()); |
|
256 |
|
257 if (error) |
|
258 { |
|
259 _LIT(KFailMess,"DbApp failed with error = %d"); |
|
260 test.Printf(KFailMess, error); |
|
261 _LIT(KAnyKeyMess," [Press any key]"); |
|
262 test.Printf(KAnyKeyMess); |
|
263 test.Getch(); |
|
264 } |
|
265 else |
|
266 { |
|
267 _LIT(KCompleteMess,"DbApp Complete OK"); |
|
268 test.Printf(KCompleteMess); |
|
269 } |
|
270 _LIT(KPanicMess,"DbApp"); |
|
271 __ASSERT_ALWAYS(!error,test.Panic(KPanicMess,error)); |
|
272 test.Close(); |
|
273 delete cleanup; |
|
274 __UHEAP_MARKEND; |
|
275 return KErrNone; |
|
276 } |