2022-10-01 15:51:26 +02:00
|
|
|
;;;; 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 <https://www.gnu.org/licenses/>.(in-package #:hssg.artifact)
|
2022-10-01 01:03:47 +02:00
|
|
|
(defpackage #:hssg/test/artifact/compound
|
|
|
|
(:use #:cl))
|
|
|
|
(in-package #:hssg/test/artifact/compound)
|
|
|
|
|
2022-10-01 15:51:26 +02:00
|
|
|
;;; "Compound artifact implementation tests")
|
|
|
|
(clunit:defsuite hssg.artifact.compound (hssg/test:hssg))
|
2022-10-01 01:03:47 +02:00
|
|
|
|
|
|
|
|
|
|
|
;;; ---------------------------------------------------------------------------
|
|
|
|
(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)
|
|
|
|
|
2022-10-01 15:51:26 +02:00
|
|
|
(clunit:deffixture hssg.artifact.compound (@body)
|
|
|
|
(let ((counter (make-counter)))
|
|
|
|
@body))
|
|
|
|
|
2022-10-01 01:03:47 +02:00
|
|
|
|
2022-10-01 15:51:26 +02:00
|
|
|
(clunit:deftest create-and-write (hssg.artifact.compound)
|
2022-10-01 01:03:47 +02:00
|
|
|
"Writing a compound artifacts writes all all of its artifacts"
|
2022-10-01 15:51:26 +02:00
|
|
|
(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)
|
2022-10-01 01:03:47 +02:00
|
|
|
"Push a new artifact onto the list of wrapped artifacts"
|
2022-10-01 15:51:26 +02:00
|
|
|
(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)
|