cauterize 0.0.1.pre1 → 0.0.1.pre5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (102) hide show
  1. data/.gitignore +5 -0
  2. data/.rspec +1 -1
  3. data/Gemfile +1 -1
  4. data/README.md +0 -2
  5. data/Rakefile +19 -3
  6. data/bin/cauterize +14 -6
  7. data/example/Cauterize +22 -10
  8. data/example/build.sh +15 -2
  9. data/lib/cauterize/base_type.rb +2 -5
  10. data/lib/cauterize/builders.rb +1 -3
  11. data/lib/cauterize/builders/c/buildable.rb +3 -2
  12. data/lib/cauterize/builders/c/builtin.rb +46 -0
  13. data/lib/cauterize/builders/c/enumeration.rb +23 -2
  14. data/lib/cauterize/builders/c/fixed_array.rb +16 -7
  15. data/lib/cauterize/builders/c/group.rb +32 -3
  16. data/lib/cauterize/builders/c/scalar.rb +5 -0
  17. data/lib/cauterize/builders/c/variable_array.rb +1 -1
  18. data/lib/cauterize/builders/cs/buildable.rb +59 -0
  19. data/lib/cauterize/builders/cs/builtin.rb +23 -0
  20. data/lib/cauterize/builders/cs/composite.rb +21 -0
  21. data/lib/cauterize/builders/cs/csarray.rb +32 -0
  22. data/lib/cauterize/builders/cs/enumeration.rb +21 -0
  23. data/lib/cauterize/builders/cs/fixed_array.rb +25 -0
  24. data/lib/cauterize/builders/cs/group.rb +33 -0
  25. data/lib/cauterize/builders/cs/scalar.rb +10 -0
  26. data/lib/cauterize/builders/cs/variable_array.rb +34 -0
  27. data/lib/cauterize/builtin.rb +52 -0
  28. data/lib/cauterize/c_builder.rb +15 -1
  29. data/lib/cauterize/cauterize.rb +44 -13
  30. data/lib/cauterize/composite.rb +3 -3
  31. data/lib/cauterize/cs_builder.rb +53 -0
  32. data/lib/cauterize/enumeration.rb +20 -3
  33. data/lib/cauterize/fixed_array.rb +3 -3
  34. data/lib/cauterize/formatter.rb +7 -3
  35. data/lib/cauterize/group.rb +5 -8
  36. data/lib/cauterize/scalar.rb +16 -7
  37. data/lib/cauterize/variable_array.rb +6 -6
  38. data/lib/cauterize/version.rb +1 -1
  39. data/spec/base_type_spec.rb +133 -125
  40. data/spec/builders/c/buildable_spec.rb +18 -18
  41. data/spec/builders/c/builtin_spec.rb +22 -0
  42. data/spec/builders/c/composite_spec.rb +37 -33
  43. data/spec/builders/c/enumeration_spec.rb +84 -21
  44. data/spec/builders/c/fixed_array_spec.rb +6 -6
  45. data/spec/builders/c/group_spec.rb +97 -90
  46. data/spec/builders/c/scalar_spec.rb +24 -6
  47. data/spec/builders/c/variable_array_spec.rb +37 -37
  48. data/spec/builders/cs/buildable_spec.rb +8 -0
  49. data/spec/builders/cs/composite_spec.rb +32 -0
  50. data/spec/builders/cs/enumeration_spec.rb +33 -0
  51. data/spec/builders/cs/fixed_array_spec.rb +40 -0
  52. data/spec/builders/cs/group_spec.rb +56 -0
  53. data/spec/builders/cs/scalar_spec.rb +7 -0
  54. data/spec/builders/cs/variable_array_spec.rb +46 -0
  55. data/spec/builders_spec.rb +38 -38
  56. data/spec/builtin_spec.rb +46 -0
  57. data/spec/c_builder_spec.rb +116 -102
  58. data/spec/cauterize_spec.rb +8 -1
  59. data/spec/composite_spec.rb +52 -48
  60. data/spec/cs_builder_spec.rb +113 -0
  61. data/spec/enumeration_spec.rb +55 -16
  62. data/spec/fixed_array_spec.rb +7 -9
  63. data/spec/group_spec.rb +81 -76
  64. data/spec/scalar_spec.rb +20 -10
  65. data/spec/spec_helper.rb +103 -94
  66. data/spec/support/shared_examples_for_c_buildables.rb +68 -64
  67. data/spec/variable_array_spec.rb +12 -17
  68. data/{c → support/c}/src/cauterize.c +8 -7
  69. data/support/c/src/cauterize.h +59 -0
  70. data/{c → support/c}/src/cauterize_debug.h +0 -0
  71. data/support/c/src/cauterize_util.h +49 -0
  72. data/{c → support/c}/test/greatest.h +0 -0
  73. data/{c → support/c}/test/test.c +0 -0
  74. data/support/cs/src/CauterizeCompositeFormatter.cs +34 -0
  75. data/support/cs/src/CauterizeContainerFormatter.cs +18 -0
  76. data/support/cs/src/CauterizeEnumFormatter.cs +67 -0
  77. data/support/cs/src/CauterizeException.cs +15 -0
  78. data/support/cs/src/CauterizeFixedArrayFormatter.cs +39 -0
  79. data/support/cs/src/CauterizeFormatter.cs +40 -0
  80. data/support/cs/src/CauterizeGroupFormatter.cs +46 -0
  81. data/support/cs/src/CauterizePrimitiveFormatter.cs +33 -0
  82. data/support/cs/src/CauterizeTypeFormatterFactory.cs +39 -0
  83. data/support/cs/src/CauterizeTypes.cs +107 -0
  84. data/support/cs/src/CauterizeVariableArrayFormatter.cs +49 -0
  85. data/support/cs/src/ICauterizeTypeFormatter.cs +12 -0
  86. data/support/cs/src/OrderAttribute.cs +50 -0
  87. data/support/cs/src/PrimitiveSupport.cs +134 -0
  88. data/support/cs/src/SerializedRepresentationAttribute.cs +24 -0
  89. data/support/cs/test/CauterizeCompositeFormatterTest.cs +59 -0
  90. data/support/cs/test/CauterizeEnumFormatterTest.cs +110 -0
  91. data/support/cs/test/CauterizeFixedArrayFormatterTest.cs +91 -0
  92. data/support/cs/test/CauterizeFormatterTest.cs +40 -0
  93. data/support/cs/test/CauterizeGroupFormatterTest.cs +147 -0
  94. data/support/cs/test/CauterizeIntegrationTest.cs +129 -0
  95. data/support/cs/test/CauterizePrimitiveFormatterTest.cs +98 -0
  96. data/support/cs/test/CauterizeTypeFormatterFactoryTest.cs +73 -0
  97. data/support/cs/test/CauterizeVariableArrayFormatterTest.cs +130 -0
  98. data/support/cs/test/OrderAttributeTest.cs +39 -0
  99. data/support/cs/test/SerializedRepresentationAttributeTest.cs +39 -0
  100. metadata +68 -10
  101. data/c/src/cauterize.h +0 -46
  102. data/c/src/cauterize_util.h +0 -7
