persistentstorage/sql/TEST/t_sqlapi.cpp
branchRCL_3
changeset 15 fcc16690f446
parent 12 6b6fd149daa2
child 16 b6ab70c1385f
equal deleted inserted replaced
14:04ec7606545c 15:fcc16690f446
   278 	
   278 	
   279 	RFs fs;
   279 	RFs fs;
   280 	TEST2(fs.Connect(), KErrNone);
   280 	TEST2(fs.Connect(), KErrNone);
   281 	TFileName privatePath;
   281 	TFileName privatePath;
   282 	TEST2(fs.PrivatePath(privatePath), KErrNone);
   282 	TEST2(fs.PrivatePath(privatePath), KErrNone);
   283 	fs.Close();
       
   284 	
   283 	
   285 	//Private shared database file on an existing drive (C:). 
   284 	//Private shared database file on an existing drive (C:). 
   286 	//Very long database file name.
   285 	//Very long database file name.
   287 	const TInt KMaxFileName2 = KMaxFileName - 40;//"-40" because the SQLITE engine creates a journal file if begins
   286 	TBuf<50>filesysname;
   288 	                                             //a transaction. The name of the journal file is 
   287 	fs.FileSystemName(filesysname,(TInt) EDriveC);
   289 	                                             //"<dbFileName>-journal.<ext>". It is obvious that if the 
   288     fs.Close();
   290 	                                             //database file name is too long but still valid and its creation
   289 
   291 	                                             //succeeds, the journal file creation may fail because the journal
   290 	RDebug::Print(_L("file system name = %S"), &filesysname);
   292 	                                             //file name becomes too long
   291 	TInt maxFileName = KMaxFileName -40;//"-40" because the SQLITE engine creates a journal file if begins
   293 	TBuf<KMaxFileName2> dbPath;
   292 	                                                 //a transaction. The name of the journal file is 
       
   293 	                                                 //"<dbFileName>-journal.<ext>". It is obvious that if the 
       
   294 	                                                 //database file name is too long but still valid and its creation
       
   295 	                                                 //succeeds, the journal file creation may fail because the journal
       
   296 	                                                 //file name becomes too long
       
   297 
       
   298 	if(filesysname.CompareF(_L("HVFS")) == 0)
       
   299 	    {
       
   300         maxFileName = KMaxFileName -150;//The test will panic in PlatSim when the file name is too long. This line should be removed when platsim team fixes the file system defect.
       
   301 	    }
       
   302 	HBufC* dbPath = HBufC::NewLC(maxFileName);
   294 	_LIT(KExt, ".DB");
   303 	_LIT(KExt, ".DB");
   295 	dbPath.Copy(_L("C:"));
   304 	dbPath->Des().Copy(_L("C:"));
   296 	dbPath.Append(KSecureUid.Name());
   305 	dbPath->Des().Append(KSecureUid.Name());
   297 	TInt len = KMaxFileName2 + 1 - (dbPath.Length() + KExt().Length() + privatePath.Length());
   306 	TInt len = maxFileName + 1 - (dbPath->Length() + KExt().Length() + privatePath.Length());
       
   307 	
   298 	while(--len)
   308 	while(--len)
   299 		{
   309 		{
   300 		dbPath.Append(TChar('A'));	
   310         dbPath->Des().Append(TChar('A'));	
   301 		}
   311 		}
   302 	dbPath.Append(KExt);	
   312 	dbPath->Des().Append(KExt);	
   303 	TEST(dbPath.Length() == (KMaxFileName2 - privatePath.Length()));
   313 	TEST(dbPath->Length() == (maxFileName - privatePath.Length()));	
   304 	rc = db.Create(dbPath, securityPolicy);
   314 	rc = db.Create(dbPath->Des(), securityPolicy);
   305 	db.Close();
   315 	TEST2(rc, KErrNone);
   306 	rc2 = RSqlDatabase::Delete(dbPath);
   316 	db.Close();
   307 	TEST2(rc, KErrNone);
   317 	rc2 = RSqlDatabase::Delete(dbPath->Des());
   308 	TEST2(rc2, KErrNone);
   318 	TEST2(rc2, KErrNone);
   309 	
   319 	
   310 	// Private database with config
   320 	// Private database with config
   311 	TBuf<KMaxFileName> cfgPath;
   321 	TBuf<KMaxFileName> cfgPath;
   312 	cfgPath.Copy(_L("C:"));
   322 	cfgPath.Copy(_L("C:"));
   318 	TEST2(rc, KErrNone);
   328 	TEST2(rc, KErrNone);
   319 	TEST2(rc2, KErrNone);
   329 	TEST2(rc2, KErrNone);
   320 	
   330 	
   321 	//Public shared database file on an existing drive (C:). 
   331 	//Public shared database file on an existing drive (C:). 
   322 	//Very long database file name.
   332 	//Very long database file name.
   323 	dbPath.Copy(_L("C:\\TEST\\D"));
   333 	dbPath->Des().Copy(_L("C:\\TEST\\D"));
   324 	len = KMaxFileName2 + 1 - (dbPath.Length() + KExt().Length());
   334 	len = maxFileName + 1 - (dbPath->Length() + KExt().Length());
   325 	while(--len)
   335 	while(--len)
   326 		{
   336 		{
   327 		dbPath.Append(TChar('A'));	
   337         dbPath->Des().Append(TChar('A'));	
   328 		}
   338 		}
   329 	dbPath.Append(KExt);	
   339 	dbPath->Des().Append(KExt);	
   330 	TEST(dbPath.Length() == KMaxFileName2);
   340 	TEST(dbPath->Length() == maxFileName);
   331 	rc = db.Create(dbPath);
   341 	rc = db.Create(dbPath->Des());
   332 	db.Close();
   342 	db.Close();
   333 	rc2 = RSqlDatabase::Delete(dbPath);
   343 	rc2 = RSqlDatabase::Delete(dbPath->Des());
       
   344 	
       
   345 	CleanupStack::PopAndDestroy(dbPath);
   334 	TEST2(rc, KErrNone);
   346 	TEST2(rc, KErrNone);
   335 	TEST2(rc2, KErrNone);
   347 	TEST2(rc2, KErrNone);
   336 
   348 
   337 	//Create/Close/Open/Close secure shared database test
   349 	//Create/Close/Open/Close secure shared database test
   338 	rc = db.Create(KTestDbName6, securityPolicy);
   350 	rc = db.Create(KTestDbName6, securityPolicy);
   395 	// this is because we can detect a corrupt database when we attempt to
   407 	// this is because we can detect a corrupt database when we attempt to
   396 	// set the configuration. If there is no cfg file, then there will be no
   408 	// set the configuration. If there is no cfg file, then there will be no
   397 	// attempt to set the pragmas and so the corrupt file is undetected
   409 	// attempt to set the pragmas and so the corrupt file is undetected
   398 	TEST(rc==KSqlErrNotDb || rc==KErrNone);
   410 	TEST(rc==KSqlErrNotDb || rc==KErrNone);
   399 	db.Close();
   411 	db.Close();
       
   412 
       
   413 	//An attempt to open database with name containing non-convertible characters.
       
   414     TBuf<6> invName;
       
   415     invName.SetLength(6);
       
   416     invName[0] = TChar('c'); 
       
   417     invName[1] = TChar(':'); 
       
   418     invName[2] = TChar('\\'); 
       
   419     invName[3] = TChar(0xD800); 
       
   420     invName[4] = TChar(0xFC00); 
       
   421     invName[5] = TChar(0x0000);
       
   422 	rc = db.Open(invName);
       
   423 	db.Close();
       
   424 	TEST(rc != KErrNone);
   400 
   425 
   401 	//Copy the corrupted database file on drive C:
   426 	//Copy the corrupted database file on drive C:
   402 	TEST2(fs.Connect(), KErrNone);
   427 	TEST2(fs.Connect(), KErrNone);
   403 	rc = BaflUtils::CopyFile(fs, KDbPath10, KTestDbName3);
   428 	rc = BaflUtils::CopyFile(fs, KDbPath10, KTestDbName3);
   404 	TEST2(rc, KErrNone);
   429 	TEST2(rc, KErrNone);
  1079 
  1104 
  1080 	//Move on row 1
  1105 	//Move on row 1
  1081 	rc = stmt.Next();
  1106 	rc = stmt.Next();
  1082 	TEST2(rc, KSqlAtRow);
  1107 	TEST2(rc, KSqlAtRow);
  1083 
  1108 
       
  1109 	//An attempt to read integer column using binary stream
       
  1110 	RSqlColumnReadStream strm2;
       
  1111 	rc = strm2.ColumnBinary(stmt, 0);
       
  1112 	strm2.Close();
       
  1113 	TEST2(rc, KErrArgument);
       
  1114 
       
  1115 	//An attempt to read integer column using text stream
       
  1116 	rc = strm2.ColumnText(stmt, 0);
       
  1117 	strm2.Close();
       
  1118 	TEST2(rc, KErrArgument);
       
  1119 	
  1084 	//Read the long text column using a stream
  1120 	//Read the long text column using a stream
  1085 	RSqlColumnReadStream columnStream;
  1121 	RSqlColumnReadStream columnStream;
  1086 	rc = columnStream.ColumnText(stmt, 1);
  1122 	rc = columnStream.ColumnText(stmt, 1);
  1087 	columnStream.Close();
  1123 	columnStream.Close();
  1088 	TEST2(rc, KErrNone);
  1124 	TEST2(rc, KErrNone);
  2349 	TEST(size.iFree >= 0);
  2385 	TEST(size.iFree >= 0);
  2350 	db.Close();
  2386 	db.Close();
  2351 	(void)RSqlDatabase::Delete(KTestDbName1);
  2387 	(void)RSqlDatabase::Delete(KTestDbName1);
  2352 	}
  2388 	}
  2353 
  2389 
       
  2390 /**
       
  2391 @SYMTestCaseID			PDS-SQL-CT-4205
       
  2392 @SYMTestCaseDesc		"PRAGMA count_changes" test.
       
  2393 						When "count_changes" pragma is ON, sqlite3_step() is called two times by the 
       
  2394 						SQL server, before getting the SQLITE_DONE return code.
       
  2395 						Everything else is the same (statement processing, etc.).
       
  2396 @SYMTestPriority		High
       
  2397 @SYMTestActions			"PRAGMA count_changes" test.
       
  2398 @SYMTestExpectedResults Test must not fail
       
  2399 */
       
  2400 void CountChangesTest()
       
  2401 	{
       
  2402 	(void)RSqlDatabase::Delete(KTestDbName1);
       
  2403 	RSqlDatabase db;
       
  2404 	TInt err = db.Create(KTestDbName1);
       
  2405 	TEST2(err, KErrNone);
       
  2406 	err = db.Exec(_L("CREATE TABLE A(I INTEGER)"));
       
  2407 	TEST(err >= 0);
       
  2408 	
       
  2409 	err = db.Exec(_L("PRAGMA count_changes=ON"));
       
  2410 	TEST(err >= 0);
       
  2411 	
       
  2412 	err = db.Exec(_L("INSERT INTO A VALUES(1)"));
       
  2413 	TEST2(err, 1);
       
  2414 	
       
  2415 	err = db.Exec(_L8("INSERT INTO A VALUES(2)"));
       
  2416 	TEST2(err, 1);
       
  2417 	
       
  2418 	RSqlStatement stmt;
       
  2419 	err = stmt.Prepare(db, _L("DELETE FROM A WHERE I>=1 AND I<=2"));
       
  2420 	TEST2(err, KErrNone);
       
  2421 	err = stmt.Exec();
       
  2422 	TEST2(err, 2);
       
  2423 	stmt.Close();
       
  2424 	
       
  2425 	err = db.Exec(_L("PRAGMA count_changes=OFF"));
       
  2426 	TEST(err >= 0);
       
  2427 	
       
  2428 	db.Close();
       
  2429 	(void)RSqlDatabase::Delete(KTestDbName1);
       
  2430 	}
       
  2431 
  2354 void DoTestsL()
  2432 void DoTestsL()
  2355 	{
  2433 	{
  2356 	TheTest.Start(_L(" @SYMTestCaseID:SYSLIB-SQL-CT-1601 Create/Open/Close database tests "));
  2434 	TheTest.Start(_L(" @SYMTestCaseID:SYSLIB-SQL-CT-1601 Create/Open/Close database tests "));
  2357 	OpenCloseDatabaseTest();
  2435 	OpenCloseDatabaseTest();
  2358 
  2436 
  2418 	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-UT-4040 RSqlDatabase::Size(RSqlDatabase::TSize&) - attached database tests"));
  2496 	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-UT-4040 RSqlDatabase::Size(RSqlDatabase::TSize&) - attached database tests"));
  2419 	AttachedSizeTest2();
  2497 	AttachedSizeTest2();
  2420 	
  2498 	
  2421 	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-UT-4041 RSqlDatabase::Size(RSqlDatabase::TSize&) - different compaction modes tests"));
  2499 	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-UT-4041 RSqlDatabase::Size(RSqlDatabase::TSize&) - different compaction modes tests"));
  2422 	DiffCompactModeSize2Test();
  2500 	DiffCompactModeSize2Test();
       
  2501 
       
  2502 	TheTest.Next(_L(" @SYMTestCaseID:PDS-SQL-CT-4205 PRAGMA \"count_changes\" test"));
       
  2503 	CountChangesTest();
  2423 	}
  2504 	}
  2424 
  2505 
  2425 TInt E32Main()
  2506 TInt E32Main()
  2426 	{
  2507 	{
  2427 	TheTest.Title();
  2508 	TheTest.Title();