Skip to content

Commit

Permalink
refactor monitor operations into separate tests because they are gett…
Browse files Browse the repository at this point in the history
…ing large.
  • Loading branch information
mpd committed Apr 24, 2010
1 parent fd9c814 commit fffc1f1
Show file tree
Hide file tree
Showing 3 changed files with 175 additions and 167 deletions.
11 changes: 7 additions & 4 deletions lib/antiquitas/monitor/breakpoint.rb
@@ -1,11 +1,14 @@
module Antiquitas
class Monitor
Breakpoint = Struct.new("AntiquitasMonitorBreakpoint", :address, :condition, :enabled) do
class Breakpoint
include Comparable

def initialize(*args)
super *args
self.enabled = true unless args.length == 3 # i.e. enabled value passed-in
attr_accessor :address, :condition, :enabled

def initialize(address = nil, condition = nil, enabled = true)
self.address = address
self.condition = condition
self.enabled = enabled
end

def <=>(other)
Expand Down
163 changes: 0 additions & 163 deletions test/monitor/monitor_test.rb
Expand Up @@ -366,168 +366,5 @@ class MonitorTest < Test::Unit::TestCase
end
end
end

context "operations" do
context "#breakpoint" do
context "no address" do
should "print out the breakpoints, sorted by address" do
bp = Antiquitas::Monitor::Breakpoint.new(0x0080)
bp2 = Antiquitas::Monitor::Breakpoint.new(0x0040)
mock(@monitor).puts(bp)
mock(@monitor).puts(bp2)
@monitor.breakpoints << bp
@monitor.breakpoints << bp2
@monitor.breakpoint
end
end

context "with address" do
setup do
@address = 0x69
end

context "no current breakpoint with address" do
should "create a new breakpoint with the address and add it to the list" do
@monitor.breakpoint(:address => @address)
assert_equal 1, @monitor.breakpoints.length
assert_equal @address, @monitor.breakpoints.first.address
end
end

context "current breakpoint with address, no condition" do
setup do
@monitor.breakpoint(:address => @address)
end

context "breakpoint enabled" do
should "disable the breakpoint, but not remove it" do
assert_equal true, @monitor.breakpoints.first.enabled
@monitor.breakpoint(:address => @address)
assert_equal 1, @monitor.breakpoints.length
assert_equal @address, @monitor.breakpoints.first.address
assert !@monitor.breakpoints.first.enabled
end
end

context "breakpoint disabled" do
setup do
@monitor.breakpoints.first.enabled = false
end

should "enable the breakpoint" do
@monitor.breakpoint(:address => @address)
assert_equal 1, @monitor.breakpoints.length
assert_equal @address, @monitor.breakpoints.first.address
assert @monitor.breakpoints.first.enabled
end
end
end

context "current breakpoint with address and condition" do
setup do
@monitor.breakpoint(:address => @address, :condition => "@flag[:Z] == 1")
end

context "breakpoint enabled" do
should "disable the breakpoint, but not remove it" do
assert_equal true, @monitor.breakpoints.first.enabled
@monitor.breakpoint(:address => @address)
assert_equal 1, @monitor.breakpoints.length
assert_equal @address, @monitor.breakpoints.first.address
assert !@monitor.breakpoints.first.enabled
end
end

context "breakpoint disabled" do
setup do
@monitor.breakpoints.first.enabled = false
end

should "enable the breakpoint" do
@monitor.breakpoint(:address => @address)
assert_equal 1, @monitor.breakpoints.length
assert_equal @address, @monitor.breakpoints.first.address
assert @monitor.breakpoints.first.enabled
end
end

end
end

context "with address and condition" do
setup do
@address = 0x69
@condition = "@foo = bar"
end

context "no current breakpoint with address" do
should "create a new breakpoint with the address and condition and add it to the list" do
@monitor.breakpoint(:address => @address, :condition => @condition)
assert_equal 1, @monitor.breakpoints.length
assert_equal @address, @monitor.breakpoints.first.address
assert_equal @condition, @monitor.breakpoints.first.condition
end
end

context "current breakpoint with address, no condition" do
setup do
@monitor.breakpoint(:address => @address)
@monitor.breakpoint(:address => @address, :condition => @condition)
end

should "set the condition on the breakpoint to the passed value" do
assert_equal @condition, @monitor.breakpoints.first.condition
end

should "not change the breakpoint's enabled status" do
assert @monitor.breakpoints.first.enabled
end
end

context "current breakpoint with address and different condition" do
setup do
@monitor.breakpoint(:address => @address, :condition => "foo == bar")
@monitor.breakpoint(:address => @address, :condition => @condition)
end

should "set the condition on the breakpoint to the passed value" do
assert_equal @condition, @monitor.breakpoints.first.condition
end

should "not change the breakpoint's enabled status" do
assert @monitor.breakpoints.first.enabled
end
end

context "current breakpoint with address and same condition" do
setup do
@monitor.breakpoint(:address => @address, :condition => @condition)
end

context "breakpoint enabled" do
setup do
@monitor.breakpoints.first.enabled = true
@monitor.breakpoint(:address => @address, :condition => @condition)
end

