1 |
# Purpose: FreeRIDE databus unit test |
# Purpose: FreeBASE databus unit test |
2 |
# |
# |
3 |
# $Id$ |
# $Id$ |
4 |
# |
# |
15 |
# |
# |
16 |
|
|
17 |
require 'rubyunit' |
require 'rubyunit' |
18 |
require 'freeride/databus' |
require 'freebase/databus' |
19 |
|
|
20 |
class Test_DataBus < TestCase |
class Test_DataBus < TestCase |
21 |
|
|
22 |
def test_1_subscribe |
def test_1_subscribe |
23 |
bus = FreeRIDE::DataBus.new |
bus = FreeBASE::DataBus.new |
24 |
parentNotified = slotNotified = false |
parentNotified = slotNotified = false |
25 |
bus["/"].subscribe do |event, slot| |
bus["/"].subscribe do |event, slot| |
26 |
if event == :notify_data_set |
if event == :notify_data_set |
54 |
end |
end |
55 |
|
|
56 |
def test_2_validate |
def test_2_validate |
57 |
bus = FreeRIDE::DataBus.new |
bus = FreeBASE::DataBus.new |
58 |
bus["/foo/bar/int"].validate_with("Does not implement to_i") { | value | value.respond_to? "to_i" } |
bus["/foo/bar/int"].validate_with("Does not implement to_i") { | value | value.respond_to? "to_i" } |
59 |
bus["/foo/bar/int"].data = 1 |
bus["/foo/bar/int"].data = 1 |
60 |
assert_equal(1, bus["/foo/bar/int"].data) |
assert_equal(1, bus["/foo/bar/int"].data) |
62 |
end |
end |
63 |
|
|
64 |
def test_3_slottype_data |
def test_3_slottype_data |
65 |
bus = FreeRIDE::DataBus.new |
bus = FreeBASE::DataBus.new |
66 |
slot = bus["slot"] |
slot = bus["slot"] |
67 |
slot.data = 1 |
slot.data = 1 |
68 |
assert(slot.is_data_slot?) |
assert(slot.is_data_slot?) |
83 |
end |
end |
84 |
|
|
85 |
def test_4_slottype_queue |
def test_4_slottype_queue |
86 |
bus = FreeRIDE::DataBus.new |
bus = FreeBASE::DataBus.new |
87 |
slot = bus["slot"] |
slot = bus["slot"] |
88 |
slot << 1 |
slot << 1 |
89 |
assert(slot.is_queue_slot?) |
assert(slot.is_queue_slot?) |
105 |
end |
end |
106 |
|
|
107 |
def test_5_slottype_stack |
def test_5_slottype_stack |
108 |
bus = FreeRIDE::DataBus.new |
bus = FreeBASE::DataBus.new |
109 |
slot = bus["slot"] |
slot = bus["slot"] |
110 |
slot.push 1 |
slot.push 1 |
111 |
assert(slot.is_stack_slot?) |
assert(slot.is_stack_slot?) |
128 |
end |
end |
129 |
|
|
130 |
def test_6_slottype_proc |
def test_6_slottype_proc |
131 |
bus = FreeRIDE::DataBus.new |
bus = FreeBASE::DataBus.new |
132 |
slot = bus["slot"] |
slot = bus["slot"] |
133 |
slot.set_proc { |param| assert_equals(4, param) } |
slot.set_proc { |param| assert_equals(4, param) } |
134 |
assert(slot.is_proc_slot?) |
assert(slot.is_proc_slot?) |
148 |
end |
end |
149 |
|
|
150 |
def test_7_slot_attributes |
def test_7_slot_attributes |
151 |
bus = FreeRIDE::DataBus.new |
bus = FreeBASE::DataBus.new |
152 |
slot = bus["test/slot"] |
slot = bus["test/slot"] |
153 |
slot.attr_test=1 |
slot.attr_test=1 |
154 |
slot.attr_test2=2 |
slot.attr_test2=2 |