diff -r 000000000000 -r ba25891c3a9e secureswitools/swisistools/test/txmlparser/txmlparser.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/secureswitools/swisistools/test/txmlparser/txmlparser.cpp Thu Dec 17 08:51:10 2009 +0200 @@ -0,0 +1,398 @@ +/* +* Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* CTestXmlParser - Used to testing retrieval of data pertianing to creation and updation +* of database. +* +*/ + + +/** + @file + @released + @internalTechnology +*/ + +#include +#include +#include +#include + +#include + +#include "txmlparser.h" +#include "xmlparser.h" +#include "exception.h" +#include "logger.h" +#include "../../source/common/utility.h" + +using namespace std; + +typedef vector::iterator StringIterator; + +typedef vector::iterator envDetailsIter; + +std::string CTestXmlParser::Passed = "Passed"; +std::string CTestXmlParser::Failed = "Failed"; + +CTestXmlParser::CTestXmlParser() + { + std::string logFile = "xmlparse.log"; + CLogger::TLogLevel logLevel = static_cast( CLogger::ELogEnter | CLogger::ELogExit); + iLogger = new CLogger(logFile, logLevel); + iXmlParser = new CScrXmlParser(); + } + +CTestXmlParser::~CTestXmlParser() + { + delete iXmlParser; + delete iLogger; + } + +CTestXmlParser::TestParser() + { + + // tests for createdb xml schema + PrintResult("TestValidDbFile()",TestValidDbFile()); + PrintResult("TestDbFileNotPresent",TestDbFileNotPresent()); + PrintResult("TestEmptyDbFile",TestEmptyDbFile()); + PrintResult("TestInvalidDbFiles",TestInvalidDbFiles()); + + PrintResult("TestValidUpdateDb",TestValidUpdateDb()); + PrintResult("TestUpdateFileNotPresent",TestUpdateFileNotPresent()); + PrintResult("TestEmptyUpdateFile",TestEmptyUpdateFile()); + PrintResult("TestInvalidUpdateDb",TestInvalidUpdateDb()); + + } + + +void CTestXmlParser::PrintResult(const char* aMethodName, bool aResult) + { + cout << aMethodName << ": "; + if(aResult) + { + cout << Passed; + } + else + { + cout << Failed; + } + cout << endl; + } + + +bool CTestXmlParser::TestValidDbFile() + { + bool retVal = false; + + try + { + string createDbFile(".\\scripts\\data\\create_db.xml"); + vector* schema = iXmlParser->ParseDbSchema(createDbFile); + retVal = true; + } + catch(CException& xmle) + { + LERROR(xmle.GetMessageA()); + } + return retVal; + } + + +bool CTestXmlParser::TestDbFileNotPresent() + { + bool retVal = false; + string createDbFile(".\\scripts\\data\\not_present.xml"); + try + { + vector* schema = iXmlParser->ParseDbSchema(createDbFile); + } + catch(CException& xmle) + { + + LERROR(xmle.GetMessageA()); + + if(xmle.GetCode() == (int)ExceptionCodes::EFatalError) + { + retVal = true; + } + } + return retVal; + } + + +bool CTestXmlParser::TestEmptyDbFile() + { + bool retVal = false; + string createDbFile(".\\scripts\\data\\create_db_empty.xml"); + try + { + vector* schema = iXmlParser->ParseDbSchema(createDbFile); + + } + catch(CException& xmle) + { + + LERROR(xmle.GetMessageA()); + + if(xmle.GetCode() == (int)ExceptionCodes::EFatalError) + { + retVal = true; + } + } + return retVal; + } + + +bool CTestXmlParser::TestInvalidDbFiles() + { + bool retVal = false; + if( TestEndTagMissing() && TestInvalidRoot() && AgainstDtdSpec()) + { + retVal = true; + } + return retVal; + } + +bool CTestXmlParser::TestInvalidRoot() + { + bool retVal = false; + + try + { + string createDbFile(".\\scripts\\data\\create_db_invalid_root.xml"); + vector* schema = iXmlParser->ParseDbSchema(createDbFile); + } + catch(CException& xmle) + { + + LERROR(xmle.GetMessageA()); + + if(xmle.GetCode() == (int)ExceptionCodes::EParseError) + { + retVal = true; + } + } + return retVal; + } + +bool CTestXmlParser::TestEndTagMissing() + { + bool retVal = false; + try + { + string createDbFile(".\\scripts\\data\\create_db_end_tag_missing.xml"); + vector* schema = iXmlParser->ParseDbSchema(createDbFile); + + } + catch(CException& xmle) + { + + LERROR(xmle.GetMessageA()); + + if(xmle.GetCode() == (int)ExceptionCodes::EFatalError) + { + retVal = true; + } + } + return retVal; + } + +bool CTestXmlParser::AgainstDtdSpec() + { + bool retVal = false; + + try + { + string createDbFile(".\\scripts\\data\\create_db_against_dtd_spec.xml"); + vector* schema = iXmlParser->ParseDbSchema(createDbFile); + } + catch(CException& xmle) + { + + LERROR(xmle.GetMessageA()); + + if(xmle.GetCode() == (int)ExceptionCodes::EParseError) + { + retVal = true; + } + } + return retVal; + } + +bool CTestXmlParser::TestValidUpdateDb() + { + bool retVal = false; + try + { + string envFile(".\\scripts\\data\\update_db.xml"); + vector* envDetails = iXmlParser->GetEnvironmentDetails(envFile); + retVal = true; + } + catch(CException& xmle) + { + + LERROR(xmle.GetMessageA()); + + } + return retVal; + } + +bool CTestXmlParser::TestUpdateFileNotPresent() + { + bool retVal = false; + string createDbFile(".\\scripts\\data\\not_present.xml"); + try + { + vector* envDetails = iXmlParser->GetEnvironmentDetails(createDbFile); + + } + catch(CException& xmle) + { + + LERROR(xmle.GetMessageA()); + + if(xmle.GetCode() == (int)ExceptionCodes::EFatalError) + { + retVal = true; + } + } + return retVal; + } + +bool CTestXmlParser::TestEmptyUpdateFile() + { + bool retVal = false; + string createDbFile(".\\scripts\\data\\update_db_empty.xml"); + + try + { + vector* envDetails = iXmlParser->GetEnvironmentDetails(createDbFile); + + } + catch(CException& xmle) + { + + LERROR(xmle.GetMessageA()); + + if(xmle.GetCode() == (int)ExceptionCodes::EFatalError) + { + retVal = true; + } + } + return retVal; + } + +bool CTestXmlParser::TestInvalidUpdateDb() + { + if(TestUpdateDbEndTagMissing() && TestUpdateDbInvalidRoot() && UpdateDbAgainstDtdSpec()) + return true; + return false; + } + + +bool CTestXmlParser::TestUpdateDbEndTagMissing() + { + bool retVal = false; + + try + { + string createDbFile(".\\scripts\\data\\update_db_end_tag_missing.xml"); + vector* envDetails = iXmlParser->GetEnvironmentDetails(createDbFile); + + } + catch(CException& xmle) + { + + LERROR(xmle.GetMessageA()); + + if(xmle.GetCode() == (int)ExceptionCodes::EFatalError) + { + retVal = true; + } + } + return retVal; + } + +bool CTestXmlParser::TestUpdateDbInvalidRoot() + { + bool retVal = false; + + try + { + string createDbFile(".\\scripts\\data\\update_db_invalid_root.xml"); + vector* envDetails = iXmlParser->GetEnvironmentDetails(createDbFile); + + } + catch(CException& xmle) + { + + LERROR(xmle.GetMessageA()); + + if(xmle.GetCode() == (int)ExceptionCodes::EParseError) + { + retVal = true; + } + } + return retVal; + } + +bool CTestXmlParser::UpdateDbAgainstDtdSpec() + { + bool retVal = false; + + try + { + string createDbFile(".\\scripts\\data\\update_db_against_dtd_spec.xml"); + vector* envDetails = iXmlParser->GetEnvironmentDetails(createDbFile); + + } + catch(CException& xmle) + { + + LERROR(xmle.GetMessageA()); + + if(xmle.GetCode() == (int)ExceptionCodes::EParseError) + { + retVal = true; + } + } + return retVal; + } + + +void CTestXmlParser::DisplayDetails(std::vector& aDetails) + { + for(StringIterator iter=aDetails.begin(); iter != aDetails.end(); ++iter) + { + cout << *iter << endl; + } + } + +void CTestXmlParser::DisplayDetails(vector& aEnvDetails) + { + for(envDetailsIter iter=aEnvDetails.begin(); iter != aEnvDetails.end(); ++iter) + { + cout << "Software type name:" << iter->iSoftwareTypeName << endl; + cout << "SIF Plugin Id:" << iter->iSifPluginUid << endl; + cout << "Installer Sid:" << iter->iInstallerSid << endl; + cout << "Execution Layer Sid:" << iter->iExecutionLayerSid << endl; + cout << "MIME Details" << endl; + for(vector::iterator mimeiter = iter->iMIMEDetails.begin() ; mimeiter != iter->iMIMEDetails.end() ; ++mimeiter ) + { + cout << "MIME Type:" << *mimeiter << endl; + } + } + } +