RuCodeGen 0.1.0

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.
Files changed (36) hide show
  1. data/LICENSE +25 -0
  2. data/README +34 -0
  3. data/Rakefile +32 -0
  4. data/docs/Principle +152 -0
  5. data/docs/ValueIncapsulator +195 -0
  6. data/docs/examples/cpp/custom/submit_deliver +909 -0
  7. data/docs/examples/cpp/value_incapsulator/cfg +127 -0
  8. data/docs/examples/cpp/value_incapsulator/host_config +51 -0
  9. data/examples/cpp/custom/submit_deliver/submit_deliver.rb +43 -0
  10. data/examples/cpp/custom/submit_deliver/submit_deliver_gen.rb +326 -0
  11. data/examples/cpp/value_incapsulator/cfg.decl.hpp +51 -0
  12. data/examples/cpp/value_incapsulator/cfg.impl.cpp +63 -0
  13. data/examples/cpp/value_incapsulator/cg-cfg.rb +19 -0
  14. data/examples/cpp/value_incapsulator/cg-cfg.test.cpp +15 -0
  15. data/examples/cpp/value_incapsulator/cg-host_config.rb +12 -0
  16. data/examples/cpp/value_incapsulator/cout.log +4 -0
  17. data/examples/cpp/value_incapsulator/host_config.impl.cpp +21 -0
  18. data/examples/cpp/value_incapsulator/host_config.impl.hpp +21 -0
  19. data/lib/rucodegen/begin_end.rb +26 -0
  20. data/lib/rucodegen/codegen.rb +4 -0
  21. data/lib/rucodegen/filename_producer.rb +57 -0
  22. data/lib/rucodegen/generation_initiator.rb +92 -0
  23. data/lib/rucodegen/generators.rb +36 -0
  24. data/lib/rucodegen/run_mode.rb +89 -0
  25. data/lib/rucodegen/value_incapsulator.rb +331 -0
  26. data/lib/rucodegen.rb +4 -0
  27. data/tests/generators_test_extension.rb +23 -0
  28. data/tests/tc_class_attribute.rb +87 -0
  29. data/tests/tc_codegen_initiator.rb +164 -0
  30. data/tests/tc_filename_producer.rb +54 -0
  31. data/tests/tc_generators.rb +55 -0
  32. data/tests/tc_run_mode.rb +72 -0
  33. data/tests/tc_value_incapsulator.rb +193 -0
  34. data/tests/tc_value_incapsulator_gen.rb +479 -0
  35. data/tests/ts_rucodegen.rb +11 -0
  36. metadata +98 -0
