rice-jdguyot 1.4.0.p1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (203) hide show
  1. data/COPYING +23 -0
  2. data/Doxyfile +1253 -0
  3. data/Makefile.am +26 -0
  4. data/Makefile.in +743 -0
  5. data/README +1119 -0
  6. data/README.mingw +8 -0
  7. data/Rakefile +33 -0
  8. data/aclocal.m4 +874 -0
  9. data/bootstrap +8 -0
  10. data/config.guess +1500 -0
  11. data/config.sub +1616 -0
  12. data/configure +7461 -0
  13. data/configure.ac +52 -0
  14. data/depcomp +584 -0
  15. data/doxygen.ac +314 -0
  16. data/doxygen.am +186 -0
  17. data/extconf.rb +34 -0
  18. data/install-sh +507 -0
  19. data/missing +367 -0
  20. data/post-autoconf.rb +22 -0
  21. data/post-automake.rb +28 -0
  22. data/rice/Address_Registration_Guard.cpp +22 -0
  23. data/rice/Address_Registration_Guard.hpp +7 -0
  24. data/rice/Address_Registration_Guard.ipp +37 -0
  25. data/rice/Address_Registration_Guard_defn.hpp +75 -0
  26. data/rice/Allocation_Strategies.hpp +37 -0
  27. data/rice/Arg.hpp +8 -0
  28. data/rice/Arg_impl.hpp +127 -0
  29. data/rice/Arg_operators.cpp +21 -0
  30. data/rice/Arg_operators.hpp +19 -0
  31. data/rice/Array.hpp +220 -0
  32. data/rice/Array.ipp +263 -0
  33. data/rice/Builtin_Object.hpp +8 -0
  34. data/rice/Builtin_Object.ipp +50 -0
  35. data/rice/Builtin_Object_defn.hpp +51 -0
  36. data/rice/Class.cpp +57 -0
  37. data/rice/Class.hpp +8 -0
  38. data/rice/Class.ipp +6 -0
  39. data/rice/Class_defn.hpp +83 -0
  40. data/rice/Constructor.hpp +367 -0
  41. data/rice/Critical_Guard.hpp +40 -0
  42. data/rice/Critical_Guard.ipp +26 -0
  43. data/rice/Data_Object.hpp +8 -0
  44. data/rice/Data_Object.ipp +133 -0
  45. data/rice/Data_Object_defn.hpp +132 -0
  46. data/rice/Data_Type.cpp +54 -0
  47. data/rice/Data_Type.hpp +8 -0
  48. data/rice/Data_Type.ipp +365 -0
  49. data/rice/Data_Type_defn.hpp +261 -0
  50. data/rice/Data_Type_fwd.hpp +12 -0
  51. data/rice/Director.cpp +13 -0
  52. data/rice/Director.hpp +39 -0
  53. data/rice/Enum.hpp +117 -0
  54. data/rice/Enum.ipp +246 -0
  55. data/rice/Exception.cpp +59 -0
  56. data/rice/Exception.hpp +9 -0
  57. data/rice/Exception_Base.hpp +8 -0
  58. data/rice/Exception_Base.ipp +13 -0
  59. data/rice/Exception_Base_defn.hpp +27 -0
  60. data/rice/Exception_defn.hpp +69 -0
  61. data/rice/Hash.hpp +210 -0
  62. data/rice/Hash.ipp +338 -0
  63. data/rice/Identifier.cpp +8 -0
  64. data/rice/Identifier.hpp +50 -0
  65. data/rice/Identifier.ipp +33 -0
  66. data/rice/Jump_Tag.hpp +24 -0
  67. data/rice/Makefile.am +130 -0
  68. data/rice/Makefile.in +716 -0
  69. data/rice/Module.cpp +84 -0
  70. data/rice/Module.hpp +8 -0
  71. data/rice/Module.ipp +6 -0
  72. data/rice/Module_defn.hpp +88 -0
  73. data/rice/Module_impl.hpp +281 -0
  74. data/rice/Module_impl.ipp +348 -0
  75. data/rice/Object.cpp +160 -0
  76. data/rice/Object.hpp +8 -0
  77. data/rice/Object.ipp +19 -0
  78. data/rice/Object_defn.hpp +191 -0
  79. data/rice/Require_Guard.hpp +21 -0
  80. data/rice/String.cpp +94 -0
  81. data/rice/String.hpp +89 -0
  82. data/rice/Struct.cpp +117 -0
  83. data/rice/Struct.hpp +162 -0
  84. data/rice/Struct.ipp +26 -0
  85. data/rice/Symbol.cpp +25 -0
  86. data/rice/Symbol.hpp +66 -0
  87. data/rice/Symbol.ipp +44 -0
  88. data/rice/VM.cpp +92 -0
  89. data/rice/VM.hpp +32 -0
  90. data/rice/config.hpp +41 -0
  91. data/rice/config.hpp.in +40 -0
  92. data/rice/detail/Arguments.hpp +118 -0
  93. data/rice/detail/Auto_Function_Wrapper.hpp +829 -0
  94. data/rice/detail/Auto_Function_Wrapper.ipp +3391 -0
  95. data/rice/detail/Auto_Member_Function_Wrapper.hpp +828 -0
  96. data/rice/detail/Auto_Member_Function_Wrapper.ipp +2503 -0
  97. data/rice/detail/Caster.hpp +103 -0
  98. data/rice/detail/Exception_Handler.hpp +8 -0
  99. data/rice/detail/Exception_Handler.ipp +68 -0
  100. data/rice/detail/Exception_Handler_defn.hpp +96 -0
  101. data/rice/detail/Iterator.hpp +93 -0
  102. data/rice/detail/Not_Copyable.hpp +25 -0
  103. data/rice/detail/Wrapped_Function.hpp +33 -0
  104. data/rice/detail/cfp.hpp +24 -0
  105. data/rice/detail/cfp.ipp +51 -0
  106. data/rice/detail/check_ruby_type.cpp +27 -0
  107. data/rice/detail/check_ruby_type.hpp +23 -0
  108. data/rice/detail/creation_funcs.hpp +37 -0
  109. data/rice/detail/creation_funcs.ipp +36 -0
  110. data/rice/detail/default_allocation_func.hpp +23 -0
  111. data/rice/detail/default_allocation_func.ipp +11 -0
  112. data/rice/detail/define_method_and_auto_wrap.hpp +31 -0
  113. data/rice/detail/define_method_and_auto_wrap.ipp +30 -0
  114. data/rice/detail/demangle.cpp +56 -0
  115. data/rice/detail/demangle.hpp +19 -0
  116. data/rice/detail/env.hpp +19 -0
  117. data/rice/detail/from_ruby.hpp +43 -0
  118. data/rice/detail/from_ruby.ipp +60 -0
  119. data/rice/detail/method_data.cpp +159 -0
  120. data/rice/detail/method_data.hpp +21 -0
  121. data/rice/detail/mininode.cpp +1220 -0
  122. data/rice/detail/mininode.hpp +320 -0
  123. data/rice/detail/node.hpp +13 -0
  124. data/rice/detail/object_call.hpp +68 -0
  125. data/rice/detail/object_call.ipp +131 -0
  126. data/rice/detail/protect.cpp +29 -0
  127. data/rice/detail/protect.hpp +34 -0
  128. data/rice/detail/ruby.hpp +93 -0
  129. data/rice/detail/ruby_version_code.hpp +6 -0
  130. data/rice/detail/ruby_version_code.hpp.in +6 -0
  131. data/rice/detail/rubysig.hpp +19 -0
  132. data/rice/detail/st.hpp +60 -0
  133. data/rice/detail/to_ruby.hpp +22 -0
  134. data/rice/detail/to_ruby.ipp +36 -0
  135. data/rice/detail/traits.hpp +43 -0
  136. data/rice/detail/win32.hpp +16 -0
  137. data/rice/detail/wrap_function.hpp +341 -0
  138. data/rice/detail/wrap_function.ipp +514 -0
  139. data/rice/global_function.hpp +33 -0
  140. data/rice/global_function.ipp +22 -0
  141. data/rice/protect.hpp +91 -0
  142. data/rice/protect.ipp +1133 -0
  143. data/rice/ruby_mark.hpp +13 -0
  144. data/rice/ruby_try_catch.hpp +86 -0
  145. data/rice/rubypp.rb +97 -0
  146. data/rice/to_from_ruby.hpp +8 -0
  147. data/rice/to_from_ruby.ipp +294 -0
  148. data/rice/to_from_ruby_defn.hpp +71 -0
  149. data/ruby/Makefile.am +1 -0
  150. data/ruby/Makefile.in +497 -0
  151. data/ruby/lib/Makefile.am +3 -0
  152. data/ruby/lib/Makefile.in +373 -0
  153. data/ruby/lib/mkmf-rice.rb.in +216 -0
  154. data/ruby/lib/version.rb +3 -0
  155. data/ruby.ac +136 -0
  156. data/sample/Makefile.am +47 -0
  157. data/sample/Makefile.in +379 -0
  158. data/sample/enum/extconf.rb +3 -0
  159. data/sample/enum/sample_enum.cpp +54 -0
  160. data/sample/enum/test.rb +8 -0
  161. data/sample/inheritance/animals.cpp +98 -0
  162. data/sample/inheritance/extconf.rb +3 -0
  163. data/sample/inheritance/test.rb +7 -0
  164. data/sample/map/extconf.rb +3 -0
  165. data/sample/map/map.cpp +81 -0
  166. data/sample/map/test.rb +7 -0
  167. data/test/Makefile.am +78 -0
  168. data/test/Makefile.in +728 -0
  169. data/test/ext/Makefile.am +43 -0
  170. data/test/ext/Makefile.in +375 -0
  171. data/test/ext/t1/Foo.hpp +10 -0
  172. data/test/ext/t1/extconf.rb +2 -0
  173. data/test/ext/t1/t1.cpp +15 -0
  174. data/test/ext/t2/extconf.rb +2 -0
  175. data/test/ext/t2/t2.cpp +11 -0
  176. data/test/test_Address_Registration_Guard.cpp +43 -0
  177. data/test/test_Allocation_Strategies.cpp +77 -0
  178. data/test/test_Array.cpp +241 -0
  179. data/test/test_Builtin_Object.cpp +72 -0
  180. data/test/test_Class.cpp +498 -0
  181. data/test/test_Constructor.cpp +128 -0
  182. data/test/test_Critical_Guard.cpp +51 -0
  183. data/test/test_Data_Object.cpp +275 -0
  184. data/test/test_Data_Type.cpp +348 -0
  185. data/test/test_Director.cpp +301 -0
  186. data/test/test_Enum.cpp +195 -0
  187. data/test/test_Exception.cpp +46 -0
  188. data/test/test_Hash.cpp +195 -0
  189. data/test/test_Identifier.cpp +70 -0
  190. data/test/test_Jump_Tag.cpp +17 -0
  191. data/test/test_Memory_Management.cpp +50 -0
  192. data/test/test_Module.cpp +481 -0
  193. data/test/test_Object.cpp +148 -0
  194. data/test/test_String.cpp +94 -0
  195. data/test/test_Struct.cpp +192 -0
  196. data/test/test_Symbol.cpp +63 -0
  197. data/test/test_To_From_Ruby.cpp +277 -0
  198. data/test/test_VM.cpp +26 -0
  199. data/test/test_global_functions.cpp +114 -0
  200. data/test/test_rice.rb +43 -0
  201. data/test/unittest.cpp +136 -0
  202. data/test/unittest.hpp +292 -0
  203. metadata +289 -0
