// -----------------------------------------------------------------------------
// CLandmarksCategoriesView::AddCategoryL
// 
// (other items were commented in a header).
// -----------------------------------------------------------------------------
//
void CLandmarksCategoriesView::AddCategoryL()
    {
    // Create and initialize dialog
    TBuf<KPosLmMaxCategoryNameLength> categoryName;
    CAknTextQueryDialog* queryDialog = CAknTextQueryDialog::NewL(categoryName);
    queryDialog->SetMaxLength(KPosLmMaxCategoryNameLength);
    CleanupStack::PushL(queryDialog);

    // Create and set title
    HBufC* title = 
        iCoeEnv->AllocReadResourceAsDes16LC(R_LMREFAPP_NEW_CATEGORY);
    queryDialog->SetPromptL(*title);
    CleanupStack::PopAndDestroy(title);

    // Launch dialog
    TBool dialogDismissed = queryDialog->ExecuteLD(R_LMREFAPP_RENAME_QUERY);
    CleanupStack::Pop(queryDialog);
    if (dialogDismissed)
        {
        // Create and add a new category with user defined name.
        CPosLandmarkCategory* newCategory = CPosLandmarkCategory::NewLC();
        newCategory->SetCategoryNameL(categoryName);
        iEngine->AddCategoryL(*newCategory);
        CleanupStack::PopAndDestroy(newCategory);
        }
    }
// -----------------------------------------------------------------------------
// CLandmarksCategoriesView::RenameCategoryL
// 
// (other items were commented in a header).
// -----------------------------------------------------------------------------
//
void CLandmarksCategoriesView::RenameCategoryL()
    {
    // Fetch existing category name
    CPosLandmarkCategory* category = 
        iEngine->CategoryLC(iContainer->CurrentCategoryId());
    TPtrC categoryName;
    category->GetCategoryName(categoryName);
    TBuf<KPosLmMaxCategoryNameLength> newCategoryName;
    newCategoryName.Insert(0, categoryName);

    // Create and initialize dialog
    CAknTextQueryDialog* queryDialog = 
        CAknTextQueryDialog::NewL(newCategoryName);
    queryDialog->SetMaxLength(KPosLmMaxCategoryNameLength);
    CleanupStack::PushL(queryDialog);

    // Create and set title
    HBufC* title = 
        iCoeEnv->AllocReadResourceAsDes16LC(R_LMREFAPP_CATEGORY_NAME);
    queryDialog->SetPromptL(*title);
    CleanupStack::PopAndDestroy(title);

    // Launch dialog
    TBool dialogAccepted = queryDialog->ExecuteLD(R_LMREFAPP_RENAME_QUERY);
    CleanupStack::Pop(queryDialog);
    if (dialogAccepted)
        {
        // Update category name
        category->SetCategoryNameL(newCategoryName);
        iEngine->UpdateCategoryL(*category);
        }

    CleanupStack::PopAndDestroy(category);
    }
Пример #3
0
// -----------------------------------------------------------------------------
// CLandmarksEditDialog::ConfigureCategoryFieldL
// 
// (other items were commented in a header).
// -----------------------------------------------------------------------------
//
void CLandmarksEditDialog::ConfigureCategoryFieldL()
    {
    TInt nrOfCategories = iCategoryIds.Count();
    const TInt KExtraChars = 2; // CRLF
    
    HBufC* lmCategoriesBuf = HBufC::NewLC(
        (KPosLmMaxTextFieldLength + KExtraChars) * nrOfCategories);
    
    TPtr lmCategories = lmCategoriesBuf->Des();
    for (TInt i = 0; i < nrOfCategories; i++)
        {
        if (i > 0)
            {
            lmCategories.Append(CEditableText::ELineBreak);
            }

        CPosLandmarkCategory* category = iEngine.CategoryLC(iCategoryIds[i]);
        TPtrC categoryName;
        category->GetCategoryName(categoryName);
        lmCategories.Append(categoryName);
        CleanupStack::PopAndDestroy(category);
        }

    ConfigureTextFieldL(ELandmarkCategoryField, *lmCategoriesBuf);

    CleanupStack::PopAndDestroy(lmCategoriesBuf);
    }
