rice 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (166) hide show
  1. data/COPYING +23 -0
  2. data/Doxyfile +1253 -0
  3. data/Makefile.am +26 -0
  4. data/Makefile.in +736 -0
  5. data/README +881 -0
  6. data/README.mingw +8 -0
  7. data/bootstrap +8 -0
  8. data/config.guess +1535 -0
  9. data/config.sub +1644 -0
  10. data/configure +7310 -0
  11. data/configure.ac +48 -0
  12. data/depcomp +584 -0
  13. data/doxygen.ac +314 -0
  14. data/doxygen.am +186 -0
  15. data/install-sh +507 -0
  16. data/missing +367 -0
  17. data/post-autoconf.rb +22 -0
  18. data/post-automake.rb +28 -0
  19. data/rice/Address_Registration_Guard.hpp +7 -0
  20. data/rice/Address_Registration_Guard.ipp +34 -0
  21. data/rice/Address_Registration_Guard_defn.hpp +65 -0
  22. data/rice/Allocation_Strategies.hpp +37 -0
  23. data/rice/Array.hpp +220 -0
  24. data/rice/Array.ipp +262 -0
  25. data/rice/Builtin_Object.hpp +8 -0
  26. data/rice/Builtin_Object.ipp +50 -0
  27. data/rice/Builtin_Object_defn.hpp +51 -0
  28. data/rice/Class.cpp +57 -0
  29. data/rice/Class.hpp +8 -0
  30. data/rice/Class.ipp +4 -0
  31. data/rice/Class_defn.hpp +83 -0
  32. data/rice/Constructor.hpp +189 -0
  33. data/rice/Critical_Guard.hpp +34 -0
  34. data/rice/Critical_Guard.ipp +20 -0
  35. data/rice/Data_Object.hpp +127 -0
  36. data/rice/Data_Object.ipp +129 -0
  37. data/rice/Data_Type.cpp +21 -0
  38. data/rice/Data_Type.hpp +8 -0
  39. data/rice/Data_Type.ipp +227 -0
  40. data/rice/Data_Type_defn.hpp +219 -0
  41. data/rice/Data_Type_fwd.hpp +12 -0
  42. data/rice/Enum.hpp +118 -0
  43. data/rice/Enum.ipp +246 -0
  44. data/rice/Exception.cpp +59 -0
  45. data/rice/Exception.hpp +69 -0
  46. data/rice/Exception_Base.hpp +30 -0
  47. data/rice/Exception_Base.ipp +11 -0
  48. data/rice/Hash.hpp +206 -0
  49. data/rice/Hash.ipp +336 -0
  50. data/rice/Identifier.cpp +8 -0
  51. data/rice/Identifier.hpp +50 -0
  52. data/rice/Identifier.ipp +33 -0
  53. data/rice/Jump_Tag.hpp +24 -0
  54. data/rice/Makefile.am +112 -0
  55. data/rice/Makefile.in +675 -0
  56. data/rice/Module.cpp +75 -0
  57. data/rice/Module.hpp +8 -0
  58. data/rice/Module.ipp +6 -0
  59. data/rice/Module_defn.hpp +87 -0
  60. data/rice/Module_impl.hpp +237 -0
  61. data/rice/Module_impl.ipp +302 -0
  62. data/rice/Object.cpp +153 -0
  63. data/rice/Object.hpp +8 -0
  64. data/rice/Object.ipp +19 -0
  65. data/rice/Object_defn.hpp +183 -0
  66. data/rice/Require_Guard.hpp +21 -0
  67. data/rice/String.cpp +93 -0
  68. data/rice/String.hpp +88 -0
  69. data/rice/Struct.cpp +117 -0
  70. data/rice/Struct.hpp +162 -0
  71. data/rice/Struct.ipp +26 -0
  72. data/rice/Symbol.cpp +25 -0
  73. data/rice/Symbol.hpp +66 -0
  74. data/rice/Symbol.ipp +44 -0
  75. data/rice/VM.cpp +79 -0
  76. data/rice/VM.hpp +27 -0
  77. data/rice/config.hpp +23 -0
  78. data/rice/config.hpp.in +22 -0
  79. data/rice/detail/Auto_Function_Wrapper.hpp +719 -0
  80. data/rice/detail/Auto_Function_Wrapper.ipp +1354 -0
  81. data/rice/detail/Auto_Member_Function_Wrapper.hpp +685 -0
  82. data/rice/detail/Auto_Member_Function_Wrapper.ipp +1435 -0
  83. data/rice/detail/Caster.hpp +61 -0
  84. data/rice/detail/Exception_Handler.hpp +118 -0
  85. data/rice/detail/Iterator_Definer.hpp +98 -0
  86. data/rice/detail/Not_Copyable.hpp +25 -0
  87. data/rice/detail/Wrapped_Function.hpp +33 -0
  88. data/rice/detail/check_ruby_type.cpp +21 -0
  89. data/rice/detail/check_ruby_type.hpp +23 -0
  90. data/rice/detail/creation_funcs.hpp +45 -0
  91. data/rice/detail/creation_funcs.ipp +62 -0
  92. data/rice/detail/default_allocation_func.hpp +23 -0
  93. data/rice/detail/default_allocation_func.ipp +11 -0
  94. data/rice/detail/define_method_and_auto_wrap.hpp +27 -0
  95. data/rice/detail/define_method_and_auto_wrap.ipp +20 -0
  96. data/rice/detail/env.hpp +13 -0
  97. data/rice/detail/from_ruby.hpp +43 -0
  98. data/rice/detail/from_ruby.ipp +74 -0
  99. data/rice/detail/method_data.cpp +105 -0
  100. data/rice/detail/method_data.hpp +33 -0
  101. data/rice/detail/node.hpp +13 -0
  102. data/rice/detail/object_call.hpp +85 -0
  103. data/rice/detail/object_call.ipp +147 -0
  104. data/rice/detail/protect.cpp +27 -0
  105. data/rice/detail/protect.hpp +34 -0
  106. data/rice/detail/remove_const.hpp +21 -0
  107. data/rice/detail/ruby.hpp +85 -0
  108. data/rice/detail/rubysig.hpp +13 -0
  109. data/rice/detail/st.hpp +56 -0
  110. data/rice/detail/to_ruby.hpp +16 -0
  111. data/rice/detail/to_ruby.ipp +10 -0
  112. data/rice/detail/win32.hpp +16 -0
  113. data/rice/detail/wrap_function.hpp +288 -0
  114. data/rice/detail/wrap_function.ipp +473 -0
  115. data/rice/generate_code.rb +1092 -0
  116. data/rice/global_function.hpp +16 -0
  117. data/rice/global_function.ipp +11 -0
  118. data/rice/protect.hpp +91 -0
  119. data/rice/protect.ipp +803 -0
  120. data/rice/ruby_try_catch.hpp +86 -0
  121. data/rice/to_from_ruby.hpp +8 -0
  122. data/rice/to_from_ruby.ipp +299 -0
  123. data/rice/to_from_ruby_defn.hpp +71 -0
  124. data/ruby.ac +105 -0
  125. data/ruby/Makefile.am +1 -0
  126. data/ruby/Makefile.in +493 -0
  127. data/ruby/lib/Makefile.am +3 -0
  128. data/ruby/lib/Makefile.in +369 -0
  129. data/ruby/lib/mkmf-rice.rb.in +199 -0
  130. data/sample/Makefile.am +47 -0
  131. data/sample/Makefile.in +375 -0
  132. data/sample/enum/extconf.rb +3 -0
  133. data/sample/enum/sample_enum.cpp +54 -0
  134. data/sample/enum/test.rb +8 -0
  135. data/sample/inheritance/animals.cpp +98 -0
  136. data/sample/inheritance/extconf.rb +3 -0
  137. data/sample/inheritance/test.rb +7 -0
  138. data/sample/map/extconf.rb +3 -0
  139. data/sample/map/map.cpp +81 -0
  140. data/sample/map/test.rb +7 -0
  141. data/test/Makefile.am +44 -0
  142. data/test/Makefile.in +575 -0
  143. data/test/test_Address_Registration_Guard.cpp +43 -0
  144. data/test/test_Allocation_Strategies.cpp +77 -0
  145. data/test/test_Array.cpp +241 -0
  146. data/test/test_Builtin_Object.cpp +72 -0
  147. data/test/test_Class.cpp +350 -0
  148. data/test/test_Constructor.cpp +30 -0
  149. data/test/test_Critical_Guard.cpp +47 -0
  150. data/test/test_Data_Object.cpp +235 -0
  151. data/test/test_Enum.cpp +162 -0
  152. data/test/test_Exception.cpp +46 -0
  153. data/test/test_Hash.cpp +195 -0
  154. data/test/test_Identifier.cpp +70 -0
  155. data/test/test_Jump_Tag.cpp +17 -0
  156. data/test/test_Module.cpp +253 -0
  157. data/test/test_Object.cpp +148 -0
  158. data/test/test_String.cpp +94 -0
  159. data/test/test_Struct.cpp +192 -0
  160. data/test/test_Symbol.cpp +63 -0
  161. data/test/test_To_From_Ruby.cpp +281 -0
  162. data/test/test_VM.cpp +26 -0
  163. data/test/test_rice.rb +30 -0
  164. data/test/unittest.cpp +136 -0
  165. data/test/unittest.hpp +292 -0
  166. metadata +209 -0
