File: test_parmencode.tcl

package info (click to toggle)
tkrat 1%3A2.2cvs20100105-true-dfsg-6.1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 10,340 kB
  • ctags: 9,259
  • sloc: ansic: 96,057; tcl: 25,667; makefile: 1,638; sh: 282
file content (112 lines) | stat: -rw-r--r-- 2,896 bytes parent folder | download | duplicates (4)
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
111
112
puts "$HEAD Parameter encoding"

namespace eval test_parmencode {
}

proc test_parmencode::compare_lists {exp got n} {
    global option

    set diff [expr [llength $exp]-[llength $got]]
    for {set i 0} {0 == $diff && $i < [llength $exp]} {incr i} {
	if {[lindex $exp $i] != [lindex $got $i]} {
	    set diff 1
	}
    }
    if {$diff} {
	puts "Expected:"
	foreach p $exp {
	    puts "  [list $p]"
	}
	puts "Got:"
	foreach p $got {
	    puts "  [list $p]"
	}
	ReportError "Encode parameter '$n' with '$option(parm_enc)' failed"
    }
}

proc test_parmencode::test_parmencode {} {
    global option

    set old_enc $option(parm_enc)

    # Each test consists of
    #  - Name of test case
    #  - Parameters to encode
    #  - Expected result with rfc2047
    #  - Expected result with rfc2231
    #  - Expected result with both
    set tests {
	{
	    "one simple parameter"
	    {{p1 simple.txt}}
	    {{P1 simple.txt}}
	    {{P1 simple.txt}}
	    {{P1 simple.txt}}
	}
	{
	    "two simple parameters"
	    {{p1 simple.txt} {p2 stupido}}
	    {{P1 simple.txt} {P2 stupido}}
	    {{P1 simple.txt} {P2 stupido}}
	    {{P1 simple.txt} {P2 stupido}}
	    {{P1 simple.txt} {P2 stupido}}
	}
	{
	    "one localized parameter"
	    {{p1 Rckmackan.txt}}
	    {{P1 =?iso-8859-1?Q?R=E4ckmackan=2Etxt?=}}
	    {{P1* iso-8859-1''R%E4ckmackan%2Etxt}}
	    {
		{P1 =?iso-8859-1?Q?R=E4ckmackan=2Etxt?=}
		{P1* iso-8859-1''R%E4ckmackan%2Etxt}
	    }
	}
	{
	    "one localized parameter and one simple"
	    {{p1 Rckmackan.txt} {p2 simple.txt}}
	    {{P1 =?iso-8859-1?Q?R=E4ckmackan=2Etxt?=} {P2 simple.txt}}
	    {{P1* iso-8859-1''R%E4ckmackan%2Etxt} {P2 simple.txt}}
	    {
		{P1 =?iso-8859-1?Q?R=E4ckmackan=2Etxt?=}
		{P1* iso-8859-1''R%E4ckmackan%2Etxt}
		{P2 simple.txt}
	    }
	}
	{
	    "A long parameter"
	    {{parameter1 {This parameter has a really long value, actually it is so long that it should wrap}}}
	    {{PARAMETER1 {This parameter has a really long value, actually it is so long that it should wrap}}}
	    {
		{PARAMETER1*0 {This parameter has a really long value, actually it is so long}}
		{PARAMETER1*1 { that it should wrap}}
	    }
	    {
		{PARAMETER1 {This parameter has a really long value, actually it is so long that it should wrap}}
		{PARAMETER1*0 {This parameter has a really long value, actually it is so long}}
		{PARAMETER1*1 { that it should wrap}}
	    }
	}
    }

    foreach te $tests {
	set n [lindex $te 0]
        StartTest "Encoding $n"

	set option(parm_enc) rfc2047
	set r [RatTest encode_parameters [lindex $te 1]]
	compare_lists [lindex $te 2] $r $n

	set option(parm_enc) rfc2231
	set r [RatTest encode_parameters [lindex $te 1]]
	compare_lists [lindex $te 3] $r $n

	set option(parm_enc) both
	set r [RatTest encode_parameters [lindex $te 1]]
	compare_lists [lindex $te 4] $r $n
    }

    set option(parm_enc) $old_enc
}

test_parmencode::test_parmencode