Пример #4
0
// ---------------------------------------------------------
// CPosTp52::CheckLongCategoryNameL
//
// (other items were commented in a header).
// ---------------------------------------------------------
//
void CPosTp52::CheckLongCategoryNameL(TInt aNumExpectedCategories )
{
    iLog->Log(_L("CheckLongCategoryNameL"));
    // Should only exist one landmark in db
    CPosLandmark* lm = iDatabase->ReadLandmarkLC(1);

    RArray<TPosLmItemId> array;
    CleanupClosePushL(array);
    lm->GetCategoriesL(array);
    TInt nr = array.Count();
    TPtrC name;

    _LIT(KLONGNAME1, "1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234");
    _LIT(KLONGNAME2, "Pizzeria10Pizzeria20Pizzeria30Pizzeria40Pizzeria50Pizzeria60Pizzeria70Pizzeria80Pizzeria90Pizzeria10Pizzeria10Pizzeria20Pizz");
    _LIT(KLONGNAME3, "Gizzeria10Gizzeria20Gizzeria30Gizzeria40Gizzeria50Gizzeria60Gizzeria70Gizzeria80Gizzeria90Gizzeria10Gizzeria10Gizzeria20_ABC");
    _LIT(KLONGNAME4, "Dizzeria10Dizzeria20Dizzeria30Dizzeria40Dizzeria50Dizzeria60Dizzeria70Dizzeria80Dizzeria90Dizzeria10Dizzeria10Dizzeria20_ABC");

    const TInt numNames = 4;
    const TPtrC names[] = { KLONGNAME1(), KLONGNAME2(), KLONGNAME3(), KLONGNAME4() };

    if (nr != aNumExpectedCategories) //LogErrorAndLeave(_L("Wrong number of categories for landmark"));
    {
        iLog->Log(_L("Wrong number of categories for landmark"));
        User::Leave(-1);
    }

    CPosLmCategoryManager* categoryManager = CPosLmCategoryManager::NewL(*iDatabase);
    CleanupStack::PushL(categoryManager);

    for ( TInt i = 0; i < aNumExpectedCategories; i++ )
    {
        CPosLandmarkCategory* cat = categoryManager->ReadCategoryLC(array[i]);

        cat->GetCategoryName(name);
        // Maximum size for category name is 124 characters
        if (name.Length() != 124)
        {
            iLog->Log(_L("Category name has wrong size, should be 124"));
            User::Leave(-1);

        }
        if (name.Compare(names[i]) != 0)
        {
            iLog->Log(_L("Long category name does not match"));
            iErrorsFound++;
        }
        CleanupStack::PopAndDestroy(cat);
    }

    CleanupStack::PopAndDestroy(categoryManager);

    CleanupStack::PopAndDestroy(&array);
    CleanupStack::PopAndDestroy(lm);
}
Пример #5
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;
}
Пример #6
0
// ---------------------------------------------------------
// CPosTp666::SetupTestEnvironmentL
//
// (other items were commented in a header).
// ---------------------------------------------------------
//
void CPosTp666::SetupTestEnvironmentL()
    {
    iLog->Put(_L("SetupTestEnvironmentL"));
    
    // Setup start conditions for compatibility test
    _LIT(KDefaultDb, "file://c:eposlm.ldb");

    CPosLmDatabaseManager* dbManager = CPosLmDatabaseManager::NewL();
    CleanupStack::PushL(dbManager);
    
    // Remove all landmark databases
    CDesCArray* uris = dbManager->ListDatabasesL();
    CleanupStack::PushL(uris);
    for (TInt i = 0; i < uris->Count(); i++)
        {
        dbManager->DeleteDatabaseL((*uris)[i]);
        }
    CleanupStack::PopAndDestroy(uris);
        
    // Create and initialize a default database
    dbManager->CreateDatabaseL(KDefaultDb);
    dbManager->SetDefaultDatabaseL(KDefaultDb);
    CPosLandmarkDatabase* database = CPosLandmarkDatabase::OpenL();
    CleanupStack::PushL(database);
    ExecuteAndDeleteLD(database->InitializeL());
    
    // Add 5 landmarks - will generate ids 1 - 5
    const TInt KFive = 5;
    for (TInt j = 0; j < KFive; j++)
        {
        CPosLandmark* lm = CPosLandmark::NewLC();
        lm->SetLandmarkNameL(_L("Landmark"));
        database->AddLandmarkL(*lm);
        CleanupStack::PopAndDestroy(lm);
        }
        
    // Add 5 categories
    CPosLmCategoryManager* catManager = CPosLmCategoryManager::NewL(*database);
    CleanupStack::PushL(catManager);
    for (TInt k = 0; k < KFive; k++)
        {
        CPosLandmarkCategory* category = CPosLandmarkCategory::NewLC();
        TBuf<15> name;
        name = _L("Category ");
        name.AppendNum(k);
        category->SetCategoryNameL(name);
        catManager->AddCategoryL(*category);
        CleanupStack::PopAndDestroy(category);
        }
       
    CleanupStack::PopAndDestroy(3, dbManager);
    }
