summaryrefslogtreecommitdiff
path: root/test/-ext-
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-06-22 09:55:27 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-06-22 09:55:27 +0000
commit8f0c3ff6e49fad5263f9be52946e1c13f9bcf021 (patch)
treef4ee1165986a8f3041cccff6abf672566cc9607e /test/-ext-
parentd73b9320cc2a19829ad089f0ec12490a10547a51 (diff)
* 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
Diffstat (limited to 'test/-ext-')
-rw-r--r--test/-ext-/bignum/test_pack.rb21
1 files changed, 21 insertions, 0 deletions
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