Пример #1
0
CPosLandmarkCategory* CPosTp147::CreateDummyCategoryLC()
{
    CPosLandmarkCategory* cat = CPosLandmarkCategory::NewLC();

    TInt KCatId = cat->CategoryId();
    _LIT(KName, "Name");
    _LIT(KIcon, "IconFile");
    const TInt KIconIndex = 1, KIconMaskIndex = 2;
    cat->SetCategoryNameL(KName);
    cat->SetIconL(KIcon, KIconIndex, KIconMaskIndex);
    return cat;
}
// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
//
EXPORT_C CPosLandmarkCategory* PosLmCategorySerialization::UnpackL( const TDesC8& aBuffer )
    {
    TPckgBuf<TCategoryBufferHeader> header;

    CPosLandmarkCategory* cat = CPosLandmarkCategory::NewLC();
    CPosReadBufStorage* buf = CPosReadBufStorage::NewLC( aBuffer );
    
    buf->GetL( header );

    if ( header().iSize != aBuffer.Size() ||
         header().iVersion != KVersion )
        {
        User::Leave( KErrCorrupt );
        }

    cat->SetCategoryIdL( header().iId );
    cat->SetGlobalCategory( header().iGlobalCategory );

    // strings
    TPtrC name, icon;

    buf->GetL( name );
    buf->GetL( icon );

    if ( name.Length() )
        {
        cat->SetCategoryNameL( name );
        }
        
    if ( header().iIsIconSet )
        {
        cat->SetIconL( icon, header().iIconIndex, header().iIconMaskIndex );
        }
    
    // cleanup
    CleanupStack::PopAndDestroy( buf );
    CleanupStack::Pop( cat );
    return cat;
    }
