rbgccxml 0.9.1 → 1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +8 -10
- data/lib/rbgccxml/node.rb +65 -64
- data/lib/rbgccxml/node_cache.rb +93 -0
- data/lib/rbgccxml/nodes/argument.rb +4 -1
- data/lib/rbgccxml/nodes/base.rb +1 -1
- data/lib/rbgccxml/nodes/class.rb +22 -15
- data/lib/rbgccxml/nodes/enum_value.rb +2 -4
- data/lib/rbgccxml/nodes/enumeration.rb +1 -1
- data/lib/rbgccxml/nodes/field.rb +3 -1
- data/lib/rbgccxml/nodes/function.rb +2 -2
- data/lib/rbgccxml/nodes/method.rb +3 -3
- data/lib/rbgccxml/nodes/namespace.rb +14 -0
- data/lib/rbgccxml/nodes/type.rb +4 -3
- data/lib/rbgccxml/nodes/types/array_type.rb +3 -2
- data/lib/rbgccxml/nodes/types/cv_qualified_type.rb +12 -6
- data/lib/rbgccxml/nodes/types/pointer_type.rb +2 -1
- data/lib/rbgccxml/nodes/types/reference_type.rb +2 -1
- data/lib/rbgccxml/parser.rb +7 -5
- data/lib/rbgccxml/query_result.rb +8 -2
- data/lib/rbgccxml/sax_parser.rb +69 -0
- data/lib/rbgccxml.rb +3 -1
- data/lib/vendor/facets/once.rb +59 -0
- data/test/arguments_test.rb +14 -14
- data/test/classes_test.rb +85 -80
- data/test/enumerations_test.rb +29 -31
- data/test/function_pointers_test.rb +7 -7
- data/test/functions_test.rb +20 -20
- data/test/methods_test.rb +26 -25
- data/test/namespaces_test.rb +6 -6
- data/test/node_test.rb +7 -7
- data/test/parser_test.rb +23 -23
- data/test/query_results_test.rb +81 -81
- data/test/structs_test.rb +19 -20
- data/test/test_helper.rb +5 -18
- data/test/types_test.rb +60 -58
- data/test/variables_test.rb +12 -12
- metadata +58 -63
- data/lib/rbgccxml/xml_parsing.rb +0 -152
data/lib/rbgccxml/parser.rb
CHANGED
@@ -58,11 +58,13 @@ module RbGCCXML
|
|
58
58
|
xml_file = @xml_file
|
59
59
|
end
|
60
60
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
61
|
+
NodeCache.clear
|
62
|
+
|
63
|
+
parser = SAXParser.new(xml_file)
|
64
|
+
|
65
|
+
# Runs the SAX parser and returns the root level node
|
66
|
+
# which will be the Namespace node for "::"
|
67
|
+
parser.parse
|
66
68
|
end
|
67
69
|
|
68
70
|
private
|
@@ -72,7 +72,7 @@ module RbGCCXML
|
|
72
72
|
|
73
73
|
if options[0] == :all
|
74
74
|
node_type = self[0].class.to_s.split(/::/)[-1]
|
75
|
-
query_set =
|
75
|
+
query_set = NodeCache.all(node_type)
|
76
76
|
options = options[1]
|
77
77
|
else
|
78
78
|
options = options[0]
|
@@ -149,7 +149,13 @@ module RbGCCXML
|
|
149
149
|
# one Node is being returned by the Enumerable#find_all, returns that
|
150
150
|
# single node.
|
151
151
|
def find_all(&block)
|
152
|
-
res = super
|
152
|
+
res = QueryResult.new(super)
|
153
|
+
res.length == 1 ? res[0] : res
|
154
|
+
end
|
155
|
+
|
156
|
+
# Same with #find_all, force to work as a QueryResult
|
157
|
+
def select(&block)
|
158
|
+
res = QueryResult.new(super)
|
153
159
|
res.length == 1 ? res[0] : res
|
154
160
|
end
|
155
161
|
|
@@ -0,0 +1,69 @@
|
|
1
|
+
module RbGCCXML
|
2
|
+
|
3
|
+
# Use SAX to parse the generated xml file.
|
4
|
+
# This will end up building the full tree of RbGCCXML::Nodes
|
5
|
+
# that fit the parsed C++ code.
|
6
|
+
class SAXParser
|
7
|
+
def initialize(xml_file)
|
8
|
+
@file = xml_file
|
9
|
+
@parser = Nokogiri::XML::SAX::Parser.new(ParserEventHandler.new)
|
10
|
+
end
|
11
|
+
|
12
|
+
# Kick off the process. When the parsing finishes, we take
|
13
|
+
# the root node of the tree and return it
|
14
|
+
def parse
|
15
|
+
@parser.parse(::File.open(@file))
|
16
|
+
NodeCache.root
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
# Our SAX Events handler class
|
21
|
+
class ParserEventHandler < Nokogiri::XML::SAX::Document
|
22
|
+
|
23
|
+
# Ignore types we don't handle yet
|
24
|
+
IGNORE_NODES = %w(
|
25
|
+
GCC_XML
|
26
|
+
Ellipsis
|
27
|
+
OperatorMethod
|
28
|
+
OperatorFunction
|
29
|
+
Unimplemented
|
30
|
+
Converter
|
31
|
+
OffsetType
|
32
|
+
)
|
33
|
+
|
34
|
+
# Some nodes are actually stored in XML as nested structures
|
35
|
+
NESTED_NODES = %w(Argument Base EnumValue)
|
36
|
+
|
37
|
+
def start_element(name, attributes = [])
|
38
|
+
attr_hash = Hash[*attributes]
|
39
|
+
|
40
|
+
# Need to build a node in memory for those
|
41
|
+
# that we don't directly support
|
42
|
+
if IGNORE_NODES.include?(name)
|
43
|
+
name = "Node"
|
44
|
+
end
|
45
|
+
|
46
|
+
node = RbGCCXML.const_get(name).new(attr_hash)
|
47
|
+
|
48
|
+
if NESTED_NODES.include?(name)
|
49
|
+
# Don't save node to cache. These nodes don't have
|
50
|
+
# ids on which we can index off of
|
51
|
+
@context_node.children << node
|
52
|
+
node.parent = @context_node
|
53
|
+
else
|
54
|
+
# Save node to node cache
|
55
|
+
NodeCache << node
|
56
|
+
|
57
|
+
# Save node for any XML children it might have later
|
58
|
+
@context_node = node
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
# Once the document is done parsing we process our node tree
|
63
|
+
def end_document
|
64
|
+
NodeCache.process_tree
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
data/lib/rbgccxml.rb
CHANGED
@@ -1,13 +1,15 @@
|
|
1
1
|
require 'gccxml'
|
2
2
|
|
3
3
|
require 'rbgccxml/rbgccxml'
|
4
|
+
require 'vendor/facets/once'
|
4
5
|
|
5
6
|
module RbGCCXML
|
6
7
|
|
7
8
|
# Core classes
|
8
9
|
autoload :Node, "rbgccxml/node"
|
9
10
|
autoload :Parser, "rbgccxml/parser"
|
10
|
-
autoload :
|
11
|
+
autoload :SAXParser, "rbgccxml/sax_parser"
|
12
|
+
autoload :NodeCache, "rbgccxml/node_cache"
|
11
13
|
autoload :QueryResult, "rbgccxml/query_result"
|
12
14
|
|
13
15
|
# Nodes
|
@@ -0,0 +1,59 @@
|
|
1
|
+
module Kernel #:nodoc:
|
2
|
+
|
3
|
+
# Directive for making your functions faster by trading
|
4
|
+
# space for time. When you "memoize" a method/function
|
5
|
+
# using #once its results are cached so that later calls
|
6
|
+
# with the same arguments return results from the cache
|
7
|
+
# instead of recalculating them.
|
8
|
+
#
|
9
|
+
# class T
|
10
|
+
# def initialize(a)
|
11
|
+
# @a = a
|
12
|
+
# end
|
13
|
+
# def a
|
14
|
+
# "#{@a ^ 3 + 4}"
|
15
|
+
# end
|
16
|
+
# once :a
|
17
|
+
# end
|
18
|
+
#
|
19
|
+
# t = T.new
|
20
|
+
# t.a.__id__ == t.a.__id__ #=> true
|
21
|
+
#
|
22
|
+
# This method can also be used at the instance level
|
23
|
+
# to cache singleton/eigen methods.
|
24
|
+
#
|
25
|
+
# Note, this method used to be called +cache+ along with
|
26
|
+
# it's other alias #memoize, but +once+ is the term used
|
27
|
+
# in PickAxe so it has been adopted instead. The #memoize
|
28
|
+
# alias has also been retained.
|
29
|
+
#
|
30
|
+
# CREDIT Robert Feldt
|
31
|
+
#
|
32
|
+
def once(*ids)
|
33
|
+
if ids.empty?
|
34
|
+
@_once ||= Hash::new{|h,k| h[k]={}}
|
35
|
+
else
|
36
|
+
base = (Module === self ? self : (class << self; self; end))
|
37
|
+
ids.each do |m|
|
38
|
+
base.module_eval <<-code
|
39
|
+
alias_method '#{ m }:once', '#{ m }'
|
40
|
+
private '#{ m }:once'
|
41
|
+
def #{ m }(*__a__,&__b__)
|
42
|
+
c = once['#{ m }']
|
43
|
+
k = [__a__,__b__]
|
44
|
+
if c.has_key? k
|
45
|
+
c[k]
|
46
|
+
else
|
47
|
+
c[k] = __send__('#{ m }:once',*__a__,&__b__)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
code
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
# +once+ is also widely known as +memoize+.
|
56
|
+
alias_method :memoize, :once
|
57
|
+
|
58
|
+
end
|
59
|
+
|
data/test/arguments_test.rb
CHANGED
@@ -1,29 +1,29 @@
|
|
1
1
|
require "test_helper"
|
2
2
|
|
3
|
-
|
3
|
+
describe "Function and Method Arguments" do
|
4
4
|
|
5
|
-
|
6
|
-
|
5
|
+
before(:all) do
|
6
|
+
@arguments_source = RbGCCXML.parse(full_dir("headers/functions.h")).namespaces("functions")
|
7
7
|
end
|
8
8
|
|
9
9
|
specify "have type and to_cpp" do
|
10
|
-
test1 =
|
11
|
-
test1.arguments.length.should
|
10
|
+
test1 = @arguments_source.functions("test1")
|
11
|
+
test1.arguments.length.should == 2
|
12
12
|
|
13
|
-
test1.arguments[0].to_cpp.should
|
14
|
-
test1.arguments[0].cpp_type.to_cpp.should
|
13
|
+
test1.arguments[0].to_cpp.should == "int x"
|
14
|
+
test1.arguments[0].cpp_type.to_cpp.should == "int"
|
15
15
|
|
16
|
-
test1.arguments[1].to_cpp.should
|
17
|
-
test1.arguments[1].cpp_type.to_cpp.should
|
16
|
+
test1.arguments[1].to_cpp.should == "double y"
|
17
|
+
test1.arguments[1].cpp_type.to_cpp.should == "double"
|
18
18
|
end
|
19
19
|
|
20
20
|
specify "can have a default value" do
|
21
|
-
test1 =
|
22
|
-
test1.arguments[0].value.should
|
23
|
-
test1.arguments[1].value.should
|
21
|
+
test1 = @arguments_source.functions("test1")
|
22
|
+
test1.arguments[0].value.should be_nil
|
23
|
+
test1.arguments[1].value.should == "3.0e+0"
|
24
24
|
|
25
|
-
rockin =
|
26
|
-
rockin.arguments[1].value.should
|
25
|
+
rockin = @arguments_source.functions("rockin")
|
26
|
+
rockin.arguments[1].value.should == "functions::test()"
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
data/test/classes_test.rb
CHANGED
@@ -1,197 +1,202 @@
|
|
1
1
|
require "test_helper"
|
2
2
|
|
3
|
-
|
4
|
-
|
3
|
+
describe "Querying for classes" do
|
4
|
+
before do
|
5
5
|
@source ||= RbGCCXML.parse(full_dir("headers/classes.h")).namespaces("classes")
|
6
6
|
end
|
7
7
|
|
8
8
|
specify "can find all classes in a given namespace" do
|
9
9
|
classes = @source.classes
|
10
|
-
classes.size.should
|
10
|
+
classes.size.should == 4
|
11
11
|
|
12
|
-
classes.find(:name => "Test1").
|
13
|
-
classes.find(:name => "Test2").
|
14
|
-
classes.find(:name => "Test3").
|
12
|
+
classes.find(:name => "Test1").should_not be_nil
|
13
|
+
classes.find(:name => "Test2").should_not be_nil
|
14
|
+
classes.find(:name => "Test3").should_not be_nil
|
15
15
|
end
|
16
16
|
|
17
17
|
specify "can find classes within classes" do
|
18
18
|
test1 = @source.classes.find(:name => "Test1")
|
19
|
-
test1.
|
20
|
-
test1.should
|
21
|
-
test1.name.should
|
19
|
+
test1.should_not be_nil
|
20
|
+
test1.should be_kind_of(RbGCCXML::Class)
|
21
|
+
test1.name.should == "Test1"
|
22
22
|
|
23
23
|
inner1 = test1.classes("Inner1")
|
24
|
-
inner1.
|
25
|
-
inner1.should
|
26
|
-
inner1.name.should
|
24
|
+
inner1.should_not be_nil
|
25
|
+
inner1.should be_kind_of(RbGCCXML::Class)
|
26
|
+
inner1.name.should == "Inner1"
|
27
27
|
|
28
28
|
inner2 = inner1.classes("Inner1")
|
29
|
-
inner2.
|
30
|
-
inner2.should
|
31
|
-
inner2.should
|
29
|
+
inner2.should_not be_nil
|
30
|
+
inner2.should be_kind_of(Array)
|
31
|
+
inner2.should be_empty
|
32
32
|
|
33
33
|
inner2 = inner1.classes("Inner2")
|
34
|
-
inner2.
|
35
|
-
inner2.should
|
36
|
-
inner2.name.should
|
34
|
+
inner2.should_not be_nil
|
35
|
+
inner2.should be_kind_of(RbGCCXML::Class)
|
36
|
+
inner2.name.should == "Inner2"
|
37
37
|
end
|
38
38
|
|
39
39
|
specify "can find classes within classes by regex" do
|
40
40
|
test1 = @source.classes(/t1/)
|
41
|
-
test1.
|
42
|
-
test1.should
|
43
|
-
test1.name.should
|
41
|
+
test1.should_not be_nil
|
42
|
+
test1.should be_kind_of(RbGCCXML::Class)
|
43
|
+
test1.name.should == "Test1"
|
44
44
|
|
45
45
|
inner1 = test1.classes(/In.*1/)
|
46
|
-
inner1.
|
47
|
-
inner1.should
|
48
|
-
inner1.name.should
|
46
|
+
inner1.should_not be_nil
|
47
|
+
inner1.should be_kind_of(RbGCCXML::Class)
|
48
|
+
inner1.name.should == "Inner1"
|
49
49
|
|
50
50
|
inner2 = inner1.classes(/1/)
|
51
|
-
inner2.
|
52
|
-
inner2.should
|
53
|
-
inner2.should
|
51
|
+
inner2.should_not be_nil
|
52
|
+
inner2.should be_kind_of(Array)
|
53
|
+
inner2.should be_empty
|
54
54
|
|
55
55
|
inner2 = inner1.classes(/2/)
|
56
|
-
inner2.
|
57
|
-
inner2.should
|
58
|
-
inner2.name.should
|
56
|
+
inner2.should_not be_nil
|
57
|
+
inner2.should be_kind_of(RbGCCXML::Class)
|
58
|
+
inner2.name.should == "Inner2"
|
59
59
|
end
|
60
60
|
|
61
61
|
specify "can find classes within classes by block" do
|
62
62
|
# We're looking for any class that has virtual methods.
|
63
|
-
test4 = @source.classes { |c| c.methods.any? { |m| m.virtual? } }
|
64
|
-
test4.
|
65
|
-
test4.should
|
66
|
-
test4.name.should
|
63
|
+
test4 = @source.classes.select { |c| c.methods.any? { |m| m.virtual? } }
|
64
|
+
test4.should_not be_nil
|
65
|
+
test4.should be_kind_of(RbGCCXML::Class)
|
66
|
+
test4.name.should == "Test4"
|
67
67
|
|
68
68
|
# Fail case -- there's no methods that return double.
|
69
|
-
test0 = @source.classes { |c| c.methods.any? { |m| m.return_type == "double" }}
|
70
|
-
test0.
|
71
|
-
test0.should
|
72
|
-
test0.should
|
69
|
+
test0 = @source.classes.select { |c| c.methods.any? { |m| m.return_type == "double" }}
|
70
|
+
test0.should_not be_nil
|
71
|
+
test0.should be_kind_of(Array)
|
72
|
+
test0.should be_empty
|
73
73
|
end
|
74
74
|
|
75
75
|
specify "can tell if a class is pure virtual" do
|
76
76
|
test1 = @source.classes("Test1")
|
77
77
|
test4 = @source.classes("Test4")
|
78
78
|
|
79
|
-
test1.pure_virtual?.should
|
80
|
-
test4.pure_virtual?.should
|
79
|
+
test1.pure_virtual?.should be_false
|
80
|
+
test4.pure_virtual?.should be_true
|
81
81
|
end
|
82
82
|
end
|
83
83
|
|
84
|
-
|
85
|
-
|
84
|
+
describe "Querying for class constructors" do
|
85
|
+
before do
|
86
86
|
@source ||= RbGCCXML.parse(full_dir("headers/classes.h")).namespaces("classes")
|
87
87
|
end
|
88
88
|
|
89
89
|
specify "should have a list of constructors" do
|
90
90
|
test1 = @source.classes.find(:name => "Test1")
|
91
|
-
test1.constructors.size.should
|
91
|
+
test1.constructors.size.should == 2
|
92
92
|
|
93
93
|
test2 = @source.classes.find(:name => "Test2")
|
94
|
-
test2.constructors.size.should
|
94
|
+
test2.constructors.size.should == 3
|
95
95
|
end
|
96
96
|
|
97
97
|
specify "constructors should have arguments" do
|
98
98
|
test2 = @source.classes.find(:name => "Test2")
|
99
|
-
test2.constructors.size.should
|
99
|
+
test2.constructors.size.should == 3
|
100
100
|
|
101
101
|
# GCC generated copy constructors
|
102
102
|
copy = test2.constructors[0]
|
103
|
-
copy.
|
103
|
+
copy.artificial?.should be_true
|
104
104
|
|
105
105
|
default = test2.constructors[1]
|
106
|
-
default.arguments.size.should
|
106
|
+
default.arguments.size.should == 0
|
107
107
|
|
108
108
|
specific = test2.constructors[2]
|
109
|
-
specific.arguments.size.should
|
110
|
-
specific.arguments[0].cpp_type.name.should
|
109
|
+
specific.arguments.size.should == 1
|
110
|
+
specific.arguments[0].cpp_type.name.should == "int"
|
111
111
|
end
|
112
112
|
end
|
113
113
|
|
114
|
-
|
115
|
-
|
114
|
+
describe "Querying for the class's deconstructor" do
|
115
|
+
before do
|
116
116
|
@source ||= RbGCCXML.parse(full_dir("headers/classes.h")).namespaces("classes")
|
117
117
|
end
|
118
118
|
|
119
119
|
specify "can tell if a class has an explicit destructor" do
|
120
120
|
test1 = @source.classes("Test1")
|
121
|
-
test1.destructor.
|
122
|
-
test1.destructor.
|
121
|
+
test1.destructor.should_not be_nil
|
122
|
+
test1.destructor.artificial?.should be_false
|
123
123
|
|
124
124
|
test2 = @source.classes("Test2")
|
125
|
-
test2.destructor.
|
126
|
-
test2.destructor.
|
125
|
+
test2.destructor.should_not be_nil
|
126
|
+
test2.destructor.artificial?.should be_true
|
127
127
|
end
|
128
128
|
|
129
129
|
end
|
130
130
|
|
131
|
-
|
132
|
-
|
131
|
+
describe "Query for class variables" do
|
132
|
+
before do
|
133
133
|
@source ||= RbGCCXML.parse(full_dir("headers/classes.h")).namespaces("classes")
|
134
134
|
end
|
135
135
|
|
136
136
|
specify "find all i-vars" do
|
137
137
|
test1 = @source.classes("Test1")
|
138
|
-
test1.variables.length.should
|
138
|
+
test1.variables.length.should == 4
|
139
139
|
end
|
140
140
|
|
141
141
|
specify "can find by access level" do
|
142
142
|
test1 = @source.classes("Test1")
|
143
|
-
test1.variables.find(:access => "public").length.should
|
144
|
-
test1.variables.find(:access => "protected").name.should
|
145
|
-
test1.variables.find(:access => "private").name.should
|
143
|
+
test1.variables.find(:access => "public").length.should == 2
|
144
|
+
test1.variables.find(:access => "protected").name.should == "protVariable"
|
145
|
+
test1.variables.find(:access => "private").name.should == "privateVariable"
|
146
146
|
end
|
147
147
|
end
|
148
148
|
|
149
|
-
|
150
|
-
|
149
|
+
describe "Query inheritance heirarchy" do
|
150
|
+
before do
|
151
151
|
@source ||= RbGCCXML.parse(full_dir("headers/inheritance.h")).namespaces("inheritance")
|
152
152
|
end
|
153
153
|
|
154
154
|
specify "can find a class's superclass" do
|
155
155
|
pc = @source.classes("ParentClass")
|
156
|
-
pc.superclass.should
|
156
|
+
pc.superclass.should be_nil
|
157
157
|
|
158
158
|
base1 = @source.classes("Base1")
|
159
|
-
base1.superclass.
|
160
|
-
base1.superclass.name.should
|
159
|
+
base1.superclass.should_not be_nil
|
160
|
+
base1.superclass.name.should == "ParentClass"
|
161
161
|
end
|
162
162
|
|
163
163
|
specify "can query for multiple inheritance" do
|
164
164
|
multi = @source.classes("MultiBase")
|
165
|
-
multi.superclasses.length.should
|
166
|
-
|
167
|
-
|
165
|
+
multi.superclasses.length.should == 2
|
166
|
+
multi.superclasses.select {|sp| sp.name == "ParentClass"}.should_not be_nil
|
167
|
+
multi.superclasses.select {|sp| sp.name == "Parent2"}.should_not be_nil
|
168
168
|
end
|
169
169
|
|
170
170
|
specify "calling #superclasses always returns an array" do
|
171
171
|
pc = @source.classes("ParentClass")
|
172
|
-
pc.superclasses.should
|
172
|
+
pc.superclasses.should be_empty
|
173
173
|
|
174
174
|
base1 = @source.classes("Base1")
|
175
|
-
base1.superclasses.length.should
|
176
|
-
base1.superclasses[0].name.should
|
175
|
+
base1.superclasses.length.should == 1
|
176
|
+
base1.superclasses[0].name.should == "ParentClass"
|
177
177
|
end
|
178
178
|
|
179
179
|
specify "can infinitely climb the inheritance heirarchy" do
|
180
180
|
low = @source.classes("VeryLow")
|
181
|
-
low.superclass.superclass.superclass.name.should
|
181
|
+
low.superclass.superclass.superclass.name.should == "ParentClass"
|
182
182
|
end
|
183
183
|
|
184
184
|
specify "can query for types of inheritance" do
|
185
185
|
pvb1 = @source.classes("PrivateBase1")
|
186
|
-
pvb1.superclass(:public).should
|
187
|
-
pvb1.superclass(:protected).should
|
188
|
-
pvb1.superclass(:private).
|
186
|
+
pvb1.superclass(:public).should be_nil
|
187
|
+
pvb1.superclass(:protected).should be_nil
|
188
|
+
pvb1.superclass(:private).should_not be_nil
|
189
189
|
|
190
|
-
pvb1.superclass(:private).name.should
|
190
|
+
pvb1.superclass(:private).name.should == "ParentClass"
|
191
191
|
|
192
|
-
pvb1.superclasses(:public).length.should
|
193
|
-
pvb1.superclasses(:protected).length.should
|
194
|
-
pvb1.superclasses(:private).length.should
|
192
|
+
pvb1.superclasses(:public).length.should == 0
|
193
|
+
pvb1.superclasses(:protected).length.should == 0
|
194
|
+
pvb1.superclasses(:private).length.should == 1
|
195
|
+
|
196
|
+
vlow = @source.classes("VeryLow")
|
197
|
+
vlow.superclasses(:public).length.should == 1
|
198
|
+
vlow.superclasses(:private).length.should == 0
|
199
|
+
vlow.superclasses(:protected).length.should == 1
|
195
200
|
end
|
196
201
|
|
197
202
|
end
|
data/test/enumerations_test.rb
CHANGED
@@ -1,51 +1,49 @@
|
|
1
1
|
require "test_helper"
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
3
|
+
describe "Querying for enumerations" do
|
4
|
+
before(:all) do
|
5
|
+
@enum_source = RbGCCXML.parse(full_dir("headers/enums.h")).namespaces("enums")
|
6
6
|
end
|
7
7
|
|
8
8
|
specify "can query for enumerations" do
|
9
|
-
enums =
|
10
|
-
enums.length.should
|
9
|
+
enums = @enum_source.enumerations
|
10
|
+
enums.length.should == 3
|
11
11
|
end
|
12
12
|
|
13
13
|
specify "can find specific enum values" do
|
14
|
-
enum =
|
15
|
-
enum.values.length.should
|
16
|
-
enum.values[0].name.should
|
17
|
-
enum.values[1].name.should
|
18
|
-
enum.values[2].name.should
|
14
|
+
enum = @enum_source.enumerations("TestEnum")
|
15
|
+
enum.values.length.should == 3
|
16
|
+
enum.values[0].name.should == "VALUE1"
|
17
|
+
enum.values[1].name.should == "VALUE2"
|
18
|
+
enum.values[2].name.should == "VALUE3"
|
19
19
|
end
|
20
20
|
|
21
21
|
specify "can find the given value of enum entries" do
|
22
|
-
enum =
|
23
|
-
enum.values[0].value.should
|
24
|
-
enum.values[1].value.should
|
25
|
-
enum.values[2].value.should
|
22
|
+
enum = @enum_source.enumerations.find(:name => "MyEnum")
|
23
|
+
enum.values[0].value.should == 3
|
24
|
+
enum.values[1].value.should == 4
|
25
|
+
enum.values[2].value.should == 7
|
26
26
|
end
|
27
27
|
|
28
28
|
specify "properly prints out fully qualified C++ identifier for enum values" do
|
29
|
-
enum =
|
30
|
-
enum.values.length.should
|
31
|
-
enum.values[0].qualified_name.should
|
32
|
-
enum.values[1].qualified_name.should
|
33
|
-
enum.values[2].qualified_name.should
|
34
|
-
|
35
|
-
enum =
|
36
|
-
enum.values[0].qualified_name.should
|
37
|
-
enum.values[1].qualified_name.should
|
29
|
+
enum = @enum_source.enumerations("TestEnum")
|
30
|
+
enum.values.length.should == 3
|
31
|
+
enum.values[0].qualified_name.should == "enums::VALUE1"
|
32
|
+
enum.values[1].qualified_name.should == "enums::VALUE2"
|
33
|
+
enum.values[2].qualified_name.should == "enums::VALUE3"
|
34
|
+
|
35
|
+
enum = @enum_source.classes("Inner").enumerations("InnerEnum")
|
36
|
+
enum.values[0].qualified_name.should == "enums::Inner::INNER_1"
|
37
|
+
enum.values[1].qualified_name.should == "enums::Inner::INNER_2"
|
38
38
|
end
|
39
39
|
|
40
40
|
specify "knows if an enumeration is anonymous" do
|
41
|
-
found =
|
42
|
-
|
43
|
-
found
|
44
|
-
|
45
|
-
|
46
|
-
found.values[
|
47
|
-
found.values[1].value.should.equal 1
|
48
|
-
found.values[2].value.should.equal 2
|
41
|
+
found = @enum_source.enumerations.select {|e| e.anonymous? }
|
42
|
+
|
43
|
+
found.should be_a(RbGCCXML::Enumeration)
|
44
|
+
found.values[0].value.should == 0
|
45
|
+
found.values[1].value.should == 1
|
46
|
+
found.values[2].value.should == 2
|
49
47
|
end
|
50
48
|
|
51
49
|
end
|
@@ -1,18 +1,18 @@
|
|
1
1
|
require "test_helper"
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
3
|
+
describe "Function pointers" do
|
4
|
+
before(:all) do
|
5
|
+
@fp_source = RbGCCXML.parse(full_dir("headers/types.h")).namespaces("types")
|
6
6
|
end
|
7
7
|
|
8
8
|
specify "have arguments" do
|
9
|
-
fp =
|
9
|
+
fp = @fp_source.functions("takesCallback").arguments[0].cpp_type.base_type
|
10
10
|
fp.arguments.length.should == 1
|
11
|
-
fp.arguments[0].cpp_type.name.should
|
11
|
+
fp.arguments[0].cpp_type.name.should == "int"
|
12
12
|
end
|
13
13
|
|
14
14
|
specify "have return value" do
|
15
|
-
fp =
|
16
|
-
fp.return_type.name.should
|
15
|
+
fp = @fp_source.functions("takesCallbackWithReturn").arguments[0].cpp_type.base_type
|
16
|
+
fp.return_type.name.should == "int"
|
17
17
|
end
|
18
18
|
end
|