Delete old test gen code

This commit is contained in:
Sean Owen 2014-02-08 09:41:38 -05:00
parent 6292ec0b6f
commit 937d087365
2 changed files with 0 additions and 255 deletions

View file

@ -1,128 +0,0 @@
#!/usr/bin/env python
import os
import glob
import sys
import subprocess
import traceback
import hashlib
import urllib
import urllib2
ZINT = 'zint'
ZINT_RSS_EXPANDED_CODE = 31
ZINT_BINARY = "zint" # If available in PATH
POSTSCRIPT = 'postscript'
TEST_FILE = "../../../src/com/google/zxing/oned/rss/RSSExpandedBlackBox3TestCase.java"
def check_zint():
try:
subprocess.Popen("zint", stdout=subprocess.PIPE, stderr=subprocess.PIPE)
except:
print >> sys.stderr, "zint not installed. Go to http://www.zint.org.uk/ and install it"
return False
return True
def check_postscript():
return True
GENERATORS = []
if check_zint():
GENERATORS.append(ZINT)
if check_postscript():
GENERATORS.append(POSTSCRIPT)
def generate_image_zint(image_filename, barcode):
braces_barcode = barcode.replace("(","[").replace(")","]")
os.system('%s -o %s -b %s -d "%s"' % (ZINT_BINARY, image_filename, ZINT_RSS_EXPANDED_CODE, braces_barcode.replace('"','\\"')))
def generate_image_postscript(image_filename, barcode):
hashname = "cache/%s.png" % hashlib.new("md5", barcode).hexdigest()
# If it exists in the cache, don't download it
if os.path.exists(hashname):
content = open(hashname).read()
open(image_filename,'w').write(content)
return
# We tried use the Python, Perl and LaTeX bindings without success :-(
baseurl = "http://www.terryburton.co.uk/barcodewriter/generator/"
encoded = urllib.urlencode({
"encoder" : "rssexpanded",
"data" : barcode,
"options" : "",
"translate_x" : "50", "translate_y" : "50",
"scale_x" : "2", "scale_y" : "2",
"rotate" : "0", "submit" : "Make Barcode"
})
web_urlobject = urllib2.urlopen(baseurl, data = encoded)
web_content = web_urlobject.read()
png_url = web_content.split('">PNG</a>')[0].split('<a href="')[-1]
if not png_url.startswith("tmp"):
raise Exception("There was an error processing barcode %s in postscript" % barcode)
full_url = baseurl + png_url
png_content = urllib2.urlopen(full_url).read()
open(hashname,'w').write(png_content)
open(image_filename,'w').write(png_content)
def generate_image(image_filename, barcode, generator):
if generator == ZINT:
generate_image_zint(image_filename, barcode)
elif generator == POSTSCRIPT:
generate_image_postscript(image_filename, barcode)
else:
raise Exception("Unknown generator: %s" % generator)
def extract_barcodes():
for line in open("generation.config"):
content = line.split("#")[0].strip()
if content != "":
if content[0] == '-':
pos = content[1:].find('-')
exceptions = content[1:pos+1].split(",")
barcode = content[pos + 2:]
yield exceptions, barcode
else:
yield (), content
if __name__ == '__main__':
counter = 0
for image_to_delete in glob.glob("*.png"):
os.remove(image_to_delete)
for text_to_delete in glob.glob("*.txt"):
os.remove(text_to_delete)
for generator in GENERATORS:
for exceptions, barcode in extract_barcodes():
if generator in exceptions:
continue
try:
counter += 1
image_filename = str(counter) + ".png"
text_filename = str(counter) + ".txt"
open(text_filename, "w").write(barcode)
generate_image(image_filename, barcode, generator)
except Exception:
print "Error with generator %s and barcode %s" % (generator, barcode)
traceback.print_exc()
counter -= 1
open(TEST_FILE,'w').write("""package com.google.zxing.oned.rss;
import com.google.zxing.BarcodeFormat;
import com.google.zxing.MultiFormatReader;
import com.google.zxing.common.AbstractBlackBoxTestCase;
public class RSSExpandedBlackBox3TestCase extends AbstractBlackBoxTestCase {
public RSSExpandedBlackBox3TestCase() {
super("test/data/blackbox/rssexpanded-3", new MultiFormatReader(), BarcodeFormat.RSS_EXPANDED);
addTest(%(number)s, %(number)s, 0.0f);
addTest(%(number)s, %(number)s, 180.0f);
}
}
""" % {"number" : counter})

View file

