Subversion Repositories DevTools

Rev

Rev 2226 | Rev 2230 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2226 Rev 2228
Line 8... Line 8...
8
#pragma hdrstop
8
#pragma hdrstop
9
 
9
 
10
#include "time.h"
10
#include "time.h"
11
#include "pcreposix.h"
11
#include "pcreposix.h"
12
 
12
 
-
 
13
#include "CopyIteration.h"
13
#include "DataModule.h"
14
#include "DataModule.h"
14
#include "DefinedVariable.h"
15
#include "DefinedVariable.h"
15
#include "DefinedVariableTable.h"
16
#include "DefinedVariableTable.h"
16
#include "EvaluationContext.h"
17
#include "EvaluationContext.h"
17
#include "FieldExpression.h"
18
#include "FieldExpression.h"
18
#include "FileCtrl.hpp"
19
#include "FileCtrl.hpp"
19
#include "GenerationProperties.h"
20
#include "GenerationProperties.h"
20
#include "ICryptographicServerProxy.h"
21
#include "ICryptographicServerProxy.h"
-
 
22
#include "IHash.h"
21
#include "ImportTransactionParameters.h"
23
#include "ImportTransactionParameters.h"
22
#include "InitProgress.h"
24
#include "InitProgress.h"
23
#include "IMessageDigest.h"
25
#include "IMessageDigest.h"
24
#include "ISecurityWrapperFactory.h"
26
#include "ISecurityWrapperFactory.h"
25
#include "Iteration.h"
27
#include "Iteration.h"
Line 609... Line 611...
609
		if ( findSchema( m_schema_handle,
611
		if ( findSchema( m_schema_handle,
610
						 m_currentproject.UpperCase(),
612
						 m_currentproject.UpperCase(),
611
						 candidate ) )
613
						 candidate ) )
612
		{
614
		{
613
			m_currentiteration = candidate;
615
			m_currentiteration = candidate;
-
 
616
			IterationCopyButton->Enabled = true;
614
		}
617
		}
615
		else
618
		else
616
		{
619
		{
617
			m_currentiteration = 0;
620
			m_currentiteration = 0;
618
			IterationsComboBox->ItemIndex = -1;
621
			IterationsComboBox->ItemIndex = -1;
-
 
622
			IterationCopyButton->Enabled = false;
619
		}
623
		}
620
	}
624
	}
621
	else
625
	else
622
	{
626
	{
623
		m_currentiteration = 0;
627
		m_currentiteration = 0;
Line 796... Line 800...
796
		IterationsComboBox->ItemIndex = mru_project_iteration_index;
800
		IterationsComboBox->ItemIndex = mru_project_iteration_index;
797
        IterationsComboBoxChange(Sender);
801
        IterationsComboBoxChange(Sender);
798
 
802
 
799
		bool allow;
803
		bool allow;
800
		TestCaseGridRowChanging(Sender, 0, 1, allow = true );
804
		TestCaseGridRowChanging(Sender, 0, 1, allow = true );
-
 
805
	}
801
    }
806
	else
-
 
807
	{
-
 
808
		IterationCopyButton->Enabled = false;
-
 
809
	}
802
 
810
 
803
    delete query;
811
    delete query;
804
}
812
}
805
//---------------------------------------------------------------------------
813
//---------------------------------------------------------------------------
806
 
814
 
Line 4020... Line 4028...
4020
}
4028
}
4021
//---------------------------------------------------------------------------
4029
//---------------------------------------------------------------------------
4022
 
4030
 
