secureswitools/swisistools/test/txmlparser/txmlparser.cpp
changeset 0 ba25891c3a9e
equal deleted inserted replaced
-1:000000000000 0:ba25891c3a9e
       
     1 /*
       
     2 * Copyright (c) 2008-2009 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 the License "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 * CTestXmlParser - Used to testing retrieval of data pertianing to creation and updation 
       
    16 * of database.
       
    17 *
       
    18 */
       
    19 
       
    20 
       
    21 /**
       
    22  @file 
       
    23  @released
       
    24  @internalTechnology
       
    25 */
       
    26 
       
    27 #include <vector>
       
    28 #include <string>
       
    29 #include <memory>
       
    30 #include <iostream>
       
    31 
       
    32 #include <xercesc/sax2/DefaultHandler.hpp>
       
    33 
       
    34 #include "txmlparser.h"
       
    35 #include "xmlparser.h"
       
    36 #include "exception.h"
       
    37 #include "logger.h"
       
    38 #include "../../source/common/utility.h"
       
    39 
       
    40 using namespace std;
       
    41 
       
    42 typedef vector<string>::iterator StringIterator;
       
    43 
       
    44 typedef vector<CScrXmlParser::TScrEnvironmentDetails>::iterator envDetailsIter;
       
    45 
       
    46 std::string CTestXmlParser::Passed = "Passed";
       
    47 std::string CTestXmlParser::Failed = "Failed";
       
    48 
       
    49 CTestXmlParser::CTestXmlParser()
       
    50 	{
       
    51 	std::string logFile = "xmlparse.log";
       
    52 	CLogger::TLogLevel logLevel = static_cast<CLogger::TLogLevel>( CLogger::ELogEnter | CLogger::ELogExit);
       
    53 	iLogger = new CLogger(logFile, logLevel);
       
    54 	iXmlParser = new CScrXmlParser();
       
    55 	}
       
    56 
       
    57 CTestXmlParser::~CTestXmlParser()
       
    58 	{
       
    59 	delete iXmlParser;
       
    60 	delete iLogger;
       
    61 	}
       
    62 
       
    63 CTestXmlParser::TestParser()
       
    64 	{
       
    65 	
       
    66 	// tests for createdb xml schema
       
    67 	PrintResult("TestValidDbFile()",TestValidDbFile());
       
    68 	PrintResult("TestDbFileNotPresent",TestDbFileNotPresent());
       
    69 	PrintResult("TestEmptyDbFile",TestEmptyDbFile());
       
    70 	PrintResult("TestInvalidDbFiles",TestInvalidDbFiles());
       
    71 	
       
    72 	PrintResult("TestValidUpdateDb",TestValidUpdateDb());
       
    73 	PrintResult("TestUpdateFileNotPresent",TestUpdateFileNotPresent());
       
    74 	PrintResult("TestEmptyUpdateFile",TestEmptyUpdateFile());
       
    75 	PrintResult("TestInvalidUpdateDb",TestInvalidUpdateDb());
       
    76 
       
    77 	}
       
    78 
       
    79 
       
    80 void CTestXmlParser::PrintResult(const char* aMethodName, bool aResult)
       
    81 	{
       
    82 	cout << aMethodName << ": ";
       
    83 	if(aResult)
       
    84 		{
       
    85 		cout << Passed;
       
    86 		}
       
    87 	else
       
    88 		{
       
    89 		cout << Failed;
       
    90 		}
       
    91 	cout << endl;
       
    92 	}
       
    93 
       
    94 
       
    95 bool CTestXmlParser::TestValidDbFile()
       
    96 	{
       
    97 	bool retVal = false;
       
    98 	
       
    99 	try
       
   100 		{
       
   101 		string createDbFile(".\\scripts\\data\\create_db.xml");
       
   102 		vector<string>* schema = iXmlParser->ParseDbSchema(createDbFile);
       
   103 		retVal = true;
       
   104 		}
       
   105 	catch(CException& xmle)
       
   106 		{
       
   107 		LERROR(xmle.GetMessageA());
       
   108 		}
       
   109 	return retVal;
       
   110 	}
       
   111 
       
   112 
       
   113 bool CTestXmlParser::TestDbFileNotPresent()
       
   114 	{
       
   115 	bool retVal = false;
       
   116 	string createDbFile(".\\scripts\\data\\not_present.xml");
       
   117 	try
       
   118 		{
       
   119 		vector<string>* schema = iXmlParser->ParseDbSchema(createDbFile);
       
   120 		}
       
   121 	catch(CException& xmle)
       
   122 		{
       
   123 		
       
   124 		LERROR(xmle.GetMessageA());
       
   125 
       
   126 		if(xmle.GetCode() == (int)ExceptionCodes::EFatalError)
       
   127 			{
       
   128 			retVal = true;
       
   129 			}
       
   130 		}
       
   131 	return retVal;
       
   132 	}
       
   133 
       
   134 
       
   135 bool CTestXmlParser::TestEmptyDbFile()
       
   136 	{
       
   137 	bool retVal = false;
       
   138 	string createDbFile(".\\scripts\\data\\create_db_empty.xml");
       
   139 	try
       
   140 		{
       
   141 		vector<string>* schema = iXmlParser->ParseDbSchema(createDbFile);
       
   142 		
       
   143 		}
       
   144 	catch(CException& xmle)
       
   145 		{
       
   146 		
       
   147 		LERROR(xmle.GetMessageA());
       
   148 		
       
   149 		if(xmle.GetCode() == (int)ExceptionCodes::EFatalError)
       
   150 			{
       
   151 			retVal = true;
       
   152 			}
       
   153 		}
       
   154 	return retVal;
       
   155 	}
       
   156 
       
   157 
       
   158 bool CTestXmlParser::TestInvalidDbFiles()
       
   159 	{
       
   160 	bool retVal = false;
       
   161 	if( TestEndTagMissing() && TestInvalidRoot() && AgainstDtdSpec())
       
   162 		{
       
   163 		retVal = true;
       
   164 		}
       
   165 	return retVal;
       
   166 	}
       
   167 
       
   168 bool CTestXmlParser::TestInvalidRoot()
       
   169 	{
       
   170 	bool retVal = false;
       
   171 	
       
   172 	try
       
   173 		{
       
   174 		string createDbFile(".\\scripts\\data\\create_db_invalid_root.xml");
       
   175 		vector<string>* schema = iXmlParser->ParseDbSchema(createDbFile);
       
   176 		}
       
   177 	catch(CException& xmle)
       
   178 		{
       
   179 		
       
   180 		LERROR(xmle.GetMessageA());
       
   181 		
       
   182 		if(xmle.GetCode() == (int)ExceptionCodes::EParseError)
       
   183 			{
       
   184 			retVal = true;
       
   185 			}
       
   186 		}
       
   187 	return retVal;
       
   188 	}
       
   189 
       
   190 bool CTestXmlParser::TestEndTagMissing()
       
   191 	{
       
   192 	bool retVal = false;
       
   193 	try
       
   194 		{
       
   195 		string createDbFile(".\\scripts\\data\\create_db_end_tag_missing.xml");
       
   196 		vector<string>* schema = iXmlParser->ParseDbSchema(createDbFile);
       
   197 		
       
   198 		}
       
   199 	catch(CException& xmle)
       
   200 		{
       
   201 		
       
   202 		LERROR(xmle.GetMessageA());
       
   203 		
       
   204 		if(xmle.GetCode() == (int)ExceptionCodes::EFatalError)
       
   205 			{
       
   206 			retVal = true;
       
   207 			}
       
   208 		}
       
   209 	return retVal;
       
   210 	}
       
   211 
       
   212 bool CTestXmlParser::AgainstDtdSpec()
       
   213 	{
       
   214 	bool retVal = false;
       
   215 	
       
   216 	try
       
   217 		{
       
   218 		string createDbFile(".\\scripts\\data\\create_db_against_dtd_spec.xml");
       
   219 		vector<string>* schema = iXmlParser->ParseDbSchema(createDbFile);
       
   220 		}
       
   221 	catch(CException& xmle)
       
   222 		{
       
   223 		
       
   224 		LERROR(xmle.GetMessageA());
       
   225 		
       
   226 		if(xmle.GetCode() == (int)ExceptionCodes::EParseError)
       
   227 			{
       
   228 			retVal = true;
       
   229 			}
       
   230 		}
       
   231 	return retVal;
       
   232 	}
       
   233 
       
   234 bool CTestXmlParser::TestValidUpdateDb()
       
   235 	{
       
   236 	bool retVal = false;
       
   237 	try
       
   238 		{
       
   239 		string envFile(".\\scripts\\data\\update_db.xml");
       
   240 		vector<CScrXmlParser::TScrEnvironmentDetails>* envDetails = iXmlParser->GetEnvironmentDetails(envFile);
       
   241 		retVal = true;
       
   242 		}
       
   243 	catch(CException& xmle)
       
   244 		{
       
   245 		
       
   246 		LERROR(xmle.GetMessageA());
       
   247 		
       
   248 		}
       
   249 	return retVal;
       
   250 	}
       
   251 
       
   252 bool CTestXmlParser::TestUpdateFileNotPresent()
       
   253 	{
       
   254 	bool retVal = false;
       
   255 	string createDbFile(".\\scripts\\data\\not_present.xml");
       
   256 	try
       
   257 		{
       
   258 		vector<CScrXmlParser::TScrEnvironmentDetails>* envDetails = iXmlParser->GetEnvironmentDetails(createDbFile);
       
   259 		
       
   260 		}
       
   261 	catch(CException& xmle)
       
   262 		{
       
   263 		
       
   264 		LERROR(xmle.GetMessageA());
       
   265 		
       
   266 		if(xmle.GetCode() == (int)ExceptionCodes::EFatalError)
       
   267 			{
       
   268 			retVal = true;
       
   269 			}
       
   270 		}
       
   271 	return retVal;
       
   272 	}
       
   273 
       
   274 bool CTestXmlParser::TestEmptyUpdateFile()
       
   275 	{
       
   276 	bool retVal = false;
       
   277 	string createDbFile(".\\scripts\\data\\update_db_empty.xml");
       
   278 	
       
   279 	try
       
   280 		{
       
   281 		vector<CScrXmlParser::TScrEnvironmentDetails>* envDetails = iXmlParser->GetEnvironmentDetails(createDbFile);
       
   282 		
       
   283 		}
       
   284 	catch(CException& xmle)
       
   285 		{
       
   286 		
       
   287 		LERROR(xmle.GetMessageA());
       
   288 		
       
   289 		if(xmle.GetCode() == (int)ExceptionCodes::EFatalError)
       
   290 			{
       
   291 			retVal = true;
       
   292 			}
       
   293 		}
       
   294 	return retVal;
       
   295 	}
       
   296 
       
   297 bool CTestXmlParser::TestInvalidUpdateDb()
       
   298 	{
       
   299 	if(TestUpdateDbEndTagMissing() && TestUpdateDbInvalidRoot() &&	UpdateDbAgainstDtdSpec())
       
   300 		return true;
       
   301 	return false;
       
   302 	}
       
   303 
       
   304 
       
   305 bool CTestXmlParser::TestUpdateDbEndTagMissing()
       
   306 	{
       
   307 	bool retVal = false;
       
   308 	
       
   309 	try
       
   310 		{
       
   311 		string createDbFile(".\\scripts\\data\\update_db_end_tag_missing.xml");
       
   312 		vector<CScrXmlParser::TScrEnvironmentDetails>* envDetails = iXmlParser->GetEnvironmentDetails(createDbFile);
       
   313 		
       
   314 		}
       
   315 	catch(CException& xmle)
       
   316 		{
       
   317 		
       
   318 		LERROR(xmle.GetMessageA());
       
   319 		
       
   320 		if(xmle.GetCode() == (int)ExceptionCodes::EFatalError)
       
   321 			{
       
   322 			retVal = true;
       
   323 			}
       
   324 		}
       
   325 	return retVal;
       
   326 	}
       
   327 
       
   328 bool CTestXmlParser::TestUpdateDbInvalidRoot()
       
   329 	{
       
   330 	bool retVal = false;
       
   331 	
       
   332 	try
       
   333 		{
       
   334 		string createDbFile(".\\scripts\\data\\update_db_invalid_root.xml");
       
   335 		vector<CScrXmlParser::TScrEnvironmentDetails>* envDetails = iXmlParser->GetEnvironmentDetails(createDbFile);
       
   336 		
       
   337 		}
       
   338 	catch(CException& xmle)
       
   339 		{
       
   340 		
       
   341 		LERROR(xmle.GetMessageA());
       
   342 		
       
   343 		if(xmle.GetCode() == (int)ExceptionCodes::EParseError)
       
   344 			{
       
   345 			retVal = true;
       
   346 			}
       
   347 		}
       
   348 	return retVal;
       
   349 	}
       
   350 
       
   351 bool CTestXmlParser::UpdateDbAgainstDtdSpec()
       
   352 	{
       
   353 	bool retVal = false;
       
   354 	
       
   355 	try
       
   356 		{
       
   357 		string createDbFile(".\\scripts\\data\\update_db_against_dtd_spec.xml");
       
   358 		vector<CScrXmlParser::TScrEnvironmentDetails>* envDetails = iXmlParser->GetEnvironmentDetails(createDbFile);
       
   359 		
       
   360 		}
       
   361 	catch(CException& xmle)
       
   362 		{
       
   363 		
       
   364 		LERROR(xmle.GetMessageA());
       
   365 		
       
   366 		if(xmle.GetCode() == (int)ExceptionCodes::EParseError)
       
   367 			{
       
   368 			retVal = true;
       
   369 			}
       
   370 		}
       
   371 	return retVal;
       
   372 	}
       
   373 
       
   374 
       
   375 void CTestXmlParser::DisplayDetails(std::vector<std::string>& aDetails)
       
   376 	{
       
   377 	for(StringIterator iter=aDetails.begin(); iter != aDetails.end(); ++iter)
       
   378 		{
       
   379 		cout << *iter << endl;
       
   380 		}
       
   381 	}
       
   382 
       
   383 void CTestXmlParser::DisplayDetails(vector<CScrXmlParser::TScrEnvironmentDetails>& aEnvDetails)
       
   384 	{
       
   385 	for(envDetailsIter iter=aEnvDetails.begin(); iter != aEnvDetails.end(); ++iter)
       
   386 		{
       
   387 		cout << "Software type name:" << iter->iSoftwareTypeName << endl;
       
   388 		cout << "SIF Plugin Id:" << iter->iSifPluginUid << endl;
       
   389 		cout << "Installer Sid:" << iter->iInstallerSid << endl;
       
   390 		cout << "Execution Layer Sid:" << iter->iExecutionLayerSid << endl;
       
   391 		cout << "MIME Details" << endl;
       
   392 		for(vector<string>::iterator mimeiter = iter->iMIMEDetails.begin() ; mimeiter != iter->iMIMEDetails.end() ; ++mimeiter )
       
   393 			{
       
   394 			cout << "MIME Type:" << *mimeiter << endl;
       
   395 			}
       
   396 		}
       
   397 	}
       
   398