Пример #7
0
// ---------------------------------------------------------
// CPosTp45::RenameGlobalCategoryL()
//
// (other items were commented in a header).
// ---------------------------------------------------------
//	
void CPosTp45::RenameGlobalCategoryL()
    {
    /*
    * Rename a global category 
    */

    TBuf<150>info;
    // Get sample global category info     
    TPosLmItemId catId(0);
    
    CPosLandmarkCategory* category = NULL;    
    catId = iCategoryManager->GetGlobalCategoryL( KAccommodation );
    category = iCategoryManager->ReadCategoryLC( catId );
    category->SetCategoryNameL(_L("TP45 - Renamed global"));
    iCategoryManager->UpdateCategoryL( *category );    
    
    CleanupStack::PopAndDestroy( category );    
    }
// -----------------------------------------------------------------------------
// CTestPosLandmarkDatabase::AddCategoriesToTestDb
// 
// 
// -----------------------------------------------------------------------------
//
TInt CTestPosLandmarkDatabase::AddCategoriesToTestDbL( CPosLandmarkDatabase* aDatabase )
	{
	_LIT( KCatName, "A Test Category " );
	// Create category manager
	CPosLmCategoryManager* categoryMgr = NULL;
	TRAPD( error,  categoryMgr = CPosLmCategoryManager::NewL( *aDatabase ));
	if( KErrNone != error )
		{
		return error;
		}
	CleanupStack::PushL( categoryMgr );		
	// Create a category, has to be trapped
	CPosLandmarkCategory* category = NULL;
	TRAP(error, category = CPosLandmarkCategory::NewL());
	if( KErrNone != error )
		{
		CleanupStack::PopAndDestroy( categoryMgr );	
		return error;
		}
	CleanupStack::PushL( category );
	// Add 5 landmarks to DB
	TBuf<20> nameBuffer;
	for(TInt i = 1; i < 6; i++)
		{
		// Set name	
		nameBuffer.Copy( KCatName );
		nameBuffer.AppendNum( i );
		TRAP( error, category->SetCategoryNameL( nameBuffer ) );
		if( KErrNone != error )
			{
			CleanupStack::PopAndDestroy( 2, categoryMgr );	
			return error;
			}
		// Add
		TRAP( error, categoryMgr->AddCategoryL( *category ) );
		if( KErrNone!= error )
			{
			CleanupStack::PopAndDestroy( 2, categoryMgr );	
			return error;
			}	
		}// Add loop
	CleanupStack::PopAndDestroy( 2, categoryMgr );
	return KErrNone;	  		
	}
