landmarks/locationlandmarks/tsrc/LandmarkTestModule/src/FT_CPosTp157.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_CPosTp157.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\\LandmarksTP157Trace.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_LandmarksTP157Trace.txt");
       
    43 
       
    44 _LIT(KKMZFile, "c:\\system\\test\\TestData\\Tp157KMZFile.kmz");
       
    45 
       
    46 
       
    47 // Maxmimum size for each line in trace file
       
    48 const TInt KBufSize = 5000;
       
    49 
       
    50 // ================= MEMBER FUNCTIONS =======================
       
    51 // ---------------------------------------------------------
       
    52 // CPosTp157::CloseTest
       
    53 //
       
    54 // (other items were commented in a header).
       
    55 // ---------------------------------------------------------
       
    56 //
       
    57 void CPosTp157::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 // CPosTp157::StartL
       
    83 //
       
    84 // (other items were commented in a header).
       
    85 // ---------------------------------------------------------
       
    86 //
       
    87 void CPosTp157::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 
       
    99    	iLog->Log(_L("Test with Tp157KMZFile.kmz"));
       
   100 	PrintParsedDataFromEncoderL(KKMZFile, *emptyBuffer, KErrNone, KKmzMimeType );
       
   101 
       
   102    
       
   103     // Now compare tha trace file against the correct one
       
   104     RFile correctFile;
       
   105     RFile file;
       
   106 
       
   107     iLog->Log(_L(">>>>>>>Comparing files<<<<<"));
       
   108     
       
   109     TFileName filename;
       
   110     CreateCorrectXmlFileL( KCorrectFile, filename );
       
   111     
       
   112     User::LeaveIfError(correctFile.Open(iFileSession, filename,  EFileRead));
       
   113     CleanupClosePushL(correctFile);
       
   114     User::LeaveIfError(file.Open(iFileSession, KFileTrace,  EFileRead));
       
   115     CleanupClosePushL(file);
       
   116 
       
   117     HBufC* correctLinebuffer = HBufC::NewLC( KBufSize );
       
   118             TPtr correctLine = correctLinebuffer->Des();    
       
   119             HBufC* linebuffer = HBufC::NewLC( KBufSize );
       
   120             TPtr line = linebuffer->Des();    
       
   121    	
       
   122     TInt err = KErrNone;
       
   123     TBool done = EFalse;
       
   124     TInt lineNr = 0;
       
   125 
       
   126     while (ReadLn(correctFile, correctLine) != KErrEof && !done)
       
   127         {
       
   128         lineNr++;
       
   129         err = ReadLn(file, line);
       
   130         if ( err == KErrEof ) 
       
   131             {
       
   132             done = ETrue;    
       
   133             }
       
   134         correctLine.Trim();
       
   135         line.Trim();
       
   136         if (correctLine.Compare(line) != KErrNone)
       
   137             {
       
   138             HBufC* buf = HBufC::NewLC( 128 );
       
   139             TPtr buffer = buf->Des();
       
   140             
       
   141             buffer.Format(_L("ERROR in TraceFile on line %d: "), lineNr);
       
   142             
       
   143             iLog->Log( buffer );
       
   144             iLog->Log( correctLine );
       
   145             iLog->Log( line );
       
   146             iErrorsFound++;
       
   147             CleanupStack::PopAndDestroy( buf );
       
   148             }
       
   149         }
       
   150 		CleanupStack::PopAndDestroy(linebuffer);
       
   151     CleanupStack::PopAndDestroy(correctLinebuffer);
       
   152     CleanupStack::PopAndDestroy(&file);
       
   153     CleanupStack::PopAndDestroy(&correctFile);
       
   154 
       
   155     // EOF for trace file was reach before EOF in the correct file
       
   156     if (done)
       
   157         {
       
   158         iLog->Log(_L("ERROR: EOF for Trace file was reached to early"));
       
   159         iErrorsFound++;
       
   160         }
       
   161         
       
   162         
       
   163   
       
   164     if (iErrorsFound != KErrNone)
       
   165         {
       
   166     	iLog->Log(_L("Errors found in TP157"));
       
   167     	User::Leave(-1);
       
   168         }
       
   169       
       
   170 	}
       
   171 
       
   172 
       
   173  // ---------------------------------------------------------
       
   174 // CPosTp157::PrintParsedDataFromEncoderL
       
   175 //
       
   176 // (other items were commented in a header).
       
   177 // ---------------------------------------------------------
       
   178 //
       
   179 void CPosTp157::PrintParsedDataFromEncoderL(
       
   180     const TDesC& aFile, 
       
   181     const TDesC8&  aBuffer, 
       
   182     TInt aExpectedStatusCode,
       
   183     const TDesC8& aMimeType)
       
   184     {
       
   185     iLog->Log(_L("===== PrintParsedDataFromEncoderL ======="));
       
   186     
       
   187     iLandmarkParser = CPosLandmarkParser::NewL(aMimeType);
       
   188 
       
   189    
       
   190         TFileName file( aFile );
       
   191         iLog->Log(_L("FILE (%S)"), &file );
       
   192         TraceL(_L("----->Using FILE<-------"));
       
   193         TraceL(file);
       
   194         TRAPD(err,iLandmarkParser->SetInputFileL(file));
       
   195 	    if(err != KErrNone)
       
   196         {
       
   197 		    TBuf<100> buffe;
       
   198 			buffe.Format(_L("\t SetInputFile  leaves with error code : %d"), err);
       
   199 			iLog->Log(buffe);
       
   200 			      		        
       
   201         }
       
   202 	    else
       
   203 		{
       
   204 		    iErrorsFound++;
       
   205 		   	TBuf<100> buffe;
       
   206 			buffe.Format(_L("\tERROR: SetInputFile should leave with error code"));
       
   207 			iLog->Log(buffe);
       
   208 		       		
       
   209 		}
       
   210 	       
       
   211    
       
   212     delete iLandmarkParser;
       
   213     iLandmarkParser = NULL;
       
   214     
       
   215     iLog->Log(_L("====== PrintParsedDataFromEncoderL Done ========\n")); 
       
   216     }
       
   217     
       
   218     
       
   219  
       
   220     
       
   221     
       
   222 // ---------------------------------------------------------
       
   223 // CPosTp157::TraceL
       
   224 //
       
   225 // (other items were commented in a header).
       
   226 // ---------------------------------------------------------
       
   227 //
       
   228 void CPosTp157::TraceL(const TDesC& msg)
       
   229     {
       
   230     _LIT8( KEnd, "\r\n" );
       
   231 
       
   232     RFile file;
       
   233     TInt err = file.Open(iFileSession, KFileTrace, EFileWrite);
       
   234     if (err == KErrNotFound)
       
   235         {
       
   236         file.Create(iFileSession, KFileTrace, EFileWrite);
       
   237         }
       
   238 
       
   239     HBufC8* line8 = CnvUtfConverter::ConvertFromUnicodeToUtf8L( msg );
       
   240     
       
   241     TInt pos( 0 );
       
   242     file.Seek( ESeekEnd, pos );
       
   243     file.Write( *line8 );
       
   244     file.Write( KEnd );
       
   245     file.Close();
       
   246 
       
   247     delete line8;
       
   248     }
       
   249 
       
   250 //  End of File