persistentstorage/sql/TEST/t_sqlblob.cpp
branchRCL_3
changeset 16 6b6fd149daa2
parent 0 08ec8eefde2f
child 55 44f437012c90
equal deleted inserted replaced
13:211563e4b919 16:6b6fd149daa2
     1 // Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
     1 // Copyright (c) 2008-2010 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     3 // This component and the accompanying materials are made available
     4 // under the terms of "Eclipse Public License v1.0"
     4 // under the terms of "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
  1957 	TEST(blobRdBufPtr.Compare(blobWrChunk) == 0);
  1957 	TEST(blobRdBufPtr.Compare(blobWrChunk) == 0);
  1958 	
  1958 	
  1959 	CleanupStack::PopAndDestroy(2, blobWrBuf); // buf, blobWrBuf
  1959 	CleanupStack::PopAndDestroy(2, blobWrBuf); // buf, blobWrBuf
  1960 	}
  1960 	}
  1961 	
  1961 	
       
  1962 /**
       
  1963 @SYMTestCaseID          PDS-SQL-CT-4194
       
  1964 @SYMTestCaseDesc        The test opens a test database, creates a table with a blob column and inserts one record.
       
  1965 						Then the test uses RSqlBlobWriteStream to modify the blob column content.
       
  1966                         MStreamBuf::SeekL() is used to modify the blob data at specific positions.
       
  1967                         Then the test uses RSqlBlobReadStream object to read the just written blob data.
       
  1968                         MStreamBuf::SeekL() is used to read the column content at specific positions 
       
  1969                         (the same positions used during the blob write operation). The read byte values must
       
  1970                         match the written byte values.
       
  1971 @SYMTestPriority        High
       
  1972 @SYMTestActions         RSqlBlobReadStream and RSqlBlobWriteStream - MStreamBuf::SeekL() test.
       
  1973 @SYMTestExpectedResults Test must not fail
       
  1974 @SYMDEF                 DEF145028
       
  1975 */  
       
  1976 void StreamSeekTestL()
       
  1977 	{
       
  1978     TInt rc = TheDb1.Exec(_L("CREATE TABLE A(Fld1 INTEGER, Fld2 BLOB)"));
       
  1979     TEST(rc >= 0);
       
  1980     
       
  1981     //Write a record to the database using a blob stream. MStreamBuf::SeekL() is used to modify the content at a specific position.
       
  1982     rc = TheDb1.Exec(_L("INSERT INTO A(Fld1, Fld2) VALUES(1, zeroblob(256))"));
       
  1983     TEST2(rc, 1);
       
  1984     RSqlBlobWriteStream strm1;
       
  1985     CleanupClosePushL(strm1);
       
  1986     strm1.OpenL(TheDb1, _L("A"), _L("Fld2"));
       
  1987     for(TInt i=0;i<256;++i)
       
  1988         {
       
  1989         strm1 << (TUint8)i;
       
  1990         }
       
  1991     
       
  1992     const TInt KStreamOffset = 10;
       
  1993     const TUint8 KByte = 'z';
       
  1994     _LIT8(KData, "QWERTYUIOPASDFG");
       
  1995     
       
  1996     MStreamBuf* strm1buf = strm1.Sink();
       
  1997     TEST(strm1buf != NULL);
       
  1998     
       
  1999     strm1buf->SeekL(MStreamBuf::EWrite, EStreamBeginning, 0);
       
  2000     strm1buf->WriteL(&KByte, 1);
       
  2001     
       
  2002     strm1buf->SeekL(MStreamBuf::EWrite, EStreamMark, KStreamOffset);
       
  2003     strm1buf->WriteL(&KByte, 1);
       
  2004     
       
  2005     strm1buf->SeekL(MStreamBuf::EWrite, EStreamEnd, -KData().Length());
       
  2006     strm1buf->WriteL(KData().Ptr(), KData().Length());
       
  2007     
       
  2008     strm1buf->SeekL(MStreamBuf::EWrite, EStreamEnd, -4 * KStreamOffset);
       
  2009     strm1buf->WriteL(&KByte, 1);
       
  2010     
       
  2011     strm1.CommitL();
       
  2012     CleanupStack::PopAndDestroy(&strm1);
       
  2013     
       
  2014     //Read the record using a blob stream. MStreamBuf::SeekL() is used to read the content at a specific position.
       
  2015     RSqlBlobReadStream strm2;
       
  2016     CleanupClosePushL(strm2);
       
  2017     strm2.OpenL(TheDb1, _L("A"), _L("Fld2"));
       
  2018 
       
  2019     TUint8 byte = 0;
       
  2020     MStreamBuf* strm2buf = strm2.Source();
       
  2021     TEST(strm1buf != NULL);
       
  2022     
       
  2023     strm2buf->SeekL(MStreamBuf::ERead, EStreamBeginning, 0);
       
  2024     rc = strm2buf->ReadL(&byte, 1);
       
  2025     TEST2(rc, 1);
       
  2026     TEST2(byte, KByte);
       
  2027     
       
  2028     strm2buf->SeekL(MStreamBuf::ERead, EStreamMark, KStreamOffset);
       
  2029     rc = strm2buf->ReadL(&byte, 1);
       
  2030     TEST2(rc, 1);
       
  2031     TEST2(byte, KByte);
       
  2032     
       
  2033     strm2buf->SeekL(MStreamBuf::ERead, EStreamEnd, -KData().Length());
       
  2034     TUint8 buf[20];
       
  2035     rc = strm2buf->ReadL(buf, KData().Length());
       
  2036     TEST2(rc, KData().Length());
       
  2037     TPtrC8 bufptr(buf, rc);
       
  2038     TEST(bufptr == KData);
       
  2039     
       
  2040     strm2buf->SeekL(MStreamBuf::ERead, EStreamEnd, -4 * KStreamOffset);
       
  2041     rc = strm2buf->ReadL(&byte, 1);
       
  2042     TEST2(rc, 1);
       
  2043     TEST2(byte, KByte);
       
  2044     
       
  2045     CleanupStack::PopAndDestroy(&strm2);
       
  2046 	}
       
  2047 
  1962 void DoTestsL()
  2048 void DoTestsL()
  1963 	{	
  2049 	{	
  1964 	CreateTestDbs();
  2050 	CreateTestDbs();
  1965 
  2051 
  1966 	// Insert a zeroblob using RSqlStatement::BindZeroBlob() and read and write to it using streams
  2052 	// Insert a zeroblob using RSqlStatement::BindZeroBlob() and read and write to it using streams
  2013 	
  2099 	
  2014 	// Big blob test
  2100 	// Big blob test
  2015 	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-UT-4114: Big blob test"));
  2101 	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-UT-4114: Big blob test"));
  2016 	BigBlobTestL();
  2102 	BigBlobTestL();
  2017 		
  2103 		
       
  2104 	TheTest.Next(_L(" @SYMTestCaseID:PDS-SQL-CT-4194: Blob streams. MStreamBuf::SeekL() test"));
       
  2105 	StreamSeekTestL();
       
  2106 		
  2018 	DeleteTestDbs();
  2107 	DeleteTestDbs();
  2019 	}
  2108 	}
  2020 
  2109 
  2021 TInt E32Main()
  2110 TInt E32Main()
  2022 	{
  2111 	{