summaryrefslogtreecommitdiff
path: root/test/fiddle/test_memory_view.rb
diff options
context:
space:
mode:
authorSutou Kouhei <kou@cozmixng.org>2021-06-17 13:36:18 +0900
committerNobuyoshi Nakada <nobu@ruby-lang.org>2021-07-13 19:37:45 +0900
commit10e26cfa76468dea6f828dbe8031b5ffcff543cb (patch)
tree2fbf89fe75da8f40c96af505c20e5e5f6b4e1dd3 /test/fiddle/test_memory_view.rb
parent9988f6ac4e887437b5a76f0a1c27fa6f5c17c039 (diff)
[ruby/fiddle] Add MemoryView.export and MemoryView#release (https://github.com/ruby/fiddle/pull/80)
fix https://github.com/ruby/fiddle/pull/79 Users can release memory views explicitly before process exit. Reported by xtkoba. Thanks!!! https://github.com/ruby/fiddle/commit/1de64b7e76
Diffstat (limited to 'test/fiddle/test_memory_view.rb')
-rw-r--r--test/fiddle/test_memory_view.rb16
1 files changed, 16 insertions, 0 deletions
diff --git a/test/fiddle/test_memory_view.rb b/test/fiddle/test_memory_view.rb
index 6777a043ce..8130823fd6 100644
--- a/test/fiddle/test_memory_view.rb
+++ b/test/fiddle/test_memory_view.rb
@@ -114,6 +114,22 @@ module Fiddle
assert_equal([-7, -8], mview[1, 3])
end
+ def test_export
+ str = "hello world"
+ mview_str = MemoryView.export(Pointer[str]) do |mview|
+ mview.to_s
+ end
+ assert_equal(str, mview_str)
+ end
+
+ def test_release
+ ptr = Pointer["hello world"]
+ mview = MemoryView.new(ptr)
+ assert_same(ptr, mview.obj)
+ mview.release
+ assert_nil(mview.obj)
+ end
+
def test_to_s
# U+3042 HIRAGANA LETTER A
data = "\u{3042}"