@@ -1,8 +1,26 @@
1
- describe Cauterize::Builders::C::Scalar do
2
- let(:type_constructor) { lambda {|name| scalar(name)}}
1
+ module Cauterize
2
+ describe Cauterize::Builders::C::Scalar do
3
+ let(:type_constructor) {
4
+ lambda {
5
+ |name| Cauterize.scalar(name) {
6
+ |t| t.type_name(:int32)
7
+ }
8
+ }
9
+ }
3
10
 
4
- it_behaves_like "a buildable"
5
- it_behaves_like "a sane buildable"
6
- include_examples "no enum"
7
- include_examples "no struct"
11
+ describe ".typedef_decl" do
12
+ it "declares the type synonym" do
13
+ s = Cauterize.scalar(:zeep) {|t| t.type_name(:int32)}
14
+
15
+ f = default_formatter
16
+ Builders.get(:c, s).typedef_decl(f)
17
+ f.to_s.should == "typedef int32_t zeep;"
18
+ end
19
+ end
20
+
21
+ it_behaves_like "a buildable"
22
+ it_behaves_like "a sane buildable"
23
+ include_examples "no enum"
24
+ include_examples "no struct"
25
+ end
8
26
  end
@@ -1,49 +1,49 @@
1
- describe Cauterize::Builders::C::VariableArray do
2
- let(:type_constructor) do
3
- lambda do |name|
4
- scalar(:uint8_t)
5
- variable_array(name) do |a|
6
- a.array_type(:uint8_t)
7
- a.array_size(8)
8
- a.size_type(:uint8_t)
1
+ module Cauterize
2
+ describe Cauterize::Builders::C::VariableArray do
3
+ let(:type_constructor) do
4
+ lambda do |name|
5
+ Cauterize.variable_array(name) do |a|
6
+ a.array_type(:uint8)
7
+ a.array_size(8)
8
+ a.size_type(:uint8)
9
+ end
9
10
  end