Пример #3
0
// ---------------------------------------------------------
// CPosTp29::DoOutOfDiskTestL
//
// (other items were commented in a header).
// ---------------------------------------------------------
//
void CPosTp29::DoOutOfDiskTestL(TBool aSync)
    {
    TVolumeInfo volumeInfo;
    TBuf<200> buf;
    CPosLmOperation* op = NULL;

    _LIT(KUID,"Unique ID: %08x\r\n");
	_LIT(KSize,"Size: %d bytes\r\n");
	_LIT(KFree,"Free space: %d bytes\r\n");
	//_LIT(KVolName,"Volume name: %S\r\n");

    TInt err=iFileServer.Volume(volumeInfo, EDriveC);
    if (err != KErrNone) iLog->Put(_L("Error from iFileServer"));

    buf.AppendFormat(KUID, volumeInfo.iUniqueID);
	buf.AppendFormat(KSize, volumeInfo.iSize);
	buf.AppendFormat(KFree, volumeInfo.iFree);
	//buf.AppendFormat(KVolName, &volumeInfo.iName);
    iLog->Put(buf);

    TTime startTime;
    TTime stopTime;

    // Just in case
    ExecuteAndDeleteLD(iLandmarksDb->CompactL());

    RArray<TPosLmItemId> lmIdArray;
    CleanupClosePushL(lmIdArray);

    // 1) Create a low disc space situation
    startTime.UniversalTime();
    ConsumeDiscSpace1L(iCriticalLevel + KSizeLimitOffset1);
    ConsumeDiscSpace2L(iCriticalLevel + KSizeLimitOffset2);
    
    err=iFileServer.Volume(volumeInfo, EDriveC);
    if (err != KErrNone) iLog->Put(_L("Error from iFileServer"));
    buf.AppendFormat(KUID, volumeInfo.iUniqueID);
	buf.AppendFormat(KSize, volumeInfo.iSize);
	buf.AppendFormat(KFree, volumeInfo.iFree);
    iLog->Put(buf);

    stopTime.UniversalTime();
    TTimeIntervalMicroSeconds executionTime = 
        stopTime.MicroSecondsFrom(startTime);

    TInt resse = executionTime.Int64()/1000000;
    buf.Zero();
    buf.Format(_L("ConsumeDiscSpaceL took %d seconds"), resse);
    iLog->Put(buf);

    // 2) Add Landmarks until "disk full" error occur
    if (iLandmarksDb->IsInitializingNeeded())
        {
        iLog->Put(_L("InitializeL"));
        // Synchronous 
        ExecuteAndDeleteLD(iLandmarksDb->InitializeL());        
        }

    CPosLandmark* landmark = CPosLandmark::NewLC();
    landmark->SetLandmarkNameL(_L("LandMarkName1"));
    iLog->Put(_L("Adding landmark1"));
    lmIdArray.Append(iLandmarksDb->AddLandmarkL(*landmark));
    CleanupStack::Pop(landmark);

    landmark = CPosLandmark::NewLC();
    landmark->SetLandmarkNameL(_L("LandMarkName2"));
    iLog->Put(_L("Adding landmark2"));
    lmIdArray.Append(iLandmarksDb->AddLandmarkL(*landmark));
    CleanupStack::Pop(landmark);
    err = KErrNone;
    TPosLmItemId idde;
    TInt i=0;
    
    startTime.UniversalTime();
    iLog->Put(_L("Adding landmark until KErrDiskFull.....1"));
    // some while loop adding landmarks here until "disk full" error occur!!!
    while (err != KErrDiskFull)
        {
        buf.Zero();
        buf.Format(_L("Land Mark___________%d"), i++);
        landmark = CPosLandmark::NewLC();
        landmark->SetLandmarkNameL(buf);
        TRAP(err, idde = iLandmarksDb->AddLandmarkL(*landmark));
        if (err == KErrNone)
            {
            lmIdArray.Append(idde);
            }
        else if (err == KErrLocked) 
            {
            iLog->Put(_L("KErrLocked when adding 1"));
            User::After(100000);
            }
        CleanupStack::Pop(landmark);
        }
    stopTime.UniversalTime();
    executionTime = stopTime.MicroSecondsFrom(startTime);
    resse = executionTime.Int64()/1000000;
    buf.Zero();
    buf.Format(_L("Added %d nr of landmarks, took %d seconds"), i, resse);
    iLog->Put(buf);

    // Check that the filesize limit has not been exceeded 
    err=iFileServer.Volume(volumeInfo, EDriveC);
    buf.Zero();
	buf.AppendFormat(KFree, volumeInfo.iFree);
    iLog->Put(buf);
    if (volumeInfo.iFree < iCriticalLevel)
        {
        LogErrorAndLeave(_L("The max size limit has been exceeded!!!"));
        }

    //Check that the added landmarks can be read
    iLog->Put(_L("Check that it is possible to read landmark"));
    TInt nrOfLandmarks = lmIdArray.Count();
    TInt p=0;
    for (p=0;p<nrOfLandmarks;p++)
        {
        landmark = iLandmarksDb->ReadLandmarkLC(lmIdArray[p]);
        CleanupStack::Pop(landmark);
        }

    // 3) Remove two landmarks and compress landmarks db
    TInt nr = lmIdArray.Count()-1;
    TPosLmItemId id = lmIdArray[nr];
    iLog->Put(_L("Removing landmark1"));
    lmIdArray.Remove(nr);
    TRAP(err, iLandmarksDb->RemoveLandmarkL(id));
    if (err == KErrDiskFull) 
        {
        ExecuteAndDeleteLD(iLandmarksDb->CompactL());

        iLandmarksDb->RemoveLandmarkL(id);
        iLog->Put(_L("DiskFull when removing1"));
        }

    nr = lmIdArray.Count() - 1;
    id = lmIdArray[nr];
    iLog->Put(_L("Removing landmark2"));
    lmIdArray.Remove(nr);
    iLandmarksDb->RemoveLandmarkL(id);
    TRAP(err, iLandmarksDb->RemoveLandmarkL(id));
    if (err == KErrDiskFull) 
        {
        ExecuteAndDeleteLD(iLandmarksDb->CompactL());
        
        iLandmarksDb->RemoveLandmarkL(id);
        iLog->Put(_L("DiskFull when removing2"));
        }
    err = KErrNone;
    iLog->Put(_L("Compacting"));
    ExecuteAndDeleteLD(iLandmarksDb->CompactL());
    
    startTime.UniversalTime();
    iLog->Put(_L("Adding landmark until KErrDiskFull.....2"));
    // 4) Add landmarks until "disk full" error occur!!!
    while (err != KErrDiskFull)
        {
        buf.Zero();
        buf.Format(_L("Land Mark___________%d"), i++);
        landmark = CPosLandmark::NewLC();
        landmark->SetLandmarkNameL(buf);
        //iLog->Put(_L("Adding landmark id to idArray"));
        TRAP(err, idde = iLandmarksDb->AddLandmarkL(*landmark));
        if (err == KErrNone)
            {
            lmIdArray.Append(idde);
            }
        else if (err == KErrLocked) 
            {
            iLog->Put(_L("KErrLocked when adding 2"));
            User::After(100000);
            }
        CleanupStack::Pop(landmark);
        }

    stopTime.UniversalTime();
    executionTime = stopTime.MicroSecondsFrom(startTime);
    resse = executionTime.Int64()/1000000;
    buf.Zero();
    buf.Format(_L("Added %d nr of landmarks, took %d seconds"), i, resse);
    iLog->Put(buf);

    iLog->Put(_L("Check that it is possible to read landmark"));
    //Check that the added landmarks can be read
    nrOfLandmarks = lmIdArray.Count();
    for (p=0;p<nrOfLandmarks;p++)
        {
        landmark = iLandmarksDb->ReadLandmarkLC(lmIdArray[p]);
        CleanupStack::Pop(landmark);
        }

    iLog->Put(_L("Remove all landmarks"));
    err = KErrNone;
    // 5) Remove all landmarks and compact database
    if (!aSync)
        {
        TRAP(err, op = iLandmarksDb->RemoveAllLandmarksL());
        if (err == KErrNone) 
            {
            ExecuteAndDeleteLD(op);
            }
        else if (err == KErrDiskFull)
            {
            iLog->Put(_L("KErrDiskFull when removing all landmarks"));
            ExecuteAndDeleteLD(iLandmarksDb->CompactL());
            
            // Delete KFile2 to free more space on disc, method also open connection to iFile2 again
            DeleteFile2L();

            iLog->Put(_L("Removing after Compact sync"));
            TRAP(err, op = iLandmarksDb->RemoveAllLandmarksL());
            if (err == KErrDiskFull)
                {
                iLog->Put(_L("KErrDiskFull when Removing all landmarks after compact1"));
                RemoveAllLandmarksL();
                }
            else
                {
                ExecuteAndDeleteLD(op);
                }
            }
        }
    else
        {
        iLog->Put(_L("Before RemoveAllLandmarksL(this)"));
        TRAP(err, op = iLandmarksDb->RemoveAllLandmarksL());
        
        if (err == KErrNone) 
            {
            //***iActiveSchedulerWait->Start();
            //***delete op; op=NULL;
            RunAsyncOperationLD(op);
            }
        else if (err == KErrDiskFull)
            {
            iLog->Put(_L("KErrDiskFull when removing all landmarks"));
            ExecuteAndDeleteLD(iLandmarksDb->CompactL());
            
            // Delete KFile2 to free more space on disc, method also open connection to iFile2 again
            DeleteFile2L();

            iLog->Put(_L("Removing after Compact async"));
            TRAP(err, op = iLandmarksDb->RemoveAllLandmarksL());
            if (err == KErrDiskFull)
                {
                iLog->Put(_L("KErrDiskFull when removing all landmarks after compact2"));
                RemoveAllLandmarksL();
                }
            else
                {
                //***iActiveSchedulerWait->Start();
                //***delete op; op=NULL;
                RunAsyncOperationLD(op);
                }
            }
        iLog->Put(_L("After RemoveAllLandmarksL(this)"));
        }
    
    ConsumeDiscSpace2L(iCriticalLevel + KSizeLimitOffset2);

    if (err == KErrDiskFull) iLog->Put(_L("KErrDiskFull when RemoveAllLandmarksL"));
    iLog->Put(_L("Compacting"));
    ExecuteAndDeleteLD(iLandmarksDb->CompactL());
    
    lmIdArray.Reset();
    i=0;
    err = KErrNone;
    startTime.UniversalTime();
    iLog->Put(_L("Adding landmarkcategories until KErrDiskFull....."));

    // 6) Add LandmarkCategories until "disk full" error occur
    while (err != KErrDiskFull)
        {
        buf.Zero();
        buf.Format(_L("Landmark Category _________ %d"), i++);
        CPosLandmarkCategory* lmc = CPosLandmarkCategory::NewLC();
        lmc->SetCategoryNameL(buf);
        lmc->SetIconL(_L("Pelles Icon"), 111, KPosLmIconMaskNotUsed);

        TRAP(err, idde = iCategoryManager->AddCategoryL(*lmc));
        if (err == KErrNone)
            {
            lmIdArray.Append(idde);
            }
        else if (err== KErrLocked)
            {
            iLog->Put(_L("KErrLocked when adding category"));
            User::After(100000);
            }
        CleanupStack::PopAndDestroy(lmc);
        }

    stopTime.UniversalTime();
    executionTime = stopTime.MicroSecondsFrom(startTime);

    resse = executionTime.Int64()/1000000;
    buf.Zero();
    buf.Format(_L("Added %d nr of landmarkcategories, took %d seconds"), i, resse);
    iLog->Put(buf);

    //Check that the added landmarkcategories can be read
    TInt nrOfCategories = lmIdArray.Count();
    for (p=0;p<nrOfCategories;p++)
        {
        CPosLandmarkCategory* lmc = iCategoryManager->ReadCategoryLC(lmIdArray[p]);
        CleanupStack::Pop(lmc);
        }

    // 7) Remove two categories and compress landmarks db
    nr = lmIdArray.Count()-1;
    id = lmIdArray[nr];
    iLog->Put(_L("Removing landmarkcategory1"));
    lmIdArray.Remove(nr);
    op=NULL;
    TRAP(err, op = iCategoryManager->RemoveCategoryL(id));
    if (err == KErrDiskFull)
        {
        ExecuteAndDeleteLD(iLandmarksDb->CompactL());
        ExecuteAndDeleteLD(iCategoryManager->RemoveCategoryL(id));
        iLog->Put(_L("KErrDiskFull when removing landmarkcategory1"));
        }

    if (err == KErrNone)
        {
        ExecuteAndDeleteLD(op);
        }
    else
        {
        delete op;
        op = NULL;
        }

    TBuf<50> buffe;
    buffe.Format(_L("1) Err after RemoveCategoryL: %d"), err);
    iLog->Put(buffe);

    nr = lmIdArray.Count()-1;
    id = lmIdArray[nr];
    iLog->Put(_L("Removing landmarkcategory2"));
    lmIdArray.Remove(nr);

    if (!aSync)
        {
        TRAP(err, op = iCategoryManager->RemoveCategoryL(id));
        if (err == KErrDiskFull)
            {
            delete op;
            op = NULL;
            iLog->Put(_L("KErrDiskFull when removing landmarkcategory2"));
            ExecuteAndDeleteLD(iLandmarksDb->CompactL());
            
            iLog->Put(_L("After compact before removing landmarkcategory2"));
            ExecuteAndDeleteLD(iCategoryManager->RemoveCategoryL(id));
            }
        else if (err == KErrNone)
            {
            ExecuteAndDeleteLD(op);
            }
        else if (err == KErrLocked)
            {
            iLog->Put(_L("KErrLocked returned from iCategoryManager->RemoveCategoryL"));
            delete op;
            op = NULL;
            }
        } 
    else
        {
        TRAP(err, op = iCategoryManager->RemoveCategoryL(id));
        if (err == KErrNone)
            {
            //***iActiveSchedulerWait->Start();
            //***delete op;
            RunAsyncOperationLD(op);
            }
        else if (err == KErrDiskFull)
            {
            delete op;
            op = NULL;
            iLog->Put(_L("KErrDiskFull when removing landmarkcategory2 async"));
            ExecuteAndDeleteLD(iLandmarksDb->CompactL());
            
            iLog->Put(_L("After compact before removing landmarkcategory2 async"));
            op = iCategoryManager->RemoveCategoryL(id);
            
            //***iActiveSchedulerWait->Start();
            //***delete op;
            RunAsyncOperationLD(op);
            }
        else if (err == KErrLocked)
            {
            delete op;
            op = NULL;
            iLog->Put(_L("KErrLocked returned from iCategoryManager->RemoveCategoryL"));
            }
        }

    buffe.Zero();
    buffe.Format(_L("2) Err after RemoveCategoryL: %d"), err);
    iLog->Put(buffe);

    iLog->Put(_L("Compacting"));
    ExecuteAndDeleteLD(iLandmarksDb->CompactL());
    iLog->Put(_L("After Compacting"));
    
    lmIdArray.Reset();
    i=0;
    err = KErrNone;

    startTime.UniversalTime();
    // 8) Add LandmarkCategories until "disk full" error occur
    while (err != KErrDiskFull)
        {
        buf.Zero();
        buf.Format(_L("LandmarkCategory %d"), i++);

        CPosLandmarkCategory* lmc = CPosLandmarkCategory::NewLC();
        lmc->SetCategoryNameL(buf);
        lmc->SetIconL(_L("PellesIcon"), 111, KPosLmIconMaskNotUsed);
        iLog->Put(buf);
        
        TRAP(err, idde = iCategoryManager->AddCategoryL(*lmc));
        if (err == KErrNone)
            {
            lmIdArray.Append(idde);
            }
        else if (err == KErrLocked)
            {
            iLog->Put(_L("KerrLocked when addCategory"));
            User::After(100000);
            }
        CleanupStack::PopAndDestroy(lmc); 
    }
    stopTime.UniversalTime();
    executionTime = stopTime.MicroSecondsFrom(startTime);

    resse = executionTime.Int64()/1000000;
    buf.Zero();
    buf.Format(_L("Added %d nr of landmarkcategories, took %d seconds"), i, resse);
    iLog->Put(buf);

    // 9) Remove all categories and compact db
    // sync method
    // XXXX add async check here
    iLog->Put(_L("Removing all categories"));
    TRAP(err, iCategoryManager->RemoveCategoriesL(lmIdArray));
    if (err == KErrDiskFull) iLog->Put(_L("KErrDiskFull when RemoveCategoriesL"));
    iLog->Put(_L("Compacting"));
    ExecuteAndDeleteLD(iLandmarksDb->CompactL());
    

    // 10) Consume more space then the limit specified in resource file
    ConsumeDiscSpace1L(iCriticalLevel - KSizeLimitOffset2);

    // 11) Try to add a landmark
    buf.Zero();
    buf.Format(_L("LandMark%d"), i++);
    landmark = CPosLandmark::NewLC();
    landmark->SetLandmarkNameL(buf);

    TRAP(err, idde = iLandmarksDb->AddLandmarkL(*landmark));
    if (err != KErrDiskFull)
        {
        buf.Zero();
        buf.Format(_L("Should leave with KErrDiskFull instead %d"), err);
        //LogErrorAndLeave(buf);
        LogErrorAndLeave(buf);
        }
    CleanupStack::PopAndDestroy(landmark);
    CleanupStack::PopAndDestroy(&lmIdArray);
    }