Пример #9
0
// ---------------------------------------------------------
// CPosTp53::AddCategoriesL()
//
// (other items were commented in a header).
// ---------------------------------------------------------
//
void CPosTp53::AddCategoriesL()
    {
    CPosLmCategoryManager* cm = CPosLmCategoryManager::NewL(*iDatabase); 
    CleanupStack::PushL(cm);

    CPosLandmarkCategory* category = CPosLandmarkCategory::NewLC();
    category->SetCategoryNameL(KCategoryName); 

    CPosLandmarkCategory* category2 = CPosLandmarkCategory::NewLC();
    category2->SetCategoryNameL(KCategoryName2);

    CPosLandmarkCategory* category3 = CPosLandmarkCategory::NewLC();
    category3->SetCategoryNameL(KCategoryName3);

    cm->AddCategoryL(*category);
    cm->AddCategoryL(*category2);
    cm->AddCategoryL(*category3);

    CleanupStack::PopAndDestroy(4, cm);
    }
// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
//
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;
    }
Пример #11
0
void CPosTp45::AddCategoriesL()
    {    
    _LIT(KName, "CategoryTP45 - %d");
    TInt err=KErrLocked;
    for (TInt i=0; i<KNoCategoriesTp45; i++)
        {
        TBuf<100> categoryName;
        categoryName.Format(KName,i);

        CPosLandmarkCategory* lmc = CPosLandmarkCategory::NewLC();
        lmc->SetCategoryNameL(categoryName);
        err = KErrLocked;
        while (err == KErrLocked)
            {
            TRAP(err, iCategoryManager->AddCategoryL(*lmc));
            }

        iCategories.Append(lmc);       
        CleanupStack::Pop(lmc);
        }    
    iLog->Log(_L("Adding categories to database done "));
    }
Пример #12
0
 // ---------------------------------------------------------
