lwes 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/COPYING +339 -0
- data/ChangeLog +2 -0
- data/README +100 -0
- data/Rakefile +11 -0
- data/examples/demo.rb +36 -0
- data/examples/my_events.esf +17 -0
- data/ext/lwes/emitter.c +366 -0
- data/ext/lwes/extconf.rb +55 -0
- data/ext/lwes/lwes.c +27 -0
- data/ext/lwes/lwes_ruby.h +40 -0
- data/ext/lwes/numeric.c +207 -0
- data/ext/lwes/type_db.c +147 -0
- data/lib/lwes.rb +6 -0
- data/lib/lwes/emitter.rb +19 -0
- data/lib/lwes/struct.rb +116 -0
- data/lib/lwes/type_db.rb +24 -0
- data/lwes.gemspec +43 -0
- data/test/test_helper.rb +45 -0
- data/test/unit/test1.esf +33 -0
- data/test/unit/test2.esf +14 -0
- data/test/unit/test_emit_struct.rb +101 -0
- data/test/unit/test_emitter.rb +169 -0
- data/test/unit/test_struct.rb +207 -0
- data/test/unit/test_type_db.rb +61 -0
- metadata +84 -0
@@ -0,0 +1,207 @@
|
|
1
|
+
require "#{File.dirname(__FILE__)}/../test_helper"
|
2
|
+
|
3
|
+
module Dummy
|
4
|
+
end
|
5
|
+
class TestStruct < Test::Unit::TestCase
|
6
|
+
|
7
|
+
EXPECT_DB = {
|
8
|
+
:SenderPort => LWES::U_INT_16,
|
9
|
+
:st => LWES::STRING,
|
10
|
+
:enc => LWES::INT_16,
|
11
|
+
:SiteID => LWES::U_INT_16,
|
12
|
+
:ReceiptTime => LWES::INT_64,
|
13
|
+
:SenderIP => LWES::IP_ADDR,
|
14
|
+
|
15
|
+
:t_ip_addr => LWES::IP_ADDR,
|
16
|
+
:t_bool => LWES::BOOLEAN,
|
17
|
+
:t_uint64 => LWES::U_INT_64,
|
18
|
+
:t_uint32 => LWES::U_INT_32,
|
19
|
+
:t_int64 => LWES::INT_64,
|
20
|
+
:t_string => LWES::STRING,
|
21
|
+
:t_int32 => LWES::INT_32,
|
22
|
+
:t_uint16 => LWES::U_INT_16,
|
23
|
+
:t_int16 => LWES::INT_16
|
24
|
+
}
|
25
|
+
EXPECT_LIST = [
|
26
|
+
# class-specific fields first
|
27
|
+
[ :t_bool, "t_bool", LWES::BOOLEAN],
|
28
|
+
[ :t_int16, "t_int16", LWES::INT_16 ],
|
29
|
+
[ :t_int32, "t_int32", LWES::INT_32],
|
30
|
+
[ :t_int64, "t_int64", LWES::INT_64],
|
31
|
+
[ :t_ip_addr, "t_ip_addr", LWES::IP_ADDR],
|
32
|
+
[ :t_string, "t_string", LWES::STRING],
|
33
|
+
[ :t_uint16, "t_uint16", LWES::U_INT_16],
|
34
|
+
[ :t_uint32, "t_uint32", LWES::U_INT_32],
|
35
|
+
[ :t_uint64, "t_uint64", LWES::U_INT_64],
|
36
|
+
|
37
|
+
# MetaEventInfo
|
38
|
+
[ :ReceiptTime, "ReceiptTime", LWES::INT_64],
|
39
|
+
[ :SenderIP, "SenderIP", LWES::IP_ADDR],
|
40
|
+
[ :SenderPort, "SenderPort", LWES::U_INT_16],
|
41
|
+
[ :SiteID, "SiteID", LWES::U_INT_16],
|
42
|
+
[ :enc, "enc", LWES::INT_16],
|
43
|
+
[ :st, "st", LWES::STRING],
|
44
|
+
]
|
45
|
+
|
46
|
+
ESF_FILE = "#{File.dirname(__FILE__)}/test1.esf"
|
47
|
+
MULTI_EVENT_ESF = "#{File.dirname(__FILE__)}/test2.esf"
|
48
|
+
|
49
|
+
def test_constants
|
50
|
+
assert_instance_of Module, LWES, "LWES is not a module"
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_multiple_events_in_esf
|
54
|
+
a = LWES::Struct.new(:file=>MULTI_EVENT_ESF, :class => :EventBool)
|
55
|
+
assert_equal "EventBool", a.name
|
56
|
+
b = LWES::Struct.new(:file=>MULTI_EVENT_ESF,
|
57
|
+
:class => :EVENT_BOOL,
|
58
|
+
:name => :EventBool)
|
59
|
+
assert_equal "EVENT_BOOL", b.name
|
60
|
+
|
61
|
+
e = assert_raises(RuntimeError) {
|
62
|
+
LWES::Struct.new(:file=>MULTI_EVENT_ESF)
|
63
|
+
}
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_new_with_defaults
|
67
|
+
type_db = LWES::TypeDB.new(ESF_FILE)
|
68
|
+
assert type_db.instance_of?(LWES::TypeDB)
|
69
|
+
a = LWES::Struct.new(:db=>type_db, :class => :TypeDB_Event)
|
70
|
+
assert a.instance_of?(Class)
|
71
|
+
assert_equal "TypeDB_Event", a.name
|
72
|
+
assert a.const_get(:TYPE_DB).instance_of?(LWES::TypeDB)
|
73
|
+
assert a.const_get(:EVENT_DEF).instance_of?(Hash)
|
74
|
+
assert_equal EXPECT_DB, a.const_get(:EVENT_DEF)
|
75
|
+
assert_equal EXPECT_LIST, a.const_get(:TYPE_LIST)
|
76
|
+
y = a.new
|
77
|
+
assert_equal "TypeDB_Event", y.class.name
|
78
|
+
assert_kind_of(::Struct, y)
|
79
|
+
end
|
80
|
+
|
81
|
+
def test_new_with_defaults
|
82
|
+
a = LWES::Struct.new(:file=>ESF_FILE)
|
83
|
+
assert a.instance_of?(Class)
|
84
|
+
assert_equal "Event1", a.name
|
85
|
+
assert a.const_get(:TYPE_DB).instance_of?(LWES::TypeDB)
|
86
|
+
assert a.const_get(:EVENT_DEF).instance_of?(Hash)
|
87
|
+
assert_equal EXPECT_DB, a.const_get(:EVENT_DEF)
|
88
|
+
assert_equal EXPECT_LIST, a.const_get(:TYPE_LIST)
|
89
|
+
y = a.new
|
90
|
+
assert_equal "Event1", y.class.name
|
91
|
+
assert_kind_of(::Struct, y)
|
92
|
+
end
|
93
|
+
|
94
|
+
def test_new_with_alt_name
|
95
|
+
a = LWES::Struct.new(:file=>ESF_FILE,:class=>:Event,:name=>:Event1)
|
96
|
+
assert a.instance_of?(Class)
|
97
|
+
assert_equal "Event", a.name
|
98
|
+
assert a.const_get(:EVENT_DEF).instance_of?(Hash)
|
99
|
+
assert_equal EXPECT_DB, a.const_get(:EVENT_DEF)
|
100
|
+
y = a.new
|
101
|
+
assert_equal "Event", y.class.name
|
102
|
+
assert_kind_of(::Struct, y)
|
103
|
+
end
|
104
|
+
|
105
|
+
def test_new_in_module
|
106
|
+
a = LWES::Struct.new(:file=>ESF_FILE,:class=>:Event1,:parent=>LWES)
|
107
|
+
assert a.instance_of?(Class)
|
108
|
+
assert_equal "LWES::Event1", a.name
|
109
|
+
assert a.const_get(:EVENT_DEF).instance_of?(Hash)
|
110
|
+
assert_equal EXPECT_DB, a.const_get(:EVENT_DEF)
|
111
|
+
y = a.new
|
112
|
+
assert_equal "LWES::Event1", y.class.name
|
113
|
+
assert_kind_of(::Struct, y)
|
114
|
+
end
|
115
|
+
|
116
|
+
def test_eval
|
117
|
+
a = LWES::Struct.new(:file=>ESF_FILE,:class=>:Eval,:name=>:Event1) do
|
118
|
+
def aaaaaaaa
|
119
|
+
true
|
120
|
+
end
|
121
|
+
|
122
|
+
class << self
|
123
|
+
def get_event_def
|
124
|
+
const_get(:EVENT_DEF)
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
128
|
+
y = a.new
|
129
|
+
assert y.respond_to?(:aaaaaaaa)
|
130
|
+
assert_instance_of TrueClass, y.aaaaaaaa
|
131
|
+
assert_equal a.const_get(:EVENT_DEF).object_id, a.get_event_def.object_id
|
132
|
+
assert_equal EXPECT_DB, a.get_event_def
|
133
|
+
end
|
134
|
+
|
135
|
+
def test_new_initialize
|
136
|
+
a = LWES::Struct.new(:file=>ESF_FILE,
|
137
|
+
:class=>:Init,
|
138
|
+
:name=>:Event1,
|
139
|
+
:parent=>Dummy)
|
140
|
+
y = Dummy::Init.new(:t_ip_addr => "192.168.0.1", :t_bool => true)
|
141
|
+
assert_equal "192.168.0.1", y.t_ip_addr
|
142
|
+
assert_equal true, y.t_bool
|
143
|
+
end
|
144
|
+
|
145
|
+
def test_new_initialize_defaults
|
146
|
+
a = LWES::Struct.new(:file=>ESF_FILE,
|
147
|
+
:class=> :LWES_Blah,
|
148
|
+
:name=>:Event1,
|
149
|
+
:defaults => { :enc => 1 })
|
150
|
+
y = LWES_Blah.new
|
151
|
+
assert_equal 1, y.enc
|
152
|
+
end
|
153
|
+
|
154
|
+
def test_new_initialize_defaults_and_hash
|
155
|
+
a = LWES::Struct.new(:file=>ESF_FILE,
|
156
|
+
:class=> :LWES_Foo,
|
157
|
+
:name=>:Event1,
|
158
|
+
:defaults => { :enc => 1 })
|
159
|
+
y = LWES_Foo.new(:enc => 2)
|
160
|
+
assert_equal 2, y.enc
|
161
|
+
end
|
162
|
+
|
163
|
+
def test_new_initialize_struct_style
|
164
|
+
a = LWES::Struct.new(:file=>ESF_FILE,
|
165
|
+
:class=> :LWES_New,
|
166
|
+
:name=>:Event1)
|
167
|
+
y = LWES_Foo.new(true, -16, -32, -64, "127.0.0.1", "HI", 16, 32, 64)
|
168
|
+
assert_equal true, y.t_bool
|
169
|
+
assert_equal -16, y.t_int16
|
170
|
+
assert_equal -32, y.t_int32
|
171
|
+
assert_equal -64, y.t_int64
|
172
|
+
assert_equal "127.0.0.1", y.t_ip_addr
|
173
|
+
assert_equal "HI", y.t_string
|
174
|
+
assert_equal 16, y.t_uint16
|
175
|
+
assert_equal 32, y.t_uint32
|
176
|
+
assert_equal 64, y.t_uint64
|
177
|
+
end
|
178
|
+
|
179
|
+
def test_skip_attr
|
180
|
+
a = LWES::Struct.new(:file=>ESF_FILE,
|
181
|
+
:class=> :LWES_Skip,
|
182
|
+
:name=>:Event1,
|
183
|
+
:skip => %w(SenderIP SenderPort SiteID ReceiptTime))
|
184
|
+
y = LWES_Skip.new
|
185
|
+
assert ! y.respond_to?(:SenderIP)
|
186
|
+
assert ! y.respond_to?(:SenderPort)
|
187
|
+
assert ! y.respond_to?(:SiteID)
|
188
|
+
assert ! y.respond_to?(:ReceiptTime)
|
189
|
+
assert y.respond_to?(:enc)
|
190
|
+
assert y.respond_to?(:st)
|
191
|
+
end
|
192
|
+
|
193
|
+
def test_skip_regexp
|
194
|
+
a = LWES::Struct.new(:file=>ESF_FILE,
|
195
|
+
:class=> :LWES_SkipRe,
|
196
|
+
:name=>:Event1,
|
197
|
+
:skip => %r(\AS))
|
198
|
+
y = LWES_SkipRe.new
|
199
|
+
assert ! y.respond_to?(:SenderIP)
|
200
|
+
assert ! y.respond_to?(:SenderPort)
|
201
|
+
assert ! y.respond_to?(:SiteID)
|
202
|
+
assert y.respond_to?(:ReceiptTime)
|
203
|
+
assert y.respond_to?(:enc)
|
204
|
+
assert y.respond_to?(:st)
|
205
|
+
end
|
206
|
+
|
207
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require "#{File.dirname(__FILE__)}/../test_helper"
|
2
|
+
require 'tempfile'
|
3
|
+
|
4
|
+
class TestTypeDB < Test::Unit::TestCase
|
5
|
+
|
6
|
+
def test_constants
|
7
|
+
assert_instance_of Module, LWES, "LWES is not a module"
|
8
|
+
assert_instance_of Class, LWES::TypeDB, "LWES::TypeDB is not a class"
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_initialize
|
12
|
+
assert_nothing_raised do
|
13
|
+
LWES::TypeDB.new("#{File.dirname(__FILE__)}/test1.esf")
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def TODO_test_raises_on_parse_error
|
18
|
+
# tmp_err = $stderr.dup
|
19
|
+
# $stderr.reopen("/dev/null", "a")
|
20
|
+
begin
|
21
|
+
LWES::TypeDB.new(__FILE__)
|
22
|
+
rescue => e
|
23
|
+
pp [:ER, e ]
|
24
|
+
end
|
25
|
+
# ensure
|
26
|
+
# $stderr.reopen(tmp_err)
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_to_hash
|
30
|
+
expect = {
|
31
|
+
:MetaEventInfo => [
|
32
|
+
[ :SenderPort, LWES::U_INT_16],
|
33
|
+
[ :st, LWES::STRING],
|
34
|
+
[ :enc, LWES::INT_16],
|
35
|
+
[ :SiteID, LWES::U_INT_16],
|
36
|
+
[ :ReceiptTime, LWES::INT_64],
|
37
|
+
[ :SenderIP, LWES::IP_ADDR ]
|
38
|
+
],
|
39
|
+
:Event1 => [
|
40
|
+
[ :t_ip_addr, LWES::IP_ADDR],
|
41
|
+
[ :t_bool, LWES::BOOLEAN],
|
42
|
+
[ :t_uint64, LWES::U_INT_64],
|
43
|
+
[ :t_uint32, LWES::U_INT_32],
|
44
|
+
[ :t_int64, LWES::INT_64],
|
45
|
+
[ :t_string, LWES::STRING],
|
46
|
+
[ :t_int32, LWES::INT_32],
|
47
|
+
[ :t_uint16, LWES::U_INT_16],
|
48
|
+
[ :t_int16, LWES::INT_16 ]
|
49
|
+
]
|
50
|
+
}
|
51
|
+
result = LWES::TypeDB.new("#{File.dirname(__FILE__)}/test1.esf").to_hash
|
52
|
+
assert_equal expect, result
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_create_classes
|
56
|
+
tdb = LWES::TypeDB.new("#{File.dirname(__FILE__)}/test2.esf")
|
57
|
+
classes = tdb.create_classes!(:parent => TestTypeDB)
|
58
|
+
classes.each { |k| assert_kind_of Class, k }
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
metadata
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: lwes
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Erik S. Chang
|
8
|
+
- Frank Maritato
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2009-11-24 00:00:00 +00:00
|
14
|
+
default_executable:
|
15
|
+
dependencies: []
|
16
|
+
|
17
|
+
description: |-
|
18
|
+
The LWES Light-Weight Event System is a framework for allowing the exchange of
|
19
|
+
information from many machines to many machines in a controlled, platform
|
20
|
+
neutral, language neutral way. The exchange of information is done in a
|
21
|
+
connectless fashion using multicast or unicast UDP, and using self describing
|
22
|
+
data so that any platform or language can translate it to it's local dialect.
|
23
|
+
email: lwes-devel@lists.sourceforge.net
|
24
|
+
executables: []
|
25
|
+
|
26
|
+
extensions:
|
27
|
+
- ext/lwes/extconf.rb
|
28
|
+
extra_rdoc_files: []
|
29
|
+
|
30
|
+
files:
|
31
|
+
- COPYING
|
32
|
+
- ChangeLog
|
33
|
+
- README
|
34
|
+
- Rakefile
|
35
|
+
- examples/demo.rb
|
36
|
+
- examples/my_events.esf
|
37
|
+
- ext/lwes/emitter.c
|
38
|
+
- ext/lwes/extconf.rb
|
39
|
+
- ext/lwes/lwes.c
|
40
|
+
- ext/lwes/lwes_ruby.h
|
41
|
+
- ext/lwes/numeric.c
|
42
|
+
- ext/lwes/type_db.c
|
43
|
+
- lib/lwes.rb
|
44
|
+
- lib/lwes/emitter.rb
|
45
|
+
- lib/lwes/struct.rb
|
46
|
+
- lib/lwes/type_db.rb
|
47
|
+
- lwes.gemspec
|
48
|
+
- test/test_helper.rb
|
49
|
+
- test/unit/test1.esf
|
50
|
+
- test/unit/test2.esf
|
51
|
+
- test/unit/test_emit_struct.rb
|
52
|
+
- test/unit/test_emitter.rb
|
53
|
+
- test/unit/test_struct.rb
|
54
|
+
- test/unit/test_type_db.rb
|
55
|
+
has_rdoc: true
|
56
|
+
homepage: http://www.lwes.org/
|
57
|
+
licenses: []
|
58
|
+
|
59
|
+
post_install_message:
|
60
|
+
rdoc_options: []
|
61
|
+
|
62
|
+
require_paths:
|
63
|
+
- lib
|
64
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: "0"
|
69
|
+
version:
|
70
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: "0"
|
75
|
+
version:
|
76
|
+
requirements: []
|
77
|
+
|
78
|
+
rubyforge_project:
|
79
|
+
rubygems_version: 1.3.5
|
80
|
+
signing_key:
|
81
|
+
specification_version: 3
|
82
|
+
summary: Ruby API for the Light Weight Event System
|
83
|
+
test_files: []
|
84
|
+
|