1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

add tests.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@18635 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
akr 2008-08-15 00:18:42 +00:00
parent 520cd6d186
commit b9d5d6a137

View file

@ -163,6 +163,44 @@ class TestEncodingConverter < Test::Unit::TestCase
check_ec("abcdef", "", :finished, *a)
end
def test_invalid_utf16le
ec = Encoding::Converter.new("UTF-16LE", "UTF-8")
a = ["", src="", ec, nil, 50, Encoding::Converter::PARTIAL_INPUT]
src << "A"; check_ec("", "", :source_buffer_empty, *a)
src << "\x00"; check_ec("A", "", :source_buffer_empty, *a)
src << "\x00"; check_ec("A", "", :source_buffer_empty, *a)
src << "\xd8"; check_ec("A", "", :source_buffer_empty, *a)
src << "\x01"; check_ec("A", "", :source_buffer_empty, *a)
src << "\x02"; check_ec("A", "", :invalid_byte_sequence, *a)
src << "\x03"; check_ec("A\u{0201}", "", :source_buffer_empty, *a)
src << "\x04"; check_ec("A\u{0201}\u{0403}", "", :source_buffer_empty, *a)
src << "\x00"; check_ec("A\u{0201}\u{0403}", "", :source_buffer_empty, *a)
src << "\xd8"; check_ec("A\u{0201}\u{0403}", "", :source_buffer_empty, *a)
src << "\x00"; check_ec("A\u{0201}\u{0403}", "", :source_buffer_empty, *a)
src << "\xd8"; check_ec("A\u{0201}\u{0403}", "", :invalid_byte_sequence, *a)
src << "\x00"; check_ec("A\u{0201}\u{0403}", "", :source_buffer_empty, *a)
src << "\xdc"; check_ec("A\u{0201}\u{0403}\u{10000}", "", :source_buffer_empty, *a)
end
def test_invalid_utf16be
ec = Encoding::Converter.new("UTF-16BE", "UTF-8")
a = ["", src="", ec, nil, 50, Encoding::Converter::PARTIAL_INPUT]
src << "\x00"; check_ec("", "", :source_buffer_empty, *a)
src << "A"; check_ec("A", "", :source_buffer_empty, *a)
src << "\xd8"; check_ec("A", "", :source_buffer_empty, *a)
src << "\x00"; check_ec("A", "", :source_buffer_empty, *a)
src << "\x02"; check_ec("A", "", :invalid_byte_sequence, *a)
src << "\x01"; check_ec("A\u{0201}", "", :source_buffer_empty, *a)
src << "\x04"; check_ec("A\u{0201}", "", :source_buffer_empty, *a)
src << "\x03"; check_ec("A\u{0201}\u{0403}", "", :source_buffer_empty, *a)
src << "\xd8"; check_ec("A\u{0201}\u{0403}", "", :source_buffer_empty, *a)
src << "\x00"; check_ec("A\u{0201}\u{0403}", "", :source_buffer_empty, *a)
src << "\xd8"; check_ec("A\u{0201}\u{0403}", "", :invalid_byte_sequence, *a)
src << "\x00"; check_ec("A\u{0201}\u{0403}", "", :source_buffer_empty, *a)
src << "\xdc"; check_ec("A\u{0201}\u{0403}", "", :source_buffer_empty, *a)
src << "\x00"; check_ec("A\u{0201}\u{0403}\u{10000}", "", :source_buffer_empty, *a)
end
def test_errors
ec = Encoding::Converter.new("UTF-16BE", "EUC-JP")
a = ["", "\xFF\xFE\x00A\xDC\x00\x00B", ec, nil, 10]