File: base64.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 (110 lines) | stat: -rw-r--r-- 2,746 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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# -*- tcl -*-
# Commands covered:  base64
#
# 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: base64.test,v 1.5 2004/02/18 19:07:18 andreas_kupries Exp $

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


test base64-2.0 {base64, ignore illegal characters} {
    set msg [base64 -mode decode aGV!bG8=]
} {he[}


foreach {index string fullencode encode} {
    1 hello {aGVsbG8=
} aGVsbG8=
2 hell  {aGVsbA==
} aGVsbA
} {
    test base64-3.$index {base64, encode string} {
	base64 -mode encode $string
    } $fullencode	;#{}

    test base64-4.$index {base64, decode string} {
	base64 -mode decode $encode
    } $string	;#{}

    # redundant tests following
    test base64-5.$index {base64, encode/decode identity} {
	base64 -mode decode [base64 -mode encode $string]
    } $string	;#{}

    test base64-6.$index {base64, decode/encode identity} {
	base64 -mode encode [base64 -mode decode $fullencode]
    } $fullencode	;#{}
}



test base64-7.1 {base64, partial conversion for attachments} {
    puts -nonewline [set ma [memchan]] aGVsbA
    seek $ma 0
    base64 -mode encode -attach $ma

    set data [read $ma]
    close $ma
    list [string length $data] $data
} {4 hell}


test base64-7.2 {base64, partial conversion for attachments} {
    puts -nonewline [set ma [memchan]] hello
    seek $ma 0

    base64 -mode decode -attach $ma

    set data [read $ma]
    close $ma
    list [string length $data] $data
} {9 {aGVsbG8=
}}

test base64-7.3 {base64, original data, no transform} {
    puts -nonewline [set ma [memchan]] aGVsbA
    seek $ma 0
    set data [read $ma]
    close $ma
    list [string length $data] $data
} {6 aGVsbA}

test base64-7.4 {base64, original data, no transform} {
    puts -nonewline [set ma [memchan]] hello
    seek $ma 0
    set data [read $ma]
    close $ma
    list [string length $data] $data
} {5 hello}



set p [makeFile {aGVsbA} foo]
test base64-7.5 {base64, partial conversion for attachments} {
    set ma [open $p r+]
    base64 -mode encode -attach $ma

    set data [read $ma]
    close $ma
    list [string length $data] $data
} {4 hell}

set p [makeFile {hell} foo]
test base64-7.6 {base64, partial conversion for attachments} {
    set ma [open $p r+]
    base64 -mode decode -attach $ma

    set data [read $ma]
    close $ma
    list [string length $data] $data
} {9 {aGVsbAo=
}}