1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
|
;; test.lisp
(defpackage :garbage-pools.test
(:use #:cl #:garbage-pools #:lift)
(:nicknames #:gp.test)
(:export #:run-garbage-pools-tests))
(in-package #:garbage-pools.test)
(deftestsuite garbage-pools-test () ())
;;; test-cleanup-pool
(addtest (garbage-pools-test)
test-cleanup-pool
(ensure-same '(1 2 3 4)
(let ((list nil)
(pool (make-instance 'pool)))
(loop for x from 1 to 4 do
(cleanup-register x (lambda (obj) (push obj list)) pool))
(cleanup-pool pool)
list)))
;;; test-with-garbage-pool-1
(addtest (garbage-pools-test)
test-with-cleanup-pool-1
(ensure-same '(1 2 3 4 5)
(let ((list nil))
(with-garbage-pool ()
(loop for x from 1 to 5 do
(cleanup-register x (lambda (obj) (push obj list)))))
list)))
;;; test-with-cleanup-pool-2
(addtest (garbage-pools-test)
test-with-cleanup-pool-2
(ensure-same '(1 2 3 4 5)
(let ((list nil))
(with-garbage-pool (mypool)
(loop for x from 1 to 5 do
(cleanup-register x (lambda (obj) (push obj list)) mypool)))
list)))
;;; test-cleanup-object-1
(addtest (garbage-pools-test)
test-cleanup-object-1
(ensure-same '((3 . 3) (1 . 1))
(let ((res nil)
(res2 nil)
(data '((0 . 0) (1 . 1) (2 . 2) (3 . 3) (4 . 4))))
(with-garbage-pool ()
(loop for x in data do
(cleanup-register x (lambda (obj) (push obj res))))
(cleanup-object (nth 1 data))
(cleanup-object (nth 3 data))
(setq res2 res)
(setq res nil))
res2)))
;;; test-cleanup-object-2
(addtest (garbage-pools-test)
test-cleanup-object-2
(ensure-same '((0 . 0) (2 . 2) (4 . 4))
(let ((res nil)
(data '((0 . 0) (1 . 1) (2 . 2) (3 . 3) (4 . 4))))
(with-garbage-pool ()
(loop for x in data do
(cleanup-register x (lambda (obj) (push obj res))))
(cleanup-object (nth 1 data))
(cleanup-object (nth 3 data))
(setq res nil))
res)))
;;; test-object-register-and-defcleanup
(defclass test-class ()
((content :initarg :content :initform nil :accessor content)))
(defvar *cesspool*)
(defcleanup test-class (lambda (obj) (push (content obj) *cesspool*)))
(addtest (garbage-pools-test)
test-object-register-and-defcleanup-1
(ensure-same '("Hello" "world")
(let ((*cesspool* nil))
(with-garbage-pool ()
(object-register (make-instance 'test-class :content "Hello"))
(object-register (make-instance 'test-class :content "world")))
*cesspool*)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; run-garbage-pools-tests
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun run-garbage-pools-tests ()
(run-tests :suite 'garbage-pools-test))
|