1335 // |
1335 // |
1336 fbuf.Close(); |
1336 fbuf.Close(); |
1337 (void)TheFs.Delete(KTestFile); |
1337 (void)TheFs.Delete(KTestFile); |
1338 } |
1338 } |
1339 |
1339 |
|
1340 /////////////////////////////////////////////////////////////////////////////////////// |
|
1341 |
|
1342 #ifdef _DEBUG |
|
1343 |
|
1344 //Panic thread function. |
|
1345 //It will cast aData parameter to a TFunctor pointer and call it. |
|
1346 //The expectation is that the called function will panic and kill the panic thread. |
|
1347 TInt ThreadFunc(void* aData) |
|
1348 { |
|
1349 CTrapCleanup* tc = CTrapCleanup::New(); |
|
1350 TEST(tc != NULL); |
|
1351 |
|
1352 User::SetJustInTime(EFalse); // disable debugger panic handling |
|
1353 |
|
1354 TFunctor* obj = reinterpret_cast<TFunctor*> (aData); |
|
1355 TEST(obj != NULL); |
|
1356 (*obj)();//call the panic function |
|
1357 |
|
1358 delete tc; |
|
1359 |
|
1360 return KErrNone; |
|
1361 } |
|
1362 |
|
1363 //Panic test. |
|
1364 //PanicTest function will create a new thread - panic thread, giving it a pointer to the function which has to |
|
1365 //be executed and the expectation is that the function will panic and kill the panic thread. |
|
1366 //PanicTest function will check the panic thread exit code, exit category and the panic code. |
|
1367 void PanicTest(TFunctor& aFunctor, TExitType aExpectedExitType, const TDesC& aExpectedCategory, TInt aExpectedPanicCode) |
|
1368 { |
|
1369 RThread thread; |
|
1370 _LIT(KThreadName,"SqlFileBufPanicThread"); |
|
1371 TEST2(thread.Create(KThreadName, &ThreadFunc, 0x2000, 0x1000, 0x10000, (void*)&aFunctor, EOwnerThread), KErrNone); |
|
1372 |
|
1373 TRequestStatus status; |
|
1374 thread.Logon(status); |
|
1375 TEST2(status.Int(), KRequestPending); |
|
1376 thread.Resume(); |
|
1377 User::WaitForRequest(status); |
|
1378 User::SetJustInTime(ETrue); // enable debugger panic handling |
|
1379 |
|
1380 TEST2(thread.ExitType(), aExpectedExitType); |
|
1381 TEST(thread.ExitCategory() == aExpectedCategory); |
|
1382 TEST2(thread.ExitReason(), aExpectedPanicCode); |
|
1383 |
|
1384 CLOSE_AND_WAIT(thread); |
|
1385 } |
|
1386 |
|
1387 //////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
1388 ////////////////////////////// Panic test functions ///////////////////////////////////////////////// |
|
1389 //////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
1390 |
|
1391 //Panic when calling RFileBuf64::RFileBuf64() with an invalid buffer capacity value. |
|
1392 class TSqlFileBuf_InvalidCapacity : public TFunctor |
|
1393 { |
|
1394 private: |
|
1395 virtual void operator()() |
|
1396 { |
|
1397 RFileBuf64 fbuf(-8192);//panic here - "-8192" - negative buffer capacity |
|
1398 } |
|
1399 }; |
|
1400 static TSqlFileBuf_InvalidCapacity TheSqlFileBuf_InvalidCapacity; |
|
1401 |
|
1402 //Panic when calling RFileBuf64::Create() with an invalid file handle. |
|
1403 class TSqlFileBuf_InvalidFileHandle1 : public TFunctor |
|
1404 { |
|
1405 private: |
|
1406 virtual void operator()() |
|
1407 { |
|
1408 RFileBuf64 fbuf(8192); |
|
1409 RFs fs; |
|
1410 fbuf.Create(fs, _L("aaa.db"), EFileRead);//panic here - invalid file handle |
|
1411 } |
|
1412 }; |
|
1413 static TSqlFileBuf_InvalidFileHandle1 TheSqlFileBuf_InvalidFileHandle1; |
|
1414 |
|
1415 //Panic when calling RFileBuf64::Create() with an invalid file name. |
|
1416 class TSqlFileBuf_InvalidFileName1 : public TFunctor |
|
1417 { |
|
1418 private: |
|
1419 virtual void operator()() |
|
1420 { |
|
1421 RFileBuf64 fbuf(8192); |
|
1422 RFs fs; |
|
1423 TInt err = fs.Connect(); |
|
1424 TEST2(err, KErrNone); |
|
1425 fbuf.Create(fs, KNullDesC, EFileRead);//panic here - invalid file name |
|
1426 fs.Close(); |
|
1427 } |
|
1428 }; |
|
1429 static TSqlFileBuf_InvalidFileName1 TheSqlFileBuf_InvalidFileName1; |
|
1430 |
|
1431 //Panic when calling RFileBuf64::Open() with an invalid file handle. |
|
1432 class TSqlFileBuf_InvalidFileHandle2 : public TFunctor |
|
1433 { |
|
1434 private: |
|
1435 virtual void operator()() |
|
1436 { |
|
1437 RFileBuf64 fbuf(8192); |
|
1438 RFs fs; |
|
1439 fbuf.Open(fs, _L("aaa.db"), EFileRead);//panic here - invalid file handle |
|
1440 } |
|
1441 }; |
|
1442 static TSqlFileBuf_InvalidFileHandle2 TheSqlFileBuf_InvalidFileHandle2; |
|
1443 |
|
1444 //Panic when calling RFileBuf64::Open() with an invalid file name. |
|
1445 class TSqlFileBuf_InvalidFileName2 : public TFunctor |
|
1446 { |
|
1447 private: |
|
1448 virtual void operator()() |
|
1449 { |
|
1450 RFileBuf64 fbuf(8192); |
|
1451 RFs fs; |
|
1452 TInt err = fs.Connect(); |
|
1453 TEST2(err, KErrNone); |
|
1454 fbuf.Open(fs, KNullDesC, EFileRead);//panic here - invalid file name |
|
1455 fs.Close(); |
|
1456 } |
|
1457 }; |
|
1458 static TSqlFileBuf_InvalidFileName2 TheSqlFileBuf_InvalidFileName2; |
|
1459 |
|
1460 //Panic when calling RFileBuf64::Temp() with an invalid file handle. |
|
1461 class TSqlFileBuf_InvalidFileHandle3 : public TFunctor |
|
1462 { |
|
1463 private: |
|
1464 virtual void operator()() |
|
1465 { |
|
1466 RFileBuf64 fbuf(8192); |
|
1467 RFs fs; |
|
1468 TFileName fname; |
|
1469 fbuf.Temp(fs, _L("c:\\test"), fname, EFileRead);//panic here - invalid file handle |
|
1470 } |
|
1471 }; |
|
1472 static TSqlFileBuf_InvalidFileHandle3 TheSqlFileBuf_InvalidFileHandle3; |
|
1473 |
|
1474 //Panic when calling RFileBuf64::AdoptFromClient() with an invalid message handle. |
|
1475 class TSqlFileBuf_InvalidMessageHandle : public TFunctor |
|
1476 { |
|
1477 private: |
|
1478 virtual void operator()() |
|
1479 { |
|
1480 RFileBuf64 fbuf(8192); |
|
1481 RMessage2 msg; |
|
1482 fbuf.AdoptFromClient(msg, 0, 1);//panic here - invalid message handle |
|
1483 } |
|
1484 }; |
|
1485 static TSqlFileBuf_InvalidMessageHandle TheSqlFileBuf_InvalidMessageHandle; |
|
1486 |
|
1487 //Panic when calling RFileBuf64::Read() with an invalid file position. |
|
1488 class TSqlFileBuf_InvalidReadPos : public TFunctor |
|
1489 { |
|
1490 private: |
|
1491 virtual void operator()() |
|
1492 { |
|
1493 RFileBuf64 fbuf(8192); |
|
1494 TBuf8<50> buf; |
|
1495 fbuf.Read(-1024, buf);//panic here - invalid file position |
|
1496 } |
|
1497 }; |
|
1498 static TSqlFileBuf_InvalidReadPos TheSqlFileBuf_InvalidReadPos; |
|
1499 |
|
1500 //Panic when calling RFileBuf64::Write() with an invalid file position. |
|
1501 class TSqlFileBuf_InvalidWritePos : public TFunctor |
|
1502 { |
|
1503 private: |
|
1504 virtual void operator()() |
|
1505 { |
|
1506 RFileBuf64 fbuf(8192); |
|
1507 TBuf8<50> buf; |
|
1508 fbuf.Write(-1024, buf);//panic here - invalid file position |
|
1509 } |
|
1510 }; |
|
1511 static TSqlFileBuf_InvalidWritePos TheSqlFileBuf_InvalidWritePos; |
|
1512 |
|
1513 //Panic when calling RFileBuf64::SetSize() with an invalid file size. |
|
1514 class TSqlFileBuf_InvalidSize : public TFunctor |
|
1515 { |
|
1516 private: |
|
1517 virtual void operator()() |
|
1518 { |
|
1519 RFileBuf64 fbuf(8192); |
|
1520 TBuf8<50> buf; |
|
1521 fbuf.SetSize(-1024);//panic here - invalid file size |
|
1522 } |
|
1523 }; |
|
1524 static TSqlFileBuf_InvalidSize TheSqlFileBuf_InvalidSize; |
|
1525 |
|
1526 #endif //_DEBUG |
|
1527 |
|
1528 /** |
|
1529 @SYMTestCaseID PDS-SQL-UT-4236 |
|
1530 @SYMTestCaseDesc RFileBuf64 panic test. |
|
1531 The test runs a thread. The thread will create a RFileBuf64 object |
|
1532 and put the object in a situation where the file buffer cannot perform |
|
1533 its duties anymore and will raise a panic. The test verifies that the file |
|
1534 buffer implementation properly detects anomalities such as bad parameters, |
|
1535 null handles, etc... |
|
1536 @SYMTestActions RFileBuf64 panic test. |
|
1537 @SYMTestExpectedResults Test must not fail |
|
1538 @SYMTestPriority High |
|
1539 */ |
|
1540 void FileBufPanicTest() |
|
1541 { |
|
1542 #ifdef _DEBUG |
|
1543 _LIT(KPanicCategory, "FBuf64"); |
|
1544 PanicTest(TheSqlFileBuf_InvalidCapacity, EExitPanic, KPanicCategory, 1); |
|
1545 PanicTest(TheSqlFileBuf_InvalidFileHandle1, EExitPanic, KPanicCategory, 7); |
|
1546 PanicTest(TheSqlFileBuf_InvalidFileName1, EExitPanic, KPanicCategory, 10); |
|
1547 PanicTest(TheSqlFileBuf_InvalidFileHandle2, EExitPanic, KPanicCategory, 7); |
|
1548 PanicTest(TheSqlFileBuf_InvalidFileName2, EExitPanic, KPanicCategory, 10); |
|
1549 PanicTest(TheSqlFileBuf_InvalidFileHandle3, EExitPanic, KPanicCategory, 7); |
|
1550 PanicTest(TheSqlFileBuf_InvalidMessageHandle, EExitPanic, KPanicCategory, 8); |
|
1551 PanicTest(TheSqlFileBuf_InvalidReadPos, EExitPanic, KPanicCategory, 4); |
|
1552 PanicTest(TheSqlFileBuf_InvalidWritePos, EExitPanic, KPanicCategory, 4); |
|
1553 PanicTest(TheSqlFileBuf_InvalidSize, EExitPanic, KPanicCategory, 5); |
|
1554 #else //_DEBUG |
|
1555 TheTest.Printf(_L("This test can be run in _DEBUG mode only!")); |
|
1556 #endif//_DEBUG |
|
1557 } |
|
1558 |
1340 void DoTests() |
1559 void DoTests() |
1341 { |
1560 { |
1342 TheTest.Start(_L(" @SYMTestCaseID:PDS-SQL-UT-4132 RFileBuf64 write test 1")); |
1561 TheTest.Start(_L(" @SYMTestCaseID:PDS-SQL-UT-4132 RFileBuf64 write test 1")); |
1343 WriteTest1(); |
1562 WriteTest1(); |
1344 TheTest.Next( _L(" @SYMTestCaseID:PDS-SQL-UT-4133 RFileBuf64 write test 2")); |
1563 TheTest.Next( _L(" @SYMTestCaseID:PDS-SQL-UT-4133 RFileBuf64 write test 2")); |