diff options
author | Sutou Kouhei <kou@clear-code.com> | 2020-06-27 07:25:47 +0900 |
---|---|---|
committer | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2020-06-27 23:54:08 +0900 |
commit | ae18220f9904c70304bd1672eecadbb3618fc7e5 (patch) | |
tree | 26356cc33a9939c1059047cf411a45f3ec26f85d /test/fiddle/test_func.rb | |
parent | 9f740acaf960c0d8fa4b72050f057bc157db31ce (diff) | |
download | ruby-ae18220f9904c70304bd1672eecadbb3618fc7e5.tar.gz |
[ruby/fiddle] Add support for variadic arguments
GitHub: fix GH-39
Reported by kojix2. Thanks!!!
https://github.com/ruby/fiddle/commit/6c4cb904dc
Diffstat (limited to 'test/fiddle/test_func.rb')
-rw-r--r-- | test/fiddle/test_func.rb | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/test/fiddle/test_func.rb b/test/fiddle/test_func.rb index ca89173766..18052fffdd 100644 --- a/test/fiddle/test_func.rb +++ b/test/fiddle/test_func.rb @@ -79,5 +79,36 @@ module Fiddle EnvUtil.under_gc_stress {qsort.call(buff, buff.size, 1, cb)} assert_equal("1349", buff, bug4929) end + + def test_snprintf + snprintf = Function.new(@libc["snprintf"], + [ + TYPE_VOIDP, + TYPE_SIZE_T, + TYPE_VOIDP, + TYPE_VARIADIC, + ], + TYPE_INT) + output_buffer = " " * 1024 + output = Pointer[output_buffer] + + written = snprintf.call(output, + output.size, + "int: %d, string: %.*s\n", + TYPE_INT, -29, + TYPE_INT, 4, + TYPE_VOIDP, "Hello") + assert_equal("int: -29, string: Hell\n", + output_buffer[0, written]) + + written = snprintf.call(output, + output.size, + "string: %.*s, uint: %u\n", + TYPE_INT, 2, + TYPE_VOIDP, "Hello", + TYPE_INT, 29) + assert_equal("string: He, uint: 29\n", + output_buffer[0, written]) + end end end if defined?(Fiddle) |