10
11
  end
11
- end
12
12
 
13
- it_behaves_like "a buildable"
14
- it_behaves_like "a sane buildable"
15
- include_examples "no enum"
13
+ it_behaves_like "a buildable"
14
+ it_behaves_like "a sane buildable"
15
+ include_examples "no enum"
16
16
 
17
- context "structure definition" do
18
- let(:vara) do
19
- scalar(:int32)
20
- _a = variable_array(:va) do |a|
21
- a.array_size(8)
22
- a.array_type(:int32)
23
- a.size_type(:int32)
24
- end
17
+ context "structure definition" do
18
+ let(:vara) do
19
+ _a = Cauterize.variable_array(:va) do |a|
20
+ a.array_size(8)
21
+ a.array_type(:int32)
22
+ a.size_type(:int32)
23
+ end
25
24
 
26
- Builders.get(:c, _a)
27
- end
25
+ Builders.get(:c, _a)
26
+ end
28
27
 
29
- describe ".struct_proto" do
30
- it "defines a structure prototype" do
31
- f = default_formatter
32
- vara.struct_proto(f)
33
- f.to_s.should == "struct va;"
28
+ describe ".struct_proto" do
29
+ it "defines a structure prototype" do
30
+ f = default_formatter
31
+ vara.struct_proto(f)
32
+ f.to_s.should == "struct va;"
33
+ end
34
34
  end
35
- end
36
35
 
37
- describe ".struct_defn" do
38
- it "defines a structure definition" do
39
- f = default_formatter
40
- vara.struct_defn(f)
41
- fs = f.to_s
36
+ describe ".struct_defn" do
37
+ it "defines a structure definition" do
38
+ f = default_formatter
39
+ vara.struct_defn(f)
40
+ fs = f.to_s
42
41
 
43
- fs.should match /struct va/
44
- fs.should match /int32 length;/
45
- fs.should match /int32 data\[8\];/
46
- fs.should match /};/
42
+ fs.should match /struct va/
43
+ fs.should match /int32_t length;/
44
+ fs.should match /int32_t data\[8\];/
45
+ fs.should match /};/
46
+ end
47
47
  end
48
48
  end
49
49
  end
