win32-service 1.0.1 → 2.1.2

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.
@@ -1,110 +0,0 @@
1
- #######################################################################
2
- # test_win32_service_configure.rb
3
- #
4
- # Test suite that validates the Service.configure method.
5
- #######################################################################
6
- require 'test-unit'
7
- require 'win32/security'
8
- require 'win32/service'
9
-
10
- class TC_Win32_Service_Configure < Test::Unit::TestCase
11
- def self.startup
12
- @@service = "notepad_service"
13
- @@command = "C:\\windows\\system32\\notepad.exe"
14
-
15
- if Win32::Security.elevated_security?
16
- Win32::Service.new(
17
- :service_name => @@service,
18
- :binary_path_name => @@command
19
- )
20
- end
21
- end
22
-
23
- def config_info
24
- Win32::Service.config_info(@@service)
25
- end
26
-
27
- def full_info
28
- service = nil
29
- Win32::Service.services{ |s|
30
- if s.service_name == @@service
31
- service = s
32
- break
33
- end
34
- }
35
- service
36
- end
37
-
38
- def service_configure(opt)
39
- options = {:service_name => @@service}
40
- options = options.merge(opt)
41
- assert_nothing_raised{ Win32::Service.configure(options) }
42
- end
43
-
44
- def setup
45
- @elevated = Win32::Security.elevated_security?
46
- @info = Win32::Service.config_info(@@service) if @elevated
47
- end
48
-
49
- test "configure method is defined" do
50
- assert_respond_to(Win32::Service, :configure)
51
- end
52
-
53
- test "configuring the service type works as expected" do
54
- omit_unless(@elevated)
55
- assert_equal('own process', config_info.service_type)
56
- service_configure(:service_type => Win32::Service::WIN32_SHARE_PROCESS)
57
- assert_equal('share process', config_info.service_type)
58
- end
59
-
60
- test "configuring the description works as expected" do
61
- omit_unless(@elevated)
62
- assert_equal('', full_info.description)
63
- service_configure(:description => 'test service')
64
- assert_equal('test service', full_info.description)
65
- end
66
-
67
- test "configuring the start type works as expected" do
68
- omit_unless(@elevated)
69
- assert_equal('demand start', config_info.start_type)
70
- service_configure(:start_type => Win32::Service::DISABLED)
71
- assert_equal('disabled', config_info.start_type)
72
- end
73
-
74
- test "service start can be delayed" do
75
- omit_unless(@elevated)
76
- service_configure(:start_type => Win32::Service::AUTO_START, :delayed_start => true)
77
- assert_equal(1, full_info.delayed_start)
78
- end
79
-
80
- test "the configure method requires one argument" do
81
- assert_raise(ArgumentError){ Win32::Service.configure }
82
- end
83
-
84
- test "the configure method requires a hash argument" do
85
- assert_raise(ArgumentError){ Win32::Service.configure('bogus') }
86
- end
87
-
88
- test "the hash argument must not be empty" do
89
- assert_raise(ArgumentError){ Win32::Service.configure({}) }
90
- end
91
-
92
- test "the service name must be provided or an error is raised" do
93
- assert_raise(ArgumentError){
94
- Win32::Service.configure(:binary_path_name => 'notepad.exe')
95
- }
96
- end
97
-
98
- def teardown
99
- @info = nil
100
- @elevated = nil
101
- end
102
-
103
- def self.shutdown
104
- if Win32::Service.exists?(@@service) && Win32::Security.elevated_security?
105
- Win32::Service.delete(@@service)
106
- end
107
- @@service = nil
108
- @@command = nil
109
- end
110
- end
@@ -1,153 +0,0 @@
1
- ########################################################################
2
- # test_win32_service_create.rb
3
- #
4
- # Test case for the Service.create method. This test case will create
5
- # a dummy (notepad) service. It won't actually run of course.
6
- ########################################################################
7
- require 'test-unit'
8
- require 'win32/security'
9
- require 'win32/service'
10
-
11
- class TC_Win32_Service_Create < Test::Unit::TestCase
12
- def self.startup
13
- @@service1 = "notepad_service1"
14
- @@service2 = "notepad_service2"
15
- @@command = "C:\\windows\\system32\\notepad.exe"
16
-
17
- if Win32::Security.elevated_security?
18
- Win32::Service.new(
19
- :service_name => @@service1,
20
- :binary_path_name => @@command
21
- )
22
-
23
- Win32::Service.new(
24
- :service_name => @@service2,
25
- :display_name => 'Notepad Test',
26
- :desired_access => Win32::Service::ALL_ACCESS,
27
- :service_type => Win32::Service::WIN32_OWN_PROCESS,
28
- :start_type => Win32::Service::DISABLED,
29
- :error_control => Win32::Service::ERROR_IGNORE,
30
- :binary_path_name => @@command,
31
- :load_order_group => 'Network',
32
- :dependencies => 'W32Time',
33
- :description => 'Test service. Please delete me'
34
- )
35
- end
36
- end
37
-
38
- def setup
39
- @elevated = Win32::Security.elevated_security?
40
-
41
- if @elevated
42
- @info1 = Win32::Service.config_info(@@service1)
43
- @info2 = Win32::Service.config_info(@@service2)
44
- end
45
- end
46
-
47
- test "constructor basic functionality" do
48
- assert_respond_to(Win32::Service, :new)
49
- end
50
-
51
- # Service.create works, but the test fails. Might be a bug in test-unit.
52
- test "create is an alias for new" do
53
- assert_respond_to(Win32::Service, :create)
54
- #assert_alias_method(Win32::Service, :create, :new)
55
- end
56
-
57
- test "ensure services were created in startup method" do
58
- omit_unless(@elevated)
59
- notify "If this test fails then remaining results are meaningless."
60
- assert_true(Win32::Service.exists?(@@service1))
61
- assert_true(Win32::Service.exists?(@@service2))
62
- end
63
-
64
- test "expected service type configuration information" do
65
- omit_unless(@elevated)
66
- assert_equal('own process', @info1.service_type)
67
- end
68
-
69
- test "expected start type configuration information" do
70
- omit_unless(@elevated)
71
- assert_equal('demand start', @info1.start_type)
72
- end
73
-
74
- test "expected error control configuration information" do
75
- omit_unless(@elevated)
76
- assert_equal('normal', @info1.error_control)
77
- end
78
-
79
- test "expected binary path name configuration information" do
80
- omit_unless(@elevated)
81
- assert_equal(@@command, @info1.binary_path_name)
82
- end
83
-
84
- test "expected load order group configuration information" do
85
- omit_unless(@elevated)
86
- assert_equal('', @info1.load_order_group)
87
- end
88
-
89
- test "expected tag id configuration information" do
90
- omit_unless(@elevated)
91
- assert_equal(0, @info1.tag_id)
92
- end
93
-
94
- test "expected dependency configuration information" do
95
- omit_unless(@elevated)
96
- assert_equal([], @info1.dependencies)
97
- end
98
-
99
- test "expected service start time configuration information" do
100
- omit_unless(@elevated)
101
- assert_equal('LocalSystem', @info1.service_start_name)
102
- end
103
-
104
- test "expected display name configuration information" do
105
- omit_unless(@elevated)
106
- assert_equal('notepad_service1', @info1.display_name)
107
- end
108
-
109
- test "configuration information options are set properly for service 2" do
110
- omit_unless(@elevated)
111
- assert_equal('own process', @info2.service_type)
112
- assert_equal('disabled', @info2.start_type)
113
- assert_equal('ignore', @info2.error_control)
114
- assert_equal(@@command, @info2.binary_path_name)
115
- assert_equal('Network', @info2.load_order_group)
116
- assert_equal(0, @info2.tag_id)
117
- assert_equal(['W32Time'], @info2.dependencies)
118
- assert_equal('LocalSystem', @info2.service_start_name)
119
- assert_equal('Notepad Test', @info2.display_name)
120
- end
121
-
122
- test "at least one argument is required or an error is raised" do
123
- assert_raise(ArgumentError){ Win32::Service.new }
124
- end
125
-
126
- test "passing a bogus option to the constructor will cause an error" do
127
- assert_raise(ArgumentError){ Win32::Service.new(:bogus => 'test.exe') }
128
- end
129
-
130
- test "the service name must be provided or an error is raised" do
131
- assert_raise(ArgumentError){ Win32::Service.new(:binary_path_name => 'test.exe') }
132
- end
133
-
134
- def teardown
135
- if @elevated
136
- @info1 = nil
137
- @info2 = nil
138
- end
139
-
140
- @elevated = nil
141
- end
142
-
143
- def self.shutdown
144
- if Win32::Security.elevated_security?
145
- Win32::Service.delete(@@service1) if Win32::Service.exists?(@@service1)
146
- Win32::Service.delete(@@service2) if Win32::Service.exists?(@@service2)
147
- end
148
-
149
- @@service1 = nil
150
- @@service2 = nil
151
- @@command = nil
152
- end
153
- end
@@ -1,189 +0,0 @@
1
- ########################################################################
2
- # test_win32_service_info.rb
3
- #
4
- # Test case for the Struct::ServiceInfo structure.
5
- ########################################################################
6
- require 'test-unit'
7
- require 'win32/service'
8
-
9
- class TC_Win32_ServiceInfo_Struct < Test::Unit::TestCase
10
- def self.startup
11
- @@services = Win32::Service.services
12
- end
13
-
14
- def setup
15
- @service_name = "Dhcp"
16
- @service_info = @@services.find{ |s| s.service_name == @service_name }
17
-
18
- @error_controls = [
19
- 'critical',
20
- 'ignore',
21
- 'normal',
22
- 'severe',
23
- nil
24
- ]
25
-
26
- @start_types = [
27
- 'auto start',
28
- 'boot start',
29
- 'demand start',
30
- 'disabled',
31
- 'system start',
32
- nil
33
- ]
34
-
35
- @types = [
36
- 'file system driver',
37
- 'kernel driver',
38
- 'own process',
39
- 'share process',
40
- 'recognizer token',
41
- 'driver',
42
- 'win32',
43
- 'all',
44
- 'own process, interactive',
45
- 'share process, interactive',
46
- nil
47
- ]
48
-
49
- @states = [
50
- 'continue pending',
51
- 'pause pending',
52
- 'paused',
53
- 'running',
54
- 'start pending',
55
- 'stop pending',
56
- 'stopped',
57
- nil
58
- ]
59
-
60
- @controls = [
61
- 'netbind change',
62
- 'param change',
63
- 'pause continue',
64
- 'pre-shutdown',
65
- 'shutdown',
66
- 'stop',
67
- 'hardware profile change',
68
- 'power event',
69
- 'session change',
70
- 'interrogate'
71
- ]
72
- end
73
-
74
- test "service_name basic functionality" do
75
- assert_respond_to(@service_info, :service_name)
76
- assert_kind_of(String, @service_info.service_name)
77
- end
78
-
79
- test "display_name basic functionality" do
80
- assert_respond_to(@service_info, :display_name)
81
- assert_kind_of(String, @service_info.display_name)
82
- end
83
-
84
- test "service_type basic functionality" do
85
- assert_respond_to(@service_info, :service_type)
86
- assert(@types.include?(@service_info.service_type))
87
- end
88
-
89
- test "current_state basic functionality" do
90
- assert_respond_to(@service_info, :current_state)
91
- assert(@states.include?(@service_info.current_state))
92
- end
93
-
94
- test "controls_accepted basic functionality" do
95
- assert_respond_to(@service_info, :controls_accepted)
96
- assert_kind_of(Array, @service_info.controls_accepted)
97
- end
98
-
99
- test "controls_accepted returns expected values" do
100
- assert_false(@service_info.controls_accepted.empty?)
101
- @service_info.controls_accepted.each{ |c| assert_true(@controls.include?(c)) }
102
- end
103
-
104
- test "win32_exit_code basic functionality" do
105
- assert_respond_to(@service_info, :win32_exit_code)
106
- assert_kind_of(Fixnum, @service_info.win32_exit_code)
107
- end
108
-
109
- test "service_specific_exit_code basic functionality" do
110
- assert_respond_to(@service_info, :service_specific_exit_code)
111
- assert_kind_of(Fixnum, @service_info.service_specific_exit_code)
112
- end
113
-
114
- test "check_point basic functionality" do
115
- assert_respond_to(@service_info, :check_point)
116
- assert_kind_of(Fixnum, @service_info.check_point)
117
- end
118
-
119
- test "wait_hint basic functionality" do
120
- assert_respond_to(@service_info, :wait_hint)
121
- assert_kind_of(Fixnum, @service_info.wait_hint)
122
- end
123
-
124
- test "binary_path_name basic functionality" do
125
- assert_respond_to(@service_info, :binary_path_name)
126
- assert_kind_of(String, @service_info.binary_path_name)
127
- end
128
-
129
- test "start_type basic functionality" do
130
- assert_respond_to(@service_info, :start_type)
131
- assert(@start_types.include?(@service_info.start_type))
132
- end
133
-
134
- test "error_control basic functionality" do
135
- assert_respond_to(@service_info, :error_control)
136
- assert(@error_controls.include?(@service_info.error_control))
137
- end
138
-
139
- test "load_order_group basic functionality" do
140
- assert_respond_to(@service_info, :load_order_group)
141
- assert_kind_of(String, @service_info.load_order_group)
142
- end
143
-
144
- test "tag_id basic functionality" do
145
- assert_respond_to(@service_info, :tag_id)
146
- assert_kind_of(Fixnum, @service_info.tag_id)
147
- end
148
-
149
- test "start_name basic functionality" do
150
- assert_respond_to(@service_info, :start_name)
151
- assert_kind_of(String, @service_info.start_name)
152
- end
153
-
154
- test "dependencies basic functionality" do
155
- assert_respond_to(@service_info, :dependencies)
156
- assert_kind_of(Array, @service_info.dependencies)
157
- end
158
-
159
- test "description basic functionality" do
160
- assert_respond_to(@service_info, :description)
161
- assert_kind_of(String, @service_info.description)
162
- end
163
-
164
- test "interactive basic functionality" do
165
- assert_respond_to(@service_info, :interactive)
166
- assert_boolean(@service_info.interactive)
167
- end
168
-
169
- test "service_flags basic functionality" do
170
- assert_respond_to(@service_info, :service_flags)
171
- assert([0,1].include?(@service_info.service_flags))
172
- end
173
-
174
- test "delayed_start basic functionality" do
175
- assert_respond_to(@service_info, :delayed_start)
176
- assert([0,1].include?(@service_info.delayed_start))
177
- end
178
-
179
- def teardown
180
- @types = nil
181
- @states = nil
182
- @controls = nil
183
- @service_name = nil
184
- end
185
-
186
- def self.shutdown
187
- @@services = nil
188
- end
189
- end