win32-service 0.5.2 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,27 +1,23 @@
1
1
  #########################################################################
2
2
  # tc_daemon.rb
3
3
  #
4
- # Test suite for the Daemon class
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.
5
9
  #########################################################################
6
- if File.basename(Dir.pwd) == "test"
7
- require "ftools"
8
- Dir.chdir ".."
9
- Dir.mkdir("win32") unless File.exists?("win32")
10
- File.copy("service.so","win32")
11
- $LOAD_PATH.unshift Dir.pwd
12
- end
13
-
14
- require "win32/service"
15
- require "test/unit"
10
+ require 'win32/daemon'
11
+ require 'test/unit'
16
12
  include Win32
17
13
 
18
14
  class TC_Daemon < Test::Unit::TestCase
19
15
  def setup
20
- @d = Daemon.new
16
+ @daemon = Daemon.new
21
17
  end
22
18
 
23
19
  def test_version
24
- assert_equal("0.5.2", Daemon::VERSION)
20
+ assert_equal('0.6.0', Daemon::VERSION)
25
21
  end
26
22
 
27
23
  def test_constructor
@@ -31,15 +27,15 @@ class TC_Daemon < Test::Unit::TestCase
31
27
  end
32
28
 
33
29
  def test_mainloop
34
- assert_respond_to(@d, :mainloop)
30
+ assert_respond_to(@daemon, :mainloop)
35
31
  end
36
32
 
37
33
  def test_state
38
- assert_respond_to(@d, :state)
34
+ assert_respond_to(@daemon, :state)
39
35
  end
40
36
 
41
37
  def test_running
42
- assert_respond_to(@d, :running?)
38
+ assert_respond_to(@daemon, :running?)
43
39
  end
44
40
 
45
41
  def test_constants
@@ -54,6 +50,6 @@ class TC_Daemon < Test::Unit::TestCase
54
50
  end
55
51
 
56
52
  def teardown
57
- @d = nil
53
+ @daemon = nil
58
54
  end
59
- end
55
+ end
@@ -1,406 +1,260 @@
1
- ###########################################################################
1
+ ##########################################################################
2
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
- ###########################################################################
3
+ #
4
+ # Test case for the Win32::Service class.
5
+ ##########################################################################
6
+ require 'win32/service'
7
+ require 'socket'
8
+ require 'test/unit'
12
9
 
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
10
+ class TC_Win32_Service < Test::Unit::TestCase
49
11
  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) }
12
+ @display_name = "Task Scheduler"
13
+ @service_name = "Schedule"
14
+ @service_stat = nil
15
+ @services = []
163
16
  end
164
17
 
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" }
18
+ def wait_for_status(status)
19
+ sleep 0.1 while Win32::Service.status(@service_name).current_state != status
170
20
  end
171
-
172
- def test_error_control_expected_errors
173
- assert_raises(ArgumentError){ @service.error_control(1) }
21
+
22
+ def test_version
23
+ assert_equal('0.6.0', Win32::Service::VERSION)
174
24
  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 }
25
+
26
+ def test_service_configure
27
+ assert_respond_to(Win32::Service, :configure)
181
28
  end
182
29
 
183
- def test_start_type_expected_errors
184
- assert_raises(ArgumentError){ @service.start_type(1) }
30
+ def test_service_configure_expected_errors
31
+ assert_raise(ArgumentError){ Win32::Service.configure }
32
+ assert_raise(ArgumentError){ Win32::Service.configure('bogus') }
33
+ assert_raise(ArgumentError){ Win32::Service.configure('bogus', 'bogus') }
34
+ assert_raise(Win32::Service::Error){ Win32::Service.configure('x', nil, :description => 'Test') }
35
+ assert_raise(Win32::Service::Error){ Win32::Service.configure('x', 'y', :description => 'Test') }
185
36
  end
186
37
 
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 }
38
+ def test_services_basic
39
+ assert_respond_to(Win32::Service, :services)
40
+ assert_nothing_raised{ Win32::Service.services }
41
+ assert_nothing_raised{ Win32::Service.services(nil) }
42
+ assert_nothing_raised{ Win32::Service.services(nil, 'network') }
192
43
  end
193
44
 
