minilab 1.0.0-mswin32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (128) hide show
  1. data/.document +2 -0
  2. data/CHANGES +2 -0
  3. data/LICENSE +19 -0
  4. data/README +107 -0
  5. data/Rakefile +145 -0
  6. data/config/environment.rb +15 -0
  7. data/config/objects.yml +22 -0
  8. data/lib/analog_io.rb +30 -0
  9. data/lib/digital_auxport_io.rb +49 -0
  10. data/lib/digital_configuration.rb +66 -0
  11. data/lib/digital_port_io.rb +68 -0
  12. data/lib/extension/extconf.rb +4 -0
  13. data/lib/extension/minilab_hardware.c +235 -0
  14. data/lib/extension/minilab_hardware.so +0 -0
  15. data/lib/library_translator.rb +48 -0
  16. data/lib/minilab.rb +149 -0
  17. data/lib/minilab_context.rb +39 -0
  18. data/lib/result_verifier.rb +14 -0
  19. data/test/integration/analog_input_output_test.rb +43 -0
  20. data/test/integration/connect_to_hardware_test.rb +13 -0
  21. data/test/integration/digital_input_output_test.rb +114 -0
  22. data/test/integration/integration_test.rb +53 -0
  23. data/test/integration/require_minilab_test.rb +9 -0
  24. data/test/system/analog_input.test +3 -0
  25. data/test/system/analog_output.test +37 -0
  26. data/test/system/digital_port_input.test +5 -0
  27. data/test/system/digital_port_output.test +39 -0
  28. data/test/system/digital_port_read_byte.test +26 -0
  29. data/test/system/digital_screw_terminals_input.test +2 -0
  30. data/test/system/digital_screw_terminals_output.test +11 -0
  31. data/test/system/minilab_driver.rb +85 -0
  32. data/test/test_helper.rb +11 -0
  33. data/test/unit/analog_io_test.rb +87 -0
  34. data/test/unit/digital_auxport_io_test.rb +114 -0
  35. data/test/unit/digital_configuration_test.rb +136 -0
  36. data/test/unit/digital_port_io_test.rb +117 -0
  37. data/test/unit/library_translator_test.rb +100 -0
  38. data/test/unit/minilab_context_test.rb +82 -0
  39. data/test/unit/minilab_hardware_test.rb +83 -0
  40. data/test/unit/minilab_test.rb +131 -0
  41. data/test/unit/result_verifier_test.rb +33 -0
  42. data/vendor/behaviors/lib/behaviors.rb +50 -0
  43. data/vendor/behaviors/tasks/behaviors_tasks.rake +140 -0
  44. data/vendor/behaviors/test/behaviors_tasks_test.rb +71 -0
  45. data/vendor/behaviors/test/behaviors_test.rb +50 -0
  46. data/vendor/behaviors/test/tasks_test/Rakefile +16 -0
  47. data/vendor/behaviors/test/tasks_test/doc/behaviors.html +55 -0
  48. data/vendor/behaviors/test/tasks_test/lib/user.rb +2 -0
  49. data/vendor/behaviors/test/tasks_test/test/user_test.rb +17 -0
  50. data/vendor/constructor/Rakefile +44 -0
  51. data/vendor/constructor/config/environment.rb +12 -0
  52. data/vendor/constructor/lib/constructor.rb +132 -0
  53. data/vendor/constructor/test/constructor_test.rb +366 -0
  54. data/vendor/constructor/test/helper.rb +3 -0
  55. data/vendor/diy/README +26 -0
  56. data/vendor/diy/Rakefile +18 -0
  57. data/vendor/diy/lib/constructor.rb +114 -0
  58. data/vendor/diy/lib/diy.rb +329 -0
  59. data/vendor/diy/proto/context.rb +117 -0
  60. data/vendor/diy/proto/context.yml +20 -0
  61. data/vendor/diy/test/diy_test.rb +370 -0
  62. data/vendor/diy/test/files/broken_construction.yml +7 -0
  63. data/vendor/diy/test/files/cat/cat.rb +4 -0
  64. data/vendor/diy/test/files/cat/extra_conflict.yml +5 -0
  65. data/vendor/diy/test/files/cat/heritage.rb +2 -0
  66. data/vendor/diy/test/files/cat/needs_input.yml +3 -0
  67. data/vendor/diy/test/files/cat/the_cat_lineage.rb +1 -0
  68. data/vendor/diy/test/files/dog/dog_model.rb +4 -0
  69. data/vendor/diy/test/files/dog/dog_presenter.rb +4 -0
  70. data/vendor/diy/test/files/dog/dog_view.rb +2 -0
  71. data/vendor/diy/test/files/dog/file_resolver.rb +2 -0
  72. data/vendor/diy/test/files/dog/other_thing.rb +2 -0
  73. data/vendor/diy/test/files/dog/simple.yml +11 -0
  74. data/vendor/diy/test/files/donkey/foo.rb +8 -0
  75. data/vendor/diy/test/files/donkey/foo/bar/qux.rb +7 -0
  76. data/vendor/diy/test/files/fud/objects.yml +13 -0
  77. data/vendor/diy/test/files/fud/toy.rb +15 -0
  78. data/vendor/diy/test/files/gnu/objects.yml +14 -0
  79. data/vendor/diy/test/files/gnu/thinger.rb +8 -0
  80. data/vendor/diy/test/files/goat/base.rb +8 -0
  81. data/vendor/diy/test/files/goat/can.rb +6 -0
  82. data/vendor/diy/test/files/goat/goat.rb +6 -0
  83. data/vendor/diy/test/files/goat/objects.yml +12 -0
  84. data/vendor/diy/test/files/goat/paper.rb +6 -0
  85. data/vendor/diy/test/files/goat/plane.rb +8 -0
  86. data/vendor/diy/test/files/goat/shirt.rb +6 -0
  87. data/vendor/diy/test/files/goat/wings.rb +8 -0
  88. data/vendor/diy/test/files/horse/holder_thing.rb +4 -0
  89. data/vendor/diy/test/files/horse/objects.yml +7 -0
  90. data/vendor/diy/test/files/yak/core_model.rb +4 -0
  91. data/vendor/diy/test/files/yak/core_presenter.rb +4 -0
  92. data/vendor/diy/test/files/yak/core_view.rb +1 -0
  93. data/vendor/diy/test/files/yak/data_source.rb +1 -0
  94. data/vendor/diy/test/files/yak/fringe_model.rb +4 -0
  95. data/vendor/diy/test/files/yak/fringe_presenter.rb +4 -0
  96. data/vendor/diy/test/files/yak/fringe_view.rb +1 -0
  97. data/vendor/diy/test/files/yak/my_objects.yml +21 -0
  98. data/vendor/diy/test/test_helper.rb +40 -0
  99. data/vendor/hardmock/CHANGES +8 -0
  100. data/vendor/hardmock/LICENSE +7 -0
  101. data/vendor/hardmock/README +48 -0
  102. data/vendor/hardmock/Rakefile +100 -0
  103. data/vendor/hardmock/TODO +7 -0
  104. data/vendor/hardmock/config/environment.rb +12 -0
  105. data/vendor/hardmock/homepage/demo.rb +21 -0
  106. data/vendor/hardmock/homepage/hardmock_sample.png +0 -0
  107. data/vendor/hardmock/homepage/index.html +65 -0
  108. data/vendor/hardmock/init.rb +3 -0
  109. data/vendor/hardmock/lib/hardmock.rb +634 -0
  110. data/vendor/hardmock/lib/method_cleanout.rb +14 -0
  111. data/vendor/hardmock/rcov.rake +18 -0
  112. data/vendor/hardmock/test/functional/assert_error_test.rb +52 -0
  113. data/vendor/hardmock/test/functional/auto_verify_test.rb +192 -0
  114. data/vendor/hardmock/test/functional/direct_mock_usage_test.rb +396 -0
  115. data/vendor/hardmock/test/functional/hardmock_test.rb +380 -0
  116. data/vendor/hardmock/test/test_helper.rb +23 -0
  117. data/vendor/hardmock/test/unit/expectation_builder_test.rb +18 -0
  118. data/vendor/hardmock/test/unit/expector_test.rb +56 -0
  119. data/vendor/hardmock/test/unit/method_cleanout_test.rb +35 -0
  120. data/vendor/hardmock/test/unit/mock_control_test.rb +172 -0
  121. data/vendor/hardmock/test/unit/mock_test.rb +273 -0
  122. data/vendor/hardmock/test/unit/simple_expectation_test.rb +345 -0
  123. data/vendor/hardmock/test/unit/trapper_test.rb +60 -0
  124. data/vendor/hardmock/test/unit/verify_error_test.rb +34 -0
  125. data/vendor/systir/systir.rb +403 -0
  126. data/vendor/systir/test/unit/ui/xml/testrunner.rb +192 -0
  127. data/vendor/systir/test/unit/ui/xml/xmltestrunner.xslt +109 -0
  128. metadata +235 -0
