[go: up one dir, main page]

Menu

[r999]: / trunk / VTS3 / ScriptFrame.cpp  Maximize  Restore  History

Download this file

638 lines (519 with data), 15.7 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
// ScriptFrame.cpp : implementation of the ScriptFrame class
//
#include "stdafx.h"
#include "VTS.h"
#include "ScriptDocument.h"
#include "ScriptFrame.h"
#include "ScriptBase.h"
#include "ScriptExecutor.h"
//MAD_DB Not needed anymore with single session VTS
//#include "ScriptSelectSession.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// ScriptFrame
//madanner 5/03
//IMPLEMENT_DYNCREATE(ScriptFrame, CMDIChildWnd)
IMPLEMENT_DYNCREATE(ScriptFrame, CMDIFrameWnd)
//madanner 5/03 BEGIN_MESSAGE_MAP(ScriptFrame, CMDIChildWnd)
BEGIN_MESSAGE_MAP(ScriptFrame, CMDIFrameWnd)
//{{AFX_MSG_MAP(ScriptFrame)
ON_UPDATE_COMMAND_UI(ID_SCRIPT_CHECK_SYNTAX, OnUpdateScriptCheckSyntax)
ON_UPDATE_COMMAND_UI(ID_SCRIPT_ENV, OnUpdateScriptEnvironment)
ON_UPDATE_COMMAND_UI(ID_SCRIPT_RUN, OnUpdateScriptRun)
ON_UPDATE_COMMAND_UI(ID_SCRIPT_HALT, OnUpdateScriptHalt)
ON_UPDATE_COMMAND_UI(ID_SCRIPT_STEP, OnUpdateScriptStep)
ON_UPDATE_COMMAND_UI(ID_SCRIPT_STEPPASS, OnUpdateScriptStepPass)
ON_UPDATE_COMMAND_UI(ID_SCRIPT_STEPFAIL, OnUpdateScriptStepFail)
ON_UPDATE_COMMAND_UI(ID_SCRIPT_KILL, OnUpdateScriptKill)
ON_UPDATE_COMMAND_UI(ID_SCRIPT_RESET, OnUpdateScriptReset)
ON_COMMAND(ID_SCRIPT_CHECK_SYNTAX, OnScriptCheckSyntax)
ON_COMMAND(ID_SCRIPT_ENV, OnScriptEnvironment)
ON_COMMAND(ID_SCRIPT_RUN, OnScriptRun)
ON_COMMAND(ID_SCRIPT_HALT, OnScriptHalt)
ON_COMMAND(ID_SCRIPT_STEP, OnScriptStep)
ON_COMMAND(ID_SCRIPT_STEPPASS, OnScriptStepPass)
ON_COMMAND(ID_SCRIPT_STEPFAIL, OnScriptStepFail)
ON_COMMAND(ID_SCRIPT_KILL, OnScriptKill)
ON_COMMAND(ID_SCRIPT_RESET, OnScriptReset)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// ScriptFrame construction/destruction
ScriptFrame::ScriptFrame()
: m_pDoc(0), m_bSyntaxOK(FALSE)
{
}
ScriptFrame::~ScriptFrame()
{
}
BOOL ScriptFrame::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
//madanner 5/03 if( !CMDIChildWnd::PreCreateWindow(cs) )
if( !CMDIFrameWnd::PreCreateWindow(cs) )
return FALSE;
return TRUE;
}
/////////////////////////////////////////////////////////////////////////////
// ScriptFrame diagnostics
#ifdef _DEBUG
void ScriptFrame::AssertValid() const
{
//madanner 5/03 CMDIChildWnd::AssertValid();
CMDIFrameWnd::AssertValid();
}
void ScriptFrame::Dump(CDumpContext& dc) const
{
//madanner 5/03 CMDIChildWnd::Dump(dc);
CMDIFrameWnd::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// ScriptFrame message handlers
static UINT Script_indicators[] =
{
ID_SEPARATOR, // status line indicator
// Added by Yajun Zhou, 2002-4-22
ID_LNCOLINDEX,
/////////////////////////
ID_INDICATOR_CAPS,
ID_INDICATOR_NUM,
ID_INDICATOR_SCRL,
};
void ScriptFrame::OnUpdateFrameTitle(BOOL bAddToTitle)
{
CFrameWnd::OnUpdateFrameTitle(bAddToTitle);
}
BOOL ScriptFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext)
{
// save a pointer to the document
m_pDoc = (ScriptDocument*)pContext->m_pCurrentDoc;
// Attempt to create toolbar and status bars
// madanner 5/03
if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
!m_wndToolBar.LoadToolBar(IDR_VTSTYPE))
{
TRACE0("Failed to create toolbar\n");
return -1; // fail to create
}
if (!m_wndStatusBar.Create(this) || !m_wndStatusBar.SetIndicators(Script_indicators, sizeof(Script_indicators)/sizeof(UINT)))
{
TRACE0("Failed to create status bar\n");
return -1; // fail to create
}
// TODO: Delete these three lines if you don't want the toolbar to
// be dockable
m_wndToolBar.EnableDocking( CBRS_ALIGN_ANY );
EnableDocking( CBRS_ALIGN_ANY );
DockControlBar( &m_wndToolBar );
// create a splitter with 2 rows, 1 column
if (!m_wndSplit1.CreateStatic(this, 2, 1))
{
TRACE0("Failed to CreateStaticSplitter\n");
return FALSE;
}
// add the first splitter pane - the edit view in row 0
// Changed by Yajun Zhou, 2002-4-22
// if (!m_wndSplit1.CreateView(0, 0,
// RUNTIME_CLASS(CEditView), CSize(0, 300), pContext))
RECT rt;
GetWindowRect(&rt);
// adjust size: left = full width, top = 1/3 of full height
rt.left = rt.right - rt.left;
rt.top = (rt.bottom - rt.top) / 3;
// if (!m_wndSplit1.CreateView(0, 0, RUNTIME_CLASS(ScriptEdit), CSize(0, 300), pContext))
if (!m_wndSplit1.CreateView(0, 0, RUNTIME_CLASS(ScriptEdit), CSize(rt.left, rt.top * 2), pContext))
{
TRACE0("Failed to create edit pane\n");
return FALSE;
}
// nice to have around
// Changed by Yajun Zhou, 2002-4-22
// m_pEditView = (CEditView*)m_wndSplit1.GetPane( 0, 0 );
m_pEditView = (ScriptEdit*)m_wndSplit1.GetPane( 0, 0 );
//madanner 5/03
// Hack to get frame because we're not really a frame window
m_pEditView->SetFrame(this);
//////////////////////////////////////////////////////////
// pass it along to the document
m_pDoc->m_editData = &m_pEditView->GetEditCtrl();
// add the second splitter pane - which is a nested splitter with 2 columns
if (!m_wndSplit2.CreateStatic(
&m_wndSplit1, // our parent window is the first splitter
1, 2, // the new splitter is 1 row, 2 columns
WS_CHILD | WS_VISIBLE | WS_BORDER, // style, WS_BORDER is needed
m_wndSplit1.IdFromRowCol(1, 0)
// new splitter is in the second row, first column of first splitter
))
{
TRACE0("Failed to create nested splitter\n");
return FALSE;
}
// now create the two views inside the nested splitter
// int cxHalf = max(lpcs->cx / 2, 20);
// tree view gets left half
// if (!m_wndSplit2.CreateView(0, 0, RUNTIME_CLASS(ScriptContentTree), CSize(cxHalf, 0), pContext))
if (!m_wndSplit2.CreateView(0, 0, RUNTIME_CLASS(ScriptContentTree), CSize(rt.left/2, rt.top), pContext))
{
TRACE0("Failed to create tree pane\n");
return FALSE;
}
// nice to have around, and pass along to the document
m_pContentTree = (ScriptContentTree*)m_wndSplit2.GetPane( 0, 0 );
m_pContentTree->m_pDoc = m_pDoc;
m_pContentTree->SetFrame(this);
m_pDoc->m_pContentTree = m_pContentTree;
// Added by Yajun Zhou, 2002-6-20
m_pContentTree->m_pEditView = m_pEditView;
//////////////////////////////////////////////////////////
// list view gets right half
if (!m_wndSplit2.CreateView(0, 1, RUNTIME_CLASS(ScriptParmList), CSize(0, 0), pContext))
{
TRACE0("Failed to create parameter list pane\n");
return FALSE;
}
// nice to have around, and pass along to the document
m_pParmList = (ScriptParmList*)m_wndSplit2.GetPane( 0, 1 );
m_pDoc->m_pParmList = m_pParmList;
// success
return TRUE;
// return CreateClient(lpcs, NULL);
}
void ScriptFrame::SetLnPaneText(LPCSTR lpszText)
{
int i = m_wndStatusBar.CommandToIndex(ID_LNCOLINDEX);
m_wndStatusBar.SetPaneText(i, lpszText);
}
//
// ScriptFrame::OnUpdateScriptCheckSyntax
//
// The syntax for a script can only be checked if there is no executor,
// that is to say, nothing is running.
//
afx_msg void ScriptFrame::OnUpdateScriptCheckSyntax(CCmdUI* pCmdUI)
{
pCmdUI->Enable( gExecutor.IsIdle() );
}
//
// ScriptFrame::OnUpdateScriptEnvironment
//
// The menu is checked when the parameter list in this frame is the
// current environment.
//
afx_msg void ScriptFrame::OnUpdateScriptEnvironment(CCmdUI* pCmdUI)
{
pCmdUI->Enable( true );
pCmdUI->SetCheck( m_pParmList == gCurrentEnv );
}
//
// ScriptFrame::OnUpdateScriptRun
//
// The run command is enabled if the executor is idle and there is
// content to run or the executor is bound to this document and it is
// not running.
//
// If a particular test is selected, then the run command is just for
// that test, otherwise it is for all tests in the script.
//
afx_msg void ScriptFrame::OnUpdateScriptRun(CCmdUI* pCmdUI)
{
if (gExecutor.IsIdle() && m_pDoc->m_pContentTree)
{
pCmdUI->Enable( m_bSyntaxOK );
// Modified by Zhu Zhenhua, 2003-12-18, to run select section
if (m_pDoc->SelectedSection() != NULL)
{
CString str( "&Run " );
str += m_pDoc->SelectedSection()->baseLabel;
str += "\tF5";
pCmdUI->SetText( str );
}
else if (m_pDoc->SelectedTest() != NULL)
{
CString str( "&Run " );
str += m_pDoc->SelectedTest()->baseLabel;
str += "\tF5";
pCmdUI->SetText( str );
}
else
{
pCmdUI->SetText( "&Run all tests\tF5" );
}
}
else if (gExecutor.IsBound(m_pDoc))
{
pCmdUI->SetText( "&Resume" );
pCmdUI->Enable( !gExecutor.IsRunning() );
}
else
{
pCmdUI->SetText( "Run\tF5" );
pCmdUI->Enable( m_bSyntaxOK );
}
}
//
// ScriptFrame::OnUpdateScriptHalt
//
// The halt menu option is only enabled if there is a running script associated with
// this frame.
//
afx_msg void ScriptFrame::OnUpdateScriptHalt(CCmdUI* pCmdUI)
{
pCmdUI->Enable( gExecutor.IsRunning() && gExecutor.IsBound(m_pDoc) );
}
//
// ScriptFrame::OnUpdateScriptStep
//
// The step command is similar to the run command. It will allow a single step to
// be processed when this script is associated with the executor but is not running.
//
afx_msg void ScriptFrame::OnUpdateScriptStep(CCmdUI* pCmdUI)
{
if (gExecutor.IsIdle() && m_pDoc->m_pContentTree)
{
if (m_pDoc->SelectedTest() != NULL)
{
CString str( "&Step " );
str += m_pDoc->SelectedTest()->baseLabel;
str += "\tF6";
pCmdUI->SetText( str );
pCmdUI->Enable( true );
}
else
{
pCmdUI->SetText( "Step\tF6" );
pCmdUI->Enable( false );
}
}
else if (gExecutor.IsBound(m_pDoc))
{
pCmdUI->SetText( "&Step\tF6" );
pCmdUI->Enable( !gExecutor.IsRunning() );
}
else
{
pCmdUI->SetText( "Step\tF6" );
pCmdUI->Enable( false );
}
}
//
// ScriptFrame::OnUpdateScriptStepPass
//
// This step command is similar to the simple step, but the executor must be stopped.
//
afx_msg void ScriptFrame::OnUpdateScriptStepPass(CCmdUI* pCmdUI)
{
pCmdUI->Enable( gExecutor.IsStopped() && gExecutor.IsBound(m_pDoc) );
}
//
// ScriptFrame::OnUpdateScriptStepFail
//
// This step command is similar to the simple step, but the executor must be stopped.
//
afx_msg void ScriptFrame::OnUpdateScriptStepFail(CCmdUI* pCmdUI)
{
pCmdUI->Enable( gExecutor.IsStopped() && gExecutor.IsBound(m_pDoc) );
}
//
// ScriptFrame::OnUpdateScriptKill
//
// If there is a running script associated with this document, allow it to be
// killed (even if it has not been halted first).
//
afx_msg void ScriptFrame::OnUpdateScriptKill(CCmdUI* pCmdUI)
{
pCmdUI->Enable( gExecutor.IsBound(m_pDoc) );
}
//
// ScriptFrame::OnUpdateScriptReset
//
// The reset command can only be executed if there is no script running.
//
afx_msg void ScriptFrame::OnUpdateScriptReset(CCmdUI* pCmdUI)
{
pCmdUI->Enable( gExecutor.IsIdle() );
}
//
// ScriptFrame::OnScriptCheckSyntax
//
void ScriptFrame::OnScriptCheckSyntax()
{
// This may take a while for large scripts
CWaitCursor cur;
m_bSyntaxOK = m_pDoc->CheckSyntax();
}
//
// ScriptFrame::OnScriptEnvironment
//
void ScriptFrame::OnScriptEnvironment()
{
ScriptParmListPtr oldEnv;
// remember the current environment
oldEnv = gCurrentEnv;
// reset the current environment and unload everyone else
if (gCurrentEnv) {
gCurrentEnv->ResetCurrentEnv();
for (int i = 0; i < gScriptParmLists.Length(); i++) {
ScriptParmListPtr splp = gScriptParmLists[i];
if (splp != gCurrentEnv)
splp->UnloadEnv();
}
gCurrentEnv = 0;
}
// if this becomes the new environment, set it and load everyone else
if (m_pParmList != oldEnv) {
gCurrentEnv = m_pParmList;
gCurrentEnv->SetCurrentEnv();
for (int j = 0; j < gScriptParmLists.Length(); j++) {
ScriptParmListPtr splp = gScriptParmLists[j];
if (splp != gCurrentEnv)
splp->LoadEnv();
}
}
}
//
// ScriptFrame::OnScriptRun
//
void ScriptFrame::OnScriptRun()
{
// if the test is already running, ignore this (probably sync issue)
if (gExecutor.IsRunning()) {
TRACE0( "Already running\n" );
return;
}
// if the test has been stopped, allow it to continue
if (gExecutor.IsStopped()) {
TRACE0( "Resume\n" );
gExecutor.Resume();
return;
}
// new test to run
TRACE0( "New run\n" );
// if it can be set up, let it run
if (DoInitialSetup())
gExecutor.Run();
}
//
// ScriptFrame::OnScriptHalt
//
void ScriptFrame::OnScriptHalt()
{
// make sure the executor is bound and running
if (gExecutor.IsIdle()) {
TRACE0( "Error: executor is idle\n" );
return;
}
if (!gExecutor.IsRunning()) {
TRACE0( "Error: executor not running\n" );
return;
}
// stop the executor
gExecutor.Halt();
}
//
// ScriptFrame::OnScriptStep
//
void ScriptFrame::OnScriptStep()
{
// if it is idle, bind it to the selected test and single step
if (gExecutor.IsIdle()) {
// new test to run
TRACE0( "Step into new run\n" );
// get the executor ready
if (!DoInitialSetup())
return;
} else
// if it is running, toss an error
if (gExecutor.IsRunning()) {
TRACE0( "Error: executor running\n" );
return;
}
// let it run for a packet
gExecutor.Step();
}
//
// ScriptFrame::OnScriptStepPass
//
void ScriptFrame::OnScriptStepPass()
{
if (!gExecutor.IsStopped()) {
// new test to run
TRACE0( "Error: executor is not stopped\n" );
return;
}
// assume current packet passed
gExecutor.Step( true );
}
//
// ScriptFrame::OnScriptStepFail
//
void ScriptFrame::OnScriptStepFail()
{
if (!gExecutor.IsStopped()) {
// new test to run
TRACE0( "Error: executor is not stopped\n" );
return;
}
// assume current packet failed
gExecutor.Step( false );
}
//
// ScriptFrame::OnScriptKill
//
void ScriptFrame::OnScriptKill()
{
// verify the executor is running or stopped
if (gExecutor.IsIdle()) {
TRACE0( "Error: executor is idle\n" );
return;
}
// kill the test, executor returns to idle
gExecutor.Kill( false );
}
//
// ScriptFrame::OnScriptReset
//
void ScriptFrame::OnScriptReset()
{
// make sure the executor is idle
if (!gExecutor.IsIdle()) {
TRACE0( "Error: executor is not idle\n" );
return;
}
// let the document reset
m_pDoc->Reset();
}
//
// ScriptFrame::DoInitialSetup
//
bool ScriptFrame::DoInitialSetup( void )
{
VTSDocPtr vdp = (VTSDoc *) ((VTSApp *) AfxGetApp())->GetWorkspace();
// find a database for test messages
if ( vdp == NULL ) {
// alert the user
AfxMessageBox( _T("No session database available to receive test results") );
return false;
}
// tell the executor to run the test
gExecutor.Setup( vdp, m_pDoc, m_pDoc->SelectedTest() );
// success
return true;
}
//
// ScriptFrame::Serialize
//
void ScriptFrame::Serialize(CArchive& ar)
{
if (ar.IsStoring())
{ // storing code
}
else
{ // loading code
}
}