annotate tests/automated/md5-tests.el @ 394:7d59cb494b73 r21-2-12

Import from CVS: tag r21-2-12
author cvs
date Mon, 13 Aug 2007 11:11:37 +0200
parents bbff43aa5eb7
children 74fd4e045ea6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
384
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents:
diff changeset
1 ;; Copyright (C) 1998 Free Software Foundation, Inc.
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents:
diff changeset
2
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents:
diff changeset
3 ;; Author: Hrvoje Niksic <hniksic@srce.hr>
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents:
diff changeset
4 ;; Maintainer: Hrvoje Niksic <hniksic@srce.hr>
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents:
diff changeset
5 ;; Created: 1998
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents:
diff changeset
6 ;; Keywords: tests
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents:
diff changeset
7
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents:
diff changeset
8 ;; This file is part of XEmacs.
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents:
diff changeset
9
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents:
diff changeset
10 ;; XEmacs is free software; you can redistribute it and/or modify it
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents:
diff changeset
11 ;; under the terms of the GNU General Public License as published by
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents:
diff changeset
12 ;; the Free Software Foundation; either version 2, or (at your option)
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents:
diff changeset
13 ;; any later version.
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents:
diff changeset
14
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents:
diff changeset
15 ;; XEmacs is distributed in the hope that it will be useful, but
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents:
diff changeset
16 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents:
diff changeset
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents:
diff changeset
18 ;; General Public License for more details.
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents:
diff changeset
19
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents:
diff changeset
20 ;; You should have received a copy of the GNU General Public License
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents:
diff changeset
21 ;; along with XEmacs; see the file COPYING. If not, write to the Free
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents:
diff changeset
22 ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents:
diff changeset
23 ;; 02111-1307, USA.
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents:
diff changeset
24
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents:
diff changeset
25 ;;; Synched up with: not in FSF Emacs.
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents:
diff changeset
26
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents:
diff changeset
27 ;;; Commentary:
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents:
diff changeset
28
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents:
diff changeset
29 ;; Test basic md5 functionality.
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents:
diff changeset
30 ;; See test-harness.el for instructions on how to run these tests.
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents:
diff changeset
31
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents:
diff changeset
32 (eval-when-compile
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents:
diff changeset
33 (condition-case nil
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents:
diff changeset
34 (require 'test-harness)
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents:
diff changeset
35 (file-error
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents:
diff changeset
36 (push "." load-path)
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents:
diff changeset
37 (when (and (boundp 'load-file-name) (stringp load-file-name))
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents:
diff changeset
38 (push (file-name-directory load-file-name) load-path))
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents:
diff changeset
39 (require 'test-harness))))
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents:
diff changeset
40
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents:
diff changeset
41 (defconst md5-tests
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents:
diff changeset
42 '(
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents:
diff changeset
43 ;; Test samples from rfc1321:
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents:
diff changeset
44 ("" . "d41d8cd98f00b204e9800998ecf8427e")
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents:
diff changeset
45 ("a" . "0cc175b9c0f1b6a831c399e269772661")
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents:
diff changeset
46 ("abc" . "900150983cd24fb0d6963f7d28e17f72")
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents:
diff changeset
47 ("message digest" . "f96b697d7cb7938d525a2f31aaf161d0")
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents:
diff changeset
48 ("abcdefghijklmnopqrstuvwxyz" . "c3fcd3d76192e4007dfb496cca67e13b")
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents:
diff changeset
49 ("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents:
diff changeset
50 . "d174ab98d277d9f5a5611c2c9f419d9f")
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents:
diff changeset
51 ("12345678901234567890123456789012345678901234567890123456789012345678901234567890"
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents:
diff changeset
52 . "57edf4a22be3c955ac49da2e2107b67a")))
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents:
diff changeset
53
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents:
diff changeset
54 ;;-----------------------------------------------------
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents:
diff changeset
55 ;; Test `md5' on strings
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents:
diff changeset
56 ;;-----------------------------------------------------
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents:
diff changeset
57
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents:
diff changeset
58 (mapcar (lambda (x)
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents:
diff changeset
59 (Assert (equal (md5 (car x)) (cdr x))))
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents:
diff changeset
60 md5-tests)
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents:
diff changeset
61
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents:
diff changeset
62 ;;-----------------------------------------------------
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents:
diff changeset
63 ;; Test `md5' on portions of strings
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents:
diff changeset
64 ;;-----------------------------------------------------
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents:
diff changeset
65
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents:
diff changeset
66 (let ((large-string (mapconcat #'car md5-tests "")))
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents:
diff changeset
67 (let ((count 0))
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents:
diff changeset
68 (mapcar (lambda (x)
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents:
diff changeset
69 (Assert (equal (md5 large-string count (+ count (length (car x))))
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents:
diff changeset
70 (cdr x)))
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents:
diff changeset
71 (incf count (length (car x))))
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents:
diff changeset
72 md5-tests)))
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents:
diff changeset
73
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents:
diff changeset
74 ;;-----------------------------------------------------
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents:
diff changeset
75 ;; Test `md5' on buffer
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents:
diff changeset
76 ;;-----------------------------------------------------
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents:
diff changeset
77
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents:
diff changeset
78 (with-temp-buffer
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents:
diff changeset
79 (mapcar (lambda (x)
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents:
diff changeset
80 (erase-buffer)
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents:
diff changeset
81 (insert (car x))
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents:
diff changeset
82 (Assert (equal (md5 (current-buffer)) (cdr x))))
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents:
diff changeset
83 md5-tests))
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents:
diff changeset
84
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents:
diff changeset
85 ;;-----------------------------------------------------
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents:
diff changeset
86 ;; Test `md5' on portions of buffer
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents:
diff changeset
87 ;;-----------------------------------------------------
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents:
diff changeset
88
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents:
diff changeset
89 (with-temp-buffer
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents:
diff changeset
90 (insert (mapconcat #'car md5-tests ""))
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents:
diff changeset
91 (let ((point 1))
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents:
diff changeset
92 (mapcar (lambda (x)
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents:
diff changeset
93 (Assert (equal (md5 (current-buffer) point (+ point (length (car x))))
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents:
diff changeset
94 (cdr x)))
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents:
diff changeset
95 (incf point (length (car x))))
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents:
diff changeset
96 md5-tests)))