ruby-libvirt-catphish 0.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,100 @@
1
+ #!/usr/bin/ruby
2
+
3
+ # Test the interface methods the bindings support
4
+
5
+ $: << File.dirname(__FILE__)
6
+
7
+ require 'libvirt'
8
+ require 'test_utils.rb'
9
+
10
+ set_test_object("interface")
11
+
12
+ conn = Libvirt::open("qemu:///system")
13
+
14
+ # test setup
15
+ begin
16
+ `rm -f /etc/sysconfig/network-scripts/ifcfg-rb-libvirt-test`
17
+ `brctl delbr rb-libvirt-test >& /dev/null`
18
+ rescue
19
+ end
20
+
21
+ # TESTGROUP: iface.undefine
22
+ newiface = conn.define_interface_xml($new_interface_xml)
23
+
24
+ expect_too_many_args(newiface, "undefine", 1)
25
+
26
+ expect_success(newiface, "no args", "undefine")
27
+
28
+ # TESTGROUP: iface.create
29
+ newiface = conn.define_interface_xml($new_interface_xml)
30
+
31
+ expect_too_many_args(newiface, "create", 1, 2)
32
+ expect_invalid_arg_type(newiface, "create", 'foo')
33
+
34
+ #expect_success(newiface, "no args", "create")
35
+
36
+ #expect_fail(newiface, Libvirt::Error, "on already running interface", "create")
37
+
38
+ #newiface.destroy
39
+ newiface.undefine
40
+
41
+ # TESTGROUP: iface.destroy
42
+ newiface = conn.define_interface_xml($new_interface_xml)
43
+
44
+ expect_too_many_args(newiface, "destroy", 1, 2)
45
+ expect_invalid_arg_type(newiface, "destroy", 'foo')
46
+
47
+ #expect_success(newiface, "no args", "destroy")
48
+
49
+ newiface.undefine
50
+
51
+ # TESTGROUP: iface.active?
52
+ newiface = conn.define_interface_xml($new_interface_xml)
53
+
54
+ expect_too_many_args(newiface, "active?", 1)
55
+
56
+ expect_success(newiface, "no args", "active?") {|x| x == false}
57
+
58
+ #newiface.create
59
+ #expect_success(newiface, "no args", "active?") {|x| x == true}
60
+
61
+ #newiface.destroy
62
+ newiface.undefine
63
+
64
+ # TESTGROUP: iface.name
65
+ newiface = conn.define_interface_xml($new_interface_xml)
66
+
67
+ expect_too_many_args(newiface, "name", 1)
68
+
69
+ expect_success(newiface, "no args", "name") {|x| x == "rb-libvirt-test"}
70
+
71
+ newiface.undefine
72
+
73
+ # TESTGROUP: iface.mac
74
+ testiface = find_valid_iface(conn)
75
+ if not testiface.nil?
76
+ expect_too_many_args(testiface, "mac", 1)
77
+
78
+ expect_success(testiface, "no args", "mac")
79
+ end
80
+
81
+ # TESTGROUP: iface.xml_desc
82
+ testiface = find_valid_iface(conn)
83
+ if not testiface.nil?
84
+ expect_too_many_args(testiface, "xml_desc", 1, 2)
85
+ expect_invalid_arg_type(testiface, "xml_desc", "foo")
86
+ expect_success(testiface, "no args", "xml_desc")
87
+ end
88
+
89
+ # TESTGROUP: iface.free
90
+ newiface = conn.define_interface_xml($new_interface_xml)
91
+ newiface.undefine
92
+ expect_too_many_args(newiface, "free", 1)
93
+
94
+ expect_success(newiface, "no args", "free")
95
+
96
+ # END TESTS
97
+
98
+ conn.close
99
+
100
+ finish_tests
@@ -0,0 +1,175 @@
1
+ #!/usr/bin/ruby
2
+
3
+ # Test the network methods the bindings support
4
+
5
+ $: << File.dirname(__FILE__)
6
+
7
+ require 'libvirt'
8
+ require 'test_utils.rb'
9
+
10
+ set_test_object("network")
11
+
12
+ conn = Libvirt::open("qemu:///system")
13
+
14
+ cleanup_test_network(conn)
15
+
16
+ # TESTGROUP: net.undefine
17
+ newnet = conn.define_network_xml($new_net_xml)
18
+
19
+ expect_too_many_args(newnet, "undefine", 1)
20
+
21
+ expect_success(newnet, "no args", "undefine")
22
+
23
+ # TESTGROUP: net.create
24
+ newnet = conn.define_network_xml($new_net_xml)
25
+
26
+ expect_too_many_args(newnet, "create", 1)
27
+
28
+ expect_success(newnet, "no args", "create")
29
+
30
+ expect_fail(newnet, Libvirt::Error, "on already running network", "create")
31
+
32
+ newnet.destroy
33
+ newnet.undefine
34
+
35
+ # TESTGROUP: net.update
36
+ newnet = conn.create_network_xml($new_net_xml)
37
+
38
+ expect_too_few_args(newnet, "update", 1)
39
+
40
+ command = Libvirt::Network::NETWORK_UPDATE_COMMAND_ADD_LAST
41
+ section = Libvirt::Network::NETWORK_SECTION_IP_DHCP_HOST
42
+ flags = Libvirt::Network::NETWORK_UPDATE_AFFECT_CURRENT
43
+ expect_success(newnet, "dhcp ip", "update",
44
+ command, section, -1, $new_network_dhcp_ip, flags)
45
+
46
+ newnet.destroy
47
+
48
+ # TESTGROUP: net.destroy
49
+ newnet = conn.create_network_xml($new_net_xml)
50
+
51
+ expect_too_many_args(newnet, "destroy", 1)
52
+
53
+ expect_success(newnet, "no args", "destroy")
54
+
55
+ # TESTGROUP: net.name
56
+ newnet = conn.create_network_xml($new_net_xml)
57
+
58
+ expect_too_many_args(newnet, "name", 1)
59
+
60
+ expect_success(newnet, "no args", "name") {|x| x == "rb-libvirt-test"}
61
+
62
+ newnet.destroy
63
+
64
+ # TESTGROUP: net.uuid
65
+ newnet = conn.create_network_xml($new_net_xml)
66
+
67
+ expect_too_many_args(newnet, "uuid", 1)
68
+
69
+ expect_success(newnet, "no args", "uuid") {|x| x == $NETWORK_UUID}
70
+
71
+ newnet.destroy
72
+
73
+ # TESTGROUP: net.xml_desc
74
+ newnet = conn.create_network_xml($new_net_xml)
75
+
76
+ expect_too_many_args(newnet, "xml_desc", 1, 2)
77
+ expect_invalid_arg_type(newnet, "xml_desc", "foo")
78
+
79
+ expect_success(newnet, "no args", "xml_desc")
80
+
81
+ newnet.destroy
82
+
83
+ # TESTGROUP: net.bridge_name
84
+ newnet = conn.create_network_xml($new_net_xml)
85
+
86
+ expect_too_many_args(newnet, "bridge_name", 1)
87
+
88
+ expect_success(newnet, "no args", "bridge_name") {|x| x == "rubybr0"}
89
+
90
+ newnet.destroy
91
+
92
+ # TESTGROUP: net.autostart?
93
+ newnet = conn.define_network_xml($new_net_xml)
94
+
95
+ expect_too_many_args(newnet, "autostart?", 1)
96
+
97
+ expect_success(newnet, "no args", "autostart?") {|x| x == false}
98
+
99
+ newnet.autostart = true
100
+
101
+ expect_success(newnet, "no args", "autostart?") {|x| x == true}
102
+
103
+ newnet.undefine
104
+
105
+ # TESTGROUP: net.autostart=
106
+ newnet = conn.define_network_xml($new_net_xml)
107
+
108
+ expect_too_many_args(newnet, "autostart=", 1, 2)
109
+ expect_invalid_arg_type(newnet, "autostart=", 'foo')
110
+ expect_invalid_arg_type(newnet, "autostart=", nil)
111
+ expect_invalid_arg_type(newnet, "autostart=", 1234)
112
+
113
+ expect_success(newnet, "boolean arg", "autostart=", true)
114
+ if not newnet.autostart?
115
+ puts_fail "network.autostart= did not set autostart to true"
116
+ else
117
+ puts_ok "network.autostart= set autostart to true"
118
+ end
119
+
120
+ expect_success(newnet, "boolean arg", "autostart=", false)
121
+ if newnet.autostart?
122
+ puts_fail "network.autostart= did not set autostart to false"
123
+ else
124
+ puts_ok "network.autostart= set autostart to false"
125
+ end
126
+
127
+ newnet.undefine
128
+
129
+ # TESTGROUP: net.free
130
+ newnet = conn.define_network_xml($new_net_xml)
131
+ newnet.undefine
132
+ expect_too_many_args(newnet, "free", 1)
133
+
134
+ expect_success(newnet, "no args", "free")
135
+
136
+ # TESTGROUP: net.active?
137
+ newnet = conn.create_network_xml($new_net_xml)
138
+
139
+ expect_too_many_args(newnet, "active?", 1)
140
+
141
+ expect_success(newnet, "no args", "active?") {|x| x == true}
142
+
143
+ newnet.destroy
144
+
145
+ newnet = conn.define_network_xml($new_net_xml)
146
+
147
+ expect_success(newnet, "no args", "active?") {|x| x == false}
148
+
149
+ newnet.create
150
+
151
+ expect_success(newnet, "no args", "active?") {|x| x == true}
152
+
153
+ newnet.destroy
154
+ newnet.undefine
155
+
156
+ # TESTGROUP: net.persistent?
157
+ newnet = conn.create_network_xml($new_net_xml)
158
+
159
+ expect_too_many_args(newnet, "persistent?", 1)
160
+
161
+ expect_success(newnet, "no args", "persistent?") {|x| x == false}
162
+
163
+ newnet.destroy
164
+
165
+ newnet = conn.define_network_xml($new_net_xml)
166
+
167
+ expect_success(newnet, "no args", "persistent?") {|x| x == true}
168
+
169
+ newnet.undefine
170
+
171
+ # END TESTS
172
+
173
+ conn.close
174
+
175
+ finish_tests
@@ -0,0 +1,90 @@
1
+ #!/usr/bin/ruby
2
+
3
+ # Test the nodedevice methods the bindings support
4
+
5
+ $: << File.dirname(__FILE__)
6
+
7
+ require 'libvirt'
8
+ require 'test_utils.rb'
9
+
10
+ set_test_object("nodedevice")
11
+
12
+ conn = Libvirt::open(URI)
13
+
14
+ # TESTGROUP: nodedevice.name
15
+ testnode = conn.lookup_nodedevice_by_name(conn.list_nodedevices[0])
16
+
17
+ expect_too_many_args(testnode, "name", 1)
18
+ expect_success(testnode, "no args", "name")
19
+
20
+ # TESTGROUP: nodedevice.parent
21
+ testnode = conn.lookup_nodedevice_by_name(conn.list_nodedevices[0])
22
+
23
+ expect_too_many_args(testnode, "parent", 1)
24
+ expect_success(testnode, "no args", "parent")
25
+
26
+ # TESTGROUP: nodedevice.num_of_caps
27
+ testnode = conn.lookup_nodedevice_by_name(conn.list_nodedevices[0])
28
+
29
+ expect_too_many_args(testnode, "num_of_caps", 1)
30
+ expect_success(testnode, "no args", "num_of_caps")
31
+
32
+ # TESTGROUP: nodedevice.list_caps
33
+ testnode = conn.lookup_nodedevice_by_name(conn.list_nodedevices[0])
34
+
35
+ expect_too_many_args(testnode, "list_caps", 1)
36
+ expect_success(testnode, "no args", "list_caps")
37
+
38
+ # TESTGROUP: nodedevice.xml_desc
39
+ testnode = conn.lookup_nodedevice_by_name(conn.list_nodedevices[0])
40
+
41
+ expect_too_many_args(testnode, "xml_desc", 1, 2)
42
+ expect_invalid_arg_type(testnode, "xml_desc", 'foo')
43
+ expect_success(testnode, "no args", "xml_desc")
44
+
45
+ # TESTGROUP: nodedevice.detach
46
+ testnode = conn.lookup_nodedevice_by_name(conn.list_nodedevices[0])
47
+
48
+ expect_too_many_args(testnode, "detach", 1, 2, 3)
49
+ expect_invalid_arg_type(testnode, "detach", 1)
50
+ expect_invalid_arg_type(testnode, "detach", [])
51
+ expect_invalid_arg_type(testnode, "detach", {})
52
+ expect_invalid_arg_type(testnode, "detach", nil, 'foo')
53
+ expect_invalid_arg_type(testnode, "detach", nil, [])
54
+ expect_invalid_arg_type(testnode, "detach", nil, {})
55
+
56
+ #expect_success(testnode, "no args", "detach")
57
+
58
+ # TESTGROUP: nodedevice.reattach
59
+ testnode = conn.lookup_nodedevice_by_name(conn.list_nodedevices[0])
60
+
61
+ expect_too_many_args(testnode, "reattach", 1)
62
+
63
+ #expect_success(testnode, "no args", "reattach")
64
+
65
+ # TESTGROUP: nodedevice.reset
66
+ testnode = conn.lookup_nodedevice_by_name(conn.list_nodedevices[0])
67
+
68
+ expect_too_many_args(testnode, "reset", 1)
69
+
70
+ #expect_success(testnode, "no args", "reset")
71
+
72
+ # TESTGROUP: nodedevice.destroy
73
+ testnode = conn.lookup_nodedevice_by_name(conn.list_nodedevices[0])
74
+
75
+ expect_too_many_args(testnode, "destroy", 1)
76
+
77
+ #expect_success(testnode, "no args", "destroy")
78
+
79
+ # TESTGROUP: nodedevice.free
80
+ testnode = conn.lookup_nodedevice_by_name(conn.list_nodedevices[0])
81
+
82
+ expect_too_many_args(testnode, "free", 1)
83
+
84
+ expect_success(testnode, "no args", "free")
85
+
86
+ # END TESTS
87
+
88
+ conn.close
89
+
90
+ finish_tests
@@ -0,0 +1,60 @@
1
+ #!/usr/bin/ruby
2
+
3
+ # Test the nwfilter methods the bindings support
4
+
5
+ $: << File.dirname(__FILE__)
6
+
7
+ require 'libvirt'
8
+ require 'test_utils.rb'
9
+
10
+ set_test_object("nwfilter")
11
+
12
+ conn = Libvirt::open("qemu:///system")
13
+
14
+ # TESTGROUP: nwfilter.undefine
15
+ newnw = conn.define_nwfilter_xml($new_nwfilter_xml)
16
+
17
+ expect_too_many_args(newnw, "undefine", 1)
18
+
19
+ expect_success(newnw, "no args", "undefine")
20
+
21
+ # TESTGROUP: nwfilter.name
22
+ newnw = conn.define_nwfilter_xml($new_nwfilter_xml)
23
+
24
+ expect_too_many_args(newnw, "name", 1)
25
+
26
+ expect_success(newnw, "no args", "name") {|x| x == "rb-libvirt-test"}
27
+
28
+ newnw.undefine
29
+
30
+ # TESTGROUP: nwfilter.uuid
31
+ newnw = conn.define_nwfilter_xml($new_nwfilter_xml)
32
+
33
+ expect_too_many_args(newnw, "uuid", 1)
34
+
35
+ expect_success(newnw, "no args", "uuid") {|x| x == $NWFILTER_UUID}
36
+
37
+ newnw.undefine
38
+
39
+ # TESTGROUP: nwfilter.xml_desc
40
+ newnw = conn.define_nwfilter_xml($new_nwfilter_xml)
41
+
42
+ expect_too_many_args(newnw, "xml_desc", 1, 2)
43
+ expect_invalid_arg_type(newnw, "xml_desc", "foo")
44
+
45
+ expect_success(newnw, "no args", "xml_desc")
46
+
47
+ newnw.undefine
48
+
49
+ # TESTGROUP: nwfilter.free
50
+ newnw = conn.define_nwfilter_xml($new_nwfilter_xml)
51
+ newnw.undefine
52
+ expect_too_many_args(newnw, "free", 1)
53
+
54
+ expect_success(newnw, "no args", "free")
55
+
56
+ # END TESTS
57
+
58
+ conn.close
59
+
60
+ finish_tests
@@ -0,0 +1,250 @@
1
+ #!/usr/bin/ruby
2
+
3
+ # Test the open calls that the bindings support
4
+
5
+ $: << File.dirname(__FILE__)
6
+
7
+ require 'libvirt'
8
+ require 'test_utils.rb'
9
+
10
+ set_test_object("Libvirt")
11
+
12
+ def expect_connect_error(func, args)
13
+ expect_fail(Libvirt, Libvirt::ConnectionError, "invalid driver", func, *args)
14
+ end
15
+
16
+ # TESTGROUP: Libvirt::version
17
+ expect_too_many_args(Libvirt, "version", "test", 1)
18
+ expect_invalid_arg_type(Libvirt, "version", 1)
19
+ expect_success(Libvirt, "no args", "version") {|x| x.class == Array and x.length == 2}
20
+ expect_success(Libvirt, "nil arg", "version", nil) {|x| x.class == Array and x.length == 2}
21
+ expect_success(Libvirt, "Test arg", "version", "Test") {|x| x.class == Array and x.length == 2}
22
+
23
+ # TESTGROUP: Libvirt::open
24
+ expect_too_many_args(Libvirt, "open", URI, 1)
25
+ expect_connect_error("open", "foo:///system")
26
+ conn = expect_success(Libvirt, "no args", "open") {|x| x.class == Libvirt::Connect }
27
+ conn.close
28
+ conn = expect_success(Libvirt, URI, "open", URI) {|x| x.class == Libvirt::Connect }
29
+ conn.close
30
+ conn = expect_success(Libvirt, "nil arg", "open", nil) {|x| x.class == Libvirt::Connect }
31
+ conn.close
32
+
33
+ # TESTGROUP: Libvirt::open_read_only
34
+ expect_too_many_args(Libvirt, "open_read_only", URI, 1)
35
+ expect_connect_error("open_read_only", "foo:///system")
36
+ conn = expect_success(Libvirt, "no args", "open_read_only") {|x| x.class == Libvirt::Connect }
37
+ conn.close
38
+ conn = expect_success(Libvirt, URI, "open_read_only", URI) {|x| x.class == Libvirt::Connect }
39
+ conn.close
40
+ conn = expect_success(Libvirt, "nil arg", "open_read_only", nil) {|x| x.class == Libvirt::Connect }
41
+ conn.close
42
+
43
+ # TESTGROUP: Libvirt::open_auth
44
+ expect_too_many_args(Libvirt, "open_auth", URI, [], "hello there", 1, 2)
45
+ expect_connect_error("open_auth", "foo:///system")
46
+ expect_invalid_arg_type(Libvirt, "open_auth", 1)
47
+ expect_invalid_arg_type(Libvirt, "open_auth", URI, [], "hello", "foo")
48
+
49
+ conn = expect_success(Libvirt, "no args", "open_auth") {|x| x.class == Libvirt::Connect }
50
+ conn.close
51
+
52
+ conn = expect_success(Libvirt, "uri arg", "open_auth", URI) {|x| x.class == Libvirt::Connect }
53
+ conn.close
54
+
55
+ conn = expect_success(Libvirt, "uri and empty cred args", "open_auth", URI, []) {|x| x.class == Libvirt::Connect }
56
+ conn.close
57
+
58
+ conn = expect_success(Libvirt, "uri and full cred args", "open_auth", URI, [Libvirt::CRED_AUTHNAME, Libvirt::CRED_PASSPHRASE]) {|x| x.class == Libvirt::Connect }
59
+ conn.close
60
+
61
+ conn = expect_success(Libvirt, "uri, full cred, and user args", "open_auth", URI, [Libvirt::CRED_AUTHNAME, Libvirt::CRED_PASSPHRASE], "hello") {|x| x.class == Libvirt::Connect }
62
+ conn.close
63
+
64
+ # equivalent to expect_invalid_arg_type
65
+ begin
66
+ conn = Libvirt::open_auth(URI, {}) do |cred|
67
+ end
68
+ rescue TypeError => e
69
+ puts_ok "#{$test_object}.open_auth invalid arg type threw #{TypeError.to_s}"
70
+ else
71
+ puts_fail "#{$test_object}.open_auth invalid arg type expected to throw #{TypeError.to_s}, but threw nothing"
72
+ end
73
+
74
+ # equivalent to expect_invalid_arg_type
75
+ begin
76
+ conn = Libvirt::open_auth(URI, 1) do |cred|
77
+ end
78
+ rescue TypeError => e
79
+ puts_ok "#{$test_object}.open_auth invalid arg type threw #{TypeError.to_s}"
80
+ else
81
+ puts_fail "#{$test_object}.open_auth invalid arg type expected to throw #{TypeError.to_s}, but threw nothing"
82
+ end
83
+
84
+ # equivalent to expect_invalid_arg_type
85
+ begin
86
+ conn = Libvirt::open_auth(URI, 'foo') do |cred|
87
+ end
88
+ rescue TypeError => e
89
+ puts_ok "#{$test_object}.open_auth invalid arg type threw #{TypeError.to_s}"
90
+ else
91
+ puts_fail "#{$test_object}.open_auth invalid arg type expected to throw #{TypeError.to_s}, but threw nothing"
92
+ end
93
+
94
+ # equivalent to "expect_success"
95
+ begin
96
+ conn = Libvirt::open_auth(URI, [Libvirt::CRED_AUTHNAME, Libvirt::CRED_PASSPHRASE], "hello") do |cred|
97
+ if not cred["userdata"].nil?
98
+ puts "userdata is #{cred["userdata"]}"
99
+ end
100
+ if cred["type"] == Libvirt::CRED_AUTHNAME
101
+ print "#{cred['prompt']}: "
102
+ res = gets
103
+ # strip off the \n
104
+ res = res[0..-2]
105
+ elsif cred["type"] == Libvirt::CRED_PASSPHRASE
106
+ print "#{cred['prompt']}: "
107
+ res = gets
108
+ res = res[0..-2]
109
+ else
110
+ raise "Unsupported credential #{cred['type']}"
111
+ end
112
+ res
113
+ end
114
+
115
+ puts_ok "Libvirt.open_auth uri, creds, userdata, auth block succeeded"
116
+ conn.close
117
+ rescue NoMethodError
118
+ puts_skipped "Libvirt.open_auth does not exist"
119
+ rescue => e
120
+ puts_fail "Libvirt.open_auth uri, creds, userdata, auth block expected to succeed, threw #{e.class.to_s}: #{e.to_s}"
121
+ end
122
+
123
+ # equivalent to "expect_success"
124
+ begin
125
+ conn = Libvirt::open_auth(URI) do |cred|
126
+ end
127
+
128
+ puts_ok "Libvirt.open_auth uri, succeeded"
129
+ conn.close
130
+ rescue NoMethodError
131
+ puts_skipped "Libvirt.open_auth does not exist"
132
+ rescue => e
133
+ puts_fail "Libvirt.open_auth uri expected to succeed, threw #{e.class.to_s}: #{e.to_s}"
134
+ end
135
+
136
+ # equivalent to "expect_success"
137
+ begin
138
+ conn = Libvirt::open_auth(URI, [Libvirt::CRED_AUTHNAME, Libvirt::CRED_PASSPHRASE], "hello", Libvirt::CONNECT_RO) do |cred|
139
+ if not cred["userdata"].nil?
140
+ puts "userdata is #{cred["userdata"]}"
141
+ end
142
+ if cred["type"] == Libvirt::CRED_AUTHNAME
143
+ print "#{cred['prompt']}: "
144
+ res = gets
145
+ # strip off the \n
146
+ res = res[0..-2]
147
+ elsif cred["type"] == Libvirt::CRED_PASSPHRASE
148
+ print "#{cred['prompt']}: "
149
+ res = gets
150
+ res = res[0..-2]
151
+ else
152
+ raise "Unsupported credential #{cred['type']}"
153
+ end
154
+ res
155
+ end
156
+
157
+ puts_ok "Libvirt.open_auth uri, creds, userdata, R/O flag, auth block succeeded"
158
+ conn.close
159
+ rescue NoMethodError
160
+ puts_skipped "Libvirt.open_auth does not exist"
161
+ rescue => e
162
+ puts_fail "Libvirt.open_auth uri, creds, userdata, R/O flag, auth block expected to succeed, threw #{e.class.to_s}: #{e.to_s}"
163
+ end
164
+
165
+ # TESTGROUP: Libvirt::event_invoke_handle_callback
166
+ conn = Libvirt::open(URI)
167
+
168
+ expect_too_many_args(Libvirt, "event_invoke_handle_callback", 1, 2, 3, 4, 5)
169
+ expect_too_few_args(Libvirt, "event_invoke_handle_callback")
170
+ expect_too_few_args(Libvirt, "event_invoke_handle_callback", 1)
171
+ expect_too_few_args(Libvirt, "event_invoke_handle_callback", 1, 2)
172
+ expect_too_few_args(Libvirt, "event_invoke_handle_callback", 1, 2, 3)
173
+ expect_invalid_arg_type(Libvirt, "event_invoke_handle_callback", "hello", 1, 1, 1)
174
+ expect_invalid_arg_type(Libvirt, "event_invoke_handle_callback", "hello", 1, 1, [])
175
+ expect_invalid_arg_type(Libvirt, "event_invoke_handle_callback", "hello", 1, 1, nil)
176
+ # this is a bit bizarre; I am constructing a bogus hash to pass as the 4th
177
+ # parameter to event_invoke_handle_callback. In a real situation, I would
178
+ # have been given this hash from libvirt earlier, and just pass it on. I
179
+ # don't want all of that complexity here, though, so I create the bogus hash.
180
+ # One caveat; the data inside the hash *must* be of type T_DATA, so I pass in
181
+ # a fake conn object just to appease the type checker (so I can test out the
182
+ # other arguments properly)
183
+ expect_invalid_arg_type(Libvirt, "event_invoke_handle_callback", "hello", 1, 1, { "libvirt_cb" => conn, "opaque" => conn })
184
+ expect_invalid_arg_type(Libvirt, "event_invoke_handle_callback", 1, "hello", 1, { "libvirt_cb" => conn, "opaque" => conn })
185
+ expect_invalid_arg_type(Libvirt, "event_invoke_handle_callback", 1, 1, "hello", { "libvirt_cb" => conn, "opaque" => conn })
186
+ expect_invalid_arg_type(Libvirt, "event_invoke_handle_callback", 1, 1, 1, { "libvirt_cb" => "hello", "opaque" => conn })
187
+ expect_invalid_arg_type(Libvirt, "event_invoke_handle_callback", 1, 1, 1, { "libvirt_cb" => conn, "opaque" => "hello" })
188
+ conn.close
189
+
190
+ # TESTGROUP: Libvirt::event_invoke_timeout_callback
191
+ conn = Libvirt::open(URI)
192
+
193
+ expect_too_many_args(Libvirt, "event_invoke_timeout_callback", 1, 2, 3)
194
+ expect_too_few_args(Libvirt, "event_invoke_timeout_callback")
195
+ expect_too_few_args(Libvirt, "event_invoke_timeout_callback", 1)
196
+ expect_invalid_arg_type(Libvirt, "event_invoke_timeout_callback", "hello", 1)
197
+ expect_invalid_arg_type(Libvirt, "event_invoke_timeout_callback", "hello", [])
198
+ expect_invalid_arg_type(Libvirt, "event_invoke_timeout_callback", "hello", nil)
199
+ # this is a bit bizarre; I am constructing a bogus hash to pass as the 4th
200
+ # parameter to event_invoke_handle_callback. In a real situation, I would
201
+ # have been given this hash from libvirt earlier, and just pass it on. I
202
+ # don't want all of that complexity here, though, so I create the bogus hash.
203
+ # One caveat; the data inside the hash *must* be of type T_DATA, so I pass in
204
+ # a fake conn object just to appease the type checker (so I can test out the
205
+ # other arguments properly)
206
+ expect_invalid_arg_type(Libvirt, "event_invoke_timeout_callback", "hello", { "libvirt_cb" => conn, "opaque" => conn })
207
+ expect_invalid_arg_type(Libvirt, "event_invoke_timeout_callback", 1, { "libvirt_cb" => "hello", "opaque" => conn })
208
+ expect_invalid_arg_type(Libvirt, "event_invoke_timeout_callback", 1, { "libvirt_cb" => conn, "opaque" => "hello" })
209
+ conn.close
210
+
211
+ # TESTGROUP: Libvirt::event_register_impl
212
+ expect_too_many_args(Libvirt, "event_register_impl", 1, 2, 3, 4, 5, 6, 7)
213
+ expect_invalid_arg_type(Libvirt, "event_register_impl", 1)
214
+
215
+ # symbol callbacks
216
+ def virEventAddHandleImpl(fd, events, opaque)
217
+ end
218
+ def virEventUpdateHandleImpl(watch, event)
219
+ end
220
+ def virEventRemoveHandleImpl(handleID)
221
+ end
222
+ def virEventAddTimerImpl(interval, opaque)
223
+ end
224
+ def virEventUpdateTimerImpl(timer, timeout)
225
+ end
226
+ def virEventRemoveTimerImpl(timerID)
227
+ end
228
+
229
+ # proc callbacks
230
+ virEventAddHandleProc = lambda {|fd, events, opaque|
231
+ }
232
+ virEventUpdateHandleProc = lambda {|watch, event|
233
+ }
234
+ virEventRemoveHandleProc = lambda {|handleID|
235
+ }
236
+ virEventAddTimerProc = lambda {|interval, opaque|
237
+ }
238
+ virEventUpdateTimerProc = lambda {|timer, timeout|
239
+ }
240
+ virEventRemoveTimerProc = lambda {|timerID|
241
+ }
242
+
243
+ expect_success(Libvirt, "all Symbol callbacks", "event_register_impl", :virEventAddHandleImpl, :virEventUpdateHandleImpl, :virEventRemoveHandleImpl, :virEventAddTimerImpl, :virEventUpdateTimerImpl, :virEventRemoveTimerImpl)
244
+ expect_success(Libvirt, "unregister all callbacks", "event_register_impl", nil, nil, nil, nil, nil, nil)
245
+ expect_success(Libvirt, "all Proc callbacks", "event_register_impl", virEventAddHandleProc, virEventUpdateHandleProc, virEventRemoveHandleProc, virEventAddTimerProc, virEventUpdateTimerProc, virEventRemoveTimerProc)
246
+ expect_success(Libvirt, "unregister all callbacks", "event_register_impl")
247
+
248
+ # END TESTS
249
+
250
+ finish_tests