@@ -0,0 +1,55 @@
1
+ $:.unshift( File.dirname( __FILE__ ) + "/../lib" )
2
+
3
+ require 'test/unit'
4
+
5
+ require 'rucodegen/generators.rb'
6
+
7
+ require 'generators_test_extension.rb'
8
+
9
+ class TC_Generators < Test::Unit::TestCase
10
+ GENERATORS = RuCodeGen::Generators
11
+
12
+ def setup
13
+ GENERATORS::test_setup
14
+
15
+ @test_generator = "test"
16
+ end
17
+
18
+ def teardown
19
+ GENERATORS::test_teardown
20
+ end
21
+
22
+ def test_add_generator
23
+ GENERATORS.add( "a.cpp", @test_generator )
24
+ GENERATORS.add( "b.cpp", @test_generator )
25
+
26
+ assert_raise( RuntimeError ) do
27
+ GENERATORS.add( "a.cpp", @test_generator )
28
+ end
29
+
30
+ assert_equal( 2,
31
+ GENERATORS.test_all_generators.size )
32
+ end
33
+
34
+ def test_all_files
35
+ GENERATORS.add( "1", @test_generator )
36
+ GENERATORS.add( "2", @test_generator )
37
+ GENERATORS.add( "3", @test_generator )
38
+ GENERATORS.add( "4", @test_generator )
39
+
40
+ assert_equal( %w{ 1 2 3 4 }.sort,
41
+ GENERATORS.all_files.sort )
42
+ end
43
+
44
+ def test_get_generator
45
+ GENERATORS.add( "a.cpp", @test_generator )
46
+ GENERATORS.add( "b.cpp", @test_generator )
47
+
48
+ assert_equal( @test_generator,
49
+ GENERATORS.for_file( "a.cpp" ) )
50
+ assert_equal( @test_generator,
51
+ GENERATORS.for_file( "b.cpp" ) )
52
+ end
53
+
54
+ end
55
+
@@ -0,0 +1,72 @@
1
+ $:.unshift( File.dirname( __FILE__ ) + "/../lib" )
2
+
3
+ require 'test/unit'
4
+
5
+ require 'rucodegen/run_mode'
6
+
7
+ module RuCodeGen
8
+
9
+ class RunMode
10
+ def RunMode.test_setup
11
+ @@mode = UNKNOWN
12
+ end
13
+ end
14
+
15
+ end
16
+
17
+ class TC_RunMode < Test::Unit::TestCase
18
+ RUNMODE = RuCodeGen::RunMode
19
+
20
+ def setup
21
+ ARGV.clear
22
+ RUNMODE.test_setup
23
+ end
24
+
25
+ def test_no_args
26
+ assert_equal RUNMODE::BUILD, RUNMODE.mode
27
+ end
28
+
29
+ def test_help_mode_short
30
+ ARGV << "-h"
31
+ assert_equal RUNMODE::HELP, RUNMODE.mode
32
+ end
33
+
34
+ def test_help_mode_long
35
+ ARGV << "--help"
36
+ assert_equal RUNMODE::HELP, RUNMODE.mode
37
+ end
38
+
39
+ def test_modes_short
40
+ modes = {
41
+ "build" => RUNMODE::BUILD,
42
+ "rebuild" => RUNMODE::REBUILD,
43
+ "clean" => RUNMODE::CLEAN,
44
+ "dry_run" => RUNMODE::DRY_RUN
45
+ }
46
+
47
+ modes.each do |key, value|
48
+ ARGV << "-m#{key}"
49
+ assert_equal value, RUNMODE.mode, "-m#{key} failed"
50
+
51
+ setup
52
+ end
53
+ end
54
+
55
+ def test_modes_long
56
+ modes = {
57
+ "build" => RUNMODE::BUILD,
58
+ "rebuild" => RUNMODE::REBUILD,
59
+ "clean" => RUNMODE::CLEAN,
60
+ "dry_run" => RUNMODE::DRY_RUN
61
+ }
62
+
63
+ modes.each do |key, value|
64
+ ARGV << "--mode=#{key}"
65
+ assert_equal value, RUNMODE.mode, "--mode=#{key} failed"
66
+
67
+ setup
68
+ end
69
+ end
70
+
71
+ end
72
+
@@ -0,0 +1,193 @@
1
+ $:.unshift( File.dirname( __FILE__ ) + "/../lib" )
2
+
3
+ require 'test/unit'
4
+
5
+ require 'rucodegen/value_incapsulator'
6
+
7
+ module EmptyValueIncapsulatorChecker
8
+ def check_empty_value_incapsulator( class_name, vi )
9
+ assert_equal( class_name, vi.class_name )
10
+ assert_equal( "", vi.get_attr_prefix )
11
+ assert_equal( "", vi.get_attr_suffix )
12
+ assert_equal( "", vi.get_getter_prefix )
13
+ assert_equal( "", vi.get_setter_prefix )
14
+ assert_equal( [], vi.get_attributes )
15
+ assert_equal( nil, vi.get_decl_file )
16
+ assert_equal( nil, vi.get_impl_file )
17
+ end
18
+ end
19
+
20
+ class TC_ValueIncapsulator < Test::Unit::TestCase
21
+ include EmptyValueIncapsulatorChecker
22
+
23
+ def test_empty_value_incapsulator
24
+ vi = RuCodeGen::ValueIncapsulator.new( "cfg_t" )
25
+
26
+ check_empty_value_incapsulator( "cfg_t", vi )
27
+ end
28
+
29
+ def test_attr_prefix_suffix
30
+ vi = RuCodeGen::ValueIncapsulator.new( "cfg_t" )
31
+ vi.attr_prefix "m_"
32
+ vi.attr_suffix "_"
33
+
34
+ assert_equal( "m_", vi.get_attr_prefix )
35
+ assert_equal( "_", vi.get_attr_suffix )
36
+ end
37
+
38
+ def test_getter_setter_prefix
39
+ vi = RuCodeGen::ValueIncapsulator.new( "cfg_t" )
40
+ vi.getter_prefix "get_"
41
+ vi.setter_prefix "set_"
42
+
43
+ assert_equal( "get_", vi.get_getter_prefix )
44
+ assert_equal( "set_", vi.get_setter_prefix )
45
+ end
46
+
47
+ def test_decl_impl_files
48
+ vi = RuCodeGen::ValueIncapsulator.new( "cfg_t" )
49
+ vi.decl_file :absolute => "/home/eao197/dummy"
50
+ vi.impl_file :script_relative => "dummy"
51
+
52
+ assert_equal(
53
+ { :absolute => "/home/eao197/dummy" },
54
+ vi.get_decl_file )
55
+ assert_equal(
56
+ { :script_relative => "dummy" },
57
+ vi.get_impl_file )
58
+ end
59
+ end
60
+
61
+ class TC_CppValueIncapsulatorFunc < Test::Unit::TestCase
62
+ def test_empty_value_incapsulator
63
+ # ������ ���� ��������� ���������� � ���, ��� �� ������
64
+ # ��� decl_file.
65
+ assert_raise( RuntimeError ) do
66
+ cpp_value_incapsulator( "cfg_t" ) { |c| }
67
+ end
68
+
69
+ # ������ ���� ��������� ���������� � ���, ��� �� ������
70
+ # ��� impl_file.
71
+ assert_raise( RuntimeError ) do
72
+ cpp_value_incapsulator( "cfg_t" ) { |c|
73
+ c.decl_file :absolute => "/home/eao197/dummy"
74
+ }
75
+ end
76
+
77
+ # �� ������ ���� ������� ����������.
78
+ cpp_value_incapsulator( "cfg_t" ) { |c|
79
+ c.decl_file :absolute => "/home/eao197/dummy.hpp"
80
+ c.impl_file :absolute => "/home/eao197/dummy.cpp"
81
+ }
82
+ end
83
+
84
+ def test_attr_prefix
85
+ vi = cpp_value_incapsulator( "cfg_t" ) do |c|
86
+ c.decl_file :script_relative => "test_attr_prefix.hpp"
87
+ c.impl_file :script_relative => "test_attr_prefix.cpp"
88
+ c.attr_prefix "m_"
89
+ end
90
+
91
+ assert_equal( "m_", vi.get_attr_prefix )
92
+ end
93
+
94
+ def test_attr_suffix
95
+ vi = cpp_value_incapsulator( "cfg_t" ) do |c|
96
+ c.decl_file :script_relative => "test_attr_suffix.hpp"
97
+ c.impl_file :script_relative => "test_attr_suffix.cpp"
98
+ c.attr_suffix "_"
99
+ end
100
+
101
+ assert_equal( "_", vi.get_attr_suffix )
102
+ end
103
+
104
+ def test_getter_prefix
105
+ vi = cpp_value_incapsulator( "cfg_t" ) do |c|
106
+ c.decl_file :script_relative => "test_getter_prefix.hpp"
107
+ c.impl_file :script_relative => "test_getter_prefix.cpp"
108
+ c.getter_prefix "query_"
109
+ end
110
+
111
+ assert_equal( "query_", vi.get_getter_prefix )
112
+ end
113
+
114
+ def test_setter_prefix
115
+ vi = cpp_value_incapsulator( "cfg_t" ) do |c|
116
+ c.decl_file :script_relative => "test_setter_prefix.hpp"
117
+ c.impl_file :script_relative => "test_setter_prefix.cpp"
118
+ c.setter_prefix "set_"
119
+ end
120
+
121
+ assert_equal( "set_", vi.get_setter_prefix )
122
+ end
123
+
124
+ def test_single_attribute_no_default
125
+ vi = cpp_value_incapsulator( "cfg_t" ) do |c|
126
+ c.decl_file :script_relative => "test_single_attribute_no_default.hpp"
127
+ c.impl_file :script_relative => "test_single_attribute_no_default.cpp"
128
+ c.attr :name, "std::string"
129
+ end
130
+
131
+ attributes = vi.get_attributes
132
+ assert_equal( 1, attributes.size )
133
+ assert_equal( :name, attributes[ 0 ].name )
134
+ assert_equal( "std::string", attributes[ 0 ].type )
135
+
136
+ # ������� �������� �������� ����� �������� ������ ��������� �
137
+ # ���������� ����������.
138
+ assert_raise( RuntimeError ) { attributes[ 0 ].default }
139
+ end
140
+
141
+ def test_single_attribute_with_default
142
+ vi = cpp_value_incapsulator( "cfg_t" ) do |c|
143
+ c.decl_file :script_relative =>
144
+ "test_single_attribute_with_default.hpp"
145
+ c.impl_file :script_relative =>
146
+ "test_single_attribute_with_default.cpp"
147
+ c.attr :name, "std::string", :default => "anonymous"
148
+ end
149
+
150
+ attributes = vi.get_attributes
151
+ assert_equal( 1, attributes.size )
152
+ assert_equal( :name, attributes[ 0 ].name )
153
+ assert_equal( "std::string", attributes[ 0 ].type )
154
+ assert_equal( "anonymous", attributes[ 0 ].default )
155
+ end
156
+
157
+ def test_multiple_attributes
158
+ vi = cpp_value_incapsulator( "cfg_t" ) do |c|
159
+ c.decl_file :script_relative => "test_multiple_attributes.hpp"
160
+ c.impl_file :script_relative => "test_multiple_attributes.cpp"
161
+ c.attr :listening_mbox, "std::string"
162
+ c.attr :interception_priority, "int", :default => 2
163
+ c.attr :low_watermark, "unsigned int"
164
+ c.attr :high_watermark, "unsigned int"
165
+ c.attr :cprov_high_watermark, "unsigned int"
166
+ c.attr :max_life_time, "unsigned int", :default => 60
167
+ c.attr :check_life_time_period, "unsigned int", :default => 5
168
+ end
169
+
170
+ attr_details = [
171
+ [ :listening_mbox, "std::string", nil ],
172
+ [ :interception_priority, "int", 2 ],
173
+ [ :low_watermark, "unsigned int", 0 ],
174
+ [ :high_watermark, "unsigned int", 0 ],
175
+ [ :cprov_high_watermark, "unsigned int", 0 ],
176
+ [ :max_life_time, "unsigned int", 60 ],
177
+ [ :check_life_time_period, "unsigned int", 5 ]
178
+ ]
179
+
180
+ assert_equal( attr_details,
181
+ vi.get_attributes.collect { |a|
182
+ default = a.has_default? ? a.default : nil
183
+ if nil == default &&
184
+ RuCodeGen::ClassAttribute.is_primitive_type(
185
+ a.type )
186
+ default = 0
187
+ end
188
+
189
+ [ a.name, a.type, default ]
190
+ } )
191
+ end
192
+ end
193
+