[go: up one dir, main page]

Menu

[r358]: / trunk / VTS3 / ScriptCommand.cpp  Maximize  Restore  History

Download this file

224 lines (167 with data), 5.5 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
// ScriptCommand.cpp: implementation of the ScriptCHECKCommand class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "ScriptDocument.h"
#include "ScriptPacket.h"
#include "ScriptIfdefHandler.h"
#include "ScriptCommand.h"
#include "ScriptMakeDlg.h"
#include "ScriptMsgMake.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
ScriptMessage::ScriptMessage( ScriptIfdefHandler & ifdefHandler, ScriptScanner & scan, ScriptToken & tok, CString * pstrTestTitle, CWnd * pparent /* = NULL */ )
: ScriptCommand(ScriptBase::scriptCheck)
, m_pstrTestTitle(pstrTestTitle)
{
baseStatus = 0;
m_pParent = pparent;
baseLineStart = tok.tokenLine;
scan.Next( tok );
if ( tok.tokenType != scriptValue || tok.tokenEnc != scriptASCIIEnc )
throw "CHECK/MAKE statement requires \"Title Text\" following keyword";
baseLabel = tok.RemoveQuotes();
Parse(ifdefHandler, scan, tok);
baseLineCount = baseLineStart - tok.tokenLine;
}
void ScriptMessage::Parse( ScriptIfdefHandler & ifdefHandler, ScriptScanner & scan, ScriptToken & tok )
{
bool fOpen = false;
// start looking first for ')'... it might be where we left off or the next line.
// either way... look for it first.
scan.Next(tok);
for(;;)
{
if ( tok.tokenType == scriptEOF )
throw "Unexpected end of file";
if ( tok.tokenType != scriptEOL )
{
if ( !fOpen )
{
// we need to check for the first thing...
if ( tok.tokenType != scriptSymbol || tok.tokenSymbol != '(' )
throw "Open parenthesis '(' expected after CHECK/MAKE title";
fOpen = true; // make sure we don't do this again
scan.Next(tok); // could look for next string right after (...
continue;
}
if ( tok.tokenEnc == scriptASCIIEnc && tok.tokenType == scriptValue )
{
if ( !tok.IsDontCare() )
m_strText = m_strText + (m_strText.IsEmpty() ? "" : "\n") + tok.RemoveQuotes();
scan.Next(tok);
}
// know when to quit?
if ( tok.tokenType != scriptEOL )
{
if ( tok.tokenType != scriptSymbol || tok.tokenSymbol != ')' )
throw "Closing parenthesis ')' expected after CHECK/MAKE text";
// found closing deal... move on from here
break;
}
}
do
scan.NextLine(tok);
while ( ifdefHandler.IsIfdefExpression(tok, &scan) || ifdefHandler.IsSkipping() );
}
}
ScriptCHECKCommand::ScriptCHECKCommand( ScriptIfdefHandler & ifdefHandler, ScriptScanner & scan, ScriptToken & tok, CString * pstrTestTitle, CWnd * pparent /* = NULL */ )
:ScriptMessage(ifdefHandler, scan, tok, pstrTestTitle, pparent)
{
baseType = scriptCheck;
// set the image list offset and status
baseImage = 21;
}
ScriptCHECKCommand::~ScriptCHECKCommand()
{
}
bool ScriptCHECKCommand::Execute(CString * pstrError)
{
CString strFullText;
strFullText.Format("TEST: %s\nCHECK: %s\n_____________________________________________\n\n%s\n_____________________________________________\nPass %s?",
(LPCSTR) *m_pstrTestTitle, baseLabel, m_strText, baseLabel);
CScriptMakeDlg dlg(false, strFullText, m_pParent);
if ( dlg.DoModal() != IDOK )
// if ( AfxMessageBox(strFullText, MB_YESNO | MB_ICONQUESTION) != IDYES )
{
ASSERT(pstrError != NULL);
if ( pstrError != NULL )
pstrError->Format("CHECK \"%s\" failed", baseLabel);
return false;
}
return true;
}
ScriptMAKECommand::ScriptMAKECommand( ScriptIfdefHandler & ifdefHandler, ScriptScanner & scan, ScriptToken & tok, CString * pstrTestTitle, CWnd * pparent /* = NULL */ )
:ScriptMessage(ifdefHandler, scan, tok, pstrTestTitle, pparent )
{
baseType = scriptMake;
// set the image list offset and status
baseImage = 25;
m_pdlg = NULL;
m_fHanging = false;
m_nDestroyCode = 0;
}
ScriptMAKECommand::~ScriptMAKECommand()
{
Kill();
}
void ScriptMAKECommand::Kill(int nDestroyCode /* = 1 */ )
{
if ( m_pdlg != NULL )
{
if ( m_pdlg->IsUp() && m_pqueue != NULL )
m_pqueue->Fire( new ScriptMsgMake(ScriptMsgMake::msgmakeDestroy, m_pdlg) );
m_pdlg = NULL;
}
// -1 for failure, 1 for success
m_nDestroyCode = nDestroyCode;
}
bool ScriptMAKECommand::IsUp()
{
if ( m_pdlg )
{
if ( m_pdlg->IsUp() )
m_nDestroyCode = 0;
else
Kill(m_pdlg->IsSuccess() ? 1 : -1);
}
return m_nDestroyCode == 0;
}
bool ScriptMAKECommand::IsSuccess()
{
IsUp();
return m_nDestroyCode == 1;
}
void ScriptMAKECommand::SetQueue(ScriptExecMsgQueue * pqueue)
{
m_pqueue = pqueue;
}
bool ScriptMAKECommand::Execute(CString * pstrError)
{
CString strFullText;
bool fResult = true;
strFullText.Format("TEST: %s\nMAKE: %s\n_____________________________________________\n\n%s\n_____________________________________________\nPress OK when complete.",
(LPCSTR) *m_pstrTestTitle, baseLabel, m_strText);
// should only be called once... but just go with the flow...
ASSERT(m_pdlg == NULL);
if ( m_pdlg != NULL )
return false;
// called with string error pointer if we should do modal...
if ( m_fHanging && m_pqueue != NULL )
{
m_pdlg = new CScriptMakeDlg(true, strFullText, m_pParent );
m_pqueue->Fire( new ScriptMsgMake(ScriptMsgMake::msgmakeCreate, m_pdlg) );
}
else
{
CScriptMakeDlg dlg(true, strFullText, m_pParent );
if ( dlg.DoModal() != IDOK )
{
if ( pstrError != NULL )
pstrError->Format("MAKE \"%s\" failed", baseLabel);
fResult = false;
}
}
return fResult;
}