taf2 / rb-bsdiff

Ruby bindings to bindary diff tools bsdiff and bspatch

This URL has Read+Write access

jwilkins (author)
Sun Jul 19 02:04:34 -0700 2009
taf2 (committer)
Sun Jul 19 14:55:51 -0700 2009
rb-bsdiff / test.rb
100644 39 lines (26 sloc) 0.881 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
require 'openssl'
require 'test/unit'
require File.join(File.dirname(__FILE__),'ext','bsdiff')
 
class TestPatch < Test::Unit::TestCase
 
  def setup
    File.unlink('b3') if File.exist?('b3')
    File.unlink('p0') if File.exist?('p0')
  end
 
  def teardown
    File.unlink('b3') if File.exist?('b3')
    File.unlink('p0') if File.exist?('p0')
  end
 
  def test_diff_and_patch
 
    #../bsdiff b0 b1 p0
    #../bspatch b0 b3 p0
 
    b0_chk = OpenSSL::Digest::MD5.hexdigest(File.read('ext/b0'))
    b1_chk = OpenSSL::Digest::MD5.hexdigest(File.read('ext/b1'))
 
    # create patch file from bspatch.o to bsdiff.o
    BSDiff.diff('ext/b0', 'ext/b1', 'p0')
 
    # apply patch to bspatch.o as bspatch2.o
    BSDiff.patch('ext/b0', 'b3', 'p0')
 
    b3_chk = OpenSSL::Digest::MD5.hexdigest(File.read('b3'))
 
    # bspatch2.o should equal bsdiff.o
    assert_equal(b1_chk,b3_chk)
 
  end
 
end