summaryrefslogtreecommitdiff
path: root/test/fiddle
diff options
context:
space:
mode:
Diffstat (limited to 'test/fiddle')
-rw-r--r--test/fiddle/test_func.rb23
-rw-r--r--test/fiddle/test_import.rb13
2 files changed, 27 insertions, 9 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
diff --git a/test/fiddle/test_import.rb b/test/fiddle/test_import.rb
index c56d81c351..4afd8e5562 100644
--- a/test/fiddle/test_import.rb
+++ b/test/fiddle/test_import.rb
@@ -112,10 +112,17 @@ module Fiddle
Fiddle.constants.grep(/\ATYPE_(?!VOID|VARIADIC\z)(.*)/) do
type = $&
- size = Fiddle.const_get("SIZEOF_#{$1}")
- name = $1.sub(/P\z/,"*").gsub(/_(?!T\z)/, " ").downcase
+ const_type_name = $1
+ size = Fiddle.const_get("SIZEOF_#{const_type_name}")
+ if const_type_name == "CONST_STRING"
+ name = "const_string"
+ type_name = "const char*"
+ else
+ name = $1.sub(/P\z/,"*").gsub(/_(?!T\z)/, " ").downcase
+ type_name = name
+ end
define_method("test_sizeof_#{name}") do
- assert_equal(size, Fiddle::Importer.sizeof(name), type)
+ assert_equal(size, Fiddle::Importer.sizeof(type_name), type)
end
end