guile-inkplate/tests/inkplate.scm

287 lines
9 KiB
Scheme
Raw Normal View History

2023-06-03 09:29:04 +02:00
(use-modules (srfi srfi-64)
(inkplate))
2023-06-03 09:29:04 +02:00
(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")