@ -1,127 +0,0 @@
###########################################################
#
# Place codes in this file, and they will be automatically
# generated by "generate.py". Everything placed after a "#"
# will be ignored, as well as every space before and after
# the codes and empty lines.
#
# If a generator can't generate a code, then place:
# -LIBRARY-. For example, if zint doesn't support a code,
# place -zint-. If neither zint or postscript support it,
# place -zint,postscript-.
#
#
#################################################
# Fixed length examples
# Encodation 0111000 - 0111111
(01)90012345678908(3103)012233(15)991231 # Example taken from 7.2.5.4.4
(01)91234567980129(3103)012233(15)991231 # Testing with other AI
(01)91234567980129(3102)012233(15)991231 # Testing with 3102 instead of 3103
(01)91234567980129(3102)012233(15)000101 # January 1st, 2000
# Encodation 0100
(01)90012345678908(3103)001750 # Example taken from 7.2.5.4.2
(01)92109876543213(3103)032767 # Maximum weight value
(01)92109876543213(3103)000000 # Minimum weight value
# Encodation 0101
(01)90012345678908(3202)000156 # Example taken from 7.2.5.4.3
(01)90012345678908(3202)009999 # 9,999 has a different behaviour than 10,000
(01)90012345678908(3203)010000 # 10,000 has a different behaviour than 9,999
(01)90012345678908(3203)032767 # 10,000 has a different behaviour than 9,999
#################################################
# Variable length examples
# Encodation 01100
(01)90012345678908(3922)795 # Example taken from 7.2.5.4.5
(01)90012345678908(3922)795888888888888888888888888888888888888888888888888888 # Longer information
# Encodation 01101
(01)90012345678908(3932)0401234 # Example taken from 7.2.5.4.6
# These three examples don't work due to a bug in zint. It has been reported.
# However, they work with http://www.terryburton.co.uk/barcodewriter/generator/
#
-zint-(01)90012345678908(3932)040EUR # Testing with alphanumeric instead of numeric
-zint-(01)90012345678908(3932)04055GBP # Testing with numeric + alphanumeric instead of only numeric
-zint-(01)90012345678908(3932)04066USD778899 # Testing with numeric + alphanumeric + numeric instead of only numeric
# Encodation 1
(01)00012345678905(10)ABC123 # Example taken from 7.2.5.4.1
(01)12345678901231(10)UNIVERSITY-OF-DEUSTO # Adding other type of information
(01)12345678901231(10)PIRAMIDE-PROJECT # Adding other type of information
(01)12345678901231(10)TREELOGIC # Adding other type of information
#
# Zint doesn't support this one because after 12A (alphanumeric) it goes back to numeric without a alpha to numeric latch
-zint-(01)98898765432106(15)991231(3103)001750(10)12A(422)123(21)123456(423)012345678901 # Adding a lot of information
# Encodation 00
# # Zint doesn't support this one because after 12A (alphanumeric) it goes back to numeric without a alpha to numeric latch
-zint-(15)991231(3103)001750(10)12A(422)123(21)123456(423)0123456789012 # Adding a lot of information
(10)5678(11)010101 # This one optimizes the last 4 bits as detailed in the end of 7.2.5.5.1
(10)5678(11)001010
(10)567890(11)010101
(10)567(11)010101
# Other tests with special characters, such as: '*',',','-','/','.',
# and ISO/IEC646 encodation characters
(10)1098-1234
(10)1098,1234
(10)1098/1234
(10)1098.1234
(10)1098*1234
(10)1098a1234
(10)1098!1234
(10)1098"1234
(10)1098%1234
(10)1098&1234
(10)1098'1234
(10)1098+1234
(10)1098:1234
(10)1098;1234
(10)1098<1234
(10)1098=1234
(10)1098>1234
(10)1098?1234
(10)1098_1234
(10)1098 1234
# Testing transitions
(10)123456A # numeric -> alpha
-zint-(10)123456A1 # numeric -> alpha
-zint-(10)123456A123 # numeric -> alpha
(10)123456A1234 # numeric -> alpha -> numeric
(10)123456A1234A # numeric -> alpha
(10)123456A123456 # numeric -> alpha -> numeric
(10)123456A12345678 # numeric -> alpha -> numeric
-zint-(10)123456A1234A(15)991231 # numeric -> alpha -> FNC1
(10)1ABCDEF;:/1234567 # numeric -> alpha -> 646 -> numeric
(10)1ABCDEF;:/ABCDEFG # numeric -> alpha -> 646 -> alpha
(10)1;:/ABCDEFGHIJKLM # numeric -> 646 -> alpha
(10)1;:/0123456789012 # numeric -> 646 -> numeric
(10)1;:/0123 # numeric -> 646
(10)1;:/0123(15)991231 # numeric -> 646 -> FNC1 numeric
# Another tests, from 7.2.5.5.2
-zint-(10)1
# Another bug in zint, it works with http://www.terryburton.co.uk/barcodewriter/generator/
-zint-(10)12A
# Another bug in zint, it works with the http://www.terryburton.co.uk/barcodewriter/generator/
-zint-(10)123