From 8f0c3ff6e49fad5263f9be52946e1c13f9bcf021 Mon Sep 17 00:00:00 2001 From: akr Date: Sat, 22 Jun 2013 09:55:27 +0000 Subject: * bignum.c (bary_pack): Support INTEGER_PACK_FORCE_GENERIC_IMPLEMENTATION flag. Fix byte order and word order handling in code specialized for wordsize % SIZEOF_BDIGITS == 0. * internal.h (INTEGER_PACK_FORCE_GENERIC_IMPLEMENTATION): Defined. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41565 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/-ext-/bignum/test_pack.rb | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'test/-ext-/bignum') diff --git a/test/-ext-/bignum/test_pack.rb b/test/-ext-/bignum/test_pack.rb index 202395324b..fddc69b792 100644 --- a/test/-ext-/bignum/test_pack.rb +++ b/test/-ext-/bignum/test_pack.rb @@ -15,6 +15,7 @@ class TestBignum < Test::Unit::TestCase LITTLE_ENDIAN = Integer::INTEGER_PACK_LITTLE_ENDIAN BIG_ENDIAN = Integer::INTEGER_PACK_BIG_ENDIAN NEGATIVE = Integer::INTEGER_PACK_NEGATIVE + GENERIC = Integer::INTEGER_PACK_FORCE_GENERIC_IMPLEMENTATION def test_pack_zero assert_equal([0, ""], 0.test_pack(0, 1, 0, BIG_ENDIAN)) @@ -123,6 +124,25 @@ class TestBignum < Test::Unit::TestCase assert_equal([-1, "\x80\x70\x60\x50\x40\x30\x20\x10"], (-0x8070605040302010).test_pack(8, 1, 0, BIG_ENDIAN)) end + def test_pack_orders + [MSWORD_FIRST, LSWORD_FIRST].each {|word_order| + [MSBYTE_FIRST, LSBYTE_FIRST, NATIVE_BYTE_ORDER].each {|byte_order| + 1.upto(16) {|wordsize| + 1.upto(20) {|numwords| + w = numwords*wordsize + n = 0; + 0.upto(w) {|i| + n |= ((i+1) % 256) << (i*8) + } + assert_equal(n.test_pack(numwords, wordsize, 0, word_order|byte_order|GENERIC), + n.test_pack(numwords, wordsize, 0, word_order|byte_order), + "#{'%#x' % n}.test_pack(#{numwords}, #{wordsize}, 0, #{'%#x' % (word_order|byte_order)})") + } + } + } + } + end + def test_pack2comp_zero assert_equal([0, ""], 0.test_pack(0, 1, 0, TWOCOMP|BIG_ENDIAN)) end @@ -273,6 +293,7 @@ class TestBignum < Test::Unit::TestCase def test_unpack2comp_negative_zero 0.upto(100) {|n| assert_equal(-(256**n), Integer.test_unpack("\x00"*n, n, 1, 0, TWOCOMP|BIG_ENDIAN|NEGATIVE)) + assert_equal(-(256**n), Integer.test_unpack("\x00"*n, n, 1, 0, TWOCOMP|LITTLE_ENDIAN|NEGATIVE)) } end end -- cgit v1.2.3