// CPosTp148::PrintParsedDataFromEncoderL
//
// (other items were commented in a header).
// ---------------------------------------------------------
//
void CPosTp148::PrintParsedDataFromEncoderL(
    const TDesC& aFile, 
    const TDesC8&  aBuffer, 
    TInt aExpectedStatusCode,
    const TDesC8& aMimeType)
    {
    iLog->Log(_L("===== PrintParsedDataFromEncoderL ======="));
    
    iLandmarkParser = CPosLandmarkParser::NewL(aMimeType);

    if (aFile != KNullDesC)
        {
        TFileName file( aFile );
        iLog->Log(_L("FILE (%S)"), &file );
        TraceL(_L("----->Using FILE<-------"));
        TraceL(file);
        iLandmarkParser->SetInputFileL(file);
        }
    else
        {
        iLog->Log(_L("BUFFER (size %d)"), aBuffer.Size() );
        TraceL(_L("----->Using BUFFER<-------"));
        iLandmarkParser->SetInputBuffer(aBuffer);
        }

    iOperation = iLandmarkParser->ParseContentL();
    TRequestStatus status = KPosLmOperationNotComplete;
    TReal32 progress;
    TInt number = 0;

    RArray<TPosLmItemId> array;
    CleanupClosePushL(array);

    while (status == KPosLmOperationNotComplete)
        {
        iLog->Log(_L("--- Parsing ---------------------------"));
        TraceL(_L("------------------------------"));
        iOperation->NextStep(status, progress);

        // Wait for NextStep to complete
        User::WaitForRequest(status);
        if (status != KPosLmOperationNotComplete && status != KErrNone)
            {
            iLog->Log(_L("Parsing Complete"));
            
            HBufC* buffer = HBufC::NewLC( 128);
            TPtr buf = buffer->Des();
                       
            buf.Format(_L("\tStatus %d"), status.Int());
            iLog->Log(buf);
            TraceL(buf);
            
            CleanupStack::PopAndDestroy( buffer );
            buffer = NULL;              
            }
        else
            {
            iLog->Log(_L("Parsing element"));
            
            if ( iLandmarkParser->NumOfParsedLandmarks() )
                {
                // Get last parsed landmark
                CPosLandmark* lm = iLandmarkParser->LandmarkLC();
                TPtrC lmName;
                TPtrC catName;
                lm->GetLandmarkName(lmName);
                lm->GetCategoriesL(array);
                //iLog->Log(lmName);
                for (TInt i=0;i<array.Count();i++)
                    {                    
                    CPosLandmarkCategory* category = iLandmarkParser->LandmarkCategoryLC( array[i] );
                    category->GetCategoryName( catName );
                     
                    HBufC* buffer = HBufC::NewLC( 128 + catName.Length());
                    TPtr buf = buffer->Des();
                                            
                    if ( category->GlobalCategory()) 
                        {
                        buf.Append(_L("\tGlobal category: "));    
                        }
                    else 
                        {
                        buf.Append(_L("\tLocal category: "));    
                        }                        
                                        
                    buf.Append( catName );
                    iLog->Log( buf );
                    TraceL( buf );

                    CleanupStack::PopAndDestroy( buffer );
                    buffer = NULL;
                                       
                    CleanupStack::PopAndDestroy(category);
                    }
                    
               	PrintLandmarkFieldsWithDescriptionL(*lm, ETrue);	
               
                
                number++;
                CleanupStack::PopAndDestroy(lm);
                }
            }
        }

    iLog->Log(_L("--- Parsing end ---------------------------"));
    TraceL(_L("------------------------------"));
    CleanupStack::PopAndDestroy(&array);

    if (status.Int() != aExpectedStatusCode)
        {
        HBufC* buffer = HBufC::NewLC( 128 );
        TPtr buf = buffer->Des();
                    
        buf.Format(_L("\tERROR: Wrong status returned, was %d, should be %d"), status.Int(), aExpectedStatusCode);
        iLog->Log( buf );
        iErrorsFound++;
        
        CleanupStack::PopAndDestroy( buffer );
        buffer = NULL;        
        }

    TUint32 nr = iLandmarkParser->NumOfParsedLandmarks();
    
    HBufC* buffer = HBufC::NewLC( 256 );
    TPtr buf = buffer->Des();
    
    buf.Format(_L("\tNr of Parsed landmarks %d, should be %d"), nr, number);
    iLog->Log(buf);
    TraceL(buf);

    CleanupStack::PopAndDestroy( buffer );
    buffer = NULL;
    
    if (nr != (TUint32)number)
        {
        iLog->Log(_L("\tERROR: Wrong number of landmarks parsed returned!"));
        iErrorsFound++;
        }

    TPosLmCollectionDataId lmId = iLandmarkParser->FirstCollectionDataId();

    iLog->Log(_L("--- CollectionData ---"));
    TraceL(_L("--- CollectionData ---"));

    if (lmId != EPosLmCollDataNone)
        {
        TPtrC first = iLandmarkParser->CollectionData(lmId);
        
        HBufC* buffer = HBufC::NewLC( first.Length() + 256 );
        TPtr buf = buffer->Des();
            
        buf.Zero();
        buf.Format(_L("\t(1)Collection Id: %d CollectionData: "), lmId);
        buf.Append(first);
        iLog->Log(buf);
        TraceL(buf);
        
        CleanupStack::PopAndDestroy( buffer );
        buffer = NULL;      
        
        }
    else 
        {
        iLog->Log(_L("\tNo collection data found 1"));    
        }

    while (lmId != EPosLmCollDataNone)
        {
        lmId = iLandmarkParser->NextCollectionDataId(lmId);
        if (lmId != EPosLmCollDataNone)
        {
            TPtrC first = iLandmarkParser->CollectionData(lmId);
            
            HBufC* buffer = HBufC::NewLC( first.Length() + 256 );
            TPtr buf = buffer->Des();         
            
            buf.Zero();
            buf.Format(_L("\t(2)Collection Id: %d CollectionData: "), lmId);
            buf.Append(first);
            iLog->Log(buf);
            TraceL(buf);
            
            CleanupStack::PopAndDestroy( buffer );
            buffer = NULL;              
        }
        else 
            {
            iLog->Log(_L("\tNo collection data found 2"));   
            }
        }

    iLog->Log(_L("--- CollectionData ---"));
    TraceL(_L("--- CollectionData ---"));

    delete iOperation;
    iOperation = NULL;
    delete iLandmarkParser;
    iLandmarkParser = NULL;
    iLog->Log(_L("====== PrintParsedDataFromEncoderL Done ========\n"));
    }