@@ -0,0 +1,8 @@
1
+ include Cauterize::Builders::CS
2
+
3
+ describe Cauterize::Builders::CS do
4
+ describe Buildable do
5
+ subject { Buildable.new(:some_blueprint) }
6
+ pending "nothing to test until packing"
7
+ end
8
+ end
@@ -0,0 +1,32 @@
1
+ module Cauterize
2
+ describe Cauterize::Builders::CS::Composite do
3
+ context "class definition" do
4
+ let(:comp) do
5
+ Cauterize.scalar(:int32_t) {|t| t.type_name(:int32) }
6
+ Cauterize.scalar(:int16_t) {|t| t.type_name(:int16) }
7
+ _c = Cauterize.composite(:foo) do |c|
8
+ c.field(:an_int, :int32_t)
9
+ c.field(:a_short, :int16_t)
10
+ end
11
+
12
+ Builders.get(:cs, _c)
13
+ end
14
+
15
+ describe ".class_defn" do
16
+ it "defines a class for the composite" do
17
+ f = four_space_formatter
18
+ comp.class_defn(f)
19
+ f.to_s.should == <<EOS
20
+ public class Foo : CauterizeComposite
21
+ {
22
+ [Order(0)]
23
+ public Int32 AnInt { get; set; }
24
+ [Order(1)]
25
+ public Int16 AShort { get; set; }
26
+ }
27
+ EOS
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,33 @@
1
+ module Cauterize
2
+ describe Cauterize::Builders::CS::Enumeration do
3
+ describe ".enum_defn" do
4
+ let(:en) do
5
+ _e = Cauterize.enumeration(:foo) do |e|
6
+ e.value :aaa
7
+ e.value :bbb
8
+ e.value "quick_brown_fox".to_sym
9
+ end
10
+
11
+ f = default_formatter
12
+ Builders.get(:cs, _e).enum_defn(f)
13
+ f.to_s
14
+ end
15
+
16
+ it "contains the serialized representation annotation" do
17
+ en.should match /\[SerializedRepresentation\(typeof\(SByte\)\)\]/
18
+ end
19
+
20
+ it "contains the enum name" do
21
+ en.should match /public enum Foo/
22
+ end
23
+
24
+ it "contains an entry for each value" do
25
+ en.should match /Aaa = 0,/
26
+ en.should match /Bbb = 1,/
27
+ en.should match /QuickBrownFox = 2,/
28
+ en.should match /};/
29
+ end
30
+ end
31
+ end
32
+ end
33
+
@@ -0,0 +1,40 @@
1
+ describe Cauterize::Builders::CS::FixedArray do
2
+
3
+ context "array class definition" do
4
+ let(:fixed_arr) do
5
+ Cauterize.scalar(:uint32_t) {|t| t.type_name(:uint32)}
6
+ _fa = Cauterize.fixed_array(:myriad_data) do |a|
7
+ a.array_type :uint32_t
8
+ a.array_size 16
9
+ end
10
+
11
+ Cauterize::Builders.get(:cs, _fa)
12
+ end
13
+
14
+ describe ".class_defn" do
15
+ let(:text) do
16
+ f = four_space_formatter
17
+ fixed_arr.class_defn(f)
18
+ text = f.to_s
19
+ end
20
+ it "defines a class for the array" do
21
+ text.should match /public class MyriadData : CauterizeFixedArrayTyped<UInt32>/
22
+ end
23
+
24
+ it "sets the size of the array from configuration" do
25
+ text.should match /public MyriadData\(\)/ # no args
26
+ text.should match /Allocate\(16\);/
27
+ end
28
+
29
+ it "allows defaulting an array" do
30
+ text.should match /public MyriadData\(UInt32\[\] data\)/
31
+ text.should match /Allocate\(data\);/
32
+ end
33
+
34
+ it "defines a size" do
35
+ text.should match /protected override int Size/
36
+ text.should match /get { return 16; }/
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,56 @@
1
+ module Cauterize
2
+ describe Cauterize::Builders::CS::Group do
3
+ context "enumeration for type tag" do
4
+ before do
5
+ Cauterize.scalar(:uint8_t) {|t| t.type_name(:uint8)}
6
+ @g = Cauterize.group!(:some_name) do |_g|
7
+ _g.field(:a, :uint8_t)
8
+ _g.field(:b, :uint8_t)
9
+ _g.field(:c)
10
+ _g.field(:d, :uint8_t)
11
+ end
12
+ @b = Cauterize::Builders::CS::Group.new(@g)
13
+ end
14
+
15
+ describe ".initialize" do
16
+ it "creates the enumeration tag" do
17
+ @b.instance_variable_get(:@tag_enum).class.name.should == "Cauterize::Enumeration"
18
+ end
19
+ end
20
+
21
+ describe "@tag_enum" do
22
+ it "contains a entry for each field in the group" do
23
+ e = @b.instance_variable_get(:@tag_enum)
24
+ e.values.keys.should =~ [ :GROUP_SOME_NAME_TYPE_A,
25
+ :GROUP_SOME_NAME_TYPE_B,
26
+ :GROUP_SOME_NAME_TYPE_C,
27
+ :GROUP_SOME_NAME_TYPE_D ]
28
+ end
29
+ end
30
+
31
+ describe ".class_defn" do
32
+ it "defines an enum and class" do
33
+ f = four_space_formatter
34
+ @b.class_defn(f)
35
+ fs = f.to_s
36
+
37
+ fs.should == <<EOS
38
+ public class SomeName : CauterizeGroup
39
+ {
40
+ [Order(0)]
41
+ public GroupSomeNameType Type { get; set; }
42
+
43
+ [Order(1)]
44
+ public Byte A { get; set; }
45
+ [Order(2)]
46
+ public Byte B { get; set; }
47
+ /* No data associated with 'c'. */
48
+ [Order(4)]
49
+ public Byte D { get; set; }
50
+ }
51
+ EOS
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,7 @@
1
+ module Cauterize
2
+ describe Cauterize::Builders::CS::Scalar do
3
+ let(:type_constructor) { lambda {|name| Cauterize.scalar(name)}}
4
+
5
+ pending "base buildable tests for csharp"
6
+ end
7
+ end
@@ -0,0 +1,46 @@
1
+ describe Cauterize::Builders::CS::VariableArray do
2
+
3
+ context "array class definition" do
4
+ let(:var_arr) do
5
+ Cauterize.scalar(:uint32_t) {|t| t.type_name(:uint32)}
6
+ Cauterize.scalar(:uint8_t) {|t| t.type_name(:uint8)}
7
+ _va = Cauterize.variable_array(:myriad_data) do |a|
8
+ a.size_type :uint8_t
9
+ a.array_type :uint32_t
10
+ a.array_size 16
11
+ end
12
+
13
+ Cauterize::Builders.get(:cs, _va)
14
+ end
15
+
16
+ describe ".class_defn" do
17
+ let(:text) do
18
+ f = four_space_formatter
19
+ var_arr.class_defn(f)
20
+ text = f.to_s
21
+ end
22
+ it "defines a class for the array" do
23
+ text.should match /public class MyriadData : CauterizeVariableArrayTyped<UInt32>/
24
+ end
25
+
26
+ it "defines the size type" do
27
+ text.should match /public static Type SizeType = typeof\(Byte\);/
28
+ end
29
+
30
+ it "sets the size of the array from configuration" do
31
+ text.should match /public MyriadData\(int size\)/ # no args
32
+ text.should match /Allocate\(size\);/
33
+ end
34
+
35
+ it "allows defaulting an array" do
36
+ text.should match /public MyriadData\(UInt32\[\] data\)/
37
+ text.should match /Allocate\(data\);/
38
+ end
39
+
40
+ it "defines a max size" do
41
+ text.should match /protected override int MaxSize/
42
+ text.should match /get { return Byte\.MaxValue; }/
43
+ end
44
+ end
45
+ end
46
+ end
@@ -1,51 +1,51 @@
1
- describe Cauterize::Builders do
2
- describe "#register and #get" do
3
- let(:s) { scalar(:uint8_t) }
4
- before do
5
- class X; def initialize(i); end; end
6
- class Y; def initialize(i); end; end
1
+ module Cauterize
2
+ describe Cauterize::Builders do
3
+ describe "#register and #get" do
4
+ let(:s) { Cauterize.scalar(:uint8_t) }
5
+ before do
6
+ class X; def initialize(i); end; end
7
+ class Y; def initialize(i); end; end
7
8
 
