win32-service 0.8.6 → 0.8.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,99 +1,99 @@
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/service'
8
-
9
- class TC_Win32_Service_Configure < Test::Unit::TestCase
10
- def self.startup
11
- @@service = "notepad_service"
12
- @@command = "C:\\windows\\system32\\notepad.exe"
13
-
14
- Win32::Service.new(
15
- :service_name => @@service,
16
- :binary_path_name => @@command
17
- )
18
- end
19
-
20
- def config_info
21
- Win32::Service.config_info(@@service)
22
- end
23
-
24
- def full_info
25
- service = nil
26
- Win32::Service.services{ |s|
27
- if s.service_name == @@service
28
- service = s
29
- break
30
- end
31
- }
32
- service
33
- end
34
-
35
- def service_configure(opt)
36
- options = {:service_name => @@service}
37
- options = options.merge(opt)
38
- assert_nothing_raised{ Win32::Service.configure(options) }
39
- end
40
-
41
- def setup
42
- @info = Win32::Service.config_info(@@service)
43
- end
44
-
45
- test "configure method is defined" do
46
- assert_respond_to(Win32::Service, :configure)
47
- end
48
-
49
- test "configuring the service type works as expected" do
50
- assert_equal('own process', config_info.service_type)
51
- service_configure(:service_type => Win32::Service::WIN32_SHARE_PROCESS)
52
- assert_equal('share process', config_info.service_type)
53
- end
54
-
55
- test "configuring the description works as expected" do
56
- assert_equal('', full_info.description)
57
- service_configure(:description => 'test service')
58
- assert_equal('test service', full_info.description)
59
- end
60
-
61
- test "configuring the start type works as expected" do
62
- assert_equal('demand start', config_info.start_type)
63
- service_configure(:start_type => Win32::Service::DISABLED)
64
- assert_equal('disabled', config_info.start_type)
65
- end
66
-
67
- test "service start can be delayed" do
68
- service_configure(:start_type => Win32::Service::AUTO_START, :delayed_start => true)
69
- assert_true(full_info.delayed_start)
70
- end
71
-
72
- test "the configure method requires one argument" do
73
- assert_raise(ArgumentError){ Win32::Service.configure }
74
- end
75
-
76
- test "the configure method requires a hash argument" do
77
- assert_raise(ArgumentError){ Win32::Service.configure('bogus') }
78
- end
79
-
80
- test "the hash argument must not be empty" do
81
- assert_raise(ArgumentError){ Win32::Service.configure({}) }
82
- end
83
-
84
- test "the service name must be provided or an error is raised" do
85
- assert_raise(ArgumentError){
86
- Win32::Service.configure(:binary_path_name => 'notepad.exe')
87
- }
88
- end
89
-
90
- def teardown
91
- @info = nil
92
- end
93
-
94
- def self.shutdown
95
- Win32::Service.delete(@@service) if Win32::Service.exists?(@@service)
96
- @@service = nil
97
- @@command = nil
98
- end
99
- 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/service'
8
+
9
+ class TC_Win32_Service_Configure < Test::Unit::TestCase
10
+ def self.startup
11
+ @@service = "notepad_service"
12
+ @@command = "C:\\windows\\system32\\notepad.exe"
13
+
14
+ Win32::Service.new(
15
+ :service_name => @@service,
16
+ :binary_path_name => @@command
17
+ )
18
+ end
19
+
20
+ def config_info
21
+ Win32::Service.config_info(@@service)
22
+ end
23
+
24
+ def full_info
25
+ service = nil
26
+ Win32::Service.services{ |s|
27
+ if s.service_name == @@service
28
+ service = s
29
+ break
30
+ end
31
+ }
32
+ service
33
+ end
34
+
35
+ def service_configure(opt)
36
+ options = {:service_name => @@service}
37
+ options = options.merge(opt)
38
+ assert_nothing_raised{ Win32::Service.configure(options) }
39
+ end
40
+
41
+ def setup
42
+ @info = Win32::Service.config_info(@@service)
43
+ end
44
+
45
+ test "configure method is defined" do
46
+ assert_respond_to(Win32::Service, :configure)
47
+ end
48
+
49
+ test "configuring the service type works as expected" do
50
+ assert_equal('own process', config_info.service_type)
51
+ service_configure(:service_type => Win32::Service::WIN32_SHARE_PROCESS)
52
+ assert_equal('share process', config_info.service_type)
53
+ end
54
+
55
+ test "configuring the description works as expected" do
56
+ assert_equal('', full_info.description)
57
+ service_configure(:description => 'test service')
58
+ assert_equal('test service', full_info.description)
59
+ end
60
+
61
+ test "configuring the start type works as expected" do
62
+ assert_equal('demand start', config_info.start_type)
63
+ service_configure(:start_type => Win32::Service::DISABLED)
64
+ assert_equal('disabled', config_info.start_type)
65
+ end
66
+
67
+ test "service start can be delayed" do
68
+ service_configure(:start_type => Win32::Service::AUTO_START, :delayed_start => true)
69
+ assert_equal(1, full_info.delayed_start)
70
+ end
71
+
72
+ test "the configure method requires one argument" do
73
+ assert_raise(ArgumentError){ Win32::Service.configure }
74
+ end
75
+
76
+ test "the configure method requires a hash argument" do
77
+ assert_raise(ArgumentError){ Win32::Service.configure('bogus') }
78
+ end
79
+
80
+ test "the hash argument must not be empty" do
81
+ assert_raise(ArgumentError){ Win32::Service.configure({}) }
82
+ end
83
+
84
+ test "the service name must be provided or an error is raised" do
85
+ assert_raise(ArgumentError){
86
+ Win32::Service.configure(:binary_path_name => 'notepad.exe')
87
+ }
88
+ end
89
+
90
+ def teardown
91
+ @info = nil
92
+ end
93
+
94
+ def self.shutdown
95
+ Win32::Service.delete(@@service) if Win32::Service.exists?(@@service)
96
+ @@service = nil
97
+ @@command = nil
98
+ end
99
+ end
@@ -1,129 +1,129 @@
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/service'
9
-
10
- class TC_Win32_Service_Create < Test::Unit::TestCase
11
- def self.startup
12
- @@service1 = "notepad_service1"
13
- @@service2 = "notepad_service2"
14
- @@command = "C:\\windows\\system32\\notepad.exe"
15
-
16
- Win32::Service.new(
17
- :service_name => @@service1,
18
- :binary_path_name => @@command
19
- )
20
-
21
- Win32::Service.new(
22
- :service_name => @@service2,
23
- :display_name => 'Notepad Test',
24
- :desired_access => Win32::Service::ALL_ACCESS,
25
- :service_type => Win32::Service::WIN32_OWN_PROCESS,
26
- :start_type => Win32::Service::DISABLED,
27
- :error_control => Win32::Service::ERROR_IGNORE,
28
- :binary_path_name => @@command,
29
- :load_order_group => 'Network',
30
- :dependencies => 'W32Time',
31
- :description => 'Test service. Please delete me'
32
- )
33
- end
34
-
35
- def setup
36
- @info1 = Win32::Service.config_info(@@service1)
37
- @info2 = Win32::Service.config_info(@@service2)
38
- end
39
-
40
- test "constructor basic functionality" do
41
- assert_respond_to(Win32::Service, :new)
42
- end
43
-
44
- # Service.create works, but the test fails. Might be a bug in test-unit.
45
- test "create is an alias for new" do
46
- assert_respond_to(Win32::Service, :create)
47
- #assert_alias_method(Win32::Service, :create, :new)
48
- end
49
-
50
- test "ensure services were created in startup method" do
51
- notify "If this test fails then remaining results are meaningless."
52
- assert_true(Win32::Service.exists?(@@service1))
53
- assert_true(Win32::Service.exists?(@@service2))
54
- end
55
-
56
- test "expected service type configuration information" do
57
- assert_equal('own process', @info1.service_type)
58
- end
59
-
60
- test "expected start type configuration information" do
61
- assert_equal('demand start', @info1.start_type)
62
- end
63
-
64
- test "expected error control configuration information" do
65
- assert_equal('normal', @info1.error_control)
66
- end
67
-
68
- test "expected binary path name configuration information" do
69
- assert_equal(@@command, @info1.binary_path_name)
70
- end
71
-
72
- test "expected load order group configuration information" do
73
- assert_equal('', @info1.load_order_group)
74
- end
75
-
76
- test "expected tag id configuration information" do
77
- assert_equal(0, @info1.tag_id)
78
- end
79
-
80
- test "expected dependency configuration information" do
81
- assert_equal([], @info1.dependencies)
82
- end
83
-
84
- test "expected service start time configuration information" do
85
- assert_equal('LocalSystem', @info1.service_start_name)
86
- end
87
-
88
- test "expected display name configuration information" do
89
- assert_equal('notepad_service1', @info1.display_name)
90
- end
91
-
92
- test "configuration information options are set properly for service 2" do
93
- assert_equal('own process', @info2.service_type)
94
- assert_equal('disabled', @info2.start_type)
95
- assert_equal('ignore', @info2.error_control)
96
- assert_equal(@@command, @info2.binary_path_name)
97
- assert_equal('Network', @info2.load_order_group)
98
- assert_equal(0, @info2.tag_id)
99
- assert_equal(['W32Time'], @info2.dependencies)
100
- assert_equal('LocalSystem', @info2.service_start_name)
101
- assert_equal('Notepad Test', @info2.display_name)
102
- end
103
-
104
- test "at least one argument is required or an error is raised" do
105
- assert_raise(ArgumentError){ Win32::Service.new }
106
- end
107
-
108
- test "passing a bogus option to the constructor will cause an error" do
109
- assert_raise(ArgumentError){ Win32::Service.new(:bogus => 'test.exe') }
110
- end
111
-
112
- test "the service name must be provided or an error is raised" do
113
- assert_raise(ArgumentError){ Win32::Service.new(:binary_path_name => 'test.exe') }
114
- end
115
-
116
- def teardown
117
- @info1 = nil
118
- @info2 = nil
119
- end
120
-
121
- def self.shutdown
122
- Win32::Service.delete(@@service1) if Win32::Service.exists?(@@service1)
123
- Win32::Service.delete(@@service2) if Win32::Service.exists?(@@service2)
124
-
125
- @@service1 = nil
126
- @@service2 = nil
127
- @@command = nil
128
- end
129
- 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/service'
9
+
10
+ class TC_Win32_Service_Create < Test::Unit::TestCase
11
+ def self.startup
12
+ @@service1 = "notepad_service1"
13
+ @@service2 = "notepad_service2"
14
+ @@command = "C:\\windows\\system32\\notepad.exe"
15
+
16
+ Win32::Service.new(
17
+ :service_name => @@service1,
18
+ :binary_path_name => @@command
19
+ )
20
+
21
+ Win32::Service.new(
22
+ :service_name => @@service2,
23
+ :display_name => 'Notepad Test',
24
+ :desired_access => Win32::Service::ALL_ACCESS,
25
+ :service_type => Win32::Service::WIN32_OWN_PROCESS,
26
+ :start_type => Win32::Service::DISABLED,
27
+ :error_control => Win32::Service::ERROR_IGNORE,
28
+ :binary_path_name => @@command,
29
+ :load_order_group => 'Network',
30
+ :dependencies => 'W32Time',
31
+ :description => 'Test service. Please delete me'
32
+ )
33
+ end
34
+
35
+ def setup
36
+ @info1 = Win32::Service.config_info(@@service1)
37
+ @info2 = Win32::Service.config_info(@@service2)
38
+ end
39
+
40
+ test "constructor basic functionality" do
41
+ assert_respond_to(Win32::Service, :new)
42
+ end
43
+
44
+ # Service.create works, but the test fails. Might be a bug in test-unit.
45
+ test "create is an alias for new" do
46
+ assert_respond_to(Win32::Service, :create)
47
+ #assert_alias_method(Win32::Service, :create, :new)
48
+ end
49
+
50
+ test "ensure services were created in startup method" do
51
+ notify "If this test fails then remaining results are meaningless."
52
+ assert_true(Win32::Service.exists?(@@service1))
53
+ assert_true(Win32::Service.exists?(@@service2))
54
+ end
55
+
56
+ test "expected service type configuration information" do
57
+ assert_equal('own process', @info1.service_type)
58
+ end
59
+
60
+ test "expected start type configuration information" do
61
+ assert_equal('demand start', @info1.start_type)
62
+ end
63
+
64
+ test "expected error control configuration information" do
65
+ assert_equal('normal', @info1.error_control)
66
+ end
67
+
68
+ test "expected binary path name configuration information" do
69
+ assert_equal(@@command, @info1.binary_path_name)
70
+ end
71
+
72
+ test "expected load order group configuration information" do
73
+ assert_equal('', @info1.load_order_group)
74
+ end
75
+
76
+ test "expected tag id configuration information" do
77
+ assert_equal(0, @info1.tag_id)
78
+ end
79
+
80
+ test "expected dependency configuration information" do
81
+ assert_equal([], @info1.dependencies)
82
+ end
83
+
84
+ test "expected service start time configuration information" do
85
+ assert_equal('LocalSystem', @info1.service_start_name)
86
+ end
87
+
88
+ test "expected display name configuration information" do
89
+ assert_equal('notepad_service1', @info1.display_name)
90
+ end
91
+
92
+ test "configuration information options are set properly for service 2" do
93
+ assert_equal('own process', @info2.service_type)
94
+ assert_equal('disabled', @info2.start_type)
95
+ assert_equal('ignore', @info2.error_control)
96
+ assert_equal(@@command, @info2.binary_path_name)
97
+ assert_equal('Network', @info2.load_order_group)
98
+ assert_equal(0, @info2.tag_id)
99
+ assert_equal(['W32Time'], @info2.dependencies)
100
+ assert_equal('LocalSystem', @info2.service_start_name)
101
+ assert_equal('Notepad Test', @info2.display_name)
102
+ end
103
+
104
+ test "at least one argument is required or an error is raised" do
105
+ assert_raise(ArgumentError){ Win32::Service.new }
106
+ end
107
+
108
+ test "passing a bogus option to the constructor will cause an error" do
109
+ assert_raise(ArgumentError){ Win32::Service.new(:bogus => 'test.exe') }
110
+ end
111
+
112
+ test "the service name must be provided or an error is raised" do
113
+ assert_raise(ArgumentError){ Win32::Service.new(:binary_path_name => 'test.exe') }
114
+ end
115
+
116
+ def teardown
117
+ @info1 = nil
118
+ @info2 = nil
119
+ end
120
+
121
+ def self.shutdown
122
+ Win32::Service.delete(@@service1) if Win32::Service.exists?(@@service1)
123
+ Win32::Service.delete(@@service2) if Win32::Service.exists?(@@service2)
124
+
125
+ @@service1 = nil
126
+ @@service2 = nil
127
+ @@command = nil
128
+ end
129
+ end