summaryrefslogtreecommitdiffhomepage
path: root/mrbgems/mruby-io/test
diff options
context:
space:
mode:
authorYukihiro "Matz" Matsumoto <[email protected]>2020-03-07 19:07:13 +0900
committerYukihiro "Matz" Matsumoto <[email protected]>2020-03-07 19:07:13 +0900
commit4398bae56a04a6ac1ac7f49935075bcbd8f50872 (patch)
tree59ac85c717351487c77d4f7e81e5cfca2cf97be3 /mrbgems/mruby-io/test
parentf45549edbfd2131e40363af93ee14e73694f3d20 (diff)
parent20f9128f732c3f4f51834fc0096abb0382cc4837 (diff)
downloadmruby-4398bae56a04a6ac1ac7f49935075bcbd8f50872.tar.gz
mruby-4398bae56a04a6ac1ac7f49935075bcbd8f50872.zip
Merge branch 'dearblue-io-pread-pwrite'
Diffstat (limited to 'mrbgems/mruby-io/test')
-rw-r--r--mrbgems/mruby-io/test/io.rb28
-rw-r--r--mrbgems/mruby-io/test/mruby_io_test.c9
2 files changed, 37 insertions, 0 deletions
diff --git a/mrbgems/mruby-io/test/io.rb b/mrbgems/mruby-io/test/io.rb
index e3024cf9a..458d2cdc2 100644
--- a/mrbgems/mruby-io/test/io.rb
+++ b/mrbgems/mruby-io/test/io.rb
@@ -564,6 +564,34 @@ assert('IO#sysseek') do
end
end
+assert('IO#pread') do
+ skip "IO#pread is not implemented on this configuration" unless MRubyIOTestUtil::MRB_WITH_IO_PREAD_PWRITE
+
+ IO.open(IO.sysopen($mrbtest_io_rfname, 'r'), 'r') do |io|
+ assert_equal $mrbtest_io_msg.byteslice(5, 8), io.pread(8, 5)
+ assert_equal 0, io.pos
+ assert_equal $mrbtest_io_msg.byteslice(1, 5), io.pread(5, 1)
+ assert_equal 0, io.pos
+ assert_raise(RuntimeError) { io.pread(20, -9) }
+ end
+end
+
+assert('IO#pwrite') do
+ skip "IO#pwrite is not implemented on this configuration" unless MRubyIOTestUtil::MRB_WITH_IO_PREAD_PWRITE
+
+ IO.open(IO.sysopen($mrbtest_io_wfname, 'w+'), 'w+') do |io|
+ assert_equal 6, io.pwrite("Warld!", 7)
+ assert_equal 0, io.pos
+ assert_equal 7, io.pwrite("Hello, ", 0)
+ assert_equal 0, io.pos
+ assert_equal "Hello, Warld!", io.read
+ assert_equal 6, io.pwrite("world!", 7)
+ assert_equal 13, io.pos
+ io.pos = 0
+ assert_equal "Hello, world!", io.read
+ end
+end
+
assert('IO.pipe') do
begin
called = false
diff --git a/mrbgems/mruby-io/test/mruby_io_test.c b/mrbgems/mruby-io/test/mruby_io_test.c
index 7e272d45a..581472eaa 100644
--- a/mrbgems/mruby-io/test/mruby_io_test.c
+++ b/mrbgems/mruby-io/test/mruby_io_test.c
@@ -64,6 +64,7 @@ mkdtemp(char *temp)
#include "mruby/error.h"
#include "mruby/string.h"
#include "mruby/variable.h"
+#include <mruby/ext/io.h>
static mrb_value
mrb_io_test_io_setup(mrb_state *mrb, mrb_value self)
@@ -219,6 +220,12 @@ mrb_io_win_p(mrb_state *mrb, mrb_value klass)
#endif
}
+#ifdef MRB_WITH_IO_PREAD_PWRITE
+# define MRB_WITH_IO_PREAD_PWRITE_ENABLED TRUE
+#else
+# define MRB_WITH_IO_PREAD_PWRITE_ENABLED FALSE
+#endif
+
void
mrb_mruby_io_gem_test(mrb_state* mrb)
{
@@ -229,4 +236,6 @@ mrb_mruby_io_gem_test(mrb_state* mrb)
mrb_define_class_method(mrb, io_test, "mkdtemp", mrb_io_test_mkdtemp, MRB_ARGS_REQ(1));
mrb_define_class_method(mrb, io_test, "rmdir", mrb_io_test_rmdir, MRB_ARGS_REQ(1));
mrb_define_class_method(mrb, io_test, "win?", mrb_io_win_p, MRB_ARGS_NONE());
+
+ mrb_define_const(mrb, io_test, "MRB_WITH_IO_PREAD_PWRITE", mrb_bool_value(MRB_WITH_IO_PREAD_PWRITE_ENABLED));
}