Subversion Repositories DevTools

Rev

Rev 2222 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2218 sbetterm 1
//## begin module%1.7%.codegen_version preserve=yes
2
//   Read the documentation to learn more about C++ code generator
3
//   versioning.
4
//## end module%1.7%.codegen_version
5
 
6
//## begin module%42030C2C00B8.cm preserve=no
7
//## end module%42030C2C00B8.cm
8
 
9
//## begin module%42030C2C00B8.cp preserve=no
10
//	C O P Y R I G H T   N O T I C E
11
//	This material is confidential to ERG and may not be disclosed in whole
12
//	or in part to any third party nor used in any manner whatsoever other
13
//	than for the purposes expressly consented to by ERG in writing.
14
//
15
//	This material is also copyright and may not be reproduced, stored in a
16
//	retrieval system or transmitted in any form or by any means in whole or
17
//	in part without the express written consent of ERG.
18
//## end module%42030C2C00B8.cp
19
 
20
//## Module: TestScenario%42030C2C00B8; Pseudo Package body
21
//## Subsystem: MASS::Dev::Tools::TxnTestManager::src%41F5A79001E4
22
//## Source file: Z:\MASS_Dev\Tools\TxnTestManager\src\TestScenario.cpp
23
 
24
//## begin module%42030C2C00B8.additionalIncludes preserve=no
25
//## end module%42030C2C00B8.additionalIncludes
26
 
27
//## begin module%42030C2C00B8.includes preserve=yes
28
#pragma warn -com
29
#include <LoggingMacros.h>
30
#pragma warn +com
31
//## end module%42030C2C00B8.includes
32
 
2224 sbetterm 33
// Iteration
34
#include "Iteration.h"
35
// TestScenario
36
#include "TestScenario.h"
2218 sbetterm 37
// TransactionSpecification
38
#include "TransactionSpecification.h"
39
// EvaluationContext
40
#include "EvaluationContext.h"
41
// TransactionStream
42
#include "TransactionStream.h"
2224 sbetterm 43
// DefinedVariable
44
#include "DefinedVariable.h"
2218 sbetterm 45
//## begin module%42030C2C00B8.additionalDeclarations preserve=yes
46
#include <locale>
47
//## end module%42030C2C00B8.additionalDeclarations
48
 
49
 
50
// Class TestScenario 
51
 
52
//## Operation: TestScenario%4203231D030E
53
TestScenario::TestScenario (const int &scenario, Iteration& iteration)
54
  //## begin TestScenario::TestScenario%4203231D030E.hasinit preserve=no
55
      : m_batchSize(0),
56
        m_repeatCount(0),
57
        m_iteration(&iteration)
58
  //## end TestScenario::TestScenario%4203231D030E.hasinit
59
  //## begin TestScenario::TestScenario%4203231D030E.initialization preserve=yes
60
 
61
,	m_scenario( scenario )
62
 
63
  //## end TestScenario::TestScenario%4203231D030E.initialization
64
{
65
  //## begin TestScenario::TestScenario%4203231D030E.body preserve=yes
66
  //## end TestScenario::TestScenario%4203231D030E.body
67
}
68
 
69
 
70
TestScenario::~TestScenario()
71
{
72
  //## begin TestScenario::~TestScenario%42030C2C00B8_dest.body preserve=yes
73
 
74
	for ( std::map< int, TransactionSpecification * >::iterator
75
			where = m_transaction.begin();
76
		  where != m_transaction.end();
77
		  ++where )
78
	{
79
		delete where->second;
80
		where->second = 0;
81
	}
82
	m_iteration = 0;	// We don't own this object.
83
 
84
  //## end TestScenario::~TestScenario%42030C2C00B8_dest.body
85
}
86
 
87
 
88
 
89
//## Other Operations (implementation)
90
//## Operation: buildBatchName%4208537A00B6
91
std::string & TestScenario::buildBatchName (std::string &batchName, const std::string &scenarioName)
92
{
93
  //## begin TestScenario::buildBatchName%4208537A00B6.body preserve=yes
94
 
95
	batchName.erase();
96
	batchName.reserve( scenarioName.length() );
97
 
98
	for ( std::string::size_type index = 0; index < scenarioName.length(); ++index )
99
	{
100
		if ( std::isalnum( scenarioName[ index ] ) )
101
		{
102
			batchName += scenarioName[ index ];
103
		}
104
		else
105
		{
106
			batchName += '_';
107
		}
108
	}
109
 
110
	return ( batchName );
111
 
112
  //## end TestScenario::buildBatchName%4208537A00B6.body
113
}
114
 
