aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorrhe <rhe@ruby-lang.org>2016-05-18 02:55:45 +0000
committerKazuki Yamaguchi <k@rhe.jp>2016-05-31 11:31:27 +0900
commit494db323a5b7313321fb8145df6cf1800146e1cb (patch)
tree05e602c2e3ad1d19131612cd3de01d8ef8233792 /test
parent92812fddde3999cfe98af172c0e6ffa010a2cbf1 (diff)
downloadruby-openssl-494db323a5b7313321fb8145df6cf1800146e1cb.tar.gz
openssl: fix equality test methods of OpenSSL::BN
* ext/openssl/ossl_bn.c (try_convert_to_bnptr): Extracted from GetBNPtr(). This doesn't raise exception but returns NULL on error. (GetBNPtr): Raise TypeError if conversion fails. (ossl_bn_eq): Implement BN#==. (ossl_bn_eql): #eql? should not raise TypeError even if the argument is not compatible with BN. (ossl_bn_hash): Implement BN#hash. * ext/openssl/ossl_bn.c (Init_ossl_bn): Define #== and #hash. * test/openssl/test_bn.rb: Test BN#eql?, #== and #hash git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55047 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test')
-rw-r--r--test/test_bn.rb16
1 files changed, 12 insertions, 4 deletions
diff --git a/test/test_bn.rb b/test/test_bn.rb
index 848d1feb..415bd74c 100644
--- a/test/test_bn.rb
+++ b/test/test_bn.rb
@@ -43,10 +43,18 @@ class OpenSSL::TestBN < Test::Unit::TestCase
assert_equal(true, OpenSSL::BN.new((2 ** 127 - 1).to_s(16), 16).prime?(1))
end
- def test_cmp_nil
- bn = OpenSSL::BN.new('1')
- assert_equal(false, bn == nil)
- assert_equal(true, bn != nil)
+ def test_cmp
+ bn1 = OpenSSL::BN.new('1')
+ bn2 = OpenSSL::BN.new('1')
+ bn3 = OpenSSL::BN.new('2')
+ assert_equal(false, bn1 == nil)
+ assert_equal(true, bn1 != nil)
+ assert_equal(true, bn1 == bn2)
+ assert_equal(false, bn1 == bn3)
+ assert_equal(true, bn1.eql?(bn2))
+ assert_equal(false, bn1.eql?(bn3))
+ assert_equal(bn1.hash, bn2.hash)
+ assert_not_equal(bn3.hash, bn1.hash)
end
end