win32-taskscheduler 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -13,512 +13,526 @@ require 'socket'
13
13
  include Win32
14
14
 
15
15
  class TC_TaskScheduler < Test::Unit::TestCase
16
- def self.startup
17
- @@host = Socket.gethostname
18
- end
19
-
20
- def setup
21
- @task = 'foo'
22
- @job_file = "C:\\WINDOWS\\Tasks\\test.job"
23
-
24
- @trigger = {
25
- 'start_year' => 2009,
26
- 'start_month' => 4,
27
- 'start_day' => 11,
28
- 'start_hour' => 7,
29
- 'start_minute' => 14,
30
- 'trigger_type' => TaskScheduler::DAILY,
31
- 'type' => { 'days_interval' => 1 }
32
- }
33
-
34
- @ts = TaskScheduler.new(@task, @trigger)
35
- @ts.save
36
- @ts.activate(@task)
37
- end
38
-
39
- def test_version
40
- assert_equal('0.2.0', TaskScheduler::VERSION)
41
- end
42
-
43
- def test_get_account_information
44
- assert_respond_to(@ts, :account_information)
45
- assert_equal(nil, @ts.account_information)
46
- end
47
-
48
- def test_get_account_information_expected_errors
49
- assert_raise(ArgumentError){ @ts.account_information('foo') }
50
- end
51
-
52
- def test_set_account_information
53
- assert_nothing_raised{ @ts.set_account_information('test', 'XXXX') }
54
- assert_equal('test', @ts.account_information)
55
- end
56
-
57
- def test_set_account_information_expected_errors
58
- assert_raise(ArgumentError){ @ts.set_account_information }
59
- assert_raise(ArgumentError){ @ts.set_account_information('x') }
60
- assert_raise(ArgumentError){ @ts.set_account_information('x', 'y', 'z') }
61
- assert_raise(TypeError){ @ts.set_account_information(1, 'XXX') }
62
- assert_raise(TypeError){ @ts.set_account_information('x', 1) }
63
- end
64
-
65
- def test_activate
66
- assert_nothing_raised{ @ts.activate('foo') }
67
- assert_nothing_raised{ @ts.activate('foo') } # Intentional duplicate
68
- end
69
-
70
- def test_activate_expected_errors
71
- assert_raise(ArgumentError){ @ts.activate }
72
- assert_raise(ArgumentError){ @ts.activate('foo', 'bar') }
73
- assert_raise(TypeError){ @ts.activate(1) }
74
- assert_raise(TaskScheduler::Error){ @ts.activate('bogus') }
75
- end
76
-
77
- def test_get_application_name
78
- assert_respond_to(@ts, :application_name)
79
- assert_nothing_raised{ @ts.application_name }
80
- assert_kind_of(String, @ts.application_name)
81
- end
82
-
83
- def test_get_application_name_expected_errors
84
- assert_raises(ArgumentError){ @ts.application_name('bogus') }
85
- end
86
-
87
- def test_set_application_name
88
- assert_respond_to(@ts, :application_name=)
89
- assert_nothing_raised{ @ts.application_name = "notepad.exe" }
90
- end
91
-
92
- def test_set_application_name_expected_errors
93
- assert_raise(ArgumentError){ @ts.send(:application_name=) }
94
- assert_raise(TypeError){ @ts.application_name = 1 }
95
- end
96
-
97
- def test_get_comment
98
- assert_respond_to(@ts, :comment)
99
- assert_nothing_raised{ @ts.comment }
100
- assert_kind_of(String, @ts.comment)
101
- end
102
-
103
- def test_get_comment_expected_errors
104
- assert_raise(ArgumentError){ @ts.comment('test') }
105
- end
106
-
107
- def test_set_comment
108
- assert_respond_to(@ts, :comment=)
109
- assert_nothing_raised{ @ts.comment = "test" }
110
- end
111
-
112
- def test_set_comment_expected_errors
113
- assert_raise(ArgumentError){ @ts.send(:comment=) }
114
- assert_raise(TypeError){ @ts.comment = 1 }
115
- end
116
-
117
- def test_get_creator
118
- assert_respond_to(@ts, :creator)
119
- assert_nothing_raised{ @ts.creator }
120
- assert_kind_of(String, @ts.creator)
121
- end
122
-
123
- def test_get_creator_expected_errors
124
- assert_raise(ArgumentError){ @ts.creator('foo') }
125
- end
126
-
127
- def test_set_creator
128
- assert_respond_to(@ts, :creator=)
129
- assert_nothing_raised{ @ts.creator = "Test Creator" }
130
- end
131
-
132
- def test_set_creator_expected_errors
133
- assert_raise(ArgumentError){ @ts.send(:creator=) }
134
- assert_raise(TypeError){ @ts.creator = 1 }
135
- end
136
-
137
- def test_delete
138
- assert_respond_to(@ts, :delete)
139
- assert_nothing_raised{ @ts.delete(@task) }
140
- end
141
-
142
- def test_delete_expected_errors
143
- assert_raise(ArgumentError){ @ts.delete }
144
- assert_raise(TaskScheduler::Error){ @ts.delete("foofoo") }
145
- end
146
-
147
- def test_delete_trigger
148
- assert_respond_to(@ts, :delete_trigger)
149
- assert_equal(0, @ts.delete_trigger(0))
150
- end
151
-
152
- # TODO: Figure out why the last two fail
153
- def test_delete_trigger_expected_errors
154
- assert_raise(ArgumentError){ @ts.delete }
155
- #assert_raise(TypeError){ @ts.delete('test') }
156
- #assert_raise(TaskScheduler::Error){ @ts.delete(-1) }
157
- end
158
-
159
- def test_enum
160
- assert_respond_to(@ts, :enum)
161
- assert_kind_of(Array, @ts.enum)
162
- assert_nothing_raised{ @ts.enum }
163
- end
164
-
165
- def test_enum_expected_errors
166
- assert_raise(ArgumentError){ @ts.enum(1) }
167
- assert_raise(NoMethodError){ @ts.enum = true }
168
- end
169
-
170
- def test_exists_basic
171
- assert_respond_to(@ts, :exists?)
172
- assert_boolean(@ts.exists?(@task))
173
- end
174
-
175
- def test_exists
176
- assert_true(@ts.exists?(@task))
177
- assert_false(@ts.exists?('bogusXYZ'))
178
- end
179
-
180
- def test_exists_expected_errors
181
- assert_raise(ArgumentError){ @ts.exists? }
182
- assert_raise(ArgumentError){ @ts.exists?('foo', 'bar') }
183
- end
184
-
185
- def test_exit_code
186
- assert_respond_to(@ts, :exit_code)
187
- assert_nothing_raised{ @ts.exit_code }
188
- assert_kind_of(Fixnum, @ts.exit_code)
189
- end
190
-
191
- def test_exit_code_expected_errors
192
- assert_raise(ArgumentError){ @ts.exit_code(true) }
193
- assert_raise(NoMethodError){ @ts.exit_code = 1 }
194
- end
195
-
196
- def test_get_flags
197
- assert_respond_to(@ts, :flags)
198
- assert_nothing_raised{ @ts.flags }
199
- assert_kind_of(Fixnum, @ts.flags)
200
- end
201
-
202
- def test_get_flags_expected_errors
203
- assert_raise(ArgumentError){ @ts.flags(1) }
204
- end
205
-
206
- def test_set_flags
207
- assert_respond_to(@ts, :flags=)
208
- assert_nothing_raised{ @ts.flags = TaskScheduler::DELETE_WHEN_DONE }
209
- end
210
-
211
- def test_set_flags_expected_errors
212
- assert_raise(ArgumentError){ @ts.send(:flags=) }
213
- assert_raise(TypeError){ @ts.flags = 'test' }
214
- end
215
-
216
- # TODO: Why does setting the host fail?
217
- def test_set_machine
218
- assert_respond_to(@ts, :host=)
219
- assert_respond_to(@ts, :machine=)
220
- #assert_nothing_raised{ @ts.machine = @@host }
221
- end
222
-
223
- def test_get_max_run_time
224
- assert_respond_to(@ts, :max_run_time)
225
- assert_nothing_raised{ @ts.max_run_time }
226
- assert_kind_of(Fixnum, @ts.max_run_time)
227
- end
228
-
229
- def test_get_max_run_time_expected_errors
230
- assert_raise(ArgumentError){ @ts.max_run_time(true) }
231
- end
232
-
233
- def test_set_max_run_time
234
- assert_respond_to(@ts, :max_run_time=)
235
- assert_nothing_raised{ @ts.max_run_time = 20000 }
236
- end
237
-
238
- def test_set_max_run_time_expected_errors
239
- assert_raise(ArgumentError){ @ts.send(:max_run_time=) }
240
- assert_raise(TypeError){ @ts.max_run_time = true }
241
- end
242
-
243
- def test_most_recent_run_time
244
- assert_respond_to(@ts, :most_recent_run_time)
245
- assert_nothing_raised{ @ts.most_recent_run_time }
246
- assert_nil(@ts.most_recent_run_time)
247
- end
248
-
249
- def test_most_recent_run_time_expected_errors
250
- assert_raise(ArgumentError){ @ts.most_recent_run_time(true) }
251
- assert_raise(NoMethodError){ @ts.most_recent_run_time = Time.now }
252
- end
253
-
254
- def test_new_work_item
255
- assert_respond_to(@ts, :new_work_item)
256
- assert_nothing_raised{ @ts.new_work_item('bar', @trigger) }
257
- end
258
-
259
- def test_new_work_item_expected_errors
260
- assert_raise(ArgumentError){ @ts.new_work_item('test', {:bogus => 1}) }
261
- end
262
-
263
- def test_new_task_alias
264
- assert_respond_to(@ts, :new_task)
265
- assert_equal(true, @ts.method(:new_task) == @ts.method(:new_work_item))
266
- end
267
-
268
- def test_new_work_item_expected_errors
269
- assert_raise(ArgumentError){ @ts.new_work_item }
270
- assert_raise(ArgumentError){ @ts.new_work_item('bar') }
271
- assert_raise(TypeError){ @ts.new_work_item(1, 'bar') }
272
- assert_raise(TypeError){ @ts.new_work_item('bar', 1) }
273
- end
274
-
275
- def test_next_run_time
276
- assert_respond_to(@ts, :next_run_time)
277
- assert_nothing_raised{ @ts.next_run_time }
278
- assert_kind_of(Time, @ts.next_run_time)
279
- end
280
-
281
- def test_next_run_time_expected_errors
282
- assert_raise(ArgumentError){ @ts.next_run_time(true) }
283
- assert_raise(NoMethodError){ @ts.next_run_time = Time.now }
284
- end
285
-
286
- def test_get_parameters
287
- assert_respond_to(@ts, :parameters)
288
- assert_nothing_raised{ @ts.parameters }
289
- end
290
-
291
- def test_get_parameters_expected_errors
292
- assert_raise(ArgumentError){ @ts.parameters('test') }
293
- end
294
-
295
- def set_parameters
296
- assert_respond_to(@ts, :parameters=)
297
- assert_nothing_raised{ @ts.parameters = "somefile.txt" }
298
- end
299
-
300
- def set_parameters_expected_errors
301
- assert_raise(ArgumentError){ @ts.send(:parameters=) }
302
- assert_raise(TypeError){ @ts.parameters = 1 }
303
- end
304
-
305
- def test_get_priority
306
- assert_respond_to(@ts, :priority)
307
- assert_nothing_raised{ @ts.priority }
308
- assert_kind_of(String, @ts.priority)
309
- end
310
-
311
- def test_get_priority_expected_errors
312
- assert_raise(ArgumentError){ @ts.priority(true) }
313
- end
314
-
315
- def test_set_priority
316
- assert_respond_to(@ts, :priority=)
317
- assert_nothing_raised{ @ts.priority = TaskScheduler::NORMAL }
318
- end
319
-
320
- def test_set_priority_expected_errors
321
- assert_raise(ArgumentError){ @ts.send(:priority=) }
322
- assert_raise(TypeError){ @ts.priority = 'alpha' }
323
- end
324
-
325
- # TODO: Find a harmless way to test this.
326
- def test_run
327
- assert_respond_to(@ts, :run)
328
- end
329
-
330
- def test_run_expected_errors
331
- assert_raise(ArgumentError){ @ts.run(true) }
332
- assert_raise(NoMethodError){ @ts.run = true }
333
- end
334
-
335
- def test_save
336
- assert_respond_to(@ts, :save)
337
- assert_nothing_raised{ @ts.save }
338
- end
339
-
340
- def test_save_custom_file
341
- assert_nothing_raised{ @ts.save(@job_file) }
342
- assert_equal(true, File.exists?(@job_file))
343
- end
344
-
345
- def test_save_expected_errors
346
- assert_raise(TypeError){ @ts.save(true) }
347
- assert_raise(ArgumentError){ @ts.save(@job_file, true) }
348
- assert_raise(NoMethodError){ @ts.save = true }
349
- assert_raise(TaskScheduler::Error){ @ts.save; @ts.save }
350
- end
351
-
352
- def test_status
353
- assert_respond_to(@ts, :status)
354
- assert_nothing_raised{ @ts.status }
355
- assert_equal('not scheduled', @ts.status)
356
- end
357
-
358
- def test_status_expected_errors
359
- assert_raise(ArgumentError){ @ts.status(true) }
360
- assert_raise(NoMethodError){ @ts.status = true }
361
- end
362
-
363
- def test_terminate
364
- assert_respond_to(@ts, :terminate)
365
- end
366
-
367
- def test_terminate_expected_errors
368
- assert_raise(ArgumentError){ @ts.terminate(true) }
369
- assert_raise(NoMethodError){ @ts.terminate = true }
370
- assert_raise(TaskScheduler::Error){ @ts.terminate } # It's not running
371
- end
372
-
373
- def test_get_trigger
374
- assert_respond_to(@ts, :trigger)
375
- assert_nothing_raised{ @ts.trigger(0) }
376
- assert_kind_of(Hash, @ts.trigger(0))
377
- end
378
-
379
- def test_get_trigger_expected_errors
380
- assert_raises(ArgumentError){ @ts.trigger }
381
- assert_raises(TaskScheduler::Error){ @ts.trigger(9999) }
382
- end
383
-
384
- def test_set_trigger
385
- assert_respond_to(@ts, :trigger=)
386
- assert_nothing_raised{ @ts.trigger = @trigger }
387
- end
388
-
389
- def test_set_trigger_expected_errors
390
- assert_raises(TypeError){ @ts.trigger = 'blah' }
391
- end
392
-
393
- def test_add_trigger
394
- assert_respond_to(@ts, :add_trigger)
395
- assert_nothing_raised{ @ts.add_trigger(0, @trigger) }
396
- end
397
-
398
- def test_add_trigger_expected_errors
399
- assert_raises(ArgumentError){ @ts.add_trigger }
400
- assert_raises(ArgumentError){ @ts.add_trigger(0) }
401
- assert_raises(TypeError){ @ts.add_trigger(0, 'foo') }
402
- end
403
-
404
- def test_trigger_count
405
- assert_respond_to(@ts, :trigger_count)
406
- assert_nothing_raised{ @ts.trigger_count }
407
- assert_kind_of(Fixnum, @ts.trigger_count)
408
- end
409
-
410
- def test_trigger_count_expected_errors
411
- assert_raise(ArgumentError){ @ts.trigger_count(true) }
412
- assert_raise(NoMethodError){ @ts.trigger_count = 1 }
413
- end
414
-
415
- def test_trigger_delete
416
- assert_respond_to(@ts, :delete_trigger)
417
- assert_nothing_raised{ @ts.delete_trigger(0) }
418
- end
419
-
420
- def test_trigger_delete_expected_errors
421
- assert_raise(ArgumentError){ @ts.delete_trigger }
422
- assert_raise(TaskScheduler::Error){ @ts.delete_trigger(9999) }
423
- end
424
-
425
- def test_trigger_string
426
- assert_respond_to(@ts, :trigger_string)
427
- assert_nothing_raised{ @ts.trigger_string(0) }
428
- assert_equal('At 7:14 AM every day, starting 4/11/2009', @ts.trigger_string(0))
429
- end
430
-
431
- def test_trigger_string_expected_errors
432
- assert_raise(ArgumentError){ @ts.trigger_string }
433
- assert_raise(ArgumentError){ @ts.trigger_string(0, 0) }
434
- assert_raise(TypeError){ @ts.trigger_string('alpha') }
435
- assert_raise(TaskScheduler::Error){ @ts.trigger_string(9999) }
436
- end
437
-
438
- def test_get_working_directory
439
- assert_respond_to(@ts, :working_directory)
440
- assert_nothing_raised{ @ts.working_directory }
441
- assert_kind_of(String, @ts.working_directory)
442
- end
443
-
444
- def test_get_working_directory_expected_errors
445
- assert_raise(ArgumentError){ @ts.working_directory(true) }
446
- end
447
-
448
- def test_set_working_directory
449
- assert_respond_to(@ts, :working_directory=)
450
- assert_nothing_raised{ @ts.working_directory = "C:\\" }
451
- end
452
-
453
- def test_set_working_directory_expected_errors
454
- assert_raise(ArgumentError){ @ts.send(:working_directory=) }
455
- assert_raise(TypeError){ @ts.working_directory = 1 }
456
- end
457
-
458
- def test_constants
459
- assert_not_nil(TaskScheduler::MONDAY)
460
- assert_not_nil(TaskScheduler::TUESDAY)
461
- assert_not_nil(TaskScheduler::WEDNESDAY)
462
- assert_not_nil(TaskScheduler::THURSDAY)
463
- assert_not_nil(TaskScheduler::FRIDAY)
464
- assert_not_nil(TaskScheduler::SATURDAY)
465
- assert_not_nil(TaskScheduler::SUNDAY)
466
-
467
- assert_not_nil(TaskScheduler::JANUARY)
468
- assert_not_nil(TaskScheduler::FEBRUARY)
469
- assert_not_nil(TaskScheduler::MARCH)
470
- assert_not_nil(TaskScheduler::APRIL)
471
- assert_not_nil(TaskScheduler::MAY)
472
- assert_not_nil(TaskScheduler::JUNE)
473
- assert_not_nil(TaskScheduler::JULY)
474
- assert_not_nil(TaskScheduler::AUGUST)
475
- assert_not_nil(TaskScheduler::SEPTEMBER)
476
- assert_not_nil(TaskScheduler::OCTOBER)
477
- assert_not_nil(TaskScheduler::NOVEMBER)
478
- assert_not_nil(TaskScheduler::DECEMBER)
479
-
480
- assert_not_nil(TaskScheduler::ONCE)
481
- assert_not_nil(TaskScheduler::DAILY)
482
- assert_not_nil(TaskScheduler::WEEKLY)
483
- assert_not_nil(TaskScheduler::MONTHLYDATE)
484
- assert_not_nil(TaskScheduler::MONTHLYDOW)
485
-
486
- assert_not_nil(TaskScheduler::ON_IDLE)
487
- assert_not_nil(TaskScheduler::AT_SYSTEMSTART)
488
- assert_not_nil(TaskScheduler::AT_LOGON)
489
-
490
- assert_not_nil(TaskScheduler::INTERACTIVE)
491
- assert_not_nil(TaskScheduler::DELETE_WHEN_DONE)
492
- assert_not_nil(TaskScheduler::DISABLED)
493
- assert_not_nil(TaskScheduler::START_ONLY_IF_IDLE)
494
- assert_not_nil(TaskScheduler::KILL_ON_IDLE_END)
495
- assert_not_nil(TaskScheduler::DONT_START_IF_ON_BATTERIES)
496
- assert_not_nil(TaskScheduler::KILL_IF_GOING_ON_BATTERIES)
497
- assert_not_nil(TaskScheduler::HIDDEN)
498
- assert_not_nil(TaskScheduler::RESTART_ON_IDLE_RESUME)
499
- assert_not_nil(TaskScheduler::SYSTEM_REQUIRED)
500
- assert_not_nil(TaskScheduler::FLAG_HAS_END_DATE)
501
- assert_not_nil(TaskScheduler::FLAG_KILL_AT_DURATION_END)
502
- assert_not_nil(TaskScheduler::FLAG_DISABLED)
503
- assert_not_nil(TaskScheduler::MAX_RUN_TIMES)
504
-
505
- assert_not_nil(TaskScheduler::IDLE)
506
- assert_not_nil(TaskScheduler::NORMAL)
507
- assert_not_nil(TaskScheduler::HIGH)
508
- assert_not_nil(TaskScheduler::REALTIME)
509
- assert_not_nil(TaskScheduler::ABOVE_NORMAL)
510
- assert_not_nil(TaskScheduler::BELOW_NORMAL)
511
- end
512
-
513
- def teardown
514
- File.delete(@job_file) if File.exists?(@job_file)
515
- @ts.delete('foo') rescue nil
516
- @ts = nil
517
- @trigger = nil
518
- @job_file = nil
519
- end
520
-
521
- def self.shutdown
522
- @@host = nil
523
- end
16
+ def self.startup
17
+ @@host = Socket.gethostname
18
+ end
19
+
20
+ def setup
21
+ @task = 'foo'
22
+ @job_file = "C:\\WINDOWS\\Tasks\\test.job"
23
+
24
+ @trigger = {
25
+ 'start_year' => 2009,
26
+ 'start_month' => 4,
27
+ 'start_day' => 11,
28
+ 'start_hour' => 7,
29
+ 'start_minute' => 14,
30
+ 'trigger_type' => TaskScheduler::DAILY,
31
+ 'type' => { 'days_interval' => 1 }
32
+ }
33
+
34
+ @ts = TaskScheduler.new(@task, @trigger)
35
+ @ts.save
36
+ @ts.activate(@task)
37
+ end
38
+
39
+ def test_version
40
+ assert_equal('0.2.1', TaskScheduler::VERSION)
41
+ end
42
+
43
+ def test_get_account_information
44
+ assert_respond_to(@ts, :account_information)
45
+ assert_equal(nil, @ts.account_information)
46
+ end
47
+
48
+ def test_get_account_information_expected_errors
49
+ assert_raise(ArgumentError){ @ts.account_information('foo') }
50
+ end
51
+
52
+ def test_set_account_information
53
+ assert_nothing_raised{ @ts.set_account_information('test', 'XXXX') }
54
+ assert_equal('test', @ts.account_information)
55
+ end
56
+
57
+ def test_set_account_information_expected_errors
58
+ assert_raise(ArgumentError){ @ts.set_account_information }
59
+ assert_raise(ArgumentError){ @ts.set_account_information('x') }
60
+ assert_raise(ArgumentError){ @ts.set_account_information('x', 'y', 'z') }
61
+ assert_raise(TypeError){ @ts.set_account_information(1, 'XXX') }
62
+ assert_raise(TypeError){ @ts.set_account_information('x', 1) }
63
+ end
64
+
65
+ def test_activate
66
+ assert_nothing_raised{ @ts.activate('foo') }
67
+ assert_nothing_raised{ @ts.activate('foo') } # Intentional duplicate
68
+ end
69
+
70
+ def test_activate_expected_errors
71
+ assert_raise(ArgumentError){ @ts.activate }
72
+ assert_raise(ArgumentError){ @ts.activate('foo', 'bar') }
73
+ assert_raise(TypeError){ @ts.activate(1) }
74
+ assert_raise(TaskScheduler::Error){ @ts.activate('bogus') }
75
+ end
76
+
77
+ def test_get_application_name
78
+ assert_respond_to(@ts, :application_name)
79
+ assert_nothing_raised{ @ts.application_name }
80
+ assert_kind_of(String, @ts.application_name)
81
+ end
82
+
83
+ def test_get_application_name_expected_errors
84
+ assert_raises(ArgumentError){ @ts.application_name('bogus') }
85
+ end
86
+
87
+ def test_set_application_name
88
+ assert_respond_to(@ts, :application_name=)
89
+ assert_nothing_raised{ @ts.application_name = "notepad.exe" }
90
+ end
91
+
92
+ def test_set_application_name_expected_errors
93
+ assert_raise(ArgumentError){ @ts.send(:application_name=) }
94
+ assert_raise(TypeError){ @ts.application_name = 1 }
95
+ end
96
+
97
+ def test_get_comment
98
+ assert_respond_to(@ts, :comment)
99
+ assert_nothing_raised{ @ts.comment }
100
+ assert_kind_of(String, @ts.comment)
101
+ end
102
+
103
+ def test_get_comment_expected_errors
104
+ assert_raise(ArgumentError){ @ts.comment('test') }
105
+ end
106
+
107
+ def test_set_comment
108
+ assert_respond_to(@ts, :comment=)
109
+ assert_nothing_raised{ @ts.comment = "test" }
110
+ end
111
+
112
+ def test_set_comment_expected_errors
113
+ assert_raise(ArgumentError){ @ts.send(:comment=) }
114
+ assert_raise(TypeError){ @ts.comment = 1 }
115
+ end
116
+
117
+ def test_get_creator
118
+ assert_respond_to(@ts, :creator)
119
+ assert_nothing_raised{ @ts.creator }
120
+ assert_kind_of(String, @ts.creator)
121
+ end
122
+
123
+ def test_get_creator_expected_errors
124
+ assert_raise(ArgumentError){ @ts.creator('foo') }
125
+ end
126
+
127
+ def test_set_creator
128
+ assert_respond_to(@ts, :creator=)
129
+ assert_nothing_raised{ @ts.creator = "Test Creator" }
130
+ end
131
+
132
+ def test_set_creator_expected_errors
133
+ assert_raise(ArgumentError){ @ts.send(:creator=) }
134
+ assert_raise(TypeError){ @ts.creator = 1 }
135
+ end
136
+
137
+ def test_delete
138
+ assert_respond_to(@ts, :delete)
139
+ assert_nothing_raised{ @ts.delete(@task) }
140
+ end
141
+
142
+ def test_delete_expected_errors
143
+ assert_raise(ArgumentError){ @ts.delete }
144
+ assert_raise(TaskScheduler::Error){ @ts.delete("foofoo") }
145
+ end
146
+
147
+ def test_delete_trigger
148
+ assert_respond_to(@ts, :delete_trigger)
149
+ assert_equal(0, @ts.delete_trigger(0))
150
+ end
151
+
152
+ # TODO: Figure out why the last two fail
153
+ def test_delete_trigger_expected_errors
154
+ assert_raise(ArgumentError){ @ts.delete }
155
+ #assert_raise(TypeError){ @ts.delete('test') }
156
+ #assert_raise(TaskScheduler::Error){ @ts.delete(-1) }
157
+ end
158
+
159
+ def test_enum
160
+ assert_respond_to(@ts, :enum)
161
+ assert_kind_of(Array, @ts.enum)
162
+ assert_nothing_raised{ @ts.enum }
163
+ end
164
+
165
+ def test_enum_expected_errors
166
+ assert_raise(ArgumentError){ @ts.enum(1) }
167
+ assert_raise(NoMethodError){ @ts.enum = true }
168
+ end
169
+
170
+ def test_exists_basic
171
+ assert_respond_to(@ts, :exists?)
172
+ assert_boolean(@ts.exists?(@task))
173
+ end
174
+
175
+ def test_exists
176
+ assert_true(@ts.exists?(@task))
177
+ assert_false(@ts.exists?('bogusXYZ'))
178
+ end
179
+
180
+ def test_exists_expected_errors
181
+ assert_raise(ArgumentError){ @ts.exists? }
182
+ assert_raise(ArgumentError){ @ts.exists?('foo', 'bar') }
183
+ end
184
+
185
+ def test_exit_code
186
+ assert_respond_to(@ts, :exit_code)
187
+ assert_nothing_raised{ @ts.exit_code }
188
+ assert_kind_of(Fixnum, @ts.exit_code)
189
+ end
190
+
191
+ def test_exit_code_expected_errors
192
+ assert_raise(ArgumentError){ @ts.exit_code(true) }
193
+ assert_raise(NoMethodError){ @ts.exit_code = 1 }
194
+ end
195
+
196
+ def test_get_flags
197
+ assert_respond_to(@ts, :flags)
198
+ assert_nothing_raised{ @ts.flags }
199
+ assert_kind_of(Fixnum, @ts.flags)
200
+ end
201
+
202
+ def test_get_flags_expected_errors
203
+ assert_raise(ArgumentError){ @ts.flags(1) }
204
+ end
205
+
206
+ def test_set_flags
207
+ assert_respond_to(@ts, :flags=)
208
+ assert_nothing_raised{ @ts.flags = TaskScheduler::DELETE_WHEN_DONE }
209
+ end
210
+
211
+ def test_set_flags_expected_errors
212
+ assert_raise(ArgumentError){ @ts.send(:flags=) }
213
+ assert_raise(TypeError){ @ts.flags = 'test' }
214
+ end
215
+
216
+ # TODO: Why does setting the host fail?
217
+ def test_set_machine
218
+ assert_respond_to(@ts, :host=)
219
+ assert_respond_to(@ts, :machine=)
220
+ #assert_nothing_raised{ @ts.machine = @@host }
221
+ end
222
+
223
+ def test_get_max_run_time
224
+ assert_respond_to(@ts, :max_run_time)
225
+ assert_nothing_raised{ @ts.max_run_time }
226
+ assert_kind_of(Fixnum, @ts.max_run_time)
227
+ end
228
+
229
+ def test_get_max_run_time_expected_errors
230
+ assert_raise(ArgumentError){ @ts.max_run_time(true) }
231
+ end
232
+
233
+ def test_set_max_run_time
234
+ assert_respond_to(@ts, :max_run_time=)
235
+ assert_nothing_raised{ @ts.max_run_time = 20000 }
236
+ end
237
+
238
+ def test_set_max_run_time_expected_errors
239
+ assert_raise(ArgumentError){ @ts.send(:max_run_time=) }
240
+ assert_raise(TypeError){ @ts.max_run_time = true }
241
+ end
242
+
243
+ def test_most_recent_run_time
244
+ assert_respond_to(@ts, :most_recent_run_time)
245
+ assert_nothing_raised{ @ts.most_recent_run_time }
246
+ assert_nil(@ts.most_recent_run_time)
247
+ end
248
+
249
+ def test_most_recent_run_time_expected_errors
250
+ assert_raise(ArgumentError){ @ts.most_recent_run_time(true) }
251
+ assert_raise(NoMethodError){ @ts.most_recent_run_time = Time.now }
252
+ end
253
+
254
+ def test_new_work_item
255
+ assert_respond_to(@ts, :new_work_item)
256
+ assert_nothing_raised{ @ts.new_work_item('bar', @trigger) }
257
+ end
258
+
259
+ def test_new_work_item_expected_errors
260
+ assert_raise(ArgumentError){ @ts.new_work_item('test', {:bogus => 1}) }
261
+ end
262
+
263
+ def test_new_task_alias
264
+ assert_respond_to(@ts, :new_task)
265
+ assert_equal(true, @ts.method(:new_task) == @ts.method(:new_work_item))
266
+ end
267
+
268
+ def test_new_work_item_expected_argument_errors
269
+ assert_raise(ArgumentError){ @ts.new_work_item }
270
+ assert_raise(ArgumentError){ @ts.new_work_item('bar') }
271
+ assert_raise(TypeError){ @ts.new_work_item(1, 'bar') }
272
+ assert_raise(TypeError){ @ts.new_work_item('bar', 1) }
273
+ end
274
+
275
+ def test_next_run_time
276
+ assert_respond_to(@ts, :next_run_time)
277
+ assert_nothing_raised{ @ts.next_run_time }
278
+ assert_kind_of(Time, @ts.next_run_time)
279
+ end
280
+
281
+ def test_next_run_time_expected_errors
282
+ assert_raise(ArgumentError){ @ts.next_run_time(true) }
283
+ assert_raise(NoMethodError){ @ts.next_run_time = Time.now }
284
+ end
285
+
286
+ def test_get_parameters
287
+ assert_respond_to(@ts, :parameters)
288
+ assert_nothing_raised{ @ts.parameters }
289
+ end
290
+
291
+ def test_get_parameters_expected_errors
292
+ assert_raise(ArgumentError){ @ts.parameters('test') }
293
+ end
294
+
295
+ def set_parameters
296
+ assert_respond_to(@ts, :parameters=)
297
+ assert_nothing_raised{ @ts.parameters = "somefile.txt" }
298
+ end
299
+
300
+ def set_parameters_expected_errors
301
+ assert_raise(ArgumentError){ @ts.send(:parameters=) }
302
+ assert_raise(TypeError){ @ts.parameters = 1 }
303
+ end
304
+
305
+ def test_get_priority
306
+ assert_respond_to(@ts, :priority)
307
+ assert_nothing_raised{ @ts.priority }
308
+ assert_kind_of(String, @ts.priority)
309
+ end
310
+
311
+ def test_get_priority_expected_errors
312
+ assert_raise(ArgumentError){ @ts.priority(true) }
313
+ end
314
+
315
+ def test_set_priority
316
+ assert_respond_to(@ts, :priority=)
317
+ assert_nothing_raised{ @ts.priority = TaskScheduler::NORMAL }
318
+ end
319
+
320
+ def test_set_priority_expected_errors
321
+ assert_raise(ArgumentError){ @ts.send(:priority=) }
322
+ assert_raise(TypeError){ @ts.priority = 'alpha' }
323
+ end
324
+
325
+ # TODO: Find a harmless way to test this.
326
+ def test_run
327
+ assert_respond_to(@ts, :run)
328
+ end
329
+
330
+ def test_run_expected_errors
331
+ assert_raise(ArgumentError){ @ts.run(true) }
332
+ assert_raise(NoMethodError){ @ts.run = true }
333
+ end
334
+
335
+ def test_save
336
+ assert_respond_to(@ts, :save)
337
+ assert_nothing_raised{ @ts.save }
338
+ end
339
+
340
+ def test_save_custom_file
341
+ assert_nothing_raised{ @ts.save(@job_file) }
342
+ assert_equal(true, File.exists?(@job_file))
343
+ end
344
+
345
+ def test_save_expected_errors
346
+ assert_raise(TypeError){ @ts.save(true) }
347
+ assert_raise(ArgumentError){ @ts.save(@job_file, true) }
348
+ assert_raise(NoMethodError){ @ts.save = true }
349
+ assert_raise(TaskScheduler::Error){ @ts.save; @ts.save }
350
+ end
351
+
352
+ def test_status
353
+ assert_respond_to(@ts, :status)
354
+ assert_nothing_raised{ @ts.status }
355
+ assert_equal('not scheduled', @ts.status)
356
+ end
357
+
358
+ def test_status_expected_errors
359
+ assert_raise(ArgumentError){ @ts.status(true) }
360
+ assert_raise(NoMethodError){ @ts.status = true }
361
+ end
362
+
363
+ def test_terminate
364
+ assert_respond_to(@ts, :terminate)
365
+ end
366
+
367
+ def test_terminate_expected_errors
368
+ assert_raise(ArgumentError){ @ts.terminate(true) }
369
+ assert_raise(NoMethodError){ @ts.terminate = true }
370
+ assert_raise(TaskScheduler::Error){ @ts.terminate } # It's not running
371
+ end
372
+
373
+ def test_get_trigger
374
+ assert_respond_to(@ts, :trigger)
375
+ assert_nothing_raised{ @ts.trigger(0) }
376
+ assert_kind_of(Hash, @ts.trigger(0))
377
+ end
378
+
379
+ def test_get_trigger_expected_errors
380
+ assert_raises(ArgumentError){ @ts.trigger }
381
+ assert_raises(TaskScheduler::Error){ @ts.trigger(9999) }
382
+ end
383
+
384
+ def test_set_trigger
385
+ assert_respond_to(@ts, :trigger=)
386
+ assert_nothing_raised{ @ts.trigger = @trigger }
387
+ end
388
+
389
+ def test_set_trigger_transforms_and_validates
390
+ symbol_trigger = @trigger.dup
391
+ symbol_trigger[:TriGger_type] = symbol_trigger.delete('trigger_type')
392
+ assert_nothing_raised{ @ts.trigger = symbol_trigger }
393
+ end
394
+
395
+ def test_set_trigger_expected_errors
396
+ assert_raises(TypeError){ @ts.trigger = 'blah' }
397
+ end
398
+
399
+ def test_add_trigger
400
+ assert_respond_to(@ts, :add_trigger)
401
+ assert_nothing_raised{ @ts.add_trigger(0, @trigger) }
402
+ end
403
+
404
+ def test_add_trigger_transforms_and_validates
405
+ symbol_trigger = @trigger.dup
406
+ symbol_trigger[:TriGger_type] = symbol_trigger.delete('trigger_type')
407
+ assert_nothing_raised{ @ts.add_trigger(0, symbol_trigger) }
408
+ end
409
+
410
+ def test_add_trigger_expected_errors
411
+ assert_raises(ArgumentError){ @ts.add_trigger }
412
+ assert_raises(ArgumentError){ @ts.add_trigger(0) }
413
+ assert_raises(TypeError){ @ts.add_trigger(0, 'foo') }
414
+ end
415
+
416
+ def test_trigger_count
417
+ assert_respond_to(@ts, :trigger_count)
418
+ assert_nothing_raised{ @ts.trigger_count }
419
+ assert_kind_of(Fixnum, @ts.trigger_count)
420
+ end
421
+
422
+ def test_trigger_count_expected_errors
423
+ assert_raise(ArgumentError){ @ts.trigger_count(true) }
424
+ assert_raise(NoMethodError){ @ts.trigger_count = 1 }
425
+ end
426
+
427
+ def test_trigger_delete
428
+ assert_respond_to(@ts, :delete_trigger)
429
+ assert_nothing_raised{ @ts.delete_trigger(0) }
430
+ end
431
+
432
+ def test_trigger_delete_expected_errors
433
+ assert_raise(ArgumentError){ @ts.delete_trigger }
434
+ assert_raise(TaskScheduler::Error){ @ts.delete_trigger(9999) }
435
+ end
436
+
437
+ def test_trigger_string
438
+ assert_respond_to(@ts, :trigger_string)
439
+ assert_nothing_raised{ @ts.trigger_string(0) }
440
+ assert_equal('At 7:14 AM every day, starting 4/11/2009', @ts.trigger_string(0))
441
+ end
442
+
443
+ def test_trigger_string_expected_errors
444
+ assert_raise(ArgumentError){ @ts.trigger_string }
445
+ assert_raise(ArgumentError){ @ts.trigger_string(0, 0) }
446
+ assert_raise(TypeError){ @ts.trigger_string('alpha') }
447
+ assert_raise(TaskScheduler::Error){ @ts.trigger_string(9999) }
448
+ end
449
+
450
+ def test_get_working_directory
451
+ assert_respond_to(@ts, :working_directory)
452
+ assert_nothing_raised{ @ts.working_directory }
453
+ assert_kind_of(String, @ts.working_directory)
454
+ end
455
+
456
+ def test_get_working_directory_expected_errors
457
+ assert_raise(ArgumentError){ @ts.working_directory(true) }
458
+ end
459
+
460
+ def test_set_working_directory
461
+ assert_respond_to(@ts, :working_directory=)
462
+ assert_nothing_raised{ @ts.working_directory = "C:\\" }
463
+ end
464
+
465
+ def test_set_working_directory_expected_errors
466
+ assert_raise(ArgumentError){ @ts.send(:working_directory=) }
467
+ assert_raise(TypeError){ @ts.working_directory = 1 }
468
+ end
469
+
470
+ def test_constants
471
+ assert_not_nil(TaskScheduler::MONDAY)
472
+ assert_not_nil(TaskScheduler::TUESDAY)
473
+ assert_not_nil(TaskScheduler::WEDNESDAY)
474
+ assert_not_nil(TaskScheduler::THURSDAY)
475
+ assert_not_nil(TaskScheduler::FRIDAY)
476
+ assert_not_nil(TaskScheduler::SATURDAY)
477
+ assert_not_nil(TaskScheduler::SUNDAY)
478
+
479
+ assert_not_nil(TaskScheduler::JANUARY)
480
+ assert_not_nil(TaskScheduler::FEBRUARY)
481
+ assert_not_nil(TaskScheduler::MARCH)
482
+ assert_not_nil(TaskScheduler::APRIL)
483
+ assert_not_nil(TaskScheduler::MAY)
484
+ assert_not_nil(TaskScheduler::JUNE)
485
+ assert_not_nil(TaskScheduler::JULY)
486
+ assert_not_nil(TaskScheduler::AUGUST)
487
+ assert_not_nil(TaskScheduler::SEPTEMBER)
488
+ assert_not_nil(TaskScheduler::OCTOBER)
489
+ assert_not_nil(TaskScheduler::NOVEMBER)
490
+ assert_not_nil(TaskScheduler::DECEMBER)
491
+
492
+ assert_not_nil(TaskScheduler::ONCE)
493
+ assert_not_nil(TaskScheduler::DAILY)
494
+ assert_not_nil(TaskScheduler::WEEKLY)
495
+ assert_not_nil(TaskScheduler::MONTHLYDATE)
496
+ assert_not_nil(TaskScheduler::MONTHLYDOW)
497
+
498
+ assert_not_nil(TaskScheduler::ON_IDLE)
499
+ assert_not_nil(TaskScheduler::AT_SYSTEMSTART)
500
+ assert_not_nil(TaskScheduler::AT_LOGON)
501
+
502
+ assert_not_nil(TaskScheduler::INTERACTIVE)
503
+ assert_not_nil(TaskScheduler::DELETE_WHEN_DONE)
504
+ assert_not_nil(TaskScheduler::DISABLED)
505
+ assert_not_nil(TaskScheduler::START_ONLY_IF_IDLE)
506
+ assert_not_nil(TaskScheduler::KILL_ON_IDLE_END)
507
+ assert_not_nil(TaskScheduler::DONT_START_IF_ON_BATTERIES)
508
+ assert_not_nil(TaskScheduler::KILL_IF_GOING_ON_BATTERIES)
509
+ assert_not_nil(TaskScheduler::HIDDEN)
510
+ assert_not_nil(TaskScheduler::RESTART_ON_IDLE_RESUME)
511
+ assert_not_nil(TaskScheduler::SYSTEM_REQUIRED)
512
+ assert_not_nil(TaskScheduler::FLAG_HAS_END_DATE)
513
+ assert_not_nil(TaskScheduler::FLAG_KILL_AT_DURATION_END)
514
+ assert_not_nil(TaskScheduler::FLAG_DISABLED)
515
+ assert_not_nil(TaskScheduler::MAX_RUN_TIMES)
516
+
517
+ assert_not_nil(TaskScheduler::IDLE)
518
+ assert_not_nil(TaskScheduler::NORMAL)
519
+ assert_not_nil(TaskScheduler::HIGH)
520
+ assert_not_nil(TaskScheduler::REALTIME)
521
+ assert_not_nil(TaskScheduler::ABOVE_NORMAL)
522
+ assert_not_nil(TaskScheduler::BELOW_NORMAL)
523
+ end
524
+
525
+ def teardown
526
+ File.delete(@job_file) if File.exists?(@job_file)
527
+ @ts.delete(@task) if @ts.enum.include?(@task + '.job')
528
+
529
+ @ts = nil
530
+ @trigger = nil
531
+ @job_file = nil
532
+ @task = nil
533
+ end
534
+
535
+ def self.shutdown
536
+ @@host = nil
537
+ end
524
538
  end