@@ -0,0 +1,195 @@
1
+ #include "unittest.hpp"
2
+ #include "rice/Enum.hpp"
3
+ #include "rice/Array.hpp"
4
+ #include "rice/String.hpp"
5
+ #include "rice/Constructor.hpp"
6
+ #include <iostream>
7
+
8
+ using namespace Rice;
9
+
10
+ TESTSUITE(Enum);
11
+
12
+ namespace
13
+ {
14
+ enum Color { RED, BLACK, GREEN };
15
+
16
+ Enum<Color> define_color_enum()
17
+ {
18
+ static Enum<Color> colors = define_enum<Color>("Color")
19
+ .define_value("RED", RED)
20
+ .define_value("BLACK", BLACK)
21
+ .define_value("GREEN", GREEN);
22
+ return colors;
23
+ }
24
+ }
25
+
26
+ SETUP(Enum)
27
+ {
28
+ ruby_init();
29
+ }
30
+
31
+ TESTCASE(copy_construct)
32
+ {
33
+ Enum<Color> rb_cColor(define_color_enum());
34
+ ASSERT_EQUAL(define_color_enum().value(), rb_cColor.value());
35
+ }
36
+
37
+ TESTCASE(assignment)
38
+ {
39
+ Enum<Color> rb_cColor;
40
+ rb_cColor = define_color_enum();
41
+ ASSERT_EQUAL(define_color_enum().value(), rb_cColor.value());
42
+ }
43
+
44
+ TESTCASE(each)
45
+ {
46
+ Enum<Color> rb_cColor = define_color_enum();
47
+ Array a = protect(rb_eval_string, "a = []; Color.each { |x| a << x }; a");
48
+ ASSERT_EQUAL(3u, a.size());
49
+ ASSERT_EQUAL(RED, from_ruby<Color>(a[0]));
50
+ ASSERT_EQUAL(BLACK, from_ruby<Color>(a[1]));
51
+ ASSERT_EQUAL(GREEN, from_ruby<Color>(a[2]));
52
+ }
53
+
54
+ TESTCASE(to_s)
55
+ {
56
+ Enum<Color> rb_cColor = define_color_enum();
57
+ ASSERT_EQUAL(String("RED"), String(protect(rb_eval_string, "Color::RED.to_s")));
58
+ ASSERT_EQUAL(String("BLACK"), String(protect(rb_eval_string, "Color::BLACK.to_s")));
59
+ ASSERT_EQUAL(String("GREEN"), String(protect(rb_eval_string, "Color::GREEN.to_s")));
60
+ }
61
+
62
+ TESTCASE(to_i)
63
+ {
64
+ Enum<Color> rb_cColor = define_color_enum();
65
+ ASSERT_EQUAL(to_ruby(int(RED)), Object(protect(rb_eval_string, "Color::RED.to_i")));
66
+ ASSERT_EQUAL(to_ruby(int(BLACK)), Object(protect(rb_eval_string, "Color::BLACK.to_i")));
67
+ ASSERT_EQUAL(to_ruby(int(GREEN)), Object(protect(rb_eval_string, "Color::GREEN.to_i")));
68
+ }
69
+
70
+ TESTCASE(inspect)
71
+ {
72
+ Enum<Color> rb_cColor = define_color_enum();
73
+ ASSERT_EQUAL(String("#<Color::RED>"), String(protect(rb_eval_string, "Color::RED.inspect")));
74
+ ASSERT_EQUAL(String("#<Color::BLACK>"), String(protect(rb_eval_string, "Color::BLACK.inspect")));
75
+ ASSERT_EQUAL(String("#<Color::GREEN>"), String(protect(rb_eval_string, "Color::GREEN.inspect")));
76
+ }
77
+
78
+ TESTCASE(compare)
79
+ {
80
+ Enum<Color> rb_cColor = define_color_enum();
81
+ ASSERT_EQUAL(to_ruby(-1), Object(protect(rb_eval_string, "Color::RED <=> Color::BLACK")));
82
+ ASSERT_EQUAL(to_ruby(1), Object(protect(rb_eval_string, "Color::GREEN <=> Color::RED")));
83
+ ASSERT_EQUAL(to_ruby(0), Object(protect(rb_eval_string, "Color::BLACK <=> Color::BLACK")));
84
+ }
85
+
86
+ TESTCASE(eql)
87
+ {
88
+ Enum<Color> rb_cColor = define_color_enum();
89
+ ASSERT_EQUAL(to_ruby(false), Object(protect(rb_eval_string, "Color::RED == Color::BLACK")));
90
+ ASSERT_EQUAL(to_ruby(true), Object(protect(rb_eval_string, "Color::GREEN == Color::GREEN")));
91
+ }
92
+
93
+ TESTCASE(invalid_to_s)
94
+ {
95
+ Enum<Color> rb_cColor = define_color_enum();
96
+ Data_Object<Color> invalid(new Color(static_cast<Color>(42)));
97
+ ASSERT_EQUAL(String("INVALID(42)"), invalid.to_s());
98
+ }
99
+
100
+ TESTCASE(invalid_to_i)
101
+ {
102
+ Enum<Color> rb_cColor = define_color_enum();
103
+ Data_Object<Color> invalid(new Color(static_cast<Color>(42)));
104
+ ASSERT_EQUAL(to_ruby(42), invalid.call("to_i"));
105
+ }
106
+
107
+ TESTCASE(invalid_inspect)
108
+ {
109
+ Enum<Color> rb_cColor = define_color_enum();
110
+ Data_Object<Color> invalid(new Color(static_cast<Color>(42)));
111
+ ASSERT_EQUAL(String("#<Color::INVALID(42)>"), invalid.inspect());
112
+ }
113
+
114
+ TESTCASE(invalid_compare)
115
+ {
116
+ Enum<Color> rb_cColor = define_color_enum();
117
+ Data_Object<Color> invalid(new Color(static_cast<Color>(42)));
118
+ Data_Object<Color> red(new Color(RED));
119
+ ASSERT_EQUAL(1, invalid.compare(red));
120
+ ASSERT_EQUAL(-1, red.compare(invalid));
121
+ ASSERT_EQUAL(0, invalid.compare(invalid));
122
+ }
123
+
124
+ TESTCASE(invalid_eql)
125
+ {
126
+ Enum<Color> rb_cColor = define_color_enum();
127
+ Data_Object<Color> invalid(new Color(static_cast<Color>(42)));
128
+ Data_Object<Color> red(new Color(RED));
129
+ ASSERT_EQUAL(false, invalid == red);
130
+ ASSERT_EQUAL(false, red == invalid);
131
+ ASSERT_EQUAL(true, invalid == invalid);
132
+ }
133
+
134
+ TESTCASE(different_objects_compare)
135
+ {
136
+ Enum<Color> rb_cColor = define_color_enum();
137
+ Data_Object<Color> red1(new Color(RED));
138
+ Data_Object<Color> red2(new Color(RED));
139
+ ASSERT_EQUAL(0, red1.compare(red2));
140
+ }
141
+
142
+ TESTCASE(different_objects_eql)
143
+ {
144
+ Enum<Color> rb_cColor = define_color_enum();
145
+ Data_Object<Color> red1(new Color(RED));
146
+ Data_Object<Color> red2(new Color(RED));
147
+ ASSERT_EQUAL(true, red1 == red2);
148
+ }
149
+
150
+ /*
151
+ TESTCASE(hash)
152
+ {
153
+ Enum<Color> rb_cColor = define_color_enum();
154
+ Data_Object<Color> red(new Color(RED));
155
+ ASSERT_EQUAL(to_ruby(int(RED)), red.call("hash"));
156
+ }
157
+ */
158
+
159
+ TESTCASE(from_int)
160
+ {
161
+ Enum<Color> rb_cColor = define_color_enum();
162
+ Data_Object<Color> color(rb_cColor.call("from_int", int(RED)));
163
+ ASSERT_EQUAL(RED, *color);
164
+ }
165
+
166
+ namespace
167
+ {
168
+ class Inner
169
+ {
170
+ public:
171
+ enum Props
172
+ {
173
+ VALUE1,
174
+ VALUE2,
175
+ VALUE3
176
+ };
177
+ };
178
+ }
179
+
180
+ TESTCASE(nested_enums)
181
+ {
182
+ {
183
+ Data_Type<Inner> inner = define_class<Inner>("Inner");
184
+ define_enum<Inner::Props>("Props", inner)
185
+ .define_value("VALUE1", Inner::VALUE1)
186
+ .define_value("VALUE2", Inner::VALUE2)
187
+ .define_value("VALUE3", Inner::VALUE3);
188
+ inner.define_constructor(Constructor<Inner>());
189
+ }
190
+
191
+ ASSERT_EQUAL(to_ruby(int(0)), Object(protect(rb_eval_string, "Inner::Props::VALUE1.to_i")));
192
+ ASSERT_EQUAL(to_ruby(int(1)), Object(protect(rb_eval_string, "Inner::Props::VALUE2.to_i")));
193
+ ASSERT_EQUAL(to_ruby(int(2)), Object(protect(rb_eval_string, "Inner::Props::VALUE3.to_i")));
194
+ }
195
+
@@ -0,0 +1,46 @@
1
+ #include "unittest.hpp"
2
+ #include "rice/Exception.hpp"
3
+ #include "rice/String.hpp"
4
+
5
+ using namespace Rice;
6
+
7
+ TESTSUITE(Exception);
8
+
9
+ SETUP(Exception)
10
+ {
11
+ ruby_init();
12
+ }
13
+
14
+ TESTCASE(construct_from_exception_object)
15
+ {
16
+ VALUE v = protect(rb_exc_new2, rb_eRuntimeError, "foo");
17
+ Exception ex(v);
18
+ ASSERT_EQUAL(ex.value(), v);
19
+ }
20
+
21
+ TESTCASE(copy_construct)
22
+ {
23
+ VALUE v = protect(rb_exc_new2, rb_eRuntimeError, "foo");
24
+ Exception ex1(v);
25
+ Exception ex2(v);
26
+ ASSERT_EQUAL(ex2.value(), v);
27
+ }
28
+
29
+ TESTCASE(construct_from_format_string)
30
+ {
31
+ Exception ex(rb_eRuntimeError, "%s", "foo");
32
+ ASSERT_EQUAL(ex.class_of(), Object(rb_eRuntimeError));
33
+ }
34
+
35
+ TESTCASE(message)
36
+ {
37
+ Exception ex(rb_eRuntimeError, "%s", "foo");
38
+ ASSERT_EQUAL(String("foo"), ex.message());
39
+ }
40
+
41
+ TESTCASE(what)
42
+ {
43
+ Exception ex(rb_eRuntimeError, "%s", "foo");
44
+ ASSERT_EQUAL("foo", ex.what());
45
+ }
46
+
@@ -0,0 +1,195 @@
1
+ #include "unittest.hpp"
2
+ #include "rice/Hash.hpp"
3
+ #include <vector>
4
+ #include <map>
5
+ #include <algorithm>
6
+
7
+ using namespace Rice;
8
+
9
+ TESTSUITE(Hash);
10
+
11
+ SETUP(Hash)
12
+ {
13
+ ruby_init();
14
+ }
15
+
16
+ TESTCASE(default_construct)
17
+ {
18
+ Hash h;
19
+ ASSERT_EQUAL(T_HASH, rb_type(h));
20
+ ASSERT_EQUAL(0, RHASH_TBL(h.value())->num_entries);
21
+ }
22
+
23
+ TESTCASE(construct_from_object)
24
+ {
25
+ Object o(rb_hash_new());
26
+ Hash h(o);
27
+ ASSERT_EQUAL(T_HASH, rb_type(h));
28
+ ASSERT_EQUAL(0, RHASH_TBL(h.value())->num_entries);
29
+ }
30
+
31
+ TESTCASE(construct_from_value)
32
+ {
33
+ VALUE v(rb_hash_new());
34
+ Hash h(v);
35
+ ASSERT_EQUAL(T_HASH, rb_type(h));
36
+ ASSERT_EQUAL(0, RHASH_TBL(h.value())->num_entries);
37
+ }
38
+
39
+ TESTCASE(copy_construct)
40
+ {
41
+ Hash h;
42
+ Hash h2(h);
43
+ ASSERT_EQUAL(h.value(), h2.value());
44
+ }
45
+
46
+ TESTCASE(assignment)
47
+ {
48
+ Hash h;
49
+ Hash h2;
50
+ h = h2;
51
+ }
52
+
53
+ TESTCASE(size)
54
+ {
55
+ Hash h;
56
+ ASSERT_EQUAL(0u, h.size());
57
+ h[1] = 5;
58
+ ASSERT_EQUAL(1u, h.size());
59
+ h[6] = 9;
60
+ ASSERT_EQUAL(2u, h.size());
61
+ h[42] = 42;
62
+ ASSERT_EQUAL(3u, h.size());
63
+ h[6] = 1;
64
+ ASSERT_EQUAL(3u, h.size());
65
+ }
66
+
67
+ TESTCASE(bracket)
68
+ {
69
+ Hash h;
70
+ h[1] = 5;
71
+ h[6] = 9;
72
+ h[42] = 42;
73
+ h[6] = 1;
74
+ ASSERT_EQUAL(to_ruby(5), Object(h[1]));
75
+ ASSERT_EQUAL(to_ruby(42), Object(h[42]));
76
+ ASSERT_EQUAL(to_ruby(1), Object(h[6]));
77
+ }
78
+
79
+ TESTCASE(get)
80
+ {
81
+ Hash h;
82
+ h[1] = 5;
83
+ h[6] = 9;
84
+ h[42] = 42;
85
+ h[6] = 1;
86
+ ASSERT_EQUAL(5, h.get<int>(1));
87
+ ASSERT_EQUAL(42, h.get<int>(42));
88
+ ASSERT_EQUAL(1, h.get<int>(6));
89
+ }
90
+
91
+ TESTCASE(construct_vector_from_hash_iterators)
92
+ {
93
+ Hash h;
94
+ h[1] = 5;
95
+ h[6] = 9;
96
+ h[42] = 42;
97
+ h[6] = 1;
98
+ std::vector<Hash::Entry> v(h.begin(), h.end());
99
+ std::sort(v.begin(), v.end());
100
+ ASSERT_EQUAL(3u, v.size());
101
+ ASSERT_EQUAL(v[0].key, to_ruby(1));
102
+ ASSERT_EQUAL(v[1].key, to_ruby(6));
103
+ ASSERT_EQUAL(v[2].key, to_ruby(42));
104
+ ASSERT_EQUAL(&v[0].key, &v[0].first);
105
+ ASSERT_EQUAL(&v[1].key, &v[1].first);
106
+ ASSERT_EQUAL(&v[2].key, &v[2].first);
107
+ ASSERT_EQUAL(v[0].value, to_ruby(5));
108
+ ASSERT_EQUAL(v[1].value, to_ruby(1));
109
+ ASSERT_EQUAL(v[2].value, to_ruby(42));
110
+ ASSERT_EQUAL(&v[0].value, &v[0].second);
111
+ ASSERT_EQUAL(&v[1].value, &v[1].second);
112
+ ASSERT_EQUAL(&v[2].value, &v[2].second);
113
+ }
114
+
115
+ TESTCASE(iterate)
116
+ {
117
+ Hash h;
118
+ h[1] = 5;
119
+ h[6] = 9;
120
+ h[42] = 42;
121
+ h[6] = 1;
122
+ std::vector<Hash::Entry> v;
123
+ Hash::iterator it = h.begin();
124
+ Hash::iterator end = h.end();
125
+ for(; it != end; ++it)
126
+ {
127
+ v.push_back(*it);
128
+ }
129
+ std::sort(v.begin(), v.end());
130
+ ASSERT_EQUAL(3u, v.size());
131
+ ASSERT_EQUAL(v[0].key, to_ruby(1));
132
+ ASSERT_EQUAL(v[1].key, to_ruby(6));
133
+ ASSERT_EQUAL(v[2].key, to_ruby(42));
134
+ ASSERT_EQUAL(&v[0].key, &v[0].first);
135
+ ASSERT_EQUAL(&v[1].key, &v[1].first);
136
+ ASSERT_EQUAL(&v[2].key, &v[2].first);
137
+ ASSERT_EQUAL(v[0].value, to_ruby(5));
138
+ ASSERT_EQUAL(v[1].value, to_ruby(1));
139
+ ASSERT_EQUAL(v[2].value, to_ruby(42));
140
+ ASSERT_EQUAL(&v[0].value, &v[0].second);
141
+ ASSERT_EQUAL(&v[1].value, &v[1].second);
142
+ ASSERT_EQUAL(&v[2].value, &v[2].second);
143
+ }
144
+
145
+ TESTCASE(const_iterate)
146
+ {
147
+ Hash h;
148
+ h[1] = 5;
149
+ h[6] = 9;
150
+ h[42] = 42;
151
+ h[6] = 1;
152
+ std::vector<Hash::Entry> v;
153
+ Hash::const_iterator it = h.begin();
154
+ Hash::const_iterator end = h.end();
155
+ for(; it != end; ++it)
156
+ {
157
+ v.push_back(*it);
158
+ }
159
+ std::sort(v.begin(), v.end());
160
+ ASSERT_EQUAL(3u, v.size());
161
+ ASSERT_EQUAL(v[0].key, to_ruby(1));
162
+ ASSERT_EQUAL(v[1].key, to_ruby(6));
163
+ ASSERT_EQUAL(v[2].key, to_ruby(42));
164
+ ASSERT_EQUAL(&v[0].key, &v[0].first);
165
+ ASSERT_EQUAL(&v[1].key, &v[1].first);
166
+ ASSERT_EQUAL(&v[2].key, &v[2].first);
167
+ ASSERT_EQUAL(v[0].value, to_ruby(5));
168
+ ASSERT_EQUAL(v[1].value, to_ruby(1));
169
+ ASSERT_EQUAL(v[2].value, to_ruby(42));
170
+ ASSERT_EQUAL(&v[0].value, &v[0].value);
171
+ ASSERT_EQUAL(&v[1].value, &v[1].value);
172
+ ASSERT_EQUAL(&v[2].value, &v[2].value);
173
+ }
174
+
175
+ TESTCASE(iterate_and_change)
176
+ {
177
+ Hash h;
178
+ h[1] = 5;
179
+ h[6] = 9;
180
+ h[42] = 42;
181
+ h[6] = 1;
182
+ Hash::const_iterator it = h.begin();
183
+ Hash::const_iterator end = h.end();
184
+ std::map<int, int> m;
185
+ for(int j = 0; it != end; ++j, ++it)
186
+ {
187
+ it->second = j;
188
+ m[from_ruby<int>(it->first)] = j;
189
+ }
190
+ ASSERT_EQUAL(3u, m.size());
191
+ ASSERT_EQUAL(to_ruby(m[1]), h[1]);
192
+ ASSERT_EQUAL(to_ruby(m[6]), h[6]);
193
+ ASSERT_EQUAL(to_ruby(m[42]), h[42]);
194
+ }
195
+
@@ -0,0 +1,70 @@
1
+ #include "unittest.hpp"
2
+ #include "rice/Identifier.hpp"
3
+ #include "rice/Symbol.hpp"
4
+
5
+ using namespace Rice;
6
+
7
+ TESTSUITE(Identifier);
8
+
9
+ SETUP(Identifier)
10
+ {
11
+ ruby_init();
12
+ }
13
+
14
+ TESTCASE(construct_from_id)
15
+ {
16
+ ID id = rb_intern("foo");
17
+ Identifier identifier(id);
18
+ ASSERT_EQUAL(id, identifier.id());
19
+ }
20
+
21
+ TESTCASE(construct_from_symbol)
22
+ {
23
+ Symbol symbol("FOO");
24
+ Identifier identifier(symbol);
25
+ ASSERT_EQUAL(rb_intern("FOO"), identifier.id());
26
+ }
27
+
28
+ TESTCASE(construct_from_c_string)
29
+ {
30
+ Identifier identifier("Foo");
31
+ ASSERT_EQUAL(rb_intern("Foo"), identifier.id());
32
+ }
33
+
34
+ TESTCASE(default_construct)
35
+ {
36
+ Identifier identifier;
37
+ ASSERT_EQUAL(rb_intern(""), identifier.id());
38
+ }
39
+
40
+ TESTCASE(copy_construct)
41
+ {
42
+ Identifier identifier1("Foo");
43
+ Identifier identifier2(identifier1);
44
+ ASSERT_EQUAL(rb_intern("Foo"), identifier2.id());
45
+ }
46
+
47
+ TESTCASE(c_str)
48
+ {
49
+ Identifier identifier("Foo");
50
+ ASSERT_EQUAL("Foo", identifier.c_str());
51
+ }
52
+
53
+ TESTCASE(str)
54
+ {
55
+ Identifier identifier("Foo");
56
+ ASSERT_EQUAL(std::string("Foo"), identifier.str());
57
+ }
58
+
59
+ TESTCASE(implicit_conversion_to_id)
60
+ {
61
+ Identifier identifier("Foo");
62
+ ASSERT_EQUAL(rb_intern("Foo"), static_cast<ID>(identifier));
63
+ }
64
+
65
+ TESTCASE(to_sym)
66
+ {
67
+ Identifier identifier("Foo");
68
+ ASSERT_EQUAL(Symbol("Foo"), Symbol(identifier.to_sym()));
69
+ }
70
+