Sha256: 957e98b722c52638e40234ffd055bd9e22633dbc568a5e1fd8af3cee4946c3e8

Contents?: true

Size: 1.33 KB

Versions: 1

Compression:

Stored size: 1.33 KB

Contents

require 'tmail/base64'
require 'test/unit'

class TestTMailBase64 < Test::Unit::TestCase
  def try(orig)
    ok = [orig].pack('m').delete("\r\n")
    result = TMail::Base64.c_encode(orig)
    assert_equal ok, result, "str=#{orig.inspect}"
    assert_equal orig, TMail::Base64.c_decode(result), "str=#{orig.inspect}"
  end

  def test_normal
    try ''
    try 'a'
    try 'ab'
    try 'abc'
    try 'abcd'
    try 'abcde'
    try 'abcdef'
    try 'abcdefg'
    try 'abcdefgh'
    try 'abcdefghi'
    try 'abcdefghij'
    try 'abcdefghijk'
    try 'abcdefghijkl'
    try 'abcdefghijklm'
    try 'abcdefghijklmn'
    try 'abcdefghijklmno'
    try 'abcdefghijklmnop'
    try 'abcdefghijklmnopq'
    try 'abcdefghijklmnopqr'
    try 'abcdefghijklmnopqrs'
    try 'abcdefghijklmnopqrst'
    try 'abcdefghijklmnopqrstu'
    try 'abcdefghijklmnopqrstuv'
    try 'abcdefghijklmnopqrstuvw'
    try 'abcdefghijklmnopqrstuvwx'
    try 'abcdefghijklmnopqrstuvwxy'
    try 'abcdefghijklmnopqrstuvwxyz'
  end

  def test_dangerous_chars
    ["\0", "\001", "\002", "\003", "\0xfd", "\0xfe", "\0xff"].each do |ch|
      1.upto(96) do |len|
        try ch * len
      end
    end
  end

  def test_random
    16.times do
      try make_random_string(96)
    end
  end

  def make_random_string(len)
    buf = ''
    len.times do
      buf << rand(255)
    end
    buf
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
tmail-1.1.1 test/test_base64.rb