win32-service 0.7.0-x86-mswin32-60 → 0.7.1-x86-mswin32-60

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,58 +1,58 @@
1
- #########################################################################
2
- # tc_daemon.rb
3
- #
4
- # Test suite for the Win32::Daemon class. You should run this test via
5
- # the 'rake test' or 'rake test_daemon' tasks.
6
- #
7
- # These tests are rather limited, since the acid test is to install
8
- # your daemon as a service and see how it behaves.
9
- #########################################################################
10
- require 'rubygems'
11
- gem 'test-unit'
12
-
13
- require 'win32/daemon'
14
- require 'test/unit'
15
- include Win32
16
-
17
- class TC_Daemon < Test::Unit::TestCase
18
- def setup
19
- @daemon = Daemon.new
20
- end
21
-
22
- def test_version
23
- assert_equal('0.7.0', Daemon::VERSION)
24
- end
25
-
26
- def test_constructor
27
- assert_respond_to(Daemon, :new)
28
- assert_nothing_raised{ Daemon.new }
29
- assert_raises(ArgumentError){ Daemon.new(1) } # No arguments by default
30
- end
31
-
32
- def test_mainloop
33
- assert_respond_to(@daemon, :mainloop)
34
- end
35
-
36
- def test_state
37
- assert_respond_to(@daemon, :state)
38
- end
39
-
40
- def test_running
41
- assert_respond_to(@daemon, :running?)
42
- end
43
-
44
- def test_constants
45
- assert_not_nil(Daemon::CONTINUE_PENDING)
46
- assert_not_nil(Daemon::PAUSE_PENDING)
47
- assert_not_nil(Daemon::PAUSED)
48
- assert_not_nil(Daemon::RUNNING)
49
- assert_not_nil(Daemon::START_PENDING)
50
- assert_not_nil(Daemon::STOP_PENDING)
51
- assert_not_nil(Daemon::STOPPED)
52
- assert_not_nil(Daemon::IDLE)
53
- end
54
-
55
- def teardown
56
- @daemon = nil
57
- end
58
- end
1
+ #########################################################################
2
+ # test_win32_daemon.rb
3
+ #
4
+ # Test suite for the Win32::Daemon class. You should run this test via
5
+ # the 'rake test' or 'rake test_daemon' tasks.
6
+ #
7
+ # These tests are rather limited, since the acid test is to install
8
+ # your daemon as a service and see how it behaves.
9
+ #########################################################################
10
+ require 'rubygems'
11
+ gem 'test-unit'
12
+
13
+ require 'win32/daemon'
14
+ require 'test/unit'
15
+ include Win32
16
+
17
+ class TC_Daemon < Test::Unit::TestCase
18
+ def setup
19
+ @daemon = Daemon.new
20
+ end
21
+
22
+ def test_version
23
+ assert_equal('0.7.1', Daemon::VERSION)
24
+ end
25
+
26
+ def test_constructor
27
+ assert_respond_to(Daemon, :new)
28
+ assert_nothing_raised{ Daemon.new }
29
+ assert_raises(ArgumentError){ Daemon.new(1) } # No arguments by default
30
+ end
31
+
32
+ def test_mainloop
33
+ assert_respond_to(@daemon, :mainloop)
34
+ end
35
+
36
+ def test_state
37
+ assert_respond_to(@daemon, :state)
38
+ end
39
+
40
+ def test_running
41
+ assert_respond_to(@daemon, :running?)
42
+ end
43
+
44
+ def test_constants
45
+ assert_not_nil(Daemon::CONTINUE_PENDING)
46
+ assert_not_nil(Daemon::PAUSE_PENDING)
47
+ assert_not_nil(Daemon::PAUSED)
48
+ assert_not_nil(Daemon::RUNNING)
49
+ assert_not_nil(Daemon::START_PENDING)
50
+ assert_not_nil(Daemon::STOP_PENDING)
51
+ assert_not_nil(Daemon::STOPPED)
52
+ assert_not_nil(Daemon::IDLE)
53
+ end
54
+
55
+ def teardown
56
+ @daemon = nil
57
+ end
58
+ end
@@ -1,251 +1,409 @@
1
- ##########################################################################
2
- # tc_service.rb
3
- #
4
- # Test case for the Win32::Service class.
5
- ##########################################################################
6
- require 'rubygems'
7
- gem 'test-unit'
8
-
9
- require 'win32/service'
10
- require 'socket'
11
- require 'test/unit'
12
-
13
- class TC_Win32_Service < Test::Unit::TestCase
14
- def setup
15
- @display_name = "Task Scheduler"
16
- @service_name = "Schedule"
17
- @service_stat = nil
18
- @services = []
19
- end
20
-
21
- def wait_for_status(status)
22
- sleep 0.1 while Win32::Service.status(@service_name).current_state != status
23
- end
24
-
25
- def test_version
26
- assert_equal('0.7.0', Win32::Service::VERSION)
27
- end
28
-
29
- def test_services_basic
30
- assert_respond_to(Win32::Service, :services)
31
- assert_nothing_raised{ Win32::Service.services }
32
- assert_nothing_raised{ Win32::Service.services(nil) }
33
- assert_nothing_raised{ Win32::Service.services(nil, 'network') }
34
- end
35
-
36
- def test_services_non_block_form
37
- assert_nothing_raised{ @services = Win32::Service.services }
38
- assert_kind_of(Array, @services)
39
- assert_kind_of(Struct::ServiceInfo, @services[0])
40
- end
41
-
42
- def test_services_block_form
43
- assert_nothing_raised{ Win32::Service.services{ |s| @services << s } }
44
- assert_kind_of(Array, @services)
45
- assert_kind_of(Struct::ServiceInfo, @services[0])
46
- end
47
-
48
- def test_services_expected_errors
49
- assert_raise(TypeError){ Win32::Service.services(1) }
50
- assert_raise(TypeError){ Win32::Service.services(nil, 1) }
51
- assert_raise(ArgumentError){ Win32::Service.services(nil, 'network', 1) }
52
- assert_raise(Win32::Service::Error){ Win32::Service.services('bogus') }
53
- end
54
-
55
- def test_delete
56
- assert_respond_to(Win32::Service, :delete)
57
- end
58
-
59
- def test_delete_expected_errors
60
- assert_raise(ArgumentError){ Win32::Service.delete }
61
- assert_raise(Win32::Service::Error){ Win32::Service.delete('bogus') }
62
- assert_raise(Win32::Service::Error){ Win32::Service.delete('bogus', 'bogus') }
63
- assert_raise(ArgumentError){ Win32::Service.delete('x', 'y', 'z') }
64
- end
65
-
66
- def test_service_pause_and_resume
67
- assert_respond_to(Win32::Service, :pause)
68
- assert_respond_to(Win32::Service, :resume)
69
- assert_nothing_raised{ Win32::Service.pause(@service_name) }
70
- assert_nothing_raised{ wait_for_status('paused') }
71
- assert_nothing_raised{ Win32::Service.pause(@service_name) }
72
- assert_nothing_raised{ Win32::Service.resume(@service_name) }
73
- assert_nothing_raised{ wait_for_status('running') }
74
- end
75
-
76
- def test_pause_expected_errors
77
- assert_raise(ArgumentError){ Win32::Service.pause }
78
- assert_raise(Win32::Service::Error){ Win32::Service.pause('bogus') }
79
- assert_raise(Win32::Service::Error){ Win32::Service.pause('bogus', 'bogus') }
80
- assert_raise(ArgumentError){ Win32::Service.pause('x', 'y', 'z') }
81
- end
82
-
83
- def test_resume_expected_errors
84
- assert_raise(ArgumentError){ Win32::Service.resume }
85
- assert_raise(Win32::Service::Error){ Win32::Service.resume('bogus') }
86
- assert_raise(Win32::Service::Error){ Win32::Service.resume('bogus', 'bogus') }
87
- assert_raise(ArgumentError){ Win32::Service.resume('bogus', 'bogus', 'a') }
88
- end
89
-
90
- def test_service_stop_and_start
91
- assert_respond_to(Win32::Service, :stop)
92
- assert_respond_to(Win32::Service, :start)
93
- assert_nothing_raised{ Win32::Service.stop(@service_name) }
94
- assert_nothing_raised{ wait_for_status('stopped') }
95
- assert_raise(Win32::Service::Error){ Win32::Service.stop(@service_name) }
96
- assert_nothing_raised{ Win32::Service.start(@service_name) }
97
- assert_nothing_raised{ wait_for_status('running') }
98
- end
99
-
100
- def test_stop_expected_errors
101
- assert_raise(ArgumentError){ Win32::Service.stop }
102
- assert_raise(Win32::Service::Error){ Win32::Service.stop('bogus') }
103
- assert_raise(Win32::Service::Error){ Win32::Service.stop('bogus', 'bogus') }
104
- assert_raise(ArgumentError){ Win32::Service.stop('x', 'y', 'z') }
105
- end
106
-
107
- def test_start_expected_errors
108
- assert_raise(ArgumentError){ Win32::Service.start }
109
- assert_raise(Win32::Service::Error){ Win32::Service.start(@service_name) } # Started
110
- assert_raise(Win32::Service::Error){ Win32::Service.start('bogus') }
111
- assert_raise(Win32::Service::Error){ Win32::Service.start('bogus', 'bogus') }
112
- assert_raise(Win32::Service::Error){ Win32::Service.start('bogus', 'bogus', 'a') }
113
- assert_raise(Win32::Service::Error){ Win32::Service.start('a', 'b', 'c', 'd') }
114
- end
115
-
116
- def test_service_stop_expected_errors
117
- assert_raise(ArgumentError){ Win32::Service.stop }
118
- assert_raise(Win32::Service::Error){ Win32::Service.stop('bogus') }
119
- assert_raise(Win32::Service::Error){ Win32::Service.stop('bogus', 'bogus') }
120
- assert_raise(ArgumentError){ Win32::Service.stop('a', 'b', 'c') }
121
- end
122
-
123
- def test_service_status_basic
124
- assert_respond_to(Win32::Service, :status)
125
- assert_nothing_raised{ Win32::Service.status(@service_name) }
126
- assert_kind_of(Struct::ServiceStatus, Win32::Service.status(@service_name))
127
- end
128
-
129
- def test_service_get_service_name_basic
130
- assert_respond_to(Win32::Service, :get_service_name)
131
- assert_nothing_raised{ Win32::Service.get_service_name(@display_name) }
132
- assert_kind_of(String, Win32::Service.get_service_name(@display_name))
133
- end
134
-
135
- def test_service_getservicename_alias_basic
136
- assert_respond_to(Win32::Service, :getservicename)
137
- assert_nothing_raised{ Win32::Service.getservicename(@display_name) }
138
- assert_kind_of(String, Win32::Service.getservicename(@display_name))
139
- end
140
-
141
- def test_service_get_service_name
142
- assert_equal(@service_name, Win32::Service.get_service_name(@display_name))
143
- assert_equal(@service_name, Win32::Service.getservicename(@display_name))
144
- end
145
-
146
- def test_service_get_service_name_expected_errors
147
- assert_raise(ArgumentError){ Win32::Service.get_service_name }
148
- assert_raise(Win32::Service::Error){ Win32::Service.get_service_name('bogus') }
149
- assert_raise(Win32::Service::Error){ Win32::Service.get_service_name('foo','bogus') }
150
- assert_raise(ArgumentError){ Win32::Service.get_service_name('x', 'y', 'z') }
151
- end
152
-
153
- def test_service_get_display_name_basic
154
- assert_respond_to(Win32::Service, :get_display_name)
155
- assert_nothing_raised{ Win32::Service.get_display_name(@service_name) }
156
- assert_kind_of(String, Win32::Service.get_display_name(@service_name))
157
- end
158
-
159
- def test_service_getdisplayname_alias_basic
160
- assert_respond_to(Win32::Service, :getdisplayname)
161
- assert_nothing_raised{ Win32::Service.getdisplayname(@service_name) }
162
- assert_kind_of(String, Win32::Service.getdisplayname(@service_name))
163
- end
164
-
165
- def test_service_get_display_name
166
- assert_equal(@display_name, Win32::Service.get_display_name(@service_name))
167
- assert_equal(@display_name, Win32::Service.getdisplayname(@service_name))
168
- end
169
-
170
- def test_service_get_display_name_expected_errors
171
- assert_raise(ArgumentError){ Win32::Service.get_display_name }
172
- assert_raise(Win32::Service::Error){ Win32::Service.get_display_name('bogus') }
173
- assert_raise(Win32::Service::Error){ Win32::Service.get_display_name('foo','bogus') }
174
- assert_raise(ArgumentError){ Win32::Service.get_display_name('x', 'y', 'z') }
175
- end
176
-
177
- def test_service_exists
178
- assert_respond_to(Win32::Service, :exists?)
179
- assert_nothing_raised{ Win32::Service.exists?('W32Time') }
180
- assert_equal(true, Win32::Service.exists?('W32Time'))
181
- assert_equal(false, Win32::Service.exists?('foobar'))
182
- end
183
-
184
- def test_service_exists_expected_errors
185
- assert_raises(ArgumentError){ Win32::Service.exists? }
186
- assert_raises(Win32::Service::Error){Win32::Service.exists?('foo', 'bogushost') }
187
- assert_raises(ArgumentError){ Win32::Service.exists?('foo', 'bar', 'baz') }
188
- end
189
-
190
- def test_scm_security_constants
191
- assert_not_nil(Win32::Service::MANAGER_ALL_ACCESS)
192
- assert_not_nil(Win32::Service::MANAGER_CREATE_SERVICE)
193
- assert_not_nil(Win32::Service::MANAGER_CONNECT)
194
- assert_not_nil(Win32::Service::MANAGER_ENUMERATE_SERVICE)
195
- assert_not_nil(Win32::Service::MANAGER_LOCK)
196
- assert_not_nil(Win32::Service::MANAGER_QUERY_LOCK_STATUS)
197
- end
198
-
199
- def test_service_specific_constants
200
- assert_not_nil(Win32::Service::ALL_ACCESS)
201
- assert_not_nil(Win32::Service::CHANGE_CONFIG)
202
- assert_not_nil(Win32::Service::ENUMERATE_DEPENDENTS)
203
- assert_not_nil(Win32::Service::INTERROGATE)
204
- assert_not_nil(Win32::Service::PAUSE_CONTINUE)
205
- assert_not_nil(Win32::Service::QUERY_CONFIG)
206
- assert_not_nil(Win32::Service::QUERY_STATUS)
207
- assert_not_nil(Win32::Service::STOP)
208
- assert_not_nil(Win32::Service::START)
209
- assert_not_nil(Win32::Service::USER_DEFINED_CONTROL)
210
- end
211
-
212
- def test_service_type_constants
213
- assert_not_nil(Win32::Service::FILE_SYSTEM_DRIVER)
214
- assert_not_nil(Win32::Service::KERNEL_DRIVER)
215
- assert_not_nil(Win32::Service::WIN32_OWN_PROCESS)
216
- assert_not_nil(Win32::Service::WIN32_SHARE_PROCESS)
217
- assert_not_nil(Win32::Service::INTERACTIVE_PROCESS)
218
- end
219
-
220
- def test_service_start_option_constants
221
- assert_not_nil(Win32::Service::AUTO_START)
222
- assert_not_nil(Win32::Service::BOOT_START)
223
- assert_not_nil(Win32::Service::DEMAND_START)
224
- assert_not_nil(Win32::Service::DISABLED)
225
- assert_not_nil(Win32::Service::SYSTEM_START)
226
- end
227
-
228
- def test_service_error_control_constants
229
- assert_not_nil(Win32::Service::ERROR_IGNORE)
230
- assert_not_nil(Win32::Service::ERROR_NORMAL)
231
- assert_not_nil(Win32::Service::ERROR_SEVERE)
232
- assert_not_nil(Win32::Service::ERROR_CRITICAL)
233
- end
234
-
235
- def test_service_state_constants
236
- assert_not_nil(Win32::Service::CONTINUE_PENDING)
237
- assert_not_nil(Win32::Service::PAUSE_PENDING)
238
- assert_not_nil(Win32::Service::PAUSED)
239
- assert_not_nil(Win32::Service::RUNNING)
240
- assert_not_nil(Win32::Service::START_PENDING)
241
- assert_not_nil(Win32::Service::STOP_PENDING)
242
- assert_not_nil(Win32::Service::STOPPED)
243
- end
244
-
245
- def teardown
246
- @display_name = nil
247
- @service_name = nil
248
- @service_stat = nil
249
- @services = nil
250
- end
251
- end
1
+ ##########################################################################
2
+ # test_win32_service.rb
3
+ #
4
+ # Tests for the Win32::Service class.
5
+ ##########################################################################
6
+ require 'rubygems'
7
+ gem 'test-unit'
8
+
9
+ require 'win32/service'
10
+ require 'socket'
11
+ require 'test/unit'
12
+
13
+ class TC_Win32_Service < Test::Unit::TestCase
14
+ def self.startup
15
+ @@host = Socket.gethostname
16
+ @@service_name = 'stisvc'
17
+ end
18
+
19
+ def setup
20
+ @display_name = 'Windows Image Acquisition (WIA)'
21
+ @service_name = 'stisvc'
22
+ @service_stat = nil
23
+ @services = []
24
+ end
25
+
26
+ def start_service(service)
27
+ status = Win32::Service.status(@service_name).current_state
28
+ if status == 'paused'
29
+ Win32::Service.resume(service)
30
+ else
31
+ unless ['running', 'start pending'].include?(status)
32
+ Win32::Service.start(service)
33
+ end
34
+ end
35
+ wait_for_status('running')
36
+ end
37
+
38
+ def stop_service(service)
39
+ status = Win32::Service.status(@service_name).current_state
40
+ unless ['stopped', 'stop pending'].include?(status)
41
+ Win32::Service.stop(service)
42
+ end
43
+ wait_for_status('stopped')
44
+ end
45
+
46
+ # Helper method that waits for a status to change its state since state
47
+ # changes aren't usually instantaneous.
48
+ def wait_for_status(status)
49
+ sleep 0.1 while Win32::Service.status(@service_name).current_state != status
50
+ end
51
+
52
+ test "version number is expected value" do
53
+ assert_equal('0.7.1', Win32::Service::VERSION)
54
+ end
55
+
56
+ test "services basic functionality" do
57
+ assert_respond_to(Win32::Service, :services)
58
+ assert_nothing_raised{ Win32::Service.services }
59
+ assert_nothing_raised{ Win32::Service.services(nil) }
60
+ assert_nothing_raised{ Win32::Service.services(nil, 'network') }
61
+ end
62
+
63
+ test "services method returns an array without a block" do
64
+ assert_nothing_raised{ @services = Win32::Service.services }
65
+ assert_kind_of(Array, @services)
66
+ assert_kind_of(Struct::ServiceInfo, @services[0])
67
+ end
68
+
69
+ test "services method yields service objects when a block is provided" do
70
+ assert_nothing_raised{ Win32::Service.services{ |s| @services << s } }
71
+ assert_kind_of(Array, @services)
72
+ assert_kind_of(Struct::ServiceInfo, @services[0])
73
+ end
74
+
75
+ test "the host argument must be a string or an error is raised" do
76
+ assert_raise(TypeError){ Win32::Service.services(1) }
77
+ end
78
+
79
+ test "the group argument must be a string or an error is raised" do
80
+ assert_raise(TypeError){ Win32::Service.services(nil, 1) }
81
+ end
82
+
83
+ test "the services method only accepts 2 arguments" do
84
+ assert_raise(ArgumentError){ Win32::Service.services(nil, 'network', 1) }
85
+ end
86
+
87
+ test "a valid hostname must be provided or an error is raised" do
88
+ assert_raise(Win32::Service::Error){ Win32::Service.services('bogus') }
89
+ end
90
+
91
+ test "delete method basic functionality" do
92
+ assert_respond_to(Win32::Service, :delete)
93
+ end
94
+
95
+ test "a service name must be provided to the delete method" do
96
+ assert_raise(ArgumentError){ Win32::Service.delete }
97
+ end
98
+
99
+ test "delete method raises an error if a bogus service name is provided" do
100
+ assert_raise(Win32::Service::Error){ Win32::Service.delete('bogus') }
101
+ end
102
+
103
+ test "delete method raises an error if a bogus host name is provided" do
104
+ assert_raise(Win32::Service::Error){ Win32::Service.delete('bogus', 'bogus') }
105
+ end
106
+
107
+ test "delete method only accepts up to two arguments" do
108
+ assert_raise(ArgumentError){ Win32::Service.delete('x', 'y', 'z') }
109
+ end
110
+
111
+ test "pause basic functionality" do
112
+ assert_respond_to(Win32::Service, :pause)
113
+ end
114
+
115
+ test "resume basic functionality" do
116
+ assert_respond_to(Win32::Service, :resume)
117
+ end
118
+
119
+ test "pause and resume work as expected" do
120
+ start_service(@service_name)
121
+
122
+ assert_nothing_raised{ Win32::Service.pause(@service_name) }
123
+ wait_for_status('paused')
124
+
125
+ assert_nothing_raised{ Win32::Service.resume(@service_name) }
126
+ wait_for_status('running')
127
+ end
128
+
129
+ test "pausing an already paused service is harmless" do
130
+ start_service(@service_name)
131
+
132
+ assert_nothing_raised{ Win32::Service.pause(@service_name) }
133
+ wait_for_status('paused')
134
+ assert_nothing_raised{ Win32::Service.pause(@service_name) }
135
+ end
136
+
137
+ test "pause requires a service name as an argument" do
138
+ assert_raise(ArgumentError){ Win32::Service.pause }
139
+ end
140
+
141
+ test "pausing an unrecognized service name raises an error" do
142
+ assert_raise(Win32::Service::Error){ Win32::Service.pause('bogus') }
143
+ end
144
+
145
+ test "pausing a service on an unrecognized host raises an error" do
146
+ assert_raise(Win32::Service::Error){ Win32::Service.pause('W32Time', 'bogus') }
147
+ end
148
+
149
+ test "pause method accepts a maximum of two arguments" do
150
+ assert_raise(ArgumentError){ Win32::Service.pause('x', 'y', 'z') }
151
+ end
152
+
153
+ test "resume method requires a service name" do
154
+ assert_raise(ArgumentError){ Win32::Service.resume }
155
+ end
156
+
157
+ test "resume method with an unrecognized service name raises an error" do
158
+ assert_raise(Win32::Service::Error){ Win32::Service.resume('bogus') }
159
+ end
160
+
161
+ test "resume method with an unrecognized host name raises an error" do
162
+ assert_raise(Win32::Service::Error){ Win32::Service.resume('W32Time', 'bogus') }
163
+ end
164
+
165
+ test "resume method accepts a maximum of two arguments" do
166
+ assert_raise(ArgumentError){ Win32::Service.resume('W32Time', @@host, true) }
167
+ end
168
+
169
+ test "stop method basic functionality" do
170
+ assert_respond_to(Win32::Service, :stop)
171
+ end
172
+
173
+ test "start method basic functionality" do
174
+ assert_respond_to(Win32::Service, :start)
175
+ end
176
+
177
+ test "stop and start methods work as expected" do
178
+ start_service(@service_name)
179
+
180
+ assert_nothing_raised{ Win32::Service.stop(@service_name) }
181
+ wait_for_status('stopped')
182
+
183
+ assert_nothing_raised{ Win32::Service.start(@service_name) }
184
+ wait_for_status('running')
185
+ end
186
+
187
+ test "attempting to stop a stopped service raises an error" do
188
+ start_service(@service_name)
189
+
190
+ assert_nothing_raised{ Win32::Service.stop(@service_name) }
191
+ wait_for_status('stopped')
192
+ assert_raise(Win32::Service::Error){ Win32::Service.stop(@service_name) }
193
+
194
+ assert_nothing_raised{ Win32::Service.start(@service_name) }
195
+ end
196
+
197
+ test "stop method requires a service name" do
198
+ assert_raise(ArgumentError){ Win32::Service.stop }
199
+ end
200
+
201
+ test "stop method raises an error if the service name is unrecognized" do
202
+ assert_raise(Win32::Service::Error){ Win32::Service.stop('bogus') }
203
+ end
204
+
205
+ test "stop method raises an error if the host is unrecognized" do
206
+ assert_raise(Win32::Service::Error){ Win32::Service.stop('W32Time', 'bogus') }
207
+ end
208
+
209
+ test "stop metho accepts a maximum of two arguments" do
210
+ assert_raise(ArgumentError){ Win32::Service.stop('W32Time', @@host, true) }
211
+ end
212
+
213
+ test "start method requires a service name" do
214
+ assert_raise(ArgumentError){ Win32::Service.start }
215
+ end
216
+
217
+ test "attempting to start a running service raises an error" do
218
+ assert_raise(Win32::Service::Error){ Win32::Service.start(@service_name) }
219
+ end
220
+
221
+ test "attempting to start an unrecognized service raises an error" do
222
+ assert_raise(Win32::Service::Error){ Win32::Service.start('bogus') }
223
+ end
224
+
225
+ test "attempting to start a service on an unknown host raises an error" do
226
+ assert_raise(Win32::Service::Error){ Win32::Service.start('bogus', 'bogus') }
227
+ end
228
+
229
+ test "stop requires at least one argument" do
230
+ assert_raise(ArgumentError){ Win32::Service.stop }
231
+ end
232
+
233
+ test "stop raises an error with an unrecognized service name" do
234
+ assert_raise(Win32::Service::Error){ Win32::Service.stop('bogus') }
235
+ end
236
+
237
+ test "stop raises an error with an unrecognized host" do
238
+ assert_raise(Win32::Service::Error){ Win32::Service.stop('W32Time', 'bogus') }
239
+ end
240
+
241
+ test "stop accepts a maximum of 2 arguments" do
242
+ assert_raise(ArgumentError){ Win32::Service.stop('a', 'b', 'c') }
243
+ end
244
+
245
+ test "status basic functionality" do
246
+ assert_respond_to(Win32::Service, :status)
247
+ assert_nothing_raised{ Win32::Service.status(@service_name) }
248
+ assert_kind_of(Struct::ServiceStatus, Win32::Service.status(@service_name))
249
+ end
250
+
251
+ test "get_service_name basic functionality" do
252
+ assert_respond_to(Win32::Service, :get_service_name)
253
+ assert_nothing_raised{ Win32::Service.get_service_name(@display_name) }
254
+ assert_kind_of(String, Win32::Service.get_service_name(@display_name))
255
+ end
256
+
257
+ test "get_service_name returns expected results" do
258
+ assert_equal(@service_name, Win32::Service.get_service_name(@display_name))
259
+ end
260
+
261
+ test "getservicename is an alias for get_service_name" do
262
+ assert_respond_to(Win32::Service, :getservicename)
263
+ assert_alias_method(Win32::Service, :getservicename, :get_service_name)
264
+ end
265
+
266
+ test "get_service_name requires at least one argument" do
267
+ assert_raise(ArgumentError){ Win32::Service.get_service_name }
268
+ end
269
+
270
+ test "get_service_name raises an error if a bogus service name is provided" do
271
+ assert_raise(Win32::Service::Error){ Win32::Service.get_service_name('bogus') }
272
+ end
273
+
274
+ test "get_service_name raises an error if a bogus service name is provided" do
275
+ assert_raise(Win32::Service::Error){ Win32::Service.get_service_name('foo','bogus') }
276
+ end
277
+
278
+ test "get_service_name accepts a maximum of two arguments" do
279
+ assert_raise(ArgumentError){ Win32::Service.get_service_name('x', 'y', 'z') }
280
+ end
281
+
282
+ test "get_display_name basic functionality" do
283
+ assert_respond_to(Win32::Service, :get_display_name)
284
+ assert_nothing_raised{ Win32::Service.get_display_name(@service_name) }
285
+ assert_kind_of(String, Win32::Service.get_display_name(@service_name))
286
+ end
287
+
288
+ test "get_display_name returns expected results" do
289
+ assert_equal(@display_name, Win32::Service.get_display_name(@service_name))
290
+ end
291
+
292
+ test "getdisplayname is an alias for get_display_name" do
293
+ assert_respond_to(Win32::Service, :getdisplayname)
294
+ assert_alias_method(Win32::Service, :getdisplayname, :get_display_name)
295
+ end
296
+
297
+ test "get_display_name requires at least one argument" do
298
+ assert_raise(ArgumentError){ Win32::Service.get_display_name }
299
+ end
300
+
301
+ test "get_display_name raises an error if the service does not exist" do
302
+ assert_raise(Win32::Service::Error){ Win32::Service.get_display_name('bogus') }
303
+ end
304
+
305
+ test "get_display_name raises an error if a bad host name is provided" do
306
+ assert_raise(Win32::Service::Error){ Win32::Service.get_display_name('W32Time', 'bogus') }
307
+ end
308
+
309
+ test "get_display_name takes a maximum of two arguments" do
310
+ assert_raise(ArgumentError){ Win32::Service.get_display_name('x', 'y', 'z') }
311
+ end
312
+
313
+ test "exists method basic functionality" do
314
+ assert_respond_to(Win32::Service, :exists?)
315
+ assert_nothing_raised{ Win32::Service.exists?('W32Time') }
316
+ end
317
+
318
+ test "exists method returns expected results" do
319
+ assert_true(Win32::Service.exists?('W32Time'))
320
+ assert_false(Win32::Service.exists?('foobar'))
321
+ end
322
+
323
+ test "exists method requires at least one argument or an error is raised" do
324
+ assert_raises(ArgumentError){ Win32::Service.exists? }
325
+ end
326
+
327
+ test "exists method raises an error if a bogus host is passed" do
328
+ assert_raises(Win32::Service::Error){Win32::Service.exists?('foo', 'bogushost') }
329
+ end
330
+
331
+ test "exists method only accepts up to two arguments" do
332
+ assert_raises(ArgumentError){ Win32::Service.exists?('foo', 'bar', 'baz') }
333
+ end
334
+
335
+ test "scm security constants are defined" do
336
+ assert_not_nil(Win32::Service::MANAGER_ALL_ACCESS)
337
+ assert_not_nil(Win32::Service::MANAGER_CREATE_SERVICE)
338
+ assert_not_nil(Win32::Service::MANAGER_CONNECT)
339
+ assert_not_nil(Win32::Service::MANAGER_ENUMERATE_SERVICE)
340
+ assert_not_nil(Win32::Service::MANAGER_LOCK)
341
+ assert_not_nil(Win32::Service::MANAGER_QUERY_LOCK_STATUS)
342
+ end
343
+
344
+ test "service specific constants are defined" do
345
+ assert_not_nil(Win32::Service::ALL_ACCESS)
346
+ assert_not_nil(Win32::Service::CHANGE_CONFIG)
347
+ assert_not_nil(Win32::Service::ENUMERATE_DEPENDENTS)
348
+ assert_not_nil(Win32::Service::INTERROGATE)
349
+ assert_not_nil(Win32::Service::PAUSE_CONTINUE)
350
+ assert_not_nil(Win32::Service::QUERY_CONFIG)
351
+ assert_not_nil(Win32::Service::QUERY_STATUS)
352
+ assert_not_nil(Win32::Service::STOP)
353
+ assert_not_nil(Win32::Service::START)
354
+ assert_not_nil(Win32::Service::USER_DEFINED_CONTROL)
355
+ end
356
+
357
+ test "service type constants are defined" do
358
+ assert_not_nil(Win32::Service::FILE_SYSTEM_DRIVER)
359
+ assert_not_nil(Win32::Service::KERNEL_DRIVER)
360
+ assert_not_nil(Win32::Service::WIN32_OWN_PROCESS)
361
+ assert_not_nil(Win32::Service::WIN32_SHARE_PROCESS)
362
+ assert_not_nil(Win32::Service::INTERACTIVE_PROCESS)
363
+ end
364
+
365
+ test "service start option constants are defined" do
366
+ assert_not_nil(Win32::Service::AUTO_START)
367
+ assert_not_nil(Win32::Service::BOOT_START)
368
+ assert_not_nil(Win32::Service::DEMAND_START)
369
+ assert_not_nil(Win32::Service::DISABLED)
370
+ assert_not_nil(Win32::Service::SYSTEM_START)
371
+ end
372
+
373
+ test "service error control constants are defined" do
374
+ assert_not_nil(Win32::Service::ERROR_IGNORE)
375
+ assert_not_nil(Win32::Service::ERROR_NORMAL)
376
+ assert_not_nil(Win32::Service::ERROR_SEVERE)
377
+ assert_not_nil(Win32::Service::ERROR_CRITICAL)
378
+ end
379
+
380
+ test "service state constants are defined" do
381
+ assert_not_nil(Win32::Service::CONTINUE_PENDING)
382
+ assert_not_nil(Win32::Service::PAUSE_PENDING)
383
+ assert_not_nil(Win32::Service::PAUSED)
384
+ assert_not_nil(Win32::Service::RUNNING)
385
+ assert_not_nil(Win32::Service::START_PENDING)
386
+ assert_not_nil(Win32::Service::STOP_PENDING)
387
+ assert_not_nil(Win32::Service::STOPPED)
388
+ end
389
+
390
+ def teardown
391
+ @display_name = nil
392
+ @service_name = nil
393
+ @service_stat = nil
394
+ @services = nil
395
+ end
396
+
397
+ def self.shutdown
398
+ @@host = nil
399
+ status = Win32::Service.status(@@service_name).current_state
400
+
401
+ if status == 'paused'
402
+ Win32::Service.resume(@@service_name)
403
+ end
404
+
405
+ unless ['running', 'start pending'].include?(status)
406
+ Win32::Service.start(@@service_name)
407
+ end
408
+ end
409
+ end