194
- def test_desired_access_expected_errors
195
- assert_raises(ArgumentError){ @service.desired_access(1) }
45
+ def test_services_non_block_form
46
+ assert_nothing_raised{ @services = Win32::Service.services }
47
+ assert_kind_of(Array, @services)
48
+ assert_kind_of(Struct::ServiceInfo, @services[0])
196
49
  end
197
50
 
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
- }
51
+ def test_services_block_form
52
+ assert_nothing_raised{ Win32::Service.services{ |s| @services << s } }
53
+ assert_kind_of(Array, @services)
54
+ assert_kind_of(Struct::ServiceInfo, @services[0])
205
55
  end
206
-
207
- def test_service_type_expected_errors
208
- assert_raises(ArgumentError){ @service.service_type(1) }
56
+
57
+ def test_services_expected_errors
58
+ assert_raise(TypeError){ Win32::Service.services(1) }
59
+ assert_raise(TypeError){ Win32::Service.services(nil, 1) }
60
+ assert_raise(ArgumentError){ Win32::Service.services(nil, 'network', 1) }
61
+ assert_raise(Win32::Service::Error){ Win32::Service.services('bogus') }
62
+ end
63
+
64
+ def test_delete
65
+ assert_respond_to(Win32::Service, :delete)
66
+ end
67
+
68
+ def test_delete_expected_errors
69
+ assert_raise(ArgumentError){ Win32::Service.delete }
70
+ assert_raise(Win32::Service::Error){ Win32::Service.delete('bogus') }
71
+ assert_raise(Win32::Service::Error){ Win32::Service.delete('bogus', 'bogus') }
72
+ assert_raise(ArgumentError){ Win32::Service.delete('x', 'y', 'z') }
73
+ end
74
+
75
+ def test_service_pause_and_resume
76
+ assert_respond_to(Win32::Service, :pause)
77
+ assert_respond_to(Win32::Service, :resume)
78
+ assert_nothing_raised{ Win32::Service.pause(@service_name) }
79
+ assert_nothing_raised{ wait_for_status('paused') }
80
+ assert_nothing_raised{ Win32::Service.pause(@service_name) }
81
+ assert_nothing_raised{ Win32::Service.resume(@service_name) }
82
+ assert_nothing_raised{ wait_for_status('running') }
83
+ end
84
+
85
+ def test_pause_expected_errors
86
+ assert_raise(ArgumentError){ Win32::Service.pause }
87
+ assert_raise(Win32::Service::Error){ Win32::Service.pause('bogus') }
88
+ assert_raise(Win32::Service::Error){ Win32::Service.pause('bogus', 'bogus') }
89
+ assert_raise(ArgumentError){ Win32::Service.pause('x', 'y', 'z') }
90
+ end
91
+
92
+ def test_resume_expected_errors
93
+ assert_raise(ArgumentError){ Win32::Service.resume }
94
+ assert_raise(Win32::Service::Error){ Win32::Service.resume('bogus') }
95
+ assert_raise(Win32::Service::Error){ Win32::Service.resume('bogus', 'bogus') }
96
+ assert_raise(ArgumentError){ Win32::Service.resume('bogus', 'bogus', 'a') }
97
+ end
98
+
99
+ def test_service_stop_and_start
100
+ assert_respond_to(Win32::Service, :stop)
101
+ assert_respond_to(Win32::Service, :start)
102
+ assert_nothing_raised{ Win32::Service.stop(@service_name) }
103
+ assert_nothing_raised{ wait_for_status('stopped') }
104
+ assert_raise(Win32::Service::Error){ Win32::Service.stop(@service_name) }
105
+ assert_nothing_raised{ Win32::Service.start(@service_name) }
106
+ assert_nothing_raised{ wait_for_status('running') }
107
+ end
108
+
109
+ def test_stop_expected_errors
110
+ assert_raise(ArgumentError){ Win32::Service.stop }
111
+ assert_raise(Win32::Service::Error){ Win32::Service.stop('bogus') }
112
+ assert_raise(Win32::Service::Error){ Win32::Service.stop('bogus', 'bogus') }
113
+ assert_raise(ArgumentError){ Win32::Service.stop('x', 'y', 'z') }
114
+ end
115
+
116
+ def test_start_expected_errors
117
+ assert_raise(ArgumentError){ Win32::Service.start }
118
+ assert_raise(Win32::Service::Error){ Win32::Service.start(@service_name) } # Started
119
+ assert_raise(Win32::Service::Error){ Win32::Service.start('bogus') }
120
+ assert_raise(Win32::Service::Error){ Win32::Service.start('bogus', 'bogus') }
121
+ assert_raise(Win32::Service::Error){ Win32::Service.start('bogus', 'bogus', 'a') }
122
+ assert_raise(Win32::Service::Error){ Win32::Service.start('a', 'b', 'c', 'd') }
123
+ end
124
+
125
+ def test_service_stop_expected_errors
126
+ assert_raise(ArgumentError){ Win32::Service.stop }
127
+ assert_raise(Win32::Service::Error){ Win32::Service.stop('bogus') }
128
+ assert_raise(Win32::Service::Error){ Win32::Service.stop('bogus', 'bogus') }
129
+ assert_raise(ArgumentError){ Win32::Service.stop('a', 'b', 'c') }
209
130
  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
