From 3e38a4910e7a3c17c07f47c4f1b9d556a4a951fd Mon Sep 17 00:00:00 2001 From: Dimid Duchovny Date: Wed, 24 Jan 2018 12:12:07 +0200 Subject: test: add a more complex test for add_child callback Signed-off-by: Dimid Duchovny --- test/test_msgthr.rb | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/test/test_msgthr.rb b/test/test_msgthr.rb index 0f31762..62b92d9 100644 --- a/test/test_msgthr.rb +++ b/test/test_msgthr.rb @@ -102,4 +102,46 @@ EOF EOF assert_equal exp, out end + + def test_add_child_callback + thr = Msgthr.new + threads = {} + [1, 1.1, 1.2, 2, 2.1, 2.11].each{ |id| threads[id] = [id]} + my_add = lambda do |id, refs, msg| + thr.add(id, refs, msg) do |parent, child| + threads[child.mid] = threads[parent.mid] + end + end + # Create the following structure + # 1 + # \ + # | 1.1 + # \ + # 1.2 + # 2 + # \ + # 2.1 + # \ + # 2.1.1 + my_add.call(1, nil, '1') + my_add.call(11, [1], '1.1') + my_add.call(12, [1], '1.2') + my_add.call(2, nil, '2') + my_add.call(21, [2], '2.1') + my_add.call(211, [21], '2.1.1') + + thr.thread! + thr.rootset.each do |cnt| + threads[cnt.mid][0] = cnt.msg + end + + assert_equal threads[1], threads[11] + assert_equal threads[1], threads[12] + assert_equal threads[2], threads[21] + assert_equal threads[2], threads[211] + assert_equal threads[21], threads[211] + assert_equal threads[1][0], '1' + assert_equal threads[2][0], '2' + end + end -- cgit v1.2.3-24-ge0c7