8
- # save the old list so that we can restore it later.
9
- old_builders = nil
10
- Cauterize::Builders.module_exec do
11
- old_builders = @builders
12
- @builders = nil
9
+ # save the old list so that we can restore it later.
10
+ old_builders = nil
11
+ Cauterize::Builders.module_exec do
12
+ old_builders = @builders
13
+ @builders = nil
14
+ end
15
+ @old_builders = old_builders
13
16
  end
14
- @old_builders = old_builders
15
- end
16
17
 
17
- after do
18
- # restore the builders so as not to break any other tests
19
- old_builders = @old_builders
20
- Cauterize::Builders.module_exec do
21
- @builders = old_builders
18
+ after do
19
+ # restore the builders so as not to break any other tests
20
+ old_builders = @old_builders
21
+ Cauterize::Builders.module_exec do
22
+ @builders = old_builders
23
+ end
22
24
  end
23
- end
24
25
 
25
- it "saves and retrieves classes" do
26
- Cauterize::Builders.register(:c, Cauterize::Scalar, X)
27
- Cauterize::Builders.get(:c, s).class.should be X
28
- end
26
+ it "saves and retrieves classes" do
27
+ Cauterize::Builders.register(:c, Cauterize::Scalar, X)
28
+ Cauterize::Builders.get(:c, s).class.should be X
29
+ end
29
30
 
