Dash:
[t2.git] / misc / luabash / md5 / test.lua
blobf45e0fd982c3c7b1c30fe80aa9008eab68560e7f
1 #!/usr/bin/env lua
3 -- --- T2-COPYRIGHT-NOTE-BEGIN ---
4 -- This copyright note is auto-generated by ./scripts/Create-CopyPatch.
5 --
6 -- T2 SDE: misc/luabash/md5/test.lua
7 -- Copyright (C) 2006 The T2 SDE Project
8 --
9 -- More information can be found in the files COPYING and README.
10 --
11 -- This program is free software; you can redistribute it and/or modify
12 -- it under the terms of the GNU General Public License as published by
13 -- the Free Software Foundation; version 2 of the License. A copy of the
14 -- GNU General Public License can be found in the file COPYING.
15 -- --- T2-COPYRIGHT-NOTE-END ---
17 require"md5"
19 -- test some known sums
20 assert(md5.sum("") == "d41d8cd98f00b204e9800998ecf8427e")
21 assert(md5.sum("a") == "0cc175b9c0f1b6a831c399e269772661")
22 assert(md5.sum("abc") == "900150983cd24fb0d6963f7d28e17f72")
23 assert(md5.sum("message digest") == "f96b697d7cb7938d525a2f31aaf161d0")
24 assert(md5.sum("abcdefghijklmnopqrstuvwxyz") == "c3fcd3d76192e4007dfb496cca67e13b")
25 assert(md5.sum("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789")
26 == "d174ab98d277d9f5a5611c2c9f419d9f")
29 -- test padding borders
30 assert(md5.sum(string.rep('a',53)) == "e9e7e260dce84ffa6e0e7eb5fd9d37fc")
31 assert(md5.sum(string.rep('a',54)) == "eced9e0b81ef2bba605cbc5e2e76a1d0")
32 assert(md5.sum(string.rep('a',55)) == "ef1772b6dff9a122358552954ad0df65")
33 assert(md5.sum(string.rep('a',56)) == "3b0c8ac703f828b04c6c197006d17218")
34 assert(md5.sum(string.rep('a',57)) == "652b906d60af96844ebd21b674f35e93")
35 assert(md5.sum(string.rep('a',63)) == "b06521f39153d618550606be297466d5")
36 assert(md5.sum(string.rep('a',64)) == "014842d480b571495a4a0363793f7367")
37 assert(md5.sum(string.rep('a',65)) == "c743a45e0d2e6a95cb859adae0248435")
38 assert(md5.sum(string.rep('a',255)) == "46bc249a5a8fc5d622cf12c42c463ae0")
39 assert(md5.sum(string.rep('a',256)) == "81109eec5aa1a284fb5327b10e9c16b9")
41 assert(md5.sum(
42 "12345678901234567890123456789012345678901234567890123456789012345678901234567890")
43 == "57edf4a22be3c955ac49da2e2107b67a")
46 print"OK"
48 -- our t2 use case
49 -- cut -d ' ' -f 2 /var/adm/flists/gtk+ | grep -v '^var/adm/' | sed -e 's,^.*,/"\0",' | xargs -r /usr/embutils/md5sum
51 local f = io.open ("/var/adm/flists/gtk+", "r")
53 for line in f:lines() do
54 local sum, file = string.match (line, "(%S*)%s(.*)")
55 --print (sum .. ": " ..file)
57 local f2 = io.open ("/"..file)
58 print (md5.sum(f2) .. " " .. "/"..file)
60 f2:close()
61 end
62 f:close()