4023
void __fastcall TMainForm::GenerateTestTestCaseBtnClick(TObject *Sender)
4031
void __fastcall TMainForm::GenerateTestTestCaseBtnClick(TObject *Sender)
4024
{
4032
{
4025
	if ( GenerationPropertiesForm->ShowModal() == mrOk )
-
 
4026
	{
-
 
4027
		const bool				generateHeaders	= GenerationPropertiesForm->GenerateHeadersCheckBox->Checked;
-
 
4028
		std::string				folder			= GenerationPropertiesForm->GenerationFolderDirectoryEdit->Text.c_str();
-
 
4029
		const std::string		batchPrefix		= GenerationPropertiesForm->DrainFilePrefixEdit->Text.c_str();
-
 
4030
		const std::string		batchSuffix		= GenerationPropertiesForm->DrainFileSuffixEdit->Text.c_str();
-
 
4031
		const bool				buildManifest	= GenerationPropertiesForm->BuildManifestCheckBox->Checked;
-
 
4032
		const std::string		manifestPrefix	= GenerationPropertiesForm->ManifestPrefixEdit->Text.c_str();
-
 
4033
		const std::string		manifestSuffix	= GenerationPropertiesForm->ManifestSuffixEdit->Text.c_str();
-
 
4034
		const std::string		securityServer	= GenerationPropertiesForm->SecurityServerPipeEdit->Text.c_str();
-
 
4035
		const unsigned short	keyNumber		= GenerationPropertiesForm->KeyNumberEdit->Text.ToInt();
-
 
4036
		const unsigned short	keyVersion		= -2;
-
 
4037
		const std::string		pathmapTarget	= GenerationPropertiesForm->PathmapTargetEdit->Text.c_str();
-
 
4038
 
-
 
4039
		/**
-
 
4040
			Create a transaction stream into our generation folder, and generate
-
 
4041
			the transactions into it.  We need to know whether we have to prepend
-
 
4042
			header (i.e., whether it is a .xdr which has a header, or a .devud which
-
 
4043
			doesn't).
-
 
4044
		 */
-
 
4045
 
-
 
4046
		const TCursor				Save_Cursor					= Screen->Cursor;
-
 
4047
		bool						transactionOpen				= false;
-
 
4048
		ICryptographicServerProxy *	cryptographicServerProxy	= 0;
-
 
4049
		IMessageDigest *			messageDigest				= 0;
-
 
4050
 
-
 
4051
		try
-
 
4052
		{
-
 
4053
			if ( m_securityWrapperFactory )
-
 
4054
			{
-
 
4055
				cryptographicServerProxy = m_securityWrapperFactory
-
 
4056
					->createCryptographicServerProxy( securityServer.c_str() );
-
 
4057
				if ( cryptographicServerProxy )
-
 
4058
				{
-
 
4059
					if ( cryptographicServerProxy->getModuleCount() )
-
 
4060
					{
-
 
4061
						/**
-
 
4062
						 *	We don't know which module will be used to compute the
-
 
4063
						 *	MAC (security doesn't tell us), so until they do we
-
 
4064
						 *	assume its the first module.
-
 
4065
						 */
-
 
4066
						const unsigned int serialNumber =
-
 
4067
							cryptographicServerProxy->getSerialNumber( 0 );
-
 
4068
 
-
 
4069
						/**
-
 
4070
							We now need to turn the 4-byte serial number into an
-
 
4071
							8-byte diversifier.  Apparently, we must do this by
-
 
4072
							writing the serial number into the lower 4-bytes in big
-
 
4073
							endian.  An API is being added to crypto to do this:
-
 
4074
							until it is there we need to do it ourselves.
-
 
4075
						 */
-
 
4076
						unsigned char buffer[ 8 ];
-
 
4077
 
-
 
4078
						buffer[ 0 ] = 0;
-
 
4079
						buffer[ 1 ] = 0;
-
 
4080
						buffer[ 2 ] = 0;
-
 
4081
						buffer[ 3 ] = 0;
-
 
4082
						buffer[ 4 ] = ( serialNumber >> 24 ) & 0xFF;
-
 
4083
						buffer[ 5 ] = ( serialNumber >> 16 ) & 0xFF;
-
 
4084
						buffer[ 6 ] = ( serialNumber >>  8 ) & 0xFF;
-
 
4085
						buffer[ 7 ] = ( serialNumber       ) & 0xFF;
-
 
4086
 
-
 
4087
						messageDigest = m_securityWrapperFactory
-
 
4088
							->createMessageDigest(
-
 
4089
								*cryptographicServerProxy,
-
 
4090
								keyNumber,
-
 
4091
								keyVersion,
-
 
4092
								buffer,
-
 
4093
								sizeof( buffer ) );
-
 
4094
					}
-
 
4095
					else
-
 
4096
					{
-
 
4097
						MWARNING( "Cryptographic server has no modules." );
-
 
4098
					}
-
 
4099
				}
-
 
4100
			}
-
 
4101
 
-
 
4102
			Screen->Cursor = crHourGlass;
-
 
4103
			Data_Module->IntegrationDBConnection->BeginTrans();
-
 
4104
			transactionOpen = true;
-
 
4105
 
-
 
4106
			TransactionStream stream(
-
 
4107
				folder,
-
 
4108
				batchPrefix,
-
 
4109
				batchSuffix,
-
 
4110
				buildManifest,
-
 
4111
				manifestPrefix,
-
 
4112
				manifestSuffix,
-
 
4113
				pathmapTarget );
-
 
4114
			Iteration iteration(
-
 
4115
				m_currentproject.c_str(),
-
 
4116
				m_currentiteration,
-
 
4117
				*XMLSchema->GetSchemaWrapperFactory(),
-
 
4118
				*XMLSchema->GetSchema(),
-
 
4119
				m_schema_handle );
-
 
4120
			DefinedVariableTable	definedVariableTable;
-
 
4121
			SequenceCollection		sequences;
-
 
4122
			TimeEstimate			timeEstimate( *MainStatusBar->Panels->Items[ 0 ] );
-
 
4123
			EvaluationContext		context(
-
 
4124
				definedVariableTable,
-
 
4125
				sequences,
-
 
4126
				*m_progressBar,
-
 
4127
				messageDigest,
-
 
4128
				cryptographicServerProxy,
-
 
4129
				timeEstimate );
-
 
4130
 
-
 
4131
			buildExecutionSchedule(
-
 
4132
				iteration,
-
 
4133
				TestCaseQuery->FieldByName( "TESTCASE_ID" )->AsString.c_str() );
-
 
4134
			loadLegacyVariables(
-
 
4135
				definedVariableTable,
-
 
4136
				m_currentproject.c_str(),
-
 
4137
				iteration );
-
 
4138
			readSequences(
-
 
4139
				sequences,
-
 
4140
				m_currentproject.c_str(),
-
 
4141
				m_currentiteration );
-
 
4142
 
-
 
4143
			try
-
 
4144
			{
-
 
4145
				const int count = iteration.getTransactionCount();
-
 
4146
				m_progressBar->open( count );
-
 
4147
				timeEstimate.start( count );
-
 
4148
			
-
 
4149
				if ( iteration.generate(
-
 
4150
						stream,
-
 
4151
						generateHeaders,
-
 
4152
						context ) )
-
 
4153
				{
-
 
4154
					writeSequences(
-
 
4155
						sequences,
-
 
4156
						m_currentproject.c_str(),
-
 
4157
						m_currentiteration );
4033
	std::vector< int > scenarios;
4158
 
4034
	
4159
					Data_Module->IntegrationDBConnection->CommitTrans();
-
 
4160
					transactionOpen = false;
4035
	generateTransaction( scenarios );
4161
				}
-
 
4162
			}
-
 
4163
			__finally
-
 
4164
			{
-
 
4165
				timeEstimate.stop();
-
 
4166
				m_progressBar->close();
-
 
4167
			}
-
 
4168
		}
-
 
4169
		__finally
-
 
4170
		{
-
 
4171
			if ( messageDigest )
-
 
4172
			{
-
 
4173
				m_securityWrapperFactory
-
 
4174
					->destroyMessageDigest( *messageDigest );
-
 
4175
				messageDigest = 0;
-
 
4176
			}
-
 
4177
			if ( cryptographicServerProxy )
-
 
4178
			{
-
 
4179
				m_securityWrapperFactory
-
 
4180
					->destroyCryptographicServerProxy( *cryptographicServerProxy );
-
 
4181
				cryptographicServerProxy = 0;
-
 
4182
			}
-
 
4183
 
-
 
4184
			if ( transactionOpen )
-
 
4185
			{
-
 
4186
				Data_Module->IntegrationDBConnection->RollbackTrans();
-
 
4187
			}
-
 
4188
			Screen->Cursor = Save_Cursor;
-
 
4189
		}
-
 
4190
	}
-
 
4191
}
4036
}
4192
//---------------------------------------------------------------------------
4037
//---------------------------------------------------------------------------
4193
 
