PageRenderTime 44ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/test/externals/ruby1.8/digest/test_digest.rb

https://bitbucket.org/nicksieger/jruby
Ruby | 120 lines | 92 code | 22 blank | 6 comment | 7 complexity | 85a2d5fd6abf1d8a6b119398ddcb7fb0 MD5 | raw file
Possible License(s): GPL-3.0, JSON
  1. #!/usr/bin/env ruby
  2. #
  3. # $RoughId: test.rb,v 1.4 2001/07/13 15:38:27 knu Exp $
  4. # $Id: test_digest.rb 11708 2007-02-12 23:01:19Z shyouhei $
  5. require 'test/unit'
  6. require 'digest'
  7. %w[digest/md5 digest/rmd160 digest/sha1 digest/sha2].each do |lib|
  8. begin
  9. require lib
  10. rescue LoadError
  11. end
  12. end
  13. module TestDigest
  14. Data1 = "abc"
  15. Data2 = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"
  16. def test_s_hexdigest
  17. self.class::DATA.each do |str, digest|
  18. assert_equal(digest, self.class::ALGO.hexdigest(str))
  19. end
  20. end
  21. def test_s_digest
  22. self.class::DATA.each do |str, digest|
  23. assert_equal([digest].pack("H*"), self.class::ALGO.digest(str))
  24. end
  25. end
  26. def test_update
  27. # This test is also for digest() and hexdigest()
  28. str = "ABC"
  29. md = self.class::ALGO.new
  30. md.update str
  31. assert_equal(self.class::ALGO.hexdigest(str), md.hexdigest)
  32. assert_equal(self.class::ALGO.digest(str), md.digest)
  33. end
  34. def test_eq
  35. # This test is also for clone()
  36. md1 = self.class::ALGO.new
  37. md1 << "ABC"
  38. assert_equal(md1, md1.clone, self.class::ALGO)
  39. md2 = self.class::ALGO.new
  40. md2 << "A"
  41. assert(md1 != md2, self.class::ALGO)
  42. md2 << "BC"
  43. assert_equal(md1, md2, self.class::ALGO)
  44. end
  45. def test_instance_eval
  46. assert_nothing_raised {
  47. self.class::ALGO.new.instance_eval { update "a" }
  48. }
  49. end
  50. class TestMD5 < Test::Unit::TestCase
  51. include TestDigest
  52. ALGO = Digest::MD5
  53. DATA = {
  54. Data1 => "900150983cd24fb0d6963f7d28e17f72",
  55. Data2 => "8215ef0796a20bcaaae116d3876c664a",
  56. }
  57. end if defined?(Digest::MD5)
  58. class TestSHA1 < Test::Unit::TestCase
  59. include TestDigest
  60. ALGO = Digest::SHA1
  61. DATA = {
  62. Data1 => "a9993e364706816aba3e25717850c26c9cd0d89d",
  63. Data2 => "84983e441c3bd26ebaae4aa1f95129e5e54670f1",
  64. }
  65. end if defined?(Digest::SHA1)
  66. class TestSHA256 < Test::Unit::TestCase
  67. include TestDigest
  68. ALGO = Digest::SHA256
  69. DATA = {
  70. Data1 => "ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad",
  71. Data2 => "248d6a61d20638b8e5c026930c3e6039a33ce45964ff2167f6ecedd419db06c1",
  72. }
  73. end if defined?(Digest::SHA256)
  74. class TestSHA384 < Test::Unit::TestCase
  75. include TestDigest
  76. ALGO = Digest::SHA384
  77. DATA = {
  78. Data1 => "cb00753f45a35e8bb5a03d699ac65007272c32ab0eded1631a8b605a43ff5bed8086072ba1e7cc2358baeca134c825a7",
  79. Data2 => "3391fdddfc8dc7393707a65b1b4709397cf8b1d162af05abfe8f450de5f36bc6b0455a8520bc4e6f5fe95b1fe3c8452b",
  80. }
  81. end if defined?(Digest::SHA384)
  82. class TestSHA512 < Test::Unit::TestCase
  83. include TestDigest
  84. ALGO = Digest::SHA512
  85. DATA = {
  86. Data1 => "ddaf35a193617abacc417349ae20413112e6fa4e89a97ea20a9eeee64b55d39a2192992a274fc1a836ba3c23a3feebbd454d4423643ce80e2a9ac94fa54ca49f",
  87. Data2 => "204a8fc6dda82f0a0ced7beb8e08a41657c16ef468b228a8279be331a703c33596fd15c13b1b07f9aa1d3bea57789ca031ad85c7a71dd70354ec631238ca3445",
  88. }
  89. end if defined?(Digest::SHA512)
  90. class TestRMD160 < Test::Unit::TestCase
  91. include TestDigest
  92. ALGO = Digest::RMD160
  93. DATA = {
  94. Data1 => "8eb208f7e05d987a9b044a8e98c6b087f15a0bfc",
  95. Data2 => "12a053384a9c0c88e405a06c27dcf49ada62eb2b",
  96. }
  97. end if defined?(Digest::RMD160)
  98. end