- }
131
+
132
+ def test_service_status_basic
133
+ assert_respond_to(Win32::Service, :status)
134
+ assert_nothing_raised{ Win32::Service.status(@service_name) }
135
+ assert_kind_of(Struct::ServiceStatus, Win32::Service.status(@service_name))
217
136
  end
218
-
219
- def test_constructor_expected_errors
220
- assert_raises(ArgumentError){ Service.new("test", 1, 1){} }
221
- assert_raises(TypeError){ Service.new(1){} }
137
+
138
+ def test_service_get_service_name_basic
139
+ assert_respond_to(Win32::Service, :get_service_name)
140
+ assert_nothing_raised{ Win32::Service.get_service_name(@display_name) }
141
+ assert_kind_of(String, Win32::Service.get_service_name(@display_name))
222
142
  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)
143
+
144
+ def test_service_getservicename_alias_basic
145
+ assert_respond_to(Win32::Service, :getservicename)
146
+ assert_nothing_raised{ Win32::Service.getservicename(@display_name) }
147
+ assert_kind_of(String, Win32::Service.getservicename(@display_name))
232
148
  end
233
-
234
- def test_services_expected_errors
235
- assert_raises(TypeError){ Service.services(1) }
149
+
150
+ def test_service_get_service_name
151
+ assert_equal(@service_name, Win32::Service.get_service_name(@display_name))
152
+ assert_equal(@service_name, Win32::Service.getservicename(@display_name))
236
153
  end
237
154
 
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) }
155
+ def test_service_get_service_name_expected_errors
156
+ assert_raise(ArgumentError){ Win32::Service.get_service_name }
157
+ assert_raise(Win32::Service::Error){ Win32::Service.get_service_name('bogus') }
158
+ assert_raise(Win32::Service::Error){ Win32::Service.get_service_name('foo','bogus') }
159
+ assert_raise(ArgumentError){ Win32::Service.get_service_name('x', 'y', 'z') }
243
160
  end
244
161
 
245
- def test_start_failure
246
- assert_raises(ServiceError){ Service.start('bogus') }
247
- assert_raises(ServiceError){ Service.start('winmgmt') }
162
+ def test_service_get_display_name_basic
163
+ assert_respond_to(Win32::Service, :get_display_name)
164
+ assert_nothing_raised{ Win32::Service.get_display_name(@service_name) }
165
+ assert_kind_of(String, Win32::Service.get_display_name(@service_name))
248
166
  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') }
167
+
168
+ def test_service_getdisplayname_alias_basic
169
+ assert_respond_to(Win32::Service, :getdisplayname)
170
+ assert_nothing_raised{ Win32::Service.getdisplayname(@service_name) }
171
+ assert_kind_of(String, Win32::Service.getdisplayname(@service_name))
257
172
  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') }
173
+
174
+ def test_service_get_display_name
175
+ assert_equal(@display_name, Win32::Service.get_display_name(@service_name))
176
+ assert_equal(@display_name, Win32::Service.getdisplayname(@service_name))
266
177
  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') }
178
+
179
+ def test_service_get_display_name_expected_errors
180
+ assert_raise(ArgumentError){ Win32::Service.get_display_name }
181
+ assert_raise(Win32::Service::Error){ Win32::Service.get_display_name('bogus') }
182
+ assert_raise(Win32::Service::Error){ Win32::Service.get_display_name('foo','bogus') }
183
+ assert_raise(ArgumentError){ Win32::Service.get_display_name('x', 'y', 'z') }
274
184
  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