@@ -0,0 +1,11 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/../config/environment")
2
+
3
+ require 'test/unit'
4
+ require 'behaviors'
5
+ require 'hardmock'
6
+
7
+ $LOAD_PATH << File.join(APP_ROOT + '/test/integration')
8
+
9
+ class Test::Unit::TestCase
10
+ extend Behaviors
11
+ end
@@ -0,0 +1,87 @@
1
+ require File.expand_path(File.dirname(__FILE__)) + "/../test_helper"
2
+ require 'analog_io'
3
+
4
+ class AnalogIoTest < Test::Unit::TestCase
5
+ def setup
6
+ mox = create_mocks(:minilab_hardware, :result_verifier)
7
+ @target = AnalogIo.new(mox)
8
+ end
9
+
10
+ # helpers.
11
+ def expects_read_analog_and_result_verification(channel, value)
12
+ result = { :value => value }
13
+ @minilab_hardware.expects.read_analog(channel).returns(result)
14
+ @result_verifier.expects.verify(result, "read_analog")
15
+ end
16
+
17
+ def expects_write_analog_and_result_verification(channel, volts)
18
+ result = { :laptop => "heavy" }
19
+ @minilab_hardware.expects.write_analog(channel, volts).returns(result)
20
+ @result_verifier.expects.verify(result, "write_analog")
21
+ end
22
+
23
+ # Input tests
24
+ should "read analog data" do
25
+ expects_read_analog_and_result_verification(2, 5.7)
26
+ assert_equal 5.7, @target.read_analog(2)
27
+
28
+ expects_read_analog_and_result_verification(2, 0.0)
29
+ assert_equal 0.0, @target.read_analog(2)
30
+
31
+ expects_read_analog_and_result_verification(1, -5.2)
32
+ assert_equal -5.2, @target.read_analog(1)
33
+ end
34
+
35
+ should "raise an exception when analog input channel is out of range" do
36
+ # The minilab device has 8 analog inputs (when used in straight
37
+ # input mode, not differential). We expects that exceptions
38
+ # should be thrown for channels that are out of bounds.
39
+ # We expect that the class will access the minilab hardware
40
+ # if the channel *is* in range. Thus, we need to do this
41
+ # in order to make the mock happy...
42
+ 8.times do |channel|
43
+ expects_read_analog_and_result_verification(channel, 1.0)
44
+ end
45
+
46
+ assert_raise(RuntimeError) { @target.read_analog(-1) }
47
+ 0.upto(7) do |channel|
48
+ assert_nothing_raised { @target.read_analog(channel) }
49
+ end
50
+ assert_raise(RuntimeError) { @target.read_analog(8) }
51
+ end
52
+
53
+ # Output tests
54
+ should "write analog data" do
55
+ expects_write_analog_and_result_verification(1, 4.5)
56
+ @target.write_analog(1, 4.5)
57
+
58
+ expects_write_analog_and_result_verification(1, 2.5)
59
+ @target.write_analog(1, 2.5)
60
+
61
+ expects_write_analog_and_result_verification(0, 1.3)
62
+ @target.write_analog(0, 1.3)
63
+ end
64
+
65
+ should "raise an error when analog output voltage is out of range" do
66
+ expects_write_analog_and_result_verification(0, 0.0)
67
+ expects_write_analog_and_result_verification(0, 2.1)
68
+ expects_write_analog_and_result_verification(0, 5.0)
69
+
70
+ assert_raise(RuntimeError) { @target.write_analog(0, -0.1) }
71
+ assert_nothing_raised { @target.write_analog(0, 0.0) }
72
+ assert_nothing_raised { @target.write_analog(0, 2.1) }
73
+ assert_nothing_raised { @target.write_analog(0, 5.0) }
74
+ assert_raise(RuntimeError) { @target.write_analog(0, 5.1) }
75
+ end
76
+
77
+ should "raise an error when analog output channel is out of range" do
78
+ 2.times do |channel|
79
+ expects_write_analog_and_result_verification(channel, 0.0)
80
+ end
81
+
82
+ assert_raise(RuntimeError) { @target.write_analog(-1, 0.0) }
83
+ assert_nothing_raised { @target.write_analog(0, 0.0) }
84
+ assert_nothing_raised { @target.write_analog(1, 0.0) }
85
+ assert_raise(RuntimeError) { @target.write_analog(2, 0.0) }
86
+ end
87
+ end
@@ -0,0 +1,114 @@
1
+ require File.expand_path(File.dirname(__FILE__)) + "/../test_helper"
2
+ require 'digital_auxport_io'
3
+
4
+ class DigitalAuxportIoTest < Test::Unit::TestCase
5
+ include MinilabConstants
6
+ def setup
7
+ mox = create_mocks(:minilab_hardware, :result_verifier)
8
+ @target = DigitalAuxportIo.new(mox)
9
+
10
+ @good_pins = ['DIO0', 'DIO1', 'DIO2', 'DIO3']
11
+ @bad_pins = ['yourmom', 'bill', nil, false, 55, 'DIO4', -1, 38]
12
+ end
13
+
14
+ # Input tests
15
+ should "read digital data from the screw terminals" do
16
+ expect_read_auxport_and_verification('DIO1', 1)
17
+ assert_equal 1, @target.read_digital('DIO1')
18
+
19
+ expect_read_auxport_and_verification('DIO2', 0)
20
+ assert_equal 0, @target.read_digital('DIO2')
21
+ end
22
+
23
+ should "raise an exception when digital input pin is not valid" do
24
+ make_sure_bad_pins_blow_up
25
+
26
+ @good_pins.each do |pin|
27
+ expect_read_auxport_and_verification(pin, 1)
28
+ assert_nothing_raised { @target.read_digital(pin) }
29
+ end
30
+ end
31
+
32
+ # Output tests
33
+ should "write digital data to the screw terminals" do
34
+ expect_write_auxport_and_verification('DIO1', 1)
35
+ @target.write_digital('DIO1', 1)
36
+
37
+ expect_write_auxport_and_verification('DIO1', 0)
38
+ @target.write_digital('DIO1', 0)
39
+
40
+ expect_write_auxport_and_verification('DIO3', 1)
41
+ @target.write_digital('DIO3', 1)
42
+ end
43
+
44
+ should "write 1 to a digital output when the commanded value is anything not 0" do
45
+ expect_write_auxport_and_verification('DIO2', 1)
46
+ @target.write_digital('DIO2', 173)
47
+
48
+ expect_write_auxport_and_verification('DIO2', 1)
49
+ @target.write_digital('DIO2', 2902)
50
+ end
51
+
52
+ should "raise an exception if someone tries to command a negative value" do
53
+ assert_raise(RuntimeError) { @target.write_digital('DIO2', -10) }
54
+ assert_raise(RuntimeError) { @target.write_digital('DIO2', -80) }
55
+ end
56
+
57
+ should "raise an exception when digital output pin is out of range" do
58
+ make_sure_bad_pins_blow_up
59
+
60
+ @good_pins.each do |pin|
61
+ expect_write_auxport_and_verification(pin, 1)
62
+ assert_nothing_raised { @target.write_digital(pin, 1) }
63
+ end
64
+ end
65
+
66
+ should "accept case-insensitive DIO strings as pins" do
67
+ expect_write_auxport_and_verification('dio1', 1)
68
+ @target.write_digital('dio1', 1)
69
+
70
+ expect_write_auxport_and_verification('dIo2', 1)
71
+ @target.write_digital('dIo2', 1)
72
+
73
+ expect_read_auxport_and_verification('DiO0', 0)
74
+ @target.read_digital('DiO0')
75
+
76
+ expect_read_auxport_and_verification('diO3', 0)
77
+ @target.read_digital('diO3')
78
+ end
79
+
80
+ private
81
+ def get_pin_number(pin)
82
+ pin.match(/(\d)$/)[0].to_i
83
+ end
84
+
85
+ def expect_read_auxport_and_verification(pin, value)
86
+ pin = get_pin_number(pin)
87
+ configuration = { :direction => DIGITALIN, :pin => pin }
88
+ result1 = { :dell => 4, :keyboard => 7 }
89
+ @minilab_hardware.expects.configure_auxport(configuration).returns(result1)
90
+ @result_verifier.expects.verify(result1, "configure_auxport_in")
91
+
92
+ result2 = { :value => value }
93
+ @minilab_hardware.expects.read_auxport(pin).returns(result2)
94
+ @result_verifier.expects.verify(result2, "read_auxport")
95
+ end
96
+
97
+ def expect_write_auxport_and_verification(pin, value)
98
+ pin = get_pin_number(pin)
99
+ configuration = { :direction => DIGITALOUT, :pin => pin }
100
+ result1 = { :stand => 2 }
101
+ @minilab_hardware.expects.configure_auxport(configuration).returns(result1)
102
+ @result_verifier.expects.verify(result1, "configure_auxport_out")
103
+
104
+ result2 = { :card => "numerous" }
105
+ @minilab_hardware.expects.write_auxport(pin, value).returns(result2)
106
+ @result_verifier.expects.verify(result2, "write_auxport")
107
+ end
108
+
109
+ def make_sure_bad_pins_blow_up
110
+ @bad_pins.each do |pin|
111
+ assert_raise(RuntimeError) { @target.read_digital(pin) }
112
+ end
113
+ end
114
+ end
@@ -0,0 +1,136 @@
1
+ require File.expand_path(File.dirname(__FILE__)) + "/../test_helper"
2
+ require 'digital_configuration'
3
+ require 'extension/minilab_hardware'
4
+
5
+ class DigitalConfigurationTest < Test::Unit::TestCase
6
+ include MinilabConstants
7
+
8
+ def setup
9
+ mox = create_mocks(:minilab_hardware, :result_verifier)
10
+ @target = DigitalConfiguration.new(mox)
11
+
12
+ @good_ports = [:porta, :portb, :portcl, :portch]
13
+ @port_to_library_port_mapping = {
14
+ :porta => FIRSTPORTA,
15
+ :portb => FIRSTPORTB,
16
+ :portcl => FIRSTPORTCL,
17
+ :portch => FIRSTPORTCH
18
+ }
19
+
20
+ @bad_ports = [nil, :portd, :portttt, "ibm"]
21
+ end
22
+
23
+ def expect_configure_input_and_verification
24
+ result = { :hey => "you" }
25
+
26
+ @good_ports.each do |port|
27
+ expected_configuration = { :direction => DIGITALIN, :port => @port_to_library_port_mapping[port] }
28
+ @minilab_hardware.expects.configure_port(expected_configuration).returns(result)
29
+ @result_verifier.expects.verify(result)
30
+ end
31
+ end
32
+
33
+ def expect_configure_output_and_verification
34
+ result = { :woo => "boo" }
35
+
36
+ @good_ports.each do |port|
37
+ expected_configuration = { :direction => DIGITALOUT, :port => @port_to_library_port_mapping[port] }
38
+ @minilab_hardware.expects.configure_port(expected_configuration).returns(result)
39
+ @result_verifier.expects.verify(result)
40
+ end
41
+ end
42
+
43
+ def check_error_for_all_bad_ports(method_to_test)
44
+ @bad_ports.each do |bad_port|
45
+ assert_raise(RuntimeError) { @target.send(method_to_test, bad_port) }
46
+ end
47
+ end
48
+
49
+ should "know the valid ports" do
50
+ expected_ports = [:porta, :portb, :portcl, :portch]
51
+ actual_ports = @target.get_valid_ports
52
+
53
+ assert_equal expected_ports.size, actual_ports.size
54
+ expected_ports.each_with_index do |port, index|
55
+ assert_equal port, actual_ports[index]
56
+ end
57
+ end
58
+
59
+ should "configure a port for input" do
60
+ expect_configure_input_and_verification
61
+
62
+ @good_ports.each do |port|
63
+ assert_equal true, @target.configure_port_for_input(port)
64
+ end
65
+ end
66
+
67
+ should "configure a port for output" do
68
+ expect_configure_output_and_verification
69
+
70
+ @good_ports.each do |port|
71
+ assert_equal true, @target.configure_port_for_output(port)
72
+ end
73
+ end
74
+
75
+ should "raise an error for an invalid input port" do
76
+ check_error_for_all_bad_ports(:configure_port_for_input)
77
+ end
78
+
79
+ should "raise an error for an invalid output port" do
80
+ check_error_for_all_bad_ports(:configure_port_for_output)
81
+ end
82
+
83
+ should "return false when each of the ports has not been configured for input yet and a client asks if it has" do
84
+ @good_ports.each do |port|
85
+ assert_equal false, @target.is_port_configured_for_input?(port)
86
+ end
87
+ end
88
+
89
+ should "return false when each of the ports has not been configured for output yet and a client asks if it has" do
90
+ @good_ports.each do |port|
91
+ assert_equal false, @target.is_port_configured_for_output?(port)
92
+ end
93
+ end
94
+
95
+ should "return the input configuration status of a port when asked" do
96
+ result = {:a => "b"}
97
+ expected_configuration = { :direction => DIGITALIN, :port => @port_to_library_port_mapping[:porta] }
98
+ @minilab_hardware.expects.configure_port(expected_configuration).returns(result)
99
+ @result_verifier.expects.verify(result)
100
+
101
+ @target.configure_port_for_input(:porta)
102
+ assert_equal true, @target.is_port_configured_for_input?(:porta)
103
+
104
+ expected_configuration = { :direction => DIGITALIN, :port => @port_to_library_port_mapping[:portch] }
105
+ @minilab_hardware.expects.configure_port(expected_configuration).returns(result)
106
+ @result_verifier.expects.verify(result)
107
+
108
+ @target.configure_port_for_input(:portch)
109
+ assert_equal true, @target.is_port_configured_for_input?(:portch)
110
+ end
111
+
112
+ should "return the output configuration status of a port when asked" do
113
+ result = {:keyboard => "mouse"}
114
+ expected_configuration = { :direction => DIGITALOUT, :port => @port_to_library_port_mapping[:portb] }
115
+ @minilab_hardware.expects.configure_port(expected_configuration).returns(result)
116
+ @result_verifier.expects.verify(result)
117
+
118
+ @target.configure_port_for_output(:portb)
119
+ assert_equal true, @target.is_port_configured_for_output?(:portb)
120
+
121
+ expected_configuration = { :direction => DIGITALOUT, :port => @port_to_library_port_mapping[:portcl] }
122
+ @minilab_hardware.expects.configure_port(expected_configuration).returns(result)
123
+ @result_verifier.expects.verify(result)
124
+
125
+ @target.configure_port_for_output(:portcl)
126
+ assert_equal true, @target.is_port_configured_for_output?(:portcl)
127
+ end
128
+
129
+ should "raise an error if you pass is_port_configured_for_input? an invalid port" do
130
+ check_error_for_all_bad_ports(:is_port_configured_for_input?)
131
+ end
132
+
133
+ should "raise an error if you pass is_port_configured_for_output? an invalid port" do
134
+ check_error_for_all_bad_ports(:is_port_configured_for_output?)
135
+ end
136
+ end
@@ -0,0 +1,117 @@
1
+ require File.expand_path(File.dirname(__FILE__)) + "/../test_helper"
2
+ require 'digital_port_io'
3
+
4
+ class DigitalPortIoTest < Test::Unit::TestCase
5
+
6
+ def setup
7
+ @good_ports = [:porta, :portb, :portcl, :portch]
8
+
9
+ mox = create_mocks(:minilab_hardware, :result_verifier,
10
+ :digital_configuration, :library_translator)
11
+ @target = DigitalPortIo.new(mox)
12
+ end
13
+
14
+ # configuration tests
15
+ should "get the list of valid ports from the configuration object" do
16
+ ports = [:porta, "signal", 1]
17
+ @digital_configuration.expects.get_valid_ports().returns(ports)
18
+
19
+ assert_same ports, @target.get_valid_ports
20
+ end
21
+
22
+ should "use the digital configuration object to configure a port for input" do
23
+ @digital_configuration.expects.configure_port_for_input(:porta).returns(true)
24
+ @target.configure_input_port(:porta)
25
+
26
+ @digital_configuration.expects.configure_port_for_input(:portch).returns(true)
27
+ assert_equal true, @target.configure_input_port(:portch)
28
+ end
29
+
30
+ should "use the digital configuration object to configure a port for output" do
31
+ @digital_configuration.expects.configure_port_for_output(:portb).returns(true)
32
+ assert @target.configure_output_port(:portb)
33
+
34
+ @digital_configuration.expects.configure_port_for_output(:portcl).returns(true)
35
+ assert_equal true, @target.configure_output_port(:portcl)
36
+ end
37
+
38
+ # read tests
39
+ should "read digital input from the digital pins" do
40
+ pin = 1
41
+
42
+ @library_translator.expects.get_port_for_pin(pin).returns(:porta)
43
+ @digital_configuration.expects.is_port_configured_for_input?(:porta).returns(true)
44
+ @library_translator.expects.get_library_pin_number(pin).returns(21)
45
+
46
+ result = { :value => "woohoo" }
47
+ @minilab_hardware.expects.read_digital_pin(21).returns(result)
48
+ @result_verifier.expects.verify(result)
49
+
50
+ assert_equal "woohoo", @target.read_digital(pin)
51
+ end
52
+
53
+ should "read digital input from a digital port" do
54
+ result = { :value => 0x34 }
55
+ @digital_configuration.expects.get_valid_ports.returns(@good_ports)
56
+ @digital_configuration.expects.is_port_configured_for_input?(:portb).returns(true)
57
+ @library_translator.expects.get_library_port(:portb).returns("some port")
58
+ @minilab_hardware.expects.read_port("some port").returns(result)
59
+ @result_verifier.expects.verify(result)
60
+
61
+ assert_equal 0x34, @target.read_port(:portb)
62
+ end
63
+
64
+ should "raise an error when the configuration object says the port isn't configured for input when reading a pin" do
65
+ @library_translator.expects.get_port_for_pin(20).returns(:portc)
66
+ @digital_configuration.expects.is_port_configured_for_input?(:portc).returns(false)
67
+
68
+ assert_raise (RuntimeError) { @target.read_digital(20) }
69
+ end
70
+
71
+ should "raise an error when the configuration objects says the port isn't configured for input when reading a port" do
72
+ @digital_configuration.expects.get_valid_ports.returns(@good_ports)
73
+ @digital_configuration.expects.is_port_configured_for_input?(:porta).returns(false)
74
+
75
+ assert_raise (RuntimeError) { @target.read_port(:porta) }
76
+ end
77
+
78
+ should "raise an error when the port passed for read_port does not exist" do
79
+ @good_ports.each do |port|
80
+ result = { :value => 0x34 }
81
+ @digital_configuration.expects.get_valid_ports.returns(@good_ports)
82
+ @digital_configuration.expects.is_port_configured_for_input?(port).returns(true)
83
+ @library_translator.expects.get_library_port(port).returns("some port")
84
+ @minilab_hardware.expects.read_port("some port").returns(result)
85
+ @result_verifier.expects.verify(result)
86
+
87
+ assert_equal 0x34, @target.read_port(port)
88
+ end
89
+
90
+ [nil, 0, false, :laptop, :portd].each do |bad_port|
91
+ @digital_configuration.expects.get_valid_ports.returns(@good_ports)
92
+ assert_raise(RuntimeError) { @target.read_port(bad_port) }
93
+ end
94
+ end
95
+
96
+ # output tests
97
+ should "write digital output to a digital pin" do
98
+ pin = 2
99
+ value = 0
100
+
101
+ @library_translator.expects.get_port_for_pin(pin).returns(:portcl)
102
+ @digital_configuration.expects.is_port_configured_for_output?(:portcl).returns(true)
103
+ @library_translator.expects.get_library_pin_number(pin).returns(7)
104
+ result = { :value => "ibm" }
105
+ @minilab_hardware.expects.write_digital_pin(7, value).returns(result)
106
+ @result_verifier.expects.verify(result)
107
+
108
+ assert_equal true, @target.write_digital(pin, value)
109
+ end
110
+
111
+ should "raise an exception when the configuration object says the port is not configured for output (for write_digital)" do
112
+ @library_translator.expects.get_port_for_pin(1).returns(:portd)
113
+ @digital_configuration.expects.is_port_configured_for_output?(:portd).returns(false)
114
+
115
+ assert_raise (RuntimeError) { @target.write_digital(1, 1) }
116
+ end
117
+ end