0e5fb1e0504b71bd876d321f09c8fa09a8dcbf9a
[cl-base64.git] / base64-tests.lisp
1 ;;;; -*- Mode: LISP; Syntax: ANSI-Common-Lisp; Base: 10 -*-
2 ;;;; *************************************************************************
3 ;;;; FILE IDENTIFICATION
4 ;;;;
5 ;;;; Name:          test.lisp
6 ;;;; Purpose:       Regression tests for cl-base64
7 ;;;; Programmer:    Kevin M. Rosenberg
8 ;;;; Date Started:  Jan 2003
9 ;;;;
10 ;;;; $Id: base64-tests.lisp,v 1.10 2003/04/15 16:21:43 kevin Exp $
11 ;;;; *************************************************************************
12
13 (in-package :cl-user)
14
15 (defpackage #:base64-test
16     (:use #:cl #:kmrcl #:base64 #:util.test))
17
18 (in-package #:base64-test)
19
20 (defun test-base64 ()
21   (setq *break-on-test-failures* t) 
22   (do* ((length 0 (+ 3 length))
23         (string (make-string length) (make-string length))
24         (usb8 (make-usb8-array length) (make-usb8-array length))
25         (integer (random (expt 10 length)) (random (expt 10 length))))
26        ((>= length 300))
27     (dotimes (i length)
28       (declare (fixnum i))
29       (let ((code (random 256)))
30         (setf (schar string i) (code-char code))
31         (setf (aref usb8 i) code)))
32     
33     (do* ((columns 0 (+ columns 4)))
34          ((> columns length))
35       ;; Test against cl-base64 routines
36       (assert (= integer (base64-string-to-integer
37                           (integer-to-base64-string integer :columns columns))))
38       (assert (string= (base64-string-to-string
39                         (string-to-base64-string string :columns columns))))
40       
41       ;; Test against AllegroCL built-in routines
42       #+allegro
43       (progn
44         (assert (= integer (excl:base64-string-to-integer
45                             (integer-to-base64-string integer :columns columns))))
46         (assert (= integer (base64-string-to-integer
47                             (excl:integer-to-base64-string integer))))
48         (assert (string= (string-to-base64-string string :columns columns)
49                          (excl:usb8-array-to-base64-string usb8
50                                                            (if (zerop columns)
51                                                                nil
52                                                                columns))))
53         (assert (string= string (base64-string-to-string
54                                  (excl:usb8-array-to-base64-string
55                                   usb8
56                                   (if (zerop columns)
57                                       nil
58                                       columns))))))))
59   (format t "~&All tests passed~%")
60   t)
61
62
63 (defun time-routines ()
64   (let* ((str "abcdefghijklmnopqwertyu1234589jhwf2ff")
65          (usb8 (string-to-usb8-array str))
66          (int 12345678901234567890)
67          (n 50000))
68     (time-iterations n (integer-to-base64-string int))
69     #+allegro
70     (time-iterations n (excl:integer-to-base64-string int))
71     (time-iterations n (string-to-base64-string str))
72     #+allegro
73     (time-iterations n (excl:usb8-array-to-base64-string usb8))))
74
75 (export 'test-base64)      
76 ;;(test-base64)