should "disable the breakpoint" do
assert !@monitor.breakpoints.first.enabled
end
end

context "breakpoint disabled" do
setup do
@monitor.breakpoints.first.enabled = false
@monitor.breakpoint(:address => @address, :condition => @condition)
end

should "enable the breakpoint" do
assert @monitor.breakpoints.first.enabled
end
end
end
end
end
end
end
end
168 changes: 168 additions & 0 deletions test/monitor/operations/breakpoint_test.rb
@@ -0,0 +1,168 @@
require File.join(File.dirname(__FILE__), '..', '..', 'test_helper')

class MonitorBreakpointOperationTest < Test::Unit::TestCase
context "#breakpoint" do
setup do
@monitor = Antiquitas::Monitor.new
end

context "no address" do
should "print out the breakpoints, sorted by address" do
bp = Antiquitas::Monitor::Breakpoint.new(0x0080)
bp2 = Antiquitas::Monitor::Breakpoint.new(0x0040)
mock(@monitor).puts(bp)
mock(@monitor).puts(bp2)
@monitor.breakpoints << bp
@monitor.breakpoints << bp2
@monitor.breakpoint
end
end

context "with address" do
setup do
@address = 0x69
end

context "no current breakpoint with address" do
should "create a new breakpoint with the address and add it to the list" do
@monitor.breakpoint(:address => @address)
assert_equal 1, @monitor.breakpoints.length
assert_equal @address, @monitor.breakpoints.first.address
end
end

context "current breakpoint with address, no condition" do
setup do
@monitor.breakpoint(:address => @address)
end

context "breakpoint enabled" do
should "disable the breakpoint, but not remove it" do
assert_equal true, @monitor.breakpoints.first.enabled
@monitor.breakpoint(:address => @address)
assert_equal 1, @monitor.breakpoints.length
assert_equal @address, @monitor.breakpoints.first.address
assert !@monitor.breakpoints.first.enabled
end
end

context "breakpoint disabled" do
setup do
@monitor.breakpoints.first.enabled = false
end

should "enable the breakpoint" do
@monitor.breakpoint(:address => @address)
assert_equal 1, @monitor.breakpoints.length
assert_equal @address, @monitor.breakpoints.first.address
assert @monitor.breakpoints.first.enabled
end
end
end

context "current breakpoint with address and condition" do
setup do
@monitor.breakpoint(:address => @address, :condition => "@flag[:Z] == 1")
end

context "breakpoint enabled" do
should "disable the breakpoint, but not remove it" do
assert_equal true, @monitor.breakpoints.first.enabled
@monitor.breakpoint(:address => @address)
assert_equal 1, @monitor.breakpoints.length
assert_equal @address, @monitor.breakpoints.first.address
assert !@monitor.breakpoints.first.enabled
end
end

context "breakpoint disabled" do
setup do
@monitor.breakpoints.first.enabled = false
end

should "enable the breakpoint" do
@monitor.breakpoint(:address => @address)
assert_equal 1, @monitor.breakpoints.length
assert_equal @address, @monitor.breakpoints.first.address
assert @monitor.breakpoints.first.enabled
end
end

end
end

context "with address and condition" do
setup do
@address = 0x69
@condition = "@foo = bar"
end

context "no current breakpoint with address" do
should "create a new breakpoint with the address and condition and add it to the list" do
@monitor.breakpoint(:address => @address, :condition => @condition)
assert_equal 1, @monitor.breakpoints.length
assert_equal @address, @monitor.breakpoints.first.address
assert_equal @condition, @monitor.breakpoints.first.condition
end
end

context "current breakpoint with address, no condition" do
setup do
@monitor.breakpoint(:address => @address)
@monitor.breakpoint(:address => @address, :condition => @condition)
end

should "set the condition on the breakpoint to the passed value" do
assert_equal @condition, @monitor.breakpoints.first.condition
end

should "not change the breakpoint's enabled status" do
assert @monitor.breakpoints.first.enabled
end
end

context "current breakpoint with address and different condition" do
setup do
@monitor.breakpoint(:address => @address, :condition => "foo == bar")
@monitor.breakpoint(:address => @address, :condition => @condition)
end

should "set the condition on the breakpoint to the passed value" do
assert_equal @condition, @monitor.breakpoints.first.condition
end

should "not change the breakpoint's enabled status" do
assert @monitor.breakpoints.first.enabled
end
end

context "current breakpoint with address and same condition" do
setup do
@monitor.breakpoint(:address => @address, :condition => @condition)
end

context "breakpoint enabled" do
setup do
@monitor.breakpoints.first.enabled = true
@monitor.breakpoint(:address => @address, :condition => @condition)
end

should "disable the breakpoint" do
assert !@monitor.breakpoints.first.enabled
end
end

context "breakpoint disabled" do
setup do
@monitor.breakpoints.first.enabled = false
@monitor.breakpoint(:address => @address, :condition => @condition)
end

should "enable the breakpoint" do
assert @monitor.breakpoints.first.enabled
end
end
end
end
end
end

0 comments on commit fffc1f1

Please sign in to comment.