retro_idl 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/ext/retro_idl/asn/ext_parser/ext_common.h +27 -0
- data/ext/retro_idl/asn/ext_parser/ext_parser.l +201 -0
- data/ext/retro_idl/asn/ext_parser/ext_parser.y +1207 -0
- data/ext/retro_idl/asn/ext_parser/extconf.rb +3 -0
- data/ext/retro_idl/asn/ext_parser/lexer.c +2873 -0
- data/ext/retro_idl/asn/ext_parser/lexer.h +366 -0
- data/ext/retro_idl/asn/ext_parser/parser.c +2963 -0
- data/ext/retro_idl/asn/ext_parser/parser.h +175 -0
- data/lib/retro_idl/asn/alternative_type.rb +43 -0
- data/lib/retro_idl/asn/asn.rb +309 -0
- data/lib/retro_idl/asn/asn_error.rb +2 -0
- data/lib/retro_idl/asn/base_type.rb +87 -0
- data/lib/retro_idl/asn/base_value.rb +75 -0
- data/lib/retro_idl/asn/bit_string.rb +44 -0
- data/lib/retro_idl/asn/boolean.rb +50 -0
- data/lib/retro_idl/asn/builtin_value.rb +51 -0
- data/lib/retro_idl/asn/choice.rb +95 -0
- data/lib/retro_idl/asn/component_type.rb +56 -0
- data/lib/retro_idl/asn/constraint.rb +162 -0
- data/lib/retro_idl/asn/defined_type.rb +61 -0
- data/lib/retro_idl/asn/defined_value.rb +82 -0
- data/lib/retro_idl/asn/enumerated.rb +127 -0
- data/lib/retro_idl/asn/enumeration_item.rb +103 -0
- data/lib/retro_idl/asn/integer.rb +84 -0
- data/lib/retro_idl/asn/location.rb +10 -0
- data/lib/retro_idl/asn/named_number.rb +83 -0
- data/lib/retro_idl/asn/null.rb +41 -0
- data/lib/retro_idl/asn/octetstring.rb +48 -0
- data/lib/retro_idl/asn/real.rb +36 -0
- data/lib/retro_idl/asn/sequence.rb +132 -0
- data/lib/retro_idl/asn/sequenceof.rb +62 -0
- data/lib/retro_idl/asn/single_value.rb +26 -0
- data/lib/retro_idl/asn/tag.rb +163 -0
- data/lib/retro_idl/asn/type_list.rb +121 -0
- data/lib/retro_idl/asn/value_assignment.rb +21 -0
- data/lib/retro_idl/asn/value_list.rb +48 -0
- data/lib/retro_idl.rb +20 -0
- data/rakefile +33 -0
- data/test/asn/ext_parser/capture_stderr.rb +20 -0
- data/test/asn/ext_parser/tc_ext_parser.rb +94 -0
- data/test/asn/parser/capture_stderr.rb +20 -0
- data/test/asn/parser/tc_parser.rb +90 -0
- metadata +133 -0
@@ -0,0 +1,62 @@
|
|
1
|
+
# Copyright (c) 2016 Cameron Harper
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy of
|
4
|
+
# this software and associated documentation files (the "Software"), to deal in
|
5
|
+
# the Software without restriction, including without limitation the rights to
|
6
|
+
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
7
|
+
# the Software, and to permit persons to whom the Software is furnished to do so,
|
8
|
+
# subject to the following conditions:
|
9
|
+
#
|
10
|
+
# The above copyright notice and this permission notice shall be included in all
|
11
|
+
# copies or substantial portions of the Software.
|
12
|
+
#
|
13
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
15
|
+
# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
16
|
+
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
17
|
+
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
18
|
+
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
19
|
+
|
20
|
+
|
21
|
+
class RetroIDL::ASN::SEQUENCEOF < BaseType
|
22
|
+
|
23
|
+
TAG_CLASS_NUMBER = 16
|
24
|
+
TAG_CLASS = :universal
|
25
|
+
|
26
|
+
def initialize(**opts)
|
27
|
+
|
28
|
+
super(**opts)
|
29
|
+
@type = RetroIDL::ASN.const_get(opts[:type][:class]).new( **opts[:type] )
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
def link(mod, stack)
|
34
|
+
|
35
|
+
if @mod.nil? or @mod != mod
|
36
|
+
|
37
|
+
@mod = nil
|
38
|
+
|
39
|
+
if @type.link(mod, stack)
|
40
|
+
|
41
|
+
super(mod, stack)
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
else
|
46
|
+
|
47
|
+
@mod
|
48
|
+
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
|
53
|
+
# @macro common_to_s
|
54
|
+
def to_s
|
55
|
+
|
56
|
+
"#{@tag} SEQUENCE #{@constraint} OF #{@type}"
|
57
|
+
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
|
62
|
+
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# Copyright (c) 2016 Cameron Harper
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy of
|
4
|
+
# this software and associated documentation files (the "Software"), to deal in
|
5
|
+
# the Software without restriction, including without limitation the rights to
|
6
|
+
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
7
|
+
# the Software, and to permit persons to whom the Software is furnished to do so,
|
8
|
+
# subject to the following conditions:
|
9
|
+
#
|
10
|
+
# The above copyright notice and this permission notice shall be included in all
|
11
|
+
# copies or substantial portions of the Software.
|
12
|
+
#
|
13
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
15
|
+
# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
16
|
+
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
17
|
+
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
18
|
+
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
19
|
+
|
20
|
+
class RetroIDL::ASN::SingleValue
|
21
|
+
|
22
|
+
def initialize(value)
|
23
|
+
@value = value
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
@@ -0,0 +1,163 @@
|
|
1
|
+
# Copyright (c) 2016 Cameron Harper
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy of
|
4
|
+
# this software and associated documentation files (the "Software"), to deal in
|
5
|
+
# the Software without restriction, including without limitation the rights to
|
6
|
+
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
7
|
+
# the Software, and to permit persons to whom the Software is furnished to do so,
|
8
|
+
# subject to the following conditions:
|
9
|
+
#
|
10
|
+
# The above copyright notice and this permission notice shall be included in all
|
11
|
+
# copies or substantial portions of the Software.
|
12
|
+
#
|
13
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
15
|
+
# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
16
|
+
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
17
|
+
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
18
|
+
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
19
|
+
|
20
|
+
# X.680 section 31.2
|
21
|
+
class RetroIDL::ASN::Tag
|
22
|
+
|
23
|
+
def initialize(**opts)
|
24
|
+
|
25
|
+
errors = false
|
26
|
+
|
27
|
+
@mod = nil
|
28
|
+
@tag = nil
|
29
|
+
@symbol = nil
|
30
|
+
@encodingReference = opts[:encodingReference]
|
31
|
+
@tagClass = opts[:class]
|
32
|
+
@location = opts[:location]
|
33
|
+
@tagType = opts[:type]
|
34
|
+
|
35
|
+
|
36
|
+
if opts[:classNumber][:ref]
|
37
|
+
|
38
|
+
if RetroIDL::ASN.is_identifier?(@location, opts[:classNumber][:ref])
|
39
|
+
|
40
|
+
@symbol = opts[:classNumber][:ref]
|
41
|
+
|
42
|
+
else
|
43
|
+
|
44
|
+
errors = true
|
45
|
+
|
46
|
+
end
|
47
|
+
|
48
|
+
else
|
49
|
+
|
50
|
+
@tagClassNumber = opts[:classNumber][:number]
|
51
|
+
|
52
|
+
if @tagClassNumber < 0
|
53
|
+
|
54
|
+
ASN.putError(opts[:classNumber][:location], "ClassNumber must be an integer >= 0")
|
55
|
+
errors = true
|
56
|
+
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
|
61
|
+
if errors
|
62
|
+
|
63
|
+
raise ASNError.new
|
64
|
+
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
68
|
+
|
69
|
+
# @return [String] EncodingReference
|
70
|
+
attr_reader :encodingReference
|
71
|
+
|
72
|
+
# @return [:IMPLICIT, :EXPLICIT] tag
|
73
|
+
attr_reader :tagClass
|
74
|
+
|
75
|
+
# Return the tag ClassNumber
|
76
|
+
#
|
77
|
+
# @return [Integer] ClassNumber
|
78
|
+
#
|
79
|
+
# @raise [ASNError] tag has not been linked
|
80
|
+
#
|
81
|
+
def tagClassNumber
|
82
|
+
|
83
|
+
if @mod
|
84
|
+
|
85
|
+
if @symbol
|
86
|
+
|
87
|
+
@symbol.value
|
88
|
+
|
89
|
+
else
|
90
|
+
|
91
|
+
@tagClassNumber
|
92
|
+
|
93
|
+
end
|
94
|
+
|
95
|
+
else
|
96
|
+
|
97
|
+
raise ASNError.new LINK_ERROR
|
98
|
+
|
99
|
+
end
|
100
|
+
|
101
|
+
end
|
102
|
+
|
103
|
+
# @macro common_link
|
104
|
+
def link(mod, stack)
|
105
|
+
|
106
|
+
if @mod.nil? or @mod != mod
|
107
|
+
|
108
|
+
@mod = nil
|
109
|
+
|
110
|
+
if @symbol
|
111
|
+
|
112
|
+
if mod.symbols(@symbol).nil?
|
113
|
+
|
114
|
+
ASN.putError(@location, SYMBOL_UNDEFINED_ERROR)
|
115
|
+
|
116
|
+
else
|
117
|
+
|
118
|
+
@mod = mod.symbols(@symbol).link(mod, stack)
|
119
|
+
|
120
|
+
end
|
121
|
+
|
122
|
+
end
|
123
|
+
|
124
|
+
else
|
125
|
+
|
126
|
+
@mod
|
127
|
+
|
128
|
+
end
|
129
|
+
|
130
|
+
end
|
131
|
+
|
132
|
+
# @macro common_to_s
|
133
|
+
def to_s
|
134
|
+
|
135
|
+
result = "["
|
136
|
+
|
137
|
+
if @encodingReference
|
138
|
+
|
139
|
+
result << " #{@encodingReference} :"
|
140
|
+
|
141
|
+
end
|
142
|
+
|
143
|
+
if @tagClass
|
144
|
+
|
145
|
+
result << " #{@tagClass}"
|
146
|
+
|
147
|
+
end
|
148
|
+
|
149
|
+
if @symbol
|
150
|
+
|
151
|
+
result << " #{@symbol}"
|
152
|
+
|
153
|
+
else
|
154
|
+
|
155
|
+
result << " #{@tagClassNumber}"
|
156
|
+
|
157
|
+
end
|
158
|
+
|
159
|
+
result << " ] #{@tagType}"
|
160
|
+
|
161
|
+
end
|
162
|
+
|
163
|
+
end
|
@@ -0,0 +1,121 @@
|
|
1
|
+
# Copyright (c) 2016 Cameron Harper
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy of
|
4
|
+
# this software and associated documentation files (the "Software"), to deal in
|
5
|
+
# the Software without restriction, including without limitation the rights to
|
6
|
+
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
7
|
+
# the Software, and to permit persons to whom the Software is furnished to do so,
|
8
|
+
# subject to the following conditions:
|
9
|
+
#
|
10
|
+
# The above copyright notice and this permission notice shall be included in all
|
11
|
+
# copies or substantial portions of the Software.
|
12
|
+
#
|
13
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
15
|
+
# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
16
|
+
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
17
|
+
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
18
|
+
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
19
|
+
|
20
|
+
class RetroIDL::ASN::TypeList
|
21
|
+
|
22
|
+
def initialize(list, type)
|
23
|
+
|
24
|
+
@mod = nil
|
25
|
+
@parent = parent
|
26
|
+
errors = false
|
27
|
+
|
28
|
+
@list = {}
|
29
|
+
|
30
|
+
list.each do |item|
|
31
|
+
|
32
|
+
if @list[item[:id]].nil?
|
33
|
+
|
34
|
+
if RetroIDL::ASN.is_identifier?(item[:location], item[:id])
|
35
|
+
|
36
|
+
begin
|
37
|
+
|
38
|
+
@list[item[:id]] = type.new(item, self)
|
39
|
+
|
40
|
+
rescue ASNError
|
41
|
+
|
42
|
+
errors = true
|
43
|
+
|
44
|
+
end
|
45
|
+
|
46
|
+
else
|
47
|
+
|
48
|
+
errors = true
|
49
|
+
|
50
|
+
end
|
51
|
+
|
52
|
+
else
|
53
|
+
|
54
|
+
ASN.putError(item[:location], "duplicate identifier")
|
55
|
+
errors = true
|
56
|
+
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
|
61
|
+
if errors
|
62
|
+
|
63
|
+
raise ASNError.new
|
64
|
+
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
68
|
+
|
69
|
+
# return [Hash] type list
|
70
|
+
attr_reader :list
|
71
|
+
|
72
|
+
# @macro common_link
|
73
|
+
def link(mod, stack)
|
74
|
+
|
75
|
+
if @mod.nil? or @mod != mod
|
76
|
+
|
77
|
+
@mod = nil
|
78
|
+
|
79
|
+
@list.values.each do |item|
|
80
|
+
|
81
|
+
if item.link(mod, stack.dup).nil?
|
82
|
+
|
83
|
+
return @mod
|
84
|
+
|
85
|
+
end
|
86
|
+
|
87
|
+
end
|
88
|
+
|
89
|
+
@mod = mod
|
90
|
+
|
91
|
+
else
|
92
|
+
|
93
|
+
@mod
|
94
|
+
|
95
|
+
end
|
96
|
+
|
97
|
+
end
|
98
|
+
|
99
|
+
# @macro common_to_s
|
100
|
+
def to_s
|
101
|
+
|
102
|
+
result = ""
|
103
|
+
|
104
|
+
@list.values.each do |item|
|
105
|
+
|
106
|
+
result << "#{item}"
|
107
|
+
|
108
|
+
if item != @list.values.last
|
109
|
+
|
110
|
+
result << ", "
|
111
|
+
|
112
|
+
end
|
113
|
+
|
114
|
+
end
|
115
|
+
|
116
|
+
result
|
117
|
+
|
118
|
+
end
|
119
|
+
|
120
|
+
end
|
121
|
+
|
@@ -0,0 +1,21 @@
|
|
1
|
+
|
2
|
+
class RetroIDL::ASN::ValueAssignment
|
3
|
+
|
4
|
+
def initialize(**opts)
|
5
|
+
|
6
|
+
@parent = parent
|
7
|
+
@location = opts[:location]
|
8
|
+
@mod = nil
|
9
|
+
@id = opts[:id]
|
10
|
+
@governor = RetroIDL::ASN.const_get(opts[:governor][:class]).new(**opts[:governor])
|
11
|
+
@value = RetroIDL::ASN.const_get(opts[:value][:class]).new(**opts[:governor])
|
12
|
+
|
13
|
+
if !RetroIDL::ASN.is_identifier?(@location, @id)
|
14
|
+
raise ASNError
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
|
@@ -0,0 +1,48 @@
|
|
1
|
+
# Copyright (c) 2016 Cameron Harper
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy of
|
4
|
+
# this software and associated documentation files (the "Software"), to deal in
|
5
|
+
# the Software without restriction, including without limitation the rights to
|
6
|
+
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
7
|
+
# the Software, and to permit persons to whom the Software is furnished to do so,
|
8
|
+
# subject to the following conditions:
|
9
|
+
#
|
10
|
+
# The above copyright notice and this permission notice shall be included in all
|
11
|
+
# copies or substantial portions of the Software.
|
12
|
+
#
|
13
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
15
|
+
# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
16
|
+
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
17
|
+
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
18
|
+
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
19
|
+
|
20
|
+
class RetroIDL::ASN::ValueList < TypeList
|
21
|
+
|
22
|
+
# @macro common_link
|
23
|
+
def link(mod, stack)
|
24
|
+
|
25
|
+
if @mod.nil? or @mod != mod
|
26
|
+
|
27
|
+
@mod = nil
|
28
|
+
ok = true
|
29
|
+
|
30
|
+
@list.values.each do |item|
|
31
|
+
if item.link(mod, []).nil?
|
32
|
+
ok = false
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
if ok
|
37
|
+
@mod = mod
|
38
|
+
else
|
39
|
+
@mod
|
40
|
+
end
|
41
|
+
|
42
|
+
else
|
43
|
+
@mod
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
data/lib/retro_idl.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# Copyright (c) 2016 Cameron Harper
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy of
|
4
|
+
# this software and associated documentation files (the "Software"), to deal in
|
5
|
+
# the Software without restriction, including without limitation the rights to
|
6
|
+
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
7
|
+
# the Software, and to permit persons to whom the Software is furnished to do so,
|
8
|
+
# subject to the following conditions:
|
9
|
+
#
|
10
|
+
# The above copyright notice and this permission notice shall be included in all
|
11
|
+
# copies or substantial portions of the Software.
|
12
|
+
#
|
13
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
15
|
+
# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
16
|
+
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
17
|
+
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
18
|
+
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
19
|
+
|
20
|
+
require 'retro_idl/asn/asn'
|
data/rakefile
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'rake/testtask'
|
2
|
+
require 'rake/extensiontask'
|
3
|
+
|
4
|
+
DIR_SRC = "ext/retro_idl/asn/ext_parser"
|
5
|
+
DIR_ETC = "etc/retro_idl/asn/ext_parser"
|
6
|
+
|
7
|
+
Rake::ExtensionTask.new do |ext|
|
8
|
+
ext.name = "ext_parser"
|
9
|
+
ext.ext_dir = "ext/retro_idl/asn/ext_parser"
|
10
|
+
ext.lib_dir = "lib/retro_idl/asn"
|
11
|
+
end
|
12
|
+
|
13
|
+
desc "ext_parser (only) tests"
|
14
|
+
Rake::TestTask.new do |t|
|
15
|
+
t.name = :test_ext_parser
|
16
|
+
t.libs << "lib"
|
17
|
+
t.test_files = FileList["test/asn/ext_parser/tc_*.rb"]
|
18
|
+
end
|
19
|
+
|
20
|
+
desc "parser tests"
|
21
|
+
Rake::TestTask.new do |t|
|
22
|
+
t.name = :test_parser
|
23
|
+
t.libs << "lib"
|
24
|
+
t.test_files = FileList["test/asn/parser/tc_*.rb"]
|
25
|
+
end
|
26
|
+
|
27
|
+
task :default => :test
|
28
|
+
|
29
|
+
desc "run flex-bison"
|
30
|
+
task :flexbison do
|
31
|
+
system "flex --outfile=#{DIR_SRC}/lexer.c --header-file=#{DIR_SRC}/lexer.h #{DIR_SRC}/ext_parser.l"
|
32
|
+
system "bison -d #{DIR_SRC}/ext_parser.y --output=#{DIR_SRC}/parser.c --report=all --report-file=#{DIR_SRC}/report.txt"
|
33
|
+
end
|
@@ -0,0 +1,94 @@
|
|
1
|
+
module RetroIDL
|
2
|
+
module ASN
|
3
|
+
end
|
4
|
+
end
|
5
|
+
|
6
|
+
require_relative "capture_stderr"
|
7
|
+
require "test/unit"
|
8
|
+
require "retro_idl/asn/location"
|
9
|
+
require "retro_idl/asn/ext_parser"
|
10
|
+
|
11
|
+
inputs = {}
|
12
|
+
root = "test/asn/input"
|
13
|
+
|
14
|
+
# generate TestParserCore at runtime with one test per input file
|
15
|
+
testClass = Class.new(Test::Unit::TestCase) do
|
16
|
+
|
17
|
+
include RetroIDL::ASN
|
18
|
+
|
19
|
+
class << self
|
20
|
+
|
21
|
+
attr_accessor :inputs
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
Dir.foreach(root) do |filename|
|
26
|
+
|
27
|
+
next if filename == ".." or filename == "."
|
28
|
+
|
29
|
+
test_name = "test_#{filename.sub(".asn1", "")}"
|
30
|
+
inputs[test_name.to_sym] = {:fileName => filename, :buffer => File.new("#{root}/#{filename}", "r").read}
|
31
|
+
|
32
|
+
# positive tests
|
33
|
+
if filename[/^pos_.*\.asn1$/]
|
34
|
+
|
35
|
+
define_method( test_name ) do
|
36
|
+
|
37
|
+
# run stage 1 and intercept stderr output
|
38
|
+
err = capture_stderr do
|
39
|
+
|
40
|
+
output = parseFileBuffer(inputs[__method__])
|
41
|
+
|
42
|
+
end
|
43
|
+
|
44
|
+
# there should have been no messages to stderr
|
45
|
+
assert_equal("", err.string, "unexpected error messages")
|
46
|
+
|
47
|
+
# if there were messages, forward them to stderr
|
48
|
+
if err.string != ""
|
49
|
+
|
50
|
+
STDERR.puts err.string
|
51
|
+
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
|
58
|
+
# negative tests
|
59
|
+
if filename[/^neg_.*\.asn1$/]
|
60
|
+
|
61
|
+
define_method( test_name ) do
|
62
|
+
|
63
|
+
# run stage 1 and intercept stderr output
|
64
|
+
err = capture_stderr do
|
65
|
+
|
66
|
+
output = parseFileBuffer(inputs[__method__])
|
67
|
+
|
68
|
+
end
|
69
|
+
|
70
|
+
# there should have been some messages to stderr
|
71
|
+
assert_not_equal("", err.string, "expecting error messages but got none")
|
72
|
+
|
73
|
+
# if there were messages, forward them to stderr
|
74
|
+
if err.string != ""
|
75
|
+
|
76
|
+
STDERR.puts err.string
|
77
|
+
|
78
|
+
end
|
79
|
+
|
80
|
+
end
|
81
|
+
|
82
|
+
end
|
83
|
+
|
84
|
+
|
85
|
+
end
|
86
|
+
|
87
|
+
end
|
88
|
+
|
89
|
+
# set inputs as a class variable
|
90
|
+
testClass.inputs = inputs
|
91
|
+
|
92
|
+
# name the dynamic test class
|
93
|
+
Object.const_set("TestParserCore", testClass)
|
94
|
+
|