@@ -0,0 +1,30 @@
1
+ #include "unittest.hpp"
2
+ #include "rice/Constructor.hpp"
3
+ #include "rice/Data_Type.hpp"
4
+ #include "rice/Constructor.hpp"
5
+
6
+ using namespace Rice;
7
+
8
+ TESTSUITE(Constructor);
9
+
10
+ namespace
11
+ {
12
+ class Default_Constructible
13
+ {
14
+ public:
15
+ Default_Constructible()
16
+ {
17
+ }
18
+ };
19
+ }
20
+
21
+ TESTCASE(default_constructor)
22
+ {
23
+ Data_Type<Default_Constructible> rb_cDefault_Constructible(
24
+ anonymous_class());
25
+ rb_cDefault_Constructible
26
+ .define_constructor(Constructor<Default_Constructible>());
27
+ Object o = rb_cDefault_Constructible.call("new");
28
+ ASSERT_EQUAL(rb_cDefault_Constructible, o.class_of());
29
+ }
30
+
@@ -0,0 +1,47 @@
1
+ #include "unittest.hpp"
2
+ #include "rice/Critical_Guard.hpp"
3
+ #include <stdexcept>
4
+
5
+ using namespace Rice;
6
+
7
+ TESTSUITE(Critical_Guard);
8
+
9
+ SETUP(Critical_Guard)
10
+ {
11
+ ruby_init();
12
+ }
13
+
14
+ TESTCASE(normal_path)
15
+ {
16
+ rb_thread_critical = 1;
17
+ {
18
+ Critical_Guard g;
19
+ ASSERT(rb_thread_critical);
20
+ }
21
+ ASSERT(!rb_thread_critical);
22
+ }
23
+
24
+ TESTCASE(unset_thread_critical_on_destruction)
25
+ {
26
+ rb_thread_critical = 1;
27
+ {
28
+ Critical_Guard g;
29
+ ASSERT(rb_thread_critical);
30
+ }
31
+ ASSERT(!rb_thread_critical);
32
+ }
33
+
34
+ TESTCASE(exception)
35
+ {
36
+ rb_thread_critical = 1;
37
+ try
38
+ {
39
+ Critical_Guard g;
40
+ throw std::runtime_error("testing");
41
+ }
42
+ catch(...)
43
+ {
44
+ }
45
+ ASSERT(!rb_thread_critical);
46
+ }
47
+
@@ -0,0 +1,235 @@
1
+ #include "unittest.hpp"
2
+ #include "rice/Data_Object.hpp"
3
+ #include "rice/Data_Type.hpp"
4
+ #include "rice/Exception.hpp"
5
+
6
+ using namespace Rice;
7
+
8
+ TESTSUITE(Data_Object);
9
+
10
+ namespace
11
+ {
12
+ struct Foo { Foo() : x_(42) { } int x_; };
13
+ }
14
+
15
+ SETUP(Data_Object)
16
+ {
17
+ ruby_init();
18
+
19
+ if(!Data_Type<Foo>::is_bound())
20
+ {
21
+ Class object(rb_cObject);
22
+ if(object.const_defined("Foo"))
23
+ {
24
+ object.remove_const("Foo");
25
+ }
26
+
27
+ define_class<Foo>("Foo");
28
+ }
29
+ }
30
+
31
+ TESTCASE(construct_from_pointer_with_defaults)
32
+ {
33
+ Data_Type<Foo> rb_cFoo;
34
+ Foo * foo = new Foo;
35
+ Data_Object<Foo> wrapped_foo(foo);
36
+ ASSERT_EQUAL(foo, wrapped_foo.get());
37
+ ASSERT_EQUAL(Data_Type<Foo>::klass(), wrapped_foo.class_of());
38
+ ASSERT_EQUAL(RUBY_DATA_FUNC(0), RDATA(wrapped_foo.value())->dmark);
39
+ ASSERT_EQUAL(
40
+ RUBY_DATA_FUNC(Default_Allocation_Strategy<Foo>::free),
41
+ RUBY_DATA_FUNC(RDATA(wrapped_foo.value())->dfree));
42
+ ASSERT_EQUAL(foo, DATA_PTR(wrapped_foo.value()));
43
+ }
44
+
45
+ TESTCASE(construct_from_pointer_and_klass)
46
+ {
47
+ Data_Type<Foo> rb_cFoo;
48
+ Foo * foo = new Foo;
49
+ Data_Object<Foo> wrapped_foo(foo, Data_Type<Foo>::klass());
50
+ ASSERT_EQUAL(foo, wrapped_foo.get());
51
+ ASSERT_EQUAL(Data_Type<Foo>::klass(), wrapped_foo.class_of());
52
+ ASSERT_EQUAL(RUBY_DATA_FUNC(0), RDATA(wrapped_foo.value())->dmark);
53
+ ASSERT_EQUAL(
54
+ RUBY_DATA_FUNC(Default_Allocation_Strategy<Foo>::free),
55
+ RUBY_DATA_FUNC(RDATA(wrapped_foo.value())->dfree));
56
+ ASSERT_EQUAL(foo, DATA_PTR(wrapped_foo.value()));
57
+ }
58
+
59
+ TESTCASE(construct_from_pointer_and_alternate_klass)
60
+ {
61
+ Data_Type<Foo> rb_cFoo;
62
+ Foo * foo = new Foo;
63
+ Data_Object<Foo> wrapped_foo(foo, rb_cObject);
64
+ ASSERT_EQUAL(foo, wrapped_foo.get());
65
+ ASSERT_EQUAL(rb_cObject, CLASS_OF(wrapped_foo.value()));
66
+ ASSERT_EQUAL(RUBY_DATA_FUNC(0), RDATA(wrapped_foo.value())->dmark);
67
+ ASSERT_EQUAL(
68
+ RUBY_DATA_FUNC(Default_Allocation_Strategy<Foo>::free),
69
+ RUBY_DATA_FUNC(RDATA(wrapped_foo.value())->dfree));
70
+ ASSERT_EQUAL(foo, DATA_PTR(wrapped_foo.value()));
71
+ }
72
+
73
+ namespace
74
+ {
75
+ void dummy_mark(Foo *)
76
+ {
77
+ }
78
+ }
79
+
80
+ TESTCASE(construct_from_pointer_and_klass_and_mark_function)
81
+ {
82
+ Data_Type<Foo> rb_cFoo;
83
+ Foo * foo = new Foo;
84
+ Data_Object<Foo> wrapped_foo(foo, rb_cFoo, dummy_mark);
85
+ ASSERT_EQUAL(foo, wrapped_foo.get());
86
+ ASSERT_EQUAL(Data_Type<Foo>::klass(), wrapped_foo.class_of());
87
+ ASSERT_EQUAL((void *)dummy_mark, RDATA(wrapped_foo.value())->dmark);
88
+ ASSERT_EQUAL(
89
+ RUBY_DATA_FUNC(Default_Allocation_Strategy<Foo>::free),
90
+ RUBY_DATA_FUNC(RDATA(wrapped_foo.value())->dfree));
91
+ ASSERT_EQUAL(foo, DATA_PTR(wrapped_foo.value()));
92
+ }
93
+
94
+ namespace
95
+ {
96
+ void my_free(Foo * f)
97
+ {
98
+ delete f;
99
+ }
100
+ }
101
+
102
+ TESTCASE(construct_from_pointer_and_klass_and_mark_and_free)
103
+ {
104
+ Data_Type<Foo> rb_cFoo;
105
+ Foo * foo = new Foo;
106
+ Data_Object<Foo> wrapped_foo(foo, rb_cFoo, dummy_mark, my_free);
107
+ ASSERT_EQUAL(foo, wrapped_foo.get());
108
+ ASSERT_EQUAL(Data_Type<Foo>::klass(), wrapped_foo.class_of());
109
+ ASSERT_EQUAL((void *)dummy_mark, RDATA(wrapped_foo.value())->dmark);
110
+ ASSERT_EQUAL(
111
+ RUBY_DATA_FUNC(my_free),
112
+ RUBY_DATA_FUNC(RDATA(wrapped_foo.value())->dfree));
113
+ ASSERT_EQUAL(foo, DATA_PTR(wrapped_foo.value()));
114
+ }
115
+
116
+ TESTCASE(construct_from_ruby_object)
117
+ {
118
+ Foo * foo = new Foo;
119
+ VALUE wrapped_foo = Data_Wrap_Struct(Data_Type<Foo>::klass(), 0, Default_Allocation_Strategy<Foo>::free, foo);
120
+ Data_Object<Foo> data_object_foo(wrapped_foo);
121
+ ASSERT_EQUAL(foo, data_object_foo.get());
122
+ ASSERT_EQUAL(Data_Type<Foo>::klass(), data_object_foo.class_of());
123
+ ASSERT_EQUAL(RDATA(wrapped_foo), RDATA(data_object_foo.value()));
124
+ ASSERT_EQUAL(RUBY_DATA_FUNC(0), RDATA(data_object_foo.value())->dmark);
125
+ ASSERT_EQUAL(
126
+ RUBY_DATA_FUNC(Default_Allocation_Strategy<Foo>::free),
127
+ RUBY_DATA_FUNC(RDATA(data_object_foo.value())->dfree));
128
+ ASSERT_EQUAL(foo, DATA_PTR(data_object_foo.value()));
129
+ }
130
+
131
+ TESTCASE(construct_from_ruby_object_and_class)
132
+ {
133
+ Data_Type<Foo> rb_cFoo;
134
+ Foo * foo = new Foo;
135
+ VALUE wrapped_foo = Data_Wrap_Struct(Data_Type<Foo>::klass(), 0, Default_Allocation_Strategy<Foo>::free, foo);
136
+ Data_Object<Foo> data_object_foo(wrapped_foo, rb_cFoo);
137
+ ASSERT_EQUAL(foo, data_object_foo.get());
138
+ ASSERT_EQUAL(Data_Type<Foo>::klass(), data_object_foo.class_of());
139
+ ASSERT_EQUAL(RDATA(wrapped_foo), RDATA(data_object_foo.value()));
140
+ ASSERT_EQUAL(RUBY_DATA_FUNC(0), RDATA(data_object_foo.value())->dmark);
141
+ ASSERT_EQUAL(
142
+ RUBY_DATA_FUNC(Default_Allocation_Strategy<Foo>::free),
143
+ RUBY_DATA_FUNC(RDATA(data_object_foo.value())->dfree));
144
+ ASSERT_EQUAL(foo, DATA_PTR(data_object_foo.value()));
145
+ }
146
+
147
+ TESTCASE(construct_from_ruby_object_and_wrong_class)
148
+ {
149
+ Foo * foo = new Foo;
150
+ Data_Type<Foo> rb_cFoo;
151
+ VALUE wrapped_foo = Data_Wrap_Struct(rb_cObject, 0, Default_Allocation_Strategy<Foo>::free, foo);
152
+ ASSERT_EXCEPTION_CHECK(
153
+ Exception,
154
+ Data_Object<Foo> data_object_foo(wrapped_foo, rb_cFoo),
155
+ ASSERT_EQUAL(
156
+ Object(rb_eTypeError),
157
+ Object(CLASS_OF(ex.value()))
158
+ )
159
+ );
160
+ }
161
+
162
+ TESTCASE(copy_construct)
163
+ {
164
+ Data_Type<Foo> rb_cFoo;
165
+ Foo * foo = new Foo;
166
+ VALUE wrapped_foo = Data_Wrap_Struct(Data_Type<Foo>::klass(), 0, Default_Allocation_Strategy<Foo>::free, foo);
167
+ Data_Object<Foo> orig_data_object_foo(wrapped_foo, rb_cFoo);
168
+ Data_Object<Foo> data_object_foo(orig_data_object_foo);
169
+ ASSERT_EQUAL(foo, data_object_foo.get());
170
+ ASSERT_EQUAL(Data_Type<Foo>::klass(), data_object_foo.class_of());
171
+ ASSERT_EQUAL(RDATA(wrapped_foo), RDATA(data_object_foo.value()));
172
+ ASSERT_EQUAL(RUBY_DATA_FUNC(0), RDATA(data_object_foo.value())->dmark);
173
+ ASSERT_EQUAL(
174
+ RUBY_DATA_FUNC(Default_Allocation_Strategy<Foo>::free),
175
+ RUBY_DATA_FUNC(RDATA(data_object_foo.value())->dfree));
176
+ ASSERT_EQUAL(foo, DATA_PTR(data_object_foo.value()));
177
+ }
178
+
179
+ TESTCASE(dereference)
180
+ {
181
+ Data_Type<Foo> rb_cFoo;
182
+ Foo * foo = new Foo;
183
+ Data_Object<Foo> wrapped_foo(foo);
184
+ ASSERT_EQUAL(foo, &*wrapped_foo);
185
+ }
186
+
187
+ TESTCASE(arrow)
188
+ {
189
+ Data_Type<Foo> rb_cFoo;
190
+ Foo * foo = new Foo;
191
+ Data_Object<Foo> wrapped_foo(foo);
192
+ ASSERT_EQUAL(42, foo->x_);
193
+ }
194
+
195
+ TESTCASE(get)
196
+ {
197
+ Data_Type<Foo> rb_cFoo;
198
+ Foo * foo = new Foo;
199
+ Data_Object<Foo> wrapped_foo(foo);
200
+ ASSERT_EQUAL(foo, wrapped_foo.get());
201
+ }
202
+
203
+ // TODO: swap
204
+
205
+ TESTCASE(to_ruby)
206
+ {
207
+ Data_Type<Foo> rb_cFoo;
208
+ Foo * foo = new Foo;
209
+ Data_Object<Foo> wrapped_foo(foo);
210
+ ASSERT_EQUAL(wrapped_foo.value(), to_ruby(wrapped_foo).value());
211
+ }
212
+
213
+ TESTCASE(from_ruby)
214
+ {
215
+ Data_Type<Foo> rb_cFoo;
216
+ Foo * foo = new Foo;
217
+ Data_Object<Foo> wrapped_foo(foo);
218
+ ASSERT_EQUAL(foo, from_ruby<Foo *>(wrapped_foo));
219
+ }
220
+
221
+ TESTCASE(from_ruby_const_ref)
222
+ {
223
+ Data_Type<Foo> rb_cFoo;
224
+ Foo * foo = new Foo;
225
+ Data_Object<Foo> wrapped_foo(foo);
226
+ ASSERT_EQUAL(foo->x_, from_ruby<Foo const &>(wrapped_foo).x_);
227
+ }
228
+
229
+ TESTCASE(from_ruby_copy)
230
+ {
231
+ Data_Type<Foo> rb_cFoo;
232
+ Foo * foo = new Foo;
233
+ Data_Object<Foo> wrapped_foo(foo);
234
+ ASSERT_EQUAL(foo->x_, from_ruby<Foo>(wrapped_foo).x_);
235
+ }
@@ -0,0 +1,162 @@
1
+ #include "unittest.hpp"
2
+ #include "rice/Enum.hpp"
3
+ #include "rice/Array.hpp"
4
+ #include "rice/String.hpp"
5
+ #include <iostream>
6
+
7
+ using namespace Rice;
8
+
9
+ TESTSUITE(Enum);
10
+
11
+ namespace
12
+ {
13
+ enum Color { RED, BLACK, GREEN };
14
+
15
+ Enum<Color> define_color_enum()
16
+ {
17
+ static Enum<Color> colors = define_enum<Color>("Color")
18
+ .define_value("RED", RED)
19
+ .define_value("BLACK", BLACK)
20
+ .define_value("GREEN", GREEN);
21
+ return colors;
22
+ }
23
+ }
24
+
25
+ SETUP(Enum)
26
+ {
27
+ ruby_init();
28
+ }
29
+
30
+ TESTCASE(copy_construct)
31
+ {
32
+ Enum<Color> rb_cColor(define_color_enum());
33
+ ASSERT_EQUAL(define_color_enum().value(), rb_cColor.value());
34
+ }
35
+
36
+ TESTCASE(assignment)
37
+ {
38
+ Enum<Color> rb_cColor;
39
+ rb_cColor = define_color_enum();
40
+ ASSERT_EQUAL(define_color_enum().value(), rb_cColor.value());
41
+ }
42
+
43
+ TESTCASE(each)
44
+ {
45
+ Enum<Color> rb_cColor = define_color_enum();
46
+ Array a = protect(rb_eval_string, "a = []; Color.each { |x| a << x }; a");
47
+ ASSERT_EQUAL(3u, a.size());
48
+ ASSERT_EQUAL(RED, from_ruby<Color>(a[0]));
49
+ ASSERT_EQUAL(BLACK, from_ruby<Color>(a[1]));
50
+ ASSERT_EQUAL(GREEN, from_ruby<Color>(a[2]));
51
+ }
52
+
53
+ TESTCASE(to_s)
54
+ {
55
+ Enum<Color> rb_cColor = define_color_enum();
56
+ ASSERT_EQUAL(String("RED"), String(protect(rb_eval_string, "Color::RED.to_s")));
57
+ ASSERT_EQUAL(String("BLACK"), String(protect(rb_eval_string, "Color::BLACK.to_s")));
58
+ ASSERT_EQUAL(String("GREEN"), String(protect(rb_eval_string, "Color::GREEN.to_s")));
59
+ }
60
+
61
+ TESTCASE(to_i)
62
+ {
63
+ Enum<Color> rb_cColor = define_color_enum();
64
+ ASSERT_EQUAL(to_ruby(int(RED)), Object(protect(rb_eval_string, "Color::RED.to_i")));
65
+ ASSERT_EQUAL(to_ruby(int(BLACK)), Object(protect(rb_eval_string, "Color::BLACK.to_i")));
66
+ ASSERT_EQUAL(to_ruby(int(GREEN)), Object(protect(rb_eval_string, "Color::GREEN.to_i")));
67
+ }
68
+
69
+ TESTCASE(inspect)
70
+ {
71
+ Enum<Color> rb_cColor = define_color_enum();
72
+ ASSERT_EQUAL(String("#<Color::RED>"), String(protect(rb_eval_string, "Color::RED.inspect")));
73
+ ASSERT_EQUAL(String("#<Color::BLACK>"), String(protect(rb_eval_string, "Color::BLACK.inspect")));
74
+ ASSERT_EQUAL(String("#<Color::GREEN>"), String(protect(rb_eval_string, "Color::GREEN.inspect")));
75
+ }
76
+
77
+ TESTCASE(compare)
78
+ {
79
+ Enum<Color> rb_cColor = define_color_enum();
80
+ ASSERT_EQUAL(to_ruby(-1), Object(protect(rb_eval_string, "Color::RED <=> Color::BLACK")));
81
+ ASSERT_EQUAL(to_ruby(1), Object(protect(rb_eval_string, "Color::GREEN <=> Color::RED")));
82
+ ASSERT_EQUAL(to_ruby(0), Object(protect(rb_eval_string, "Color::BLACK <=> Color::BLACK")));
83
+ }
84
+
85
+ TESTCASE(eql)
86
+ {
87
+ Enum<Color> rb_cColor = define_color_enum();
88
+ ASSERT_EQUAL(to_ruby(false), Object(protect(rb_eval_string, "Color::RED == Color::BLACK")));
89
+ ASSERT_EQUAL(to_ruby(true), Object(protect(rb_eval_string, "Color::GREEN == Color::GREEN")));
90
+ }
91
+
92
+ TESTCASE(invalid_to_s)
93
+ {
94
+ Enum<Color> rb_cColor = define_color_enum();
95
+ Data_Object<Color> invalid(new Color(static_cast<Color>(42)));
96
+ ASSERT_EQUAL(String("INVALID(42)"), invalid.to_s());
97
+ }
98
+
99
+ TESTCASE(invalid_to_i)
100
+ {
101
+ Enum<Color> rb_cColor = define_color_enum();
102
+ Data_Object<Color> invalid(new Color(static_cast<Color>(42)));
103
+ ASSERT_EQUAL(to_ruby(42), invalid.call("to_i"));
104
+ }
105
+
106
+ TESTCASE(invalid_inspect)
107
+ {
108
+ Enum<Color> rb_cColor = define_color_enum();
109
+ Data_Object<Color> invalid(new Color(static_cast<Color>(42)));
110
+ ASSERT_EQUAL(String("#<Color::INVALID(42)>"), invalid.inspect());
111
+ }
112
+
113
+ TESTCASE(invalid_compare)
114
+ {
115
+ Enum<Color> rb_cColor = define_color_enum();
116
+ Data_Object<Color> invalid(new Color(static_cast<Color>(42)));
117
+ Data_Object<Color> red(new Color(RED));
118
+ ASSERT_EQUAL(1, invalid.compare(red));
119
+ ASSERT_EQUAL(-1, red.compare(invalid));
120
+ ASSERT_EQUAL(0, invalid.compare(invalid));
121
+ }
122
+
123
+ TESTCASE(invalid_eql)
124
+ {
125
+ Enum<Color> rb_cColor = define_color_enum();
126
+ Data_Object<Color> invalid(new Color(static_cast<Color>(42)));
127
+ Data_Object<Color> red(new Color(RED));
128
+ ASSERT_EQUAL(false, invalid == red);
129
+ ASSERT_EQUAL(false, red == invalid);
130
+ ASSERT_EQUAL(true, invalid == invalid);
131
+ }
132
+
133
+ TESTCASE(different_objects_compare)
134
+ {
135
+ Enum<Color> rb_cColor = define_color_enum();
136
+ Data_Object<Color> red1(new Color(RED));
137
+ Data_Object<Color> red2(new Color(RED));
138
+ ASSERT_EQUAL(0, red1.compare(red2));
139
+ }
140
+
141
+ TESTCASE(different_objects_eql)
142
+ {
143
+ Enum<Color> rb_cColor = define_color_enum();
144
+ Data_Object<Color> red1(new Color(RED));
145
+ Data_Object<Color> red2(new Color(RED));
146
+ ASSERT_EQUAL(true, red1 == red2);
147
+ }
148
+
149
+ TESTCASE(hash)
150
+ {
151
+ Enum<Color> rb_cColor = define_color_enum();
152
+ Data_Object<Color> red(new Color(RED));
153
+ ASSERT_EQUAL(to_ruby(int(RED)), red.call("hash"));
154
+ }
155
+
156
+ TESTCASE(from_int)
157
+ {
158
+ Enum<Color> rb_cColor = define_color_enum();
159
+ Data_Object<Color> color(rb_cColor.call("from_int", int(RED)));
160
+ ASSERT_EQUAL(RED, *color);
161
+ }
162
+