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