rice 4.6.1 → 4.7.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +31 -0
- data/CMakeLists.txt +0 -4
- data/Rakefile +2 -8
- data/bin/rice-doc.rb +212 -0
- data/bin/rice-rbs.rb +93 -0
- data/include/rice/rice.hpp +4972 -4015
- data/include/rice/stl.hpp +822 -294
- data/lib/rice/doc/cpp_reference.rb +166 -0
- data/lib/rice/doc/doxygen.rb +294 -0
- data/lib/rice/doc/mkdocs.rb +298 -0
- data/lib/rice/doc/rice.rb +29 -0
- data/lib/rice/doc/ruby.rb +37 -0
- data/lib/rice/doc.rb +5 -0
- data/lib/{make_rice_headers.rb → rice/make_rice_headers.rb} +3 -0
- data/lib/rice/native.rb +18 -0
- data/lib/rice/native_registry.rb +21 -0
- data/lib/rice/parameter.rb +7 -0
- data/lib/rice/rbs.rb +104 -0
- data/lib/rice/version.rb +1 -1
- data/lib/rice.rb +4 -0
- data/lib/rubygems/cmake_builder.rb +24 -27
- data/rice/Arg.hpp +4 -4
- data/rice/Arg.ipp +4 -4
- data/rice/Buffer.hpp +32 -28
- data/rice/Buffer.ipp +306 -178
- data/rice/Data_Object.ipp +101 -82
- data/rice/Data_Type.hpp +5 -7
- data/rice/Data_Type.ipp +48 -29
- data/rice/Enum.ipp +15 -21
- data/rice/Function.hpp +17 -0
- data/rice/Function.ipp +13 -0
- data/rice/Pointer.hpp +15 -0
- data/rice/Pointer.ipp +49 -0
- data/rice/Return.hpp +1 -1
- data/rice/Return.ipp +2 -2
- data/rice/api.hpp +30 -0
- data/rice/cpp_api/Array.hpp +2 -2
- data/rice/cpp_api/Array.ipp +50 -5
- data/rice/cpp_api/Class.hpp +0 -5
- data/rice/cpp_api/Class.ipp +19 -0
- data/rice/cpp_api/Hash.ipp +20 -0
- data/rice/cpp_api/Module.hpp +6 -3
- data/rice/cpp_api/Module.ipp +49 -11
- data/rice/cpp_api/Object.ipp +31 -2
- data/rice/cpp_api/String.hpp +1 -2
- data/rice/cpp_api/String.ipp +21 -1
- data/rice/cpp_api/Struct.ipp +5 -0
- data/rice/cpp_api/Symbol.ipp +34 -0
- data/rice/cpp_api/shared_methods.hpp +12 -12
- data/rice/detail/MethodInfo.hpp +4 -2
- data/rice/detail/MethodInfo.ipp +19 -3
- data/rice/detail/ModuleRegistry.hpp +18 -0
- data/rice/detail/ModuleRegistry.ipp +25 -0
- data/rice/detail/Native.hpp +45 -2
- data/rice/detail/Native.ipp +196 -2
- data/rice/detail/NativeAttributeGet.hpp +9 -4
- data/rice/detail/NativeAttributeGet.ipp +65 -11
- data/rice/detail/NativeAttributeSet.hpp +4 -0
- data/rice/detail/NativeAttributeSet.ipp +30 -2
- data/rice/detail/NativeCallbackFFI.ipp +2 -2
- data/rice/detail/NativeCallbackSimple.ipp +1 -1
- data/rice/detail/NativeFunction.hpp +11 -49
- data/rice/detail/NativeFunction.ipp +82 -379
- data/rice/detail/NativeInvoker.hpp +74 -0
- data/rice/detail/NativeInvoker.ipp +197 -0
- data/rice/detail/NativeIterator.hpp +4 -0
- data/rice/detail/NativeIterator.ipp +19 -0
- data/rice/detail/NativeMethod.hpp +97 -0
- data/rice/detail/NativeMethod.ipp +332 -0
- data/rice/detail/NativeProc.hpp +51 -0
- data/rice/detail/NativeProc.ipp +133 -0
- data/rice/detail/NativeRegistry.hpp +8 -0
- data/rice/detail/NativeRegistry.ipp +27 -0
- data/rice/detail/Parameter.hpp +47 -0
- data/rice/detail/Parameter.ipp +105 -0
- data/rice/detail/Proc.ipp +14 -13
- data/rice/detail/Registries.hpp +1 -0
- data/rice/detail/RubyType.hpp +0 -2
- data/rice/detail/RubyType.ipp +15 -33
- data/rice/detail/Type.hpp +44 -8
- data/rice/detail/Type.ipp +151 -49
- data/rice/detail/TypeRegistry.hpp +3 -0
- data/rice/detail/TypeRegistry.ipp +17 -27
- data/rice/detail/Types.ipp +430 -0
- data/rice/detail/Wrapper.hpp +12 -0
- data/rice/detail/Wrapper.ipp +45 -2
- data/rice/detail/from_ruby.ipp +567 -1073
- data/rice/detail/ruby.hpp +1 -0
- data/rice/detail/to_ruby.ipp +4 -635
- data/rice/libc/file.ipp +3 -6
- data/rice/rice.hpp +22 -12
- data/rice/rice_api/Arg.hpp +7 -0
- data/rice/rice_api/Arg.ipp +9 -0
- data/rice/rice_api/ModuleRegistry.hpp +7 -0
- data/rice/rice_api/ModuleRegistry.ipp +10 -0
- data/rice/rice_api/Native.hpp +7 -0
- data/rice/rice_api/Native.ipp +52 -0
- data/rice/rice_api/NativeRegistry.hpp +7 -0
- data/rice/rice_api/NativeRegistry.ipp +21 -0
- data/rice/rice_api/Parameter.hpp +7 -0
- data/rice/rice_api/Parameter.ipp +11 -0
- data/rice/rice_api/Registries.hpp +6 -0
- data/rice/rice_api/Registries.ipp +12 -0
- data/rice/rice_api/TypeRegistry.hpp +7 -0
- data/rice/rice_api/TypeRegistry.ipp +10 -0
- data/rice/stl/complex.ipp +35 -0
- data/rice/stl/exception.ipp +20 -7
- data/rice/stl/filesystem.hpp +6 -0
- data/rice/stl/filesystem.ipp +34 -0
- data/rice/stl/map.ipp +13 -21
- data/rice/stl/monostate.ipp +37 -1
- data/rice/stl/multimap.ipp +17 -24
- data/rice/stl/optional.ipp +47 -2
- data/rice/stl/pair.ipp +23 -58
- data/rice/stl/reference_wrapper.ipp +22 -1
- data/rice/stl/set.ipp +17 -9
- data/rice/stl/shared_ptr.ipp +44 -17
- data/rice/stl/string.ipp +175 -7
- data/rice/stl/string_view.ipp +5 -0
- data/rice/stl/tuple.ipp +38 -9
- data/rice/stl/unique_ptr.ipp +46 -2
- data/rice/stl/unordered_map.ipp +13 -21
- data/rice/stl/variant.ipp +47 -11
- data/rice/stl/vector.ipp +183 -104
- data/rice/stl.hpp +1 -0
- data/rice/traits/function_traits.hpp +2 -2
- data/rice/traits/method_traits.hpp +5 -16
- data/rice/traits/rice_traits.hpp +24 -4
- data/rice.gemspec +11 -22
- data/test/embed_ruby.cpp +0 -3
- data/test/test_Array.cpp +38 -38
- data/test/test_Attribute.cpp +187 -2
- data/test/test_Buffer.cpp +302 -26
- data/test/test_Callback.cpp +2 -3
- data/test/test_Class.cpp +5 -5
- data/test/test_Data_Object.cpp +0 -55
- data/test/test_Data_Type.cpp +19 -30
- data/test/test_Enum.cpp +4 -46
- data/test/test_From_Ruby.cpp +88 -81
- data/test/test_GVL.cpp +109 -0
- data/test/test_Iterator.cpp +1 -1
- data/test/test_Keep_Alive_No_Wrapper.cpp +5 -3
- data/test/test_Module.cpp +8 -9
- data/test/test_Object.cpp +1 -1
- data/test/test_Overloads.cpp +3 -3
- data/test/test_Stl_Map.cpp +8 -8
- data/test/test_Stl_Multimap.cpp +4 -4
- data/test/test_Stl_Pair.cpp +5 -3
- data/test/test_Stl_SharedPtr.cpp +24 -12
- data/test/test_Stl_Tuple.cpp +1 -1
- data/test/test_Stl_UniquePtr.cpp +8 -0
- data/test/test_Stl_Unordered_Map.cpp +9 -9
- data/test/test_Stl_Variant.cpp +9 -3
- data/test/test_Stl_Vector.cpp +118 -13
- data/test/test_To_Ruby.cpp +35 -28
- data/test/test_Type.cpp +256 -53
- data/test/unittest.hpp +35 -0
- metadata +66 -34
- data/rice/Init.hpp +0 -8
- data/rice/Init.ipp +0 -8
- data/rice/detail/RubyFunction.hpp +0 -31
- data/rice/detail/RubyFunction.ipp +0 -77
- data/sample/callbacks/extconf.rb +0 -5
- data/sample/callbacks/sample_callbacks.cpp +0 -35
- data/sample/callbacks/test.rb +0 -28
- data/sample/enum/extconf.rb +0 -5
- data/sample/enum/sample_enum.cpp +0 -40
- data/sample/enum/test.rb +0 -8
- data/sample/inheritance/animals.cpp +0 -82
- data/sample/inheritance/extconf.rb +0 -5
- data/sample/inheritance/test.rb +0 -7
- data/sample/map/extconf.rb +0 -5
- data/sample/map/map.cpp +0 -73
- data/sample/map/test.rb +0 -7
- data/test/ext/t1/Foo.hpp +0 -10
- data/test/ext/t1/extconf.rb +0 -4
- data/test/ext/t1/t1.cpp +0 -13
- data/test/ext/t2/extconf.rb +0 -4
- data/test/ext/t2/t2.cpp +0 -11
- data/test/ruby/test_callbacks_sample.rb +0 -28
- data/test/ruby/test_multiple_extensions.rb +0 -18
- data/test/ruby/test_multiple_extensions_same_class.rb +0 -14
- data/test/ruby/test_multiple_extensions_with_inheritance.rb +0 -20
- /data/test/{test_Stl_Type.cpp → test_Stl_Type_Info.cpp} +0 -0
data/test/test_Data_Type.cpp
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
#include <assert.h>
|
|
2
2
|
|
|
3
3
|
#include "unittest.hpp"
|
|
4
4
|
#include "embed_ruby.hpp"
|
|
@@ -457,7 +457,7 @@ TESTCASE(move_assignment)
|
|
|
457
457
|
{
|
|
458
458
|
Class c = define_class<RValue>("RValue")
|
|
459
459
|
.define_constructor(Constructor<RValue>())
|
|
460
|
-
.define_method<RValue&(RValue::*)(RValue
|
|
460
|
+
.define_method<RValue&(RValue::*)(RValue&& other) noexcept>("=", &RValue::operator=);
|
|
461
461
|
|
|
462
462
|
Module m(anonymous_module());
|
|
463
463
|
std::string code = R"(object1 = RValue.new
|
|
@@ -554,7 +554,7 @@ namespace
|
|
|
554
554
|
private:
|
|
555
555
|
Helper* helper_ = nullptr;
|
|
556
556
|
};
|
|
557
|
-
}
|
|
557
|
+
}
|
|
558
558
|
|
|
559
559
|
TESTCASE(pointers)
|
|
560
560
|
{
|
|
@@ -648,13 +648,10 @@ namespace
|
|
|
648
648
|
private:
|
|
649
649
|
BigObject** bigObjects_ = nullptr;
|
|
650
650
|
};
|
|
651
|
-
|
|
652
651
|
}
|
|
653
652
|
|
|
654
653
|
TESTCASE(pointerToPointer)
|
|
655
654
|
{
|
|
656
|
-
define_buffer<BigObject*>();
|
|
657
|
-
|
|
658
655
|
Module m = define_module("DataTypePointerToPointer");
|
|
659
656
|
|
|
660
657
|
Class BigObjectClass = define_class<BigObject>("BigObject")
|
|
@@ -664,9 +661,9 @@ TESTCASE(pointerToPointer)
|
|
|
664
661
|
.define_constructor(Constructor<Processor>())
|
|
665
662
|
.define_method("create", &Processor::createBigObjects)
|
|
666
663
|
.define_method("sum", &Processor::sumBigObjects,
|
|
667
|
-
Arg("bigObjects").
|
|
664
|
+
Arg("bigObjects").setBuffer(), Arg("size"))
|
|
668
665
|
.define_method("sum_const", &Processor::sumBigObjectsConst,
|
|
669
|
-
Arg("bigObjects").
|
|
666
|
+
Arg("bigObjects").setBuffer(), Arg("size"));
|
|
670
667
|
|
|
671
668
|
std::string code = R"(count = 2
|
|
672
669
|
processor = ProcessorClass.new
|
|
@@ -782,7 +779,7 @@ namespace RangesTest
|
|
|
782
779
|
int y;
|
|
783
780
|
};
|
|
784
781
|
|
|
785
|
-
int sumRangesArray(
|
|
782
|
+
int sumRangesArray(RangeCustom ranges[], int size)
|
|
786
783
|
{
|
|
787
784
|
int result = 0;
|
|
788
785
|
for (int i = 0; i < size; i++)
|
|
@@ -794,7 +791,7 @@ namespace RangesTest
|
|
|
794
791
|
return result;
|
|
795
792
|
}
|
|
796
793
|
|
|
797
|
-
int sumRanges(
|
|
794
|
+
int sumRanges(const RangeCustom* ranges, int size)
|
|
798
795
|
{
|
|
799
796
|
int result = 0;
|
|
800
797
|
for (int i = 0; i < size; i++)
|
|
@@ -806,7 +803,7 @@ namespace RangesTest
|
|
|
806
803
|
return result;
|
|
807
804
|
}
|
|
808
805
|
|
|
809
|
-
int sumRanges(
|
|
806
|
+
int sumRanges(const RangeCustom** ranges, int size)
|
|
810
807
|
{
|
|
811
808
|
int result = 0;
|
|
812
809
|
for (int i = 0; i < size; i++)
|
|
@@ -821,8 +818,6 @@ namespace RangesTest
|
|
|
821
818
|
|
|
822
819
|
TESTCASE(array_of_ranges)
|
|
823
820
|
{
|
|
824
|
-
define_buffer<RangesTest::RangeCustom>();
|
|
825
|
-
|
|
826
821
|
Module m = define_module("CustomRanges");
|
|
827
822
|
|
|
828
823
|
Class c = define_class_under<RangesTest::RangeCustom>(m, "RangeCustom")
|
|
@@ -831,14 +826,14 @@ TESTCASE(array_of_ranges)
|
|
|
831
826
|
.define_attr("y", &RangesTest::RangeCustom::y);
|
|
832
827
|
|
|
833
828
|
m.define_module_function("sum_ranges_array", RangesTest::sumRangesArray,
|
|
834
|
-
Arg("
|
|
829
|
+
Arg("ranges[]").setBuffer(), Arg("size"));
|
|
835
830
|
|
|
836
831
|
std::string code = R"(range1 = RangeCustom.new(1, 2)
|
|
837
832
|
range2 = RangeCustom.new(3, 4)
|
|
838
833
|
range3 = RangeCustom.new(5, 6)
|
|
839
834
|
|
|
840
835
|
buffer = Rice::Buffer≺RangesTest꞉꞉RangeCustom≻.new([range1, range2, range3])
|
|
841
|
-
sum_ranges_array(buffer.
|
|
836
|
+
sum_ranges_array(buffer.data, buffer.size))";
|
|
842
837
|
|
|
843
838
|
Object result = m.module_eval(code);
|
|
844
839
|
ASSERT_EQUAL(21, detail::From_Ruby<int>().convert(result));
|
|
@@ -846,8 +841,6 @@ TESTCASE(array_of_ranges)
|
|
|
846
841
|
|
|
847
842
|
TESTCASE(pointer_of_ranges)
|
|
848
843
|
{
|
|
849
|
-
define_buffer<RangesTest::RangeCustom>();
|
|
850
|
-
|
|
851
844
|
Module m = define_module("CustomRanges");
|
|
852
845
|
|
|
853
846
|
Class c = define_class_under<RangesTest::RangeCustom>(m, "RangeCustom")
|
|
@@ -855,15 +848,15 @@ TESTCASE(pointer_of_ranges)
|
|
|
855
848
|
.define_attr("x", &RangesTest::RangeCustom::x)
|
|
856
849
|
.define_attr("y", &RangesTest::RangeCustom::y);
|
|
857
850
|
|
|
858
|
-
m.define_module_function<int(*)(
|
|
859
|
-
Arg("
|
|
851
|
+
m.define_module_function<int(*)(const RangesTest::RangeCustom*, int)>("sum_ranges", RangesTest::sumRanges,
|
|
852
|
+
Arg("ranges").setBuffer(), Arg("size"));
|
|
860
853
|
|
|
861
854
|
std::string code = R"(range1 = RangeCustom.new(1, 2)
|
|
862
855
|
range2 = RangeCustom.new(3, 4)
|
|
863
856
|
range3 = RangeCustom.new(5, 6)
|
|
864
857
|
|
|
865
858
|
buffer = Rice::Buffer≺RangesTest꞉꞉RangeCustom≻.new([range1, range2, range3])
|
|
866
|
-
sum_ranges(buffer.
|
|
859
|
+
sum_ranges(buffer.data, buffer.size))";
|
|
867
860
|
|
|
868
861
|
Object result = m.module_eval(code);
|
|
869
862
|
ASSERT_EQUAL(21, detail::From_Ruby<int>().convert(result));
|
|
@@ -871,8 +864,6 @@ TESTCASE(pointer_of_ranges)
|
|
|
871
864
|
|
|
872
865
|
TESTCASE(pointer_of_ranges_wrong)
|
|
873
866
|
{
|
|
874
|
-
define_buffer<RangesTest::RangeCustom>();
|
|
875
|
-
|
|
876
867
|
Module m = define_module("CustomRanges");
|
|
877
868
|
|
|
878
869
|
Class c = define_class_under<RangesTest::RangeCustom>(m, "RangeCustom")
|
|
@@ -880,26 +871,24 @@ TESTCASE(pointer_of_ranges_wrong)
|
|
|
880
871
|
.define_attr("x", &RangesTest::RangeCustom::x)
|
|
881
872
|
.define_attr("y", &RangesTest::RangeCustom::y);
|
|
882
873
|
|
|
883
|
-
m.define_module_function<int(*)(
|
|
874
|
+
m.define_module_function<int(*)(const RangesTest::RangeCustom*, int)>("sum_ranges_wrong", RangesTest::sumRanges);
|
|
884
875
|
|
|
885
876
|
std::string code = R"(range1 = RangeCustom.new(1, 2)
|
|
886
877
|
range2 = RangeCustom.new(3, 4)
|
|
887
878
|
range3 = RangeCustom.new(5, 6)
|
|
888
879
|
|
|
889
880
|
buffer = Rice::Buffer≺RangesTest꞉꞉RangeCustom≻.new([range1, range2, range3])
|
|
890
|
-
sum_ranges_wrong(buffer
|
|
881
|
+
sum_ranges_wrong(buffer, buffer.size))";
|
|
891
882
|
|
|
892
883
|
ASSERT_EXCEPTION_CHECK(
|
|
893
884
|
Rice::Exception,
|
|
894
885
|
m.module_eval(code),
|
|
895
|
-
ASSERT_EQUAL("
|
|
886
|
+
ASSERT_EQUAL("Wrong argument type. Expected: Rice::Pointer≺RangesTest꞉꞉RangeCustom≻. Received: Rice::Buffer≺RangesTest꞉꞉RangeCustom≻.", ex.what())
|
|
896
887
|
);
|
|
897
888
|
}
|
|
898
889
|
|
|
899
890
|
TESTCASE(pointer_of_pointer_ranges)
|
|
900
891
|
{
|
|
901
|
-
define_buffer<RangesTest::RangeCustom*>();
|
|
902
|
-
|
|
903
892
|
Module m = define_module("CustomRanges");
|
|
904
893
|
|
|
905
894
|
Class c = define_class_under<RangesTest::RangeCustom>(m, "RangeCustom")
|
|
@@ -907,13 +896,13 @@ TESTCASE(pointer_of_pointer_ranges)
|
|
|
907
896
|
.define_attr("x", &RangesTest::RangeCustom::x)
|
|
908
897
|
.define_attr("y", &RangesTest::RangeCustom::y);
|
|
909
898
|
|
|
910
|
-
m.define_module_function<int(*)(
|
|
899
|
+
m.define_module_function<int(*)(const RangesTest::RangeCustom**, int)>("sum_ranges", RangesTest::sumRanges, Arg("ranges").setBuffer());
|
|
911
900
|
|
|
912
901
|
std::string code = R"(range1 = RangeCustom.new(1, 2)
|
|
913
902
|
range2 = RangeCustom.new(3, 4)
|
|
914
903
|
range3 = RangeCustom.new(5, 6)
|
|
915
|
-
buffer = Rice::Buffer≺RangesTest꞉꞉RangeCustom
|
|
916
|
-
sum_ranges(buffer.
|
|
904
|
+
buffer = Rice::Buffer≺RangesTest꞉꞉RangeCustom∗≻.new([range1, range2, range3])
|
|
905
|
+
sum_ranges(buffer.data, buffer.size))";
|
|
917
906
|
|
|
918
907
|
Object result = m.module_eval(code);
|
|
919
908
|
ASSERT_EQUAL(21, detail::From_Ruby<int>().convert(result));
|
data/test/test_Enum.cpp
CHANGED
|
@@ -67,15 +67,13 @@ TESTCASE(assignment)
|
|
|
67
67
|
ASSERT_EQUAL(define_color_enum().value(), colorEnum.value());
|
|
68
68
|
}
|
|
69
69
|
|
|
70
|
-
TESTCASE(
|
|
70
|
+
TESTCASE(values)
|
|
71
71
|
{
|
|
72
72
|
Module m = define_module("Testing");
|
|
73
73
|
|
|
74
74
|
Enum<Color> colorEnum = define_color_enum();
|
|
75
75
|
|
|
76
|
-
std::string code = R"(
|
|
77
|
-
Color.each { |x| a << x }
|
|
78
|
-
a)";
|
|
76
|
+
std::string code = R"(Color.values)";
|
|
79
77
|
|
|
80
78
|
Array a = m.module_eval(code);
|
|
81
79
|
ASSERT_EQUAL(3u, a.size());
|
|
@@ -90,52 +88,12 @@ TESTCASE(each)
|
|
|
90
88
|
ASSERT_EQUAL(GREEN, *enum_2);
|
|
91
89
|
}
|
|
92
90
|
|
|
93
|
-
TESTCASE(
|
|
94
|
-
{
|
|
95
|
-
Module m = define_module("Testing");
|
|
96
|
-
|
|
97
|
-
Enum<Color> colorEnum = define_color_enum();
|
|
98
|
-
|
|
99
|
-
std::string code = R"(Color.each {|x|})";
|
|
100
|
-
Object colorEnum2 = m.module_eval(code);
|
|
101
|
-
ASSERT_EQUAL(colorEnum2, Enum<Color>().klass());
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
TESTCASE(to_enum)
|
|
105
|
-
{
|
|
106
|
-
Module m = define_module("Testing");
|
|
107
|
-
|
|
108
|
-
Enum<Color> colorEnum = define_color_enum();
|
|
109
|
-
|
|
110
|
-
std::string code = R"(a = []
|
|
111
|
-
Color.each.with_index {|x, i| a << x }
|
|
112
|
-
a)";
|
|
113
|
-
|
|
114
|
-
Array a = m.module_eval(code);
|
|
115
|
-
ASSERT_EQUAL(3u, a.size());
|
|
116
|
-
|
|
117
|
-
Data_Object<Color> enum_0(a[0]);
|
|
118
|
-
ASSERT_EQUAL(RED, *enum_0);
|
|
119
|
-
|
|
120
|
-
Data_Object<Color> enum_1(a[1]);
|
|
121
|
-
ASSERT_EQUAL(BLACK, *enum_1);
|
|
122
|
-
|
|
123
|
-
Data_Object<Color> enum_2(a[2]);
|
|
124
|
-
ASSERT_EQUAL(GREEN, *enum_2);
|
|
125
|
-
|
|
126
|
-
code = R"(Color.each)";
|
|
127
|
-
Object enumerator = m.module_eval(code);
|
|
128
|
-
ASSERT(enumerator.is_instance_of(rb_cEnumerator));
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
TESTCASE(each_seasons)
|
|
91
|
+
TESTCASE(seasons_values)
|
|
132
92
|
{
|
|
133
93
|
Module m = define_module("Testing");
|
|
134
94
|
|
|
135
95
|
Enum<Season> rb_cSeason = define_season_enum();
|
|
136
|
-
std::string code = R"(
|
|
137
|
-
Season.each { |x| a << x }
|
|
138
|
-
a)";
|
|
96
|
+
std::string code = R"(Season.values)";
|
|
139
97
|
|
|
140
98
|
Array a = m.module_eval(code);
|
|
141
99
|
ASSERT_EQUAL(4u, a.size());
|
data/test/test_From_Ruby.cpp
CHANGED
|
@@ -13,7 +13,6 @@ TESTSUITE(FromRuby);
|
|
|
13
13
|
SETUP(FromRuby)
|
|
14
14
|
{
|
|
15
15
|
embed_ruby();
|
|
16
|
-
define_fundamental_buffer_types();
|
|
17
16
|
}
|
|
18
17
|
|
|
19
18
|
TEARDOWN(FromRuby)
|
|
@@ -132,93 +131,100 @@ TESTCASE(char_fixnum)
|
|
|
132
131
|
TESTCASE(char_pointer)
|
|
133
132
|
{
|
|
134
133
|
Module m = define_module("Testing");
|
|
134
|
+
define_pointer<char>();
|
|
135
|
+
define_buffer<char>();
|
|
135
136
|
detail::From_Ruby<char*> fromRuby;
|
|
136
137
|
|
|
137
|
-
char*
|
|
138
|
-
|
|
139
|
-
ASSERT_EQUAL(expected, data);
|
|
138
|
+
char* buffer = fromRuby.convert(Qnil);
|
|
139
|
+
ASSERT_EQUAL(nullptr, buffer);
|
|
140
140
|
|
|
141
141
|
std::string code = R"(Rice::Buffer≺char≻.new("my string"))";
|
|
142
142
|
Object result = m.instance_eval(code);
|
|
143
|
-
data =
|
|
144
|
-
|
|
145
|
-
|
|
143
|
+
Object data = result.call("data");
|
|
144
|
+
buffer = fromRuby.convert(data);
|
|
145
|
+
const char* expected = "my string";
|
|
146
|
+
ASSERT_EQUAL(*expected, *buffer);
|
|
146
147
|
|
|
147
148
|
code = R"(Rice::Buffer≺char≻.new([0, 127, 128, 255, 256, -128, -129, -255]))";
|
|
148
149
|
result = m.instance_eval(code);
|
|
149
|
-
data =
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
ASSERT_EQUAL(
|
|
153
|
-
ASSERT_EQUAL(
|
|
154
|
-
ASSERT_EQUAL(
|
|
155
|
-
ASSERT_EQUAL(
|
|
156
|
-
ASSERT_EQUAL(
|
|
157
|
-
ASSERT_EQUAL(
|
|
158
|
-
ASSERT_EQUAL(
|
|
150
|
+
data = result.call("data");
|
|
151
|
+
buffer = fromRuby.convert(data);
|
|
152
|
+
|
|
153
|
+
ASSERT_EQUAL(buffer[0], 0);
|
|
154
|
+
ASSERT_EQUAL(buffer[1], 127);
|
|
155
|
+
ASSERT_EQUAL(buffer[2], -128);
|
|
156
|
+
ASSERT_EQUAL(buffer[3], -1);
|
|
157
|
+
ASSERT_EQUAL(buffer[4], 0);
|
|
158
|
+
ASSERT_EQUAL(buffer[5], -128);
|
|
159
|
+
ASSERT_EQUAL(buffer[6], 127);
|
|
160
|
+
ASSERT_EQUAL(buffer[7], 1);
|
|
159
161
|
|
|
160
162
|
ASSERT_EXCEPTION_CHECK(
|
|
161
163
|
Exception,
|
|
162
164
|
fromRuby.convert(rb_float_new(11.11)),
|
|
163
|
-
ASSERT_EQUAL("wrong argument type Float (expected
|
|
165
|
+
ASSERT_EQUAL("wrong argument type Float (expected Pointer≺char≻)", ex.what())
|
|
164
166
|
);
|
|
165
167
|
}
|
|
166
168
|
|
|
167
169
|
TESTCASE(signed_char_pointer)
|
|
168
170
|
{
|
|
169
171
|
Module m = define_module("Testing");
|
|
172
|
+
define_buffer<signed char>();
|
|
170
173
|
detail::From_Ruby<signed char*> fromRuby;
|
|
171
174
|
|
|
172
175
|
signed char* expected = nullptr;
|
|
173
|
-
signed char*
|
|
174
|
-
ASSERT_EQUAL(expected,
|
|
176
|
+
signed char* buffer = fromRuby.convert(Qnil);
|
|
177
|
+
ASSERT_EQUAL(expected, buffer);
|
|
175
178
|
|
|
176
179
|
std::string code = R"(Rice::Buffer≺signed char≻.new("my string"))";
|
|
177
180
|
Object result = m.instance_eval(code);
|
|
178
|
-
data =
|
|
181
|
+
Object data = result.call("data");
|
|
182
|
+
buffer = fromRuby.convert(data);
|
|
179
183
|
expected = (signed char*)"my string";
|
|
180
|
-
ASSERT_EQUAL(*expected, *
|
|
184
|
+
ASSERT_EQUAL(*expected, *buffer);
|
|
181
185
|
|
|
182
186
|
code = R"(Rice::Buffer≺signed char≻.new([0, 127, 128, 255, 256, -128, -129, -255]))";
|
|
183
187
|
result = m.instance_eval(code);
|
|
184
|
-
data =
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
ASSERT_EQUAL(
|
|
188
|
-
ASSERT_EQUAL(
|
|
189
|
-
ASSERT_EQUAL(
|
|
190
|
-
ASSERT_EQUAL(
|
|
191
|
-
ASSERT_EQUAL(
|
|
192
|
-
ASSERT_EQUAL(
|
|
193
|
-
ASSERT_EQUAL(
|
|
188
|
+
data = result.call("data");
|
|
189
|
+
buffer = fromRuby.convert(data);
|
|
190
|
+
|
|
191
|
+
ASSERT_EQUAL(buffer[0], 0);
|
|
192
|
+
ASSERT_EQUAL(buffer[1], 127);
|
|
193
|
+
ASSERT_EQUAL(buffer[2], -128);
|
|
194
|
+
ASSERT_EQUAL(buffer[3], -1);
|
|
195
|
+
ASSERT_EQUAL(buffer[4], 0);
|
|
196
|
+
ASSERT_EQUAL(buffer[5], -128);
|
|
197
|
+
ASSERT_EQUAL(buffer[6], 127);
|
|
198
|
+
ASSERT_EQUAL(buffer[7], 1);
|
|
194
199
|
|
|
195
200
|
ASSERT_EXCEPTION_CHECK(
|
|
196
201
|
Exception,
|
|
197
202
|
fromRuby.convert(rb_float_new(11.11)),
|
|
198
|
-
ASSERT_EQUAL("
|
|
203
|
+
ASSERT_EQUAL("Wrong argument type. Expected: Rice::Pointer≺signed char≻. Received: Float.", ex.what())
|
|
199
204
|
);
|
|
200
205
|
}
|
|
201
206
|
|
|
202
207
|
TESTCASE(char_pointer_const)
|
|
203
208
|
{
|
|
204
209
|
Module m = define_module("Testing");
|
|
210
|
+
define_pointer<char>();
|
|
205
211
|
|
|
206
212
|
std::string code = R"(Rice::Buffer≺char≻.new("my string"))";
|
|
207
213
|
Object result = m.instance_eval(code);
|
|
208
214
|
const char* expected = "my string";
|
|
209
|
-
const char* data = detail::From_Ruby<
|
|
215
|
+
const char* data = detail::From_Ruby<char*>().convert(result.call("data"));
|
|
210
216
|
ASSERT_EQUAL(expected, data);
|
|
211
217
|
|
|
212
218
|
code = R"(Rice::Buffer≺char≻.new(""))";
|
|
213
219
|
result = m.instance_eval(code);
|
|
214
220
|
expected = "";
|
|
215
|
-
data = detail::From_Ruby<
|
|
221
|
+
data = detail::From_Ruby<char*>().convert(result.call("data"));
|
|
216
222
|
ASSERT_EQUAL(expected, data);
|
|
217
223
|
|
|
218
224
|
ASSERT_EXCEPTION_CHECK(
|
|
219
225
|
Exception,
|
|
220
|
-
detail::From_Ruby<char
|
|
221
|
-
ASSERT_EQUAL("wrong argument type Float (expected
|
|
226
|
+
detail::From_Ruby<char*>().convert(rb_float_new(32.3)),
|
|
227
|
+
ASSERT_EQUAL("wrong argument type Float (expected Pointer≺char≻)", ex.what())
|
|
222
228
|
);
|
|
223
229
|
}
|
|
224
230
|
|
|
@@ -234,45 +240,46 @@ TESTCASE(unsigned_char)
|
|
|
234
240
|
TESTCASE(unsigned_char_pointer)
|
|
235
241
|
{
|
|
236
242
|
Module m = define_module("Testing");
|
|
243
|
+
define_buffer<unsigned char>();
|
|
244
|
+
detail::From_Ruby<Buffer<unsigned char>*> fromRuby;
|
|
237
245
|
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
unsigned char* expected = nullptr;
|
|
241
|
-
unsigned char* data = fromRuby.convert(Qnil);
|
|
242
|
-
ASSERT_EQUAL(expected, data);
|
|
246
|
+
Buffer<unsigned char>* buffer = fromRuby.convert(Qnil);
|
|
247
|
+
ASSERT_EQUAL(nullptr, buffer);
|
|
243
248
|
|
|
244
249
|
std::string code = R"(Rice::Buffer≺unsigned char≻.new([0, 127, 128, 255, 256, -128, -129, -255]))";
|
|
245
250
|
Object result = m.instance_eval(code);
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
ASSERT_EQUAL(
|
|
249
|
-
ASSERT_EQUAL(
|
|
250
|
-
ASSERT_EQUAL(
|
|
251
|
-
ASSERT_EQUAL(
|
|
252
|
-
ASSERT_EQUAL(
|
|
253
|
-
ASSERT_EQUAL(
|
|
254
|
-
ASSERT_EQUAL(
|
|
255
|
-
ASSERT_EQUAL(
|
|
251
|
+
buffer = fromRuby.convert(result.value());
|
|
252
|
+
|
|
253
|
+
ASSERT_EQUAL((size_t)8, buffer->size());
|
|
254
|
+
ASSERT_EQUAL(buffer->operator[](0), 0x0);
|
|
255
|
+
ASSERT_EQUAL(buffer->operator[](1), 0x7F);
|
|
256
|
+
ASSERT_EQUAL(buffer->operator[](2), 0x80);
|
|
257
|
+
ASSERT_EQUAL(buffer->operator[](3), 0xFF);
|
|
258
|
+
ASSERT_EQUAL(buffer->operator[](4), 0x00);
|
|
259
|
+
ASSERT_EQUAL(buffer->operator[](5), 0x80);
|
|
260
|
+
ASSERT_EQUAL(buffer->operator[](6), 0x7F);
|
|
261
|
+
ASSERT_EQUAL(buffer->operator[](7), 0x01);
|
|
256
262
|
|
|
257
263
|
code = R"(array = [0, 127, 128, 255, 256, -128, -129, -255]
|
|
258
|
-
|
|
259
|
-
|
|
264
|
+
packed = array.pack("C*")
|
|
265
|
+
Rice::Buffer≺unsigned char≻.new(packed))";
|
|
260
266
|
result = m.instance_eval(code);
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
ASSERT_EQUAL(
|
|
264
|
-
ASSERT_EQUAL(
|
|
265
|
-
ASSERT_EQUAL(
|
|
266
|
-
ASSERT_EQUAL(
|
|
267
|
-
ASSERT_EQUAL(
|
|
268
|
-
ASSERT_EQUAL(
|
|
269
|
-
ASSERT_EQUAL(
|
|
270
|
-
ASSERT_EQUAL(
|
|
267
|
+
buffer = fromRuby.convert(result.value());
|
|
268
|
+
|
|
269
|
+
ASSERT_EQUAL((size_t)8, buffer->size());
|
|
270
|
+
ASSERT_EQUAL(buffer->operator[](0), 0x0);
|
|
271
|
+
ASSERT_EQUAL(buffer->operator[](1), 0x7F);
|
|
272
|
+
ASSERT_EQUAL(buffer->operator[](2), 0x80);
|
|
273
|
+
ASSERT_EQUAL(buffer->operator[](3), 0xFF);
|
|
274
|
+
ASSERT_EQUAL(buffer->operator[](4), 0x00);
|
|
275
|
+
ASSERT_EQUAL(buffer->operator[](5), 0x80);
|
|
276
|
+
ASSERT_EQUAL(buffer->operator[](6), 0x7F);
|
|
277
|
+
ASSERT_EQUAL(buffer->operator[](7), 0x01);
|
|
271
278
|
|
|
272
279
|
ASSERT_EXCEPTION_CHECK(
|
|
273
280
|
Exception,
|
|
274
281
|
detail::From_Ruby<const char*>().convert(rb_float_new(11.11)),
|
|
275
|
-
ASSERT_EQUAL("
|
|
282
|
+
ASSERT_EQUAL("Wrong argument type. Expected: Rice::Pointer≺char≻. Received: Float.", ex.what())
|
|
276
283
|
);
|
|
277
284
|
}
|
|
278
285
|
|
|
@@ -284,7 +291,7 @@ TESTCASE(unsigned_char_pointer_array)
|
|
|
284
291
|
|
|
285
292
|
std::string code = R"(arr = ["A", "B"]
|
|
286
293
|
buffer = Rice::Buffer≺unsigned char≻.new(arr)
|
|
287
|
-
unsigned_char_pointer(buffer, buffer.size))";
|
|
294
|
+
unsigned_char_pointer(buffer.data, buffer.size))";
|
|
288
295
|
|
|
289
296
|
ASSERT_EXCEPTION_CHECK(
|
|
290
297
|
Exception,
|
|
@@ -296,20 +303,20 @@ TESTCASE(unsigned_char_pointer_array)
|
|
|
296
303
|
char.ord
|
|
297
304
|
end
|
|
298
305
|
buffer = Rice::Buffer≺unsigned char≻.new(arr)
|
|
299
|
-
unsigned_char_pointer(buffer, buffer.size))";
|
|
306
|
+
unsigned_char_pointer(buffer.data, buffer.size))";
|
|
300
307
|
|
|
301
308
|
Object result = m.module_eval(code);
|
|
302
309
|
ASSERT_EQUAL("[A, B]", detail::From_Ruby<std::string>().convert(result.value()));
|
|
303
310
|
|
|
304
311
|
code = R"(arr = [65, 66]
|
|
305
312
|
buffer = Rice::Buffer≺unsigned char≻.new(arr)
|
|
306
|
-
unsigned_char_pointer(buffer, buffer.size))";
|
|
313
|
+
unsigned_char_pointer(buffer.data, buffer.size))";
|
|
307
314
|
result = m.module_eval(code);
|
|
308
315
|
ASSERT_EQUAL("[A, B]", detail::From_Ruby<std::string>().convert(result.value()));
|
|
309
316
|
|
|
310
317
|
code = R"(arr = [true]
|
|
311
318
|
buffer = Rice::Buffer≺unsigned char≻.new(arr)
|
|
312
|
-
unsigned_char_pointer(buffer, buffer.size))";
|
|
319
|
+
unsigned_char_pointer(buffer.ptr, buffer.size))";
|
|
313
320
|
|
|
314
321
|
ASSERT_EXCEPTION_CHECK(
|
|
315
322
|
Exception,
|
|
@@ -346,7 +353,7 @@ TESTCASE(double_pointer_array)
|
|
|
346
353
|
|
|
347
354
|
std::string code = R"(arr = [1.1, 2.2, 3.3, 4.4]
|
|
348
355
|
buffer = Rice::Buffer≺double≻.new(arr)
|
|
349
|
-
double_pointer(buffer, buffer.size))";
|
|
356
|
+
double_pointer(buffer.data, buffer.size))";
|
|
350
357
|
|
|
351
358
|
Object result = m.module_eval(code);
|
|
352
359
|
|
|
@@ -382,19 +389,19 @@ TESTCASE(float_pointer_array)
|
|
|
382
389
|
|
|
383
390
|
std::string code = R"(arr = [4.3, 3.2, 2.1, 1.1]
|
|
384
391
|
buffer = Rice::Buffer≺float≻.new(arr)
|
|
385
|
-
float_pointer(buffer, buffer.size))";
|
|
392
|
+
float_pointer(buffer.data, buffer.size))";
|
|
386
393
|
Object result = m.module_eval(code);
|
|
387
394
|
ASSERT_EQUAL("[4.3, 3.2, 2.1, 1.1]", detail::From_Ruby<std::string>().convert(result.value()));
|
|
388
395
|
|
|
389
396
|
code = R"(arr = [4, 3, 2.8, 1]
|
|
390
397
|
buffer = Rice::Buffer≺float≻.new(arr)
|
|
391
|
-
float_pointer(buffer, buffer.size))";
|
|
398
|
+
float_pointer(buffer.data, buffer.size))";
|
|
392
399
|
result = m.module_eval(code);
|
|
393
400
|
ASSERT_EQUAL("[4, 3, 2.8, 1]", detail::From_Ruby<std::string>().convert(result.value()));
|
|
394
401
|
|
|
395
402
|
code = R"(arr = [4, "bad", 2, 1]
|
|
396
403
|
buffer = Rice::Buffer≺float≻.new(arr)
|
|
397
|
-
float_pointer(buffer, buffer.size))";
|
|
404
|
+
float_pointer(buffer.data, buffer.size))";
|
|
398
405
|
|
|
399
406
|
ASSERT_EXCEPTION_CHECK(
|
|
400
407
|
Exception,
|
|
@@ -410,17 +417,17 @@ TESTCASE(float_array_array)
|
|
|
410
417
|
m.define_singleton_function("array_array_to_string", &arrayofArraysToString<float>);
|
|
411
418
|
|
|
412
419
|
std::string code = R"(buffer = Rice::Buffer≺float∗≻.new([[1.1, 2.2], [3.3, 4.4], [5.5, 6.6]])
|
|
413
|
-
array_array_to_string(buffer, buffer.size, 2))";
|
|
420
|
+
array_array_to_string(buffer.data, buffer.size, 2))";
|
|
414
421
|
Object result = m.module_eval(code);
|
|
415
422
|
ASSERT_EQUAL("[[1.1, 2.2], [3.3, 4.4], [5.5, 6.6]]", detail::From_Ruby<std::string>().convert(result.value()));
|
|
416
423
|
|
|
417
424
|
code = R"(buffer = Rice::Buffer≺float∗≻.new([[4, 3], [2.8, 1]])
|
|
418
|
-
array_array_to_string(buffer, buffer.size, 2))";
|
|
425
|
+
array_array_to_string(buffer.data, buffer.size, 2))";
|
|
419
426
|
result = m.module_eval(code);
|
|
420
427
|
ASSERT_EQUAL("[[4, 3], [2.8, 1]]", detail::From_Ruby<std::string>().convert(result.value()));
|
|
421
428
|
|
|
422
429
|
code = R"(buffer = Rice::Buffer≺float∗≻.new([[4, "bad"], [2, 1]])
|
|
423
|
-
array_array_to_string(buffer, buffer.size, 2))";
|
|
430
|
+
array_array_to_string(buffer.data, buffer.size, 2))";
|
|
424
431
|
|
|
425
432
|
ASSERT_EXCEPTION_CHECK(
|
|
426
433
|
Exception,
|
|
@@ -434,7 +441,7 @@ TESTCASE(float_array_array)
|
|
|
434
441
|
ASSERT_EXCEPTION_CHECK(
|
|
435
442
|
Exception,
|
|
436
443
|
m.module_eval(code),
|
|
437
|
-
ASSERT_EQUAL("
|
|
444
|
+
ASSERT_EQUAL("Wrong argument type. Expected: Rice::Pointer≺float∗≻. Received: Array.", ex.what())
|
|
438
445
|
);
|
|
439
446
|
}
|
|
440
447
|
|
|
@@ -462,13 +469,13 @@ TESTCASE(int_pointer_array)
|
|
|
462
469
|
|
|
463
470
|
std::string code = R"(arr = [4, 3, 2, 1]
|
|
464
471
|
buffer = Rice::Buffer≺int≻.new(arr)
|
|
465
|
-
int_pointer(buffer, buffer.size))";
|
|
472
|
+
int_pointer(buffer.data, buffer.size))";
|
|
466
473
|
Object result = m.module_eval(code);
|
|
467
474
|
ASSERT_EQUAL("[4, 3, 2, 1]", detail::From_Ruby<std::string>().convert(result.value()));
|
|
468
475
|
|
|
469
476
|
code = R"(arr = [4.2, 3.8, 2.0, 1]
|
|
470
477
|
buffer = Rice::Buffer≺int≻.new(arr)
|
|
471
|
-
int_pointer(buffer, buffer.size))";
|
|
478
|
+
int_pointer(buffer.data, buffer.size))";
|
|
472
479
|
result = m.module_eval(code);
|
|
473
480
|
ASSERT_EQUAL("[4, 3, 2, 1]", detail::From_Ruby<std::string>().convert(result.value()));
|
|
474
481
|
}
|
|
@@ -602,8 +609,8 @@ TESTCASE(void_pointer_array)
|
|
|
602
609
|
m.define_singleton_function("void_pointer", &voidToString<int>);
|
|
603
610
|
|
|
604
611
|
std::string code = R"(arr = [4, 3, 2, 1]
|
|
605
|
-
|
|
606
|
-
void_pointer(
|
|
612
|
+
data = arr.pack("i*")
|
|
613
|
+
void_pointer(data, data.size))";
|
|
607
614
|
Object result = m.module_eval(code);
|
|
608
615
|
ASSERT_EQUAL("[4, 3, 2, 1]", detail::From_Ruby<std::string>().convert(result.value()));
|
|
609
616
|
}
|