win32-service 0.5.2-mswin32

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,406 @@
1
+ ###########################################################################
2
+ # tc_service.rb
3
+ #
4
+ # Test suite for Win32::Service. Note that this test suite will take
5
+ # a few seconds to run. There are some 'sleep' calls sprinkled throughout
6
+ # this code. These are necessary for some of the methods to complete
7
+ # before subsequent tests are run.
8
+ #
9
+ # Also note that if the W32Time or Schedule services aren't running, some
10
+ # of these tests will fail.
11
+ ###########################################################################
12
+
13
+ info = <<HERE
14
+ This test will stop and start your Time service, as well as pause and
15
+ resume your Schedule service. This is harmless unless you are actually
16
+ using these services at the moment you run this test. Is it OK to
17
+ proceed? (y/N)
18
+ HERE
19
+
20
+ puts info
21
+ ans = STDIN.gets.chomp.downcase
22
+ unless ans == 'y'
23
+ puts "Exiting without running test suite..."
24
+ exit!
25
+ end
26
+
27
+ base = File.basename(Dir.pwd)
28
+ if base == "test" || base =~ /win32-service/
29
+ require 'fileutils'
30
+ Dir.chdir("..") if base == "test"
31
+ Dir.mkdir("win32") unless File.exists?("win32")
32
+ FileUtils.cp("service.so", "win32")
33
+ $LOAD_PATH.unshift Dir.pwd
34
+ Dir.chdir("test") rescue nil
35
+ end
36
+
37
+ require 'yaml'
38
+ puts Dir.pwd
39
+ $HASH = YAML.load(File.open('tmp.yml'))
40
+
41
+ puts "This will take a few seconds. Be patient..."
42
+
43
+ require "test/unit"
44
+ require "win32/service"
45
+ require "socket"
46
+ include Win32
47
+
48
+ class TC_Win32Service < Test::Unit::TestCase
49
+ def setup
50
+ @service = Service.new
51
+ @stop_start_service = 'W32Time'
52
+ @pause_resume_service = 'Schedule'
53
+
54
+ # Not to panic - we don't stop or disable these services in this test.
55
+ # These are only used for getting the service name and display name.
56
+ @dname = "Remote Procedure Call (RPC)"
57
+ @sname = "dmadmin"
58
+ end
59
+
60
+ def test_version
61
+ assert_equal("0.5.2", Service::VERSION, "Bad version")
62
+ end
63
+
64
+ def test_class_type
65
+ assert_kind_of(Win32::Service, @service)
66
+ end
67
+
68
+ def test_open
69
+ assert_respond_to(Service, :open)
70
+ assert_nothing_raised{ Service.open(@stop_start_service){} }
71
+ assert_nothing_raised{ @service = Service.open(@stop_start_service) }
72
+ assert_nil(Service.open(@stop_start_service){})
73
+ assert_kind_of(Win32::Service, @service )
74
+ end
75
+
76
+ def test_machine_name
77
+ assert_respond_to(@service, :machine_name)
78
+ assert_respond_to(@service, :machine_name=)
79
+ assert_nothing_raised{ @service.machine_name }
80
+ assert_nothing_raised{ @service.machine_name = Socket.gethostname }
81
+ end
82
+
83
+ def test_machine_name_expected_errors
84
+ assert_raises(ArgumentError){ @service.machine_name(1) }
85
+ end
86
+
87
+ def test_service_name
88
+ assert_respond_to(@service, :service_name)
89
+ assert_respond_to(@service, :service_name=)
90
+ assert_nothing_raised{ @service.service_name }
91
+ assert_nothing_raised{ @service.service_name = 'foo' }
92
+ end
93
+
94
+ def test_service_name_expected_errors
95
+ assert_raises(ArgumentError){ @service.service_name(1) }
96
+ end
97
+
98
+ def test_display_name
99
+ assert_respond_to(@service, :display_name)
100
+ assert_respond_to(@service, :display_name=)
101
+ assert_nothing_raised{ @service.display_name }
102
+ assert_nothing_raised{ @service.display_name = "foosvc" }
103
+ end
104
+
105
+ def test_display_name_expected_errors
106
+ assert_raises(ArgumentError){ @service.display_name(1) }
107
+ end
108
+
109
+ def test_binary_path_name
110
+ assert_respond_to(@service, :binary_path_name)
111
+ assert_respond_to(@service, :binary_path_name=)
112
+ assert_nothing_raised{ @service.binary_path_name }
113
+ assert_nothing_raised{ @service.binary_path_name = "C:/foo/bar" }
114
+ end
115
+
116
+ def test_binary_path_name_expected_errors
117
+ assert_raises(ArgumentError){ @service.binary_path_name(1) }
118
+ end
119
+
120
+ def test_load_order_group
121
+ assert_respond_to(@service, :load_order_group)
122
+ assert_respond_to(@service, :load_order_group=)
123
+ assert_nothing_raised{ @service.load_order_group }
124
+ assert_nothing_raised{ @service.load_order_group = 'foo' }
125
+ end
126
+
127
+ def test_load_order_group_expected_errors
128
+ assert_raises(ArgumentError){ @service.load_order_group(1) }
129
+ end
130
+
131
+ def test_dependencies
132
+ assert_respond_to(@service, :dependencies)
133
+ assert_respond_to(@service, :dependencies=)
134
+ assert_nothing_raised{ @service.dependencies = ['foo', "bar"] }
135
+ end
136
+
137
+ def test_dependencies_expected_errors
138
+ assert_raises(ArgumentError){ @service.dependencies(1) }
139
+ assert_raises(TypeError){ @service.dependencies = 'foo' }
140
+ assert_raises(TypeError){ @service.dependencies = 1 }
141
+ end
142
+
143
+ def test_start_name
144
+ assert_respond_to(@service, :start_name)
145
+ assert_respond_to(@service, :start_name=)
146
+ assert_nothing_raised{ @service.start_name }
147
+ assert_nothing_raised{ @service.start_name = 'foo' }
148
+ end
149
+
150
+ def test_start_name_expected_errors
151
+ assert_raises(ArgumentError){ @service.start_name(1) }
152
+ end
153
+
154
+ def test_password
155
+ assert_respond_to(@service, :password)
156
+ assert_respond_to(@service, :password=)
157
+ assert_nothing_raised{ @service.password }
158
+ assert_nothing_raised{ @service.password = "mypass" }
159
+ end
160
+
161
+ def test_password_expected_errors
162
+ assert_raises(ArgumentError){ @service.password(1) }
163
+ end
164
+
165
+ def test_error_control
166
+ assert_respond_to(@service, :error_control)
167
+ assert_respond_to(@service, :error_control=)
168
+ assert_nothing_raised{ @service.error_control }
169
+ assert_nothing_raised{ @service.error_control = "test" }
170
+ end
171
+
172
+ def test_error_control_expected_errors
173
+ assert_raises(ArgumentError){ @service.error_control(1) }
174
+ end
175
+
176
+ def test_start_type
177
+ assert_respond_to(@service, :start_type)
178
+ assert_respond_to(@service, :start_type=)
179
+ assert_nothing_raised{ @service.start_type }
180
+ assert_nothing_raised{ @service.start_type = Service::DEMAND_START }
181
+ end
182
+
183
+ def test_start_type_expected_errors
184
+ assert_raises(ArgumentError){ @service.start_type(1) }
185
+ end
186
+
187
+ def test_desired_access
188
+ assert_respond_to(@service, :desired_access)
189
+ assert_respond_to(@service, :desired_access=)
190
+ assert_nothing_raised{ @service.desired_access }
191
+ assert_nothing_raised{ @service.desired_access = Service::MANAGER_LOCK }
192
+ end
193
+
194
+ def test_desired_access_expected_errors
195
+ assert_raises(ArgumentError){ @service.desired_access(1) }
196
+ end
197
+
198
+ def test_service_type
199
+ assert_respond_to(@service, :service_type)
200
+ assert_respond_to(@service, :service_type=)
201
+ assert_nothing_raised{ @service.service_type }
202
+ assert_nothing_raised{
203
+ @service.service_type = Service::WIN32_OWN_PROCESS
204
+ }
205
+ end
206
+
207
+ def test_service_type_expected_errors
208
+ assert_raises(ArgumentError){ @service.service_type(1) }
209
+ end
210
+
211
+ def test_constructor_arguments
212
+ assert_nothing_raised{ Service.new{} }
213
+ assert_nothing_raised{ Service.new(Socket.gethostname){} }
214
+ assert_nothing_raised{
215
+ Service.new(Socket.gethostname, Service::MANAGER_ALL_ACCESS){}
216
+ }
217
+ end
218
+
219
+ def test_constructor_expected_errors
220
+ assert_raises(ArgumentError){ Service.new("test", 1, 1){} }
221
+ assert_raises(TypeError){ Service.new(1){} }
222
+ end
223
+
224
+ # This occasionally fails for some reason with an error about an invalid
225
+ # handle value. I'm not sure why.
226
+ def test_services
227
+ assert_respond_to(Service, :services)
228
+ assert_nothing_raised{ Service.services{ } }
229
+ assert_nothing_raised{ Service.services }
230
+ assert_kind_of(Array, Service.services)
231
+ assert_kind_of(Struct::Win32Service, Service.services.first)
232
+ end
233
+
234
+ def test_services_expected_errors
235
+ assert_raises(TypeError){ Service.services(1) }
236
+ end
237
+
238
+ # This test will fail if the W32Time service isn't started.
239
+ def test_stop_start
240
+ assert_nothing_raised{ Service.stop(@stop_start_service) }
241
+ sleep 3
242
+ assert_nothing_raised{ Service.start(@stop_start_service) }
243
+ end
244
+
245
+ def test_start_failure
246
+ assert_raises(ServiceError){ Service.start('bogus') }
247
+ assert_raises(ServiceError){ Service.start('winmgmt') }
248
+ end
249
+
250
+ # Trying to stop a non-existant should fail, as well as trying to
251
+ # pause a service that isn't running. Here I use the Telnet server for
252
+ # the latter case because it is disabled by default.
253
+ #
254
+ def test_stop_failure
255
+ assert_raises(ServiceError){ Service.stop('bogus') }
256
+ assert_raises(ServiceError){ Service.stop('TlntSvr') }
257
+ end
258
+
259
+ # Trying to pause a non-existant should fail, as well as trying to
260
+ # pause a service that isn't running. Here I use the Telnet server for
261
+ # the latter case because it is disabled by default.
262
+ #
263
+ def test_pause_failure
264
+ assert_raises(ServiceError){ Service.pause('bogus') }
265
+ assert_raises(ServiceError){ Service.pause('TlntSvr') }
266
+ end
267
+
268
+ # Trying to resume a non-existant should fail, as well as trying to
269
+ # resume a service that is already running.
270
+ #
271
+ def test_resume_failure
272
+ assert_raises(ServiceError){ Service.resume('bogus') }
273
+ assert_raises(ServiceError){ Service.resume('W32Time') }
274
+ end
275
+
276
+ def test_pause_resume
277
+ assert_nothing_raised{ Service.pause(@pause_resume_service) }
278
+ sleep 2
279
+ assert_nothing_raised{ Service.resume(@pause_resume_service) }
280
+ sleep 2
281
+ end
282
+
283
+ def test_getservicename
284
+ assert_respond_to(Service, :getservicename)
285
+ assert_nothing_raised{ Service.getservicename(@dname) }
286
+ assert_kind_of(String, Service.getservicename(@dname))
287
+ end
288
+
289
+ def test_getdisplayname
290
+ assert_respond_to(Service, :getdisplayname)
291
+ assert_nothing_raised{ Service.getdisplayname(@sname) }
292
+ assert_kind_of(String, Service.getdisplayname(@sname))
293
+ end
294
+
295
+ def test_create_delete
296
+ assert_nothing_raised{
297
+ @service.create_service{ |s|
298
+ s.service_name = 'foo'
299
+ s.display_name = "Foo Test"
300
+ s.binary_path_name = "C:\\ruby\\bin\\rubyw.exe -v"
301
+ }
302
+ }
303
+ sleep 2
304
+ assert_nothing_raised{ Service.delete('foo') }
305
+ sleep 2
306
+ assert_raises(ServiceError){ Service.delete('foo') }
307
+ end
308
+
309
+ def test_configure_service
310
+ assert_nothing_raised{
311
+ @service.configure_service{ |s|
312
+ s.service_name = 'W32Time'
313
+ s.display_name = "Hammer Time"
314
+ }
315
+ }
316
+ sleep 2
317
+ assert_nothing_raised{
318
+ @service.configure_service{ |s|
319
+ s.service_name = 'W32Time'
320
+ s.display_name = "Windows Time"
321
+ }
322
+ }
323
+ end
324
+
325
+ def test_configure_expected_errors
326
+ assert_raises(LocalJumpError){ @service.configure_service }
327
+ end
328
+
329
+ def test_status
330
+ members = %w/service_type current_state controls_accepted/
331
+ members.push(%w/win32_exit_code service_specific_exit_code/)
332
+ members.push(%w/check_point wait_hint interactive/)
333
+
334
+ if $HASH['HAVE_QUERYSERVICESTATUSEX']
335
+ members.push(%w/pid service_flags/)
336
+ end
337
+ members.flatten!
338
+
339
+ assert_nothing_raised{ Service.status('W32Time') }
340
+ struct = Service.status('W32Time')
341
+ assert_kind_of(Struct::Win32ServiceStatus, struct)
342
+ assert_equal(members, struct.members)
343
+ end
344
+
345
+ def test_constants
346
+ assert_not_nil(Service::MANAGER_ALL_ACCESS)
347
+ assert_not_nil(Service::MANAGER_CREATE_SERVICE)
348
+ assert_not_nil(Service::MANAGER_CONNECT)
349
+ assert_not_nil(Service::MANAGER_ENUMERATE_SERVICE)
350
+ assert_not_nil(Service::MANAGER_LOCK)
351
+ #assert_not_nil(Service::MANAGER_BOOT_CONFIG)
352
+ assert_not_nil(Service::MANAGER_QUERY_LOCK_STATUS)
353
+
354
+ assert_not_nil(Service::ALL_ACCESS)
355
+ assert_not_nil(Service::CHANGE_CONFIG)
356
+ assert_not_nil(Service::ENUMERATE_DEPENDENTS)
357
+ assert_not_nil(Service::INTERROGATE)
358
+ assert_not_nil(Service::PAUSE_CONTINUE)
359
+ assert_not_nil(Service::QUERY_CONFIG)
360
+ assert_not_nil(Service::QUERY_STATUS)
361
+ assert_not_nil(Service::STOP)
362
+ assert_not_nil(Service::START)
363
+ assert_not_nil(Service::USER_DEFINED_CONTROL)
364
+
365
+ assert_not_nil(Service::FILE_SYSTEM_DRIVER)
366
+ assert_not_nil(Service::KERNEL_DRIVER)
367
+ assert_not_nil(Service::WIN32_OWN_PROCESS)
368
+ assert_not_nil(Service::WIN32_SHARE_PROCESS)
369
+ assert_not_nil(Service::INTERACTIVE_PROCESS)
370
+
371
+ assert_not_nil(Service::AUTO_START)
372
+ assert_not_nil(Service::BOOT_START)
373
+ assert_not_nil(Service::DEMAND_START)
374
+ assert_not_nil(Service::DISABLED)
375
+ assert_not_nil(Service::SYSTEM_START)
376
+
377
+ assert_not_nil(Service::ERROR_IGNORE)
378
+ assert_not_nil(Service::ERROR_NORMAL)
379
+ assert_not_nil(Service::ERROR_SEVERE)
380
+ assert_not_nil(Service::ERROR_CRITICAL)
381
+
382
+ assert_not_nil(Service::CONTINUE_PENDING)
383
+ assert_not_nil(Service::PAUSE_PENDING)
384
+ assert_not_nil(Service::PAUSED)
385
+ assert_not_nil(Service::RUNNING)
386
+ assert_not_nil(Service::START_PENDING)
387
+ assert_not_nil(Service::STOP_PENDING)
388
+ assert_not_nil(Service::STOPPED)
389
+ end
390
+
391
+ def test_exists
392
+ assert_nothing_raised{ Service.exists?('W32Time') }
393
+ assert_raises(ArgumentError){ Service.exists? }
394
+ assert_equal(true, Service.exists?('W32Time'))
395
+ assert_equal(false, Service.exists?('foobar'))
396
+ end
397
+
398
+ def teardown
399
+ begin
400
+ @service.close
401
+ rescue ServiceError
402
+ # Ignore - not sure why this happens
403
+ end
404
+ @service = nil
405
+ end
406
+ end
metadata ADDED
@@ -0,0 +1,59 @@
1
+ --- !ruby/object:Gem::Specification
2
+ rubygems_version: 0.9.0
3
+ specification_version: 1
4
+ name: win32-service
5
+ version: !ruby/object:Gem::Version
6
+ version: 0.5.2
7
+ date: 2006-12-05 00:00:00 -07:00
8
+ summary: An interface for MS Windows services
9
+ require_paths:
10
+ - lib
11
+ email: djberg96@gmail.com
12
+ homepage: http://www.rubyforge.org/projects/win32utils
13
+ rubyforge_project: win32utils
14
+ description: An interface for MS Windows services
15
+ autorequire:
16
+ default_executable:
17
+ bindir: bin
18
+ has_rdoc: true
19
+ required_ruby_version: !ruby/object:Gem::Version::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 1.8.2
24
+ version:
25
+ platform: mswin32
26
+ signing_key:
27
+ cert_chain:
28
+ post_install_message:
29
+ authors:
30
+ - Daniel J. Berger
31
+ files:
32
+ - doc/daemon.txt
33
+ - doc/service.txt
34
+ - test/tc_daemon.rb
35
+ - test/tc_service.rb
36
+ - lib/win32/service.c
37
+ - lib/win32/service.h
38
+ - lib/win32/service.so
39
+ - CHANGES
40
+ - README
41
+ - MANIFEST
42
+ test_files:
43
+ - test/tc_service.rb
44
+ rdoc_options: []
45
+
46
+ extra_rdoc_files:
47
+ - CHANGES
48
+ - README
49
+ - MANIFEST
50
+ - doc/service.txt
51
+ - doc/daemon.txt
52
+ executables: []
53
+
54
+ extensions: []
55
+
56
+ requirements: []
57
+
58
+ dependencies: []
59
+