;;;; SPDX-License-Identifier AGPL-3.0-or-later ;;;; compound.lisp Compound artifact implementation ;;;; Copyright (C) 2022 Alejandro "HiPhish" Sanchez ;;;; ;;;; This file is part of CL-HSSG. ;;;; ;;;; CL-HSSG is free software: you can redistribute it and/or modify it under ;;;; the terms of the GNU Affero General Public License as published by the ;;;; Free Software Foundation, either version 3 of the License, or (at your ;;;; option) any later version. ;;;; ;;;; CL-HSSG is distributed in the hope that it will be useful, but WITHOUT ANY ;;;; WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS ;;;; FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for ;;;; more details. ;;;; ;;;; You should have received a copy of the GNU Affero General Public License ;;;; along with CL-HSSG If not, see .(in-package #:hssg.artifact) (defpackage #:hssg/test/artifact/compound (:use #:cl)) (in-package #:hssg/test/artifact/compound) ;;; "Compound artifact implementation tests") (clunit:defsuite hssg.artifact.compound (hssg/test:hssg)) ;;; --------------------------------------------------------------------------- (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) (clunit:deffixture hssg.artifact.compound (@body) (let ((counter (make-counter))) @body)) (clunit:deftest create-and-write (hssg.artifact.compound) "Writing a compound artifacts writes all all of its artifacts" (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)) (let ((count (counter-count counter))) (clunit:assert-eql 3 count count))) (clunit:deftest push-artifact (hssg.artifact.compound) "Push a new artifact onto the list of wrapped artifacts" (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)) (clunit:assert-eql 2 (counter-count counter))) (hssg/test:test-all)