Пример #13
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);
    }
Пример #14
0
// ---------------------------------------------------------
// CPosTp26::DoLandmarkCategorySearch
//
// (other items were commented in a header).
// ---------------------------------------------------------
//
void CPosTp26::DoLandmarkCategorySearchL(const RPointerArray<CCategorySearchResult>& aSearchResults)
    {
    _LIT(KNumOfMatchesErr, "No. of matches is incorrect when the search is performed");
    _LIT(KNotFoundErr, "Id %d not found in parsed Lm search results when the search is performed syncronously");
    _LIT(KWrongIdErr, "Wrong id returned from iterator after reset");

    CPosLmCategoryManager* categoryManager = CPosLmCategoryManager::NewL(*iDatabase);
    CleanupStack::PushL(categoryManager);
    CPosLmCatNameCriteria* nameCriteria = CPosLmCatNameCriteria::NewLC();
    // Use wildcard * as search pattern
    nameCriteria->SetSearchPatternL(aSearchResults[0]->TextCriteria());
    
    ExecuteAndDeleteLD(iLandmarkSearch->StartCategorySearchL(*nameCriteria, CPosLmCategoryManager::ECategorySortOrderNone)); 
    
    CPosLmItemIterator* iter = iLandmarkSearch->MatchIteratorL();
    CleanupStack::PushL(iter);
    
    if ((TUint)(aSearchResults[0]->SearchResult()).Count() != iLandmarkSearch->NumOfMatches())
        {
        _LIT(KExpected, "Expected no. of matches: %d");
        _LIT(KReturned, "Returned no. of matches: %d");
        TBuf<100> info;
        info.Format(KExpected, (aSearchResults[0]->SearchResult()).Count());
        iLog->Log(info);
        info.Format(KReturned, iLandmarkSearch->NumOfMatches());
        iLog->Log(info);
        iLog->Log(_L("Name criteria: "));
        iLog->Log(nameCriteria->SearchPattern());
        
        iLog->Log(KNumOfMatchesErr);
       	User::Leave(-1);
        }

    // Get the first category in list, id1
    TPosLmItemId id1 = iter->NextL();
    CPosLandmarkCategory* cat = categoryManager->ReadCategoryLC(id1);
    TPtrC name;
    cat->GetCategoryName(name);
    iLog->Log(_L("First time"));
    iLog->Log(name);
    CleanupStack::PopAndDestroy(cat);

    //Reset iterator and make sure that id1 is returned again
    iter->Reset();
    TPosLmItemId id11 = iter->NextL();
    AssertTrueSecL(id1 == id11, KWrongIdErr);

    iLog->Log(_L("******************"));
    // Iterate through whole iterator
    while (id11 != KPosLmNullItemId)
        {
        AssertTrueSecL(aSearchResults[0]->FindSearchResult(id11), KNotFoundErr, id11);
        CPosLandmarkCategory* cat = categoryManager->ReadCategoryLC(id11);
        TPtrC name;
        cat->GetCategoryName(name);
        iLog->Log(name);
        CleanupStack::PopAndDestroy(cat);
        id11 = iter->NextL();
        }
    iLog->Log(_L("******************"));
    RArray<TPosLmItemId> lmIdArray;
    CleanupClosePushL(lmIdArray);

    // Get a sequence of items from the iterated set
    // lmIdArray should be reset in GetItemIdsL
    // Use some magic numbers here, check landmarksDb.xls for more info
    iter->GetItemIdsL(lmIdArray, 5, 10);
    TInt nr = lmIdArray.Count();
    for (TInt j=0;j<nr; j++)
        {
        AssertTrueSecL(aSearchResults[0]->FindSearchResult(lmIdArray[j]), KNotFoundErr);
        CPosLandmarkCategory* cat = categoryManager->ReadCategoryLC(lmIdArray[j]);
        TPtrC name;
        cat->GetCategoryName(name);
        iLog->Log(name);
        CleanupStack::PopAndDestroy(cat);
        }

    CleanupStack::PopAndDestroy(&lmIdArray);
    CleanupStack::PopAndDestroy(2, nameCriteria);
    CleanupStack::PopAndDestroy(categoryManager);
    }
