File: zip.test

package info (click to toggle)
tcltrf 2.1.4-dfsg3-1
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 9,628 kB
  • sloc: ansic: 73,134; sh: 3,155; tcl: 1,343; makefile: 176; exp: 22
file content (95 lines) | stat: -rw-r--r-- 2,576 bytes parent folder | download | duplicates (6)
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# -*- tcl -*-
# Commands covered:  bin
#
# This file contains a collection of tests for one or more of the trf
# commands of the TRF extension. Sourcing this file into Tcl runs the
# tests and generates output for errors.  No output means no errors were
# found.
#
# Copyright (c) 1995 Andreas Kupries (andreas_kupries@users.sourceforge.net)
#
# See the file "license.terms" for information on usage and redistribution
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
#
# $Id: zip.test,v 1.5 1999/10/20 22:47:06 aku Exp $

if {[string compare test [info procs test]] == 1} then {source defs}

set text                               "hello, hello!"
set text_compressed_as_hex             "789CCB48CDC9C9D751C800518A0021700496"
set text_compressed_as_hex_with_nowrap "CB48CDC9C9D751C800518A00"


# differentiate tcl versions
if {[info tclversion] < 8.0} {
    # 7.6, use channels to transfer information, we have embedded \0s.

    test zip-1.0-7.6 {zip compression} {hasZlib} {
	set in  [text2chan $text]
	set out [memchan]

	fconfigure   $out -translation binary
	hex  -attach $out -mode encode

	zip -mode compress -in $in -out $out

	unstack $out
	seek             $out 0
	set data   [read $out]
	close            $out
	close $in

	set data
    } $text_compressed_as_hex	; #{}

    test zip-1.1-7.6 {zip decompression} {hasZlib} {
	set in  [hex2chan $text_compressed_as_hex]
	set out [memchan]

	seek $in 0
	zip -mode decompress -in $in -out $out

	seek             $out 0
	set data   [read $out]
	close            $out
	close $in

	set data
    } $text	; #{}

} else {
    # 8.x is able to work with embedded \0s.

    test zip-1.0-8.x {zip compression} {hasZlib} {
	hex -mode encode [zip -mode compress $text]
    } $text_compressed_as_hex	; #{}

    test zip-1.1-8.x {zip decompression} {hasZlib} {
	zip -mode decompress [hex -mode decode $text_compressed_as_hex]
    } $text	; #{}

    test zip-1.2-8.x {zip compression with nowrap} {
	hex -mode encode [zip -mode compress -nowrap true $text]
    } $text_compressed_as_hex_with_nowrap	; #{}

    test zip-1.3-8.x {zip decompression with nowrap} {
	zip -mode decompress -nowrap true [hex -mode decode $text_compressed_as_hex_with_nowrap]
    } $text	; #{}
}


set data  [info commands]
set zdata [zip -mode compress $data]

test zip-2.0 {(De)compression while reading/writing from/to a file} {hasZlib} {
    write_zip zip $data
    read_zip  zip
} $data


test zip-2.1 {(De)compression of binary information} {hasZlib} {
    write_file zip $zdata
    zip -mode decompress [read_file zip]
} $data

unset data zdata