4038
 
4194
const unsigned __fastcall TMainForm::countTransactionsInIteration( const char * project, const int & iteration )
4039
const unsigned __fastcall TMainForm::countTransactionsInIteration( const char * project, const int & iteration )
4195
{
4040
{
Line 5236... Line 5081...
5236
		}
5081
		}
5237
	}
5082
	}
5238
}
5083
}
5239
//---------------------------------------------------------------------------
5084
//---------------------------------------------------------------------------
5240
 
5085
 
-
 
5086
void __fastcall TMainForm::IterationCopyButtonClick(TObject *Sender)
-
 
5087
{
-
 
5088
	if ( !m_currentproject.IsEmpty() && m_currentiteration )
-
 
5089
	{
-
 
5090
		CopyIterationForm->ShowForm( m_currentproject, m_currentiteration );
-
 
5091
	}
-
 
5092
}
-
 
5093
//---------------------------------------------------------------------------
-
 
5094
 
-
 
5095
void __fastcall TMainForm::generateTransaction( std::vector< int > & scenarios )
-
 
5096
{
-
 
5097
	if ( GenerationPropertiesForm->ShowModal() == mrOk )
-
 
5098
	{
-
 
5099
		const bool				generateHeaders	= GenerationPropertiesForm->GenerateHeadersCheckBox->Checked;
-
 
5100
		const std::string		folder			= GenerationPropertiesForm->GenerationFolderDirectoryEdit->Text.c_str();
-
 
5101
		const std::string		batchPrefix		= GenerationPropertiesForm->DrainFilePrefixEdit->Text.c_str();
-
 
5102
		const std::string		batchSuffix		= GenerationPropertiesForm->DrainFileSuffixEdit->Text.c_str();
-
 
5103
		const bool				buildManifest	= GenerationPropertiesForm->BuildManifestCheckBox->Checked;
-
 
5104
		const std::string		manifestPrefix	= GenerationPropertiesForm->ManifestPrefixEdit->Text.c_str();
-
 
5105
		const std::string		manifestSuffix	= GenerationPropertiesForm->ManifestSuffixEdit->Text.c_str();
-
 
5106
		const std::string		securityServer	= GenerationPropertiesForm->SecurityServerPipeEdit->Text.c_str();
-
 
5107
		const unsigned short	keyNumber		= GenerationPropertiesForm->KeyNumberEdit->Text.ToInt();
-
 
5108
		const unsigned short	keyVersion		= -2;
-
 
5109
		const std::string		pathmapTarget	= GenerationPropertiesForm->PathmapTargetEdit->Text.c_str();
-
 
5110
		const int				macAlgorithm	= GenerationPropertiesForm->MacAlgorithmComboBox->ItemIndex;
-
 
5111
 
-
 
5112
		/**
-
 
5113
			Create a transaction stream into our generation folder, and generate
-
 
5114
			the transactions into it.  We need to know whether we have to prepend
-
 
5115
			header (i.e., whether it is a .xdr which has a header, or a .devud which
-
 
5116
			doesn't).
-
 
5117
		 */
-
 
5118
 
-
 
5119
		const TCursor				Save_Cursor					= Screen->Cursor;
-
 
5120
		bool						transactionOpen				= false;
-
 
5121
		ICryptographicServerProxy *	cryptographicServerProxy	= 0;
-
 
5122
		IMessageDigest *			messageDigest				= 0;
-
 
5123
		IHash *						hash						= 0;
-
 
5124
 
-
 
5125
		try
-
 
5126
		{
-
 
5127
			if ( m_securityWrapperFactory )
-
 
5128
			{
-
 
5129
				cryptographicServerProxy = m_securityWrapperFactory
-
 
5130
					->createCryptographicServerProxy( securityServer.c_str() );
-
 
5131
				if ( cryptographicServerProxy )
-
 
5132
				{
-
 
5133
					if ( cryptographicServerProxy->getModuleCount() )
-
 
5134
					{
-
 
5135
						/**
-
 
5136
						 *	We don't know which module will be used to compute the
-
 
5137
						 *	MAC (security doesn't tell us), so until they do we
-
 
5138
						 *	assume its the first module.
-
 
5139
						 */
-
 
5140
						const unsigned int serialNumber =
-
 
5141
							cryptographicServerProxy->getSerialNumber( 0 );
-
 
5142
 
-
 
5143
						/**
-
 
5144
							We now need to turn the 4-byte serial number into an
-
 
5145
							8-byte diversifier.  Apparently, we must do this by
-
 
5146
							writing the serial number into the lower 4-bytes in big
-
 
5147
							endian.  An API is being added to crypto to do this:
-
 
5148
							until it is there we need to do it ourselves.
-
 
5149
						 */
-
 
5150
						unsigned char buffer[ 8 ];
-
 
5151
 
-
 
5152
						buffer[ 0 ] = 0;
-
 
5153
						buffer[ 1 ] = 0;
-
 
5154
						buffer[ 2 ] = 0;
-
 
5155
						buffer[ 3 ] = 0;
-
 
5156
						buffer[ 4 ] = ( serialNumber >> 24 ) & 0xFF;
-
 
5157
						buffer[ 5 ] = ( serialNumber >> 16 ) & 0xFF;
-
 
5158
						buffer[ 6 ] = ( serialNumber >>  8 ) & 0xFF;
-
 
5159
						buffer[ 7 ] = ( serialNumber       ) & 0xFF;
-
 
5160
 
-
 
5161
						messageDigest = m_securityWrapperFactory
-
 
5162
							->createMessageDigest(
-
 
5163
								*cryptographicServerProxy,
-
 
5164
								keyNumber,
-
 
5165
								keyVersion,
-
 
5166
								buffer,
-
 
5167
								sizeof( buffer ) );
-
 
5168
						/**
-
 
5169
						 *	If we need to compute the MAC by computing the MAC
-
 
5170
						 *	of the SHA-1 hash, then we create the hash object
-
 
5171
						 *	here.
-
 
5172
						 */
-
 
5173
						if ( macAlgorithm == 1 )
-
 
5174
						{
-
 
5175
							hash = m_securityWrapperFactory->createHash();
-
 
5176
						}
-
 
5177
					}
-
 
5178
					else
-
 
5179
					{
-
 
5180
						MWARNING( "Cryptographic server has no modules." );
-
 
5181
					}
-
 
5182
				}
-
 
5183
			}
-
 
5184
 
-
 
5185
			Screen->Cursor = crHourGlass;
-
 
5186
			Data_Module->IntegrationDBConnection->BeginTrans();
-
 
5187
			transactionOpen = true;
-
 
5188
 
-
 
5189
			TransactionStream stream(
-
 
5190
				folder,
-
 
5191
				batchPrefix,
-
 
5192
				batchSuffix,
-
 
5193
				buildManifest,
-
 
5194
				manifestPrefix,
-
 
5195
				manifestSuffix,
-
 
5196
				pathmapTarget );
-
 
5197
			Iteration iteration(
-
 
5198
				m_currentproject.c_str(),
-
 
5199
				m_currentiteration,
-
 
5200
				*XMLSchema->GetSchemaWrapperFactory(),
-
 
5201
				*XMLSchema->GetSchema(),
-
 
5202
				m_schema_handle );
-
 
5203
			DefinedVariableTable	definedVariableTable;
-
 
5204
			SequenceCollection		sequences;
-
 
5205
			TimeEstimate			timeEstimate( *MainStatusBar->Panels->Items[ 0 ] );
-
 
5206
			EvaluationContext		context(
-
 
5207
				definedVariableTable,
-
 
5208
				sequences,
-
 
5209
				*m_progressBar,
-
 
5210
				messageDigest,
-
 
5211
				hash,
-
 
5212
				cryptographicServerProxy,
-
 
5213
				timeEstimate );
-
 
5214
 
-
 
5215
			buildExecutionSchedule(
-
 
5216
				iteration,
-
 
5217
				TestCaseQuery->FieldByName( "TESTCASE_ID" )->AsString.c_str() );
-
 
5218
			loadLegacyVariables(
-
 
5219
				definedVariableTable,
-
 
5220
				m_currentproject.c_str(),
-
 
5221
				iteration );
-
 
5222
			readSequences(
-
 
5223
				sequences,
-
 
5224
				m_currentproject.c_str(),
-
 
5225
				m_currentiteration );
-
 
5226
 
-
 
5227
			try
-
 
5228
			{
-
 
5229
				int		count		= 0;
-
 
5230
				bool	generated	= false;
-
 
5231
				
-
 
5232
				if ( scenarios.empty() )
-
 
5233
				{
-
 
5234
					count = iteration.getTransactionCount();
-
 
5235
 
-
 
5236
					m_progressBar->open( count );
-
 
5237
					timeEstimate.start( count );
-
 
5238
 
-
 
5239
					generated = iteration.generate(
-
 
5240
						stream,
-
 
5241
						generateHeaders,
-
 
5242
						context );
-
 
5243
				}
-
 
5244
				else
-
 
5245
				{
-
 
5246
					std::vector< int >::const_iterator where = scenarios.begin();
-
 
5247
					for ( where = scenarios.begin();
-
 
5248
						  where != scenarios.end();
-
 
5249
						  ++where )
-
 
5250
					{
-
 
5251
						count += iteration.
-
 
5252
							findTestScenario( *where ).getTransactionCount();
-
 
5253
					}
-
 
5254
 
-
 
5255
					m_progressBar->open( count );
-
 
5256
					timeEstimate.start( count );
-
 
5257
 
-
 
5258
					for ( where = scenarios.begin();
-
 
5259
						  where != scenarios.end();
-
 
5260
						  ++where )
-
 
5261
					{
-
 
5262
						iteration.findTestScenario( *where ).generate(
-
 
5263
							stream,
-
 
5264
							generateHeaders,
-
 
5265
							context );
-
 
5266
					}
-
 
5267
				}
-
 
5268
 
-
 
5269
				if ( generated )
-
 
5270
				{
-
 
5271
					writeSequences(
-
 
5272
						sequences,
-
 
5273
						m_currentproject.c_str(),
-
 
5274
						m_currentiteration );
-
 
5275
 
-
 
5276
					Data_Module->IntegrationDBConnection->CommitTrans();
-
 
5277
					transactionOpen = false;
-
 
5278
				}
-
 
5279
			}
-
 
5280
			__finally
-
 
5281
			{
-
 
5282
				timeEstimate.stop();
-
 
5283
				m_progressBar->close();
-
 
5284
			}
-
 
5285
		}
-
 
5286
		__finally
-
 
5287
		{
-
 
5288
			if ( hash )
-
 
5289
			{
-
 
5290
				m_securityWrapperFactory->destroyHash( *hash );
-
 
5291
				hash = 0;
-
 
5292
			}
-
 
5293
			if ( messageDigest )
-
 
5294
			{
-
 
5295
				m_securityWrapperFactory
-
 
5296
					->destroyMessageDigest( *messageDigest );
-
 
5297
				messageDigest = 0;
-
 
5298
			}
-
 
5299
			if ( cryptographicServerProxy )
-
 
5300
			{
-
 
5301
				m_securityWrapperFactory
-
 
5302
					->destroyCryptographicServerProxy( *cryptographicServerProxy );
-
 
5303
				cryptographicServerProxy = 0;
-
 
5304
			}
-
 
5305
 
-
 
5306
			if ( transactionOpen )
-
 
5307
			{
-
 
5308
				Data_Module->IntegrationDBConnection->RollbackTrans();
-
 
5309
			}
-
 
5310
			Screen->Cursor = Save_Cursor;
-
 
5311
		}
-
 
5312
	}
-
 
5313
}
-
 
5314
//---------------------------------------------------------------------------
-
 
5315
 
-
 
5316
void __fastcall TMainForm::GenerateActionExecute(TObject *Sender)
-
 
5317
{
-
 
5318
	TTreeNode *			currentNode = 0;
-
 
5319
	std::vector< int >	scenarios;
-
 
5320
 
-
 
5321
	for ( unsigned selection=0;
-
 
5322
		  selection<TestCaseTreeView->SelectionCount;
-
 
5323
		  selection++ )
-
 
5324
	{
-
 
5325
		currentNode = TestCaseTreeView->Selections[ selection ];
-
 
5326
		if ( currentNode )
-
 
5327
		{
-
 
5328
			scenarios.push_back( reinterpret_cast< int >( currentNode->Data ) );
-
 
5329
		}
-
 
5330
	}
-
 
5331
	generateTransaction( scenarios );
-
 
5332
}
-
 
5333
//---------------------------------------------------------------------------
-
 
5334