185
+
186
+ def test_service_exists
187
+ assert_respond_to(Win32::Service, :exists?)
188
+ assert_nothing_raised{ Win32::Service.exists?('W32Time') }
189
+ assert_equal(true, Win32::Service.exists?('W32Time'))
190
+ assert_equal(false, Win32::Service.exists?('foobar'))
281
191
  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))
192
+
193
+ def test_service_exists_expected_errors
194
+ assert_raises(ArgumentError){ Win32::Service.exists? }
195
+ assert_raises(Win32::Service::Error){Win32::Service.exists?('foo', 'bogushost') }
196
+ assert_raises(ArgumentError){ Win32::Service.exists?('foo', 'bar', 'baz') }
287
197
  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))
198
+
199
+ def test_scm_security_constants
200
+ assert_not_nil(Win32::Service::MANAGER_ALL_ACCESS)
201
+ assert_not_nil(Win32::Service::MANAGER_CREATE_SERVICE)
202
+ assert_not_nil(Win32::Service::MANAGER_CONNECT)
203
+ assert_not_nil(Win32::Service::MANAGER_ENUMERATE_SERVICE)
204
+ assert_not_nil(Win32::Service::MANAGER_LOCK)
205
+ assert_not_nil(Win32::Service::MANAGER_QUERY_LOCK_STATUS)
293
206
  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') }
207
+
208
+ def test_service_specific_constants
209
+ assert_not_nil(Win32::Service::ALL_ACCESS)
210
+ assert_not_nil(Win32::Service::CHANGE_CONFIG)
211
+ assert_not_nil(Win32::Service::ENUMERATE_DEPENDENTS)
212
+ assert_not_nil(Win32::Service::INTERROGATE)
213
+ assert_not_nil(Win32::Service::PAUSE_CONTINUE)
214
+ assert_not_nil(Win32::Service::QUERY_CONFIG)
215
+ assert_not_nil(Win32::Service::QUERY_STATUS)
216
+ assert_not_nil(Win32::Service::STOP)
217
+ assert_not_nil(Win32::Service::START)
218
+ assert_not_nil(Win32::Service::USER_DEFINED_CONTROL)
307
219
  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
- }
220
+
221
+ def test_service_type_constants
222
+ assert_not_nil(Win32::Service::FILE_SYSTEM_DRIVER)
223
+ assert_not_nil(Win32::Service::KERNEL_DRIVER)
224
+ assert_not_nil(Win32::Service::WIN32_OWN_PROCESS)
225
+ assert_not_nil(Win32::Service::WIN32_SHARE_PROCESS)
226
+ assert_not_nil(Win32::Service::INTERACTIVE_PROCESS)
323
227
  end
324
-
325
- def test_configure_expected_errors
326
- assert_raises(LocalJumpError){ @service.configure_service }
228
+
229
+ def test_service_start_option_constants
230
+ assert_not_nil(Win32::Service::AUTO_START)
231
+ assert_not_nil(Win32::Service::BOOT_START)
232
+ assert_not_nil(Win32::Service::DEMAND_START)
233
+ assert_not_nil(Win32::Service::DISABLED)
234
+ assert_not_nil(Win32::Service::SYSTEM_START)
327
235
  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
236
 
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)
237
+ def test_service_error_control_constants
238
+ assert_not_nil(Win32::Service::ERROR_IGNORE)
239
+ assert_not_nil(Win32::Service::ERROR_NORMAL)
240
+ assert_not_nil(Win32::Service::ERROR_SEVERE)
241
+ assert_not_nil(Win32::Service::ERROR_CRITICAL)
389
242
  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'))
243
+
244
+ def test_service_state_constants
245
+ assert_not_nil(Win32::Service::CONTINUE_PENDING)
246
+ assert_not_nil(Win32::Service::PAUSE_PENDING)
247
+ assert_not_nil(Win32::Service::PAUSED)
248
+ assert_not_nil(Win32::Service::RUNNING)
249
+ assert_not_nil(Win32::Service::START_PENDING)
250
+ assert_not_nil(Win32::Service::STOP_PENDING)
251
+ assert_not_nil(Win32::Service::STOPPED)
396
252
  end
397
253
 
398
254
  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
255
+ @display_name = nil
256
+ @service_name = nil
257
+ @service_stat = nil
258
+ @services = nil
259
+ end
260
+ end