PageRenderTime 38ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/test/externals/ruby1.9/zlib/test_zlib.rb

https://bitbucket.org/nicksieger/jruby
Ruby | 698 lines | 585 code | 110 blank | 3 comment | 1 complexity | 90a0e111b74d18729aec6f2c4ba17ea1 MD5 | raw file
Possible License(s): GPL-3.0, JSON
  1. require 'test/unit'
  2. require 'stringio'
  3. require 'tempfile'
  4. begin
  5. require 'zlib'
  6. rescue LoadError
  7. end
  8. if defined? Zlib
  9. class TestZlibDeflate < Test::Unit::TestCase
  10. def test_initialize
  11. z = Zlib::Deflate.new
  12. s = z.deflate("foo", Zlib::FINISH)
  13. assert_equal("foo", Zlib::Inflate.inflate(s))
  14. z = Zlib::Deflate.new
  15. s = z.deflate("foo")
  16. s << z.deflate(nil, Zlib::FINISH)
  17. assert_equal("foo", Zlib::Inflate.inflate(s))
  18. assert_raise(Zlib::StreamError) { Zlib::Deflate.new(10000) }
  19. end
  20. def test_dup
  21. z1 = Zlib::Deflate.new
  22. s = z1.deflate("foo")
  23. z2 = z1.dup
  24. s1 = s + z1.deflate("bar", Zlib::FINISH)
  25. s2 = s + z2.deflate("baz", Zlib::FINISH)
  26. assert_equal("foobar", Zlib::Inflate.inflate(s1))
  27. assert_equal("foobaz", Zlib::Inflate.inflate(s2))
  28. end
  29. def test_deflate
  30. s = Zlib::Deflate.deflate("foo")
  31. assert_equal("foo", Zlib::Inflate.inflate(s))
  32. assert_raise(Zlib::StreamError) { Zlib::Deflate.deflate("foo", 10000) }
  33. end
  34. def test_addstr
  35. z = Zlib::Deflate.new
  36. z << "foo"
  37. s = z.deflate(nil, Zlib::FINISH)
  38. assert_equal("foo", Zlib::Inflate.inflate(s))
  39. end
  40. def test_flush
  41. z = Zlib::Deflate.new
  42. z << "foo"
  43. s = z.flush
  44. z << "bar"
  45. s << z.flush_next_in
  46. z << "baz"
  47. s << z.flush_next_out
  48. s << z.deflate("qux", Zlib::FINISH)
  49. assert_equal("foobarbazqux", Zlib::Inflate.inflate(s))
  50. end
  51. def test_avail
  52. z = Zlib::Deflate.new
  53. assert_equal(0, z.avail_in)
  54. assert_equal(0, z.avail_out)
  55. z << "foo"
  56. z.avail_out += 100
  57. z << "bar"
  58. s = z.finish
  59. assert_equal("foobar", Zlib::Inflate.inflate(s))
  60. end
  61. def test_total
  62. z = Zlib::Deflate.new
  63. 1000.times { z << "foo" }
  64. s = z.finish
  65. assert_equal(3000, z.total_in)
  66. assert_operator(3000, :>, z.total_out)
  67. assert_equal("foo" * 1000, Zlib::Inflate.inflate(s))
  68. end
  69. def test_data_type
  70. z = Zlib::Deflate.new
  71. assert([Zlib::ASCII, Zlib::BINARY, Zlib::UNKNOWN].include?(z.data_type))
  72. end
  73. def test_adler
  74. z = Zlib::Deflate.new
  75. z << "foo"
  76. s = z.finish
  77. assert_equal(0x02820145, z.adler)
  78. end
  79. def test_finished_p
  80. z = Zlib::Deflate.new
  81. assert_equal(false, z.finished?)
  82. z << "foo"
  83. assert_equal(false, z.finished?)
  84. s = z.finish
  85. assert_equal(true, z.finished?)
  86. z.close
  87. assert_raise(Zlib::Error) { z.finished? }
  88. end
  89. def test_closed_p
  90. z = Zlib::Deflate.new
  91. assert_equal(false, z.closed?)
  92. z << "foo"
  93. assert_equal(false, z.closed?)
  94. s = z.finish
  95. assert_equal(false, z.closed?)
  96. z.close
  97. assert_equal(true, z.closed?)
  98. end
  99. def test_params
  100. z = Zlib::Deflate.new
  101. z << "foo"
  102. z.params(Zlib::DEFAULT_COMPRESSION, Zlib::DEFAULT_STRATEGY)
  103. z << "bar"
  104. s = z.finish
  105. assert_equal("foobar", Zlib::Inflate.inflate(s))
  106. data = ('a'..'z').to_a.join
  107. z = Zlib::Deflate.new(Zlib::NO_COMPRESSION, Zlib::MAX_WBITS,
  108. Zlib::DEF_MEM_LEVEL, Zlib::DEFAULT_STRATEGY)
  109. z << data[0, 10]
  110. z.params(Zlib::BEST_COMPRESSION, Zlib::DEFAULT_STRATEGY)
  111. z << data[10 .. -1]
  112. assert_equal(data, Zlib::Inflate.inflate(z.finish))
  113. z = Zlib::Deflate.new
  114. s = z.deflate("foo", Zlib::FULL_FLUSH)
  115. z.avail_out = 0
  116. z.params(Zlib::NO_COMPRESSION, Zlib::FILTERED)
  117. s << z.deflate("bar", Zlib::FULL_FLUSH)
  118. z.avail_out = 0
  119. z.params(Zlib::BEST_COMPRESSION, Zlib::HUFFMAN_ONLY)
  120. s << z.deflate("baz", Zlib::FINISH)
  121. assert_equal("foobarbaz", Zlib::Inflate.inflate(s))
  122. z = Zlib::Deflate.new
  123. assert_raise(Zlib::StreamError) { z.params(10000, 10000) }
  124. z.close # without this, outputs `zlib(finalizer): the stream was freed prematurely.'
  125. end
  126. def test_set_dictionary
  127. z = Zlib::Deflate.new
  128. z.set_dictionary("foo")
  129. s = z.deflate("foo" * 100, Zlib::FINISH)
  130. z = Zlib::Inflate.new
  131. assert_raise(Zlib::NeedDict) { z.inflate(s) }
  132. z.set_dictionary("foo")
  133. assert_equal("foo" * 100, z.inflate(s)) # ???
  134. z = Zlib::Deflate.new
  135. z << "foo"
  136. assert_raise(Zlib::StreamError) { z.set_dictionary("foo") }
  137. z.close # without this, outputs `zlib(finalizer): the stream was freed prematurely.'
  138. end
  139. def test_reset
  140. z = Zlib::Deflate.new
  141. z << "foo"
  142. z.reset
  143. z << "bar"
  144. s = z.finish
  145. assert_equal("bar", Zlib::Inflate.inflate(s))
  146. end
  147. def test_close
  148. z = Zlib::Deflate.new
  149. z.close
  150. assert_raise(Zlib::Error) { z << "foo" }
  151. assert_raise(Zlib::Error) { z.reset }
  152. end
  153. end
  154. class TestZlibInflate < Test::Unit::TestCase
  155. def test_initialize
  156. assert_raise(Zlib::StreamError) { Zlib::Inflate.new(-1) }
  157. s = Zlib::Deflate.deflate("foo")
  158. z = Zlib::Inflate.new
  159. z << s << nil
  160. assert_equal("foo", z.finish)
  161. end
  162. def test_inflate
  163. s = Zlib::Deflate.deflate("foo")
  164. z = Zlib::Inflate.new
  165. s = z.inflate(s)
  166. s << z.inflate(nil)
  167. assert_equal("foo", s)
  168. z.inflate("foo") # ???
  169. z << "foo" # ???
  170. end
  171. def test_sync
  172. z = Zlib::Deflate.new
  173. s = z.deflate("foo" * 1000, Zlib::FULL_FLUSH)
  174. z.avail_out = 0
  175. z.params(Zlib::NO_COMPRESSION, Zlib::FILTERED)
  176. s << z.deflate("bar" * 1000, Zlib::FULL_FLUSH)
  177. z.avail_out = 0
  178. z.params(Zlib::BEST_COMPRESSION, Zlib::HUFFMAN_ONLY)
  179. s << z.deflate("baz" * 1000, Zlib::FINISH)
  180. z = Zlib::Inflate.new
  181. assert_raise(Zlib::DataError) { z << "\0" * 100 }
  182. assert_equal(false, z.sync(""))
  183. assert_equal(false, z.sync_point?)
  184. z = Zlib::Inflate.new
  185. assert_raise(Zlib::DataError) { z << "\0" * 100 + s }
  186. assert_equal(true, z.sync(""))
  187. #assert_equal(true, z.sync_point?)
  188. z = Zlib::Inflate.new
  189. assert_equal(false, z.sync("\0" * 100))
  190. assert_equal(false, z.sync_point?)
  191. z = Zlib::Inflate.new
  192. assert_equal(true, z.sync("\0" * 100 + s))
  193. #assert_equal(true, z.sync_point?)
  194. end
  195. def test_set_dictionary
  196. z = Zlib::Inflate.new
  197. assert_raise(Zlib::StreamError) { z.set_dictionary("foo") }
  198. z.close
  199. end
  200. end
  201. class TestZlibGzipFile < Test::Unit::TestCase
  202. def test_to_io
  203. t = Tempfile.new("test_zlib_gzip_file")
  204. t.close
  205. Zlib::GzipWriter.open(t.path) {|gz| gz.print("foo") }
  206. f = Zlib::GzipReader.open(t.path)
  207. assert_kind_of(IO, f.to_io)
  208. end
  209. def test_crc
  210. t = Tempfile.new("test_zlib_gzip_file")
  211. t.close
  212. Zlib::GzipWriter.open(t.path) {|gz| gz.print("foo") }
  213. f = Zlib::GzipReader.open(t.path)
  214. f.read
  215. assert_equal(0x8c736521, f.crc)
  216. end
  217. def test_mtime
  218. tim = Time.now
  219. t = Tempfile.new("test_zlib_gzip_file")
  220. t.close
  221. Zlib::GzipWriter.open(t.path) do |gz|
  222. gz.mtime = -1
  223. gz.mtime = tim
  224. gz.print("foo")
  225. gz.flush
  226. assert_raise(Zlib::GzipFile::Error) { gz.mtime = Time.now }
  227. end
  228. f = Zlib::GzipReader.open(t.path)
  229. assert_equal(tim.to_i, f.mtime.to_i)
  230. end
  231. def test_level
  232. t = Tempfile.new("test_zlib_gzip_file")
  233. t.close
  234. Zlib::GzipWriter.open(t.path) {|gz| gz.print("foo") }
  235. f = Zlib::GzipReader.open(t.path)
  236. assert_equal(Zlib::DEFAULT_COMPRESSION, f.level)
  237. end
  238. def test_os_code
  239. t = Tempfile.new("test_zlib_gzip_file")
  240. t.close
  241. Zlib::GzipWriter.open(t.path) {|gz| gz.print("foo") }
  242. f = Zlib::GzipReader.open(t.path)
  243. assert_equal(Zlib::OS_CODE, f.os_code)
  244. end
  245. def test_orig_name
  246. t = Tempfile.new("test_zlib_gzip_file")
  247. t.close
  248. Zlib::GzipWriter.open(t.path) do |gz|
  249. gz.orig_name = "foobarbazqux\0quux"
  250. gz.print("foo")
  251. gz.flush
  252. assert_raise(Zlib::GzipFile::Error) { gz.orig_name = "quux" }
  253. end
  254. f = Zlib::GzipReader.open(t.path)
  255. assert_equal("foobarbazqux", f.orig_name)
  256. end
  257. def test_comment
  258. t = Tempfile.new("test_zlib_gzip_file")
  259. t.close
  260. Zlib::GzipWriter.open(t.path) do |gz|
  261. gz.comment = "foobarbazqux\0quux"
  262. gz.print("foo")
  263. gz.flush
  264. assert_raise(Zlib::GzipFile::Error) { gz.comment = "quux" }
  265. end
  266. f = Zlib::GzipReader.open(t.path)
  267. assert_equal("foobarbazqux", f.comment)
  268. end
  269. def test_lineno
  270. t = Tempfile.new("test_zlib_gzip_file")
  271. t.close
  272. Zlib::GzipWriter.open(t.path) {|gz| gz.print("foo\nbar\nbaz\nqux\n") }
  273. f = Zlib::GzipReader.open(t.path)
  274. assert_equal([0, "foo\n"], [f.lineno, f.gets])
  275. assert_equal([1, "bar\n"], [f.lineno, f.gets])
  276. f.lineno = 1000
  277. assert_equal([1000, "baz\n"], [f.lineno, f.gets])
  278. assert_equal([1001, "qux\n"], [f.lineno, f.gets])
  279. end
  280. def test_closed_p
  281. t = Tempfile.new("test_zlib_gzip_file")
  282. t.close
  283. Zlib::GzipWriter.open(t.path) {|gz| gz.print("foo") }
  284. f = Zlib::GzipReader.open(t.path)
  285. assert_equal(false, f.closed?)
  286. f.read
  287. assert_equal(false, f.closed?)
  288. f.close
  289. assert_equal(true, f.closed?)
  290. end
  291. def test_sync
  292. t = Tempfile.new("test_zlib_gzip_file")
  293. t.close
  294. Zlib::GzipWriter.open(t.path) {|gz| gz.print("foo") }
  295. f = Zlib::GzipReader.open(t.path)
  296. f.sync = true
  297. assert_equal(true, f.sync)
  298. f.read
  299. f.sync = false
  300. assert_equal(false, f.sync)
  301. f.close
  302. end
  303. def test_pos
  304. t = Tempfile.new("test_zlib_gzip_file")
  305. t.close
  306. Zlib::GzipWriter.open(t.path) do |gz|
  307. gz.print("foo")
  308. gz.flush
  309. assert_equal(3, gz.tell)
  310. end
  311. end
  312. def test_path
  313. t = Tempfile.new("test_zlib_gzip_file")
  314. t.close
  315. gz = Zlib::GzipWriter.open(t.path)
  316. gz.print("foo")
  317. assert_equal(t.path, gz.path)
  318. gz.close
  319. assert_equal(t.path, gz.path)
  320. f = Zlib::GzipReader.open(t.path)
  321. assert_equal(t.path, f.path)
  322. f.close
  323. assert_equal(t.path, f.path)
  324. s = ""
  325. sio = StringIO.new(s)
  326. gz = Zlib::GzipWriter.new(sio)
  327. gz.print("foo")
  328. assert_raise(NoMethodError) { gz.path }
  329. gz.close
  330. sio = StringIO.new(s)
  331. f = Zlib::GzipReader.new(sio)
  332. assert_raise(NoMethodError) { f.path }
  333. f.close
  334. end
  335. end
  336. class TestZlibGzipReader < Test::Unit::TestCase
  337. D0 = "\037\213\010\000S`\017A\000\003\003\000\000\000\000\000\000\000\000\000"
  338. def test_read0
  339. assert_equal("", Zlib::GzipReader.new(StringIO.new(D0)).read(0))
  340. end
  341. def test_ungetc
  342. s = ""
  343. w = Zlib::GzipWriter.new(StringIO.new(s))
  344. w << (1...1000).to_a.inspect
  345. w.close
  346. r = Zlib::GzipReader.new(StringIO.new(s))
  347. r.read(100)
  348. r.ungetc ?a
  349. assert_nothing_raised("[ruby-dev:24060]") {
  350. r.read(100)
  351. r.read
  352. r.close
  353. }
  354. end
  355. def test_ungetc_paragraph
  356. s = ""
  357. w = Zlib::GzipWriter.new(StringIO.new(s))
  358. w << "abc"
  359. w.close
  360. r = Zlib::GzipReader.new(StringIO.new(s))
  361. r.ungetc ?\n
  362. assert_equal("abc", r.gets(""))
  363. assert_nothing_raised("[ruby-dev:24065]") {
  364. r.read
  365. r.close
  366. }
  367. end
  368. def test_open
  369. t = Tempfile.new("test_zlib_gzip_reader")
  370. t.close
  371. Zlib::GzipWriter.open(t.path) {|gz| gz.print("foo") }
  372. assert_raise(ArgumentError) { Zlib::GzipReader.open }
  373. assert_equal("foo", Zlib::GzipReader.open(t.path) {|gz| gz.read })
  374. f = Zlib::GzipReader.open(t.path)
  375. assert_equal("foo", f.read)
  376. f.close
  377. end
  378. def test_rewind
  379. t = Tempfile.new("test_zlib_gzip_reader")
  380. t.close
  381. Zlib::GzipWriter.open(t.path) {|gz| gz.print("foo") }
  382. f = Zlib::GzipReader.open(t.path)
  383. assert_equal("foo", f.read)
  384. f.rewind
  385. assert_equal("foo", f.read)
  386. f.close
  387. end
  388. def test_unused
  389. t = Tempfile.new("test_zlib_gzip_reader")
  390. t.close
  391. Zlib::GzipWriter.open(t.path) {|gz| gz.print("foobar") }
  392. f = Zlib::GzipReader.open(t.path)
  393. assert_equal("foo", f.read(3))
  394. f.unused
  395. assert_equal("bar", f.read)
  396. f.unused
  397. f.close
  398. end
  399. def test_read
  400. t = Tempfile.new("test_zlib_gzip_reader")
  401. t.close
  402. str = "\u3042\u3044\u3046"
  403. Zlib::GzipWriter.open(t.path) {|gz| gz.print(str) }
  404. f = Zlib::GzipReader.open(t.path, encoding: "UTF-8")
  405. assert_raise(ArgumentError) { f.read(-1) }
  406. assert_equal(str, f.read)
  407. end
  408. def test_readpartial
  409. t = Tempfile.new("test_zlib_gzip_reader")
  410. t.close
  411. Zlib::GzipWriter.open(t.path) {|gz| gz.print("foobar") }
  412. f = Zlib::GzipReader.open(t.path)
  413. assert("foo".start_with?(f.readpartial(3)))
  414. f = Zlib::GzipReader.open(t.path)
  415. s = ""
  416. f.readpartial(3, s)
  417. assert("foo".start_with?(s))
  418. assert_raise(ArgumentError) { f.readpartial(-1) }
  419. end
  420. def test_getc
  421. t = Tempfile.new("test_zlib_gzip_reader")
  422. t.close
  423. Zlib::GzipWriter.open(t.path) {|gz| gz.print("foobar") }
  424. f = Zlib::GzipReader.open(t.path)
  425. "foobar".each_char {|c| assert_equal(c, f.getc) }
  426. assert_nil(f.getc)
  427. end
  428. def test_getbyte
  429. t = Tempfile.new("test_zlib_gzip_reader")
  430. t.close
  431. Zlib::GzipWriter.open(t.path) {|gz| gz.print("foobar") }
  432. f = Zlib::GzipReader.open(t.path)
  433. "foobar".each_byte {|c| assert_equal(c, f.getbyte) }
  434. assert_nil(f.getbyte)
  435. end
  436. def test_readchar
  437. t = Tempfile.new("test_zlib_gzip_reader")
  438. t.close
  439. Zlib::GzipWriter.open(t.path) {|gz| gz.print("foobar") }
  440. f = Zlib::GzipReader.open(t.path)
  441. "foobar".each_byte {|c| assert_equal(c, f.readchar.ord) }
  442. assert_raise(EOFError) { f.readchar }
  443. end
  444. def test_each_byte
  445. t = Tempfile.new("test_zlib_gzip_reader")
  446. t.close
  447. Zlib::GzipWriter.open(t.path) {|gz| gz.print("foobar") }
  448. f = Zlib::GzipReader.open(t.path)
  449. a = []
  450. f.each_byte {|c| a << c }
  451. assert_equal("foobar".each_byte.to_a, a)
  452. end
  453. def test_gets2
  454. t = Tempfile.new("test_zlib_gzip_reader")
  455. t.close
  456. Zlib::GzipWriter.open(t.path) {|gz| gz.print("foo\nbar\nbaz\n") }
  457. f = Zlib::GzipReader.open(t.path)
  458. assert_equal("foo\n", f.gets)
  459. assert_equal("bar\n", f.gets)
  460. assert_equal("baz\n", f.gets)
  461. assert_nil(f.gets)
  462. f.close
  463. f = Zlib::GzipReader.open(t.path)
  464. assert_equal("foo\nbar\nbaz\n", f.gets(nil))
  465. f.close
  466. end
  467. def test_gets
  468. t = Tempfile.new("test_zlib_gzip_reader")
  469. t.close
  470. Zlib::GzipWriter.open(t.path) {|gz| gz.print("foo\nbar\nbaz\n") }
  471. f = Zlib::GzipReader.open(t.path)
  472. assert_equal("foo\n", f.readline)
  473. assert_equal("bar\n", f.readline)
  474. assert_equal("baz\n", f.readline)
  475. assert_raise(EOFError) { f.readline }
  476. f.close
  477. end
  478. def test_each
  479. t = Tempfile.new("test_zlib_gzip_reader")
  480. t.close
  481. Zlib::GzipWriter.open(t.path) {|gz| gz.print("foo\nbar\nbaz\n") }
  482. f = Zlib::GzipReader.open(t.path)
  483. a = ["foo\n", "bar\n", "baz\n"]
  484. f.each {|l| assert_equal(a.shift, l) }
  485. f.close
  486. end
  487. def test_readlines
  488. t = Tempfile.new("test_zlib_gzip_reader")
  489. t.close
  490. Zlib::GzipWriter.open(t.path) {|gz| gz.print("foo\nbar\nbaz\n") }
  491. f = Zlib::GzipReader.open(t.path)
  492. assert_equal(["foo\n", "bar\n", "baz\n"], f.readlines)
  493. f.close
  494. end
  495. def test_reader_wrap
  496. t = Tempfile.new("test_zlib_gzip_reader")
  497. t.close
  498. Zlib::GzipWriter.open(t.path) {|gz| gz.print("foo") }
  499. f = open(t.path)
  500. assert_equal("foo", Zlib::GzipReader.wrap(f) {|gz| gz.read })
  501. assert_raise(IOError) { f.close }
  502. end
  503. end
  504. class TestZlibGzipWriter < Test::Unit::TestCase
  505. def test_invalid_new
  506. assert_raise(NoMethodError, "[ruby-dev:23228]") { Zlib::GzipWriter.new(nil).close }
  507. assert_raise(NoMethodError, "[ruby-dev:23344]") { Zlib::GzipWriter.new(true).close }
  508. assert_raise(NoMethodError, "[ruby-dev:23344]") { Zlib::GzipWriter.new(0).close }
  509. assert_raise(NoMethodError, "[ruby-dev:23344]") { Zlib::GzipWriter.new(:hoge).close }
  510. end
  511. def test_open
  512. assert_raise(ArgumentError) { Zlib::GzipWriter.open }
  513. t = Tempfile.new("test_zlib_gzip_writer")
  514. t.close
  515. Zlib::GzipWriter.open(t.path) {|gz| gz.print("foo") }
  516. assert_equal("foo", Zlib::GzipReader.open(t.path) {|gz| gz.read })
  517. f = Zlib::GzipWriter.open(t.path)
  518. f.print("bar")
  519. f.close
  520. assert_equal("bar", Zlib::GzipReader.open(t.path) {|gz| gz.read })
  521. assert_raise(Zlib::StreamError) { Zlib::GzipWriter.open(t.path, 10000) }
  522. end
  523. def test_write
  524. t = Tempfile.new("test_zlib_gzip_writer")
  525. t.close
  526. Zlib::GzipWriter.open(t.path) {|gz| gz.print("foo") }
  527. assert_equal("foo", Zlib::GzipReader.open(t.path) {|gz| gz.read })
  528. o = Object.new
  529. def o.to_s; "bar"; end
  530. Zlib::GzipWriter.open(t.path) {|gz| gz.print(o) }
  531. assert_equal("bar", Zlib::GzipReader.open(t.path) {|gz| gz.read })
  532. end
  533. def test_putc
  534. t = Tempfile.new("test_zlib_gzip_writer")
  535. t.close
  536. Zlib::GzipWriter.open(t.path) {|gz| gz.putc(?x) }
  537. assert_equal("x", Zlib::GzipReader.open(t.path) {|gz| gz.read })
  538. # todo: multibyte char
  539. end
  540. def test_writer_wrap
  541. t = Tempfile.new("test_zlib_gzip_writer")
  542. Zlib::GzipWriter.wrap(t) {|gz| gz.print("foo") }
  543. t.close
  544. assert_equal("foo", Zlib::GzipReader.open(t.path) {|gz| gz.read })
  545. end
  546. end
  547. class TestZlib < Test::Unit::TestCase
  548. def test_version
  549. assert_instance_of(String, Zlib.zlib_version)
  550. assert(Zlib.zlib_version.tainted?)
  551. end
  552. def test_adler32
  553. assert_equal(0x00000001, Zlib.adler32)
  554. assert_equal(0x02820145, Zlib.adler32("foo"))
  555. assert_equal(0x02820145, Zlib.adler32("o", Zlib.adler32("fo")))
  556. assert_equal(0x8a62c964, Zlib.adler32("abc\x01\x02\x03" * 10000))
  557. end
  558. def test_adler32_combine
  559. one = Zlib.adler32("fo")
  560. two = Zlib.adler32("o")
  561. begin
  562. assert_equal(0x02820145, Zlib.adler32_combine(one, two, 1))
  563. rescue NotImplementedError
  564. skip "adler32_combine is not implemented"
  565. end
  566. end
  567. def test_crc32
  568. assert_equal(0x00000000, Zlib.crc32)
  569. assert_equal(0x8c736521, Zlib.crc32("foo"))
  570. assert_equal(0x8c736521, Zlib.crc32("o", Zlib.crc32("fo")))
  571. assert_equal(0x07f0d68f, Zlib.crc32("abc\x01\x02\x03" * 10000))
  572. end
  573. def test_crc32_combine
  574. one = Zlib.crc32("fo")
  575. two = Zlib.crc32("o")
  576. begin
  577. assert_equal(0x8c736521, Zlib.crc32_combine(one, two, 1))
  578. rescue NotImplementedError
  579. skip "crc32_combine is not implemented"
  580. end
  581. end
  582. def test_crc_table
  583. t = Zlib.crc_table
  584. assert_instance_of(Array, t)
  585. t.each {|x| assert_kind_of(Integer, x) }
  586. end
  587. end
  588. end