win32-eventlog 0.4.3 → 0.4.4
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +10 -1
- data/MANIFEST +17 -22
- data/README +44 -38
- data/Rakefile +23 -0
- data/lib/win32/eventlog.rb +33 -25
- data/lib/win32/mc.rb +8 -7
- data/test/tc_eventlog.rb +18 -22
- data/test/tc_mc.rb +5 -7
- data/test/ts_all.rb +3 -5
- data/win32-eventlog.gemspec +2 -2
- metadata +5 -4
- data/install.rb +0 -13
data/CHANGES
CHANGED
@@ -1,3 +1,12 @@
|
|
1
|
+
= 0.4.4 - 31-Jul-2007
|
2
|
+
* The EventLogError class is now EventLog::Error.
|
3
|
+
* The MCError class is now MC::Error.
|
4
|
+
* Added a Rakefile with tasks for installation and testing.
|
5
|
+
* Removed the install.rb file. Installation is now handled by the Rakefile.
|
6
|
+
* Fixed some bad test cases in tc_eventlog.rb.
|
7
|
+
* Added some more source comments.
|
8
|
+
* Updates to the README and MANIFEST file.
|
9
|
+
|
1
10
|
= 0.4.3 - 18-Dec-2006
|
2
11
|
* Removed the FORMAT_MESSAGE_FROM_SYSTEM flag to the FormatMessage function
|
3
12
|
in the get_description private method because it could sometimes return
|
@@ -143,4 +152,4 @@
|
|
143
152
|
* Minor doc updates and cleanup.
|
144
153
|
|
145
154
|
== 0.1.0 - 14-Oct-2003
|
146
|
-
* Initial release
|
155
|
+
* Initial release
|
data/MANIFEST
CHANGED
@@ -1,22 +1,17 @@
|
|
1
|
-
MANIFEST
|
2
|
-
CHANGES
|
3
|
-
README
|
4
|
-
|
5
|
-
win32-eventlog.gemspec
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
examples/
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
test/foo.mc
|
20
|
-
test/ts_all.rb
|
21
|
-
test/tc_eventlog.rb
|
22
|
-
test/tc_mc.rb
|
1
|
+
* MANIFEST
|
2
|
+
* CHANGES
|
3
|
+
* README
|
4
|
+
* Rakefile
|
5
|
+
* win32-eventlog.gemspec
|
6
|
+
* doc/tutorial.txt
|
7
|
+
* examples/test_read.rb
|
8
|
+
* examples/test_write.rb
|
9
|
+
* examples/test_notify.rb
|
10
|
+
* lib/win32/eventlog.rb
|
11
|
+
* lib/win32/mc.rb
|
12
|
+
* misc/install_msg.rb
|
13
|
+
* misc/rubymsg.mc
|
14
|
+
* test/foo.mc
|
15
|
+
* test/ts_all.rb
|
16
|
+
* test/tc_eventlog.rb
|
17
|
+
* test/tc_mc.rb
|
data/README
CHANGED
@@ -1,60 +1,66 @@
|
|
1
|
-
=
|
2
|
-
|
1
|
+
= Description
|
2
|
+
The win32-eventlog library provides an interface for reading from and
|
3
|
+
writing to the MS Windows Event Log.
|
4
|
+
|
5
|
+
In addition, you can create your own message event sources using the
|
6
|
+
win32-mc library (provided with this distro), assuming you have the
|
7
|
+
proper tools installed.
|
3
8
|
|
4
9
|
= Prerequisites
|
5
|
-
Ruby 1.8.2 or later.
|
6
|
-
windows-pr 0.5.0 or later.
|
10
|
+
Ruby 1.8.2 or later.
|
11
|
+
windows-pr 0.5.0 or later.
|
12
|
+
|
13
|
+
The 'mc', 'rc' and 'link' command line tools are required to create and
|
14
|
+
install message sources. You won't need these for simply reading from or
|
15
|
+
writing to an existing event log.
|
7
16
|
|
8
17
|
= Installation
|
9
|
-
|
10
|
-
|
11
|
-
ruby install.rb
|
12
|
-
== Gem Install
|
13
|
-
ruby win32-eventlog.gemspec
|
14
|
-
gem install win32-eventlog-X.Y.Z-mswin32.gem
|
18
|
+
rake test (optional)
|
19
|
+
rake install (non-gem) or rake install_gem (gem)
|
15
20
|
|
16
|
-
This will install both the win32-eventlog and win32-mc
|
17
|
-
is strictly for turning .mc files into .dll files.
|
18
|
-
for more details.
|
21
|
+
This will install both the win32-eventlog and win32-mc libraries. The latter
|
22
|
+
is strictly for turning .mc files into .dll files. See the mc documentation
|
23
|
+
for more details.
|
19
24
|
|
20
25
|
= Installing the 'RubyMsg' event source
|
21
|
-
If you wish to install the RubyMsg event source, run the 'install_msg.rb'
|
22
|
-
script in the 'misc' directory. This will create a 'rubymsg' directory
|
23
|
-
your toplevel Ruby installation directory (usually C:\ruby), and
|
24
|
-
.dll, .h, .rc and .res files there, in addition to copying the
|
25
|
-
It will then install the 'RubyMsg' event source into your
|
26
|
+
If you wish to install the RubyMsg event source, run the 'install_msg.rb'
|
27
|
+
script in the 'misc' directory. This will create a 'rubymsg' directory
|
28
|
+
under your toplevel Ruby installation directory (usually C:\ruby), and
|
29
|
+
create the .dll, .h, .rc and .res files there, in addition to copying the
|
30
|
+
rubymsg.mc file. It will then install the 'RubyMsg' event source into your
|
31
|
+
registry.
|
26
32
|
|
27
|
-
DO NOT MOVE THE DLL FILE ONCE IT IS INSTALLED! If you do, you will have
|
28
|
-
to delete the registry entry and reinstall it with the correct path.
|
33
|
+
DO NOT MOVE THE DLL FILE ONCE IT IS INSTALLED! If you do, you will have
|
34
|
+
to delete the registry entry and reinstall it with the correct path.
|
29
35
|
|
30
|
-
Take a look at the rubymsg.mc file for the category and message values.
|
31
|
-
you do not understand this, please read the 'tutorial.txt' file in the 'doc'
|
32
|
-
directory.
|
36
|
+
Take a look at the rubymsg.mc file for the category and message values. If
|
37
|
+
you do not understand this, please read the 'tutorial.txt' file in the 'doc'
|
38
|
+
directory.
|
33
39
|
|
34
40
|
= Additional documentation
|
35
|
-
If you are unfamiliar with message files and event logging on Windows in
|
36
|
-
general, please read the 'tutorial.txt' file.
|
41
|
+
If you are unfamiliar with message files and event logging on Windows in
|
42
|
+
general, please read the 'tutorial.txt' file.
|
37
43
|
|
38
|
-
There are also a couple of sample test scripts under the 'examples'
|
39
|
-
directory if you want to futz around and get a feel for how things work.
|
44
|
+
There are also a couple of sample test scripts under the 'examples'
|
45
|
+
directory if you want to futz around and get a feel for how things work.
|
40
46
|
|
41
47
|
= If the tc_mc.rb tests fail
|
42
|
-
There's a chance that you either don't have the mc, rc and/or link commands
|
43
|
-
installed or they're not in your %PATH%.
|
44
|
-
them somewhere on your system.
|
48
|
+
There's a chance that you either don't have the mc, rc and/or link commands
|
49
|
+
installed or they're not in your %PATH%. If you have MSVC++, you should have
|
50
|
+
them somewhere on your system.
|
45
51
|
|
46
52
|
= Known Issues
|
47
|
-
The code currently only checks the EventMessage file, it does not check the
|
48
|
-
CategoryMessage or ParameterMessage files.
|
53
|
+
The code currently only checks the EventMessage file, it does not check the
|
54
|
+
CategoryMessage or ParameterMessage files.
|
49
55
|
|
50
56
|
= License
|
51
|
-
Ruby's
|
57
|
+
Ruby's
|
52
58
|
|
53
59
|
= Warranty
|
54
|
-
This package is provided "as is" and without any express or
|
55
|
-
implied warranties, including, without limitation, the implied
|
56
|
-
warranties of merchantability and fitness for a particular purpose.
|
60
|
+
This package is provided "as is" and without any express or
|
61
|
+
implied warranties, including, without limitation, the implied
|
62
|
+
warranties of merchantability and fitness for a particular purpose.
|
57
63
|
|
58
64
|
= Authors
|
59
|
-
Daniel J. Berger
|
60
|
-
Park Heesob
|
65
|
+
Daniel J. Berger
|
66
|
+
Park Heesob
|
data/Rakefile
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'rake'
|
2
|
+
require 'rake/testtask'
|
3
|
+
|
4
|
+
desc "Install the win32-eventlog and win32-mc libraries (non-gem)"
|
5
|
+
task :install do
|
6
|
+
dest = File.join(Config::CONFIG['sitelibdir'], 'win32')
|
7
|
+
Dir.mkdir(dest) unless File.exists? dest
|
8
|
+
cp 'lib/win32/eventlog.rb', dest, :verbose => true
|
9
|
+
cp 'lib/win32/mc.rb', dest, :verbose => true
|
10
|
+
end
|
11
|
+
|
12
|
+
desc "Install the win32-eventlog package as a gem"
|
13
|
+
task :install_gem do
|
14
|
+
ruby 'win32-eventlog.gemspec'
|
15
|
+
file = Dir["*.gem"].first
|
16
|
+
sh "gem install #{file}"
|
17
|
+
end
|
18
|
+
|
19
|
+
Rake::TestTask.new do |t|
|
20
|
+
t.libs << 'lib'
|
21
|
+
t.warning = true
|
22
|
+
t.test_files = FileList['test/ts*']
|
23
|
+
end
|
data/lib/win32/eventlog.rb
CHANGED
@@ -15,9 +15,17 @@ class String
|
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
|
+
# The Win32 module serves as a namespace only.
|
18
19
|
module Win32
|
19
|
-
|
20
|
+
|
21
|
+
# The EventLog class encapsulates an Event Log source and provides methods
|
22
|
+
# for interacting with that source.
|
20
23
|
class EventLog
|
24
|
+
|
25
|
+
# The EventLog::Error is raised in cases where interaction with the
|
26
|
+
# event log should happen to fail for any reason.
|
27
|
+
class Error < StandardError; end
|
28
|
+
|
21
29
|
include Windows::Error
|
22
30
|
include Windows::EventLog
|
23
31
|
include Windows::Security
|
@@ -29,7 +37,7 @@ module Win32
|
|
29
37
|
extend Windows::Error
|
30
38
|
extend Windows::Registry
|
31
39
|
|
32
|
-
VERSION = '0.4.
|
40
|
+
VERSION = '0.4.4'
|
33
41
|
|
34
42
|
# Aliased read flags
|
35
43
|
FORWARDS_READ = EVENTLOG_FORWARDS_READ
|
@@ -45,12 +53,12 @@ module Win32
|
|
45
53
|
AUDIT_SUCCESS = EVENTLOG_AUDIT_SUCCESS
|
46
54
|
AUDIT_FAILURE = EVENTLOG_AUDIT_FAILURE
|
47
55
|
|
48
|
-
# These are not meant for public use
|
49
56
|
BUFFER_SIZE = 1024 * 64
|
50
57
|
MAX_SIZE = 256
|
51
58
|
MAX_STRINGS = 16
|
52
59
|
BASE_KEY = "SYSTEM\\CurrentControlSet\\Services\\EventLog\\"
|
53
60
|
|
61
|
+
# The EventLogStruct encapsulates a single event log record.
|
54
62
|
EventLogStruct = Struct.new('EventLogStruct', :record_number,
|
55
63
|
:time_generated, :time_written, :event_id, :event_type, :category,
|
56
64
|
:source, :computer, :user, :string_inserts, :description
|
@@ -101,7 +109,7 @@ module Win32
|
|
101
109
|
|
102
110
|
if @handle == 0
|
103
111
|
error = "#{function} failed: " + get_last_error
|
104
|
-
raise
|
112
|
+
raise Error, error
|
105
113
|
end
|
106
114
|
|
107
115
|
# Ensure the handle is closed at the end of a block
|
@@ -181,14 +189,14 @@ module Win32
|
|
181
189
|
|
182
190
|
# The key_name must be specified
|
183
191
|
unless hash['key_name']
|
184
|
-
raise
|
192
|
+
raise Error, 'no event_type specified'
|
185
193
|
end
|
186
194
|
|
187
195
|
key = key_base << hash['source'] << "\\" << hash['key_name']
|
188
196
|
|
189
197
|
if RegCreateKey(HKEY_LOCAL_MACHINE, key, hkey) != ERROR_SUCCESS
|
190
198
|
error = 'RegCreateKey() failed: ' + get_last_error
|
191
|
-
raise
|
199
|
+
raise Error, error
|
192
200
|
end
|
193
201
|
|
194
202
|
hkey = hkey.unpack('L').first
|
@@ -208,7 +216,7 @@ module Win32
|
|
208
216
|
if rv != ERROR_SUCCESS
|
209
217
|
error = 'RegSetValueEx() failed: ', get_last_error
|
210
218
|
RegCloseKey(hkey)
|
211
|
-
raise
|
219
|
+
raise Error, error
|
212
220
|
end
|
213
221
|
end
|
214
222
|
|
@@ -227,7 +235,7 @@ module Win32
|
|
227
235
|
if rv != ERROR_SUCCESS
|
228
236
|
error = 'RegSetValueEx() failed: ', get_last_error
|
229
237
|
RegCloseKey(hkey)
|
230
|
-
raise
|
238
|
+
raise Error, error
|
231
239
|
end
|
232
240
|
end
|
233
241
|
|
@@ -246,7 +254,7 @@ module Win32
|
|
246
254
|
if rv != ERROR_SUCCESS
|
247
255
|
error = 'RegSetValueEx() failed: ', get_last_error
|
248
256
|
RegCloseKey(hkey)
|
249
|
-
raise
|
257
|
+
raise Error, error
|
250
258
|
end
|
251
259
|
end
|
252
260
|
|
@@ -263,7 +271,7 @@ module Win32
|
|
263
271
|
if rv != ERROR_SUCCESS
|
264
272
|
error = 'RegSetValueEx() failed: ', get_last_error
|
265
273
|
RegCloseKey(hkey)
|
266
|
-
raise
|
274
|
+
raise Error, error
|
267
275
|
end
|
268
276
|
|
269
277
|
RegCloseKey(hkey)
|
@@ -271,13 +279,13 @@ module Win32
|
|
271
279
|
end
|
272
280
|
|
273
281
|
# Backs up the event log to +file+. Note that you cannot backup to
|
274
|
-
# a file that already exists or a
|
282
|
+
# a file that already exists or a Error will be raised.
|
275
283
|
#
|
276
284
|
def backup(file)
|
277
285
|
raise TypeError unless file.is_a?(String)
|
278
286
|
unless BackupEventLog(@handle, file)
|
279
287
|
error = 'BackupEventLog() failed: ' + get_last_error
|
280
|
-
raise
|
288
|
+
raise Error, error
|
281
289
|
end
|
282
290
|
self
|
283
291
|
end
|
@@ -291,7 +299,7 @@ module Win32
|
|
291
299
|
|
292
300
|
unless ClearEventLog(@handle, backup_file)
|
293
301
|
error = 'ClearEventLog() failed: ' + get_last_error
|
294
|
-
raise
|
302
|
+
raise Error
|
295
303
|
end
|
296
304
|
|
297
305
|
self
|
@@ -326,7 +334,7 @@ module Win32
|
|
326
334
|
|
327
335
|
unless GetOldestEventLogRecord(@handle, rec)
|
328
336
|
error = 'GetOldestEventLogRecord() failed: ' + get_last_error
|
329
|
-
raise
|
337
|
+
raise Error, error
|
330
338
|
end
|
331
339
|
|
332
340
|
rec.unpack('L').first
|
@@ -340,7 +348,7 @@ module Win32
|
|
340
348
|
unless GetNumberOfEventLogRecords(@handle, total)
|
341
349
|
error = 'GetNumberOfEventLogRecords() failed: '
|
342
350
|
error += get_last_error
|
343
|
-
raise
|
351
|
+
raise Error, error
|
344
352
|
end
|
345
353
|
|
346
354
|
total.unpack('L').first
|
@@ -350,11 +358,11 @@ module Win32
|
|
350
358
|
# log. Unlike EventLog#tail, this method breaks out of the block after
|
351
359
|
# the event.
|
352
360
|
#
|
353
|
-
# Raises an
|
361
|
+
# Raises an Error if no block is provided.
|
354
362
|
#
|
355
363
|
def notify_change(&block)
|
356
364
|
unless block_given?
|
357
|
-
raise
|
365
|
+
raise Error, 'block missing for notify_change()'
|
358
366
|
end
|
359
367
|
|
360
368
|
# Reopen the handle because the NotifyChangeEventLog() function will
|
@@ -363,14 +371,14 @@ module Win32
|
|
363
371
|
|
364
372
|
if @handle == 0
|
365
373
|
error = "OpenEventLog() failed: " + get_last_error
|
366
|
-
raise
|
374
|
+
raise Error, error
|
367
375
|
end
|
368
376
|
|
369
377
|
event = CreateEvent(0, 0, 0, 0)
|
370
378
|
|
371
379
|
unless NotifyChangeEventLog(@handle, event)
|
372
380
|
error = 'NotifyChangeEventLog() failed: ' + get_last_error
|
373
|
-
raise
|
381
|
+
raise Error, error
|
374
382
|
end
|
375
383
|
|
376
384
|
wait_result = WaitForSingleObject(event, INFINITE)
|
@@ -378,7 +386,7 @@ module Win32
|
|
378
386
|
if wait_result == WAIT_FAILED
|
379
387
|
error = 'WaitForSingleObject() failed: ' + get_last_error
|
380
388
|
CloseHandle(event)
|
381
|
-
raise
|
389
|
+
raise Error, error
|
382
390
|
else
|
383
391
|
last = read_last_event
|
384
392
|
block.call(last)
|
@@ -393,7 +401,7 @@ module Win32
|
|
393
401
|
# this method does not break out of the block after the event. The read
|
394
402
|
# +frequency+ is set to 5 seconds by default.
|
395
403
|
#
|
396
|
-
# Raises an
|
404
|
+
# Raises an Error if no block is provided.
|
397
405
|
#
|
398
406
|
# The delay between reads is due to the nature of the Windows event log.
|
399
407
|
# It is not really designed to be tailed in the manner of a Unix syslog,
|
@@ -402,7 +410,7 @@ module Win32
|
|
402
410
|
#
|
403
411
|
def tail(frequency = 5)
|
404
412
|
unless block_given?
|
405
|
-
raise
|
413
|
+
raise Error, 'block missing for tail()'
|
406
414
|
end
|
407
415
|
|
408
416
|
old_total = total_records()
|
@@ -578,14 +586,14 @@ module Win32
|
|
578
586
|
|
579
587
|
# The event_type must be specified
|
580
588
|
unless hash['event_type']
|
581
|
-
raise
|
589
|
+
raise Error, 'no event_type specified'
|
582
590
|
end
|
583
591
|
|
584
592
|
handle = RegisterEventSource(@server, hash['source'])
|
585
593
|
|
586
594
|
if handle == 0
|
587
595
|
error = 'RegisterEventSource() failed: ' + get_last_error
|
588
|
-
raise
|
596
|
+
raise Error, error
|
589
597
|
end
|
590
598
|
|
591
599
|
if hash['data'].is_a?(String)
|
@@ -611,7 +619,7 @@ module Win32
|
|
611
619
|
|
612
620
|
unless bool
|
613
621
|
error = 'ReportEvent() failed: ' + get_last_error
|
614
|
-
raise
|
622
|
+
raise Error, error
|
615
623
|
end
|
616
624
|
|
617
625
|
self
|
data/lib/win32/mc.rb
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
module Win32
|
2
|
-
class MCError < StandardError; end
|
3
2
|
class MC
|
4
|
-
|
3
|
+
class Error < StandardError; end;
|
4
|
+
|
5
|
+
VERSION = '0.1.3'
|
5
6
|
|
6
7
|
attr_accessor :mc_file, :res_file, :dll_file
|
7
8
|
|
@@ -38,24 +39,24 @@ module Win32
|
|
38
39
|
end
|
39
40
|
|
40
41
|
# Creates the .res (resource) file from the .rc file generated by the
|
41
|
-
# MC#create_header method. Raises an
|
42
|
+
# MC#create_header method. Raises an MC::Error if the .rc file is not
|
42
43
|
# found.
|
43
44
|
#
|
44
45
|
def create_res_file
|
45
46
|
rc_file = File.basename(@mc_file, '.mc') + '.rc'
|
46
47
|
unless File.exists?(rc_file)
|
47
|
-
raise
|
48
|
+
raise MC::Error, "No .rc file found: #{@rc_file}"
|
48
49
|
end
|
49
50
|
system("rc -r -fo #{@res_file} #{rc_file}")
|
50
51
|
end
|
51
52
|
|
52
53
|
# Creates the .dll file from the .res file generated by the
|
53
|
-
# MC#create_res_file method. Raises an
|
54
|
+
# MC#create_res_file method. Raises an MC::Error if the .res file is not
|
54
55
|
# found.
|
55
56
|
#
|
56
57
|
def create_dll_file
|
57
58
|
unless File.exists?(@res_file)
|
58
|
-
raise
|
59
|
+
raise MC::Error, "No .res file found: #{@res_file}"
|
59
60
|
end
|
60
61
|
system("link -dll -noentry -out:#{@dll_file} #{@res_file}")
|
61
62
|
end
|
@@ -93,7 +94,7 @@ if $0 == __FILE__
|
|
93
94
|
|
94
95
|
unless mc_file
|
95
96
|
msg = "Usage: ruby mc.rb 'filename.mc'"
|
96
|
-
raise
|
97
|
+
raise MC::Error, msg
|
97
98
|
end
|
98
99
|
|
99
100
|
m = MC.new(mc_file)
|
data/test/tc_eventlog.rb
CHANGED
@@ -1,13 +1,10 @@
|
|
1
|
-
|
1
|
+
##############################################################################
|
2
2
|
# tc_eventlog.rb
|
3
3
|
#
|
4
|
-
# Test case for the win32-eventlog package.
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
$LOAD_PATH.unshift Dir.pwd + '/lib'
|
9
|
-
Dir.chdir('test') rescue nil
|
10
|
-
|
4
|
+
# Test case for the win32-eventlog package. You should run this test case
|
5
|
+
# via the 'rake test' Rakefile task. This test will take a minute or two
|
6
|
+
# to complete.
|
7
|
+
#############################################################################
|
11
8
|
require 'test/unit'
|
12
9
|
require 'win32/eventlog'
|
13
10
|
require 'socket'
|
@@ -26,7 +23,7 @@ class TC_EventLog < Test::Unit::TestCase
|
|
26
23
|
end
|
27
24
|
|
28
25
|
def test_version
|
29
|
-
assert_equal('0.4.
|
26
|
+
assert_equal('0.4.4', EventLog::VERSION)
|
30
27
|
end
|
31
28
|
|
32
29
|
# Use the alias to validate it as well.
|
@@ -39,7 +36,7 @@ class TC_EventLog < Test::Unit::TestCase
|
|
39
36
|
end
|
40
37
|
|
41
38
|
def test_constructor_expected_errors
|
42
|
-
assert_raises(
|
39
|
+
assert_raises(EventLog::Error){ EventLog.new('System', @hostname, 'foo') }
|
43
40
|
assert_raises(TypeError){ EventLog.open(1) }
|
44
41
|
assert_raises(TypeError){ EventLog.open('System', 1) }
|
45
42
|
end
|
@@ -109,20 +106,19 @@ class TC_EventLog < Test::Unit::TestCase
|
|
109
106
|
|
110
107
|
def test_seek_read
|
111
108
|
flags = EventLog::SEEK_READ | EventLog::FORWARDS_READ
|
112
|
-
assert_nothing_raised{ @last = @log.
|
109
|
+
assert_nothing_raised{ @last = @log.read[-10].record_number }
|
113
110
|
assert_nothing_raised{
|
114
|
-
@records = EventLog.read(nil, nil, flags, @last
|
111
|
+
@records = EventLog.read(nil, nil, flags, @last)
|
115
112
|
}
|
116
|
-
assert_equal(
|
117
|
-
assert_equal(@last, @records.last.record_number)
|
113
|
+
assert_equal(10, @records.length)
|
118
114
|
end
|
119
115
|
|
116
|
+
# This test could fail, since a record number + 10 may not actually exist.
|
120
117
|
def test_seek_read_backwards
|
121
118
|
flags = EventLog::SEEK_READ | EventLog::BACKWARDS_READ
|
122
|
-
assert_nothing_raised{ @
|
123
|
-
|
124
|
-
assert_equal(
|
125
|
-
assert_equal(1, @records.last.record_number)
|
119
|
+
assert_nothing_raised{ @last = @log.oldest_record_number + 10 }
|
120
|
+
assert_nothing_raised{ @records = EventLog.read(nil, nil, flags, @last) }
|
121
|
+
assert_equal(11, @records.length)
|
126
122
|
end
|
127
123
|
|
128
124
|
def test_server
|
@@ -146,7 +142,7 @@ class TC_EventLog < Test::Unit::TestCase
|
|
146
142
|
assert_respond_to(@log, :backup)
|
147
143
|
assert_nothing_raised{ @log.backup(@bakfile) }
|
148
144
|
assert(File.exists?(@bakfile))
|
149
|
-
assert_raises(
|
145
|
+
assert_raises(EventLog::Error){ @log.backup(@bakfile) }
|
150
146
|
end
|
151
147
|
|
152
148
|
# Since I don't want to actually clear anyone's event log, I can't really
|
@@ -181,7 +177,7 @@ class TC_EventLog < Test::Unit::TestCase
|
|
181
177
|
#
|
182
178
|
def test_tail
|
183
179
|
assert_respond_to(@log, :tail)
|
184
|
-
assert_raises(
|
180
|
+
assert_raises(EventLog::Error){ @log.tail } # requires block
|
185
181
|
end
|
186
182
|
|
187
183
|
# We can't test that this method actually executes properly since it goes
|
@@ -189,7 +185,7 @@ class TC_EventLog < Test::Unit::TestCase
|
|
189
185
|
#
|
190
186
|
def test_notify_change
|
191
187
|
assert_respond_to(@log, :notify_change)
|
192
|
-
assert_raises(
|
188
|
+
assert_raises(EventLog::Error){ @log.notify_change } # requires block
|
193
189
|
end
|
194
190
|
|
195
191
|
# I can't really do more in depth testing for this method since there
|
@@ -225,4 +221,4 @@ class TC_EventLog < Test::Unit::TestCase
|
|
225
221
|
@records = nil
|
226
222
|
@last = nil
|
227
223
|
end
|
228
|
-
end
|
224
|
+
end
|
data/test/tc_mc.rb
CHANGED
@@ -3,23 +3,21 @@
|
|
3
3
|
#
|
4
4
|
# Test suite for the win32-mc package. The tests need to run in a specific
|
5
5
|
# order, hence the numerics added to the method names.
|
6
|
+
#
|
7
|
+
# This test case should be run via the 'rake test' Rakefile task.
|
6
8
|
############################################################################
|
7
|
-
Dir.chdir('..') if File.basename(Dir.pwd) == 'test'
|
8
|
-
$LOAD_PATH.unshift Dir.pwd
|
9
|
-
$LOAD_PATH.unshift Dir.pwd + '/lib'
|
10
|
-
Dir.chdir('test') rescue nil
|
11
|
-
|
12
9
|
require 'test/unit'
|
13
10
|
require 'win32/mc'
|
14
11
|
include Win32
|
15
12
|
|
16
13
|
class TC_Win32_MC < Test::Unit::TestCase
|
17
14
|
def setup
|
15
|
+
Dir.chdir('test') unless File.basename(Dir.pwd) == 'test'
|
18
16
|
@mc = MC.new('foo.mc')
|
19
17
|
end
|
20
18
|
|
21
19
|
def test_01_version
|
22
|
-
assert_equal('0.1.
|
20
|
+
assert_equal('0.1.3', MC::VERSION)
|
23
21
|
end
|
24
22
|
|
25
23
|
def test_02_create_header
|
@@ -46,4 +44,4 @@ class TC_Win32_MC < Test::Unit::TestCase
|
|
46
44
|
@mc = nil
|
47
45
|
File.delete('foo.dll') rescue nil
|
48
46
|
end
|
49
|
-
end
|
47
|
+
end
|
data/test/ts_all.rb
CHANGED
@@ -1,7 +1,5 @@
|
|
1
|
-
|
2
|
-
$LOAD_PATH.unshift
|
3
|
-
$LOAD_PATH.unshift Dir.pwd + '/lib'
|
4
|
-
Dir.chdir('test') rescue nil
|
1
|
+
$LOAD_PATH.unshift(Dir.pwd)
|
2
|
+
$LOAD_PATH.unshift(File.join(Dir.pwd, 'test'))
|
5
3
|
|
6
4
|
require 'tc_eventlog'
|
7
|
-
require 'tc_mc'
|
5
|
+
require 'tc_mc'
|
data/win32-eventlog.gemspec
CHANGED
@@ -2,7 +2,7 @@ require "rubygems"
|
|
2
2
|
|
3
3
|
spec = Gem::Specification.new do |gem|
|
4
4
|
gem.name = "win32-eventlog"
|
5
|
-
gem.version = "0.4.
|
5
|
+
gem.version = "0.4.4"
|
6
6
|
gem.author = "Daniel J. Berger"
|
7
7
|
gem.email = "djberg96@gmail.com"
|
8
8
|
gem.homepage = "http://www.rubyforge.org/projects/win32utils"
|
@@ -14,7 +14,7 @@ spec = Gem::Specification.new do |gem|
|
|
14
14
|
gem.files = Dir["lib/win32/*.rb"] + Dir["test/*"] + Dir["[A-Z]*"]
|
15
15
|
gem.files.reject! { |fn| fn.include? "CVS" }
|
16
16
|
gem.require_path = "lib"
|
17
|
-
gem.extra_rdoc_files = ["README", "CHANGES", "doc/tutorial.txt"]
|
17
|
+
gem.extra_rdoc_files = ["README", "CHANGES", "MANIFEST", "doc/tutorial.txt"]
|
18
18
|
gem.add_dependency("windows-pr", ">= 0.5.0")
|
19
19
|
end
|
20
20
|
|
metadata
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
|
-
rubygems_version: 0.9.
|
2
|
+
rubygems_version: 0.9.2
|
3
3
|
specification_version: 1
|
4
4
|
name: win32-eventlog
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.4.
|
7
|
-
date:
|
6
|
+
version: 0.4.4
|
7
|
+
date: 2007-07-31 00:00:00 -06:00
|
8
8
|
summary: Interface for the MS Windows Event Log.
|
9
9
|
require_paths:
|
10
10
|
- lib
|
@@ -40,10 +40,10 @@ files:
|
|
40
40
|
- CVS
|
41
41
|
- doc
|
42
42
|
- examples
|
43
|
-
- install.rb
|
44
43
|
- lib
|
45
44
|
- MANIFEST
|
46
45
|
- misc
|
46
|
+
- Rakefile
|
47
47
|
- README
|
48
48
|
- test
|
49
49
|
- win32-eventlog.gemspec
|
@@ -55,6 +55,7 @@ rdoc_options: []
|
|
55
55
|
extra_rdoc_files:
|
56
56
|
- README
|
57
57
|
- CHANGES
|
58
|
+
- MANIFEST
|
58
59
|
- doc/tutorial.txt
|
59
60
|
executables: []
|
60
61
|
|
data/install.rb
DELETED
@@ -1,13 +0,0 @@
|
|
1
|
-
# For those who don't like gems...
|
2
|
-
require 'rbconfig'
|
3
|
-
require 'ftools'
|
4
|
-
include Config
|
5
|
-
|
6
|
-
sitelibdir = CONFIG['sitelibdir']
|
7
|
-
installdir = sitelibdir + '/win32'
|
8
|
-
file1 = 'lib\win32\eventlog.rb'
|
9
|
-
file2 = 'lib\win32\mc.rb'
|
10
|
-
|
11
|
-
Dir.mkdir(installdir) unless File.exists?(installdir)
|
12
|
-
File.copy(file1, installdir, true)
|
13
|
-
File.copy(file2, installdir, true)
|