root/trunk/bknr/datastore/src/data/encoding-test.lisp

Revision 3818, 23.1 kB (checked in by ksprotte, 3 months ago)

whitespace / indent datastore/src/data

Line 
1 (in-package :bknr.datastore)
2
3 (test:def-suite :bknr.datastore)
4 (test:in-suite :bknr.datastore)
5
6 (defun files-identical-content-p (path-a path-b)
7   "Are files of PATH-A and PATH-B byte per byte identical?"
8   (with-open-file (in-a path-a :element-type '(unsigned-byte 8))
9     (with-open-file (in-b path-b :element-type '(unsigned-byte 8))
10       (loop
11          for byte-a = (read-byte in-a nil nil)
12          for byte-b = (read-byte in-b nil nil)
13          while (or byte-a byte-b)
14          unless (and byte-a byte-b (= byte-a byte-b))
15          return nil
16          finally (return t)))))
17
18 (defun congruent-p (a b)
19   "Are lisp value A and B (deeply) congruent?"
20   (bknr.utils:with-temporary-file (path-a)
21     (bknr.utils:with-temporary-file (path-b)
22       (cl-store:store a path-a)
23       (cl-store:store b path-b)
24       (prog1
25           (files-identical-content-p path-a path-b)
26         (delete-file path-a)
27         (delete-file path-b)))))
28
29 (defun copy-by-encoding (value)
30   (bknr.utils:with-temporary-file (path)
31     (with-open-file (out path :direction :output :if-exists :supersede
32                          :element-type '(unsigned-byte 8))
33       (encode value out))
34     (with-open-file (in path :element-type '(unsigned-byte 8))
35       (decode in))))
36
37 (defmacro test-encoding (name value)
38   (let ((options (arnesi:ensure-list name)))
39     (destructuring-bind (name &key skip) options
40       `(test:test ,name
41                   ,(if skip
42                        `(test:skip ,skip)
43                        `(test:is (congruent-p ,value (copy-by-encoding ,value))))))))
44
45 (test-encoding list.1 '(1 2 3))
46 (test-encoding list.len.30 (loop repeat 30 collect 'x))
47 (test-encoding list.len.254 (loop repeat 254 collect 'x))
48 (test-encoding list.len.255 (loop repeat 255 collect 'x))
49 (test-encoding list.len.256 (loop repeat 256 collect 'x))
50 (test-encoding list.len.257 (loop repeat 257 collect 'x))
51 (test-encoding list.len.3000 (loop repeat 3000 collect 'x))
52 (test-encoding improper-list.1 '(1 2 3 4 . 5))
53
54 (test-encoding cons.1 '(1 . 2))
55
56 ;;; from cl-store :)
57 (test-encoding integer.1 1)
58 (test-encoding integer.2 0)
59 (test-encoding integer.3 23423333333333333333333333423102334)
60 (test-encoding integer.4 -2322993)
61 (test-encoding integer.5 most-positive-fixnum)
62 (test-encoding integer.6 most-negative-fixnum)
63
64 ;; ratios
65 (test-encoding ratio.1 1/2)
66 (test-encoding ratio.2 234232/23434)
67 (test-encoding ratio.3 -12/2)
68 (test-encoding ratio.4 -6/11)
69 (test-encoding ratio.5 23222/13)
70
71 ;; complex numbers - currently not supported
72 ;; (test-encoding complex.1 #C(0 1))
73 ;; (test-encoding complex.2 #C(0.0 1.0))
74 ;; (test-encoding complex.3 #C(32 -23455))
75 ;; (test-encoding complex.4 #C(-222.32 2322.21))
76 ;; (test-encoding complex.5 #C(-111 -1123))
77 ;; (test-encoding complex.6 #C(-11.2 -34.5))
78
79 ;; single-float
80 (test-encoding single-float.1 3244.32)
81 (test-encoding single-float.2 0.12)
82 (test-encoding single-float.3 -233.001)
83 (test-encoding single-float.4 most-positive-single-float)
84 (test-encoding single-float.5 most-negative-single-float)
85
86 ;; double-float
87 (test-encoding double-float.1 2343.3d0)
88 (test-encoding double-float.2 -1211111.3343d0)
89 (test-encoding double-float.3 99999999999123456789012345678222222222222290.0987654321d0)
90 (test-encoding double-float.4 -99999999999123456789012345678222222222222290.0987654321d0)
91 (test-encoding double-float.5 most-positive-double-float)
92 (test-encoding double-float.6 most-negative-double-float)
93
94 ;; characters
95 (test-encoding char.1 #\Space)
96 (test-encoding char.2 #\f )
97 (test-encoding char.3 #\Rubout)
98 (test-encoding char.4 (code-char 255))
99
100 (test:test char.random
101            (test:for-all ((char (test:gen-character)))
102                          (test:is (char= char (copy-by-encoding char)))))
103
104 ;; strings
105 (test:test string.random
106            (test:for-all ((string (test:gen-string)))
107                          (test:is (string= string (copy-by-encoding string)))))
108
109 (test:test string.random.code-limited
110            (test:for-all ((string (test:gen-string :elements (test:gen-character :code-limit 10000))))
111                          (test:is (string= string (copy-by-encoding string)))))
112
113 (test:test string.decode-utf-8
114            (labels ((decode-string-from-octets (octets)
115                       (flexi-streams:with-input-from-sequence (in octets)
116                         (bknr.datastore::%decode-string in))))
117              (test:is (string-equal "<=>" (decode-string-from-octets #(1 3 60 61 62))))
118              ;; #\? is the substitution char
119              (string-equal "<?>" (decode-string-from-octets #(1 3 60 188 62)))
120              ;; kilian 2008-03-20: the following for-all test failed on ccl,
121              ;; because the correct utf-8 sequence could produce a char-code
122              ;; above char-code-limit - bknr.datastore::%decode-string should
123              ;; throw an error in this case, but I dont know how to test this
124              ;; (test:for-all ((octets (test:gen-buffer)))
125              ;;       (test:finishes (decode-string-from-octets (concatenate 'vector (vector 1 (length octets)) octets))))
126              ))
127
128 ;; #+(or (and sbcl sb-unicode) lispworks clisp acl)
129 ;; (progn
130 ;;   (test-encoding unicode.1 (map #-lispworks 'string
131 ;;                             #+lispworks 'lw:text-string
132 ;;                             #'code-char (list #X20AC #X3BB)))
133 ;;   (test-encoding unicode.2 (intern (map #-lispworks 'string
134 ;;                                     #+lispworks 'lw:text-string
135 ;;                                     #'code-char (list #X20AC #X3BB))
136 ;;                                :pwgl-test-suite)))
137 ;; vectors
138 (test-encoding vector.1 #(1 2 3 4))
139
140
141 (test-encoding vector.2 (make-array 5 :element-type 'fixnum
142                                       :initial-contents (list 1 2 3 4 5)))
143
144 (test-encoding vector.4 #*101101101110)
145 (test-encoding vector.3
146                (make-array 5
147                            :element-type 'fixnum
148                            :fill-pointer 2
149                            :initial-contents (list 1 2 3 4 5)))
150
151
152
153 (test-encoding vector.5 #*)
154 (test-encoding vector.6 #())
155
156
157 ;; arrays
158 (test-encoding array.1
159                (make-array '(2 2) :initial-contents '((1 2) (3 4))))
160
161 (test-encoding array.2
162                (make-array '(2 2) :initial-contents '((1 1) (1 1))))
163
164 (test-encoding array.3
165                (make-array '(2 2) :element-type 'fixnum :initial-element 3))
166
167 (test-encoding (array.3b :skip "will be fixed later - http://trac.common-lisp.net/bknr/ticket/31")
168                (make-array '(2 2) :element-type '(mod 10) :initial-element 3))
169
170 (test-encoding array.4
171                (make-array  '(2 3 5)
172                             :initial-contents
173                             '(((1 2 #\f 5 12.0) (#\Space 0 4 1 0) ('d 0 #() 3 -1))
174                               ((0 #\a #\b 4 #\q) (12.0d0 0 '(d) 4 1)
175                                (#\Newline 1 7 #\4 #\0)))))
176
177 ;; (test-encoding array.5
178 ;;                (let* ((a1 (make-array 5))
179 ;;                       (a2 (make-array 4 :displaced-to a1
180 ;;                                       :displaced-index-offset 1))
181 ;;                       (a3 (make-array 2 :displaced-to a2
182 ;;                                       :displaced-index-offset 2)))
183 ;;                  a3))
184
185
186
187
188
189 ;; symbols
190
191 (test-encoding symbol.1  t)
192 (test-encoding symbol.2  nil)
193 (test-encoding symbol.3  :foo)
194 (test-encoding symbol.4  'bknr.datastore::foo)
195 (test-encoding symbol.5  'make-hash-table)
196 (test-encoding symbol.6 '|foo bar|)
197 (test-encoding symbol.7 'foo\ bar\ baz)
198
199 ;; (deftest gensym.1 (progn
200 ;;                     (store (gensym "Foobar") *test-file*)
201 ;;                     (let ((new (restore *test-file*)))
202 ;;                       (list (symbol-package new)
203 ;;                             (mismatch "Foobar" (symbol-name new)))))
204 ;;          (nil 6))
205
206 ;; This failed in cl-store < 0.5.5
207 ;; (deftest gensym.2 (let ((x (gensym)))
208 ;;                     (store (list x x) *test-file*)
209 ;;                     (let ((new (restore *test-file*)))
210 ;;                       (eql (car new) (cadr new))))
211 ;;          t)
212
213
214 ;; cons
215
216 (test-encoding cons.1 '(1 2 3))
217 (test-encoding cons.2 '((1 2 3)))
218 (test-encoding cons.3 '(#\Space 1 1.2 1.3 #(1 2 3)))
219
220 (test-encoding cons.4  '(1 . 2))
221 (test-encoding cons.5  '(t . nil))
222 (test-encoding cons.6 '(1 2 3 . 5))
223 ;; (deftest cons.7 (let ((list (cons nil nil))) ;  '#1=(#1#)))
224 ;;                   (setf (car list) list)
225 ;;                   (store list *test-file*)
226 ;;                   (let ((ret (restore *test-file*)))
227 ;;                     (eq ret (car ret))))
228 ;;          t)
229
230
231 ;; hash tables
232 ;; for some reason (make-hash-table) is not equalp
233 ;; to (make-hash-table) with ecl.
234
235 #-openmcl(test-encoding hash.1 (make-hash-table))
236 #+openmcl(test:test hash.1 (test:skip "the hash-table-size is not preserved - do we need to fix this?"))
237 #-openmcl(test-encoding hash.2 (make-hash-table :test #'equal))
238 #+openmcl(test:test hash.2 (test:skip "the hash-table-size is not preserved - do we need to fix this?"))
239
240 ;; (defvar *hash* (let ((in (make-hash-table :test #'equal
241 ;;                                           :rehash-threshold 0.4 :size 20
242 ;;                                           :rehash-size 40)))
243 ;;                  (dotimes (x 1000) (setf (gethash (format nil "~R" x) in) x))
244 ;;                  in))
245
246 ;; (test-encoding hash.3 *hash*)
247 (test:test hash.3 (test:skip "will be fixed later - http://trac.common-lisp.net/bknr/ticket/29"))
248
249 ;; ;; packages
250 ;; (test-encoding package.1 (find-package :cl-store))
251
252 ;; (defpackage foo
253 ;;   (:nicknames foobar)
254 ;;   (:use :cl)
255 ;;   (:shadow cl:format)
256 ;;   (:export bar))
257
258 ;; (defun package-restores ()
259 ;;   (let (( *nuke-existing-packages* t))
260 ;;     (store (find-package :foo) *test-file*)
261 ;;     (delete-package :foo)
262 ;;     (restore *test-file*)
263 ;;     (list (package-name (find-package :foo))
264 ;;           (mapcar #'package-name (package-use-list :foo))
265 ;;           (package-nicknames :foo)
266 ;;           (equalp (remove-duplicates (package-shadowing-symbols :foo))
267 ;;                   (list (find-symbol "FORMAT" "FOO")))
268 ;;           (equalp (cl-store::external-symbols (find-package :foo))
269 ;;                   (make-array 1 :initial-element (find-symbol "BAR" "FOO"))))))
270
271
272 ;; ; unfortunately it's difficult to portably test the internal symbols
273 ;; ; in a package so we just assume that it's OK.
274 ;; (deftest package.2
275 ;;          (package-restores)
276 ;;          ("FOO" ("COMMON-LISP") ("FOOBAR") t t))
277
278 ;; ;; objects
279 (define-persistent-class foo ()
280   ((x :update)))
281
282 (define-persistent-class bar (foo)
283   ((y :update)))
284
285 ;; (deftest standard-object.1
286 ;;   (let ((val (store (make-instance 'foo :x 3) *test-file*)))
287 ;;     (= (get-x val) (get-x (restore *test-file*))))
288 ;;   t)
289
290 ;; (deftest standard-object.2
291 ;;   (let ((val (store (make-instance 'bar
292 ;;                                    :x (list 1 "foo" 1.0)
293 ;;                                    :y (vector 1 2 3 4))
294 ;;                     *test-file*)))
295 ;;     (let ((ret (restore *test-file*)))
296 ;;       (and (equalp (get-x val) (get-x ret))
297 ;;            (equalp (get-y val) (get-y ret)))))
298 ;;   t)
299
300 ;; (deftest standard-object.3
301 ;;   (let ((*store-class-slots* nil)
302 ;;         (val (make-instance 'baz :z 9)))
303 ;;     (store val *test-file*)
304 ;;     (make-instance 'baz :z 2)
305 ;;     (= (get-z (restore *test-file*))
306 ;;        2))
307 ;;   t)
308
309 ;; (deftest standard-object.4
310 ;;   (let ((*store-class-slots* t)
311 ;;         (val (make-instance 'baz :z 9)))
312 ;;     (store val *test-file*)
313 ;;     (make-instance 'baz :z 2)
314 ;;     (let ((ret (restore *test-file*)))
315 ;;       (= (get-z ret )
316 ;;          9)))
317 ;;   t)
318
319 ;; ;; classes
320 ;; (deftest standard-class.1 (progn (store (find-class 'foo) *test-file*)
321 ;;                                  (restore *test-file*)
322 ;;                                  t)
323 ;;   t)
324
325 ;; (deftest standard-class.2 (progn (store (find-class 'bar) *test-file*)
326 ;;                                  (restore *test-file*)
327 ;;                                  t)
328 ;;   t)
329
330 ;; (deftest standard-class.3 (progn (store (find-class 'baz) *test-file*)
331 ;;                                  (restore *test-file*)
332 ;;                                  t)
333 ;;   t)
334
335
336
337 ;; ;; conditions
338 ;; (deftest condition.1
339 ;;   (handler-case (/ 1 0)
340 ;;     (division-by-zero (c)
341 ;;       (store c *test-file*)
342 ;;       (typep (restore *test-file*) 'division-by-zero)))
343 ;;   t)
344
345 ;; (deftest condition.2
346 ;;   (handler-case (car (read-from-string "3"))
347 ;;     ;; allegro pre 7.0 signalled a simple-error here
348 ;;     ((or type-error simple-error) (c)
349 ;;       (store c *test-file*)
350 ;;       (typep (restore *test-file*)
351 ;;              '(or type-error simple-error))))
352 ;;   t)
353
354 ;; ;; structure-object
355
356 ;; (defstruct a
357 ;;   a b c)
358
359 ;; (defstruct (b (:include a))
360 ;;   d e f)
361
362 ;; #+(or sbcl cmu lispworks openmcl)
363 ;; (test-encoding structure-object.1 (make-a :a 1 :b 2 :c 3))
364 ;; #+(or sbcl cmu lispworks openmcl)
365 ;; (test-encoding structure-object.2 (make-b :a 1 :b 2 :c 3 :d 4 :e 5 :f 6))
366 ;; #+(or sbcl cmu lispworks openmcl)
367 ;; (test-encoding structure-object.3 (make-b :a 1 :b (make-a :a 1 :b 3 :c 2)
368 ;;                                       :c #\Space :d #(1 2 3) :e (list 1 2 3)
369 ;;                                       :f (make-hash-table)))
370
371 ;; ;; setf test
372 ;; (test-encoding setf.1 (setf (restore *test-file*) 0))
373 ;; (test-encoding setf.2 (incf (restore *test-file*)))
374 ;; (test-encoding setf.3 (decf (restore *test-file*) 2))
375
376 ;; (test-encoding pathname.1 #P"/home/foo")
377 ;; (test-encoding pathname.2 (make-pathname :name "foo"))
378 ;; (test-encoding pathname.3 (make-pathname :name "foo" :type "bar"))
379
380
381 ;; ; built-in classes
382 ;; (test-encoding built-in.1 (find-class 'hash-table))
383 ;; (test-encoding built-in.2 (find-class 'integer))
384
385
386 ;; ;; find-backend tests
387 ;; (deftest find-backend.1
388 ;;     (and (find-backend 'cl-store) t)
389 ;;   t)
390
391 ;; (deftest find-backend.2
392 ;;     (find-backend (gensym))
393 ;;   nil)
394
395 ;; (deftest find-backend.3
396 ;;     (handler-case (find-backend (gensym) t)
397 ;;       (error (c) (and c t))
398 ;;       (:no-error (val) (and val nil)))
399 ;;   t)
400
401
402
403 ;; ;; circular objects
404 ;; (defvar circ1 (let ((x (list 1 2 3 4)))
405 ;;                 (setf (cdr (last x)) x)))
406 ;; (deftest circ.1 (progn (store circ1 *test-file*)
407 ;;                        (let ((x (restore *test-file*)))
408 ;;                          (eql (cddddr x) x)))
409 ;;   t)
410
411 ;; (defvar circ2 (let ((x (list 2 3 4 4 5)))
412 ;;                 (setf (second x) x)))
413 ;; (deftest circ.2 (progn (store circ2 *test-file*)
414 ;;                        (let ((x (restore *test-file*)))
415 ;;                          (eql (second x) x)))
416 ;;   t)
417
418
419
420 ;; (defvar circ3 (let ((x (list (list 1 2 3 4 )
421 ;;                              (list 5 6 7 8)
422 ;;                              9)))
423 ;;                 (setf (second x) (car x))
424 ;;                 (setf (cdr (last x)) x)
425 ;;                 x))
426
427 ;; (deftest circ.3 (progn (store circ3 *test-file*)
428 ;;                        (let ((x (restore *test-file*)))
429 ;;                          (and (eql (second x) (car x))
430 ;;                               (eql (cdddr x) x))))
431 ;;   t)
432
433
434 ;; (defvar circ4 (let ((x (make-hash-table)))
435 ;;                 (setf (gethash 'first x) (make-hash-table))
436 ;;                 (setf (gethash 'second x) (gethash 'first x))
437 ;;                 (setf (gethash 'inner (gethash 'first x)) x)
438 ;;                 x))
439
440 ;; (deftest circ.4 (progn (store circ4 *test-file*)
441 ;;                        (let ((x (restore *test-file*)))
442 ;;                          (and (eql (gethash 'first x)
443 ;;                                   (gethash 'second x))
444 ;;                               (eql x
445 ;;                                   (gethash 'inner
446 ;;                                            (gethash 'first x))))))
447 ;;   t)
448
449 ;; (deftest circ.5  (let ((circ5 (make-instance 'bar)))
450 ;;                    (setf (get-y circ5) circ5)
451 ;;                    (store circ5 *test-file*)
452 ;;                    (let ((x (restore *test-file*)))
453 ;;                      (eql x (get-y x))))
454 ;;   t)
455
456
457 ;; (defvar circ6 (let ((y (make-array '(2 2 2)
458 ;;                                    :initial-contents '((("foo" "bar")
459 ;;                                                         ("me" "you"))
460 ;;                                                        ((5 6) (7 8))))))
461 ;;                 (setf (aref y 1 1 1) y)
462 ;;                 (setf (aref y 0 0 0) (aref y 1 1 1))
463 ;;                 y))
464
465
466 ;; (deftest circ.6 (progn (store circ6 *test-file*)
467 ;;                        (let ((x (restore *test-file*)))
468 ;;                          (and (eql (aref x 1 1 1) x)
469 ;;                               (eql (aref x 0 0 0) (aref x 1 1 1)))))
470 ;;   t)
471
472
473
474 ;; (defvar circ7 (let ((x (make-a)))
475 ;;                 (setf (a-a x) x)))
476
477 ;; #+(or sbcl cmu lispworks)
478 ;; (deftest circ.7 (progn (store circ7 *test-file*)
479 ;;                        (let ((x (restore *test-file*)))
480 ;;                          (eql (a-a x) x)))
481 ;;   t)
482
483 ;; (defvar circ.8 (let ((x "foo"))
484 ;;                  (make-pathname :name x :type x)))
485
486
487 ;; ;; clisp apparently creates a copy of the strings in a pathname
488 ;; ;; so a test for eqness is pointless.
489 ;; #-clisp
490 ;; (deftest circ.8 (progn (store circ.8 *test-file*)
491 ;;                        (let ((x (restore *test-file*)))
492 ;;                          (eql (pathname-name x)
493 ;;                               (pathname-type x))))
494 ;;   t)
495
496
497 ;; (deftest circ.9 (let ((val (vector "foo" "bar" "baz" 1 2)))
498 ;;                   (setf (aref val 3) val)
499 ;;                   (setf (aref val 4) (aref val 0))
500 ;;                   (store val *test-file*)
501 ;;                   (let ((rest (restore *test-file*)))
502 ;;                     (and (eql rest (aref rest 3))
503 ;;                          (eql (aref rest 4) (aref rest 0)))))
504 ;;   t)
505
506 ;; (deftest circ.10 (let* ((a1 (make-array 5))
507 ;;                         (a2 (make-array 4 :displaced-to a1
508 ;;                                         :displaced-index-offset 1))
509 ;;                         (a3 (make-array 2 :displaced-to a2
510 ;;                                         :displaced-index-offset 2)))
511 ;;                    (setf (aref a3 1) a3)
512 ;;                    (store a3 *test-file*)
513 ;;                    (let ((ret (restore *test-file*)))
514 ;;                      (eql a3 (aref a3 1))))
515 ;;   t)
516
517 ;; (defvar circ.11 (let ((x (make-hash-table)))
518 ;;                   (setf (gethash x x) x)
519 ;;                   x))
520
521 ;; (deftest circ.11 (progn (store circ.11 *test-file*)
522 ;;                         (let ((val (restore *test-file*)))
523 ;;                           (eql val (gethash val val))))
524 ;;   t)
525
526 ;; (deftest circ.12 (let ((x (vector 1 2 "foo" 4 5)))
527 ;;                    (setf (aref x 0) x)
528 ;;                    (setf (aref x 1) (aref x 2))
529 ;;                    (store x *test-file*)
530 ;;                    (let ((ret (restore *test-file*)))
531 ;;                      (and (eql (aref ret 0) ret)
532 ;;                           (eql (aref ret 1) (aref ret 2)))))
533 ;;   t)
534
535 ;; (defclass foo.1 ()
536 ;;   ((a :accessor foo1-a)))
537
538 ;; ;; a test from Robert Sedgwick which crashed in earlier
539 ;; ;; versions (pre 0.2)
540 ;; (deftest circ.13 (let ((foo (make-instance 'foo.1))
541 ;;                        (bar (make-instance 'foo.1)))
542 ;;                    (setf (foo1-a foo) bar)
543 ;;                    (setf (foo1-a bar) foo)
544 ;;                    (store (list foo) *test-file*)
545 ;;                    (let ((ret (car (restore *test-file*))))
546 ;;                      (and (eql ret (foo1-a (foo1-a ret)))
547 ;;                           (eql (foo1-a ret)
548 ;;                               (foo1-a (foo1-a (foo1-a ret)))))))
549 ;;   t)
550
551
552 ;; (deftest circ.14 (let ((list '#1=(1 2 3 #1# . #1#)))
553 ;;                    (store list *test-file*)
554 ;;                    (let ((ret (restore *test-file*)))
555 ;;                      (and (eq ret (cddddr ret))
556 ;;                           (eq (fourth ret) ret))))
557 ;;          t)
558
559
560
561
562 ;; (deftest circ.15 (let ((list '#1=(1 2 3 #2=(#2#) . #1#)))
563 ;;                    (store list *test-file*)
564 ;;                    (let ((ret (restore *test-file*)))
565 ;;                      (and (eq ret (cddddr ret))
566 ;;                           (eq (fourth ret)
567 ;;                               (car (fourth ret))))))
568 ;;          t)
569
570
571
572 ;; ;; this had me confused for a while since what was
573 ;; ;; restored #1=(1 (#1#) #1#) looks nothing like this list,
574 ;; ;; but it turns out that it is correct
575 ;; (deftest circ.16  (let ((list '#1=(1 #2=(#1#) . #2#)))
576 ;;                     (store list *test-file*)
577 ;;                     (let ((ret (restore *test-file*)))
578 ;;                       (and (eq ret (caadr ret))
579 ;;                            (eq ret (third ret)))))
580 ;;          t)
581
582 ;; ;; large circular lists
583 ;; (deftest large.1 (let ((list (make-list 100000)))
584 ;;                    (setf (cdr (last list)) list)
585 ;;                    (store list *test-file*)
586 ;;                    (let ((ret (restore *test-file*)))
587 ;;                      (eq (nthcdr 100000 ret) ret)))
588 ;;          t)
589
590 ;; ;; large dotted lists
591 ;; (test-encoding large.2 (let ((list (make-list 100000)))
592 ;;                      (setf (cdr (last list)) 'foo)
593 ;;                      list))
594
595
596
597 ;; ;; custom storing
598 ;; (defclass random-obj () ((size :accessor size :initarg :size)))
599
600 ;; (defvar *random-obj-code* (register-code 100 'random-obj))
601
602 ;; (defstore-cl-store (obj random-obj buff)
603 ;;   (output-type-code *random-obj-code* buff)
604 ;;   (store-object (size obj) buff))
605
606 ;; (defrestore-cl-store (random-obj buff)
607 ;;   (random (restore-object buff)))
608
609
610 ;; (deftest custom.1
611 ;;   (progn (store (make-instance 'random-obj :size 5) *test-file* )
612 ;;          (typep (restore *test-file*) '(integer 0 4)))
613 ;;   t)
614
615
616
617 ;; (test-encoding function.1 #'restores)
618 ;; (test-encoding function.2 #'car)
619
620 ;; (test-encoding gfunction.1 #'cl-store:restore)
621 ;; (test-encoding gfunction.2 #'cl-store:store)
622 ;; #-clisp
623 ;; (test-encoding gfunction.3 #'(setf get-y))
624
625
626 ;; (deftest nocirc.1
627 ;;     (let* ((string "FOO")
628 ;;            (list `(,string . ,string))
629 ;;            (*check-for-circs* nil))
630 ;;       (store list *test-file*)
631 ;;       (let ((res (restore *test-file*)))
632 ;;         (and (not (eql (car res) (cdr res)))
633 ;;              (string= (car res) (cdr res)))))
634 ;;   t)
635
636
637 ;; (defstruct st.bar x)
638 ;; (defstruct (st.foo (:conc-name f-)
639 ;;                    (:constructor fooo (z y x))
640 ;;                    (:copier cp-foo)
641 ;;                    (:include st.bar)
642 ;;                    (:predicate is-foo)
643 ;;                    (:print-function (lambda (obj st dep)
644 ;;                                       (declare (ignore dep))
645 ;;                                       (print-unreadable-object (obj st :type t)
646 ;;                                         (format st "~A" (f-x obj))))))
647 ;;   (y 0 :type integer) (z nil :type simple-string))
648
649
650 ;; #+(or sbcl cmu)
651 ;; (deftest struct-class.1
652 ;;     (let* ((obj (fooo "Z" 2 3))
653 ;;            (string (format nil "~A" obj)))
654 ;;       (let ((*nuke-existing-classes* t))
655 ;;         (store (find-class 'st.foo) *test-file*)
656 ;;         (fmakunbound 'cp-foo)
657 ;;         (fmakunbound 'is-foo)
658 ;;         (fmakunbound 'fooo)
659 ;;         (fmakunbound 'f-x)
660 ;;         (fmakunbound 'f-y)
661 ;;         (fmakunbound 'f-z)
662 ;;         (restore *test-file*)
663 ;;         (let* ((new-obj (cp-foo (fooo "Z" 2 3)))
664 ;;                (new-string (format nil "~A" new-obj)))
665 ;;           (list (is-foo new-obj) (equalp obj new-obj)
666 ;;                 (string= new-string string)
667 ;;                 (f-x new-obj) (f-y new-obj) (f-z new-obj)))))
668 ;;   (t t t 3 2 "Z"))
669
670 ;; (defun run-tests (backend)
671 ;;   (with-backend backend
672 ;;     (regression-test:do-tests))
673 ;;   (when (probe-file *test-file*)
674 ;;     (ignore-errors (delete-file *test-file*))))
Note: See TracBrowser for help on using the browser.