"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "core/src/test/java/com/google/zxing/datamatrix/encoder/HighLevelEncodeTestCase.java" between
zxing-zxing-3.4.1.tar.gz and zxing-zxing-3.5.0.tar.gz

About: ZXing ("zebra crossing") is a multi-format 1D/2D barcode image processing library implemented in Java, with ports to other languages. Info: Project is in maintenance mode (no active development).

HighLevelEncodeTestCase.java  (zxing-zxing-3.4.1):HighLevelEncodeTestCase.java  (zxing-zxing-3.5.0)
skipping to change at line 19 skipping to change at line 19
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package com.google.zxing.datamatrix.encoder; package com.google.zxing.datamatrix.encoder;
import java.nio.charset.StandardCharsets;
import junit.framework.ComparisonFailure; import junit.framework.ComparisonFailure;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Ignore;
import org.junit.Test; import org.junit.Test;
import java.nio.charset.StandardCharsets;
/** /**
* Tests for {@link HighLevelEncoder}. * Tests for {@link HighLevelEncoder} and {@link MinimalEncoder}
*/ */
public final class HighLevelEncodeTestCase extends Assert { public final class HighLevelEncodeTestCase extends Assert {
private static final SymbolInfo[] TEST_SYMBOLS = { private static final SymbolInfo[] TEST_SYMBOLS = {
new SymbolInfo(false, 3, 5, 8, 8, 1), new SymbolInfo(false, 3, 5, 8, 8, 1),
new SymbolInfo(false, 5, 7, 10, 10, 1), new SymbolInfo(false, 5, 7, 10, 10, 1),
/*rect*/new SymbolInfo(true, 5, 7, 16, 6, 1), /*rect*/new SymbolInfo(true, 5, 7, 16, 6, 1),
new SymbolInfo(false, 8, 10, 12, 12, 1), new SymbolInfo(false, 8, 10, 12, 12, 1),
/*rect*/new SymbolInfo(true, 10, 11, 14, 6, 2), /*rect*/new SymbolInfo(true, 10, 11, 14, 6, 2),
new SymbolInfo(false, 13, 0, 0, 0, 1), new SymbolInfo(false, 13, 0, 0, 0, 1),
skipping to change at line 117 skipping to change at line 115
assertEquals("230 88 88 40 8 107 147 59 67 126 206 78 126 144 121 35 47 254" , visualized); assertEquals("230 88 88 40 8 107 147 59 67 126 206 78 126 144 121 35 47 254" , visualized);
} }
@Test @Test
public void testC40EncodationSpecialCases1() { public void testC40EncodationSpecialCases1() {
//Special tests avoiding ultra-long test strings because these tests are onl y used //Special tests avoiding ultra-long test strings because these tests are onl y used
//with the 16x48 symbol (47 data codewords) //with the 16x48 symbol (47 data codewords)
useTestSymbols(); useTestSymbols();
String visualized = encodeHighLevel("AIMAIMAIMAIMAIMAIM"); String visualized = encodeHighLevel("AIMAIMAIMAIMAIMAIM", false);
assertEquals("230 91 11 91 11 91 11 91 11 91 11 91 11", visualized); assertEquals("230 91 11 91 11 91 11 91 11 91 11 91 11", visualized);
//case "a": Unlatch is not required //case "a": Unlatch is not required
visualized = encodeHighLevel("AIMAIMAIMAIMAIMAI"); visualized = encodeHighLevel("AIMAIMAIMAIMAIMAI", false);
assertEquals("230 91 11 91 11 91 11 91 11 91 11 90 241", visualized); assertEquals("230 91 11 91 11 91 11 91 11 91 11 90 241", visualized);
//case "b": Add trailing shift 0 and Unlatch is not required //case "b": Add trailing shift 0 and Unlatch is not required
visualized = encodeHighLevel("AIMAIMAIMAIMAIMA"); visualized = encodeHighLevel("AIMAIMAIMAIMAIMA");
assertEquals("230 91 11 91 11 91 11 91 11 91 11 254 66", visualized); assertEquals("230 91 11 91 11 91 11 91 11 91 11 254 66", visualized);
//case "c": Unlatch and write last character in ASCII //case "c": Unlatch and write last character in ASCII
resetSymbols(); resetSymbols();
visualized = encodeHighLevel("AIMAIMAIMAIMAIMAI"); visualized = encodeHighLevel("AIMAIMAIMAIMAIMAI");
skipping to change at line 166 skipping to change at line 164
//assertEquals("239 91 11 91 11 91 11 7 49 254", visualized); //assertEquals("239 91 11 91 11 91 11 7 49 254", visualized);
//This is an alternative, but doesn't strictly follow the rules in the spec. //This is an alternative, but doesn't strictly follow the rules in the spec.
visualized = encodeHighLevel("aimaimaIm"); visualized = encodeHighLevel("aimaimaIm");
assertEquals("239 91 11 91 11 87 218 110", visualized); assertEquals("239 91 11 91 11 87 218 110", visualized);
visualized = encodeHighLevel("aimaimaimB"); visualized = encodeHighLevel("aimaimaimB");
assertEquals("239 91 11 91 11 91 11 254 67 129", visualized); assertEquals("239 91 11 91 11 91 11 254 67 129", visualized);
visualized = encodeHighLevel("aimaimaim{txt}\u0004"); visualized = encodeHighLevel("aimaimaim{txt}\u0004");
assertEquals("239 91 11 91 11 91 11 16 218 236 107 181 69 254 129 237", visu alized); assertEquals("239 91 11 91 11 91 11 254 124 117 121 117 126 5 129 237", visu alized);
} }
@Test @Test
public void testX12Encodation() { public void testX12Encodation() {
//238 shifts to X12 encodation, 254 unlatches //238 shifts to X12 encodation, 254 unlatches
String visualized = encodeHighLevel("ABC>ABC123>AB"); String visualized = encodeHighLevel("ABC>ABC123>AB");
assertEquals("238 89 233 14 192 100 207 44 31 67", visualized); assertEquals("238 89 233 14 192 100 207 44 31 67", visualized);
skipping to change at line 242 skipping to change at line 240
assertEquals("231 44 108 59 226 126 1 104", visualized); assertEquals("231 44 108 59 226 126 1 104", visualized);
visualized = encodeHighLevel("\u00ABäöüéà\u00BB"); visualized = encodeHighLevel("\u00ABäöüéà\u00BB");
assertEquals("231 51 108 59 226 126 1 141 254 129", visualized); assertEquals("231 51 108 59 226 126 1 141 254 129", visualized);
visualized = encodeHighLevel("\u00ABäöüéàá\u00BB"); visualized = encodeHighLevel("\u00ABäöüéàá\u00BB");
assertEquals("231 44 108 59 226 126 1 141 36 147", visualized); assertEquals("231 44 108 59 226 126 1 141 36 147", visualized);
visualized = encodeHighLevel(" 23£"); //ASCII only (for reference) visualized = encodeHighLevel(" 23£"); //ASCII only (for reference)
assertEquals("33 153 235 36 129", visualized); assertEquals("33 153 235 36 129", visualized);
visualized = encodeHighLevel("\u00ABäöüé\u00BB 234"); //Mixed Base256 + ASCI I visualized = encodeHighLevel("\u00ABäöüé\u00BB 234"); //Mixed Base256 + ASCI I
assertEquals("231 51 108 59 226 126 1 104 99 153 53 129", visualized); assertEquals("231 50 108 59 226 126 1 104 33 153 53 129", visualized);
visualized = encodeHighLevel("\u00ABäöüé\u00BB 23£ 1234567890123456789"); visualized = encodeHighLevel("\u00ABäöüé\u00BB 23£ 1234567890123456789");
assertEquals("231 55 108 59 226 126 1 104 99 10 161 167 185 142 164 186 208" assertEquals("231 54 108 59 226 126 1 104 99 10 161 167 33 142 164 186 208"
+ " 220 142 164 186 208 58 129 59 209 104 254 150 45", visu alized); + " 220 142 164 186 208 58 129 59 209 104 254 150 45", visu alized);
visualized = encodeHighLevel(createBinaryMessage(20)); visualized = encodeHighLevel(createBinaryMessage(20));
assertEquals("231 44 108 59 226 126 1 141 36 5 37 187 80 230 123 17 166 60 2 10 103 253 150", assertEquals("231 44 108 59 226 126 1 141 36 5 37 187 80 230 123 17 166 60 2 10 103 253 150",
visualized); visualized);
visualized = encodeHighLevel(createBinaryMessage(19)); //padding necessary a t the end visualized = encodeHighLevel(createBinaryMessage(19)); //padding necessary a t the end
assertEquals("231 63 108 59 226 126 1 141 36 5 37 187 80 230 123 17 166 60 2 10 103 1 129", assertEquals("231 63 108 59 226 126 1 141 36 5 37 187 80 230 123 17 166 60 2 10 103 1 129",
visualized); visualized);
visualized = encodeHighLevel(createBinaryMessage(276)); visualized = encodeHighLevel(createBinaryMessage(276));
skipping to change at line 313 skipping to change at line 311
String visualized = encodeHighLevel("Hello World!"); String visualized = encodeHighLevel("Hello World!");
assertEquals("73 239 116 130 175 123 148 64 158 233 254 34", visualized); assertEquals("73 239 116 130 175 123 148 64 158 233 254 34", visualized);
} }
@Test @Test
public void testBug1664266() { public void testBug1664266() {
//There was an exception and the encoder did not handle the unlatching from //There was an exception and the encoder did not handle the unlatching from
//EDIFACT encoding correctly //EDIFACT encoding correctly
String visualized = encodeHighLevel("CREX-TAN:h"); String visualized = encodeHighLevel("CREX-TAN:h");
assertEquals("240 13 33 88 181 64 78 124 59 105", visualized); assertEquals("68 83 70 89 46 85 66 79 59 105", visualized);
visualized = encodeHighLevel("CREX-TAN:hh"); visualized = encodeHighLevel("CREX-TAN:hh");
assertEquals("240 13 33 88 181 64 78 124 59 105 105 129", visualized); assertEquals("68 83 70 89 46 85 66 79 59 105 105 129", visualized);
visualized = encodeHighLevel("CREX-TAN:hhh"); visualized = encodeHighLevel("CREX-TAN:hhh");
assertEquals("240 13 33 88 181 64 78 124 59 105 105 105", visualized); assertEquals("68 83 70 89 46 85 66 79 59 105 105 105", visualized);
} }
@Test @Test
public void testX12Unlatch() { public void testX12Unlatch() {
String visualized = encodeHighLevel("*DTCP01"); String visualized = encodeHighLevel("*DTCP01");
assertEquals("238 9 10 104 141 254 50 129", visualized); assertEquals("43 69 85 68 81 131 129 56", visualized);
} }
@Test @Test
public void testX12Unlatch2() { public void testX12Unlatch2() {
String visualized = encodeHighLevel("*DTCP0"); String visualized = encodeHighLevel("*DTCP0");
assertEquals("238 9 10 104 141", visualized); assertEquals("238 9 10 104 141", visualized);
} }
@Test @Test
public void testBug3048549() { public void testBug3048549() {
//There was an IllegalArgumentException for an illegal character here becaus e //There was an IllegalArgumentException for an illegal character here becaus e
//of an encoding problem of the character 0x0060 in Java source code. //of an encoding problem of the character 0x0060 in Java source code.
String visualized = encodeHighLevel("fiykmj*Rh2`,e6"); String visualized = encodeHighLevel("fiykmj*Rh2`,e6");
assertEquals("239 122 87 154 40 7 171 115 207 12 130 71 155 254 129 237", vi sualized); assertEquals("103 106 122 108 110 107 43 83 105 51 97 45 102 55 129 237", vi sualized);
} }
@Test @Test
public void testMacroCharacters() { public void testMacroCharacters() {
String visualized = encodeHighLevel("[)>\u001E05\u001D5555\u001C6666\u001E\u 0004"); String visualized = encodeHighLevel("[)>\u001E05\u001D5555\u001C6666\u001E\u 0004");
//assertEquals("92 42 63 31 135 30 185 185 29 196 196 31 5 129 87 237", visu alized); //assertEquals("92 42 63 31 135 30 185 185 29 196 196 31 5 129 87 237", visu alized);
assertEquals("236 185 185 29 196 196 129 56", visualized); assertEquals("236 185 185 29 196 196 129 56", visualized);
} }
@Test @Test
public void testEncodingWithStartAsX12AndLatchToEDIFACTInTheMiddle() { public void testEncodingWithStartAsX12AndLatchToEDIFACTInTheMiddle() {
String visualized = encodeHighLevel("*MEMANT-1F-MESTECH"); String visualized = encodeHighLevel("*MEMANT-1F-MESTECH");
assertEquals("238 10 99 164 204 254 240 82 220 70 180 209 83 80 80 200", vis ualized); assertEquals("240 168 209 77 4 229 45 196 107 77 21 53 5 12 135 192", visual ized);
} }
@Ignore
@Test @Test
public void testDataURL() { public void testX12AndEDIFACTSpecErrors() {
//X12 encoding error with spec conform float point comparisons in lookAheadT
byte[] data = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0 est()
x0A, String visualized = encodeHighLevel("AAAAAAAAAAA**\u00FCAAAAAAAAAAAAAAAAAAAA
0x7E, 0x7F, (byte) 0x80, (byte) 0x81, (byte) 0x82}; AAAAAAAAAA");
String expected = encodeHighLevel(new String(data, StandardCharsets.ISO_8859 assertEquals("230 89 191 89 191 89 191 89 178 56 114 10 243 177 63 89 191 89
_1)); 191 89 191 89 191 89 191 89 191 89 " +
String visualized = encodeHighLevel("url(data:text/plain;charset=iso-8859-1, "191 89 191 89 191 254 66 129", visualized);
" //X12 encoding error with integer comparisons in lookAheadTest()
+ "%00%01%02%03%04%05%06%07%08%09%0A visualized = encodeHighLevel("AAAAAAAAAAAA0+****AAAAAAAAAAAAAAAAAAAAAAAAAAAA
%7E%7F%80%81%82)"); AA");
assertEquals(expected, visualized); assertEquals("238 89 191 89 191 89 191 89 191 254 240 194 186 170 170 160 65
assertEquals("1 2 3 4 5 6 7 8 9 10 11 231 153 173 67 218 112 7", visualized) 4 16 65 4 16 65 4 16 65 4 16 65 4 " +
; "16 65 4 16 65 4 16 65 124 129 167 62 212 107", visualized);
//EDIFACT encoding error with spec conform float point comparisons in lookAh
visualized = encodeHighLevel("url(data:;base64,flRlc3R+)"); eadTest()
assertEquals("127 85 102 116 117 127 129 56", visualized); visualized = encodeHighLevel("AAAAAAAAAAA++++\u00FCAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAA");
assertEquals("230 89 191 89 191 89 191 254 66 66 44 44 44 44 235 125 230 89
191 89 191 89 191 89 191 89 191 89 " +
"191 89 191 89 191 89 191 89 191 254 129 17 167 62 212 107", visualized)
;
//EDIFACT encoding error with integer comparisons in lookAheadTest()
visualized = encodeHighLevel("++++++++++AAa0 0++++++++++++++++++++++++++++++
");
assertEquals("240 174 186 235 174 186 235 174 176 65 124 98 240 194 12 43 17
4 186 235 174 186 235 174 186 235 " +
"174 186 235 174 186 235 174 186 235 174 186 235 173 240 129 167 62 212
107", visualized);
visualized = encodeHighLevel("AAAAAAAAAAAA*+AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA")
;
assertEquals("230 89 191 89 191 89 191 89 191 7 170 64 191 89 191 89 191 89
191 89 191 89 191 89 191 89 191 89 " +
"191 89 191 66", visualized);
visualized = encodeHighLevel("AAAAAAAAAAA*0a0 *AAAAAAAAAAAAAAAAAAAAAAAAAAAAA
A");
assertEquals("230 89 191 89 191 89 191 89 178 56 227 6 228 7 183 89 191 89 1
91 89 191 89 191 89 191 89 191 89 " +
"191 89 191 89 191 254 66 66", visualized);
}
@Test
public void testSizes() {
int[] sizes = new int[2];
encodeHighLevel("A", sizes);
assertEquals(3, sizes[0]);
assertEquals(3, sizes[1]);
encodeHighLevel("AB", sizes);
assertEquals(3, sizes[0]);
assertEquals(3, sizes[1]);
encodeHighLevel("ABC", sizes);
assertEquals(3, sizes[0]);
assertEquals(3, sizes[1]);
encodeHighLevel("ABCD", sizes);
assertEquals(5, sizes[0]);
assertEquals(5, sizes[1]);
encodeHighLevel("ABCDE", sizes);
assertEquals(5, sizes[0]);
assertEquals(5, sizes[1]);
encodeHighLevel("ABCDEF", sizes);
assertEquals(5, sizes[0]);
assertEquals(5, sizes[1]);
encodeHighLevel("ABCDEFG", sizes);
assertEquals(8, sizes[0]);
assertEquals(8, sizes[1]);
encodeHighLevel("ABCDEFGH", sizes);
assertEquals(8, sizes[0]);
assertEquals(8, sizes[1]);
encodeHighLevel("ABCDEFGHI", sizes);
assertEquals(8, sizes[0]);
assertEquals(8, sizes[1]);
encodeHighLevel("ABCDEFGHIJ", sizes);
assertEquals(8, sizes[0]);
assertEquals(8, sizes[1]);
encodeHighLevel("a", sizes);
assertEquals(3, sizes[0]);
assertEquals(3, sizes[1]);
encodeHighLevel("ab", sizes);
assertEquals(3, sizes[0]);
assertEquals(3, sizes[1]);
encodeHighLevel("abc", sizes);
assertEquals(3, sizes[0]);
assertEquals(3, sizes[1]);
encodeHighLevel("abcd", sizes);
assertEquals(5, sizes[0]);
assertEquals(5, sizes[1]);
encodeHighLevel("abcdef", sizes);
assertEquals(5, sizes[0]);
assertEquals(5, sizes[1]);
encodeHighLevel("abcdefg", sizes);
assertEquals(8, sizes[0]);
assertEquals(8, sizes[1]);
encodeHighLevel("abcdefgh", sizes);
assertEquals(8, sizes[0]);
assertEquals(8, sizes[1]);
encodeHighLevel("+", sizes);
assertEquals(3, sizes[0]);
assertEquals(3, sizes[1]);
encodeHighLevel("++", sizes);
assertEquals(3, sizes[0]);
assertEquals(3, sizes[1]);
encodeHighLevel("+++", sizes);
assertEquals(3, sizes[0]);
assertEquals(3, sizes[1]);
encodeHighLevel("++++", sizes);
assertEquals(5, sizes[0]);
assertEquals(5, sizes[1]);
encodeHighLevel("+++++", sizes);
assertEquals(5, sizes[0]);
assertEquals(5, sizes[1]);
encodeHighLevel("++++++", sizes);
assertEquals(8, sizes[0]);
assertEquals(8, sizes[1]);
encodeHighLevel("+++++++", sizes);
assertEquals(8, sizes[0]);
assertEquals(8, sizes[1]);
encodeHighLevel("++++++++", sizes);
assertEquals(8, sizes[0]);
assertEquals(8, sizes[1]);
encodeHighLevel("+++++++++", sizes);
assertEquals(8, sizes[0]);
assertEquals(8, sizes[1]);
encodeHighLevel("\u00F0\u00F0" +
"ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRS
TUVWXYZABCDEF", sizes);
assertEquals(114, sizes[0]);
assertEquals(62, sizes[1]);
}
@Test
public void testECIs() {
String visualized = visualize(MinimalEncoder.encodeHighLevel("that particula
rly stands out to me is \u0625\u0650" +
"\u062C\u064E\u0651\u0627\u0635 (\u02BE\u0101\u1E63) \"pear\", suggested
to have originated from Hebrew " +
"\u05D0\u05B7\u05D2\u05B8\u05BC\u05E1 (ag\u00E1s)"));
assertEquals("239 209 151 206 214 92 122 140 35 158 144 162 52 205 55 171 13
7 23 67 206 218 175 147 113 15 254" +
" 116 33 241 25 231 186 14 212 64 253 151 252 159 33 41 241 27 231 83 17
1 53 209 35 25 134 6 42 33 35 239 184" +
" 31 193 234 7 252 205 101 127 241 209 34 24 5 22 23 221 148 179 239 128
140 92 187 106 204 198 59 19 25 114" +
" 248 118 36 254 231 106 196 19 239 101 27 107 69 189 112 236 156 252 16
174 125 24 10 125 116 42 129",
visualized);
visualized = visualize(MinimalEncoder.encodeHighLevel("that particularly sta
nds out to me is \u0625\u0650" +
"\u062C\u064E\u0651\u0627\u0635 (\u02BE\u0101\u1E63) \"pear\", suggested
to have originated from Hebrew " +
"\u05D0\u05B7\u05D2\u05B8\u05BC\u05E1 (ag\u00E1s)", StandardCharsets.UTF
_8, -1 , SymbolShapeHint.FORCE_NONE));
assertEquals("241 27 239 209 151 206 214 92 122 140 35 158 144 162 52 205 55
171 137 23 67 206 218 175 147 113" +
" 15 254 116 33 231 202 33 131 77 154 119 225 163 238 206 28 249 93 36 1
50 151 53 108 246 145 228 217 71" +
" 199 42 33 35 239 184 31 193 234 7 252 205 101 127 241 209 34 24 5 22 2
3 221 148 179 239 128 140 92 187 106" +
" 204 198 59 19 25 114 248 118 36 254 231 43 133 212 175 38 220 44 6 125
49 172 93 189 209 111 61 217 203 62" +
" 116 42 129 1 151 46 196 91 241 137 32 182 77 227 122 18 168 63 213 108
4 154 49 199 94 244 140 35 185 80",
visualized);
}
@Test
public void testPadding() {
int[] sizes = new int[2];
encodeHighLevel("IS010000000000000000000000S1118058599124123S21.2.250.1.213.
1.4.8 S3FIRST NAMETEST S5MS618-06" +
"-1985S713201S4LASTNAMETEST", sizes);
assertEquals(86, sizes[0]);
assertEquals(86, sizes[1]);
}
private static void encodeHighLevel(String msg, int[] sizes) {
sizes[0] = HighLevelEncoder.encodeHighLevel(msg).length();
sizes[1] = MinimalEncoder.encodeHighLevel(msg).length();
} }
private static String encodeHighLevel(String msg) { private static String encodeHighLevel(String msg) {
return encodeHighLevel(msg, true);
}
private static String encodeHighLevel(String msg, boolean compareSizeToMinimal
Encoder) {
CharSequence encoded = HighLevelEncoder.encodeHighLevel(msg); CharSequence encoded = HighLevelEncoder.encodeHighLevel(msg);
//DecodeHighLevel.decode(encoded); CharSequence encoded2 = MinimalEncoder.encodeHighLevel(msg);
assertTrue(!compareSizeToMinimalEncoder || encoded2.length() <= encoded.leng
th());
return visualize(encoded); return visualize(encoded);
} }
/** /**
* Convert a string of char codewords into a different string which lists each character * Convert a string of char codewords into a different string which lists each character
* using its decimal value. * using its decimal value.
* *
* @param codewords the codewords * @param codewords the codewords
* @return the visualized codewords * @return the visualized codewords
*/ */
 End of changes. 19 change blocks. 
34 lines changed or deleted 226 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)