/ src /
/src/operators.lisp
1 (in-package :qt.tests)
2
3 (5am:in-suite :qt.suite)
4
5 (5am:test cxx-equality
6 "Test cxx:= cxx:/="
7 (5am:is (eq t (cxx:= (make-instance 'qt:point))))
8 (5am:is (eq t (cxx:= (make-instance 'qt:point)
9 (make-instance 'qt:point))))
10 (5am:is (eq t (cxx:= (make-instance 'qt:point)
11 (make-instance 'qt:point)
12 (make-instance 'qt:point))))
13 (5am:for-all ((x1 (5am:gen-integer))
14 (x2 (5am:gen-integer))
15 (y1 (5am:gen-integer))
16 (y2 (5am:gen-integer)))
17 (let ((p1 (make-instance 'qt:point :args (list x1 y1)))
18 (p2 (make-instance 'qt:point :args (list x2 y2))))
19 (5am:is (eq (and (= x1 x2)
20 (= y1 y2))
21 (cxx:= p1 p2)))
22 (5am:is (eq (or (/= x1 x2)
23 (/= y1 y2))
24 (cxx:/= p1 p2))))))
25
26 (5am:test cxx-equality-conversion
27 "Test cxx:= overload resolution."
28 (5am:is (eq t (cxx:= (qt:make-variant "foo") "foo")))
29 (5am:is (eq t (cxx:= "foo" (qt:make-variant "foo") "foo")))
30 (5am:is (eq nil (cxx:= "foo" (qt:make-variant "foo") "bar"))))
31
32 (5am:test (cxx-+ :depends-on cxx-equality)
33 "Test cxx:+"
34 (5am:for-all ((x1 (5am:gen-integer))
35 (x2 (5am:gen-integer))
36 (y1 (5am:gen-integer))
37 (y2 (5am:gen-integer)))
38 (let ((p1 (make-instance 'qt:point :args (list x1 y1)))
39 (p2 (make-instance 'qt:point :args (list x2 y2))))
40 (5am:is (eq t (cxx:= (cxx:+ p1 p2)
41 (make-instance 'qt:point :args (list
42 (+ x1 x2)
43 (+ y1 y2)))))))))
44
45
46 (5am:test (cxx-decf :depends-on cxx-equality)
47 "Test cxx:decf"
48 (5am:for-all ((x1 (5am:gen-integer))
49 (x2 (5am:gen-integer))
50 (y1 (5am:gen-integer))
51 (y2 (5am:gen-integer)))
52 (let ((p1 (make-instance 'qt:point :args (list x1 y1)))
53 (p2 (make-instance 'qt:point :args (list x2 y2))))
54 (cxx:decf p1 p2)
55 (5am:is (eq t (cxx:= p1
56 (make-instance 'qt:point :args (list
57 (- x1 x2)
58 (- y1 y2)))))))))
59
60 (5am:test (cxx-<=)
61 "Test cxx:<="
62 (let ((p1 (make-instance 'qt:byte-array :args '("")))
63 (p2 (make-instance 'qt:byte-array :args '("a")))
64 (p3 (make-instance 'qt:byte-array :args '("b"))))
65 (5am:is (eq t (cxx:<= p1 p2 p3)))
66 (5am:is (eq t (cxx:<= p1 p2 p2 p3)))
67 (5am:is (eq nil (cxx:<= p2 p1)))
68 (5am:is (eq nil (cxx:<= p1 p2 p1)))))
69
70 (5am:test cxx-aref
71 "Test cxx-aref"
72 (let ((byte-array (make-instance 'qt:byte-array :args '("foobar"))))
73 (5am:is (eq #\b (cxx:aref byte-array 3)))
74 (5am:is (eq #\B
75 (setf (cxx:aref byte-array 3)
76 #\B)))
77 (5am:is (eq #\B (cxx:aref byte-array 3)))))
78
79 (5am:test relations
80 "Test cxx order relations."
81 (dolist (relation (list #'cxx:< #'cxx:<= #'cxx:>= #'cxx:>))
82 (5am:is (eq t (funcall relation (make-instance 'qt:byte-array)))))
83
84 (5am:is (eq t (cxx:<= (make-instance 'qt:byte-array)
85 (make-instance 'qt:byte-array))))
86 (5am:is (eq nil (cxx:< (make-instance 'qt:byte-array)
87 (make-instance 'qt:byte-array))))
88 (5am:is (eq t (cxx:>= (make-instance 'qt:byte-array)
89 (make-instance 'qt:byte-array))))
90 (5am:is (eq nil (cxx:> (make-instance 'qt:byte-array)
91 (make-instance 'qt:byte-array)))))