File: test.py

package info (click to toggle)
python-yenc 0.3%2Bdebian-2
  • links: PTS
  • area: main
  • in suites: lenny, squeeze, wheezy
  • size: 188 kB
  • ctags: 93
  • sloc: python: 388; ansic: 375; makefile: 45; sh: 21
file content (80 lines) | stat: -rwxr-xr-x 2,569 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/usr/bin/env python
##=============================================================================
 #
 # Copyright (C) 2003, 2004 Alessandro Duca
 #
 # This program is free software; you can redistribute it and/or
 # modify it under the terms of the GNU General Public License
 # as published by the Free Software Foundation; either version 2
 # of the License, or (at your option) any later version.
 # 
 # This program is distributed in the hope that it will be useful,
 # but WITHOUT ANY WARRANTY; without even the implied warranty of
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
 # 
 # See the GNU General Public License for more details.
 # 
 # You should have received a copy of the GNU General Public License
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 #
 #=============================================================================
 #
 # $Id: test.py,v 1.2 2004/02/18 23:11:46 cvs Exp $
 # 
##=============================================================================

import yenc
import os
import sys
import time
from binascii import crc32
from stat import *

def main():
	os.system("dd if=/dev/urandom of=sampledata bs=1M count=1")
	file_in = open("sampledata","r")
	file_out = open("sampledata.out","w")
	data = file_in.read()
	file_in.seek(0,0)
	size = len(data)
	crc = hex(crc32(data))[2:]
	print "initial file crc: %s dec: %d" % (crc, crc32(data))
	del(data)
	print "Starting encoding test:"
	startime = time.time()
	bytes_out, crc_out = yenc.encode(file_in, file_out, size)
	secs = time.time() - startime
	print "Bytes out:", bytes_out, "output crc:", crc_out
	if crc != crc_out:
		print "crc error, 1Mb block encoding"
		sys.exit(1)
	elif bytes_out != size:
		print "size error, 1Mb block encoding"
		sys.exit(1)
	else:
		print "crc and size, 1Mb block encoding ok. %f secs." % secs

	file_in.close()
	file_out.close()
	os.unlink("sampledata")
	file_in = open("sampledata.out","r")
	file_out = open("sampledata","w")
	print "Starting decoding test:"
	startime = time.time()
	bytes_out, crc_out = yenc.decode(file_in, file_out, size)
	secs = time.time() - startime
	print "Bytes out:", bytes_out, "output crc:", crc_out
	if crc != crc_out:
		print "crc error, 1Mb block decoding"
		sys.exit(1)
	elif bytes_out != size:
		print "size error, 1Mb block decoding"
		sys.exit(1)
	else:
		print "crc and size, 1Mb block decoding ok. %f secs." % secs
	os.unlink("sampledata")
	os.unlink("sampledata.out")

if __name__ == "__main__":
	main()