summaryrefslogtreecommitdiff
path: root/test/-ext-/bignum
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-06-07 12:41:02 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-06-07 12:41:02 +0000
commita08b001100734a3db4efbe9d38d3226950a538e0 (patch)
tree365b7af5aaa31ce9415c7df99f23854a3ab85314 /test/-ext-/bignum
parent07b72b8c856353096fad39a7f628e9076533dc18 (diff)
* bignum.c (rb_integer_pack): Renamed from rb_int_export.
(rb_integer_unpack): Renamed from rb_int_import. * internal.h, pack.c: Follow the above change. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41147 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/-ext-/bignum')
-rw-r--r--test/-ext-/bignum/test_export.rb67
-rw-r--r--test/-ext-/bignum/test_import.rb54
-rw-r--r--test/-ext-/bignum/test_pack.rb112
3 files changed, 112 insertions, 121 deletions
diff --git a/test/-ext-/bignum/test_export.rb b/test/-ext-/bignum/test_export.rb
deleted file mode 100644
index 3c1fc2e5e7e..00000000000
--- a/test/-ext-/bignum/test_export.rb
+++ /dev/null
@@ -1,67 +0,0 @@
-# coding: ASCII-8BIT
-
-require 'test/unit'
-require "-test-/bignum"
-
-class TestBignum < Test::Unit::TestCase
- class TestExport < Test::Unit::TestCase
- def test_export_zero
- assert_equal([0, "", 0], 0.test_export(nil, 1, 1, 1, 0))
- end
-
- def test_argument_check
- assert_raise(ArgumentError) { 0.test_export(nil, 0, 1, 1, 0) }
- assert_raise(ArgumentError) { 0.test_export(nil, 1, 1, 2, 0) }
- assert_raise(ArgumentError) { 0.test_export(nil, 1, 0, 1, 0) }
- assert_raise(ArgumentError) { 0.test_export(nil, 1, 1, 1, 8) }
-
- # assume sizeof(ssize_t) == sizeof(intptr_t)
- assert_raise(ArgumentError) { 0.test_export(nil, 1, 1 << ([""].pack("p").length * 8 - 1), 1, 0) }
- end
-
- def test_export_wordsize
- assert_equal([1, "\x01", 1], 1.test_export(nil, 1, 1, 1, 0))
- assert_equal([1, "\x00\x01", 1], 1.test_export(nil, 1, 2, 1, 0))
- assert_equal([1, "\x00\x00\x01", 1], 1.test_export(nil, 1, 3, 1, 0))
- assert_equal([1, "\x01", 1], 1.test_export(nil, 1, 1, -1, 0))
- assert_equal([1, "\x01\x00", 1], 1.test_export(nil, 1, 2, -1, 0))
- assert_equal([1, "\x01\x00\x00", 1], 1.test_export(nil, 1, 3, -1, 0))
- end
-
- def test_export_fixed_buffer
- assert_equal([0, "\x00\x00", 2], 0.test_export("xx", 1, 1, 1, 0))
- assert_equal([1, "\x00\x01", 2], 0x01.test_export("xx", 1, 1, 1, 0))
- assert_equal([1, "\x02\x01", 2], 0x0201.test_export("xx", 1, 1, 1, 0))
- assert_equal([2, "\x02\x01", 2], 0x030201.test_export("xx", 1, 1, 1, 0))
- assert_equal([2, "\x02\x01", 2], 0x04030201.test_export("xx", 1, 1, 1, 0))
- assert_equal([0, "\x00\x00", 2], 0.test_export("xx", -1, 1, 1, 0))
- assert_equal([1, "\x01\x00", 2], 0x01.test_export("xx", -1, 1, 1, 0))
- assert_equal([1, "\x01\x02", 2], 0x0201.test_export("xx", -1, 1, 1, 0))
- assert_equal([2, "\x01\x02", 2], 0x030201.test_export("xx", -1, 1, 1, 0))
- assert_equal([2, "\x01\x02", 2], 0x04030201.test_export("xx", -1, 1, 1, 0))
- end
-
- def test_export_wordorder_and_endian
- assert_equal([1, "\x12\x34\x56\x78", 2], 0x12345678.test_export(nil, 1, 2, 1, 0))
- assert_equal([1, "\x34\x12\x78\x56", 2], 0x12345678.test_export(nil, 1, 2, -1, 0))
- assert_equal([1, "\x56\x78\x12\x34", 2], 0x12345678.test_export(nil, -1, 2, 1, 0))
- assert_equal([1, "\x78\x56\x34\x12", 2], 0x12345678.test_export(nil, -1, 2, -1, 0))
- end
-
- def test_export_native_endian
- assert_equal([1, [0x1234].pack("S!"), 1], 0x1234.test_export(nil, 1, 2, 0, 0))
- end
-
- def test_export_nail
- assert_equal([1, "\x01\x00\x00\x00\x01\x01", 6], 0b100011.test_export(nil, 1, 1, 1, 7))
- assert_equal([1, "\x01\x02\x03\x04\x05\x06\x07\x08", 8], 0x12345678.test_export(nil, 1, 1, 1, 4))
- assert_equal([1, "\x00\x12\x00\x34\x00\x56\x00\x78", 4], 0x12345678.test_export(nil, 1, 2, 1, 8))
- end
-
- def test_export_sign
- assert_equal([-1, "\x01", 1], (-1).test_export(nil, 1, 1, 1, 0))
- assert_equal([-1, "\x80\x70\x60\x50\x40\x30\x20\x10", 8], (-0x8070605040302010).test_export(nil, 1, 1, 1, 0))
- end
-
- end
-end
diff --git a/test/-ext-/bignum/test_import.rb b/test/-ext-/bignum/test_import.rb
deleted file mode 100644
index 5a456508fc7..00000000000
--- a/test/-ext-/bignum/test_import.rb
+++ /dev/null
@@ -1,54 +0,0 @@
-# coding: ASCII-8BIT
-
-require 'test/unit'
-require "-test-/bignum"
-
-class TestBignum < Test::Unit::TestCase
- class TestImport < Test::Unit::TestCase
- def test_import_zero
- assert_equal(0, Integer.test_import(0, "", 1, 1, 1, 1, 0))
- end
-
- def test_argument_check
- assert_raise(ArgumentError) { Integer.test_import(1, "x", 1, 0, 1, 1, 0) }
- assert_raise(ArgumentError) { Integer.test_import(1, "x", 1, 1, 1, 2, 0) }
- assert_raise(ArgumentError) { Integer.test_import(1, "x", 1, 1, 0, 1, 0) }
- assert_raise(ArgumentError) { Integer.test_import(1, "x", 1, 1, 1, 1, 8) }
-
- # assume sizeof(ssize_t) == sizeof(intptr_t)
- assert_raise(ArgumentError) { Integer.test_import(1, "x", 1, 1, 1 << ([""].pack("p").length * 8 - 1), 1, 0) }
- end
-
- def test_import_wordsize
- assert_equal(1, Integer.test_import(1, "\x01", 1, 1, 1, 1, 0))
- assert_equal(1, Integer.test_import(1, "\x00\x01", 1, 1, 2, 1, 0))
- assert_equal(1, Integer.test_import(1, "\x00\x00\x01", 1, 1, 3, 1, 0))
- assert_equal(1, Integer.test_import(1, "\x01", 1, 1, 1, -1, 0))
- assert_equal(1, Integer.test_import(1, "\x01\x00", 1, 1, 2, -1, 0))
- assert_equal(1, Integer.test_import(1, "\x01\x00\x00", 1, 1, 3, -1, 0))
- end
-
- def test_import_wordorder_and_endian
- assert_equal(0x01020304, Integer.test_import(1, "\x01\x02\x03\x04", 2, 1, 2, 1, 0))
- assert_equal(0x02010403, Integer.test_import(1, "\x01\x02\x03\x04", 2, 1, 2, -1, 0))
- assert_equal(0x03040102, Integer.test_import(1, "\x01\x02\x03\x04", 2, -1, 2, 1, 0))
- assert_equal(0x04030201, Integer.test_import(1, "\x01\x02\x03\x04", 2, -1, 2, -1, 0))
- end
-
- def test_import_native_endian
- assert_equal("\x12\x34".unpack("S!")[0], Integer.test_import(1, "\x12\x34", 1, 1, 2, 0, 0))
- end
-
- def test_import_nail
- assert_equal(0b100011, Integer.test_import(1, "\x01\x00\x00\x00\x01\x01", 6, 1, 1, 1, 7))
- assert_equal(0x12345678, Integer.test_import(1, "\x01\x02\x03\x04\x05\x06\x07\x08", 8, 1, 1, 1, 4))
- assert_equal(0x12345678, Integer.test_import(1, "\x00\x12\x00\x34\x00\x56\x00\x78", 4, 1, 2, 1, 8))
- end
-
- def test_import_sign
- assert_equal(-1, Integer.test_import(-1, "\x01", 1, 1, 1, 1, 0))
- assert_equal(-0x8070605040302010, Integer.test_import(-1, "\x80\x70\x60\x50\x40\x30\x20\x10", 8, 1, 1, 1, 0))
- end
-
- end
-end
diff --git a/test/-ext-/bignum/test_pack.rb b/test/-ext-/bignum/test_pack.rb
new file mode 100644
index 00000000000..3dae0275394
--- /dev/null
+++ b/test/-ext-/bignum/test_pack.rb
@@ -0,0 +1,112 @@
+# coding: ASCII-8BIT
+
+require 'test/unit'
+require "-test-/bignum"
+
+class TestBignum < Test::Unit::TestCase
+ class TestPack < Test::Unit::TestCase
+ def test_pack_zero
+ assert_equal([0, "", 0], 0.test_pack(nil, 1, 1, 1, 0))
+ end
+
+ def test_argument_check
+ assert_raise(ArgumentError) { 0.test_pack(nil, 0, 1, 1, 0) }
+ assert_raise(ArgumentError) { 0.test_pack(nil, 1, 1, 2, 0) }
+ assert_raise(ArgumentError) { 0.test_pack(nil, 1, 0, 1, 0) }
+ assert_raise(ArgumentError) { 0.test_pack(nil, 1, 1, 1, 8) }
+
+ # assume sizeof(ssize_t) == sizeof(intptr_t)
+ assert_raise(ArgumentError) { 0.test_pack(nil, 1, 1 << ([""].pack("p").length * 8 - 1), 1, 0) }
+ end
+
+ def test_pack_wordsize
+ assert_equal([1, "\x01", 1], 1.test_pack(nil, 1, 1, 1, 0))
+ assert_equal([1, "\x00\x01", 1], 1.test_pack(nil, 1, 2, 1, 0))
+ assert_equal([1, "\x00\x00\x01", 1], 1.test_pack(nil, 1, 3, 1, 0))
+ assert_equal([1, "\x01", 1], 1.test_pack(nil, 1, 1, -1, 0))
+ assert_equal([1, "\x01\x00", 1], 1.test_pack(nil, 1, 2, -1, 0))
+ assert_equal([1, "\x01\x00\x00", 1], 1.test_pack(nil, 1, 3, -1, 0))
+ end
+
+ def test_pack_fixed_buffer
+ assert_equal([0, "\x00\x00", 2], 0.test_pack("xx", 1, 1, 1, 0))
+ assert_equal([1, "\x00\x01", 2], 0x01.test_pack("xx", 1, 1, 1, 0))
+ assert_equal([1, "\x02\x01", 2], 0x0201.test_pack("xx", 1, 1, 1, 0))
+ assert_equal([2, "\x02\x01", 2], 0x030201.test_pack("xx", 1, 1, 1, 0))
+ assert_equal([2, "\x02\x01", 2], 0x04030201.test_pack("xx", 1, 1, 1, 0))
+ assert_equal([0, "\x00\x00", 2], 0.test_pack("xx", -1, 1, 1, 0))
+ assert_equal([1, "\x01\x00", 2], 0x01.test_pack("xx", -1, 1, 1, 0))
+ assert_equal([1, "\x01\x02", 2], 0x0201.test_pack("xx", -1, 1, 1, 0))
+ assert_equal([2, "\x01\x02", 2], 0x030201.test_pack("xx", -1, 1, 1, 0))
+ assert_equal([2, "\x01\x02", 2], 0x04030201.test_pack("xx", -1, 1, 1, 0))
+ end
+
+ def test_pack_wordorder_and_endian
+ assert_equal([1, "\x12\x34\x56\x78", 2], 0x12345678.test_pack(nil, 1, 2, 1, 0))
+ assert_equal([1, "\x34\x12\x78\x56", 2], 0x12345678.test_pack(nil, 1, 2, -1, 0))
+ assert_equal([1, "\x56\x78\x12\x34", 2], 0x12345678.test_pack(nil, -1, 2, 1, 0))
+ assert_equal([1, "\x78\x56\x34\x12", 2], 0x12345678.test_pack(nil, -1, 2, -1, 0))
+ end
+
+ def test_pack_native_endian
+ assert_equal([1, [0x1234].pack("S!"), 1], 0x1234.test_pack(nil, 1, 2, 0, 0))
+ end
+
+ def test_pack_nail
+ assert_equal([1, "\x01\x00\x00\x00\x01\x01", 6], 0b100011.test_pack(nil, 1, 1, 1, 7))
+ assert_equal([1, "\x01\x02\x03\x04\x05\x06\x07\x08", 8], 0x12345678.test_pack(nil, 1, 1, 1, 4))
+ assert_equal([1, "\x00\x12\x00\x34\x00\x56\x00\x78", 4], 0x12345678.test_pack(nil, 1, 2, 1, 8))
+ end
+
+ def test_pack_sign
+ assert_equal([-1, "\x01", 1], (-1).test_pack(nil, 1, 1, 1, 0))
+ assert_equal([-1, "\x80\x70\x60\x50\x40\x30\x20\x10", 8], (-0x8070605040302010).test_pack(nil, 1, 1, 1, 0))
+ end
+
+ def test_unpack_zero
+ assert_equal(0, Integer.test_unpack(0, "", 1, 1, 1, 1, 0))
+ end
+
+ def test_argument_check
+ assert_raise(ArgumentError) { Integer.test_unpack(1, "x", 1, 0, 1, 1, 0) }
+ assert_raise(ArgumentError) { Integer.test_unpack(1, "x", 1, 1, 1, 2, 0) }
+ assert_raise(ArgumentError) { Integer.test_unpack(1, "x", 1, 1, 0, 1, 0) }
+ assert_raise(ArgumentError) { Integer.test_unpack(1, "x", 1, 1, 1, 1, 8) }
+
+ # assume sizeof(ssize_t) == sizeof(intptr_t)
+ assert_raise(ArgumentError) { Integer.test_unpack(1, "x", 1, 1, 1 << ([""].pack("p").length * 8 - 1), 1, 0) }
+ end
+
+ def test_unpack_wordsize
+ assert_equal(1, Integer.test_unpack(1, "\x01", 1, 1, 1, 1, 0))
+ assert_equal(1, Integer.test_unpack(1, "\x00\x01", 1, 1, 2, 1, 0))
+ assert_equal(1, Integer.test_unpack(1, "\x00\x00\x01", 1, 1, 3, 1, 0))
+ assert_equal(1, Integer.test_unpack(1, "\x01", 1, 1, 1, -1, 0))
+ assert_equal(1, Integer.test_unpack(1, "\x01\x00", 1, 1, 2, -1, 0))
+ assert_equal(1, Integer.test_unpack(1, "\x01\x00\x00", 1, 1, 3, -1, 0))
+ end
+
+ def test_unpack_wordorder_and_endian
+ assert_equal(0x01020304, Integer.test_unpack(1, "\x01\x02\x03\x04", 2, 1, 2, 1, 0))
+ assert_equal(0x02010403, Integer.test_unpack(1, "\x01\x02\x03\x04", 2, 1, 2, -1, 0))
+ assert_equal(0x03040102, Integer.test_unpack(1, "\x01\x02\x03\x04", 2, -1, 2, 1, 0))
+ assert_equal(0x04030201, Integer.test_unpack(1, "\x01\x02\x03\x04", 2, -1, 2, -1, 0))
+ end
+
+ def test_unpack_native_endian
+ assert_equal("\x12\x34".unpack("S!")[0], Integer.test_unpack(1, "\x12\x34", 1, 1, 2, 0, 0))
+ end
+
+ def test_unpack_nail
+ assert_equal(0b100011, Integer.test_unpack(1, "\x01\x00\x00\x00\x01\x01", 6, 1, 1, 1, 7))
+ assert_equal(0x12345678, Integer.test_unpack(1, "\x01\x02\x03\x04\x05\x06\x07\x08", 8, 1, 1, 1, 4))
+ assert_equal(0x12345678, Integer.test_unpack(1, "\x00\x12\x00\x34\x00\x56\x00\x78", 4, 1, 2, 1, 8))
+ end
+
+ def test_unpack_sign
+ assert_equal(-1, Integer.test_unpack(-1, "\x01", 1, 1, 1, 1, 0))
+ assert_equal(-0x8070605040302010, Integer.test_unpack(-1, "\x80\x70\x60\x50\x40\x30\x20\x10", 8, 1, 1, 1, 0))
+ end
+
+ end
+end