summaryrefslogtreecommitdiff
path: root/test/fiddle/test_func.rb
diff options
context:
space:
mode:
authorSutou Kouhei <kou@clear-code.com>2020-07-09 20:19:20 +0900
committerSutou Kouhei <kou@cozmixng.org>2020-11-18 09:05:13 +0900
commitae7b53546ca18b56c23f612b6935e98268a07602 (patch)
tree6669206356ba05e4ee4d0e34dd99901ad1ea268c /test/fiddle/test_func.rb
parent64926d500782cadf578724c3d1e7f59e7aaf200f (diff)
[ruby/fiddle] Add TYPE_CONST_STRING and SIZEOF_CONST_STRING for "const char *"
Add rb_fiddle_ prefix to conversion functions.h to keep backward compatibility but value_to_generic() isn't safe for TYPE_CONST_STRING and not String src. Use rb_fiddle_value_to_generic() instead. https://github.com/ruby/fiddle/commit/0ffcaa39e5
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/3780
Diffstat (limited to 'test/fiddle/test_func.rb')
-rw-r--r--test/fiddle/test_func.rb23
1 files changed, 17 insertions, 6 deletions
diff --git a/test/fiddle/test_func.rb b/test/fiddle/test_func.rb
index 29a0a455f1..ca9d4ccb34 100644
--- a/test/fiddle/test_func.rb
+++ b/test/fiddle/test_func.rb
@@ -98,7 +98,7 @@ module Fiddle
[
TYPE_VOIDP,
TYPE_SIZE_T,
- TYPE_VOIDP,
+ TYPE_CONST_STRING,
TYPE_VARIADIC,
],
TYPE_INT)
@@ -107,20 +107,31 @@ module Fiddle
written = snprintf.call(output,
output.size,
- "int: %d, string: %.*s\n",
+ "int: %d, string: %.*s, const string: %s\n",
TYPE_INT, -29,
TYPE_INT, 4,
- TYPE_VOIDP, "Hello")
- assert_equal("int: -29, string: Hell\n",
+ TYPE_VOIDP, "Hello",
+ TYPE_CONST_STRING, "World")
+ assert_equal("int: -29, string: Hell, const string: World\n",
output_buffer[0, written])
+ string_like_class = Class.new do
+ def initialize(string)
+ @string = string
+ end
+
+ def to_str
+ @string
+ end
+ end
written = snprintf.call(output,
output.size,
- "string: %.*s, uint: %u\n",
+ "string: %.*s, const string: %s, uint: %u\n",
TYPE_INT, 2,
TYPE_VOIDP, "Hello",
+ TYPE_CONST_STRING, string_like_class.new("World"),
TYPE_INT, 29)
- assert_equal("string: He, uint: 29\n",
+ assert_equal("string: He, const string: World, uint: 29\n",
output_buffer[0, written])
end
end