sl@0
|
1 |
// Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
2 |
// All rights reserved.
|
sl@0
|
3 |
// This component and the accompanying materials are made available
|
sl@0
|
4 |
// under the terms of "Eclipse Public License v1.0"
|
sl@0
|
5 |
// which accompanies this distribution, and is available
|
sl@0
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
7 |
//
|
sl@0
|
8 |
// Initial Contributors:
|
sl@0
|
9 |
// Nokia Corporation - initial contribution.
|
sl@0
|
10 |
//
|
sl@0
|
11 |
// Contributors:
|
sl@0
|
12 |
//
|
sl@0
|
13 |
// Description:
|
sl@0
|
14 |
//
|
sl@0
|
15 |
|
sl@0
|
16 |
#include <d32dbms.h>
|
sl@0
|
17 |
#include <s32file.h>
|
sl@0
|
18 |
#include <e32test.h>
|
sl@0
|
19 |
|
sl@0
|
20 |
#include "crccheck.h"
|
sl@0
|
21 |
|
sl@0
|
22 |
#undef __UHEAP_MARK
|
sl@0
|
23 |
#undef __UHEAP_MARKEND
|
sl@0
|
24 |
#define __UHEAP_MARK
|
sl@0
|
25 |
#define __UHEAP_MARKEND
|
sl@0
|
26 |
|
sl@0
|
27 |
LOCAL_D TDBMS_CRCChecks TheCrcChecker;
|
sl@0
|
28 |
|
sl@0
|
29 |
#ifndef __linux__ //No CRC test on LINUX
|
sl@0
|
30 |
#ifdef __TOOLS2__
|
sl@0
|
31 |
const TPtrC KCrcRecord=_L("\\epoc32\\winscw\\c\\dbms-tst\\T_LONGCOL.CRC");
|
sl@0
|
32 |
#else
|
sl@0
|
33 |
const TPtrC KCrcRecord=_L("C:\\dbms-tst\\T_LONGCOL.CRC");
|
sl@0
|
34 |
#endif
|
sl@0
|
35 |
#endif
|
sl@0
|
36 |
|
sl@0
|
37 |
static RTest TheTest(_L("T_LONGCOL"));
|
sl@0
|
38 |
static CTrapCleanup* TheTrapCleanup;
|
sl@0
|
39 |
const TInt KTestCleanupStack=0x40;
|
sl@0
|
40 |
RFs TheFsSession;
|
sl@0
|
41 |
|
sl@0
|
42 |
#ifdef __TOOLS2__
|
sl@0
|
43 |
const TPtrC KTestDir=_L(".\\dbms-tst\\");
|
sl@0
|
44 |
#else
|
sl@0
|
45 |
const TPtrC KTestDir=_L("C:\\dbms-tst\\");
|
sl@0
|
46 |
#endif
|
sl@0
|
47 |
|
sl@0
|
48 |
#ifndef __TOOLS2__
|
sl@0
|
49 |
const TPtrC KSearchTestDbPath = _L("c:\\dbms-tst\\eposlmserachtest.ldb");
|
sl@0
|
50 |
#else
|
sl@0
|
51 |
const TPtrC KSearchTestDbPath = _L(".\\eposlmserachtest.ldb");
|
sl@0
|
52 |
#endif
|
sl@0
|
53 |
|
sl@0
|
54 |
//Delete "aFullName" file.
|
sl@0
|
55 |
static void DeleteDataFile(const TDesC& aFullName)
|
sl@0
|
56 |
{
|
sl@0
|
57 |
RFs fsSession;
|
sl@0
|
58 |
TInt err = fsSession.Connect();
|
sl@0
|
59 |
if(err == KErrNone)
|
sl@0
|
60 |
{
|
sl@0
|
61 |
TEntry entry;
|
sl@0
|
62 |
if(fsSession.Entry(aFullName, entry) == KErrNone)
|
sl@0
|
63 |
{
|
sl@0
|
64 |
RDebug::Print(_L("Deleting \"%S\" file.\n"), &aFullName);
|
sl@0
|
65 |
err = fsSession.SetAtt(aFullName, 0, KEntryAttReadOnly);
|
sl@0
|
66 |
if(err != KErrNone)
|
sl@0
|
67 |
{
|
sl@0
|
68 |
RDebug::Print(_L("Error %d changing \"%S\" file attributes.\n"), err, &aFullName);
|
sl@0
|
69 |
}
|
sl@0
|
70 |
err = fsSession.Delete(aFullName);
|
sl@0
|
71 |
if(err != KErrNone)
|
sl@0
|
72 |
{
|
sl@0
|
73 |
RDebug::Print(_L("Error %d deleting \"%S\" file.\n"), err, &aFullName);
|
sl@0
|
74 |
}
|
sl@0
|
75 |
}
|
sl@0
|
76 |
fsSession.Close();
|
sl@0
|
77 |
}
|
sl@0
|
78 |
else
|
sl@0
|
79 |
{
|
sl@0
|
80 |
RDebug::Print(_L("Error %d connecting file session. File: %S.\n"), err, &aFullName);
|
sl@0
|
81 |
}
|
sl@0
|
82 |
}
|
sl@0
|
83 |
|
sl@0
|
84 |
///////////////////////////////////////////////////////////////////////////////////////
|
sl@0
|
85 |
///////////////////////////////////////////////////////////////////////////////////////
|
sl@0
|
86 |
//Tests macros and functions.
|
sl@0
|
87 |
//If (!aValue) then the test will be panicked, the test data files will be deleted.
|
sl@0
|
88 |
static void Check(TInt aValue, TInt aLine)
|
sl@0
|
89 |
{
|
sl@0
|
90 |
if(!aValue)
|
sl@0
|
91 |
{
|
sl@0
|
92 |
::DeleteDataFile(KSearchTestDbPath);
|
sl@0
|
93 |
TheTest(EFalse, aLine);
|
sl@0
|
94 |
}
|
sl@0
|
95 |
}
|
sl@0
|
96 |
//If (aValue != aExpected) then the test will be panicked, the test data files will be deleted.
|
sl@0
|
97 |
static void Check(TInt aValue, TInt aExpected, TInt aLine)
|
sl@0
|
98 |
{
|
sl@0
|
99 |
if(aValue != aExpected)
|
sl@0
|
100 |
{
|
sl@0
|
101 |
RDebug::Print(_L("*** Expected error: %d, got: %d\r\n"), aExpected, aValue);
|
sl@0
|
102 |
::DeleteDataFile(KSearchTestDbPath);
|
sl@0
|
103 |
TheTest(EFalse, aLine);
|
sl@0
|
104 |
}
|
sl@0
|
105 |
}
|
sl@0
|
106 |
//Use these to test conditions.
|
sl@0
|
107 |
#define TEST(arg) ::Check((arg), __LINE__)
|
sl@0
|
108 |
#define TEST2(aValue, aExpected) ::Check(aValue, aExpected, __LINE__)
|
sl@0
|
109 |
|
sl@0
|
110 |
///////////////////////////////////////////////////////////////////////////////////////
|
sl@0
|
111 |
|
sl@0
|
112 |
static void Leave(TInt aLine, TInt aError)
|
sl@0
|
113 |
{
|
sl@0
|
114 |
RDebug::Print(_L("*** Leave. Error: %d, line: %d\r\n"), aError, aLine);
|
sl@0
|
115 |
User::Leave(aError);
|
sl@0
|
116 |
}
|
sl@0
|
117 |
static void LeaveIfError(TInt aLine, TInt aError)
|
sl@0
|
118 |
{
|
sl@0
|
119 |
if(aError < KErrNone)
|
sl@0
|
120 |
{
|
sl@0
|
121 |
::Leave(aLine, aError);
|
sl@0
|
122 |
}
|
sl@0
|
123 |
}
|
sl@0
|
124 |
#define __LEAVE(err) ::Leave(__LINE__, err)
|
sl@0
|
125 |
#define __LEAVE_IF_ERROR(err) ::LeaveIfError(__LINE__, err)
|
sl@0
|
126 |
|
sl@0
|
127 |
///////////////////////////////////////////////////////////////////////////////////////
|
sl@0
|
128 |
///////////////////////////////////////////////////////////////////////////////////////
|
sl@0
|
129 |
|
sl@0
|
130 |
//
|
sl@0
|
131 |
// Prepare the test directory.
|
sl@0
|
132 |
//
|
sl@0
|
133 |
static void SetupTestDirectory()
|
sl@0
|
134 |
{
|
sl@0
|
135 |
TInt r=TheFsSession.MkDir(KTestDir);
|
sl@0
|
136 |
TEST(r==KErrNone || r==KErrAlreadyExists);
|
sl@0
|
137 |
r=TheFsSession.SetSessionPath(KTestDir);
|
sl@0
|
138 |
TEST2(r,KErrNone);
|
sl@0
|
139 |
// On TOOLS2 - RFs::SetSessionPath() will affect all RFs Sessions,
|
sl@0
|
140 |
// the two RFs need same session path anyway
|
sl@0
|
141 |
#ifdef __WINSCW__
|
sl@0
|
142 |
r=TheCrcChecker.SetSessionPath(KTestDir);
|
sl@0
|
143 |
TEST2(r,KErrNone);
|
sl@0
|
144 |
#endif
|
sl@0
|
145 |
}
|
sl@0
|
146 |
|
sl@0
|
147 |
static TInt SearchFor( const TPtrC& aSearchString, RDbNamedDatabase& aDb )
|
sl@0
|
148 |
{
|
sl@0
|
149 |
_LIT( KSQLSearchStatement, "select Notes from CDs where Notes like '%S'" );
|
sl@0
|
150 |
TBuf<512> query;
|
sl@0
|
151 |
query.Format( KSQLSearchStatement, &aSearchString );
|
sl@0
|
152 |
|
sl@0
|
153 |
// Display query
|
sl@0
|
154 |
_LIT( KQueryFormatter, "\r\n %S\r\n" );
|
sl@0
|
155 |
TBuf<512> msg;
|
sl@0
|
156 |
msg.Format( KQueryFormatter, &query );
|
sl@0
|
157 |
TheTest.Printf( msg );
|
sl@0
|
158 |
|
sl@0
|
159 |
// create a view on the database
|
sl@0
|
160 |
RDbView view;
|
sl@0
|
161 |
// use EDbCompareCollated in order to search case-insensitive
|
sl@0
|
162 |
__LEAVE_IF_ERROR( view.Prepare( aDb, TDbQuery( query, EDbCompareCollated ) ) );
|
sl@0
|
163 |
__LEAVE_IF_ERROR( view.EvaluateAll() );
|
sl@0
|
164 |
|
sl@0
|
165 |
// iterate across the row set
|
sl@0
|
166 |
TInt noOfMatches = 0;
|
sl@0
|
167 |
for ( view.FirstL(); view.AtRow(); view.NextL() )
|
sl@0
|
168 |
{
|
sl@0
|
169 |
// retrieve the row
|
sl@0
|
170 |
view.GetL();
|
sl@0
|
171 |
noOfMatches++;
|
sl@0
|
172 |
}
|
sl@0
|
173 |
|
sl@0
|
174 |
// Display no of matches
|
sl@0
|
175 |
_LIT( KNoOfMatchFormatter, " Found %d matches\r\n" );
|
sl@0
|
176 |
msg.Format( KNoOfMatchFormatter, noOfMatches );
|
sl@0
|
177 |
TheTest.Printf( msg );
|
sl@0
|
178 |
|
sl@0
|
179 |
// close the view
|
sl@0
|
180 |
view.Close();
|
sl@0
|
181 |
return noOfMatches;
|
sl@0
|
182 |
}
|
sl@0
|
183 |
|
sl@0
|
184 |
/**
|
sl@0
|
185 |
@SYMTestCaseID SYSLIB-DBMS-CT-0645
|
sl@0
|
186 |
@SYMTestCaseDesc Searching for data from a database
|
sl@0
|
187 |
@SYMTestPriority Medium
|
sl@0
|
188 |
@SYMTestActions Tests for EDbColText,EDbColLongText column type
|
sl@0
|
189 |
@SYMTestExpectedResults Test must not fail
|
sl@0
|
190 |
@SYMREQ REQ0000
|
sl@0
|
191 |
*/
|
sl@0
|
192 |
static void TestSearchL( TInt aIndex )
|
sl@0
|
193 |
{
|
sl@0
|
194 |
// Default database
|
sl@0
|
195 |
_LIT( KComposer1, "Elgar" );
|
sl@0
|
196 |
_LIT( KCol1, "Artist" );
|
sl@0
|
197 |
_LIT( KCol2, "Notes" );
|
sl@0
|
198 |
_LIT( KTable, "CDs" );
|
sl@0
|
199 |
|
sl@0
|
200 |
TInt err = TheFsSession.Delete( KSearchTestDbPath );
|
sl@0
|
201 |
if ( ( err != KErrNone ) && ( err != KErrNotFound ) && ( err != KErrPathNotFound ) )
|
sl@0
|
202 |
{
|
sl@0
|
203 |
__LEAVE( err );
|
sl@0
|
204 |
}
|
sl@0
|
205 |
|
sl@0
|
206 |
RDbNamedDatabase db;
|
sl@0
|
207 |
CleanupClosePushL( db );
|
sl@0
|
208 |
__LEAVE_IF_ERROR( db.Create( TheFsSession, KSearchTestDbPath ) );
|
sl@0
|
209 |
|
sl@0
|
210 |
//
|
sl@0
|
211 |
// Create the database table
|
sl@0
|
212 |
//
|
sl@0
|
213 |
// Create a table definition
|
sl@0
|
214 |
CDbColSet* columns = CDbColSet::NewLC();
|
sl@0
|
215 |
// add the columns
|
sl@0
|
216 |
columns->AddL( TDbCol( KCol1, EDbColText ) );
|
sl@0
|
217 |
if ( aIndex == 0 )
|
sl@0
|
218 |
columns->AddL( TDbCol( KCol2, EDbColText ) );
|
sl@0
|
219 |
else
|
sl@0
|
220 |
columns->AddL( TDbCol( KCol2, EDbColLongText ) );
|
sl@0
|
221 |
// if the column is of type "EDbColText" instead,
|
sl@0
|
222 |
// all searching is working properly
|
sl@0
|
223 |
// Create a table
|
sl@0
|
224 |
__LEAVE_IF_ERROR( db.CreateTable( KTable, *columns ) );
|
sl@0
|
225 |
// cleanup the column set
|
sl@0
|
226 |
CleanupStack::PopAndDestroy( columns );
|
sl@0
|
227 |
|
sl@0
|
228 |
//
|
sl@0
|
229 |
// Add data
|
sl@0
|
230 |
//
|
sl@0
|
231 |
// create a view on the database
|
sl@0
|
232 |
_LIT( KSQLStatement, "select Artist,Notes from CDs order by Artist" );
|
sl@0
|
233 |
RDbView view;
|
sl@0
|
234 |
__LEAVE_IF_ERROR( view.Prepare( db, TDbQuery( KSQLStatement, EDbCompareNormal ) ) );
|
sl@0
|
235 |
__LEAVE_IF_ERROR( view.EvaluateAll() );
|
sl@0
|
236 |
|
sl@0
|
237 |
// Get the structure of rowset
|
sl@0
|
238 |
CDbColSet* colSet = view.ColSetL();
|
sl@0
|
239 |
// insert a row
|
sl@0
|
240 |
view.InsertL();
|
sl@0
|
241 |
view.SetColL( colSet->ColNo( KCol1 ), KComposer1 ); // Artist
|
sl@0
|
242 |
// Use the stream
|
sl@0
|
243 |
// RDbColWriteStream out;
|
sl@0
|
244 |
// TDbColNo col = colSet->ColNo( KCol2 ); // Ordinal position of long column
|
sl@0
|
245 |
//
|
sl@0
|
246 |
// out.OpenLC( view, col );
|
sl@0
|
247 |
// out.WriteL( _L( "Some additional comment here." ) );
|
sl@0
|
248 |
// out.Close();
|
sl@0
|
249 |
//
|
sl@0
|
250 |
// CleanupStack::PopAndDestroy(); // out
|
sl@0
|
251 |
view.SetColL( colSet->ColNo( KCol2 ), _L( "Some additional comment here." ) );
|
sl@0
|
252 |
view.PutL();
|
sl@0
|
253 |
// close the view
|
sl@0
|
254 |
view.Close();
|
sl@0
|
255 |
delete colSet;
|
sl@0
|
256 |
|
sl@0
|
257 |
//
|
sl@0
|
258 |
// Display the data
|
sl@0
|
259 |
//
|
sl@0
|
260 |
_LIT( KRowFormatter, "\r\n Artist: %S \r\n Notes: %S \r\n" );
|
sl@0
|
261 |
__LEAVE_IF_ERROR( view.Prepare( db, TDbQuery( KSQLStatement, EDbCompareNormal ) ) );
|
sl@0
|
262 |
__LEAVE_IF_ERROR( view.EvaluateAll() );
|
sl@0
|
263 |
|
sl@0
|
264 |
// Get the structure of the rowset
|
sl@0
|
265 |
colSet = view.ColSetL();
|
sl@0
|
266 |
// iterate across the row set
|
sl@0
|
267 |
for ( view.FirstL(); view.AtRow(); view.NextL() )
|
sl@0
|
268 |
{
|
sl@0
|
269 |
// retrieve the row
|
sl@0
|
270 |
view.GetL();
|
sl@0
|
271 |
// while the rowset is on this row, can use a TPtrC to
|
sl@0
|
272 |
// refer to any text columns
|
sl@0
|
273 |
TPtrC artist = view.ColDes( colSet->ColNo( KCol1 ) );
|
sl@0
|
274 |
// and a stream for long columns
|
sl@0
|
275 |
RDbColReadStream in;
|
sl@0
|
276 |
TDbColNo col = colSet->ColNo( KCol2 ); // Ordinal position of long column
|
sl@0
|
277 |
TBuf<256> notes; // Buffer for out notes
|
sl@0
|
278 |
in.OpenLC( view, col );
|
sl@0
|
279 |
in.ReadL( notes, view.ColLength( col ) );
|
sl@0
|
280 |
in.Close();
|
sl@0
|
281 |
CleanupStack::PopAndDestroy(); // in
|
sl@0
|
282 |
// Display the artist and notes
|
sl@0
|
283 |
TBuf<512> msg;
|
sl@0
|
284 |
msg.Format( KRowFormatter, &artist, ¬es );
|
sl@0
|
285 |
TheTest.Printf( msg );
|
sl@0
|
286 |
}
|
sl@0
|
287 |
// close the view
|
sl@0
|
288 |
view.Close();
|
sl@0
|
289 |
delete colSet;
|
sl@0
|
290 |
|
sl@0
|
291 |
//
|
sl@0
|
292 |
// Search for the data
|
sl@0
|
293 |
//
|
sl@0
|
294 |
TInt result;
|
sl@0
|
295 |
result = SearchFor( _L( "Some*" ), db ); // matches
|
sl@0
|
296 |
TEST(result == 1);
|
sl@0
|
297 |
result = SearchFor( _L( "some*" ), db ); // defect causes no match, should match
|
sl@0
|
298 |
TEST(result == 1);
|
sl@0
|
299 |
result = SearchFor( _L( "*some*" ), db ); // matches
|
sl@0
|
300 |
TEST(result == 1);
|
sl@0
|
301 |
result = SearchFor( _L( "s?me*" ), db ); // matches
|
sl@0
|
302 |
TEST(result == 1);
|
sl@0
|
303 |
result = SearchFor( _L( "Some additional comment here." ), db ); // matches
|
sl@0
|
304 |
TEST(result == 1);
|
sl@0
|
305 |
result = SearchFor( _L( "some additional comment here." ), db ); // defect causes no match, should match
|
sl@0
|
306 |
TEST(result == 1);
|
sl@0
|
307 |
|
sl@0
|
308 |
CleanupStack::PopAndDestroy( &db );
|
sl@0
|
309 |
TheCrcChecker.GenerateCrcL(KSearchTestDbPath);
|
sl@0
|
310 |
}
|
sl@0
|
311 |
|
sl@0
|
312 |
//
|
sl@0
|
313 |
// Initialise the cleanup stack.
|
sl@0
|
314 |
//
|
sl@0
|
315 |
static void setupCleanup()
|
sl@0
|
316 |
{
|
sl@0
|
317 |
TheTrapCleanup=CTrapCleanup::New();
|
sl@0
|
318 |
TEST(TheTrapCleanup!=NULL);
|
sl@0
|
319 |
TRAPD(r,\
|
sl@0
|
320 |
{\
|
sl@0
|
321 |
for (TInt i=KTestCleanupStack;i>0;i--)\
|
sl@0
|
322 |
CleanupStack::PushL((TAny*)0);\
|
sl@0
|
323 |
CleanupStack::Pop(KTestCleanupStack);\
|
sl@0
|
324 |
});
|
sl@0
|
325 |
TEST2(r,KErrNone);
|
sl@0
|
326 |
}
|
sl@0
|
327 |
|
sl@0
|
328 |
//
|
sl@0
|
329 |
// Test streaming conversions.
|
sl@0
|
330 |
//
|
sl@0
|
331 |
GLDEF_C TInt E32Main()
|
sl@0
|
332 |
{
|
sl@0
|
333 |
TheTest.Title();
|
sl@0
|
334 |
setupCleanup();
|
sl@0
|
335 |
__UHEAP_MARK;
|
sl@0
|
336 |
|
sl@0
|
337 |
TInt err = TheFsSession.Connect();
|
sl@0
|
338 |
TEST2(err, KErrNone);
|
sl@0
|
339 |
::SetupTestDirectory();
|
sl@0
|
340 |
|
sl@0
|
341 |
TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-0645 Testing DBMS - EDbColText "));
|
sl@0
|
342 |
TRAP(err, TestSearchL( 0 ));
|
sl@0
|
343 |
TEST2(err,KErrNone);
|
sl@0
|
344 |
TheTest.Start(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-0645 Testing DBMS - EDbColLongText "));
|
sl@0
|
345 |
TRAP(err, TestSearchL( 1 ));
|
sl@0
|
346 |
TEST2(err,KErrNone);
|
sl@0
|
347 |
::DeleteDataFile(KSearchTestDbPath);
|
sl@0
|
348 |
|
sl@0
|
349 |
#ifndef __linux__
|
sl@0
|
350 |
#ifndef __TOOLS2__
|
sl@0
|
351 |
TRAPD(lc, err = TheCrcChecker.DumpCrcRecordsL(KCrcRecord));
|
sl@0
|
352 |
TheTest(err==KErrNone);
|
sl@0
|
353 |
TheTest(lc==KErrNone);
|
sl@0
|
354 |
#else
|
sl@0
|
355 |
TRAPD(lc, err = TheCrcChecker.ValidateCrcRecordsL(KCrcRecord));
|
sl@0
|
356 |
TPtrC errmsg;
|
sl@0
|
357 |
TheCrcChecker.ErrorReportL(err, errmsg);
|
sl@0
|
358 |
RDebug::Print(errmsg);
|
sl@0
|
359 |
TheTest(err==KErrNone || err==TDBMS_CRCChecks::ECrcCheckOk);
|
sl@0
|
360 |
#endif
|
sl@0
|
361 |
#endif
|
sl@0
|
362 |
|
sl@0
|
363 |
TheTest.End();
|
sl@0
|
364 |
|
sl@0
|
365 |
TheFsSession.Close();
|
sl@0
|
366 |
|
sl@0
|
367 |
__UHEAP_MARKEND;
|
sl@0
|
368 |
delete TheTrapCleanup;
|
sl@0
|
369 |
TheTest.Close();
|
sl@0
|
370 |
return 0;
|
sl@0
|
371 |
}
|
sl@0
|
372 |
|