1351 db.Close(); |
1351 db.Close(); |
1352 |
1352 |
1353 rc = RSqlDatabase::Delete(KTestDbName1); |
1353 rc = RSqlDatabase::Delete(KTestDbName1); |
1354 TEST2(rc, KErrNone); |
1354 TEST2(rc, KErrNone); |
1355 } |
1355 } |
|
1356 |
|
1357 /** |
|
1358 @SYMTestCaseID PDS-SQL-CT-4191 |
|
1359 @SYMTestCaseDesc The test creates a test database and inserts one record using a stream. |
|
1360 MStreamBuf::SeekL() is used to modify the parameter data at specific positions. |
|
1361 Then the test executes a SELECT statement to read the just written record. |
|
1362 MStreamBuf::SeekL() is used to read the column content at specific positions |
|
1363 (the same positions used during the record write operation). The read byte values must |
|
1364 match the written byte values. |
|
1365 @SYMTestPriority High |
|
1366 @SYMTestActions RSqlColumnReadStream::ColumnBinary() and RSqlParamWriteStream::BindBinary() - MStreamBuf::SeekL() test. |
|
1367 @SYMTestExpectedResults Test must not fail |
|
1368 @SYMDEF DEF145125 |
|
1369 */ |
|
1370 void StreamSeekTestL() |
|
1371 { |
|
1372 RSqlDatabase db; |
|
1373 CleanupClosePushL(db); |
|
1374 TInt rc = db.Create(KTestDbName1); |
|
1375 TEST2(rc, KErrNone); |
|
1376 rc = db.Exec(_L("CREATE TABLE A(Fld1 INTEGER, Fld2 BLOB)")); |
|
1377 TEST(rc >= 0); |
|
1378 //Write a record to the database using a stream. MStreamBuf::SeekL() is used to modify the content at a specific position. |
|
1379 RSqlStatement stmt; |
|
1380 CleanupClosePushL(stmt); |
|
1381 rc = stmt.Prepare(db, _L("INSERT INTO A(Fld1, Fld2) VALUES(1, ?)")); |
|
1382 TEST2(rc, KErrNone); |
|
1383 |
|
1384 RSqlParamWriteStream strm1; |
|
1385 CleanupClosePushL(strm1); |
|
1386 rc = strm1.BindBinary(stmt, 0); |
|
1387 TEST2(rc, KErrNone); |
|
1388 |
|
1389 for(TInt i=0;i<256;++i) |
|
1390 { |
|
1391 strm1 << (TUint8)i; |
|
1392 } |
|
1393 |
|
1394 const TInt KStreamOffset = 10; |
|
1395 const TUint8 KByte = 'z'; |
|
1396 _LIT8(KData, "QWERTYUIOPASDFG"); |
|
1397 |
|
1398 MStreamBuf* strm1buf = strm1.Sink(); |
|
1399 TEST(strm1buf != NULL); |
|
1400 |
|
1401 strm1buf->SeekL(MStreamBuf::EWrite, EStreamBeginning, 0); |
|
1402 strm1buf->WriteL(&KByte, 1); |
|
1403 |
|
1404 strm1buf->SeekL(MStreamBuf::EWrite, EStreamMark, KStreamOffset); |
|
1405 strm1buf->WriteL(&KByte, 1); |
|
1406 |
|
1407 strm1buf->SeekL(MStreamBuf::EWrite, EStreamEnd, 0); |
|
1408 strm1buf->WriteL(KData().Ptr(), KData().Length()); |
|
1409 |
|
1410 strm1buf->SeekL(MStreamBuf::EWrite, EStreamEnd, -4 * KStreamOffset); |
|
1411 strm1buf->WriteL(&KByte, 1); |
|
1412 |
|
1413 strm1.CommitL(); |
|
1414 CleanupStack::PopAndDestroy(&strm1); |
|
1415 |
|
1416 rc = stmt.Exec(); |
|
1417 TEST2(rc, 1); |
|
1418 CleanupStack::PopAndDestroy(&stmt); |
|
1419 |
|
1420 //Read the record using a stream. MStreamBuf::SeekL() is used to read the content at a specific position. |
|
1421 CleanupClosePushL(stmt); |
|
1422 rc = stmt.Prepare(db, _L("SELECT Fld2 FROM A WHERE Fld1 = 1")); |
|
1423 TEST2(rc, KErrNone); |
|
1424 rc = stmt.Next(); |
|
1425 TEST2(rc, KSqlAtRow); |
|
1426 |
|
1427 RSqlColumnReadStream strm2; |
|
1428 CleanupClosePushL(strm2); |
|
1429 rc = strm2.ColumnBinary(stmt, 0); |
|
1430 TEST2(rc, KErrNone); |
|
1431 |
|
1432 TUint8 byte = 0; |
|
1433 MStreamBuf* strm2buf = strm2.Source(); |
|
1434 TEST(strm1buf != NULL); |
|
1435 |
|
1436 strm2buf->SeekL(MStreamBuf::ERead, EStreamBeginning, 0); |
|
1437 rc = strm2buf->ReadL(&byte, 1); |
|
1438 TEST2(rc, 1); |
|
1439 TEST2(byte, KByte); |
|
1440 |
|
1441 strm2buf->SeekL(MStreamBuf::ERead, EStreamMark, KStreamOffset); |
|
1442 rc = strm2buf->ReadL(&byte, 1); |
|
1443 TEST2(rc, 1); |
|
1444 TEST2(byte, KByte); |
|
1445 |
|
1446 strm2buf->SeekL(MStreamBuf::ERead, EStreamEnd, -KData().Length()); |
|
1447 TUint8 buf[20]; |
|
1448 rc = strm2buf->ReadL(buf, KData().Length()); |
|
1449 TEST2(rc, KData().Length()); |
|
1450 TPtrC8 bufptr(buf, rc); |
|
1451 TEST(bufptr == KData); |
|
1452 |
|
1453 strm2buf->SeekL(MStreamBuf::ERead, EStreamEnd, -4 * KStreamOffset); |
|
1454 rc = strm2buf->ReadL(&byte, 1); |
|
1455 TEST2(rc, 1); |
|
1456 TEST2(byte, KByte); |
|
1457 |
|
1458 CleanupStack::PopAndDestroy(&strm2); |
|
1459 CleanupStack::PopAndDestroy(&stmt); |
|
1460 |
|
1461 CleanupStack::PopAndDestroy(&db); |
|
1462 rc = RSqlDatabase::Delete(KTestDbName1); |
|
1463 TEST2(rc, KErrNone); |
|
1464 } |
1356 |
1465 |
1357 /** |
1466 /** |
1358 @SYMTestCaseID PDS-SQL-CT-4174 |
1467 @SYMTestCaseID PDS-SQL-CT-4174 |
1359 @SYMTestCaseDesc Test for DEF144937: SQL, SQL server, the code coverage can be improved in some areas. |
1468 @SYMTestCaseDesc Test for DEF144937: SQL, SQL server, the code coverage can be improved in some areas. |
1360 @SYMTestPriority High |
1469 @SYMTestPriority High |