1 58 package org.krysalis.barcode.impl; 59 60 import org.krysalis.barcode.ChecksumMode; 61 62 import junit.framework.TestCase; 63 64 69 public class UPCEANTest extends TestCase { 70 71 public UPCEANTest(String name) { 72 super(name); 73 } 74 75 public void testRemoveSupplemental() throws Exception { 76 assertEquals("1234", UPCEANLogicImpl.removeSupplemental("1234")); 77 assertEquals("1234", UPCEANLogicImpl.removeSupplemental("1234+20")); 78 } 79 80 public void testRetrieveSupplemental() throws Exception { 81 assertNull(UPCEANLogicImpl.retrieveSupplemental("1234")); 82 assertEquals("20", UPCEANLogicImpl.retrieveSupplemental("1234+20")); 83 } 84 85 public void testGetSupplementalLength() throws Exception { 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 iae) { 92 } 94 } 95 96 public void testSupplemental2() throws Exception { 97 StringBuffer sb = new StringBuffer (); 98 EAN13LogicImpl logic; 99 String 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 assertEquals(expected, sb.toString()); 112 } 113 114 public void testSupplemental5() throws Exception { 115 StringBuffer sb = new StringBuffer (); 116 EAN13LogicImpl logic; 117 String 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 assertEquals(expected, sb.toString()); 136 } 137 138 } | Popular Tags |