win32-service 0.7.2-x86-mingw32

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