30
- it "handles multiple languages" do
31
- Cauterize::Builders.register(:c, Cauterize::Scalar, X)
32
- Cauterize::Builders.get(:c, s).class.should be X
31
+ it "handles multiple languages" do
32
+ Cauterize::Builders.register(:c, Cauterize::Scalar, X)
33
+ Cauterize::Builders.get(:c, s).class.should be X
33
34
 
34
- Cauterize::Builders.register(:cs, Cauterize::Scalar, Y)
35
- Cauterize::Builders.get(:cs, s).class.should be Y
36
- end
35
+ Cauterize::Builders.register(:cs, Cauterize::Scalar, Y)
36
+ Cauterize::Builders.get(:cs, s).class.should be Y
37
+ end
37
38
 
38
- it "raises an error on duplicate registrations" do
39
- Cauterize::Builders.register(:c, Cauterize::Scalar, X)
40
- lambda {
39
+ it "raises an error on duplicate registrations" do
41
40
  Cauterize::Builders.register(:c, Cauterize::Scalar, X)
42
- }.should raise_error /already registered/
43
- end
41
+ lambda {
42
+ Cauterize::Builders.register(:c, Cauterize::Scalar, X)
43
+ }.should raise_error /already registered/
44
+ end
44
45
 
45
- it "raises an error if no builder is registered" do
46
- lambda {
47
- Cauterize::Builders.get(:c, s)
48
- }.should raise_error /unregistered/
46
+ it "is nil if no builder is registered" do
47
+ Cauterize::Builders.get(:c, s).should be_nil
48
+ end
49
49
  end
50
50
  end
51
51
  end
@@ -0,0 +1,46 @@
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.is_signed(false)
8
+ b.byte_length(4)
9
+
10
+ b.name.should == :foo
11
+ b.is_signed.should == false
12
+ b.byte_length.should == 4
13
+ end
14
+ end
15
+
16
+ describe :id do
17
+ it "has a unique id for each builtin" do
18
+ ids = Cauterize.builtins.values.map(&:id)
19
+ ids.uniq.should =~ ids
20
+ end
21
+ end
22
+ end
23
+
24
+
25
+ # Since the builtins are static, we make sure they are all defined here. They
26
+ # should be created as part of the loading process. This is kinda evil.
27
+ describe :builtins do
28
+ Cauterize.builtins.keys.should =~ [
29
+ :int8, :int16, :int32, :int64,
30
+ :uint8, :uint16, :uint32, :uint64,
31
+ ]
32
+ end
33
+
34
+ # We should not provide a way for people to build more builtin types directly.
35
+ # This test ensures that there isn't a method to do so, but only by checking
36
+ # that we haven't added the convention.
37
+ #
38
+ # I know, I know, testing negative behavior.
39
+ describe :builtin do
40
+ it "should not exist" do
41
+ lambda {
42
+ Cauterize.builtin(:foo)
43
+ }.should raise_error /undefined method/
44
+ end
45
+ end
46
+ end