ruby-changes:14877
From: knu <ko1@a...>
Date: Wed, 24 Feb 2010 02:36:24 +0900 (JST)
Subject: [ruby-changes:14877] Ruby:r26744 (trunk): Add some more tests, revisited.
knu 2010-02-24 02:36:12 +0900 (Wed, 24 Feb 2010) New Revision: 26744 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=26744 Log: Add some more tests, revisited. Modified files: trunk/test/openssl/test_hmac.rb Index: test/openssl/test_hmac.rb =================================================================== --- test/openssl/test_hmac.rb (revision 26743) +++ test/openssl/test_hmac.rb (revision 26744) @@ -4,15 +4,13 @@ end require "test/unit" -if defined?(OpenSSL) - class OpenSSL::TestHMAC < Test::Unit::TestCase def setup - @digest = OpenSSL::Digest::MD5.new + @digest = OpenSSL::Digest::MD5 @key = "KEY" @data = "DATA" - @h1 = OpenSSL::HMAC.new(@key, @digest) - @h2 = OpenSSL::HMAC.new(@key, @digest) + @h1 = OpenSSL::HMAC.new(@key, @digest.new) + @h2 = OpenSSL::HMAC.new(@key, "MD5") end def teardown @@ -20,8 +18,14 @@ def test_hmac @h1.update(@data) - assert_equal(OpenSSL::HMAC.digest(@digest, @key, @data), @h1.digest, "digest") - assert_equal(OpenSSL::HMAC.hexdigest(@digest, @key, @data), @h1.hexdigest, "hexdigest") + @h2.update(@data) + assert_equal(@h1.digest, @h2.digest) + + assert_equal(OpenSSL::HMAC.digest(@digest.new, @key, @data), @h1.digest, "digest") + assert_equal(OpenSSL::HMAC.hexdigest(@digest.new, @key, @data), @h1.hexdigest, "hexdigest") + + assert_equal(OpenSSL::HMAC.digest("MD5", @key, @data), @h2.digest, "digest") + assert_equal(OpenSSL::HMAC.hexdigest("MD5", @key, @data), @h2.hexdigest, "hexdigest") end def test_dup @@ -29,6 +33,4 @@ h = @h1.dup assert_equal(@h1.digest, h.digest, "dup digest") end -end - -end +end if defined?(OpenSSL) -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/