diff options
Diffstat (limited to 'xdelta3/go/src/regtest.go')
-rw-r--r-- | xdelta3/go/src/regtest.go | 105 |
1 files changed, 105 insertions, 0 deletions
diff --git a/xdelta3/go/src/regtest.go b/xdelta3/go/src/regtest.go new file mode 100644 index 0000000..6497166 --- /dev/null +++ b/xdelta3/go/src/regtest.go | |||
@@ -0,0 +1,105 @@ | |||
1 | package main | ||
2 | |||
3 | import ( | ||
4 | "errors" | ||
5 | "fmt" | ||
6 | "io" | ||
7 | |||
8 | "xdelta" | ||
9 | ) | ||
10 | |||
11 | const ( | ||
12 | blocksize = 1<<16 | ||
13 | winsize = 1<<26 | ||
14 | xdelta3 = "/volume/home/jmacd/src/xdelta-64bithash/xdelta3/build/x86_64-pc-linux-gnu-m64/usize64/xoff64/xdelta3" | ||
15 | seed = 1422253499919909358 | ||
16 | ) | ||
17 | |||
18 | func smokeTest(r *xdelta.Runner, t *xdelta.TestGroup, p *xdelta.Program) { | ||
19 | t.Add(1) | ||
20 | target := "Hello world!" | ||
21 | source := "Hello world, nice to meet you!" | ||
22 | |||
23 | run, err := r.Exec(p, true, []string{"-evv"}) | ||
24 | if err != nil { | ||
25 | t.Panic(err) | ||
26 | } | ||
27 | encodeout := t.Drain(run.Stdout, "encode.stdout") | ||
28 | t.Empty(run.Stderr, "encode") | ||
29 | |||
30 | t.Write("encode.stdin", run.Stdin, []byte(target)) | ||
31 | t.Write("encode.srcin", run.Srcin, []byte(source)) | ||
32 | |||
33 | if err := run.Cmd.Wait(); err != nil { | ||
34 | t.Panic(err) | ||
35 | } | ||
36 | |||
37 | run, err = r.Exec(p, true, []string{"-dvv"}) | ||
38 | if err != nil { | ||
39 | t.Panic(err) | ||
40 | } | ||
41 | |||
42 | decodeout := t.Drain(run.Stdout, "decode.stdout") | ||
43 | t.Empty(run.Stderr, "decode") | ||
44 | |||
45 | t.Write("decode.stdin", run.Stdin, <-encodeout) | ||
46 | t.Write("decode.srcin", run.Srcin, []byte(source)) | ||
47 | decoded := string(<-decodeout) | ||
48 | if err := run.Cmd.Wait(); err != nil { | ||
49 | t.Panic(err) | ||
50 | } | ||
51 | if decoded != target { | ||
52 | t.Panic(errors.New("It's not working!!!")) | ||
53 | } | ||
54 | t.Done() | ||
55 | fmt.Println("Smoketest pass") | ||
56 | } | ||
57 | |||
58 | func offsetTest(r *xdelta.Runner, t *xdelta.TestGroup, p *xdelta.Program, offset, bufsize, length int64) { | ||
59 | t.Add(1) | ||
60 | eargs := []string{"-e", "-1", "-N", fmt.Sprint("-B", bufsize), "-vv", fmt.Sprint("-W", winsize)} | ||
61 | enc, err := r.Exec(p, true, eargs) | ||
62 | if err != nil { | ||
63 | t.Panic(err) | ||
64 | } | ||
65 | dargs := []string{"-d", fmt.Sprint("-B", bufsize), "-vv", fmt.Sprint("-W", winsize)} | ||
66 | dec, err := r.Exec(p, true, dargs) | ||
67 | if err != nil { | ||
68 | t.Panic(err) | ||
69 | } | ||
70 | |||
71 | read, write := io.Pipe() | ||
72 | |||
73 | t.Empty(enc.Stderr, "encode") | ||
74 | t.Empty(dec.Stderr, "decode") | ||
75 | |||
76 | t.CopyStreams(enc.Stdout, dec.Stdin) | ||
77 | t.CompareStreams(dec.Stdout, read, length) | ||
78 | |||
79 | // TODO: seems possible to use one WriteRstreams call to generate | ||
80 | // the source and target for both encoder and decoder. Why not? | ||
81 | xdelta.WriteRstreams(t, seed, offset, length, enc.Srcin, enc. Stdin) | ||
82 | xdelta.WriteRstreams(t, seed, offset, length, dec.Srcin, write) | ||
83 | |||
84 | if err := enc.Cmd.Wait(); err != nil { | ||
85 | t.Panic(err) | ||
86 | } | ||
87 | if err := dec.Cmd.Wait(); err != nil { | ||
88 | t.Panic(err) | ||
89 | } | ||
90 | t.Done() | ||
91 | } | ||
92 | |||
93 | func main() { | ||
94 | r, err := xdelta.NewRunner() | ||
95 | if err != nil { | ||
96 | panic(err) | ||
97 | } | ||
98 | defer r.Cleanup() | ||
99 | |||
100 | prog := &xdelta.Program{xdelta3} | ||
101 | |||
102 | smokeTest(r, xdelta.NewTestGroup(), prog) | ||
103 | |||
104 | offsetTest(r, xdelta.NewTestGroup(), prog, 1 << 31, 1 << 32, 1 << 33) | ||
105 | } | ||