2224 sbetterm 115
//## Operation: defineVariable%425B47DD004F
116
DefinedVariable& TestScenario::defineVariable (const std::string &variableName)
117
{
118
  //## begin TestScenario::defineVariable%425B47DD004F.body preserve=yes
119
 
120
	std::map< std::string, DefinedVariable * >::const_iterator
121
		instance = m_variable.find( variableName );
122
 
123
	if ( instance != m_variable.end() )
124
	{
125
		return ( *instance->second );
126
	}
127
	else
128
	{
129
		DefinedVariable * object = 0;
130
 
131
		try
132
		{
133
			object = new DefinedVariable( variableName );
134
 
135
			if ( m_variable.insert(
136
					std::map< std::string, DefinedVariable * >::value_type(
137
						variableName,
138
						object ) ).second )
139
			{
140
				return ( *object );
141
			}
142
			else
143
			{
144
				MTHROW( std::runtime_error, \
145
					"Cannot add variable \"" \
146
					<< variableName \
147
					<< "\" to defined variable table." );
148
			}
149
		}
150
		catch ( ... )
151
		{
152
			delete object;
153
			object = 0;
154
 
155
			throw;
156
		}
157
	}
158
 
159
  //## end TestScenario::defineVariable%425B47DD004F.body
160
}
161
 
2218 sbetterm 162
//## Operation: generate%420455D80390
163
const bool TestScenario::generate (TransactionStream& stream, const bool &generateHeaders, EvaluationContext& evaluationContext)
164
{
165
  //## begin TestScenario::generate%420455D80390.body preserve=yes
166
 
167
	bool generated = true;
168
	if ( m_repeatCount )
169
	{
170
		std::string batchName;
171
		stream.newBatch(
172
			m_batchSize,
173
			buildBatchName( batchName, m_scenarioName ) );
2222 sbetterm 174
		for ( unsigned repeat = 1; repeat <= m_repeatCount && generated; ++repeat )
2218 sbetterm 175
		{
2222 sbetterm 176
			evaluationContext.setScenarioIndex( repeat );
177
 
2218 sbetterm 178
			for ( std::vector< TransactionSpecification * >::iterator
179
					where = m_orderedTransactionCollection.begin();
180
				  where != m_orderedTransactionCollection.end();
181
				  ++where )
182
			{
183
				if ( !(*where)->generate(
184
							stream,
185
							generateHeaders,
186
							evaluationContext ) )
187
				{
188
					generated = false;
189
					break;
190
				}
191
			}
192
		}
193
	}
194
	return ( generated );
195
 
196
  //## end TestScenario::generate%420455D80390.body
197
}
198
 
199
//## Operation: getBatchSize%42042C5E0029
200
const unsigned & TestScenario::getBatchSize () const
201
{
202
  //## begin TestScenario::getBatchSize%42042C5E0029.body preserve=yes
203
 
204
	return ( m_batchSize );
205
 
206
  //## end TestScenario::getBatchSize%42042C5E0029.body
207
}
208
 
209
//## Operation: getIteration%420460EA003C
2224 sbetterm 210
const Iteration & TestScenario::getIteration () const
2218 sbetterm 211
{
212
  //## begin TestScenario::getIteration%420460EA003C.body preserve=yes
213
 
214
	return ( *m_iteration );  
215
 
216
  //## end TestScenario::getIteration%420460EA003C.body
217
}
218
 
219
//## Operation: getRepeatCount%42042C5D02F8
220
const unsigned & TestScenario::getRepeatCount () const
221
{
222
  //## begin TestScenario::getRepeatCount%42042C5D02F8.body preserve=yes
223
 
224
	return ( m_repeatCount );
225
 
226
  //## end TestScenario::getRepeatCount%42042C5D02F8.body
227
}
228
 
229
//## Operation: getScenarioName%42084D3A0270
230
const std::string & TestScenario::getScenarioName () const
231
{
232
  //## begin TestScenario::getScenarioName%42084D3A0270.body preserve=yes
233
 
234
	return ( m_scenarioName );
235
 
236
  //## end TestScenario::getScenarioName%42084D3A0270.body
237
}
238
 
239
//## Operation: getScenarioNumber%4203252300A6
240
const int & TestScenario::getScenarioNumber () const
241
{
242
  //## begin TestScenario::getScenarioNumber%4203252300A6.body preserve=yes
243
 
244
	return ( m_scenario );
245
 
246
  //## end TestScenario::getScenarioNumber%4203252300A6.body
247
}
248
 
