r4489: Auto commit for Debian build
[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.6 2003/04/15 16:02:21 kevin Exp $
11 ;;;; *************************************************************************
12
13 (in-package :cl-user)
14
15 (in-package #:base64)
16
17 (defun test-base64 ()
18   (setq *break-on-test-failures* t) 
19   (with-tests (:name "cl-base64 tests")
20     (do* ((length 0 (+ 3 length))
21           (string (make-string length) (make-string length))
22           (usb8 (make-usb8-array length) (make-usb8-array length))
23           (integer (random (expt 10 length)) (random (expt 10 length))))
24          ((>= length 300))
25     (dotimes (i length)
26       (declare (fixnum i))
27       (let ((code (random 256)))
28         (setf (schar string i) (code-char code))
29         (setf (aref usb8 i) code)))
30
31       (do* ((columns 0 (+ columns 4)))
32            ((> columns length))
33       ;; Test against cl-base64 routines
34         (test integer (base64-string-to-integer
35                                  (integer-to-base64-string integer :columns columns)))
36         (test string (base64-string-to-string
37                                 (string-to-base64-string string :columns columns))
38                       :test #'string=)
39       
40       ;; Test against AllegroCL built-in routines
41       #+allegro
42       (progn
43       (test integer (excl:base64-string-to-integer
44                                (integer-to-base64-string integer :columns columns)))
45       (test integer (base64-string-to-integer
46                                (excl:integer-to-base64-string integer)))
47       (test (string-to-base64-string string :columns columns)
48             (excl:usb8-array-to-base64-string usb8
49                                               (if (zerop columns)
50                                                   nil
51                                                   columns))
52             :test #'string=)
53       (test string (base64-string-to-string
54                     (excl:usb8-array-to-base64-string
55                      usb8
56                      (if (zerop columns)
57                          nil
58                          columns)))
59             :test #'string=)))))
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     (time-iterations n (excl:integer-to-base64-string int))
70     (time-iterations n (string-to-base64-string str))
71     (time-iterations n (excl:usb8-array-to-base64-string usb8))))
72
73 (export 'test-base64)      
74 ;;(test-base64)