47 lines
1.8 KiB
Common Lisp
47 lines
1.8 KiB
Common Lisp
![]() |
(defpackage #:hssg/test/artifact/compound
|
||
|
(:use #:cl))
|
||
|
(in-package #:hssg/test/artifact/compound)
|
||
|
|
||
|
(fiveam:def-suite hssg/artifact/compound
|
||
|
:description "Compound artifact implementation tests")
|
||
|
(fiveam:in-suite hssg/artifact/compound)
|
||
|
|
||
|
|
||
|
;;; ---------------------------------------------------------------------------
|
||
|
(defstruct counter
|
||
|
"A mutable counter to keep track of how often the dummy artifact has been
|
||
|
written."
|
||
|
(count 0))
|
||
|
|
||
|
(defclass dummy-artifact ()
|
||
|
((counter :initarg :counter :accessor dummy-counter
|
||
|
:documentation "A (possibly shared) counter instance"))
|
||
|
(:documentation "A fake artifact which increments its counter"))
|
||
|
|
||
|
(defmethod hssg:write-artifact ((dummy dummy-artifact))
|
||
|
(incf (counter-count (dummy-counter dummy)))
|
||
|
:ok)
|
||
|
|
||
|
|
||
|
;;; ---------------------------------------------------------------------------
|
||
|
(fiveam:test create-and-write
|
||
|
"Writing a compound artifacts writes all all of its artifacts"
|
||
|
(let ((counter (make-counter)))
|
||
|
(let ((artifact (hssg:make-compound-artifact
|
||
|
(make-instance 'dummy-artifact :counter counter)
|
||
|
(make-instance 'dummy-artifact :counter counter)
|
||
|
(make-instance 'dummy-artifact :counter counter))))
|
||
|
(hssg:write-artifact artifact))
|
||
|
(fiveam:is (= 3 (counter-count counter)))))
|
||
|
|
||
|
(fiveam:test push-artifact
|
||
|
"Push a new artifact onto the list of wrapped artifacts"
|
||
|
(let ((counter (make-counter)))
|
||
|
(let ((compound (hssg:make-compound-artifact))
|
||
|
(dummy1 (make-instance 'dummy-artifact :counter counter))
|
||
|
(dummy2 (make-instance 'dummy-artifact :counter counter)))
|
||
|
(hssg:compound-artifact-push compound dummy1)
|
||
|
(hssg:compound-artifact-push compound dummy2)
|
||
|
(hssg:write-artifact compound))
|
||
|
(fiveam:is (= 2 (counter-count counter)))))
|