landmarks/locationlandmarks/tsrc/LandmarkTestModule/src/FT_CPosTp160.cpp
branchRCL_3
changeset 44 2b4ea9893b66
equal deleted inserted replaced
42:02ba3f1733c6 44:2b4ea9893b66
       
     1 /*
       
     2 * Copyright (c) 2005 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: 
       
    15 *   ?description_line
       
    16 *
       
    17 */
       
    18 
       
    19 //  INCLUDES
       
    20 #include "FT_CPosTp160.h"
       
    21 #include <EPos_CPosLandmarkDatabase.h>
       
    22 #include <EPos_CPosLandmarkParser.h>
       
    23 #include <EPos_CPosLandmarkEncoder.h>
       
    24 #include <LbsPosition.h>
       
    25 #include <e32math.h>
       
    26 #include <bautils.h>
       
    27 #include <utf.h>
       
    28 #include <xml/xmlparsererrors.h>
       
    29 
       
    30 // CONSTANTS
       
    31 
       
    32 _LIT(KFileTrace, "c:\\documents\\LandmarksTP160Trace.txt");
       
    33 
       
    34 // See \epoc32\include\xml\XmlParserErrors.h for error codes
       
    35 
       
    36 
       
    37 
       
    38 
       
    39 // See \epoc32\include\xml\XmlParserErrors.h for error codes
       
    40 
       
    41 
       
    42 _LIT(KCorrectFile, "c:\\system\\test\\TestData\\CorrectFileFor_LandmarksTP160Trace.txt");
       
    43 
       
    44 _LIT(KKMZFile, "c:\\system\\test\\TestData\\Tp160KMZFile.kmz");
       
    45 
       
    46 
       
    47 // Maxmimum size for each line in trace file
       
    48 const TInt KBufSize = 5000;
       
    49 
       
    50 // ================= MEMBER FUNCTIONS =======================
       
    51 // ---------------------------------------------------------
       
    52 // CPosTp160::CloseTest
       
    53 //
       
    54 // (other items were commented in a header).
       
    55 // ---------------------------------------------------------
       
    56 //
       
    57 void CPosTp160::CloseTest()
       
    58     {
       
    59     iLog->Log(_L("CloseTest"));
       
    60 
       
    61     delete iEncoderBuffer;
       
    62     iEncoderBuffer = NULL;
       
    63 
       
    64     iLandmarks.ResetAndDestroy();
       
    65     iLandmarks.Close();
       
    66 
       
    67 
       
    68     delete iLandmarkEncoder;
       
    69     iLandmarkEncoder = NULL;
       
    70 
       
    71     delete iLandmarkParser;
       
    72     iLandmarkParser = NULL;
       
    73 
       
    74     delete iOperation;
       
    75     iOperation = NULL;
       
    76 
       
    77 
       
    78     iLog->Log(_L("CloseTest Done"));
       
    79     }
       
    80     
       
    81 // ---------------------------------------------------------
       
    82 // CPosTp160::StartL
       
    83 //
       
    84 // (other items were commented in a header).
       
    85 // ---------------------------------------------------------
       
    86 //
       
    87 void CPosTp160::StartL()
       
    88     {
       
    89     BaflUtils::EnsurePathExistsL( iFileSession, KKMZFile );
       
    90 
       
    91 
       
    92     // Delete the trace file
       
    93     DeleteFileL(KFileTrace);
       
    94 
       
    95 
       
    96     HBufC8* emptyBuffer=NULL;
       
    97     
       
    98    	iLog->Log(_L("Test with Tp160KMZFile.kmz"));
       
    99 	PrintParsedDataFromEncoderL(KKMZFile, *emptyBuffer, KErrNone, KKmzMimeType );
       
   100 
       
   101 
       
   102     // Now compare tha trace file against the correct one
       
   103     RFile correctFile;
       
   104     RFile file;
       
   105 
       
   106     iLog->Log(_L(">>>>>>>Comparing files<<<<<"));
       
   107     
       
   108     TFileName filename;
       
   109     CreateCorrectXmlFileL( KCorrectFile, filename );
       
   110     
       
   111     User::LeaveIfError(correctFile.Open(iFileSession, filename,  EFileRead));
       
   112     CleanupClosePushL(correctFile);
       
   113     User::LeaveIfError(file.Open(iFileSession, KFileTrace,  EFileRead));
       
   114     CleanupClosePushL(file);
       
   115 
       
   116     HBufC* correctLinebuffer = HBufC::NewLC( KBufSize );
       
   117     TPtr correctLine = correctLinebuffer->Des();    
       
   118     HBufC* linebuffer = HBufC::NewLC( KBufSize );
       
   119     TPtr line = linebuffer->Des();    
       
   120    	
       
   121     TInt err = KErrNone;
       
   122     TBool done = EFalse;
       
   123     TInt lineNr = 0;
       
   124 
       
   125     while (ReadLn(correctFile, correctLine) != KErrEof && !done)
       
   126         {
       
   127         lineNr++;
       
   128         err = ReadLn(file, line);
       
   129         if ( err == KErrEof ) 
       
   130             {
       
   131             done = ETrue;    
       
   132             }
       
   133         correctLine.Trim();
       
   134         line.Trim();
       
   135         if (correctLine.Compare(line) != KErrNone)
       
   136             {
       
   137             HBufC* buf = HBufC::NewLC( 128 );
       
   138             TPtr buffer = buf->Des();
       
   139             
       
   140             buffer.Format(_L("ERROR in TraceFile on line %d: "), lineNr);
       
   141             
       
   142             iLog->Log( buffer );
       
   143             iLog->Log( correctLine );
       
   144             iLog->Log( line );
       
   145             iErrorsFound++;
       
   146             CleanupStack::PopAndDestroy( buf );
       
   147             }
       
   148         }
       
   149 		CleanupStack::PopAndDestroy(linebuffer);
       
   150     CleanupStack::PopAndDestroy(correctLinebuffer);
       
   151     CleanupStack::PopAndDestroy(&file);
       
   152     CleanupStack::PopAndDestroy(&correctFile);
       
   153 
       
   154     // EOF for trace file was reach before EOF in the correct file
       
   155     if (done)
       
   156         {
       
   157         iLog->Log(_L("ERROR: EOF for Trace file was reached to early"));
       
   158         iErrorsFound++;
       
   159         }
       
   160         
       
   161         
       
   162    
       
   163 
       
   164     if (iErrorsFound != KErrNone)
       
   165         {
       
   166     	iLog->Log(_L("Errors found in TP160"));
       
   167     	User::Leave(-1);
       
   168         }
       
   169 	}
       
   170 
       
   171 
       
   172     
       
   173  // ---------------------------------------------------------
       
   174 // CPosTp160::PrintParsedDataFromEncoderL
       
   175 //
       
   176 // (other items were commented in a header).
       
   177 // ---------------------------------------------------------
       
   178 //
       
   179 void CPosTp160::PrintParsedDataFromEncoderL(
       
   180     const TDesC& aFile, 
       
   181     const TDesC8&  aBuffer, 
       
   182     TInt aExpectedStatusCode,
       
   183     const TDesC8& aMimeType)
       
   184     {
       
   185     iLog->Log(_L("===== PrintParsedDataFromEncoderL ======="));
       
   186     iLandmarkParser = CPosLandmarkParser::NewL(aMimeType);
       
   187 
       
   188     
       
   189         TFileName file( aFile );
       
   190         iLog->Log(_L("FILE (%S)"), &file );
       
   191         TraceL(_L("----->Using FILE<-------"));
       
   192         TraceL(file);
       
   193         TRAPD(err,iLandmarkParser->SetInputFileL(file));
       
   194         if(err != KErrNone)
       
   195 	        {
       
   196 	        	TBuf<100> buffe;
       
   197 		        buffe.Format(_L("\t SetInputFile  leaves with error code : %d"), err);
       
   198 		        iLog->Log(buffe);
       
   199 		      		        
       
   200 	        }
       
   201        else
       
   202 	       	{
       
   203 	       		iErrorsFound++;
       
   204 	       		TBuf<100> buffe;
       
   205 		        buffe.Format(_L("\tERROR: SetInputFile should leave with error code"));
       
   206 		        iLog->Log(buffe);
       
   207 	       		
       
   208 	       	}
       
   209    
       
   210     delete iLandmarkParser;
       
   211     iLandmarkParser = NULL;
       
   212     iLog->Log(_L("====== PrintParsedDataFromEncoderL Done ========\n"));
       
   213     }
       
   214     
       
   215     
       
   216 
       
   217     
       
   218     
       
   219 // ---------------------------------------------------------
       
   220 // CPosTp160::TraceL
       
   221 //
       
   222 // (other items were commented in a header).
       
   223 // ---------------------------------------------------------
       
   224 //
       
   225 void CPosTp160::TraceL(const TDesC& msg)
       
   226     {
       
   227     _LIT8( KEnd, "\r\n" );
       
   228 
       
   229     RFile file;
       
   230     TInt err = file.Open(iFileSession, KFileTrace, EFileWrite);
       
   231     if (err == KErrNotFound)
       
   232         {
       
   233         file.Create(iFileSession, KFileTrace, EFileWrite);
       
   234         }
       
   235 
       
   236     HBufC8* line8 = CnvUtfConverter::ConvertFromUnicodeToUtf8L( msg );
       
   237     
       
   238     TInt pos( 0 );
       
   239     file.Seek( ESeekEnd, pos );
       
   240     file.Write( *line8 );
       
   241     file.Write( KEnd );
       
   242     file.Close();
       
   243 
       
   244     delete line8;
       
   245     }
       
   246 
       
   247 //  End of File