This repository has been archived by the owner on Apr 29, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.rb
executable file
·138 lines (122 loc) · 3.64 KB
/
test.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#!/usr/bin/ruby
require 'test/unit'
require 'jlog'
# require 'pp'
class TC_JLog < Test::Unit::TestCase
def test_CreateJLog
assert_nothing_raised {@jo = JLog.new("/tmp/junit.log")}
assert_kind_of(JLog, @jo, "JLog Object creation failed");
assert_nothing_raised {@jo.close}
end
def test_AddSubscriber
@jo = JLog.new("/tmp/junit.log")
assert_nothing_raised do
@jo.add_subscriber("TestSub")
@jo.add_subscriber("TestSubRemove")
end
assert_nothing_raised do
@flag = 2;
@jo.list_subscribers.each { |s|
if(s =~ /TestSub(Remove|)/)
@flag -= 1;
end
}
end
assert_equal(0, @flag, "The two expected subscribers exist")
@jo.close
end
def test_RMSubscriber
@jo = JLog.new("/tmp/junit.log")
assert_nothing_raised { @jo.remove_subscriber("TestSubRemove") }
@jo.close
@jo = JLog.new("/tmp/junit.log")
@jo.list_subscribers.each { |s|
assert_not_equal("TestSubRemove", s, "Test Subscriber was not removed")
}
@jo.close
end
end
class TC_JLogWriter < Test::Unit::TestCase
def test_Open
assert_nothing_raised {@jwo = JLog::Writer.new("/tmp/junit.log")}
assert_kind_of(JLog::Writer, @jwo, "JLogWriter Object creation failed");
assert_nothing_raised { @jwo.open }
assert_nothing_raised {@jwo.close}
end
def test_Write
@jwo = JLog::Writer.new("/tmp/junit.log")
@jwo.open
assert_nothing_raised do
@jwo.write("Test Unit")
1.upto(10) do |n|
@jwo.write("Test Unit #{n}")
end
end
@jwo.close
end
def teardown
@jro = JLog::Reader.new("/tmp/junit.log")
@jro.open("TestSub")
@jro.auto_checkpoint(1)
while @msg = @jro.read do
end
@jro.close
end
end
class TC_JLogReader < Test::Unit::TestCase
def setup
@jwo = JLog::Writer.new("/tmp/junit.log")
@jwo.open
@jwo.write("Test Unit")
1.upto(10) do |n|
@jwo.write("Test Unit #{n}")
end
@jwo.close
end
def test_Open
assert_nothing_raised {@jro = JLog::Reader.new("/tmp/junit.log")}
assert_kind_of(JLog::Reader, @jro, "JLogReader Object creation failed");
assert_nothing_raised {@jro.open("TestSub")}
assert_nothing_raised {@jro.close}
end
def test_Read_Once
@jro = JLog::Reader.new("/tmp/junit.log")
@jro.open("TestSub")
@first = @jro.read
@jro.close
@jro = JLog::Reader.new("/tmp/junit.log")
@jro.open("TestSub")
assert_equal(@first, @jro.read, "LogMessage was inappropriately CheckPointed!")
@jro.close
end
def test_Rewind
@jro = JLog::Reader.new("/tmp/junit.log")
@jro.open("TestSub")
@res1 = @jro.read
assert_nothing_raised { @jro.rewind }
@res2 = @jro.read
assert_equal(@res1, @res2, "Rewound Log Messages do not match")
@jro.close
end
def test_Checkpoint
@jro = JLog::Reader.new("/tmp/junit.log")
@jro.open("TestSub")
res1 = @jro.read
assert_nothing_raised { @jro.checkpoint }
res2 = @jro.read
assert_not_equal(res1, res2, "Checkpointed Log Messages should not match")
@jro.checkpoint
@jro.close
end
def test_AutoCheckpoint
@jro = JLog::Reader.new("/tmp/junit.log")
@jro.open("TestSub")
assert_equal(1, @jro.auto_checkpoint(1), "AutoCheckpoint not successfully set");
@lastmsg = nil
while @msg = @jro.read do
assert_not_equal(@msg, @lastmsg, "Auto_Checkpointed Log Messages should not match")
@lastmsg = @msg
end
@jro.close
end
end