win32-service 0.8.10 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,110 +1,110 @@
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
+ #######################################################################
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 +1,153 @@
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
+ ########################################################################
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