~ubuntu-branches/ubuntu/quantal/ruby1.9.1/quantal

« back to all changes in this revision

Viewing changes to test/openssl/test_buffering.rb

  • Committer: Bazaar Package Importer
  • Author(s): Lucas Nussbaum
  • Date: 2011-09-24 19:16:17 UTC
  • mfrom: (1.1.8 upstream) (13.1.7 experimental)
  • Revision ID: james.westby@ubuntu.com-20110924191617-o1qz4rcmqjot8zuy
Tags: 1.9.3~rc1-1
* New upstream release: 1.9.3 RC1.
  + Includes load.c fixes. Closes: #639959.
* Upload to unstable.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
require_relative 'utils'
2
2
require 'stringio'
3
 
require 'minitest/unit'
4
3
 
5
 
class OpenSSL::TestBuffering < MiniTest::Unit::TestCase
 
4
class OpenSSL::TestBuffering < Test::Unit::TestCase
6
5
 
7
6
  class IO
8
7
    include OpenSSL::Buffering
10
9
    attr_accessor :sync
11
10
 
12
11
    def initialize
13
 
      @io = StringIO.new
 
12
      @io = ""
 
13
      def @io.sync
 
14
        true
 
15
      end
14
16
 
15
17
      super
16
18
 
18
20
    end
19
21
 
20
22
    def string
21
 
      @io.string
22
 
    end
23
 
 
24
 
    def sysread *a
25
 
      @io.sysread *a
26
 
    end
27
 
 
28
 
    def syswrite *a
29
 
      @io.syswrite *a
 
23
      @io
 
24
    end
 
25
 
 
26
    def sysread(size)
 
27
      str = @io.slice!(0, size)
 
28
      raise EOFError if str.empty?
 
29
      str
 
30
    end
 
31
 
 
32
    def syswrite(str)
 
33
      @io << str
 
34
      str.size
30
35
    end
31
36
  end
32
37
 
63
68
    refute @io.sync, 'sync must not change'
64
69
  end
65
70
 
 
71
  def test_getc
 
72
    @io.syswrite('abc')
 
73
    res = []
 
74
    assert_equal(?a, @io.getc)
 
75
    assert_equal(?b, @io.getc)
 
76
    assert_equal(?c, @io.getc)
 
77
  end
 
78
 
 
79
  def test_each_byte
 
80
    @io.syswrite('abc')
 
81
    res = []
 
82
    @io.each_byte do |c|
 
83
      res << c
 
84
    end
 
85
    assert_equal([97, 98, 99], res)
 
86
  end
 
87
 
66
88
end if defined?(OpenSSL)