249
//## Operation: getTransactionCount%420890BF03BE
250
const unsigned TestScenario::getTransactionCount () const
251
{
252
  //## begin TestScenario::getTransactionCount%420890BF03BE.body preserve=yes
253
 
254
	return ( m_transaction.size() * m_repeatCount );
255
 
256
  //## end TestScenario::getTransactionCount%420890BF03BE.body
257
}
258
 
259
//## Operation: getTransactionSpecification%420328E00043
260
TransactionSpecification& TestScenario::getTransactionSpecification (const int &transaction, const std::string &payloadStructureName)
261
{
262
  //## begin TestScenario::getTransactionSpecification%420328E00043.body preserve=yes
263
 
264
	std::map< int, TransactionSpecification * >::const_iterator
265
		instance = m_transaction.find( transaction );
266
 
267
	if ( instance != m_transaction.end() )
268
	{
269
		return ( *instance->second );
270
	}
271
	else
272
	{
273
		TransactionSpecification * object = 0;
274
 
275
		try
276
		{
277
			object = new TransactionSpecification( transaction, payloadStructureName, *this );
278
 
279
			m_orderedTransactionCollection.push_back( object );
280
			if ( m_transaction.insert(
281
					std::map< int, TransactionSpecification * >::value_type(
282
						transaction,
283
						object ) ).second )
284
			{
285
				return ( *object );
286
			}
287
			else
288
			{
289
				MTHROW( std::runtime_error, \
290
					"Cannot add transaction \"" \
291
					<< transaction \
292
					<< "\" to scenario " \
293
					<< m_scenario \
294
					<< '.' );
295
			}
296
		}
297
		catch ( ... )
298
		{
299
			delete object;
300
			object = 0;
301
 
302
			throw;
303
		}
304
	}
305
 
306
  //## end TestScenario::getTransactionSpecification%420328E00043.body
307
}
308
 
2224 sbetterm 309
//## Operation: getVariable%425B47F50012
310
DefinedVariable& TestScenario::getVariable (const std::string &variableName)
311
{
312
  //## begin TestScenario::getVariable%425B47F50012.body preserve=yes
313
 
314
	std::map< std::string, DefinedVariable * >::const_iterator
315
		instance = m_variable.find( variableName );
316
 
317
	if ( instance != m_variable.end() )
318
	{
319
		return ( *instance->second );
320
	}
321
 
322
	MTHROW( std::runtime_error, \
323
		"Variable \"" \
324
		<< variableName \
325
		<< "\" is not defined." );
326
 
327
  //## end TestScenario::getVariable%425B47F50012.body
328
}
329
 
330
//## Operation: isVariable%425B4B6A01C1
331
const bool TestScenario::isVariable (const std::string &symbol) const
332
{
333
  //## begin TestScenario::isVariable%425B4B6A01C1.body preserve=yes
334
 
335
	return ( m_variable.find( symbol ) != m_variable.end() );
336
 
337
  //## end TestScenario::isVariable%425B4B6A01C1.body
338
}
339
 
2218 sbetterm 340
//## Operation: setBatchSize%42042CF100D5
341
const unsigned & TestScenario::setBatchSize (const unsigned &value)
342
{
343
  //## begin TestScenario::setBatchSize%42042CF100D5.body preserve=yes
344
 
345
	return ( m_batchSize = value );
346
 
347
  //## end TestScenario::setBatchSize%42042CF100D5.body
348
}
349
 
350
//## Operation: setRepeatCount%42042CF100E5
351
const unsigned & TestScenario::setRepeatCount (const unsigned &value)
352
{
353
  //## begin TestScenario::setRepeatCount%42042CF100E5.body preserve=yes
354
 
355
	return ( m_repeatCount = value );
356
 
357
  //## end TestScenario::setRepeatCount%42042CF100E5.body
358
}
359
 
360
//## Operation: setScenarioName%42084D300222
361
std::string & TestScenario::setScenarioName (const std::string &value)
362
{
363
  //## begin TestScenario::setScenarioName%42084D300222.body preserve=yes
364
 
365
	return ( m_scenarioName = value );
366
 
367
  //## end TestScenario::setScenarioName%42084D300222.body
368
}
369
 
370
// Additional Declarations
371
  //## begin TestScenario%42030C2C00B8.declarations preserve=yes
372
  //## end TestScenario%42030C2C00B8.declarations
373
 
374
//## begin module%42030C2C00B8.epilog preserve=yes
375
//## end module%42030C2C00B8.epilog