Mon Jun 1 00:24:46 CEST 2009 Tobias Rautenkranz * Test undo stack diff -rN -u old-qt.tests/qt.tests.mbd new-qt.tests/qt.tests.mbd --- old-qt.tests/qt.tests.mbd 2014-10-30 07:57:32.000000000 +0100 +++ new-qt.tests/qt.tests.mbd 2014-10-30 07:57:32.000000000 +0100 @@ -21,6 +21,7 @@ ("application" (:needs "tests")) ("signal-slot" (:needs "tests")) ("operators" (:needs "tests")) + ("undo" (:needs "tests")) ("thread" (:needs "tests")) ("properties" (:needs "tests")) ("click" (:needs "tests")))))) diff -rN -u old-qt.tests/src/undo.lisp new-qt.tests/src/undo.lisp --- old-qt.tests/src/undo.lisp 1970-01-01 01:00:00.000000000 +0100 +++ new-qt.tests/src/undo.lisp 2014-10-30 07:57:32.000000000 +0100 @@ -0,0 +1,34 @@ +(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)))) +