forked from OpenPrinting/ipp-usb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
paper_test.go
110 lines (90 loc) · 2.42 KB
/
paper_test.go
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
/* ipp-usb - HTTP reverse proxy, backed by IPP-over-USB connection to device
*
* Copyright (C) 2020 and up by Alexander Pevzner ([email protected])
* See LICENSE for license terms and conditions
*
* Tests for paper.go
*/
package main
import (
"testing"
)
var allSizes = []PaperSize{
PaperLegal,
PaperA4,
PaperTabloid,
PaperA3,
PaperC,
PaperA2,
}
// Compute p.Less(p2) and check answer
func testPaperSizeLess(t *testing.T, p, p2 PaperSize, answer bool) {
rsp := p.Less(p2)
if rsp != answer {
t.Errorf("PaperSize{%d,%d}.Less(PaperSize{%d,%d}): %v, must be %v",
p.Width, p.Height,
p2.Width, p2.Height,
rsp, answer,
)
}
}
// Compute p.Classify() and check answer
func testPaperSizeClassify(t *testing.T, p PaperSize, answer string) {
rsp := p.Classify()
if rsp != answer {
t.Errorf("PaperSize{%d,%d}.Classify(): %v, must be %v",
p.Width, p.Height,
rsp, answer,
)
}
}
// Test (PaperSize) Less()
func TestPaperSizeLess(t *testing.T) {
var p2 PaperSize
for _, p := range allSizes {
testPaperSizeLess(t, p, p, false)
if p.Less(p) {
t.Fail()
}
p2 = PaperSize{p.Width - 1, p.Height}
testPaperSizeLess(t, p, p2, false)
testPaperSizeLess(t, p2, p, true)
p2 = PaperSize{p.Width, p.Height - 1}
testPaperSizeLess(t, p, p2, false)
testPaperSizeLess(t, p2, p, true)
p2 = PaperSize{p.Width - 1, p.Height + 1}
testPaperSizeLess(t, p, p2, false)
testPaperSizeLess(t, p2, p, false)
p2 = PaperSize{p.Width + 1, p.Height - 1}
testPaperSizeLess(t, p, p2, false)
testPaperSizeLess(t, p2, p, false)
}
}
// Test (PaperSize) Classify()
func TestPaperSizeClassify(t *testing.T) {
testPaperSizeClassify(t, PaperLegal, "legal-A4")
testPaperSizeClassify(t, PaperA4, "legal-A4")
testPaperSizeClassify(t, PaperTabloid, "tabloid-A3")
testPaperSizeClassify(t, PaperA3, "tabloid-A3")
testPaperSizeClassify(t, PaperC, "isoC-A2")
testPaperSizeClassify(t, PaperA2, "isoC-A2")
var sizes []PaperSize
sizes = []PaperSize{
{PaperA4.Width - 1, PaperA4.Height},
{PaperA4.Width, PaperA4.Height - 1},
}
for _, p := range sizes {
testPaperSizeClassify(t, p, "<legal-A4")
}
sizes = []PaperSize{
{PaperC.Width + 1, PaperC.Height},
{PaperC.Width, PaperC.Height + 1},
{PaperA2.Width + 1, PaperA2.Height},
{PaperA2.Width, PaperA2.Height + 1},
}
for _, p := range sizes {
testPaperSizeClassify(t, p, ">isoC-A2")
}
// HP LaserJet MFP M28
testPaperSizeClassify(t, PaperSize{21590, 29692}, "legal-A4")
}