Пример #15
0
// ---------------------------------------------------------
// CPosTp56::TestMultipleExportL
//
// (other items were commented in a header).
// ---------------------------------------------------------
//
void CPosTp56::TestMultipleExportL()
    {
    _LIT(KDb1, "eposlm1.ldb");
    _LIT(KDb2, "eposlm2.ldb");
    _LIT(KDb3, "eposlm3.ldb");
    
    CreateDatabasesL();

    CPosLandmarkDatabase* lmd1 = CPosLandmarkDatabase::OpenL(KDb1);
    CleanupStack::PushL(lmd1);
    
    CPosLandmarkDatabase* lmd2 = CPosLandmarkDatabase::OpenL(KDb2);
    CleanupStack::PushL(lmd2);

    CPosLandmarkDatabase* lmd3 = CPosLandmarkDatabase::OpenL(KDb3);
    CleanupStack::PushL(lmd3);

    CPosLandmark* lm = CreateXMLLandmarkLC(_L("TP56 - LM with all fields set"));
    AddAllXMLFieldsL(lm);    

    lmd1->AddLandmarkL(*lm);
    CleanupStack::PopAndDestroy(lm);  
    
    CPosLandmark* lm2 = CreateXMLLandmarkLC(_L("TP56 - LM2"));
    lmd2->AddLandmarkL(*lm2);
    CleanupStack::PopAndDestroy(lm2);
    
    
    CPosLandmark* lm3 = CreateXMLLandmarkLC(_L("TP56 - LM3"));
    
    CPosLmCategoryManager* cm = CPosLmCategoryManager::NewL(*lmd3);
    CleanupStack::PushL(cm);
    
    CPosLandmarkCategory* category = CPosLandmarkCategory::NewLC();
    category->SetCategoryNameL(_L("category"));
    TPosLmItemId id = cm->AddCategoryL(*category);
    CleanupStack::PopAndDestroy(2, cm);
    
    lm3->AddCategoryL(id);
    lmd3->AddLandmarkL(*lm3);
    CleanupStack::PopAndDestroy(lm3);
    
    CPosLandmarkEncoder* encoder = CPosLandmarkEncoder::NewL(KMimeType);
    CleanupStack::PushL(encoder);

    encoder->SetOutputFileL(KExportFileFullPath);
    
    CPosLmItemIterator* iter = lmd1->LandmarkIteratorL();
    CleanupStack::PushL(iter);
    
    RArray<TPosLmItemId> arrayOfIds;
    CleanupClosePushL(arrayOfIds);
    
    TInt numberOfElements = iter->NumOfItemsL();    
    iter->GetItemIdsL(arrayOfIds, 0, (numberOfElements));

    ExecuteAndDeleteLD(lmd1->ExportLandmarksL(*encoder, arrayOfIds, CPosLandmarkDatabase::EDefaultOptions));

    RunAsyncOperationLD(lmd2->ExportLandmarksL(*encoder, arrayOfIds, CPosLandmarkDatabase::EDefaultOptions));

    ExecuteAndDeleteLD(lmd3->ExportLandmarksL(*encoder, arrayOfIds, CPosLandmarkDatabase::EIncludeCategories));

    ExecuteAndDeleteLD(encoder->FinalizeEncodingL()); 
    
    CleanupStack::PopAndDestroy(6, lmd1);

    TInt err = CompareL(KExportFile);
    AssertTrueSecL(err == KErrNone, _L("The exported file is not equal to file exported prevoius release"));
    }