StepCommand.cc Source File

Back to the index.

StepCommand.cc
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2009-2010 Anders Gavare. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are met:
6  *
7  * 1. Redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution.
12  * 3. The name of the author may not be used to endorse or promote products
13  * derived from this software without specific prior written permission.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25  * SUCH DAMAGE.
26  */
27 
28 #include "commands/StepCommand.h"
29 #include "GXemul.h"
30 
31 
33  : Command("step", "[nsteps]")
34 {
35 }
36 
37 
39 {
40 }
41 
42 
43 bool StepCommand::Execute(GXemul& gxemul, const vector<string>& arguments)
44 {
45  int64_t nsteps = 1;
46 
47  if (arguments.size() > 1) {
48  gxemul.GetUI()->ShowDebugMessage("step: Too many arguments.\n");
49  return false;
50  }
51 
52  if (arguments.size() > 0) {
53  stringstream ss;
54  ss << arguments[0];
55  ss >> nsteps;
56  }
57 
58  if (nsteps < 1) {
59  gxemul.GetUI()->ShowDebugMessage("nr of steps must be at least 1\n");
60  return false;
61  }
62 
64  gxemul.SetNrOfSingleStepsInARow(nsteps);
65 
66  return true;
67 }
68 
69 
71 {
72  return "Runs one step of the emulation.";
73 }
74 
75 
77 {
78  return "Runs one step (or multiple single-steps) in the emulation.\n"
79  "\n"
80  "See also: continue (to continue without single-stepping)\n";
81 }
82 
83 
84 /*****************************************************************************/
85 
86 
87 #ifdef WITHUNITTESTS
88 
89 static void Test_StepCommand_Affect_RunState()
90 {
92  vector<string> dummyArguments;
93 
94  GXemul gxemul;
95 
96  UnitTest::Assert("the default GXemul instance should be Paused",
97  gxemul.GetRunState() == GXemul::Paused);
98 
99  cmd->Execute(gxemul, dummyArguments);
100 
101  UnitTest::Assert("runstate should have been changed to SingleStepping",
102  gxemul.GetRunState() == GXemul::SingleStepping);
103 }
104 
105 static void Test_StepCommand_GoodArgs()
106 {
108  vector<string> arguments;
109 
110  GXemul gxemul;
111  arguments.push_back("42");
112 
113  UnitTest::Assert("should have succeeded; good arguments",
114  cmd->Execute(gxemul, arguments));
115 }
116 
117 static void Test_StepCommand_BadArgs_TooMany()
118 {
120  vector<string> arguments;
121 
122  GXemul gxemul;
123  arguments.push_back("42");
124  arguments.push_back("43");
125 
126  UnitTest::Assert("should not have succeeded; noo many args",
127  !cmd->Execute(gxemul, arguments));
128 }
129 
130 static void Test_StepCommand_BadArgs_Zero()
131 {
133  vector<string> arguments;
134 
135  GXemul gxemul;
136  arguments.push_back("0");
137 
138  UnitTest::Assert("should not have succeeded; too few steps",
139  !cmd->Execute(gxemul, arguments));
140 }
141 
142 static void Test_StepCommand_BadArgs_Negative()
143 {
145  vector<string> arguments;
146 
147  GXemul gxemul;
148  arguments.push_back("-42");
149 
150  UnitTest::Assert("should not have succeeded; negative nr of steps",
151  !cmd->Execute(gxemul, arguments));
152 }
153 
155 {
156  UNITTEST(Test_StepCommand_Affect_RunState);
157  UNITTEST(Test_StepCommand_GoodArgs);
158  UNITTEST(Test_StepCommand_BadArgs_TooMany);
159  UNITTEST(Test_StepCommand_BadArgs_Zero);
160  UNITTEST(Test_StepCommand_BadArgs_Negative);
161 }
162 
163 #endif
GXemul
The main emulator class.
Definition: GXemul.h:55
GXemul::SetNrOfSingleStepsInARow
void SetNrOfSingleStepsInARow(uint64_t steps)
Sets the nr of single-steps to perform in a row.
Definition: GXemul.cc:792
StepCommand::GetShortDescription
virtual string GetShortDescription() const
Returns a short (one-line) description of the command.
Definition: StepCommand.cc:70
StepCommand::~StepCommand
virtual ~StepCommand()
Definition: StepCommand.cc:38
refcount_ptr< Command >
UNITTESTS
#define UNITTESTS(class)
Helper for unit test case execution.
Definition: UnitTest.h:184
Command
A Command is a named function, executed by the CommandInterpreter.
Definition: Command.h:51
cmd
Definition: debugger_cmds.cc:1189
UNITTEST
#define UNITTEST(functionname)
Helper for unit test case execution.
Definition: UnitTest.h:217
StepCommand::StepCommand
StepCommand()
Constructs a StepCommand.
Definition: StepCommand.cc:32
UnitTest::Assert
static void Assert(const string &strFailMessage, bool condition)
Asserts that a boolean condition is correct.
Definition: UnitTest.cc:40
GXemul::SetRunState
void SetRunState(RunState newState)
Sets the RunState.
Definition: GXemul.cc:733
UI::ShowDebugMessage
virtual void ShowDebugMessage(const string &msg)=0
Shows a debug message.
StepCommand::Execute
virtual bool Execute(GXemul &gxemul, const vector< string > &arguments)
Executes the command on a given GXemul instance.
Definition: StepCommand.cc:43
StepCommand
A Command which sets the RunState to SingleStepping.
Definition: StepCommand.h:42
GXemul::GetRunState
RunState GetRunState() const
Gets the current RunState.
Definition: GXemul.cc:741
GXemul::GetUI
UI * GetUI()
Gets a pointer to the GXemul instance' active UI.
Definition: GXemul.cc:653
GXemul::Paused
@ Paused
Definition: GXemul.h:59
GXemul::SingleStepping
@ SingleStepping
Definition: GXemul.h:60
StepCommand.h
GXemul.h
StepCommand::GetLongDescription
virtual string GetLongDescription() const
Returns a long description/help message for the command.
Definition: StepCommand.cc:76

Generated on Tue Aug 25 2020 19:25:06 for GXemul by doxygen 1.8.18