aboutsummaryrefslogtreecommitdiffstats
path: root/tests/inkplate.scm
blob: fb181995dae7f475b0a55d064779a8c0b58ea880 (plain)
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
(use-modules (srfi srfi-64)
             (inkplate lowlevel))

(define* (call-with-test-device func #:key (input-string ""))
  (let ((device (make-inkplate (open-input-string input-string) (open-output-string))))
    (func device)
    (close device)))

(test-begin "Inkplate")
(test-equal "Convert hello" "48656c6c6f" (convert-string-to-hex "Hello"))
(test-equal "Convert zero-pads result" "0a" (convert-string-to-hex "\n"))
(test-equal "Convert a path" "2f696d616765312e626d70" (convert-string-to-hex "/image1.bmp"))

(call-with-test-device
 (lambda (test-device)
   (test-equal "Draw pixel command zero-padds coordinates and color"
     "#0(005,005,01)*"
     (begin
       (draw-pixel test-device 5 5 1)
       (get-output-string (inkplate-output-port test-device))))))

(call-with-test-device
 (lambda (test-device)
   (test-equal "Draw line command zero-padds coordinates and color"
     "#1(005,010,005,010,01)*"
     (begin
       (draw-line test-device 5 10 5 10 1)
       (get-output-string (inkplate-output-port test-device))))))

(call-with-test-device
 (lambda (test-device)
   (test-equal "Draw fast vertical line command zero-padds coordinates and color"
     "#2(005,010,005,01)*"
     (begin
       (draw-fast-vertical-line test-device 5 10 5 1)
       (get-output-string (inkplate-output-port test-device))))))

(call-with-test-device
 (lambda (test-device)
   (test-equal "Draw fast horizontal line command zero-padds coordinates and color"
     "#3(005,010,005,01)*"
     (begin
       (draw-fast-horizontal-line test-device 5 10 5 1)
       (get-output-string (inkplate-output-port test-device))))))

(call-with-test-device
 (lambda (test-device)
   (test-equal "Draw rectangle command zero-padds coordinates and color"
     "#4(005,010,005,010,01)*"
     (begin
       (draw-rectangle test-device 5 10 5 10 1)
       (get-output-string (inkplate-output-port test-device))))))

(call-with-test-device
 (lambda (test-device)
   (test-equal "Draw circle command zero-padds coordinates and color"
     "#5(005,010,005,01)*"
     (begin
       (draw-circle test-device 5 10 5 1)
       (get-output-string (inkplate-output-port test-device))))))

(call-with-test-device
 (lambda (test-device)
   (test-equal "Draw triangle command zero-padds coordinates and color"
     "#6(005,010,005,010,005,010,01)*"
     (begin
       (draw-triangle test-device 5 10 5 10 5 10 1)
       (get-output-string (inkplate-output-port test-device))))))

(call-with-test-device
 (lambda (test-device)
   (test-equal "Draw rounded rectangle command zero-padds coordinates and color"
     "#7(005,010,005,010,005,01)*"
     (begin
       (draw-rounded-rectangle test-device 5 10 5 10 5 1)
       (get-output-string (inkplate-output-port test-device))))))

(call-with-test-device
 (lambda (test-device)
   (test-equal "Fill rectangle command zero-padds coordinates and color"
     "#8(005,010,005,010,01)*"
     (begin
       (fill-rectangle test-device 5 10 5 10 1)
       (get-output-string (inkplate-output-port test-device))))))

(call-with-test-device
 (lambda (test-device)
   (test-equal "Fill circle command zero-padds coordinates and color"
     "#9(005,010,005,01)*"
     (begin
       (fill-circle test-device 5 10 5 1)
       (get-output-string (inkplate-output-port test-device))))))

(call-with-test-device
 (lambda (test-device)
   (test-equal "Fill triangle command zero-padds coordinates and color"
     "#A(005,010,005,010,005,010,01)*"
     (begin
       (fill-triangle test-device 5 10 5 10 5 10 1)
       (get-output-string (inkplate-output-port test-device))))))

(call-with-test-device
 (lambda (test-device)
   (test-equal "Fill rounded rectangle command zero-padds coordinates and color"
     "#B(005,010,005,010,005,01)*"
     (begin
       (fill-rounded-rectangle test-device 5 10 5 10 5 1)
       (get-output-string (inkplate-output-port test-device))))))

(call-with-test-device
 (lambda (test-device)
   (test-equal "Print command quotes its argument"
     "#C(\"48656c6c6f\")*"
     (begin
       (print test-device "48656c6c6f")
       (get-output-string (inkplate-output-port test-device))))))

(call-with-test-device
 (lambda (test-device)
   (test-equal "Set text size command zero-padds size"
     "#D(05)*"
     (begin
       (set-text-size test-device 5)
       (get-output-string (inkplate-output-port test-device))))))

(call-with-test-device
 (lambda (test-device)
   (test-equal "Set cursor command zero-padds coordinates"
     "#E(005,010)*"
     (begin
       (set-cursor test-device 5 10)
       (get-output-string (inkplate-output-port test-device))))))

(call-with-test-device
 (lambda (test-device)
   (test-equal "Set test wrap #t becomes T"
     "#F(T)*"
     (begin
       (set-text-wrap test-device #t)
       (get-output-string (inkplate-output-port test-device))))))

(call-with-test-device
 (lambda (test-device)
   (test-equal "Set test wrap #f becomes F"
     "#F(F)*"
     (begin
       (set-text-wrap test-device #f)
       (get-output-string (inkplate-output-port test-device))))))

(call-with-test-device
 (lambda (test-device)
   (test-equal "Set rotation command zero-padds the rotation"
     "#G(000)*"
     (begin
       (set-rotation test-device 0)
       (get-output-string (inkplate-output-port test-device))))))

(call-with-test-device
 (lambda (test-device)
   (test-equal "Draw bitmap command zero-padds the coordinates and quotes the path"
     "#H(005,010,\"48656c6c6f\")*"
     (begin
       (draw-bitmap test-device 5 10 "48656c6c6f")
       (get-output-string (inkplate-output-port test-device))))))

(call-with-test-device
 (lambda (test-device)
   (test-equal "Set display mode command inserts a number"
     "#I(1)*"
     (begin
       (set-display-mode test-device 1)
       (get-output-string (inkplate-output-port test-device))))))

(call-with-test-device
 (lambda (test-device)
   (test-equal "Get display mode command gets created"
     "#J(?)*"
     (begin
       (get-display-mode test-device)
       (get-output-string (inkplate-output-port test-device))))))

(call-with-test-device
 (lambda (test-device)
   (test-equal "Clear screen command gets created"
     "#K(1)*"
     (begin
       (clear-screen test-device)
       (get-output-string (inkplate-output-port test-device))))))

(call-with-test-device
 (lambda (test-device)
   (test-equal "Update display command gets created"
     "#L(1)*"
     (begin
       (update test-device)
       (get-output-string (inkplate-output-port test-device))))))

(call-with-test-device
 (lambda (test-device)
   (test-equal "Partial update command zero-padds coordinates"
     "#M(005,010,100)*"
     (begin
       (partial-update test-device 5 10 100)
       (get-output-string (inkplate-output-port test-device))))))

(call-with-test-device
 (lambda (test-device)
   (test-equal "Read temperature command gets created"
     "#N(?)*"
     (begin
       (read-temperature test-device)
       (get-output-string (inkplate-output-port test-device))))))

(call-with-test-device
 (lambda (test-device)
   (test-equal "Read touchpad command gets created"
     "#O(1)*"
     (begin
       (read-touchpad test-device 1)
       (get-output-string (inkplate-output-port test-device))))))

(call-with-test-device
 (lambda (test-device)
   (test-equal "Read battery command gets created"
     "#P(?)*"
     (begin
       (read-battery test-device)
       (get-output-string (inkplate-output-port test-device))))))

(call-with-test-device
 (lambda (test-device)
   (test-equal "Panel supply command #t becomes 1"
     "#Q(1)*"
     (begin
       (panel-supply test-device #t)
       (get-output-string (inkplate-output-port test-device))))))

(call-with-test-device
 (lambda (test-device)
   (test-equal "Panel supply command #f becomes 0"
     "#Q(0)*"
     (begin
       (panel-supply test-device #f)
       (get-output-string (inkplate-output-port test-device))))))

(call-with-test-device
 (lambda (test-device)
   (test-equal "Get panel state command gets created"
     "#R(?)*"
     (begin
       (get-panel-state test-device)
       (get-output-string (inkplate-output-port test-device))))))

(call-with-test-device
 (lambda (test-device)
   (test-equal "Draw image zero-padds coordinates and quotes path"
     "#S(005,010,\"2f696d616765312e626d70\")*"
     (begin
       (draw-image test-device 5 10 "2f696d616765312e626d70")
       (get-output-string (inkplate-output-port test-device))))))

(call-with-test-device
 (lambda (test-device)
   (test-equal "Draw thick line zero-padds arguments"
     "#T(005,010,100,005,10,01)*"
     (begin
       (draw-thick-line test-device 5 10 100 5 10 1)
       (get-output-string (inkplate-output-port test-device))))))

(call-with-test-device
 (lambda (test-device)
   (test-equal "Draw ellipse zero-padds arguments"
     "#U(005,010,100,005,01)*"
     (begin
       (draw-ellipse test-device 5 10 100 5 1)
       (get-output-string (inkplate-output-port test-device))))))

(call-with-test-device
 (lambda (test-device)
   (test-equal "Fill ellipse zero-padds arguments"
     "#V(005,010,100,005,01)*"
     (begin
       (fill-ellipse test-device 5 10 100 5 1)
       (get-output-string (inkplate-output-port test-device))))))

(test-end "Inkplate")