Skip to content

Commit 0f0a0b6

Browse files
committed
tests: add tests for core-protocol (section 3. Displays)
Additional cleanup is performed: - spurious files are removed (test.lisp and example.lisp) - some notes regarding manual are added at the top of file Manual require more thought. When all tests are added, manual should be updated to reflect these things.
1 parent 82156f8 commit 0f0a0b6

File tree

5 files changed

+90
-35
lines changed

5 files changed

+90
-35
lines changed

clx.asd

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,10 +135,7 @@ Independent FOSS developers"
135135
((:module "tests"
136136
:components
137137
((:file "package")
138-
(:file "test"
139-
:depends-on ("package"))
140-
(:file "example"
141-
:depends-on ("test"))))))
138+
(:file "core-protocol" :depends-on ("package"))))))
142139

143140
#+sbcl
144141
(defmethod perform :around ((o compile-op) (f xrender-source-file))

tests/core-protocol.lisp

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
(fiasco:define-test-package (#:xlib-test-displays :in xlib-test:xlib-all-tests)
2+
(:documentation "Tests for `3. Displays' section of the manual."))
3+
(in-package #:xlib-test-displays)
4+
5+
;;; Manual notes:
6+
;;;
7+
;;; - Manual claims xlib:display-authorization-data returns a string. Either
8+
;;; review manual or fix this;
9+
;;;
10+
;;; - xlib:display-error-handler documentation says, that it returns function,
11+
;;; yet by default it returns symbol (denoting a function) [minor];
12+
;;;
13+
;;; - xlib:display-error-handler documentation has broken reference "See
14+
;;; <undefined> [Errors], page <undefined>";
15+
;;;
16+
;;; - `xlib:display-vendor' returns 2 values, second is release. It is said,
17+
;;; that second value type card16, but it is card32. Also it is mentioned,
18+
;;; that function to probe second value is named `xlib:display-release-number'
19+
;;; (and this is implemented), but later we have documentation for
20+
;;; `xlib:display-version-number' – function which doesn't exist;
21+
;;;
22+
;;; - `xlib:display-xid' is documented to return a function, but default value
23+
;;; is a symbol (denoting a function) [minor];
24+
25+
;;; This test will fail the day "FOO" extension is written.
26+
(deftest display-protocol ()
27+
"Opens display, checks its attributes and closes it."
28+
(let ((display (xlib:open-default-display)))
29+
(is (null (xlib:query-extension display "FOO")))
30+
(is (typep (xlib:display-authorization-data display) 'string))
31+
(is (typep (xlib:display-authorization-name display) 'string))
32+
(is (typep (xlib:display-bitmap-format display) 'xlib:bitmap-format))
33+
(is (typep (xlib:display-byte-order display) '(member :lsbfirst :msbfirst)))
34+
(is (typep (xlib:display-display display) 'integer))
35+
(is (typep (xlib:display-error-handler display) '(or function symbol)))
36+
(is (typep (xlib:display-image-lsb-first-p display) 'boolean))
37+
(multiple-value-bind (min-keycode max-keycode) (xlib:display-keycode-range display)
38+
(is (typep min-keycode 'xlib:card8))
39+
(is (typep max-keycode 'xlib:card8))
40+
(is (= min-keycode (xlib:display-min-keycode display)))
41+
(is (= max-keycode (xlib:display-max-keycode display))))
42+
(let ((max-request-size (xlib:display-max-request-length display)))
43+
(is (>= max-request-size 4096))
44+
(is (typep max-request-size 'xlib:card16)))
45+
(is (typep (xlib:display-motion-buffer-size display) 'xlib:card32))
46+
(is (typep (xlib:display-nscreens display) 'integer))
47+
(is (xlib:display-p display))
48+
(is (not (xlib:display-p :not-a-display)))
49+
(is (every #'xlib:pixmap-format-p (xlib:display-pixmap-formats display)))
50+
;; display-plist
51+
(finishes (setf (getf (xlib:display-plist display) :foo) :bar))
52+
(is (eql :bar (getf (xlib:display-plist display) :foo)))
53+
(finishes (remf (xlib:display-plist display) :foo))
54+
(is (eql nil (getf (xlib:display-plist display) :foo)))
55+
(multiple-value-bind (major minor) (xlib:display-protocol-version display)
56+
(is (typep minor 'xlib:card16))
57+
(is (typep major 'xlib:card16))
58+
(is (= minor (xlib:display-protocol-minor-version display)))
59+
(is (= major (xlib:display-protocol-major-version display))))
60+
(is (typep (xlib:display-resource-id-base display) 'xlib:resource-id))
61+
(is (typep (xlib:display-resource-id-mask display) 'xlib:resource-id))
62+
(is (every #'xlib:screen-p (xlib:display-roots display)))
63+
(multiple-value-bind (name release) (xlib:display-vendor display)
64+
(is (typep name 'string))
65+
(is (typep release 'xlib:card32))
66+
(is (string= name (xlib:display-vendor-name display)))
67+
(is (= release (xlib:display-release-number display))))
68+
(is (typep (xlib:display-xid display) '(or function symbol)))
69+
;; dummy test
70+
(let ((count 0))
71+
(finishes (setf (xlib:display-after-function display)
72+
(lambda (display)
73+
(declare (ignore display))
74+
(incf count)))
75+
(xlib:with-display (display)
76+
(xlib:query-extension display "FOO")
77+
(xlib:display-finish-output display)
78+
(xlib:query-extension display "FOO")
79+
(xlib:display-force-output display)))
80+
(is (<= 2 count)))
81+
(is (null (xlib:close-display display)))
82+
;; We can't query closed display.
83+
(signals xlib:closed-display (xlib:query-extension display "FOO"))))

tests/example.lisp

Lines changed: 0 additions & 18 deletions
This file was deleted.

tests/package.lisp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
(defpackage :xlib-test
2-
(:use :common-lisp)
3-
(:export :run-all-tests
4-
:define-test-suite
5-
:xlib-all-tests))
1+
(defpackage #:xlib-test
2+
(:use :cl)
3+
(:export #:run-all-tests #:xlib-test #:xlib-all-tests))
4+
(in-package #:xlib-test)
5+
6+
(fiasco:defsuite (xlib-all-tests :bind-to-package #:xlib-test))

tests/test.lisp

Lines changed: 0 additions & 8 deletions
This file was deleted.

0 commit comments

Comments
 (0)