aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog9
-rw-r--r--ext/openssl/lib/openssl/buffering.rb5
-rw-r--r--test/openssl/test_buffering.rb35
3 files changed, 40 insertions, 9 deletions
diff --git a/ChangeLog b/ChangeLog
index bee6cb58b0..1f88bb0237 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+Sat Jun 11 23:02:36 2011 Hiroshi Nakamura <nahi@ruby-lang.org>
+
+ * ext/openssl/lib/openssl/buffering.rb (module OpenSSL):
+ Buffering#each_byte should return String in accordance with IO in
+ 1.9.
+
+ * test/openssl/test_buffering.rb (class OpenSSL): add tests for getc
+ and each_byte.
+
Sat Jun 11 22:41:37 2011 Tadayoshi Funaba <tadf@dotrb.org>
* time.c: a correction of doc for strftime (%v).
diff --git a/ext/openssl/lib/openssl/buffering.rb b/ext/openssl/lib/openssl/buffering.rb
index a11fe73357..eb39dabcef 100644
--- a/ext/openssl/lib/openssl/buffering.rb
+++ b/ext/openssl/lib/openssl/buffering.rb
@@ -252,8 +252,7 @@ module OpenSSL::Buffering
# file.
def getc
- c = read(1)
- c ? c[0] : nil
+ read(1)
end
##
@@ -261,7 +260,7 @@ module OpenSSL::Buffering
def each_byte # :yields: byte
while c = getc
- yield(c)
+ yield(c.ord)
end
end
diff --git a/test/openssl/test_buffering.rb b/test/openssl/test_buffering.rb
index 49335de8d2..25e0b66232 100644
--- a/test/openssl/test_buffering.rb
+++ b/test/openssl/test_buffering.rb
@@ -10,7 +10,10 @@ class OpenSSL::TestBuffering < MiniTest::Unit::TestCase
attr_accessor :sync
def initialize
- @io = StringIO.new
+ @io = ""
+ def @io.sync
+ true
+ end
super
@@ -18,15 +21,18 @@ class OpenSSL::TestBuffering < MiniTest::Unit::TestCase
end
def string
- @io.string
+ @io
end
- def sysread *a
- @io.sysread *a
+ def sysread(size)
+ str = @io.slice!(0, size)
+ raise EOFError if str.empty?
+ str
end
- def syswrite *a
- @io.syswrite *a
+ def syswrite(str)
+ @io << str
+ str.size
end
end
@@ -63,4 +69,21 @@ class OpenSSL::TestBuffering < MiniTest::Unit::TestCase
refute @io.sync, 'sync must not change'
end
+ def test_getc
+ @io.syswrite('abc')
+ res = []
+ assert_equal(?a, @io.getc)
+ assert_equal(?b, @io.getc)
+ assert_equal(?c, @io.getc)
+ end
+
+ def test_each_byte
+ @io.syswrite('abc')
+ res = []
+ @io.each_byte do |c|
+ res << c
+ end
+ assert_equal([97, 98, 99], res)
+ end
+
end if defined?(OpenSSL)