cauterize 0.0.1.pre13 → 0.0.1.pre14
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +33 -33
- data/.rspec +1 -1
- data/.travisci.yml +4 -4
- data/Gemfile +4 -4
- data/LICENSE.txt +21 -21
- data/README.md +177 -177
- data/Rakefile +54 -54
- data/bin/cauterize +61 -61
- data/cauterize.gemspec +27 -27
- data/example/Cauterize +68 -68
- data/example/build.sh +25 -25
- data/example/c_example_support/empty_main.c +1 -1
- data/example/c_example_support/example_project_config.c +11 -11
- data/example/c_example_support/example_project_config.h +15 -15
- data/example/ruby_ex.rb +14 -14
- data/lib/cauterize.rb +117 -117
- data/lib/cauterize/base_type.rb +78 -78
- data/lib/cauterize/builders.rb +41 -41
- data/lib/cauterize/builders/c/buildable.rb +91 -91
- data/lib/cauterize/builders/c/builtin.rb +43 -43
- data/lib/cauterize/builders/c/composite.rb +57 -57
- data/lib/cauterize/builders/c/enumeration.rb +60 -60
- data/lib/cauterize/builders/c/fixed_array.rb +74 -74
- data/lib/cauterize/builders/c/group.rb +143 -143
- data/lib/cauterize/builders/c/scalar.rb +34 -34
- data/lib/cauterize/builders/c/variable_array.rb +98 -98
- data/lib/cauterize/builders/cs/buildable.rb +59 -59
- data/lib/cauterize/builders/cs/builtin.rb +22 -22
- data/lib/cauterize/builders/cs/composite.rb +21 -21
- data/lib/cauterize/builders/cs/csarray.rb +32 -32
- data/lib/cauterize/builders/cs/enumeration.rb +21 -21
- data/lib/cauterize/builders/cs/fixed_array.rb +27 -27
- data/lib/cauterize/builders/cs/group.rb +32 -32
- data/lib/cauterize/builders/cs/scalar.rb +10 -10
- data/lib/cauterize/builders/cs/variable_array.rb +40 -34
- data/lib/cauterize/builders/doc/buildable.rb +30 -30
- data/lib/cauterize/builders/doc/builtin.rb +21 -21
- data/lib/cauterize/builders/doc/composite.rb +23 -23
- data/lib/cauterize/builders/doc/enumeration.rb +24 -24
- data/lib/cauterize/builders/doc/fixed_array.rb +26 -26
- data/lib/cauterize/builders/doc/group.rb +29 -29
- data/lib/cauterize/builders/doc/scalar.rb +21 -21
- data/lib/cauterize/builders/doc/variable_array.rb +26 -26
- data/lib/cauterize/builders/ruby/buildable.rb +11 -11
- data/lib/cauterize/builders/ruby/builtin.rb +25 -25
- data/lib/cauterize/builders/ruby/composite.rb +26 -26
- data/lib/cauterize/builders/ruby/enumeration.rb +27 -27
- data/lib/cauterize/builders/ruby/fixed_array.rb +20 -20
- data/lib/cauterize/builders/ruby/group.rb +35 -35
- data/lib/cauterize/builders/ruby/scalar.rb +19 -19
- data/lib/cauterize/builders/ruby/variable_array.rb +22 -22
- data/lib/cauterize/builtin.rb +62 -62
- data/lib/cauterize/c_builder.rb +103 -103
- data/lib/cauterize/cauterize.rb +76 -76
- data/lib/cauterize/composite.rb +64 -64
- data/lib/cauterize/cs_builder.rb +58 -58
- data/lib/cauterize/doc_builder.rb +34 -34
- data/lib/cauterize/enumeration.rb +98 -98
- data/lib/cauterize/fixed_array.rb +50 -50
- data/lib/cauterize/formatter.rb +67 -67
- data/lib/cauterize/group.rb +81 -81
- data/lib/cauterize/representation.rb +32 -32
- data/lib/cauterize/ruby_builder.rb +44 -44
- data/lib/cauterize/scalar.rb +53 -53
- data/lib/cauterize/snake_case.rb +21 -21
- data/lib/cauterize/variable_array.rb +55 -55
- data/lib/cauterize/version.rb +3 -3
- data/spec/base_type_spec.rb +251 -251
- data/spec/builders/c/buildable_spec.rb +25 -25
- data/spec/builders/c/builtin_spec.rb +22 -22
- data/spec/builders/c/composite_spec.rb +50 -50
- data/spec/builders/c/enumeration_spec.rb +95 -95
- data/spec/builders/c/fixed_array_spec.rb +36 -36
- data/spec/builders/c/group_spec.rb +140 -140
- data/spec/builders/c/scalar_spec.rb +26 -26
- data/spec/builders/c/variable_array_spec.rb +48 -48
- data/spec/builders/cs/buildable_spec.rb +8 -8
- data/spec/builders/cs/composite_spec.rb +32 -32
- data/spec/builders/cs/enumeration_spec.rb +33 -33
- data/spec/builders/cs/fixed_array_spec.rb +41 -41
- data/spec/builders/cs/group_spec.rb +56 -56
- data/spec/builders/cs/scalar_spec.rb +7 -7
- data/spec/builders/cs/variable_array_spec.rb +49 -45
- data/spec/builders/doc/buildable_spec.rb +25 -25
- data/spec/builders_spec.rb +57 -57
- data/spec/builtin_spec.rb +43 -43
- data/spec/c_builder_spec.rb +176 -176
- data/spec/cauterize_spec.rb +15 -15
- data/spec/composite_spec.rb +77 -77
- data/spec/cs_builder_spec.rb +115 -115
- data/spec/doc_builder_spec.rb +260 -260
- data/spec/enumeration_spec.rb +145 -145
- data/spec/fixed_array_spec.rb +61 -61
- data/spec/group_spec.rb +111 -111
- data/spec/ruby_builder_spec.rb +83 -83
- data/spec/ruby_generated_spec.rb +735 -735
- data/spec/scalar_spec.rb +44 -44
- data/spec/spec_helper.rb +122 -122
- data/spec/support/shared_examples_for_array_buildables.rb +22 -22
- data/spec/support/shared_examples_for_c_buildables.rb +103 -103
- data/spec/support/shared_examples_for_sane_c_buildables.rb +22 -22
- data/spec/support/shared_examples_for_stubbed_functions.rb +18 -18
- data/spec/support/spec_sample_model.rb +74 -74
- data/spec/test_main.c +13 -13
- data/spec/variable_array_spec.rb +73 -73
- data/support/c/src/cauterize.c +75 -75
- data/support/c/src/cauterize.h +60 -60
- data/support/c/src/cauterize_debug.h +29 -29
- data/support/c/src/cauterize_util.h +8 -8
- data/support/c/test/greatest.h +536 -536
- data/support/c/test/test.c +166 -166
- data/support/cs/src/CauterizeCompositeFormatter.cs +0 -0
- data/support/cs/src/CauterizeContainerFormatter.cs +0 -0
- data/support/cs/src/CauterizeEnumFormatter.cs +0 -0
- data/support/cs/src/CauterizeException.cs +15 -15
- data/support/cs/src/CauterizeFixedArrayFormatter.cs +2 -2
- data/support/cs/src/CauterizeFormatter.cs +0 -0
- data/support/cs/src/CauterizeGroupFormatter.cs +0 -0
- data/support/cs/src/CauterizeTypeFormatterFactory.cs +0 -0
- data/support/cs/src/CauterizeTypes.cs +46 -12
- data/support/cs/src/CauterizeVariableArrayFormatter.cs +1 -1
- data/support/cs/src/ICauterizeTypeFormatter.cs +0 -0
- data/support/cs/src/OrderAttribute.cs +0 -0
- data/support/cs/src/PrimitiveSupport.cs +12 -0
- data/support/cs/test/CauterizeCompositeFormatterTest.cs +0 -0
- data/support/cs/test/CauterizeEnumFormatterTest.cs +0 -0
- data/support/cs/test/CauterizeFixedArrayFormatterTest.cs +0 -0
- data/support/cs/test/CauterizeFormatterTest.cs +0 -0
- data/support/cs/test/CauterizeGroupFormatterTest.cs +0 -0
- data/support/cs/test/CauterizeIntegrationTest.cs +0 -0
- data/support/cs/test/CauterizePrimitiveFormatterTest.cs +0 -0
- data/support/cs/test/CauterizeTypeFormatterFactoryTest.cs +0 -0
- data/support/cs/test/CauterizeVariableArrayFormatterTest.cs +0 -0
- data/support/cs/test/OrderAttributeTest.cs +0 -0
- data/support/ruby/src/cauterize_ruby_baseclasses.rb +367 -367
- data/support/ruby/src/cauterize_ruby_builtins.rb +148 -148
- metadata +20 -20
data/spec/builtin_spec.rb
CHANGED
@@ -1,43 +1,43 @@
|
|
1
|
-
module Cauterize
|
2
|
-
|
3
|
-
describe BuiltIn do
|
4
|
-
describe :initialize do
|
5
|
-
it "creates a builtin" do
|
6
|
-
b = BuiltIn.new(:foo)
|
7
|
-
b.flavor(:unsigned)
|
8
|
-
b.byte_length(4)
|
9
|
-
|
10
|
-
b.name.should == :foo
|
11
|
-
b.flavor.should == :unsigned
|
12
|
-
b.byte_length.should == 4
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
it { can_be_documented(BuiltIn) }
|
17
|
-
end
|
18
|
-
|
19
|
-
|
20
|
-
# Since the builtins are static, we make sure they are all defined here. They
|
21
|
-
# should be created as part of the loading process. This is kinda evil.
|
22
|
-
describe :builtins do
|
23
|
-
Cauterize.builtins.keys.should =~ [
|
24
|
-
:int8, :int16, :int32, :int64,
|
25
|
-
:uint8, :uint16, :uint32, :uint64,
|
26
|
-
:float32, :float64,
|
27
|
-
:bool,
|
28
|
-
]
|
29
|
-
end
|
30
|
-
|
31
|
-
# We should not provide a way for people to build more builtin types directly.
|
32
|
-
# This test ensures that there isn't a method to do so, but only by checking
|
33
|
-
# that we haven't added the convention.
|
34
|
-
#
|
35
|
-
# I know, I know, testing negative behavior.
|
36
|
-
describe :builtin do
|
37
|
-
it "should not exist" do
|
38
|
-
lambda {
|
39
|
-
Cauterize.builtin(:foo)
|
40
|
-
}.should raise_error /undefined method/
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
1
|
+
module Cauterize
|
2
|
+
|
3
|
+
describe BuiltIn do
|
4
|
+
describe :initialize do
|
5
|
+
it "creates a builtin" do
|
6
|
+
b = BuiltIn.new(:foo)
|
7
|
+
b.flavor(:unsigned)
|
8
|
+
b.byte_length(4)
|
9
|
+
|
10
|
+
b.name.should == :foo
|
11
|
+
b.flavor.should == :unsigned
|
12
|
+
b.byte_length.should == 4
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
it { can_be_documented(BuiltIn) }
|
17
|
+
end
|
18
|
+
|
19
|
+
|
20
|
+
# Since the builtins are static, we make sure they are all defined here. They
|
21
|
+
# should be created as part of the loading process. This is kinda evil.
|
22
|
+
describe :builtins do
|
23
|
+
Cauterize.builtins.keys.should =~ [
|
24
|
+
:int8, :int16, :int32, :int64,
|
25
|
+
:uint8, :uint16, :uint32, :uint64,
|
26
|
+
:float32, :float64,
|
27
|
+
:bool,
|
28
|
+
]
|
29
|
+
end
|
30
|
+
|
31
|
+
# We should not provide a way for people to build more builtin types directly.
|
32
|
+
# This test ensures that there isn't a method to do so, but only by checking
|
33
|
+
# that we haven't added the convention.
|
34
|
+
#
|
35
|
+
# I know, I know, testing negative behavior.
|
36
|
+
describe :builtin do
|
37
|
+
it "should not exist" do
|
38
|
+
lambda {
|
39
|
+
Cauterize.builtin(:foo)
|
40
|
+
}.should raise_error /undefined method/
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
data/spec/c_builder_spec.rb
CHANGED
@@ -1,176 +1,176 @@
|
|
1
|
-
require 'tmpdir'
|
2
|
-
require 'fileutils'
|
3
|
-
|
4
|
-
module Cauterize
|
5
|
-
describe Cauterize::CBuilder do
|
6
|
-
before do
|
7
|
-
@tempdir = Dir.mktmpdir
|
8
|
-
@h_path = File.join(@tempdir, "testing.h")
|
9
|
-
@c_path = File.join(@tempdir, "testing.c")
|
10
|
-
|
11
|
-
@cb = CBuilder.new(@h_path, @c_path, "testing")
|
12
|
-
end
|
13
|
-
after { FileUtils.rm_rf @tempdir }
|
14
|
-
|
15
|
-
describe :initialize do
|
16
|
-
it "saves the h and c paths" do
|
17
|
-
@cb.h.should == @h_path
|
18
|
-
@cb.c.should == @c_path
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
describe :build do
|
23
|
-
before do
|
24
|
-
Cauterize.set_version("1.2.3")
|
25
|
-
|
26
|
-
Cauterize.scalar(:small_uint) {|t| t.type_name(:uint8)}
|
27
|
-
|
28
|
-
Cauterize.fixed_array(:mac_address) do |fa|
|
29
|
-
fa.array_type :small_uint
|
30
|
-
fa.array_size 6
|
31
|
-
end
|
32
|
-
|
33
|
-
Cauterize.variable_array(:mac_table) do |t|
|
34
|
-
t.array_type :mac_address
|
35
|
-
t.array_size 64
|
36
|
-
end
|
37
|
-
|
38
|
-
Cauterize.variable_array(:name) do |va|
|
39
|
-
va.array_type :small_uint
|
40
|
-
va.array_size 32
|
41
|
-
end
|
42
|
-
|
43
|
-
Cauterize.enumeration(:gender) do |e|
|
44
|
-
e.value :male
|
45
|
-
e.value :female
|
46
|
-
end
|
47
|
-
|
48
|
-
Cauterize.composite(:place) do |c|
|
49
|
-
c.field :name, :name
|
50
|
-
c.field :elevation, :uint32
|
51
|
-
end
|
52
|
-
|
53
|
-
Cauterize.composite(:person) do |c|
|
54
|
-
c.field :first_name, :name
|
55
|
-
c.field :last_name, :name
|
56
|
-
c.field :gender, :gender
|
57
|
-
end
|
58
|
-
|
59
|
-
Cauterize.composite(:dog) do |c|
|
60
|
-
c.field :name, :name
|
61
|
-
c.field :gender, :gender
|
62
|
-
c.field :leg_count, :small_uint
|
63
|
-
end
|
64
|
-
|
65
|
-
Cauterize.group(:creature) do |g|
|
66
|
-
g.field :person, :person
|
67
|
-
g.field :dog, :dog
|
68
|
-
end
|
69
|
-
|
70
|
-
@cb.build
|
71
|
-
@h_text = File.read(@cb.h)
|
72
|
-
@h_lines = @h_text.lines.to_a
|
73
|
-
@c_text = File.read(@cb.c)
|
74
|
-
@c_lines = @c_text.lines.to_a
|
75
|
-
end
|
76
|
-
|
77
|
-
describe "header generation" do
|
78
|
-
it "informs the user the code is generated" do
|
79
|
-
@h_text.should include("generated code. Do not edit")
|
80
|
-
end
|
81
|
-
|
82
|
-
it "externs 'c'" do
|
83
|
-
@h_lines.should include("extern \"C\" {\n")
|
84
|
-
end
|
85
|
-
|
86
|
-
it "creates a VERSION define" do
|
87
|
-
@h_lines.should include("#define GEN_VERSION (\"1.2.3\")\n")
|
88
|
-
end
|
89
|
-
|
90
|
-
it "creates a DATE define" do
|
91
|
-
@h_lines.any?{|l| l.match /GEN_DATE/}.should be_true
|
92
|
-
end
|
93
|
-
|
94
|
-
it "prevents multiple inclusion in headers" do
|
95
|
-
@h_lines[2].should match /#ifndef TESTING_H_\d+/
|
96
|
-
@h_lines[3].should match /#define TESTING_H_\d+/
|
97
|
-
@h_lines[-2].should match /#endif \/\* TESTING_H_\d+ \*\//
|
98
|
-
@h_lines.last.should == "\n"
|
99
|
-
end
|
100
|
-
|
101
|
-
it "includes prototype information for all defined types" do
|
102
|
-
@h_text.should match "struct name;"
|
103
|
-
@h_text.should match "struct person;"
|
104
|
-
@h_text.should match "struct place;"
|
105
|
-
end
|
106
|
-
|
107
|
-
it "includes enumeration and structure definitions" do
|
108
|
-
@h_text.should match /gender/
|
109
|
-
@h_text.should match /MALE = 0/
|
110
|
-
@h_text.should match /FEMALE = 1/
|
111
|
-
end
|
112
|
-
|
113
|
-
it "includes preprocessor definitions for fixed and variable arrays" do
|
114
|
-
@h_text.should match /FIXED_ARRAY_LENGTH_mac_address/
|
115
|
-
@h_text.should match /VARIABLE_ARRAY_MAX_LENGTH_mac_table/
|
116
|
-
@h_text.should match /VARIABLE_ARRAY_MAX_LENGTH_name/
|
117
|
-
end
|
118
|
-
|
119
|
-
it "includes preprocessor definitions for maximum encoded length" do
|
120
|
-
@h_text.should match /MAX_ENCODED_LENGTH_small_uint/
|
121
|
-
@h_text.should match /MAX_ENCODED_LENGTH_mac_address/
|
122
|
-
@h_text.should match /MAX_ENCODED_LENGTH_mac_table/
|
123
|
-
@h_text.should match /MAX_ENCODED_LENGTH_name/
|
124
|
-
@h_text.should match /MAX_ENCODED_LENGTH_gender/
|
125
|
-
@h_text.should match /MAX_ENCODED_LENGTH_place/
|
126
|
-
@h_text.should match /MAX_ENCODED_LENGTH_person/
|
127
|
-
@h_text.should match /MAX_ENCODED_LENGTH_dog/
|
128
|
-
@h_text.should match /MAX_ENCODED_LENGTH_creature/
|
129
|
-
end
|
130
|
-
end
|
131
|
-
|
132
|
-
describe "c body generation" do
|
133
|
-
it "informs the user the code is generated" do
|
134
|
-
@c_text.should include("generated code. Do not edit")
|
135
|
-
end
|
136
|
-
|
137
|
-
it "includes the generated header file" do
|
138
|
-
@c_text.should match /#include "testing.h"/
|
139
|
-
end
|
140
|
-
|
141
|
-
it "uses the fixed array length preprocessor define" do
|
142
|
-
@c_text.should match /FIXED_ARRAY_LENGTH_mac_address/
|
143
|
-
end
|
144
|
-
end
|
145
|
-
|
146
|
-
describe "compilation" do
|
147
|
-
it "can be built" do
|
148
|
-
caut_dir = "#{File.dirname(__FILE__)}/../support/c/src"
|
149
|
-
|
150
|
-
res = Dir.chdir @tempdir do
|
151
|
-
File.open("test_main.c", "wb") do |fh|
|
152
|
-
syms = BaseType.all_instances.map do |i|
|
153
|
-
b = Builders.get(:c, i)
|
154
|
-
[b.packer_sym, b.unpacker_sym]
|
155
|
-
end.flatten
|
156
|
-
fh.write(gen_test_main(syms))
|
157
|
-
end
|
158
|
-
|
159
|
-
cmd = %W{
|
160
|
-
gcc -Wall -Wextra -Werror
|
161
|
-
-I#{caut_dir}
|
162
|
-
#{@cb.c}
|
163
|
-
#{caut_dir}/cauterize.c
|
164
|
-
test_main.c
|
165
|
-
-o testing.bin 2>&1
|
166
|
-
}.join(" ")
|
167
|
-
|
168
|
-
`#{cmd}`
|
169
|
-
end
|
170
|
-
|
171
|
-
res.should == ""
|
172
|
-
end
|
173
|
-
end
|
174
|
-
end
|
175
|
-
end
|
176
|
-
end
|
1
|
+
require 'tmpdir'
|
2
|
+
require 'fileutils'
|
3
|
+
|
4
|
+
module Cauterize
|
5
|
+
describe Cauterize::CBuilder do
|
6
|
+
before do
|
7
|
+
@tempdir = Dir.mktmpdir
|
8
|
+
@h_path = File.join(@tempdir, "testing.h")
|
9
|
+
@c_path = File.join(@tempdir, "testing.c")
|
10
|
+
|
11
|
+
@cb = CBuilder.new(@h_path, @c_path, "testing")
|
12
|
+
end
|
13
|
+
after { FileUtils.rm_rf @tempdir }
|
14
|
+
|
15
|
+
describe :initialize do
|
16
|
+
it "saves the h and c paths" do
|
17
|
+
@cb.h.should == @h_path
|
18
|
+
@cb.c.should == @c_path
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe :build do
|
23
|
+
before do
|
24
|
+
Cauterize.set_version("1.2.3")
|
25
|
+
|
26
|
+
Cauterize.scalar(:small_uint) {|t| t.type_name(:uint8)}
|
27
|
+
|
28
|
+
Cauterize.fixed_array(:mac_address) do |fa|
|
29
|
+
fa.array_type :small_uint
|
30
|
+
fa.array_size 6
|
31
|
+
end
|
32
|
+
|
33
|
+
Cauterize.variable_array(:mac_table) do |t|
|
34
|
+
t.array_type :mac_address
|
35
|
+
t.array_size 64
|
36
|
+
end
|
37
|
+
|
38
|
+
Cauterize.variable_array(:name) do |va|
|
39
|
+
va.array_type :small_uint
|
40
|
+
va.array_size 32
|
41
|
+
end
|
42
|
+
|
43
|
+
Cauterize.enumeration(:gender) do |e|
|
44
|
+
e.value :male
|
45
|
+
e.value :female
|
46
|
+
end
|
47
|
+
|
48
|
+
Cauterize.composite(:place) do |c|
|
49
|
+
c.field :name, :name
|
50
|
+
c.field :elevation, :uint32
|
51
|
+
end
|
52
|
+
|
53
|
+
Cauterize.composite(:person) do |c|
|
54
|
+
c.field :first_name, :name
|
55
|
+
c.field :last_name, :name
|
56
|
+
c.field :gender, :gender
|
57
|
+
end
|
58
|
+
|
59
|
+
Cauterize.composite(:dog) do |c|
|
60
|
+
c.field :name, :name
|
61
|
+
c.field :gender, :gender
|
62
|
+
c.field :leg_count, :small_uint
|
63
|
+
end
|
64
|
+
|
65
|
+
Cauterize.group(:creature) do |g|
|
66
|
+
g.field :person, :person
|
67
|
+
g.field :dog, :dog
|
68
|
+
end
|
69
|
+
|
70
|
+
@cb.build
|
71
|
+
@h_text = File.read(@cb.h)
|
72
|
+
@h_lines = @h_text.lines.to_a
|
73
|
+
@c_text = File.read(@cb.c)
|
74
|
+
@c_lines = @c_text.lines.to_a
|
75
|
+
end
|
76
|
+
|
77
|
+
describe "header generation" do
|
78
|
+
it "informs the user the code is generated" do
|
79
|
+
@h_text.should include("generated code. Do not edit")
|
80
|
+
end
|
81
|
+
|
82
|
+
it "externs 'c'" do
|
83
|
+
@h_lines.should include("extern \"C\" {\n")
|
84
|
+
end
|
85
|
+
|
86
|
+
it "creates a VERSION define" do
|
87
|
+
@h_lines.should include("#define GEN_VERSION (\"1.2.3\")\n")
|
88
|
+
end
|
89
|
+
|
90
|
+
it "creates a DATE define" do
|
91
|
+
@h_lines.any?{|l| l.match /GEN_DATE/}.should be_true
|
92
|
+
end
|
93
|
+
|
94
|
+
it "prevents multiple inclusion in headers" do
|
95
|
+
@h_lines[2].should match /#ifndef TESTING_H_\d+/
|
96
|
+
@h_lines[3].should match /#define TESTING_H_\d+/
|
97
|
+
@h_lines[-2].should match /#endif \/\* TESTING_H_\d+ \*\//
|
98
|
+
@h_lines.last.should == "\n"
|
99
|
+
end
|
100
|
+
|
101
|
+
it "includes prototype information for all defined types" do
|
102
|
+
@h_text.should match "struct name;"
|
103
|
+
@h_text.should match "struct person;"
|
104
|
+
@h_text.should match "struct place;"
|
105
|
+
end
|
106
|
+
|
107
|
+
it "includes enumeration and structure definitions" do
|
108
|
+
@h_text.should match /gender/
|
109
|
+
@h_text.should match /MALE = 0/
|
110
|
+
@h_text.should match /FEMALE = 1/
|
111
|
+
end
|
112
|
+
|
113
|
+
it "includes preprocessor definitions for fixed and variable arrays" do
|
114
|
+
@h_text.should match /FIXED_ARRAY_LENGTH_mac_address/
|
115
|
+
@h_text.should match /VARIABLE_ARRAY_MAX_LENGTH_mac_table/
|
116
|
+
@h_text.should match /VARIABLE_ARRAY_MAX_LENGTH_name/
|
117
|
+
end
|
118
|
+
|
119
|
+
it "includes preprocessor definitions for maximum encoded length" do
|
120
|
+
@h_text.should match /MAX_ENCODED_LENGTH_small_uint/
|
121
|
+
@h_text.should match /MAX_ENCODED_LENGTH_mac_address/
|
122
|
+
@h_text.should match /MAX_ENCODED_LENGTH_mac_table/
|
123
|
+
@h_text.should match /MAX_ENCODED_LENGTH_name/
|
124
|
+
@h_text.should match /MAX_ENCODED_LENGTH_gender/
|
125
|
+
@h_text.should match /MAX_ENCODED_LENGTH_place/
|
126
|
+
@h_text.should match /MAX_ENCODED_LENGTH_person/
|
127
|
+
@h_text.should match /MAX_ENCODED_LENGTH_dog/
|
128
|
+
@h_text.should match /MAX_ENCODED_LENGTH_creature/
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
describe "c body generation" do
|
133
|
+
it "informs the user the code is generated" do
|
134
|
+
@c_text.should include("generated code. Do not edit")
|
135
|
+
end
|
136
|
+
|
137
|
+
it "includes the generated header file" do
|
138
|
+
@c_text.should match /#include "testing.h"/
|
139
|
+
end
|
140
|
+
|
141
|
+
it "uses the fixed array length preprocessor define" do
|
142
|
+
@c_text.should match /FIXED_ARRAY_LENGTH_mac_address/
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
describe "compilation" do
|
147
|
+
it "can be built" do
|
148
|
+
caut_dir = "#{File.dirname(__FILE__)}/../support/c/src"
|
149
|
+
|
150
|
+
res = Dir.chdir @tempdir do
|
151
|
+
File.open("test_main.c", "wb") do |fh|
|
152
|
+
syms = BaseType.all_instances.map do |i|
|
153
|
+
b = Builders.get(:c, i)
|
154
|
+
[b.packer_sym, b.unpacker_sym]
|
155
|
+
end.flatten
|
156
|
+
fh.write(gen_test_main(syms))
|
157
|
+
end
|
158
|
+
|
159
|
+
cmd = %W{
|
160
|
+
gcc -Wall -Wextra -Werror
|
161
|
+
-I#{caut_dir}
|
162
|
+
#{@cb.c}
|
163
|
+
#{caut_dir}/cauterize.c
|
164
|
+
test_main.c
|
165
|
+
-o testing.bin 2>&1
|
166
|
+
}.join(" ")
|
167
|
+
|
168
|
+
`#{cmd}`
|
169
|
+
end
|
170
|
+
|
171
|
+
res.should == ""
|
172
|
+
end
|
173
|
+
end
|
174
|
+
end
|
175
|
+
end
|
176
|
+
end
|
data/spec/cauterize_spec.rb
CHANGED
@@ -1,15 +1,15 @@
|
|
1
|
-
describe Cauterize do
|
2
|
-
describe :set_name do
|
3
|
-
it "sets the name of the project" do
|
4
|
-
Cauterize.set_name("some_name")
|
5
|
-
Cauterize.get_name.should == "some_name"
|
6
|
-
end
|
7
|
-
end
|
8
|
-
|
9
|
-
describe :set_version do
|
10
|
-
it "sets a version string" do
|
11
|
-
Cauterize.set_version("0.1.2")
|
12
|
-
Cauterize.get_version.should == "0.1.2"
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
1
|
+
describe Cauterize do
|
2
|
+
describe :set_name do
|
3
|
+
it "sets the name of the project" do
|
4
|
+
Cauterize.set_name("some_name")
|
5
|
+
Cauterize.get_name.should == "some_name"
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
describe :set_version do
|
10
|
+
it "sets a version string" do
|
11
|
+
Cauterize.set_version("0.1.2")
|
12
|
+
Cauterize.get_version.should == "0.1.2"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|