securityanddataprivacytools/securitytools/certapp/test/tcertapp/tcertapp.cpp
changeset 0 2c201484c85f
child 8 35751d3474b7
equal deleted inserted replaced
-1:000000000000 0:2c201484c85f
       
     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 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <iostream>
       
    20 #include "certapp-api.h"
       
    21 #include "badconfigwriter.h"
       
    22 #include "tcertapp_good.h"
       
    23 #include "tcertapp_bad.h"
       
    24 #include "goodconfigwriter.h"
       
    25 #include <string>
       
    26 #include <sstream>
       
    27 #include <stdlib.h>
       
    28 #include <stdio.h>
       
    29 #include "logger.h"
       
    30 #include "utils.h"
       
    31 
       
    32 using namespace std;
       
    33 
       
    34 //Funtions to generate Good/Valid config files for tcertapp
       
    35 void GoodFileCaCertTests(const stringstream &aFilename, int aArray_value);
       
    36 void GoodFileCertClientsTests(const stringstream &aFilename);
       
    37 void GoodSwiCertTests(const stringstream &aFilename, int aArray_value);
       
    38 
       
    39 //Functions to generate Good/Valid script files for emulator tests
       
    40 void GenerateGoodCaCertsTestScripts(const stringstream &aFilename);
       
    41 void GenerateGoodCertClientTestScripts(const stringstream &aFilename);
       
    42 void GenerateGoodSwiCertTestScripts(const stringstream &aFilename);
       
    43 
       
    44 //Funtions to generate Bad/illegal config files for tcertapp
       
    45 void BadFileCaCertTests(const stringstream &aFilename, int aArray_value);
       
    46 void BadFileCertClientsTests(const stringstream &aFilename, int aIndex);
       
    47 void BadSwiCertTests(const stringstream &aFilename, int aArray_value);
       
    48 
       
    49 //Function call for RunCertApp api
       
    50 void RunCertAppTool(int argc, char **argv, stringstream &aStringval);
       
    51 void RunCertAppToolForStoreDump(int aArgc, char **aArgv, stringstream &aStringval); 
       
    52 void RunCertAppToolForBadParams(int aArgc, char **aArgv, stringstream &aStringval); 
       
    53 
       
    54 void TestsWithEmptyConfigFile();
       
    55 void CreateFileToAugmentStore();
       
    56 void TestsWithEncodedFileFormats();
       
    57 void TestToDecodeAndEncodeStore();
       
    58 void TestToReviewingAggregateStore();
       
    59 void TestBadConfigFiles(const stringstream &aFilename, bool aBool);
       
    60 void CertClientBadParamsFuncCall(stringstream &aFileName);
       
    61 void decodeEncodeCertAppCall(const char *aArray[]);
       
    62 int CompareFiles(stringstream &aFileName1, stringstream &aFileName2);
       
    63 int Compare(istream &aIstream1, istream &aIstream2);
       
    64 void TestWithUnicodFileName();
       
    65 
       
    66 ofstream file; //global file handle to write to output file
       
    67 const char *progress = "progress.txt";  // logs the progress report
       
    68 const char *errors = "error.txt";       // logs the error report
       
    69 
       
    70 //some constants used
       
    71 const int KFileArrayIndex = 8;
       
    72 const int KSwicertIndex = 10;
       
    73 const int KSwiBadcertIndex = 11;
       
    74 const int KFileBadcertIndex = 9;
       
    75 const int KAppUidIndex = 4; 
       
    76 const int KIndex = 4;
       
    77 
       
    78 // to get the count of passed and failed test cases
       
    79 static int failCount = 0, passCount = 0;
       
    80 
       
    81 //pointers required for creation of good filecerts config files
       
    82 const char **filecert_array[KFileArrayIndex]=
       
    83 {
       
    84 	goodCert_array,
       
    85 	goodDeletables,
       
    86 	goodFormats,
       
    87 	goodCertOwnerTypes,
       
    88 	goodSubjectKeyIds,
       
    89 	goodIssuerKeyIds,
       
    90 	goodApplications,
       
    91 	goodTrusteds
       
    92 };
       
    93 
       
    94 //pointers required for creation of bad filecerts config files
       
    95 const char **badfilecert_array[KFileBadcertIndex]=
       
    96 {
       
    97 	badLabels,
       
    98 	badDeletables,
       
    99 	badFormats,
       
   100 	badCertOwnerTypes,
       
   101 	badSubjectKeyIds,
       
   102 	badIssuerKeyIds,
       
   103 	badApplications,
       
   104 	badTrusteds,
       
   105 	badDatafilePath
       
   106 };
       
   107 
       
   108 
       
   109 //pointers required for creation of good swicerts config files
       
   110 const char **swicert_array[KSwicertIndex]=
       
   111 {
       
   112 	goodLabels,
       
   113 	goodFormats,
       
   114 	goodCertOwnerTypes,
       
   115 	goodSubjectKeyIds,
       
   116 	goodIssuerKeyIds,
       
   117 	goodAppNames,
       
   118 	goodTrusteds,
       
   119 	goodCapabilitySets,
       
   120 	goodMandatory,
       
   121 	goodSystemUpgrade
       
   122 };
       
   123 
       
   124 //pointers required for creation of bad swicerts config files
       
   125 const char **badswicert_array[KSwiBadcertIndex]=
       
   126 {
       
   127 	badLabels,
       
   128 	badFormats,
       
   129 	badCertOwnerTypes,
       
   130 	badSubjectKeyIds,
       
   131 	badIssuerKeyIds,
       
   132 	badApplications,
       
   133 	badTrusteds,
       
   134 	badDatafilePath,
       
   135 	badCapabilitySets,
       
   136 	badMandatory,
       
   137 	badSystemUpgrade
       
   138 };
       
   139 
       
   140 
       
   141 //encoded file names for input to the tool
       
   142 const char *fileEncodeType[4]=
       
   143 {
       
   144 "--hfilecertstore=utf8.txt",
       
   145 "--hfilecertstore=utf8_without_bom.txt",
       
   146 "--hfilecertstore=ucs2-bigendian.txt",
       
   147 "--hfilecertstore=ucs2-littleendian.txt"
       
   148 };
       
   149 
       
   150 
       
   151 //RunCertApp call to create store from text input
       
   152 void RunCertAppTool( int argc, char **argv, stringstream &stringval)
       
   153 {
       
   154 	for(int i =0; i<argc; i++)
       
   155 		{
       
   156 		cout << "Arguments Being passed to the RunCertApp tool is " << argv[i] << endl;
       
   157 		}
       
   158 	int ret = RunCertApp(progress, errors, argc, argv); 
       
   159 	cout << "Return Value from CertApp Tool is " << ret << endl;
       
   160 	if(ret!= 0)
       
   161 		{
       
   162 		failCount++;
       
   163 		file<< "Error in creating store for " << stringval.str() << " and result is " << ret << " Fail" << endl ;
       
   164 		}
       
   165 	else
       
   166 		{
       
   167 		passCount++;
       
   168 		file << "No Error in creating store for " << stringval.str() << " and result is " << ret << " Pass" <<endl ;
       
   169 		}
       
   170 }
       
   171 
       
   172 //RunCertApp call to dump the store to human readable format
       
   173 void RunCertAppToolForStoreDump(int argc, char **argv, stringstream &stringval)
       
   174 {
       
   175 	int ret = RunCertApp(progress, errors, argc, argv); 
       
   176 	cout << "Return Value from CertApp Tool is " << ret << endl;
       
   177 	if(ret!= 0)
       
   178 		{
       
   179 		failCount++;
       
   180 		file<< "Error in Dumping the store file for " << stringval.str() << " and result is " << ret << " Fail" << endl ;
       
   181 		}
       
   182 	else
       
   183 		{
       
   184 		passCount++;
       
   185 		file << "No Error in Dumping store for " << stringval.str() << " and result is " << ret << " Pass" <<endl ;
       
   186 		}
       
   187 }
       
   188 
       
   189 //RunCertApp call to create store for bad params
       
   190 void RunCertAppToolForBadParams(int argc, char **argv, stringstream &stringval)
       
   191 {
       
   192 	int ret = RunCertApp(progress, errors, argc, argv); 
       
   193 	if(ret!= 0)
       
   194 		{
       
   195 		passCount++;
       
   196 		cout << "We have passsed bad paramerters! Expected Return value is -1 And the RunCertApp has returned " << ret << " as Expected"<< endl;
       
   197 		file<< "Bad Params! So Cannot create the store for " << stringval.str() << " and result is " << ret << " Pass" << endl ;
       
   198 		}
       
   199 	else
       
   200 		{
       
   201 		failCount++;
       
   202 		file << "We are using bad parameters! So the tools should fail to create store! " << stringval.str() << " and result is " << ret << " Fail" <<endl ;
       
   203 		cout << "We have passsed bad paramerters! The Tool has failed- It should return -1, But returned" << ret << endl;
       
   204 		}
       
   205 }
       
   206 
       
   207 
       
   208 /**
       
   209 main entry to the program
       
   210 */
       
   211 int main(int /*argc*/, char ** /*argv*/)
       
   212 {
       
   213 	dbg.SetStream(&std::cout);
       
   214 	prog.SetStream(&std::cout);
       
   215 	std::cout << std::dec;
       
   216 
       
   217 	int num_tests = 0; 
       
   218 	int argCount3 = 3;
       
   219 	int argCount4 = 4;
       
   220 	// File to log the result of all tests
       
   221 	if(file)
       
   222 		{
       
   223 		file.open("tCertapp_Output.txt", ios_base::trunc | ios_base::out);
       
   224 		}
       
   225 
       
   226 	//create a file to augment the content to existing store
       
   227 	CreateFileToAugmentStore();
       
   228 
       
   229 	//create certclient config files 
       
   230 	//Format used for the files name is SDP-Security_Tools-CertApp-XXX-000X  to match with the TMS test case id
       
   231 	stringstream certclientfileName;
       
   232 	certclientfileName << "SDP-Security_Tools-CertApp-CCDAT_000"<<num_tests<<".txt";
       
   233 	GoodFileCertClientsTests(certclientfileName);
       
   234 	
       
   235 	//create command line argument for creation of certclientx.dat through certapp tool
       
   236 	stringstream strArg1, strArg2, augFileName;
       
   237 	strArg1 <<"--hcertclients=" << certclientfileName.str();
       
   238 	cout << "test" << strArg1.str().c_str() <<endl;
       
   239 
       
   240 	strArg2<< "--bcertclients=SDP-Security_Tools-CertApp-CCDAT_000" <<num_tests <<".dat";
       
   241 	cout <<"string value is " << strArg2.str().c_str() << endl;		
       
   242 	
       
   243 	string argument1, argument2;
       
   244 	const char *argv_certclient[4];
       
   245 	
       
   246 	argument1 = strArg1.str().c_str();
       
   247 	argv_certclient[0] = argument1.c_str();
       
   248 			
       
   249 	argv_certclient[1] = "--out";
       
   250 	argument2 = strArg2.str().c_str();
       
   251 	argv_certclient[2] = argument2.c_str();
       
   252 
       
   253 	char **argv, **argv1;
       
   254 	char *argument_ptr[3]; //[Format:: certapp --hcertclients=t_certclients_0.txt --out --bcertclients=certclients5.dat]
       
   255 
       
   256 	for(int n1 = 0; n1<argCount3; n1++)
       
   257 		{
       
   258 		argument_ptr[n1] = const_cast<char*>(argv_certclient[n1]);
       
   259 		argv = argument_ptr;
       
   260 		}
       
   261 	
       
   262 	RunCertAppTool(argCount3, argv, certclientfileName); // creating dat file
       
   263 	
       
   264 	//Augment the Store with Extra entries
       
   265 	augFileName<<"SDP-Security_Tools-CertApp-CCAUG_0000.dat";
       
   266 	argv_certclient[0] = "--hcertclients=tCertClient_Augment.txt";
       
   267 	argv_certclient[1] =  argv_certclient[2];  
       
   268 	argv_certclient[2] = "--out";
       
   269 	argv_certclient[3] = "--bcertclients=SDP-Security_Tools-CertApp-CCAUG_0000.dat";
       
   270 	for(int x = 0; x<argCount4; x++)
       
   271 			{
       
   272 			argument_ptr[x] = const_cast<char*>(argv_certclient[x]);
       
   273 			argv1 = argument_ptr;   
       
   274 			}
       
   275 	RunCertAppTool(argCount4, argv1, augFileName);
       
   276 
       
   277 	//Dump the dat file to human readable text format
       
   278 	argv_certclient[0] = argv_certclient[3];
       
   279 	argv_certclient[1] = "--out";
       
   280 	argv_certclient[2] = "--hcertclients=SDP-Security_Tools-CertApp-CCDUMP_0000.txt";
       
   281 			
       
   282 	for(int k = 0; k<argCount3; k++)
       
   283 		{
       
   284 		argument_ptr[k] = const_cast<char*>(argv_certclient[k]);
       
   285 		argv1 = argument_ptr;
       
   286 		}
       
   287 	RunCertAppToolForStoreDump(argCount3, argv1, certclientfileName); 
       
   288 	//End of t_certclients
       
   289 	
       
   290 	//Creates good config files to augment store and dump store to text format for file certstore - cacerts.dat
       
   291 	//Test for all positive cases
       
   292 	for(num_tests = 0; num_tests<=KFileArrayIndex; num_tests++)
       
   293 		{
       
   294 		stringstream caCertFileName;
       
   295 		caCertFileName << "SDP-Security_Tools-CertApp-FILEDAT_000"<<num_tests<<".txt";
       
   296 		GoodFileCaCertTests(caCertFileName,num_tests);
       
   297 
       
   298 		// CREATE CACERTS STORE FROM HUMAN READABLE TEXT INPUT
       
   299 		//ex:certapp --hcertclients=t_certclients_0.txt --hfilecertstore=t_cacerts_0.txt --out --bfilecertstore=cacerts_x.dat
       
   300 		stringstream strArg1, strArg2, strArg3, strArg4, strArg5;
       
   301 		strArg1 <<"--hfilecertstore=SDP-Security_Tools-CertApp-FILEDAT_000" <<num_tests << ".txt" ; 
       
   302 		
       
   303 		strArg2<< "--bfilecertstore=SDP-Security_Tools-CertApp-FILEDAT_000"<<num_tests <<".dat";
       
   304 		cout <<"string value is " << strArg2.str().c_str() << endl;	
       
   305 		
       
   306 		strArg3<< "--hcertclients=SDP-Security_Tools-CertApp-CCDAT_0000.txt";
       
   307 		cout <<"string value is " << strArg3.str().c_str() << endl;
       
   308 
       
   309 		string argument1, argument2, argument3, argument4, argument5;
       
   310 		const char *argv_certclient[4];
       
   311 		
       
   312 		argument1 = strArg1.str().c_str();
       
   313 		argument3 = strArg3.str().c_str();
       
   314 
       
   315 		argv_certclient[0] = argument3.c_str(); // --hcertclients=t_certclients_0.txt
       
   316 		argv_certclient[1] = argument1.c_str(); // --hfilecertstore=t_cacerts_x.txt
       
   317 		argv_certclient[2] = "--out";			//--out
       
   318 		argument2 = strArg2.str().c_str();
       
   319 		argv_certclient[3] = argument2.c_str(); //--bfilecertstore=cacerts_x.dat
       
   320 
       
   321 		char *argument_ptr[4]; 
       
   322 		char **argv, **argv1, **argv2 ;
       
   323 		for(int n = 0; n<argCount4; n++)
       
   324 			{
       
   325 			argument_ptr[n] = const_cast<char*>(argv_certclient[n]);
       
   326 			argv = argument_ptr;  
       
   327 			}
       
   328 		RunCertAppTool(argCount4, argv, caCertFileName); 
       
   329 
       
   330 		//AUGMENT THE CACERT STORE WITH EXTRA INFORMATION
       
   331 		//ex:certapp  --hfilecertstore=tAugment_cacerts_x.txt  --bfilecertstore=cacerts.dat --out --bfilecertstore=new_extra_filecertstore.dat
       
   332 		stringstream augFileName, textDumpFileName;
       
   333 		augFileName<<"SDP-Security_Tools-CertApp-FILEAUG_000" <<num_tests << ".dat";
       
   334 		strArg4<<"--bfilecertstore=SDP-Security_Tools-CertApp-FILEAUG_000" << num_tests << ".dat";
       
   335 		argument4 = strArg4.str();
       
   336 		argv_certclient[0] =  "--hfilecertstore=tfile_Augment.txt";  //--hfilecertstore=tAugment_cacerts_x.txt
       
   337 		argv_certclient[1] =  argv_certclient[3]; //--bfilecertstore=cacerts_x.dat
       
   338 		argv_certclient[2] = "--out";			  //--out
       
   339 		argv_certclient[3] = argument4.c_str();  //--bfilecertstore=aug_cacerts_x.dat
       
   340 		
       
   341 		for(int x = 0; x<argCount4; x++)
       
   342 			{
       
   343 			argument_ptr[x] = const_cast<char*>(argv_certclient[x]);
       
   344 			argv1 = argument_ptr;   
       
   345 			}
       
   346 		RunCertAppTool(argCount4, argv1, augFileName);
       
   347 
       
   348 		//DUMP THE STORE TO HUMAN READABLE FORMAT
       
   349 		//ex:certapp --bfilecertstore=test.dat --out --hfilecertstore=t_cacerts.txt 
       
   350 		textDumpFileName <<"SDP-Security_Tools-CertApp-FILEDUMP_000"<< num_tests << ".txt";
       
   351 		argv_certclient[0] =  argv_certclient[3];  //--bfilecertstore=aug_cacerts_x.dat
       
   352 		argv_certclient[1] = "--out";
       
   353 		strArg5<< "--hfilecertstore=SDP-Security_Tools-CertApp-FILEDUMP_000" <<num_tests << ".txt";
       
   354 		argument5 = strArg5.str().c_str();
       
   355 		argv_certclient[2] = argument5.c_str();
       
   356 						
       
   357 		for(int k = 0; k<argCount3; k++)
       
   358 			{
       
   359 			argument_ptr[k] = const_cast<char*>(argv_certclient[k]);
       
   360 			argv2 = argument_ptr;
       
   361 			}
       
   362 		//Dumps the augmented store
       
   363 		RunCertAppToolForStoreDump(argCount3, argv2, textDumpFileName); 
       
   364 		}//End of cacerts
       
   365 
       
   366 
       
   367 	//create config files with legal values for swi certstore 
       
   368 	for(num_tests = 0; num_tests<KSwicertIndex; num_tests++)
       
   369 		{
       
   370 		stringstream swiCertStoreFileName;
       
   371 		swiCertStoreFileName << "SDP-Security_Tools-CertApp-SWIDAT_000"<<num_tests<<".txt";
       
   372 		GoodSwiCertTests(swiCertStoreFileName,num_tests);
       
   373 
       
   374 		//CREATE THE SWICERTSTORE  FROM THE HUMAN READABLE TEXT INPUT
       
   375 		//Ex: certapp --hcertclients=t_certclients_0.txt --hswicertstore=t_swicertstore_0.txt --out --bswicertstore=swicertstore_x.dat
       
   376 		stringstream strArg1, strArg2, strArg3, strArg4, strArg5;
       
   377 		strArg1 <<"--hswicertstore=SDP-Security_Tools-CertApp-SWIDAT_000" <<num_tests << ".txt" ; //--hswicertstore=t_cacerts_x.txt
       
   378 		
       
   379 		strArg2<< "--bswicertstore=SDP-Security_Tools-CertApp-SWIDAT_000" <<num_tests <<".dat"; //--bswicertstore=swicertstore.dat
       
   380 		cout <<"string value is " << strArg2.str().c_str() << endl;	
       
   381 		
       
   382 		strArg3<< "--hcertclients=SDP-Security_Tools-CertApp-CCDAT_0000.txt";
       
   383 		cout <<"string value is " << strArg3.str().c_str() << endl;
       
   384 
       
   385 		string argument1, argument2, argument3, argument4, argument5;
       
   386 		const char *argv_certclient[4];
       
   387 		
       
   388 		argument1 = strArg1.str().c_str();
       
   389 		argument3 = strArg3.str().c_str();
       
   390 
       
   391 		argv_certclient[0] = argument3.c_str(); //--hcertclients=t_certclients_0.txt
       
   392 		argv_certclient[1] = argument1.c_str(); //--hswicertstore=t_swicertstore_
       
   393 		argv_certclient[2] = "--out";
       
   394 		argument2 = strArg2.str().c_str();
       
   395 		argv_certclient[3] = argument2.c_str();  //--bswicertstore=swicertstore_x.dat
       
   396 
       
   397 	    char *argument_ptr[4]; 
       
   398 	
       
   399 		for(int j=0; j<argCount4; j++)
       
   400 			{
       
   401 			cout << "Value in argv_certclient " << j << "is " <<argv_certclient[j] <<endl;
       
   402 			}
       
   403 
       
   404 		char **argv;
       
   405 		for(int n = 0; n<argCount4; n++)
       
   406 			{
       
   407 			argument_ptr[n] = const_cast<char*>(argv_certclient[n]);
       
   408 			argv = argument_ptr;
       
   409 			}
       
   410 		RunCertAppTool(argCount4, argv,swiCertStoreFileName); 
       
   411 
       
   412 		//AUGMENT THE CACERT STORE WITH EXTRA INFORMATION
       
   413 		//certapp  --hswicertstore=tAugment_swicertstore_x.txt  --bswicertstore=swicertstore_x.dat --out --bswicertstore=aug_swicertstore_x.dat
       
   414 		stringstream augFileName, textDumpFileName;
       
   415 		augFileName << "SDP-Security_Tools-CertApp-SWIAUG_000" << num_tests <<".dat";
       
   416 		strArg4<<"--bswicertstore=SDP-Security_Tools-CertApp-SWIAUG_000" << num_tests << ".dat";
       
   417 		argument4 = strArg4.str();
       
   418 		argv_certclient[0] =  "--hswicertstore=tswi_Augment.txt";  //--hswicertstore=tAugment_swicertstore_x.txt
       
   419 		argv_certclient[1] =  argv_certclient[3]; //--bswicertstore=swicertstore_x.dat
       
   420 		argv_certclient[2] = "--out";
       
   421 		argv_certclient[3] = argument4.c_str();  //--bswicertstore=aug_swicertstore_x.dat
       
   422 		char **argv1;
       
   423 		for(int x = 0; x<argCount4; x++)
       
   424 			{
       
   425 			argument_ptr[x] = const_cast<char*>(argv_certclient[x]);
       
   426 			argv1 = argument_ptr;   
       
   427 			}
       
   428 		RunCertAppTool(argCount4, argv1, augFileName);
       
   429 
       
   430 		//DUMP THE SWI CERTSTORE TO HUMAN READABLE FORMAT
       
   431 		textDumpFileName << "SDP-Security_Tools-CertApp-SWIDUMP_000" <<num_tests << ".txt";
       
   432 		argv_certclient[0] =  argv_certclient[3];  
       
   433 		argv_certclient[1] = "--out";
       
   434 		strArg5<< "--hswicertstore=SDP-Security_Tools-CertApp-SWIDUMP_000" <<num_tests << ".txt";
       
   435 		argument5= strArg5.str().c_str();
       
   436 		argv_certclient[2] = argument5.c_str();
       
   437 			
       
   438 		char ** argv2;
       
   439 		for(int k = 0; k<argCount3; k++)
       
   440 			{
       
   441 			argument_ptr[k] = const_cast<char*>(argv_certclient[k]);
       
   442 			argv2 = argument_ptr;
       
   443 			}
       
   444 
       
   445 		RunCertAppToolForStoreDump(argCount3, argv2, textDumpFileName); 
       
   446 		}
       
   447 	
       
   448 	//Test with unicode filename
       
   449 	TestWithUnicodFileName();
       
   450 
       
   451 	//create empty config file
       
   452 	TestsWithEmptyConfigFile();
       
   453 
       
   454 	//Test case to test for different file formats
       
   455 	TestsWithEncodedFileFormats();
       
   456 
       
   457 	//Test case for REQ10313 to check decode/encode of stores
       
   458 	TestToDecodeAndEncodeStore();
       
   459 
       
   460 	//Test case for REQ10314 - reviewing aggregate certificate database
       
   461 	TestToReviewingAggregateStore();
       
   462 
       
   463 	//Test cases for BAD Params
       
   464 	//create certclient config files 
       
   465 	for(num_tests =0; num_tests<3; num_tests++) 
       
   466 		{
       
   467 		stringstream badCertClientsFileName;
       
   468 		badCertClientsFileName << "SDP-Security_Tools-CertApp-CCBadParams-000"<<num_tests;
       
   469 		BadFileCertClientsTests(badCertClientsFileName,num_tests);
       
   470 		} //End of bad params for cerclients
       
   471 
       
   472 	//create bad config files for file certstore - cacerts.dat
       
   473 	for(num_tests = 0; num_tests<KFileArrayIndex+1; num_tests++)
       
   474 		{
       
   475 		stringstream badCaCertsFileName;
       
   476 		badCaCertsFileName << "SDP-Security_Tools-CertApp-FileBadParams-000"<<num_tests; 
       
   477 		BadFileCaCertTests(badCaCertsFileName,num_tests);
       
   478 		}
       
   479 	
       
   480 	//create config files with invalid values swi certstore 
       
   481 	for(num_tests = 0; num_tests<KSwiBadcertIndex; num_tests++)
       
   482 		{
       
   483 		stringstream badSwiCertsFileName;
       
   484 		badSwiCertsFileName << "SDP-Security_Tools-CertApp-SwiBadParams-000"<<num_tests;
       
   485 		BadSwiCertTests(badSwiCertsFileName,num_tests);
       
   486 		}
       
   487 
       
   488 	//Code to create Script files for the file/sw/certclients to run validation tests on emulator
       
   489 	//create script file for the symbian test harness-  for cacerts.dat
       
   490 	for(num_tests = 0; num_tests<1; num_tests++)
       
   491 		{
       
   492 		stringstream emu_CacertsFileName;
       
   493 		emu_CacertsFileName << "SDP-Security_Tools-CertApp-FILEDAT-EMU0"<<num_tests<<".txt";
       
   494 		GenerateGoodCaCertsTestScripts(emu_CacertsFileName);
       
   495 		}
       
   496 
       
   497 	//create script file for certclients.dat
       
   498 	for(num_tests = 0; num_tests<1; num_tests++)
       
   499 		{
       
   500 		stringstream emu_CertClientsFileName;
       
   501 		emu_CertClientsFileName << "SDP-Security_Tools-CertApp-CCDAT-EMU0"<<num_tests<<".txt";
       
   502 		GenerateGoodCertClientTestScripts(emu_CertClientsFileName);
       
   503 		}
       
   504 
       
   505 	//create script file for the symbian test harness-  for swicerts.dat
       
   506 	for(num_tests = 0; num_tests<1; num_tests++)
       
   507 		{
       
   508 		stringstream emu_SwiCertsFileName;
       
   509 		emu_SwiCertsFileName << "SDP-Security_Tools-CertApp-SWIDAT-EMU0"<<num_tests<<".txt";
       
   510 		GenerateGoodSwiCertTestScripts(emu_SwiCertsFileName);
       
   511 		}
       
   512 
       
   513 	int testCaseCount = failCount+passCount;
       
   514 	cout  << "\nTestrun result is :: " << failCount <<" tests failed out of " << testCaseCount <<endl;
       
   515 	file << "\n\nTotal number of test cases run is -> " << testCaseCount << endl;
       
   516 	file << failCount << " tests failed out of " << testCaseCount <<endl;
       
   517 	file.close();
       
   518 	return 0;
       
   519 }
       
   520 
       
   521 
       
   522 
       
   523 /**
       
   524 Function to create input file for augmenting the existing store
       
   525 */
       
   526 void CreateFileToAugmentStore()
       
   527 {
       
   528 	stringstream swifilename, cacertsfilename, certclientName;
       
   529 	swifilename <<"tswi_Augment.txt";
       
   530 	cacertsfilename<< "tfile_Augment.txt";
       
   531 	certclientName << "tCertClient_Augment.txt";
       
   532 
       
   533 	SwiCertStoreConfigWriter swiwriter(swifilename);
       
   534 	swiwriter.WriteExtraSwiEntry();
       
   535 	
       
   536 	FileCertStoreConfigWriter filewriter(cacertsfilename);
       
   537 	filewriter.WriteExtraFileEntry();
       
   538 
       
   539 	FileCertClientConfigWriter certclientwriter(certclientName);
       
   540 	certclientwriter.WriteExtraCertClientEntry();
       
   541 }
       
   542 
       
   543 
       
   544 /**
       
   545 Test case to check the certapp tool for unicode named config file
       
   546 Testing with only one unicode named config file for now
       
   547 */
       
   548 void TestWithUnicodFileName()
       
   549 {
       
   550 	//unicode file name in utf8 format
       
   551 	const char *filename= "\xe4\xb8\x95\xe4\xb8\x8d\xe4\xb8\x8e\xe4\xb8\x90\xe4\xb8\x91\xe4\xb8\x96\xe4\xb8\x99\x2e\x74\x78\x74";
       
   552 	fstream fileHandle;
       
   553 
       
   554 	OpenUtf8FStreamForWrite(fileHandle,filename);
       
   555 
       
   556 	char * buffer;
       
   557 	long size;
       
   558 
       
   559 	ifstream infile ("SDP-Security_Tools-CertApp-CCDAT_0000.txt",ifstream::binary);
       
   560 	// get size of file
       
   561 	infile.seekg(0,ifstream::end);
       
   562 	size=infile.tellg();
       
   563 	infile.seekg(0);
       
   564 	// allocate memory for file content
       
   565 	buffer = new char [size];
       
   566 	// read content of infile
       
   567 	infile.read (buffer,size);
       
   568 	// write to outfile
       
   569 	fileHandle.write (buffer,size);
       
   570   
       
   571 	// release dynamically-allocated memory
       
   572 	delete[] buffer;
       
   573 	fileHandle.close();
       
   574 	infile.close();
       
   575 
       
   576 	//create argument list for certapp
       
   577 	const char *argv_certclient[3];
       
   578 	stringstream str1;
       
   579 	str1 <<"--hcertclients=" << filename;
       
   580 	string string1;
       
   581 	string1 = str1.str();
       
   582 
       
   583 	argv_certclient[0] =  string1.c_str();
       
   584 	argv_certclient[1] = "--out";
       
   585 	argv_certclient[2] = "--bcertclients=SDP-Security_Tools-CertApp-UNI00.dat";
       
   586 	
       
   587 	char **argv;
       
   588 	char *argument_ptr[3];
       
   589 	int argCount=3;
       
   590 	for(int n = 0; n<argCount; n++)
       
   591 		{
       
   592 		argument_ptr[n] = const_cast<char*>(argv_certclient[n]);
       
   593 		argv = argument_ptr;
       
   594 		}
       
   595 
       
   596 	for(int i =0; i<argCount; i++)
       
   597 		{
       
   598 		cout << "Arguments Being passed to the RunCertApp tool is " << argv[i] << endl;
       
   599 		}
       
   600 
       
   601 	int ret = RunCertApp(progress, errors, argCount, argv); 
       
   602 	cout << "Return value from certapp is " << ret <<endl;
       
   603 	if(ret!= 0)
       
   604 		{
       
   605 		failCount++;
       
   606 		file<< "Error in creating store using the unicode file name config file " << filename << " and result is " << ret << " Fail" << endl ;
       
   607 		}
       
   608 	else
       
   609 		{
       
   610 		passCount++;
       
   611 		file << "No Error in creating store using the unicode file named config file " << filename << " and result is " << ret << " Pass" <<endl ;
       
   612 		}
       
   613 }
       
   614 
       
   615 /**
       
   616 Generate Certclient config files
       
   617 */
       
   618 void GoodFileCertClientsTests(const stringstream &aFilename)
       
   619 {
       
   620 	FileCertClientConfigWriter filewriter(aFilename);
       
   621 	const char *certclientPtr1; 
       
   622 	const char *certclientPtr2;
       
   623 	for(int i = 0; i<KAppUidIndex ; i++)
       
   624 		{
       
   625 		certclientPtr1 = goodAppNames[i];
       
   626 		certclientPtr2 = gooduid_array[i];
       
   627 		filewriter.WriteCertClientUid(certclientPtr2);
       
   628 		filewriter.WriteCertClientName(certclientPtr1);
       
   629 		}
       
   630 }
       
   631 
       
   632 
       
   633 /**
       
   634 Generate good config files for cacerts
       
   635 */
       
   636 void GoodFileCaCertTests(const stringstream &aFilename ,int aValue)
       
   637 {
       
   638 	FileCertStoreConfigWriter fileCertWriter(aFilename);
       
   639 	const char **cacertPtr; 
       
   640 	const char **label = filecert_array[0];
       
   641 	switch(aValue)
       
   642 	{
       
   643 	case 0:
       
   644 		{
       
   645 		// Tests for GoodLabels
       
   646 		for(label = filecert_array[aValue]; *label; ++label)
       
   647 			{
       
   648 		
       
   649 			fileCertWriter.WriteFileEntry(*label);
       
   650 			}
       
   651 		break;
       
   652 		}
       
   653 	case 1:
       
   654 		{
       
   655 		// Tests for GoodDeletables
       
   656 		for(cacertPtr = filecert_array[aValue]; *cacertPtr; ++cacertPtr)
       
   657 			{
       
   658 			fileCertWriter.WriteFileEntry(*label,*cacertPtr);
       
   659 			label++;
       
   660 			}
       
   661 		break;
       
   662 		}
       
   663 	case 2:
       
   664 		{
       
   665 		//Tests for GoodFormats
       
   666 		for(cacertPtr = filecert_array[aValue]; *cacertPtr; ++cacertPtr)
       
   667 			{
       
   668 			fileCertWriter.WriteFileEntry(*label,0,*cacertPtr);
       
   669 			label++;
       
   670 			}
       
   671 		break;
       
   672 		}
       
   673 	case 3:
       
   674 		{
       
   675 		//Tests for GoodCertOwnerTypes
       
   676 		for(cacertPtr = filecert_array[aValue]; *cacertPtr; ++cacertPtr)
       
   677 			{
       
   678 			fileCertWriter.WriteFileEntry(*label,0,0,*cacertPtr);
       
   679 			label++;
       
   680 			}
       
   681 		break;
       
   682 		}
       
   683 	case 4:
       
   684 		{
       
   685 		//Tests for GoodSubjectKeyIds
       
   686 		for(cacertPtr = filecert_array[aValue]; *cacertPtr; ++cacertPtr)
       
   687 			{
       
   688 			fileCertWriter.WriteFileEntry(*label,0,0,0,*cacertPtr);
       
   689 			label++;
       
   690 			}
       
   691 		break;
       
   692 		}
       
   693 	case 5:
       
   694 		{
       
   695 		//Tests for GoodIssuerKeyIds
       
   696 		for(cacertPtr = filecert_array[aValue]; *cacertPtr; ++cacertPtr)
       
   697 			{
       
   698 			fileCertWriter.WriteFileEntry(*label,0,0,0,0,*cacertPtr);
       
   699 			label++;
       
   700 			}
       
   701 		break;
       
   702 		}
       
   703 	case 6:
       
   704 		{
       
   705 		//Tests for GoodApplications
       
   706 		for(cacertPtr = filecert_array[aValue]; *cacertPtr; ++cacertPtr)
       
   707 			{
       
   708 			fileCertWriter.WriteFileEntry(*label,0,0,0,0,0,*cacertPtr);
       
   709 			label++;
       
   710 			}
       
   711 		break;
       
   712 		}
       
   713 	case 7:
       
   714 		{
       
   715 		//Tests for GoodTrusteds
       
   716 		for(cacertPtr = filecert_array[aValue]; *cacertPtr; ++cacertPtr)
       
   717 			{
       
   718 			fileCertWriter.WriteFileEntry(*label,0,0,0,0,0,0,*cacertPtr);
       
   719 			label++;
       
   720 			}
       
   721 		break;
       
   722 		}
       
   723 	
       
   724 	case 8:
       
   725 		{	
       
   726 		//Test for PEM support
       
   727 		const char* datafilename = "\"root5ca.pem\"";
       
   728 		fileCertWriter.WriteFileEntry(*label,0,0,0,0,0,0,0,datafilename);
       
   729 		}
       
   730 		break;
       
   731 	
       
   732 	default:
       
   733 		break;
       
   734 	}
       
   735 }
       
   736 
       
   737 /**
       
   738 Generate  config file for swicert
       
   739 */
       
   740 void GoodSwiCertTests(const stringstream &aFilename, int aIndex)
       
   741 {
       
   742 	SwiCertStoreConfigWriter swiWriter(aFilename);
       
   743 	const char **swiPtr1, **swiPtr2; 
       
   744 	swiPtr2 = swicert_array[0]; // labels for all scripts
       
   745 	switch(aIndex)
       
   746 	{
       
   747 	case 0:
       
   748 		{
       
   749 		// Tests for GoodLabels
       
   750 		for(swiPtr2=swicert_array[aIndex] ; *swiPtr2; ++swiPtr2)
       
   751 			{
       
   752 			swiWriter.WriteSwiEntry(*swiPtr2);
       
   753 			}
       
   754 		break;
       
   755 		}
       
   756 	case 1:
       
   757 		{
       
   758 		//Tests for GoodFormats
       
   759 		for(swiPtr1 = swicert_array[aIndex]; *swiPtr1; ++swiPtr1)
       
   760 			{
       
   761 			swiWriter.WriteSwiEntry(*swiPtr2,*swiPtr1);
       
   762 			++swiPtr2;
       
   763 			}
       
   764 		break;
       
   765 		}
       
   766 	case 2:
       
   767 		{
       
   768 		//Tests for GoodCertOwnerTypes
       
   769 		for(swiPtr1 = swicert_array[aIndex]; *swiPtr1; ++swiPtr1)
       
   770 			{
       
   771 			swiWriter.WriteSwiEntry(*swiPtr2,0,*swiPtr1);
       
   772 			++swiPtr2;
       
   773 			}
       
   774 		break;
       
   775 		}
       
   776 	case 3:
       
   777 		{
       
   778 		//Tests for GoodSubjectKeyIds
       
   779 		for(swiPtr1 = swicert_array[aIndex]; *swiPtr1; ++swiPtr1)
       
   780 			{
       
   781 			swiWriter.WriteSwiEntry(*swiPtr2,0,0,*swiPtr1);
       
   782 			++swiPtr2;
       
   783 			}
       
   784 		break;
       
   785 		}
       
   786 	case 4:
       
   787 		{
       
   788 		//Tests for GoodIssuerKeyIds
       
   789 		for(swiPtr1 = swicert_array[aIndex]; *swiPtr1; ++swiPtr1)
       
   790 			{
       
   791 			swiWriter.WriteSwiEntry(*swiPtr2,0,0,0,*swiPtr1);
       
   792 			++swiPtr2;
       
   793 			}
       
   794 		break;
       
   795 		}
       
   796 	case 5:
       
   797 		{
       
   798 		//Tests for GoodAswiPtr1lications
       
   799 		for(swiPtr1 = swicert_array[aIndex]; *swiPtr1; ++swiPtr1)
       
   800 			{
       
   801 			swiWriter.WriteSwiEntry(*swiPtr2,0,0,0,0,*swiPtr1);
       
   802 			++swiPtr2;
       
   803 			}
       
   804 		break;
       
   805 		}
       
   806 	case 6:
       
   807 		{
       
   808 		//Tests for GoodTrusteds
       
   809 		for(swiPtr1 = swicert_array[aIndex]; *swiPtr1; ++swiPtr1)
       
   810 			{
       
   811 			swiWriter.WriteSwiEntry(*swiPtr2,0,0,0,0,0,*swiPtr1);
       
   812 			++swiPtr2;
       
   813 			}
       
   814 		break;
       
   815 		}
       
   816 	case 7:
       
   817 		{
       
   818 		//Tests for GoodCapabilities
       
   819 		swiPtr1 = swicert_array[aIndex]; 
       
   820 		swiWriter.WriteSwiEntry(*swiPtr2,0,0,0,0,0,0,*swiPtr1);
       
   821 		break;
       
   822 		}
       
   823 	case 8:
       
   824 		{
       
   825 		//Tests for sGoodMandatory
       
   826 		for(swiPtr1 = swicert_array[aIndex]; *swiPtr1; ++swiPtr1)
       
   827 			{
       
   828 			swiWriter.WriteSwiEntry(*swiPtr2,0,0,0,0,0,0,0,*swiPtr1);
       
   829 			++swiPtr2;
       
   830 			}
       
   831 		break;
       
   832 		}
       
   833 	case 9:
       
   834 		{
       
   835 		//Tests for sGoodSystemUpgrade
       
   836 		for(swiPtr1 = swicert_array[aIndex]; *swiPtr1; ++swiPtr1)
       
   837 			{
       
   838 			swiWriter.WriteSwiEntry(*swiPtr2,0,0,0,0,0,0,0,0,*swiPtr1);
       
   839 			++swiPtr2;
       
   840 			}
       
   841 		break;
       
   842 		}
       
   843 	default:
       
   844 		break;
       
   845 	}
       
   846 }
       
   847 
       
   848 /**
       
   849 Generate config  files with invalid values for the store
       
   850 */
       
   851 void TestBadConfigFiles(const stringstream &aFilename, bool aBool)
       
   852 {
       
   853 	// create command line input for cacerts
       
   854 	//Ex:certapp --hcertclients=t_certclients_0.txt --hfilecertstore=t_cacerts_0.txt --out --bfilecertstore=cacerts_x.dat
       
   855 	stringstream strArg1, strArg2, strArg3;
       
   856 	stringstream configFileName;
       
   857 	configFileName <<aFilename.str() << ".txt";
       
   858 	cout << aFilename.str() <<endl;
       
   859 	if(aBool == 0) // file store
       
   860 		{
       
   861 		strArg1 <<"--hfilecertstore="<<aFilename.str() <<".txt";;//--hfilecertstore=t_cacerts_x.txt
       
   862 		
       
   863 		strArg2<< "--bfilecertstore=" << aFilename.str() <<".dat"; //--bfilecertstore=cacerts_x.dat
       
   864 		cout <<"string value is " << strArg2.str().c_str() << endl;	
       
   865 		}
       
   866 	else  //swi store
       
   867 		{
       
   868 		strArg1 <<"--hswicertstore="<<aFilename.str() <<".txt";;//--hswicertstore=t_cacerts_x.txt
       
   869 		
       
   870 		strArg2<< "--bswicertstore=" << aFilename.str() <<".dat"; //--bswicertstore=cacerts_x.dat
       
   871 		cout <<"string value is " << strArg2.str().c_str() << endl;	
       
   872 		}
       
   873 
       
   874 	strArg3<< "--hcertclients=SDP-Security_Tools-CertApp-CCDAT_0000.txt";
       
   875 	cout <<"string value is " << strArg3.str().c_str() << endl;
       
   876 
       
   877 	string argument1, argument2, argument3;
       
   878 	const char *argv_certclient[4];
       
   879 	
       
   880 	argument1 = strArg1.str().c_str();
       
   881 	argument3 = strArg3.str().c_str();
       
   882 
       
   883 	argv_certclient[0] = argument3.c_str(); // --hcertclients=t_certclients_0.txt
       
   884 	argv_certclient[1] = argument1.c_str(); // --hfilecertstore=t_cacerts_x.txt
       
   885 	argv_certclient[2] = "--out";			//--out
       
   886 	argument2 = strArg2.str().c_str();
       
   887 	argv_certclient[3] = argument2.c_str(); //--bfilecertstore=cacerts_x.dat
       
   888 
       
   889 	char *argument_ptr[4]; 
       
   890 	int argCount4 = 4;
       
   891 	char **argv;
       
   892 	for(int n = 0; n<argCount4; n++)
       
   893 		{
       
   894 		argument_ptr[n] = const_cast<char*>(argv_certclient[n]);
       
   895 		argv = argument_ptr;   
       
   896 		}
       
   897 	RunCertAppToolForBadParams(argCount4, argv, configFileName); 
       
   898 }
       
   899 
       
   900 /**
       
   901 Generate bad config files for cacerts
       
   902 */
       
   903 void BadFileCaCertTests(const stringstream &aFilename ,int aValue)
       
   904 {
       
   905 	const char **caCertPtr; 
       
   906 	int count = 0;
       
   907 	switch(aValue)
       
   908 	{
       
   909 	case 0:
       
   910 		{
       
   911 		// Tests for BadLabels
       
   912 		for(caCertPtr = badfilecert_array[aValue]; *caCertPtr ; ++caCertPtr )
       
   913 			{
       
   914 			stringstream file1, file2;
       
   915 			file1 << aFilename.str() <<"_"<<count;
       
   916 			file2 << aFilename.str() <<"_"<<count <<".txt";
       
   917 			FileBadCertStoreConfigWriter badcertfileWriter(file2);
       
   918 			badcertfileWriter.WriteFileEntry(*caCertPtr);
       
   919 			TestBadConfigFiles(file1, 0);
       
   920 			count++;
       
   921 			}
       
   922 		break;
       
   923 		}
       
   924 	case 1:
       
   925 		{
       
   926 		// Tests for BadDeletables
       
   927 		for(caCertPtr = badfilecert_array[aValue]; *caCertPtr; ++caCertPtr)
       
   928 			{
       
   929 			stringstream file1, file2;
       
   930 			file1 << aFilename.str() <<"_"<<count;
       
   931 			file2 << aFilename.str() <<"_"<<count <<".txt";
       
   932 			FileBadCertStoreConfigWriter badcertfileWriter(file2);
       
   933 			badcertfileWriter.WriteFileEntry(0,*caCertPtr);
       
   934 			TestBadConfigFiles(file1,0);
       
   935 			count++;
       
   936 			}
       
   937 		break;
       
   938 		}
       
   939 	case 2:
       
   940 		{
       
   941 		//Tests for BadFormats
       
   942 		for(caCertPtr = badfilecert_array[aValue]; *caCertPtr; ++caCertPtr)
       
   943 			{
       
   944 			stringstream file1, file2;
       
   945 			file1 << aFilename.str() <<"_"<<count;
       
   946 			file2 << aFilename.str() <<"_"<<count <<".txt";
       
   947 			FileBadCertStoreConfigWriter badcertfileWriter(file2);
       
   948 			badcertfileWriter.WriteFileEntry(0,0,*caCertPtr);
       
   949 			TestBadConfigFiles(file1,0);
       
   950 			count++;
       
   951 			}
       
   952 		break;
       
   953 		}
       
   954 	case 3:
       
   955 		{
       
   956 		//Tests for BadCertOwnerTypes
       
   957 		for(caCertPtr = badfilecert_array[aValue]; *caCertPtr; ++caCertPtr)
       
   958 			{
       
   959 			stringstream file1, file2;
       
   960 			file1 << aFilename.str() <<"_"<<count;
       
   961 			file2 << aFilename.str() <<"_"<<count <<".txt";
       
   962 			FileBadCertStoreConfigWriter badcertfileWriter(file2);
       
   963 			badcertfileWriter.WriteFileEntry(0,0,0,*caCertPtr);
       
   964 			TestBadConfigFiles(file1,0);
       
   965 			count++;
       
   966 			}
       
   967 		break;
       
   968 		}
       
   969 	case 4:
       
   970 		{
       
   971 		//Tests for BadSubjectKeyIds
       
   972 		for(caCertPtr = badfilecert_array[aValue]; *caCertPtr; ++caCertPtr)
       
   973 			{
       
   974 			stringstream file1, file2;
       
   975 			file1 << aFilename.str() <<"_"<<count;
       
   976 			file2 << aFilename.str() <<"_"<<count <<".txt";
       
   977 			FileBadCertStoreConfigWriter badcertfileWriter(file2);
       
   978 			badcertfileWriter.WriteFileEntry(0,0,0,0,*caCertPtr);
       
   979 			TestBadConfigFiles(file1,0);
       
   980 			count++;
       
   981 			}
       
   982 		break;
       
   983 		}
       
   984 	case 5:
       
   985 		{
       
   986 		//Tests for BadIssuerKeyIds
       
   987 		for(caCertPtr = badfilecert_array[aValue]; *caCertPtr; ++caCertPtr)
       
   988 			{
       
   989 			stringstream file1, file2;
       
   990 			file1 << aFilename.str() <<"_"<<count;
       
   991 			file2 << aFilename.str() <<"_"<<count <<".txt";
       
   992 			FileBadCertStoreConfigWriter badcertfileWriter(file2);
       
   993 			badcertfileWriter.WriteFileEntry(0,0,0,0,0,*caCertPtr);
       
   994 			TestBadConfigFiles(file1,0);
       
   995 			count++;
       
   996 			}
       
   997 		break;
       
   998 		}
       
   999 	case 6:
       
  1000 		{
       
  1001 		//Tests for BadApplications
       
  1002 		caCertPtr = badfilecert_array[aValue];
       
  1003 		stringstream file1, file2;
       
  1004 		file1 << aFilename.str() <<"_"<<count;
       
  1005 		file2 << aFilename.str() <<"_"<<count <<".txt";
       
  1006 		FileBadCertStoreConfigWriter badcertfileWriter(file2);
       
  1007 		badcertfileWriter.WriteFileEntry(0,0,0,0,0,0,*caCertPtr);
       
  1008 		TestBadConfigFiles(file1,0);
       
  1009 		break;
       
  1010 		}
       
  1011 	case 7:
       
  1012 		{
       
  1013 		//Tests for BadTrusteds
       
  1014 		for(caCertPtr = badfilecert_array[aValue]; *caCertPtr; ++caCertPtr)
       
  1015 			{
       
  1016 			stringstream file1, file2;
       
  1017 			file1 << aFilename.str() <<"_"<<count;
       
  1018 			file2 << aFilename.str() <<"_"<<count <<".txt";
       
  1019 			FileBadCertStoreConfigWriter badcertfileWriter(file2);
       
  1020 			badcertfileWriter.WriteFileEntry(0,0,0,0,0,0,0,*caCertPtr);
       
  1021 			TestBadConfigFiles(file1,0);
       
  1022 			count++;
       
  1023 			}
       
  1024 		break;
       
  1025 		}
       
  1026 	case 8:
       
  1027 		{
       
  1028 		//Tests for BadDataFileName
       
  1029 		for(caCertPtr = badfilecert_array[aValue]; *caCertPtr; ++caCertPtr)
       
  1030 			{
       
  1031 			stringstream file1, file2;
       
  1032 			file1 << aFilename.str() <<"_"<<count;
       
  1033 			file2 << aFilename.str() <<"_"<<count <<".txt";
       
  1034 			FileBadCertStoreConfigWriter badcertfileWriter(file2);
       
  1035 			badcertfileWriter.WriteFileEntry(0,0,0,0,0,0,0,0,*caCertPtr);
       
  1036 			TestBadConfigFiles(file1,0);
       
  1037 			count++;
       
  1038 			}
       
  1039 		break;
       
  1040 		}
       
  1041 	default:
       
  1042 		break;
       
  1043 	}
       
  1044 }
       
  1045 
       
  1046 
       
  1047 /**
       
  1048 Generate bad Certclient config files
       
  1049 */
       
  1050 void BadFileCertClientsTests(const stringstream &aFilename, int aIndex)
       
  1051 {
       
  1052 	FileBadCertClientConfigWriter certfileWriter(aFilename);
       
  1053 	const char *certfilePtr1, *certfilePtr2; 
       
  1054 	
       
  1055 	switch(aIndex)
       
  1056 	{
       
  1057 	case 0:
       
  1058 		{
       
  1059 		for(int i=0; i<KAppUidIndex; i++) // 4 badUids[] length
       
  1060 			{
       
  1061 			stringstream file1, file2;
       
  1062 			file2 << aFilename.str() << "_" << i ;
       
  1063 			file1 << aFilename.str() <<"_"<<i <<".txt";
       
  1064 			FileBadCertClientConfigWriter certfileWriter(file1);
       
  1065 			certfilePtr1 = goodcertclient_array[0]; // good app name and 
       
  1066 			certfilePtr2 = badUids[i];
       
  1067 			certfileWriter.WriteCertClientUid(certfilePtr2); // bad uid entry
       
  1068 			certfileWriter.WriteCertClientName(certfilePtr1);
       
  1069 			CertClientBadParamsFuncCall(file2);
       
  1070 			}
       
  1071 		break;
       
  1072 		}
       
  1073 
       
  1074 	case 1:
       
  1075 		{
       
  1076 		for(int i = 0; i<4 ; i++) // length of badcertclient_array
       
  1077 			{
       
  1078 			stringstream file1, file2;
       
  1079 			file2 << aFilename.str() << "_" << i ;
       
  1080 			file1 << aFilename.str() <<"_"<<i <<".txt";
       
  1081 			FileBadCertClientConfigWriter certfileWriter(file1);
       
  1082 			certfilePtr1 = badcertclient_array[i];
       
  1083 			certfilePtr2 = goodUids[0];
       
  1084 			certfileWriter.WriteCertClientUid(certfilePtr2);
       
  1085 			certfileWriter.WriteCertClientName(certfilePtr1);
       
  1086 			CertClientBadParamsFuncCall(file2);
       
  1087 			}
       
  1088 		break;
       
  1089 		}
       
  1090 	
       
  1091 	// multiple names mapping to single uid
       
  1092 	case 2:
       
  1093 		{
       
  1094 		stringstream file1;
       
  1095 		file1 << aFilename.str() <<".txt";
       
  1096 		FileBadCertClientConfigWriter certfileWriter(file1);
       
  1097 		for(int i= 0; i<KAppUidIndex; i++)
       
  1098 			{
       
  1099 			certfilePtr1 = goodAppNames[i]; //app names - SW Install,SW install Ocsp Signing etc.
       
  1100 			certfilePtr2 = goodUids[0];
       
  1101 			certfileWriter.WriteCertClientName(certfilePtr1);
       
  1102 			certfileWriter.WriteCertClientUid(certfilePtr2);
       
  1103 			}
       
  1104 		CertClientBadParamsFuncCall(file1);
       
  1105 		break;
       
  1106 		}
       
  1107 	
       
  1108 	default:
       
  1109 		break;
       
  1110 	}
       
  1111 }
       
  1112 
       
  1113 
       
  1114 void CertClientBadParamsFuncCall(stringstream &aFileName)
       
  1115 {
       
  1116 	//Ex:certapp --hcertclients=t_certclients_0.txt --out --bcertclients=t_certclients_0.dat 
       
  1117 	stringstream strArg1, strArg2, strArg3;
       
  1118 	strArg1 <<"--hcertclients=" << aFileName.str() << ".txt";   
       
  1119 	
       
  1120 	strArg2<< "--bcertclients=" << aFileName.str() << ".dat"; 
       
  1121 	cout <<"string value is " << strArg2.str().c_str() << endl;	
       
  1122 	
       
  1123 	string argument1, argument2;
       
  1124 	const char *argv_certclient[3];
       
  1125 	
       
  1126 	argument1= strArg1.str().c_str();
       
  1127 	argument2= strArg2.str().c_str();
       
  1128 
       
  1129 	argv_certclient[0] = argument1.c_str(); // --hcertclients=tbad_certclients_x.txt
       
  1130 	argv_certclient[1] = "--out";			//--out
       
  1131 	argv_certclient[2] = argument2.c_str(); //--bcertclients=t_certclients_x.dat
       
  1132 
       
  1133 	char *argument_ptr[3]; 
       
  1134 	int argCount3 = 3;
       
  1135 	char **argv;
       
  1136 	for(int n = 0; n<argCount3; n++)
       
  1137 		{
       
  1138 		argument_ptr[n] = const_cast<char*>(argv_certclient[n]);
       
  1139 		argv = argument_ptr;   
       
  1140 		}
       
  1141 	RunCertAppToolForBadParams(argCount3, argv, aFileName); 
       
  1142 }
       
  1143 
       
  1144 
       
  1145 /**
       
  1146 Generate  config file for swicert
       
  1147 */
       
  1148 void BadSwiCertTests(const stringstream &aFileName, int aIndex)
       
  1149 {
       
  1150 	const char **swicertPtr1; 
       
  1151 	int count = 0 ;
       
  1152 	switch(aIndex)
       
  1153 	{
       
  1154 	case 0:
       
  1155 		{
       
  1156 		// Tests for BadLabels
       
  1157 		for(swicertPtr1= badswicert_array[aIndex]; *swicertPtr1; ++swicertPtr1)
       
  1158 			{
       
  1159 			stringstream file1, file2;
       
  1160 			file1 << aFileName.str() <<"_"<<count;
       
  1161 			file2 << aFileName.str() <<"_"<<count <<".txt";
       
  1162 			SwiBadCertStoreConfigWriter badswiWriter(file2);
       
  1163 			badswiWriter.WriteSwiEntry(*swicertPtr1);
       
  1164 			TestBadConfigFiles(file1,1);
       
  1165 			count++;
       
  1166 			}
       
  1167 		break;
       
  1168 		}
       
  1169 
       
  1170 	case 1:
       
  1171 		{
       
  1172 		//Tests for BadFormats
       
  1173 		for(swicertPtr1 = badswicert_array[aIndex]; *swicertPtr1; ++swicertPtr1)
       
  1174 			{
       
  1175 			stringstream file1, file2;
       
  1176 			file1 << aFileName.str() <<"_"<<count;
       
  1177 			file2 << aFileName.str() <<"_"<<count <<".txt";
       
  1178 			SwiBadCertStoreConfigWriter badswiWriter(file2);
       
  1179 			badswiWriter.WriteSwiEntry(0,*swicertPtr1);
       
  1180 			TestBadConfigFiles(file1,1);
       
  1181 			count++;
       
  1182 			}
       
  1183 		break;
       
  1184 		}
       
  1185 	case 2:
       
  1186 		{
       
  1187 		//Tests for BadCertOwnerTypes
       
  1188 		for(swicertPtr1 = badswicert_array[aIndex]; *swicertPtr1; ++swicertPtr1)
       
  1189 			{
       
  1190 			stringstream file1, file2;
       
  1191 			file1 << aFileName.str() <<"_"<<count;
       
  1192 			file2 << aFileName.str() <<"_"<<count <<".txt";
       
  1193 			SwiBadCertStoreConfigWriter badswiWriter(file2);
       
  1194 			badswiWriter.WriteSwiEntry(0,0,*swicertPtr1);
       
  1195 			TestBadConfigFiles(file1,1);
       
  1196 			count++;
       
  1197 			}
       
  1198 		break;
       
  1199 		}
       
  1200 	case 3:
       
  1201 		{
       
  1202 		//Tests for BadSubjectKeyIds
       
  1203 		for(swicertPtr1 = badswicert_array[aIndex]; *swicertPtr1; ++swicertPtr1)
       
  1204 			{
       
  1205 			stringstream file1, file2;
       
  1206 			file1 << aFileName.str() <<"_"<<count;
       
  1207 			file2 << aFileName.str() <<"_"<<count <<".txt";
       
  1208 			SwiBadCertStoreConfigWriter badswiWriter(file2);
       
  1209 			badswiWriter.WriteSwiEntry(0,0,0,*swicertPtr1);
       
  1210 			TestBadConfigFiles(file1,1);
       
  1211 			count++;	
       
  1212 			}
       
  1213 		break;
       
  1214 		}
       
  1215 	case 4:
       
  1216 		{
       
  1217 		//Tests for BadIssuerKeyIds
       
  1218 		for(swicertPtr1 = badswicert_array[aIndex]; *swicertPtr1; ++swicertPtr1)
       
  1219 			{
       
  1220 			stringstream file1, file2;
       
  1221 			file1 << aFileName.str() <<"_"<<count;
       
  1222 			file2 << aFileName.str() <<"_"<<count <<".txt";
       
  1223 			SwiBadCertStoreConfigWriter badswiWriter(file2);
       
  1224 			badswiWriter.WriteSwiEntry(0,0,0,0,*swicertPtr1);
       
  1225 			TestBadConfigFiles(file1,1);
       
  1226 			count++;
       
  1227 			}
       
  1228 		break;
       
  1229 		}
       
  1230 	case 5:
       
  1231 		{
       
  1232 		//Tests for BadApplications
       
  1233 		swicertPtr1 = badswicert_array[aIndex];
       
  1234 			{
       
  1235 			stringstream file1, file2;
       
  1236 			file1 << aFileName.str() <<"_"<<count;
       
  1237 			file2 << aFileName.str() <<"_"<<count <<".txt";
       
  1238 			SwiBadCertStoreConfigWriter badswiWriter(file2);
       
  1239 			badswiWriter.WriteSwiEntry(0,0,0,0,0,*swicertPtr1);
       
  1240 			TestBadConfigFiles(file1,1);
       
  1241 			count++;
       
  1242 			}
       
  1243 		break;
       
  1244 		}
       
  1245 	case 6:
       
  1246 		{
       
  1247 		//Tests for BadTrusteds
       
  1248 		for(swicertPtr1 = badswicert_array[aIndex]; *swicertPtr1; ++swicertPtr1)
       
  1249 			{
       
  1250 			stringstream file1, file2;
       
  1251 			file1 << aFileName.str() <<"_"<<count;
       
  1252 			file2 << aFileName.str() <<"_"<<count <<".txt";
       
  1253 			SwiBadCertStoreConfigWriter badswiWriter(file2);
       
  1254 			badswiWriter.WriteSwiEntry(0,0,0,0,0,0,*swicertPtr1);
       
  1255 			TestBadConfigFiles(file1,1);
       
  1256 			count++;
       
  1257 			}
       
  1258 		break;
       
  1259 		}
       
  1260 	case 7:
       
  1261 		{
       
  1262 		//Tests for BadDataFileName
       
  1263 		for(swicertPtr1 = badswicert_array[aIndex]; *swicertPtr1; ++swicertPtr1)
       
  1264 			{
       
  1265 			stringstream file1, file2;
       
  1266 			file1 << aFileName.str() <<"_"<<count;
       
  1267 			file2 << aFileName.str() <<"_"<<count <<".txt";
       
  1268 			SwiBadCertStoreConfigWriter badswiWriter(file2);
       
  1269 			badswiWriter.WriteSwiEntry(0,0,0,0,0,0,0,*swicertPtr1);
       
  1270 			TestBadConfigFiles(file1,1);
       
  1271 			count++;
       
  1272 			}
       
  1273 		break;
       
  1274 		}
       
  1275 	case 8:
       
  1276 		{
       
  1277 		//Tests for BadCapabilities
       
  1278 		swicertPtr1 = badswicert_array[aIndex];
       
  1279 			{
       
  1280 			stringstream file1, file2;
       
  1281 			file1 << aFileName.str() <<"_"<<count;
       
  1282 			file2 << aFileName.str() <<"_"<<count <<".txt";
       
  1283 			SwiBadCertStoreConfigWriter badswiWriter(file2);
       
  1284 			badswiWriter.WriteSwiEntry(0,0,0,0,0,0,0,0,*swicertPtr1);
       
  1285 			TestBadConfigFiles(file1,1);
       
  1286 			count++;
       
  1287 			}
       
  1288 		break;
       
  1289 		}
       
  1290 	case 9:
       
  1291 		{
       
  1292 		//Tests for BadMandatory
       
  1293 		for(swicertPtr1 = badswicert_array[aIndex]; *swicertPtr1; ++swicertPtr1)
       
  1294 			{
       
  1295 			stringstream file1, file2;
       
  1296 			file1 << aFileName.str() <<"_"<<count;
       
  1297 			file2 << aFileName.str() <<"_"<<count <<".txt";
       
  1298 			SwiBadCertStoreConfigWriter badswiWriter(file2);
       
  1299 			badswiWriter.WriteSwiEntry(0,0,0,0,0,0,0,0,0,*swicertPtr1);
       
  1300 			TestBadConfigFiles(file1,1);
       
  1301 			count++;
       
  1302 			}
       
  1303 		break;
       
  1304 		}
       
  1305 	case 10:
       
  1306 		{
       
  1307 		//Tests for BadSystemUpgrade
       
  1308 		for(swicertPtr1 = badswicert_array[aIndex]; *swicertPtr1; ++swicertPtr1)
       
  1309 			{
       
  1310 			stringstream file1, file2;
       
  1311 			file1 << aFileName.str() <<"_"<<count;
       
  1312 			file2 << aFileName.str() <<"_"<<count <<".txt";
       
  1313 			SwiBadCertStoreConfigWriter badswiWriter(file2);
       
  1314 			badswiWriter.WriteSwiEntry(0,0,0,0,0,0,0,0,0,0,*swicertPtr1);
       
  1315 			TestBadConfigFiles(file1,1);
       
  1316 			count++;
       
  1317 			}
       
  1318 		break;
       
  1319 		}
       
  1320 	default:
       
  1321 		break;
       
  1322 	}
       
  1323 }
       
  1324 
       
  1325 /**
       
  1326 Test cases to test the tool with empty configuration files as input for all the stores
       
  1327 */
       
  1328 void TestsWithEmptyConfigFile()
       
  1329 {
       
  1330 	for(int i = 0 ; i<3 ; i++)
       
  1331 		{
       
  1332 		stringstream emptyConfigFileName, configFileName1, configFileName2;
       
  1333 		emptyConfigFileName<< "SDP-Security_Tools-CertApp-EmptyFile_000"<< i <<".txt";
       
  1334 		switch(i)
       
  1335 			{
       
  1336 			case 0:
       
  1337 				{
       
  1338 				configFileName1 << "--hcertclients=" << emptyConfigFileName.str();
       
  1339 				configFileName2 << "--bcertclients=SDP-Security_Tools-CertApp-EmptyFile_0000"<<".dat";
       
  1340 				FileCertClientConfigWriter certclient(emptyConfigFileName);
       
  1341 				}
       
  1342 			break;
       
  1343 
       
  1344 			case 1:
       
  1345 				{
       
  1346 				configFileName1 << "--hfilecertstore=" << emptyConfigFileName.str();
       
  1347 				configFileName2 << "--bfilecertstore=SDP-Security_Tools-CertApp-EmptyFile_0001"<<".dat";
       
  1348 				FileCertStoreConfigWriter fileWriter(emptyConfigFileName);
       
  1349 				}
       
  1350 			break;
       
  1351 
       
  1352 			case 2:
       
  1353 				{
       
  1354 				configFileName1 << "--hswicertstore=" << emptyConfigFileName.str();
       
  1355 				configFileName2 << "--bswicertstore=SDP-Security_Tools-CertApp-EmptyFile_0002"<<".dat";
       
  1356 				SwiCertStoreConfigWriter swiFileWriter(emptyConfigFileName);
       
  1357 				}
       
  1358 			break;
       
  1359 
       
  1360 			default:
       
  1361 				break;
       
  1362 			}
       
  1363 
       
  1364 		string argument1, argument2;
       
  1365 		argument1  = configFileName1.str().c_str();
       
  1366 		argument2  = configFileName2.str().c_str();
       
  1367 		const char *argv_certclient[4];
       
  1368 		argv_certclient[0] = "--hcertclients=SDP-Security_Tools-CertApp-CCDAT_0000.txt";
       
  1369 		argv_certclient[1] = argument1.c_str();  //"--hfilecertstore=t_emptyConfig.txt";
       
  1370 		argv_certclient[2] = "--out";
       
  1371 		argv_certclient[3] = argument2.c_str();
       
  1372 
       
  1373 		int argcount = 4;
       
  1374 		char *argument_ptr[4]; 
       
  1375 		char **argv;
       
  1376 		for(int n = 0; n<argcount; n++)
       
  1377 			{
       
  1378 			argument_ptr[n] = const_cast<char*>(argv_certclient[n]);
       
  1379 			argv = argument_ptr;
       
  1380 			}
       
  1381 		for(int z=0; z<argcount; z++)
       
  1382 			{
       
  1383 			cout << "Testing with empty configuration file" << argv[z] <<endl;
       
  1384 			}
       
  1385 
       
  1386 		RunCertAppTool(argcount, argv, emptyConfigFileName);
       
  1387 		}
       
  1388 }
       
  1389 
       
  1390 /**
       
  1391 Code to test the certapp tool for different file encode formats
       
  1392 */
       
  1393 void TestsWithEncodedFileFormats()
       
  1394 {
       
  1395 	//Provide files with different encoded formats
       
  1396 	for(int i = 0; i<4; i++)
       
  1397 		{
       
  1398 		stringstream unicodeName, outputFileName, strArg3;
       
  1399 		const char *argv_certclient[KIndex];
       
  1400 		unicodeName<< fileEncodeType[i];
       
  1401 		outputFileName <<"SDP-Security_Tools-CertApp-FileFormats-000" <<i;
       
  1402 		strArg3 << "--bfilecertstore="<< "SDP-Security_Tools-CertApp-FileFormats-000" <<i<<".dat";
       
  1403 		
       
  1404 		string argument;
       
  1405 		argument = strArg3.str().c_str();
       
  1406 		argv_certclient[0] = "--hcertclients=SDP-Security_Tools-CertApp-CCDAT_0000.txt";
       
  1407 		argv_certclient[1] = fileEncodeType[i];   // manually created unicode content files
       
  1408 		argv_certclient[2] = "--out";
       
  1409 		argv_certclient[3] = argument.c_str();
       
  1410 
       
  1411 		for(int m=0; m<KIndex; m++)
       
  1412 			{
       
  1413 			cout << "Value in argv_certclient " << m << "is " <<argv_certclient[m] <<endl;
       
  1414 			}
       
  1415 		 char *argument_ptr[4]; 
       
  1416 		char **argv;
       
  1417 		for(int n = 0; n<KIndex; n++)
       
  1418 			{
       
  1419 			argument_ptr[n] = const_cast<char*>(argv_certclient[n]);
       
  1420 			argv = argument_ptr;
       
  1421 			}
       
  1422 		
       
  1423 		for(int z=0; z<KIndex; z++)
       
  1424 			{
       
  1425 			cout << "Argument array contains : " << argv[z] <<endl;
       
  1426 			}
       
  1427 		
       
  1428 		int ret = RunCertApp(progress, errors, KIndex, argv); 
       
  1429 		cout << "Return value from RunCertApp tool is "  << ret << endl;
       
  1430 		
       
  1431 		if(ret!= 0 && ((strcmp(unicodeName.str().c_str(),"--hfilecertstore=ucs2-bigendian.txt")==0) || (strcmp(unicodeName.str().c_str(),"--hfilecertstore=ucs2-littleendian.txt")==0)))
       
  1432 			{
       
  1433 			passCount++;
       
  1434 			file<< "Tool doesnt support for UCS encoded file-"<< outputFileName.str() <<" so the result is " << ret << " Pass" << endl ;
       
  1435 			}
       
  1436 		else if(ret== 0 && ((strcmp(unicodeName.str().c_str(),"--hfilecertstore=utf8.txt") ==0) || (strcmp(unicodeName.str().c_str(),"--hfilecertstore=utf8_without_bom.txt")==0)))
       
  1437 			{
       
  1438 			passCount++;
       
  1439 			file << "No Error in creating store for UTF8 encoded file-"<<outputFileName.str()<< " and result is " << ret << " Pass" <<endl ;
       
  1440 			}
       
  1441 		} //End of encoded file formats testing
       
  1442 }
       
  1443 
       
  1444 /**
       
  1445 Test case for REQ-10314 (Reviewing Aggregate Certificate DataBase)
       
  1446 */
       
  1447 void TestToReviewingAggregateStore()
       
  1448 {
       
  1449 	for(int index = 0; index<2; index++)
       
  1450 		{
       
  1451 		stringstream file1, file2;
       
  1452 		const char *argv_certclient[4];
       
  1453 		argv_certclient[2] = "--out";
       
  1454 		switch(index)
       
  1455 			{
       
  1456 			case 0: // different certificate labels in two stores
       
  1457 				{
       
  1458 				argv_certclient[0] = "--bfilecertstore=teststore1.dat";   // these are 2 binary stores saved in perforce
       
  1459 				argv_certclient[1] = "--bfilecertstore=teststore3.dat"; 
       
  1460 				argv_certclient[3] = "--hfilecertstore=SDP-Security_Tools-CertApp-AggrCertStore-0000.txt";
       
  1461 				file1 <<"SDP-Security_Tools-CertApp-AggrCertStore-0000.txt";
       
  1462 				file2 <<"aggregatestorecontents1_3.txt";
       
  1463 				}
       
  1464 				break;
       
  1465 
       
  1466 			case 1: //duplicate certificate labels in two stores
       
  1467 				{
       
  1468 				argv_certclient[0] = "--bfilecertstore=teststore2.dat";   // these are 2 binary stores saved in perforce
       
  1469 				argv_certclient[1] = "--bfilecertstore=teststore3.dat"; 
       
  1470 				argv_certclient[3] = "--hfilecertstore=SDP-Security_Tools-CertApp-AggrCertStore-0001.txt";
       
  1471 				file1 <<"SDP-Security_Tools-CertApp-AggrCertStore-0001.txt";
       
  1472 				file2 <<"aggregatestorecontents2_3.txt";
       
  1473 				}
       
  1474 				break;
       
  1475 
       
  1476 			default:
       
  1477 				break;
       
  1478 			}
       
  1479 
       
  1480 		for(int m=0; m<KIndex; m++)
       
  1481 			{
       
  1482 			cout << "Value in argv_certclient " << m << "is " <<argv_certclient[m] <<endl;
       
  1483 			}
       
  1484 		char *argument_ptr[KIndex]; 
       
  1485 		char **argv;
       
  1486 		for(int n = 0; n<KIndex; n++)
       
  1487 			{
       
  1488 			argument_ptr[n] = const_cast<char*>(argv_certclient[n]);
       
  1489 			argv = argument_ptr;
       
  1490 			}
       
  1491 		
       
  1492 		int ret = RunCertApp(progress, errors, KIndex, argv); 
       
  1493 		if(!ret)
       
  1494 			{
       
  1495 			passCount++;
       
  1496 			int compareValue  = CompareFiles(file1,file2); // compare with the reference files in perforce
       
  1497 			if (compareValue)
       
  1498 				{
       
  1499 				file << "Failed to successfully create Aggregate Database for " << file1.str() << " is Fail" <<endl;
       
  1500 				}
       
  1501 			else
       
  1502 				{
       
  1503 				file << "Successfully created Aggregate Database(text form) for " <<file1.str() << " result is Pass" <<endl;
       
  1504 				}
       
  1505 			}
       
  1506 		else
       
  1507 			{
       
  1508 			failCount++;
       
  1509 			file << "Failed to dump the stores to single text format for " <<file1.str() <<endl;
       
  1510 			}
       
  1511 		}
       
  1512 }
       
  1513 
       
  1514 
       
  1515 /**
       
  1516 TestCase to test the req of 10313- decode/encode certstore
       
  1517 Encode-decode test for certclient store
       
  1518 */
       
  1519 void TestToDecodeAndEncodeStore()
       
  1520 {
       
  1521 	stringstream outputFileName, strArg1, strArg2;
       
  1522 	outputFileName <<"SDP-Security_Tools-CertApp-DecodeEncode-0000";
       
  1523 	strArg1 << "decodeoutput1.txt";
       
  1524 	strArg2 << "decodeoutput2.txt";
       
  1525 	
       
  1526 	const char *argv_certclient[3]; //dump store to text
       
  1527 	argv_certclient[0] = "--bcertclients=certclients_0.dat";
       
  1528 	argv_certclient[1] = "--out";
       
  1529 	argv_certclient[2] = "--hcertclients=decodeoutput1.txt";   
       
  1530 	decodeEncodeCertAppCall(argv_certclient);
       
  1531 
       
  1532 	//create store with the decoded text as input
       
  1533 	argv_certclient[0] = "--hcertclients=decodeoutput1.txt";
       
  1534 	argv_certclient[2] = "--bcertclients=decodeoutput.dat";   
       
  1535 	decodeEncodeCertAppCall(argv_certclient);
       
  1536 
       
  1537 	//take the encoded store and dump it back to text form
       
  1538 	argv_certclient[0] = "--bcertclients=decodeoutput.dat";
       
  1539 	argv_certclient[2] = "--hcertclients=decodeoutput2.txt"; 
       
  1540 	decodeEncodeCertAppCall(argv_certclient);
       
  1541 
       
  1542 	int compVal = CompareFiles(strArg1, strArg2);
       
  1543 	cout << "Return value of comparision is " << compVal <<endl;
       
  1544 	if (compVal)
       
  1545 		{
       
  1546 		failCount++;
       
  1547 		file << "Encode-Decode fail for " <<outputFileName.str() << " result is Fail" <<endl;
       
  1548 		}
       
  1549 	else
       
  1550 		{
       
  1551 		passCount++;
       
  1552 		file << "Encode-Decode Pass for " <<outputFileName.str() << " result is Pass" <<endl;
       
  1553 		}
       
  1554 }
       
  1555 
       
  1556 void decodeEncodeCertAppCall(const char *aArray[])
       
  1557 {
       
  1558 	char *argument_ptr[3]; 
       
  1559 	char **argv;
       
  1560 	for(int m=0; m<3; m++)
       
  1561 		{
       
  1562 		cout << "Value in argv_certclient " << m << "is " <<aArray[m] <<endl;
       
  1563 		}
       
  1564 	for(int n = 0; n<3; n++)
       
  1565 		{
       
  1566 		argument_ptr[n] = const_cast<char*>(aArray[n]);
       
  1567 		argv = argument_ptr;
       
  1568 		}
       
  1569 	RunCertApp(progress, errors ,3, argv);
       
  1570 }
       
  1571 
       
  1572 
       
  1573 int CompareFiles(stringstream &aFile1, stringstream &aFile2)
       
  1574 {
       
  1575 	ifstream inFile1, inFile2;
       
  1576 	string name1 = aFile1.str();
       
  1577 	string name2 = aFile2.str();
       
  1578 	inFile1.open(name1.c_str(),  ifstream::in);
       
  1579 	if (inFile1.fail())
       
  1580 		{
       
  1581 		cout << "Failed to open the file! May be not existing" << endl;
       
  1582 		return -1;
       
  1583 		}
       
  1584 	inFile2.open(name1.c_str(),  ifstream::in);
       
  1585 	if (inFile2.fail()) 
       
  1586 		{
       
  1587 	    cout << "Failed to open the file! May be not existing" << endl;
       
  1588 	    return -1;
       
  1589 		}
       
  1590 	return Compare(inFile1, inFile2);
       
  1591 }
       
  1592 
       
  1593 
       
  1594 int Compare(istream &aIstream1, istream &aIstream2)
       
  1595 {
       
  1596   char ch1, ch2;
       
  1597   while (aIstream1.get(ch1)) 
       
  1598   {
       
  1599     if (!aIstream2.get(ch2) || (ch1 != ch2))
       
  1600 	{
       
  1601       cout << "files are not equal";
       
  1602 	  return -1;
       
  1603     }
       
  1604   }
       
  1605   if (!aIstream2.get(ch2))  // no more chars to read fom file
       
  1606 	{
       
  1607 	  cout << "files are equal\n";
       
  1608 	  return 0;
       
  1609 	}
       
  1610   else 
       
  1611 	{
       
  1612 	  cout << "files are not equal";
       
  1613 	  return -1;
       
  1614 	}
       
  1615 }
       
  1616 
       
  1617 
       
  1618 /**
       
  1619 Generate script files for the filecertstore emulator tests
       
  1620 */
       
  1621 void GenerateGoodCertClientTestScripts(const stringstream &aFilename)
       
  1622 {
       
  1623 	CertClientsStoreScriptGeneration cert_clients(aFilename);
       
  1624 
       
  1625 	cert_clients.WriteInitialiseCertClient();
       
  1626 	cert_clients.WriteGetCount(KAppUidIndex);
       
  1627 	cert_clients.WriteGetApplicationsList();
       
  1628 	
       
  1629 	for(int i = 0; i<KAppUidIndex;i++)
       
  1630 		{
       
  1631 		const char *goodlabel = goodcertclient_array[i]; 
       
  1632 		const char *uid = gooddecimalUid_array[i];
       
  1633 		cert_clients.WriteGetAppWithUid(goodlabel, uid);
       
  1634 		}
       
  1635 	cert_clients.WriteDestroyManager();
       
  1636 }
       
  1637 
       
  1638 /**
       
  1639 Generates config files for cacerts
       
  1640 */
       
  1641 void GenerateGoodCaCertsTestScripts(const stringstream &aFilename)
       
  1642 {
       
  1643 	FileStoreScriptGeneration fileStore(aFilename);
       
  1644 
       
  1645 	const char *mode = "write"; 
       
  1646 	const char *ownertype = goodOwnerType[0]; //CA ownerType
       
  1647 
       
  1648 	fileStore.WriteInitialiseCert(mode);
       
  1649 	fileStore.WriteListcert(ownertype);
       
  1650 	
       
  1651 	for(int i = 0; i<6;i++)
       
  1652 		{
       
  1653 		const char *trust = goodTrust[0]; // true
       
  1654 		const char *goodlabel = goodEmuCert_array[i]; // list of label - root5ca , symbiandtestcsa, symbiantestrcsa
       
  1655 
       
  1656 		fileStore.WriteGetCertificateDetails(goodlabel);
       
  1657 		fileStore.WriteGetTrust(goodlabel,trust);
       
  1658 		fileStore.WriteGetApplications(goodlabel);
       
  1659 		fileStore.WriteRetrieveCerts(goodlabel);
       
  1660 		}
       
  1661 }
       
  1662 
       
  1663 /**
       
  1664 Generate script files for the swicertstore emulator tests
       
  1665 */
       
  1666 void GenerateGoodSwiCertTestScripts(const stringstream &aFilename)
       
  1667 {
       
  1668 	SWIStoreScriptGeneration swiStore(aFilename);
       
  1669 	
       
  1670 	const char *ownertype = goodOwnerType[0]; //CA ownerType
       
  1671 	
       
  1672 	//initilaise the store and get list all the certificate ones
       
  1673 	swiStore.WriteInitialiseCert();
       
  1674 	swiStore.WriteListcert(ownertype);
       
  1675 
       
  1676 	for(int i = 0; i<6;i++)
       
  1677 		{
       
  1678 		const char *trust = goodTrust[0]; // true
       
  1679 		const char *goodlabel = goodSwiCert_array[i]; // list of label - root5ca , symbiandtestcsa, symbiantestrcsa
       
  1680 		const char *mandatoryVal = mandatory[0];
       
  1681 		const char *systemupgrade = systemUpgrade[0];
       
  1682 
       
  1683 		swiStore.WriteGetSystemUpgrade(goodlabel,systemupgrade);
       
  1684 		swiStore.WriteRetrieveCerts(goodlabel);
       
  1685 		swiStore.WriteGetApplications(goodlabel);
       
  1686 		swiStore.WriteGetTrust(goodlabel,trust);
       
  1687 		swiStore.WriteGetCapabilities(goodlabel);
       
  1688 		swiStore.WriteGetMandatoryFlag(goodlabel, mandatoryVal);
       
  1689 		}
       
  1690 }
       
  1691 
       
  1692 //End of file