(in-package :qt.tests) (5am:in-suite :qt.suite) (defclass reversible-incf (qt:undo-command) ((place :accessor place :initarg :place)) (:metaclass cxx:class)) (defmethod cxx:redo ((incf reversible-incf)) (incf (symbol-value (place incf)))) (defmethod cxx:undo ((incf reversible-incf)) (decf (symbol-value (place incf)))) (5am:test undo-stack "Test ownership transfer of a undo-command to the undo-stack." (let ((undo-stack (make-instance 'qt:undo-stack)) (iterations 10) (counter 0)) (declare (special counter)) (dotimes (i iterations) (cxx:push undo-stack (make-instance 'reversible-incf :place 'counter)) (gc :full t)) ;; Test for faulty ownership transfer (5am:is (eq t (cxx:can-undo undo-stack))) (5am:is (= iterations counter)) (dotimes (i iterations) (cxx:undo undo-stack)) (5am:is (eq nil (cxx:can-undo undo-stack))) (5am:is (= 0 counter))))