Class: CallbacksTest
- Inherits:
-
Test::Unit::TestCase
- Object
- Test::Unit::TestCase
- CallbacksTest
- Defined in:
- lib/vendor/xmpp4r/test/tc_callbacks.rb
Instance Method Summary collapse
- #test_callbacklist1 ⇒ Object
- #test_callbacklist2 ⇒ Object
- #test_callbacklist4 ⇒ Object
- #test_callbacklist5 ⇒ Object
- #test_callbacklist6 ⇒ Object
- #test_callbacklist7 ⇒ Object
- #test_nested ⇒ Object
- #test_test1 ⇒ Object
Instance Method Details
#test_callbacklist1 ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/vendor/xmpp4r/test/tc_callbacks.rb', line 21 def test_callbacklist1 cbl = CallbackList.new called1 = false called2 = false called3 = false called4 = false cbl.add(5, "ref1") { called1 = true ; true } cbl.add(7, "ref1") { |e| called2 = true ; false} cbl.add(9, "ref1") { called3 = true ;false } cbl.add(11, "ref1") { called4 = true ; false } o = "aaaa" assert(cbl.process(o)) assert(called1) assert(called2) assert(called3) assert(called4) end |
#test_callbacklist2 ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/vendor/xmpp4r/test/tc_callbacks.rb', line 39 def test_callbacklist2 cbl = CallbackList.new assert(0, cbl.length) cbl.add(5, "ref1") { called1 = true } assert(1, cbl.length) cbl.add(7, "ref2") { |e| called2 = true ; e.consume } assert(2, cbl.length) cbl.delete("ref2") assert(1, cbl.length) cbl.add(9, "ref3") { called3 = true } assert(2, cbl.length) end |
#test_callbacklist4 ⇒ Object
52 53 54 55 56 57 58 |
# File 'lib/vendor/xmpp4r/test/tc_callbacks.rb', line 52 def test_callbacklist4 cbl = CallbackList.new cbl.add(5, "ref1") { false } cbl.add(7, "ref1") { false } o = "o" assert(!cbl.process(o)) end |
#test_callbacklist5 ⇒ Object
60 61 62 63 64 65 66 |
# File 'lib/vendor/xmpp4r/test/tc_callbacks.rb', line 60 def test_callbacklist5 cbl = CallbackList.new cbl.add(5, "ref1") { true } cbl.add(7, "ref1") { false } o = "o" assert(cbl.process(o)) end |
#test_callbacklist6 ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/vendor/xmpp4r/test/tc_callbacks.rb', line 68 def test_callbacklist6 cbl = CallbackList.new ok = false c = 'a' d = 'b' cbl.add(5, "ref1") { |a, b| if a == 'a' and b == 'b' ok = true end false } assert(!cbl.process(c, d)) assert(ok) end |
#test_callbacklist7 ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/vendor/xmpp4r/test/tc_callbacks.rb', line 83 def test_callbacklist7 cbl = CallbackList.new called1 = false called2 = false called3 = false called4 = false cbl.add(3, "ref1") { called4 = true ; true } cbl.add(5, "ref1") { called1 = true ; true } cbl.add(7, "ref1") { called2 = true ; 'a'} cbl.add(9, "ref1") { called3 = true ;1 } o = "aaaa" assert(cbl.process(o)) assert(called1) assert(called2) assert(called3) assert(!called4) end |
#test_nested ⇒ Object
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 |
# File 'lib/vendor/xmpp4r/test/tc_callbacks.rb', line 101 def test_nested cbl = CallbackList.new called_outer = 0 called_inner = 0 cbl.add(100, nil) { called_outer += 1 if called_outer == 1 cbl.add(200, nil) { called_inner += 1 } end } assert_equal(0, called_inner) assert_equal(0, called_outer) cbl.process assert_equal(0, called_inner) assert_equal(1, called_outer) cbl.process assert_equal(1, called_inner) assert_equal(2, called_outer) end |
#test_test1 ⇒ Object
10 11 12 13 14 15 16 17 18 19 |
# File 'lib/vendor/xmpp4r/test/tc_callbacks.rb', line 10 def test_test1 called = 0 cb = Callback.new(5, "toto", Proc.new { called += 1 }) assert_equal(5, cb.priority) assert_equal("toto", cb.ref) cb.block.call assert_equal(1, called) cb.block.call assert_equal(2, called) end |