persistentstorage/sql/TEST/t_sqlapi.cpp
branchRCL_3
changeset 11 211563e4b919
parent 10 31a8f755b7fe
child 12 6b6fd149daa2
equal deleted inserted replaced
10:31a8f755b7fe 11:211563e4b919
  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
  2237 	(void)RSqlDatabase::Delete(KTestDbName1);
  2346 	(void)RSqlDatabase::Delete(KTestDbName1);
  2238 	}
  2347 	}
  2239 
  2348 
  2240 void DoTestsL()
  2349 void DoTestsL()
  2241 	{
  2350 	{
  2242 	TheTest.Start(_L(" @SYMTestCaseID:SYSLIB-SQL-CT-1601 Create/Open/Close database tests "));	
  2351 	TheTest.Start(_L(" @SYMTestCaseID:SYSLIB-SQL-CT-1601 Create/Open/Close database tests "));
  2243 	OpenCloseDatabaseTest();
  2352 	OpenCloseDatabaseTest();
  2244 
  2353 
  2245 	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-CT-1602 SetIsolationLevel() database tests "));	
  2354 	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-CT-1602 SetIsolationLevel() database tests "));	
  2246 	SetIsolationLevelTest();
  2355 	SetIsolationLevelTest();
  2247 	
  2356 	
  2281 	TextParameterStreamTest();
  2390 	TextParameterStreamTest();
  2282 
  2391 
  2283 	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-CT-1622 RSqlParamWriteStream test. Long binary parameter "));
  2392 	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-CT-1622 RSqlParamWriteStream test. Long binary parameter "));
  2284 	BinaryParameterStreamTest();
  2393 	BinaryParameterStreamTest();
  2285 
  2394 
       
  2395     TheTest.Next(_L(" @SYMTestCaseID:PDS-SQL-CT-4191 MStreamBuf::SeekL() test"));
       
  2396     StreamSeekTestL();
       
  2397 	
  2286 	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-CT-1634 RSqlStatement test. Nameless parameter "));
  2398 	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-CT-1634 RSqlStatement test. Nameless parameter "));
  2287 	NamelessParameterTest();
  2399 	NamelessParameterTest();
  2288 
  2400 
  2289 	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-CT-1768 Asynchronous execution tests "));
  2401 	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-CT-1768 Asynchronous execution tests "));
  2290 	AsyncTest();	
  2402 	AsyncTest();