KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > krysalis > barcode > impl > UPCEANTest


1 /*
2  * $Id: UPCEANTest.java,v 1.1 2003/04/11 15:29:32 jmaerki Exp $
3  * ============================================================================
4  * The Krysalis Patchy Software License, Version 1.1_01
5  * Copyright (c) 2002-2003 Nicola Ken Barozzi. All rights reserved.
6  *
7  * This Licence is compatible with the BSD licence as described and
8  * approved by http://www.opensource.org/, and is based on the
9  * Apache Software Licence Version 1.1.
10  *
11  * Redistribution and use in source and binary forms, with or without
12  * modification, are permitted provided that the following conditions
13  * are met:
14  *
15  * 1. Redistributions of source code must retain the above copyright
16  * notice, this list of conditions and the following disclaimer.
17  *
18  * 2. Redistributions in binary form must reproduce the above copyright
19  * notice, this list of conditions and the following disclaimer in
20  * the documentation and/or other materials provided with the
21  * distribution.
22  *
23  * 3. The end-user documentation included with the redistribution,
24  * if any, must include the following acknowledgment:
25  * "This product includes software developed for project
26  * Krysalis (http://www.krysalis.org/)."
27  * Alternately, this acknowledgment may appear in the software itself,
28  * if and wherever such third-party acknowledgments normally appear.
29  *
30  * 4. The names "Krysalis" and "Nicola Ken Barozzi" and
31  * "Krysalis Barcode" must not be used to endorse or promote products
32  * derived from this software without prior written permission. For
33  * written permission, please contact nicolaken@krysalis.org.
34  *
35  * 5. Products derived from this software may not be called "Krysalis",
36  * "Krysalis Barcode", nor may "Krysalis" appear in their name,
37  * without prior written permission of Nicola Ken Barozzi.
38  *
39  * 6. This software may contain voluntary contributions made by many
40  * individuals, who decided to donate the code to this project in
41  * respect of this licence, and was originally created by
42  * Jeremias Maerki <jeremias@maerki.org>.
43  *
44  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
45  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
46  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
47  * DISCLAIMED. IN NO EVENT SHALL THE KRYSALIS PROJECT OR
48  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
49  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
50  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
51  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
52  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
53  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
54  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
55  * SUCH DAMAGE.
56  * ====================================================================
57  */

58 package org.krysalis.barcode.impl;
59
60 import org.krysalis.barcode.ChecksumMode;
61
62 import junit.framework.TestCase;
63
64 /**
65  * Test class for general UPC/EAN functionality.
66  *
67  * @author Jeremias Maerki
68  */

69 public class UPCEANTest extends TestCase {
70
71     public UPCEANTest(String JavaDoc name) {
72         super(name);
73     }
74
75     public void testRemoveSupplemental() throws Exception JavaDoc {
76         assertEquals("1234", UPCEANLogicImpl.removeSupplemental("1234"));
77         assertEquals("1234", UPCEANLogicImpl.removeSupplemental("1234+20"));
78     }
79
80     public void testRetrieveSupplemental() throws Exception JavaDoc {
81         assertNull(UPCEANLogicImpl.retrieveSupplemental("1234"));
82         assertEquals("20", UPCEANLogicImpl.retrieveSupplemental("1234+20"));
83     }
84     
85     public void testGetSupplementalLength() throws Exception JavaDoc {
86         assertEquals(0, UPCEANLogicImpl.getSupplementalLength("1234"));
87         assertEquals(2, UPCEANLogicImpl.getSupplementalLength("1234+12"));
88         assertEquals(5, UPCEANLogicImpl.getSupplementalLength("1234+12345"));
89         try {
90             UPCEANLogicImpl.getSupplementalLength("1234+123");
91         } catch (IllegalArgumentException JavaDoc iae) {
92             //must fail
93
}
94     }
95
96     public void testSupplemental2() throws Exception JavaDoc {
97         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
98         EAN13LogicImpl logic;
99         String JavaDoc expected;
100         
101         logic = new EAN13LogicImpl(ChecksumMode.CP_AUTO);
102         logic.drawSupplemental(new MockClassicBarcodeLogicHandler(sb), "34");
103         expected = "<SBG:upc-ean-supp:34>"
104             + "<SBG:upc-ean-guard:null>B1W1B2</SBG>"
105             + "<SBG:msg-char:3>W1B1W4B1</SBG>"
106             + "<SBG:upc-ean-guard:null>W1B1</SBG>"
107             + "<SBG:msg-char:4>W1B1W3B2</SBG>"
108             + "</SBG>";
109         //System.out.println("expected: " + expected);
110
//System.out.println("actual: " + sb.toString());
111
assertEquals(expected, sb.toString());
112     }
113
114     public void testSupplemental5() throws Exception JavaDoc {
115         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
116         EAN13LogicImpl logic;
117         String JavaDoc expected;
118         
119         logic = new EAN13LogicImpl(ChecksumMode.CP_AUTO);
120         logic.drawSupplemental(new MockClassicBarcodeLogicHandler(sb), "51234");
121         expected = "<SBG:upc-ean-supp:51234>"
122             + "<SBG:upc-ean-guard:null>B1W1B2</SBG>"
123             + "<SBG:msg-char:5>W1B2W3B1</SBG>"
124             + "<SBG:upc-ean-guard:null>W1B1</SBG>"
125             + "<SBG:msg-char:1>W2B2W2B1</SBG>"
126             + "<SBG:upc-ean-guard:null>W1B1</SBG>"
127             + "<SBG:msg-char:2>W2B2W1B2</SBG>"
128             + "<SBG:upc-ean-guard:null>W1B1</SBG>"
129             + "<SBG:msg-char:3>W1B4W1B1</SBG>"
130             + "<SBG:upc-ean-guard:null>W1B1</SBG>"
131             + "<SBG:msg-char:4>W2B3W1B1</SBG>"
132             + "</SBG>";
133         //System.out.println("expected: " + expected);
134
//System.out.println("actual: " + sb.toString());
135
assertEquals(expected, sb.toString());
136     }
137
138 }
Popular Tags