test_maxicode.c 119 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010
  1. /*
  2. libzint - the open source barcode library
  3. Copyright (C) 2019-2024 Robin Stuart <rstuart114@gmail.com>
  4. Redistribution and use in source and binary forms, with or without
  5. modification, are permitted provided that the following conditions
  6. are met:
  7. 1. Redistributions of source code must retain the above copyright
  8. notice, this list of conditions and the following disclaimer.
  9. 2. Redistributions in binary form must reproduce the above copyright
  10. notice, this list of conditions and the following disclaimer in the
  11. documentation and/or other materials provided with the distribution.
  12. 3. Neither the name of the project nor the names of its contributors
  13. may be used to endorse or promote products derived from this software
  14. without specific prior written permission.
  15. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  16. ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  17. IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  18. ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
  19. FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  20. DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  21. OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  22. HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  23. LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  24. OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  25. SUCH DAMAGE.
  26. */
  27. /* SPDX-License-Identifier: BSD-3-Clause */
  28. #include "testcommon.h"
  29. static void test_large(const testCtx *const p_ctx) {
  30. int debug = p_ctx->debug;
  31. struct item {
  32. int option_1;
  33. int option_2;
  34. char *pattern;
  35. int length;
  36. char *primary;
  37. int ret;
  38. int expected_rows;
  39. int expected_width;
  40. int bwipp_cmp;
  41. char *comment;
  42. };
  43. /* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */
  44. static const struct item data[] = {
  45. /* 0*/ { -1, -1, "1", 138, "", 0, 33, 30, 1, "Mode 4 (138 agrees with ISO/IEC 16023:2000)" },
  46. /* 1*/ { -1, -1, "1", 139, "", ZINT_ERROR_TOO_LONG, -1, -1, 1, "" },
  47. /* 2*/ { -1, -1, "1", 144, "", ZINT_ERROR_TOO_LONG, -1, -1, 1, "" },
  48. /* 3*/ { -1, -1, "1", 145, "", ZINT_ERROR_TOO_LONG, -1, -1, 1, "Absolute max" },
  49. /* 4*/ { -1, -1, "A", 93, "", 0, 33, 30, 1, "" },
  50. /* 5*/ { -1, -1, "A", 94, "", ZINT_ERROR_TOO_LONG, -1, -1, 1, "" },
  51. /* 6*/ { -1, -1, "\001", 91, "", 0, 33, 30, 1, "" },
  52. /* 7*/ { -1, -1, "\001", 92, "", ZINT_ERROR_TOO_LONG, -1, -1, 1, "" },
  53. /* 8*/ { -1, -1, "\200", 91, "", 0, 33, 30, 1, "" },
  54. /* 9*/ { -1, -1, "\200", 92, "", ZINT_ERROR_TOO_LONG, -1, -1, 1, "" },
  55. /* 10*/ { 2, -1, "1", 126, "123456789123123", 0, 33, 30, 1, "" },
  56. /* 11*/ { 2, -1, "1", 127, "123456789123123", ZINT_ERROR_TOO_LONG, -1, -1, 1, "" },
  57. /* 12*/ { 2, -1, "A", 84, "123456789123123", 0, 33, 30, 1, "" },
  58. /* 13*/ { 2, -1, "A", 85, "123456789123123", ZINT_ERROR_TOO_LONG, -1, -1, 1, "" },
  59. /* 14*/ { 2, 96 + 1, "1", 109, "123456789123123", 0, 33, 30, 1, "" },
  60. /* 15*/ { 2, 96 + 1, "1", 110, "123456789123123", ZINT_ERROR_TOO_LONG, -1, -1, 1, "" },
  61. /* 16*/ { 2, 96 + 1, "1", 136, "123456789123123", ZINT_ERROR_TOO_LONG, -1, -1, 1, "Absolute max with SCM vv" },
  62. /* 17*/ { 3, -1, "1", 126, "ABCDEF123123", 0, 33, 30, 1, "" },
  63. /* 18*/ { 3, -1, "1", 127, "ABCDEF123123", ZINT_ERROR_TOO_LONG, -1, -1, 1, "" },
  64. /* 19*/ { 3, -1, "A", 84, "ABCDEF123123", 0, 33, 30, 1, "" },
  65. /* 20*/ { 3, -1, "A", 85, "ABCDEF123123", ZINT_ERROR_TOO_LONG, -1, -1, 1, "" },
  66. /* 21*/ { 3, 96 + 1, "1", 109, "ABCDEF123123", 0, 33, 30, 1, "" },
  67. /* 22*/ { 3, 96 + 1, "1", 110, "ABCDEF123123", ZINT_ERROR_TOO_LONG, -1, -1, 1, "" },
  68. /* 23*/ { 0, -1, "1", 126, "123456789123123", 0, 33, 30, 1, "Mode 2" },
  69. /* 24*/ { 0, -1, "1", 127, "123456789123123", ZINT_ERROR_TOO_LONG, -1, -1, 1, "" },
  70. /* 25*/ { 0, -1, "1", 126, "ABCDEF123123", 0, 33, 30, 1, "Mode 3" },
  71. /* 26*/ { 0, -1, "1", 127, "ABCDEF123123", ZINT_ERROR_TOO_LONG, -1, -1, 1, "" },
  72. /* 27*/ { 5, -1, "1", 113, "", 0, 33, 30, 1, "Extra EEC" },
  73. /* 28*/ { 5, -1, "1", 114, "", ZINT_ERROR_TOO_LONG, -1, -1, 1, "" },
  74. /* 29*/ { 5, -1, "A", 77, "", 0, 33, 30, 1, "" },
  75. /* 30*/ { 5, -1, "A", 78, "", ZINT_ERROR_TOO_LONG, -1, -1, 1, "" },
  76. /* 31*/ { 6, -1, "1", 138, "", 0, 33, 30, 1, "" },
  77. /* 32*/ { 6, -1, "1", 139, "", ZINT_ERROR_TOO_LONG, -1, -1, 1, "" },
  78. /* 33*/ { 6, -1, "A", 93, "", 0, 33, 30, 1, "" },
  79. /* 34*/ { 6, -1, "A", 94, "", ZINT_ERROR_TOO_LONG, -1, -1, 1, "" },
  80. };
  81. const int data_size = ARRAY_SIZE(data);
  82. int i, length, ret;
  83. struct zint_symbol *symbol = NULL;
  84. char data_buf[256];
  85. char escaped[1024];
  86. char cmp_buf[32768];
  87. char cmp_msg[1024];
  88. const char expected_errtxt[] = "Error 553: Input too long, requires too many codewords (maximum 144)";
  89. int do_bwipp = (debug & ZINT_DEBUG_TEST_BWIPP) && testUtilHaveGhostscript(); /* Only do BWIPP test if asked, too slow otherwise */
  90. int do_zxingcpp = (debug & ZINT_DEBUG_TEST_ZXINGCPP) && testUtilHaveZXingCPPDecoder(); /* Only do ZXing-C++ test if asked, too slow otherwise */
  91. testStartSymbol("test_large", &symbol);
  92. for (i = 0; i < data_size; i++) {
  93. if (testContinue(p_ctx, i)) continue;
  94. symbol = ZBarcode_Create();
  95. assert_nonnull(symbol, "Symbol not created\n");
  96. testUtilStrCpyRepeat(data_buf, data[i].pattern, data[i].length);
  97. assert_equal(data[i].length, (int) strlen(data_buf), "i:%d length %d != strlen(data_buf) %d\n", i, data[i].length, (int) strlen(data_buf));
  98. length = testUtilSetSymbol(symbol, BARCODE_MAXICODE, -1 /*input_mode*/, -1 /*eci*/, data[i].option_1, data[i].option_2, -1, -1 /*output_options*/, data_buf, data[i].length, debug);
  99. strcpy(symbol->primary, data[i].primary);
  100. ret = ZBarcode_Encode(symbol, (unsigned char *) data_buf, length);
  101. assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
  102. assert_equal(symbol->errtxt[0] == '\0', ret == 0, "i:%d symbol->errtxt not %s (%s)\n", i, ret ? "set" : "empty", symbol->errtxt);
  103. if (ret < ZINT_ERROR) {
  104. assert_equal(symbol->rows, data[i].expected_rows, "i:%d symbol->rows %d != %d\n", i, symbol->rows, data[i].expected_rows);
  105. assert_equal(symbol->width, data[i].expected_width, "i:%d symbol->width %d != %d\n", i, symbol->width, data[i].expected_width);
  106. } else {
  107. assert_zero(strcmp(symbol->errtxt, expected_errtxt), "i:%d strcmp(%s, %s) != 0\n", i, symbol->errtxt, expected_errtxt);
  108. }
  109. if (ret < ZINT_ERROR) {
  110. if (do_bwipp && testUtilCanBwipp(i, symbol, data[i].option_1, data[i].option_2, -1, debug)) {
  111. if (!data[i].bwipp_cmp) {
  112. if (debug & ZINT_DEBUG_TEST_PRINT) printf("i:%d %s not BWIPP compatible (%s)\n", i, testUtilBarcodeName(symbol->symbology), data[i].comment);
  113. } else {
  114. char modules_dump[33 * 33 + 1];
  115. assert_notequal(testUtilModulesDump(symbol, modules_dump, sizeof(modules_dump)), -1, "i:%d testUtilModulesDump == -1\n", i);
  116. ret = testUtilBwipp(i, symbol, data[i].option_1, data[i].option_2, -1, data_buf, length, symbol->primary, cmp_buf, sizeof(cmp_buf), NULL);
  117. assert_zero(ret, "i:%d %s testUtilBwipp ret %d != 0\n", i, testUtilBarcodeName(symbol->symbology), ret);
  118. ret = testUtilBwippCmp(symbol, cmp_msg, cmp_buf, modules_dump);
  119. assert_zero(ret, "i:%d %s testUtilBwippCmp %d != 0 %s\n actual: %s\nexpected: %s\n",
  120. i, testUtilBarcodeName(symbol->symbology), ret, cmp_msg, cmp_buf, modules_dump);
  121. }
  122. }
  123. if (do_zxingcpp && testUtilCanZXingCPP(i, symbol, data_buf, length, debug)) {
  124. int cmp_len, ret_len;
  125. char modules_dump[33 * 33 + 1];
  126. assert_notequal(testUtilModulesDump(symbol, modules_dump, sizeof(modules_dump)), -1, "i:%d testUtilModulesDump == -1\n", i);
  127. ret = testUtilZXingCPP(i, symbol, data_buf, length, modules_dump, cmp_buf, sizeof(cmp_buf), &cmp_len);
  128. assert_zero(ret, "i:%d %s testUtilZXingCPP ret %d != 0\n", i, testUtilBarcodeName(symbol->symbology), ret);
  129. ret = testUtilZXingCPPCmp(symbol, cmp_msg, cmp_buf, cmp_len, data_buf, length, symbol->primary, escaped, &ret_len);
  130. assert_zero(ret, "i:%d %s testUtilZXingCPPCmp %d != 0 %s\n actual: %.*s\nexpected: %.*s\n",
  131. i, testUtilBarcodeName(symbol->symbology), ret, cmp_msg, cmp_len, cmp_buf, ret_len, escaped);
  132. }
  133. }
  134. ZBarcode_Delete(symbol);
  135. }
  136. testFinish();
  137. }
  138. static void test_input(const testCtx *const p_ctx) {
  139. int debug = p_ctx->debug;
  140. struct item {
  141. int input_mode;
  142. int eci;
  143. int option_1;
  144. int option_2;
  145. struct zint_structapp structapp;
  146. char *data;
  147. int length;
  148. char *primary;
  149. int ret;
  150. int expected_width;
  151. char *expected;
  152. int bwipp_cmp;
  153. int zxingcpp_cmp;
  154. char *comment;
  155. };
  156. /* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */
  157. static const struct item data[] = {
  158. /* 0*/ { UNICODE_MODE, -1, -1, -1, { 0, 0, "" }, "A", -1, "", 0, 30, "(144) 04 01 21 21 21 21 21 21 21 21 08 0E 19 2B 20 0C 24 06 32 1C 21 21 21 21 21 21 21 21", 1, 1, "" },
  159. /* 1*/ { UNICODE_MODE, -1, 2, -1, { 0, 0, "" }, "A", -1, "", ZINT_ERROR_INVALID_DATA, 0, "Error 548: Primary Message empty", 1, 1, "" },
  160. /* 2*/ { UNICODE_MODE, -1, 2, -1, { 0, 0, "" }, "A", -1, "A123456", ZINT_ERROR_INVALID_DATA, 0, "Error 555: Non-numeric postcode in Primary Message", 1, 1, "" },
  161. /* 3*/ { UNICODE_MODE, -1, 2, -1, { 0, 0, "" }, "A", -1, "1123456", 0, 30, "(144) 12 00 00 00 00 10 30 1E 20 1C 1A 3D 1C 0D 1B 15 3C 17 3C 08 01 21 21 21 21 21 21 21", 1, 1, "1-digit postcode" },
  162. /* 4*/ { UNICODE_MODE, -1, 2, -1, { 0, 0, "" }, "A", -1, "1 123456", 0, 30, "(144) 12 00 00 00 00 10 30 1E 20 1C 1A 3D 1C 0D 1B 15 3C 17 3C 08 01 21 21 21 21 21 21 21", 1, 0, "1-digit postcode; ZXing-C++ test can't handle space" },
  163. /* 5*/ { UNICODE_MODE, -1, 2, -1, { 0, 0, "" }, "A", -1, "123456789123456", 0, 30, "(144) 12 05 0D 2F 35 11 32 1E 20 1C 0D 1D 3B 12 22 3F 30 14 23 1A 01 21 21 21 21 21 21 21", 1, 1, "9-digit postcode" },
  164. /* 6*/ { UNICODE_MODE, -1, 2, -1, { 0, 0, "" }, "A", -1, "1234567890123456", ZINT_ERROR_INVALID_DATA, 0, "Error 551: Primary Message length 16 wrong (7 to 15 only)", 1, 1, "10-digit postcode" },
  165. /* 7*/ { UNICODE_MODE, -1, -1, -1, { 0, 0, "" }, "A", -1, "1123456", 0, 30, "(144) 12 00 00 00 00 10 30 1E 20 1C 1A 3D 1C 0D 1B 15 3C 17 3C 08 01 21 21 21 21 21 21 21", 1, 1, "1-digit postcode" },
  166. /* 8*/ { UNICODE_MODE, -1, -1, -1, { 0, 0, "" }, "A", -1, "123456789123456", 0, 30, "(144) 12 05 0D 2F 35 11 32 1E 20 1C 0D 1D 3B 12 22 3F 30 14 23 1A 01 21 21 21 21 21 21 21", 1, 1, "9-digit postcode" },
  167. /* 9*/ { UNICODE_MODE, -1, -1, -1, { 0, 0, "" }, "A", -1, "1234567890123456", ZINT_ERROR_INVALID_DATA, 0, "Error 551: Primary Message length 16 wrong (7 to 15 only)", 1, 1, "10-digit postcode" },
  168. /* 10*/ { UNICODE_MODE, -1, -1, -1, { 0, 0, "" }, "A", -1, "123456", ZINT_ERROR_INVALID_DATA, 0, "Error 551: Primary Message length 6 wrong (7 to 15 only)", 1, 1, "0-digit postcode" },
  169. /* 11*/ { UNICODE_MODE, -1, -1, -1, { 0, 0, "" }, "A", -1, "12345678123456", 0, 30, "(144) 22 13 21 31 0B 00 32 1E 20 1C 04 14 07 30 10 07 08 28 1D 09 01 21 21 21 21 21 21 21", 1, 1, "8-digit postcode" },
  170. /* 12*/ { UNICODE_MODE, -1, 2, -1, { 0, 0, "" }, "A", -1, "12345678123456", 0, 30, "(144) 22 13 21 31 0B 00 32 1E 20 1C 04 14 07 30 10 07 08 28 1D 09 01 21 21 21 21 21 21 21", 1, 1, "8-digit postcode" },
  171. /* 13*/ { UNICODE_MODE, -1, 3, -1, { 0, 0, "" }, "A", -1, "", ZINT_ERROR_INVALID_DATA, 0, "Error 548: Primary Message empty", 1, 1, "" },
  172. /* 14*/ { UNICODE_MODE, -1, 3, -1, { 0, 0, "" }, "A", -1, "A123456", 0, 30, "(144) 03 08 08 08 08 18 30 1E 20 1C 22 35 1C 0F 02 1A 26 04 10 31 01 21 21 21 21 21 21 21", 1, 1, "1-alphanumeric postcode" },
  173. /* 15*/ { UNICODE_MODE, -1, 3, -1, { 0, 0, "" }, "A", -1, "1123456", 0, 30, "(144) 03 08 08 08 08 18 3C 1E 20 1C 13 37 07 2C 26 2D 18 29 3F 2C 01 21 21 21 21 21 21 21", 1, 0, "1-digit postcode; ZXing-C++ test can't handle padding" },
  174. /* 16*/ { UNICODE_MODE, -1, -1, -1, { 0, 0, "" }, "A", -1, "A123456", 0, 30, "(144) 03 08 08 08 08 18 30 1E 20 1C 22 35 1C 0F 02 1A 26 04 10 31 01 21 21 21 21 21 21 21", 1, 1, "1-alphanumeric postcode" },
  175. /* 17*/ { UNICODE_MODE, -1, -1, -1, { 0, 0, "" }, "A", -1, "ABCDEF123456", 0, 30, "(144) 23 11 01 31 20 10 30 1E 20 1C 3C 1D 22 03 19 15 0F 20 0F 2A 01 21 21 21 21 21 21 21", 1, 1, "6-alphanumeric postcode" },
  176. /* 18*/ { UNICODE_MODE, -1, -1, -1, { 0, 0, "" }, "A", -1, "ABCDEFG123456", 0, 30, "(144) 23 11 01 31 20 10 30 1E 20 1C 3C 1D 22 03 19 15 0F 20 0F 2A 01 21 21 21 21 21 21 21", 1, 0, "7-alphanumeric postcode truncated; ZXing-C++ test can't handle truncation" },
  177. /* 19*/ { UNICODE_MODE, -1, -1, -1, { 0, 0, "" }, "A", -1, "ABCDE123456", 0, 30, "(144) 03 18 01 31 20 10 30 1E 20 1C 0F 38 38 1A 39 10 2F 37 22 12 01 21 21 21 21 21 21 21", 1, 1, "5-alphanumeric postcode" },
  178. /* 20*/ { UNICODE_MODE, -1, -1, -1, { 0, 0, "" }, "A", -1, "AAAAAA 840001", 0, 30, "(144) 13 10 10 10 10 10 00 12 07 00 17 36 2E 38 04 29 16 0D 27 16 01 21 21 21 21 21 21 21", 1, 0, "6-alphanumeric postcode with padding; ZXing-C++ test can't handle padding" },
  179. /* 21*/ { UNICODE_MODE, -1, -1, -1, { 0, 0, "" }, "A", -1, "AAAAA A840001", 0, 30, "(144) 03 18 10 10 10 10 00 12 07 00 19 07 29 31 26 01 23 2C 2E 07 01 21 21 21 21 21 21 21", 1, 0, "7-alphanumeric with embedded padding truncated; ZXing-C++ test can't handle truncation" },
  180. /* 22*/ { UNICODE_MODE, -1, -1, -1, { 0, 0, "" }, "A", -1, "AA\015AAA840001", ZINT_ERROR_INVALID_DATA, 0, "Error 556: Invalid character in postcode in Primary Message", 1, 1, "Alphanumeric postcode with CR" },
  181. /* 23*/ { UNICODE_MODE, -1, -1, -1, { 0, 0, "" }, "A", -1, "A#%-/A840001", 0, 30, "(144) 13 30 1B 1B 39 18 00 12 07 00 3F 1E 25 07 2A 1E 14 3C 28 2D 01 21 21 21 21 21 21 21", 1, 1, "Alphanumeric postcode with non-control Code A chars" },
  182. /* 24*/ { UNICODE_MODE, -1, -1, -1, { 0, 0, "" }, "A", -1, "1A23456", ZINT_ERROR_INVALID_DATA, 0, "Error 552: Non-numeric country code or service class in Primary Message", 1, 1, "Non-numeric country code" },
  183. /* 25*/ { UNICODE_MODE, -1, -1, -1, { 0, 0, "" }, "A", -1, "12345678912345A", ZINT_ERROR_INVALID_DATA, 0, "Error 552: Non-numeric country code or service class in Primary Message", 1, 1, "Non-numeric service class" },
  184. /* 26*/ { UNICODE_MODE, -1, 0, -1, { 0, 0, "" }, "A", -1, "123456789123456", 0, 30, "(144) 12 05 0D 2F 35 11 32 1E 20 1C 0D 1D 3B 12 22 3F 30 14 23 1A 01 21 21 21 21 21 21 21", 1, 1, "Auto-determine mode 2" },
  185. /* 27*/ { UNICODE_MODE, -1, 0, -1, { 0, 0, "" }, "A", -1, "", ZINT_ERROR_INVALID_DATA, 0, "Error 554: Primary Message empty", 1, 1, "Auto-determine mode 2/3 requires primary message" },
  186. /* 28*/ { UNICODE_MODE, -1, 0, -1, { 0, 0, "" }, "A", -1, "A23456123456", 0, 30, "(144) 23 1D 0D 3D 2C 1C 30 1E 20 1C 24 35 30 31 2A 0D 17 14 16 3D 01 21 21 21 21 21 21 21", 1, 1, "Auto-determine mode 3" },
  187. /* 29*/ { UNICODE_MODE, -1, -1, 100, { 0, 0, "" }, "A", -1, "123456123456", 0, 30, "(144) 02 10 22 07 00 20 31 1E 20 1C 0E 29 13 1B 0D 26 36 25 3B 22 3B 2A 29 3B 28 1E 30 31", 1, 1, "SCM prefix version" },
  188. /* 30*/ { UNICODE_MODE, -1, -1, 101, { 0, 0, "" }, "A", -1, "123456123456", ZINT_ERROR_INVALID_OPTION, 0, "Error 557: SCM prefix version '101' out of range (1 to 100)", 1, 1, "SCM prefix version" },
  189. /* 31*/ { UNICODE_MODE, 25, -1, 96 + 1, { 0, 0, "" }, "A", -1, "123456123456", ZINT_ERROR_INVALID_OPTION, 0, "Error 547: SCM prefix can not be used with ECI 25 (ECI must be ASCII compatible)", 1, 1, "SCM prefix version UTF-16BE" },
  190. /* 32*/ { UNICODE_MODE, 33, -1, 96 + 1, { 0, 0, "" }, "A", -1, "123456123456", ZINT_ERROR_INVALID_OPTION, 0, "Error 547: SCM prefix can not be used with ECI 33 (ECI must be ASCII compatible)", 1, 1, "SCM prefix version UTF-16LE" },
  191. /* 33*/ { UNICODE_MODE, 34, -1, 96 + 1, { 0, 0, "" }, "A", -1, "123456123456", ZINT_ERROR_INVALID_OPTION, 0, "Error 547: SCM prefix can not be used with ECI 34 (ECI must be ASCII compatible)", 1, 1, "SCM prefix version UTF-32BE" },
  192. /* 34*/ { UNICODE_MODE, 35, -1, 96 + 1, { 0, 0, "" }, "A", -1, "123456123456", ZINT_ERROR_INVALID_OPTION, 0, "Error 547: SCM prefix can not be used with ECI 35 (ECI must be ASCII compatible)", 1, 1, "SCM prefix version UTF-32LE" },
  193. /* 35*/ { UNICODE_MODE, 3, 2, 96 + 1, { 0, 0, "" }, "A", -1, "999999999840333", 0, 30, "(144) 32 3F 09 2B 39 1E 02 12 37 14 2F 1E 03 29 3E 1B 2D 2A 06 20 3B 2A 29 3B 28 1E 30 31", 1, 1, "SCM prefix version ISO/IEC 8859-1" },
  194. /* 36*/ { UNICODE_MODE, 170, 2, 96 + 1, { 0, 0, "" }, "A", -1, "1234567123456", 0, 30, "(144) 32 21 16 0B 01 30 31 1E 20 1C 13 22 04 28 0E 21 13 1E 3A 14 3B 2A 29 3B 28 1E 30 31", 1, 1, "SCM prefix version ASCII Invariant" },
  195. /* 37*/ { UNICODE_MODE, 20, 2, 96 + 1, { 0, 0, "" }, "テ", -1, "12345678123456", 0, 30, "(144) 22 13 21 31 0B 00 32 1E 20 1C 04 14 07 30 10 07 08 28 1D 09 3B 2A 29 3B 28 1E 30 31", 1, 1, "SCM prefix version Shift JIS" },
  196. /* 38*/ { UNICODE_MODE | ESCAPE_MODE, 3, 2, -1, { 0, 0, "" }, "[)>\\R01\\G96A", -1, "999999999840333", 0, 30, "(144) 32 3F 09 2B 39 1E 02 12 37 14 2F 1E 03 29 3E 1B 2D 2A 06 20 3B 2A 29 3B 28 1E 30 31", 1, 1, "Manual SCM prefix ISO/IEC 8859-1" },
  197. /* 39*/ { UNICODE_MODE, 3, -1, -1, { 0, 0, "" }, "A", -1, "", 0, 30, "(144) 04 1B 03 01 21 21 21 21 21 21 2F 14 23 21 05 24 27 00 24 0C 21 21 21 21 21 21 21 21", 1, 1, "" },
  198. /* 40*/ { UNICODE_MODE, 31, -1, -1, { 0, 0, "" }, "A", -1, "", 0, 30, "(144) 04 1B 1F 01 21 21 21 21 21 21 00 2F 0E 09 39 3B 24 1A 21 05 21 21 21 21 21 21 21 21", 1, 1, "ECI 0x1F" },
  199. /* 41*/ { UNICODE_MODE, 32, -1, -1, { 0, 0, "" }, "A", -1, "", 0, 30, "(144) 04 1B 20 20 01 21 21 21 21 21 3D 15 0F 30 0D 22 24 35 22 06 21 21 21 21 21 21 21 21", 1, 1, "ECI 0x20" },
  200. /* 42*/ { UNICODE_MODE, 1023, -1, -1, { 0, 0, "" }, "A", -1, "", 0, 30, "(144) 04 1B 2F 3F 01 21 21 21 21 21 2E 27 23 1D 35 19 21 04 3A 26 21 21 21 21 21 21 21 21", 1, 1, "ECI 0x3FF" },
  201. /* 43*/ { UNICODE_MODE, 1024, -1, -1, { 0, 0, "" }, "A", -1, "", 0, 30, "(144) 04 1B 30 10 00 01 21 21 21 21 11 2F 15 10 1D 29 06 35 14 2B 21 21 21 21 21 21 21 21", 1, 1, "ECI 0x400" },
  202. /* 44*/ { UNICODE_MODE, 32767, -1, -1, { 0, 0, "" }, "A", -1, "", 0, 30, "(144) 04 1B 37 3F 3F 01 21 21 21 21 3E 15 12 01 07 30 39 27 04 2B 21 21 21 21 21 21 21 21", 1, 1, "ECI 0x7FFF" },
  203. /* 45*/ { UNICODE_MODE, 32768, -1, -1, { 0, 0, "" }, "A", -1, "", 0, 30, "(144) 04 1B 38 08 00 00 01 21 21 21 10 30 3A 04 26 23 0E 21 3D 0F 21 21 21 21 21 21 21 21", 1, 1, "ECI 0x8000" },
  204. /* 46*/ { UNICODE_MODE, 65535, -1, -1, { 0, 0, "" }, "A", -1, "", 0, 30, "(144) 04 1B 38 0F 3F 3F 01 21 21 21 1C 0E 1D 39 3B 0D 38 25 00 30 21 21 21 21 21 21 21 21", 1, 1, "ECI 0xFFFF" },
  205. /* 47*/ { UNICODE_MODE, 65536, -1, -1, { 0, 0, "" }, "A", -1, "", 0, 30, "(144) 04 1B 38 10 00 00 01 21 21 21 2B 1F 24 06 38 2E 17 1B 10 2F 21 21 21 21 21 21 21 21", 1, 1, "ECI 0x10000" },
  206. /* 48*/ { UNICODE_MODE, 131071, -1, -1, { 0, 0, "" }, "A", -1, "", 0, 30, "(144) 04 1B 38 1F 3F 3F 01 21 21 21 0F 05 09 04 2F 3A 17 09 36 31 21 21 21 21 21 21 21 21", 1, 1, "ECI 0x1FFFF" },
  207. /* 49*/ { UNICODE_MODE, 999999, -1, -1, { 0, 0, "" }, "A", -1, "", 0, 30, "(144) 04 1B 3B 34 08 3F 01 21 21 21 26 3B 2B 23 08 17 32 05 26 35 21 21 21 21 21 21 21 21", 1, 1, "Max ECI" },
  208. /* 50*/ { UNICODE_MODE, -1, 1, -1, { 0, 0, "" }, "A", -1, "", ZINT_ERROR_INVALID_OPTION, 0, "Error 550: Mode '1' out of range (2 to 6)", 1, 1, "" },
  209. /* 51*/ { UNICODE_MODE, -1, 7, -1, { 0, 0, "" }, "A", -1, "", ZINT_ERROR_INVALID_OPTION, 0, "Error 550: Mode '7' out of range (2 to 6)", 1, 1, "" },
  210. /* 52*/ { UNICODE_MODE, -1, -1, -1, { 0, 0, "" }, "\015", -1, "", 0, 30, "(144) 04 00 21 21 21 21 21 21 21 21 37 32 10 01 24 1B 10 11 38 0C 21 21 21 21 21 21 21 21", 1, 1, "" },
  211. /* 53*/ { UNICODE_MODE, -1, -1, -1, { 0, 0, "" }, "\015\034\035\036 ", -1, "", 0, 30, "(144) 04 00 1C 1D 1E 20 21 21 21 21 3E 18 0B 14 22 27 2D 3A 18 22 21 21 21 21 21 21 21 21", 1, 1, "Code Set A" },
  212. /* 54*/ { UNICODE_MODE, -1, -1, -1, { 0, 0, "" }, "abc\034\035\036 ,./:", -1, "", 0, 30, "(144) 04 3F 01 02 03 1C 1D 1E 2F 30 21 1F 2B 2A 35 0A 00 10 36 1D 31 32 33 21 21 21 21 21", 1, 1, "Code Set B" },
  213. /* 55*/ { UNICODE_MODE, -1, -1, -1, { 0, 0, "" }, "\001\002\003\015\034\035\036 ", -1, "", 0, 30, "(144) 04 3E 3E 01 02 03 0D 20 21 22 3D 0F 31 3A 0C 0C 34 26 27 31 3B 1C 1C 1C 1C 1C 1C 1C", 1, 1, "Code Set E" },
  214. /* 56*/ { UNICODE_MODE, -1, -1, -1, { 0, 0, "" }, "ÀÀÀ\034\035\036 ", -1, "", 0, 30, "(144) 04 3C 3C 00 00 00 1C 1D 1E 3B 3C 05 39 07 18 15 25 36 28 11 3A 21 21 21 21 21 21 21", 1, 1, "Code Set C" },
  215. /* 57*/ { UNICODE_MODE, -1, -1, -1, { 0, 0, "" }, "ààà\034\035\036 ", -1, "", 0, 30, "(144) 04 3D 3D 00 00 00 1C 1D 1E 3B 06 26 23 19 32 1E 0C 1A 05 11 3A 21 21 21 21 21 21 21", 1, 1, "Code Set D" },
  216. /* 58*/ { UNICODE_MODE, -1, -1, -1, { 0, 0, "" }, "\001\034\001\035\001\036\001a:b", -1, "", 0, 30, "(144) 04 3E 3E 01 20 01 21 01 22 01 27 0B 35 01 08 0D 16 02 17 1A 3F 01 33 02 21 21 21 21", 1, 1, "" },
  217. /* 59*/ { UNICODE_MODE, -1, -1, -1, { 1, 2, "" }, "A", -1, "", 0, 30, "(144) 04 21 01 01 21 21 21 21 21 21 09 0B 26 03 37 0E 25 27 07 1E 21 21 21 21 21 21 21 21", 1, 1, "" },
  218. /* 60*/ { UNICODE_MODE, -1, -1, -1, { 0, 2, "" }, "A", -1, "", ZINT_ERROR_INVALID_OPTION, 0, "Error 559: Structured Append index '0' out of range (1 to count 2)", 1, 1, "" },
  219. /* 61*/ { UNICODE_MODE, -1, -1, -1, { 1, 1, "" }, "A", -1, "", ZINT_ERROR_INVALID_OPTION, 0, "Error 558: Structured Append count '1' out of range (2 to 8)", 1, 1, "" },
  220. /* 62*/ { UNICODE_MODE, -1, -1, -1, { 1, 9, "" }, "A", -1, "", ZINT_ERROR_INVALID_OPTION, 0, "Error 558: Structured Append count '9' out of range (2 to 8)", 1, 1, "" },
  221. /* 63*/ { UNICODE_MODE, -1, -1, -1, { 3, 2, "" }, "A", -1, "", ZINT_ERROR_INVALID_OPTION, 0, "Error 559: Structured Append index '3' out of range (1 to count 2)", 1, 1, "" },
  222. /* 64*/ { UNICODE_MODE, -1, -1, -1, { 1, 2, "A" }, "A", -1, "", ZINT_ERROR_INVALID_OPTION, 0, "Error 549: Structured Append ID not available for MaxiCode", 1, 1, "" },
  223. /* 65*/ { UNICODE_MODE, -1, -1, -1, { 0, 0, "" }, "b..A", -1, "", 0, 30, "(144) 04 3B 02 2E 2E 01 21 21 21 21 11 1C 30 14 2D 3E 16 0E 0C 31 21 21 21 21 21 21 21 21", 1, 1, "" },
  224. /* 66*/ { UNICODE_MODE, -1, -1, -1, { 0, 0, "" }, "A123456789b123456789bbbA", -1, "", 0, 30, "(144) 04 01 1F 07 16 3C 34 15 3F 02 10 1B 28 22 20 32 37 0C 0B 2A 1F 07 16 3C 34 15 02 02", 1, 1, "" },
  225. /* 67*/ { ESCAPE_MODE, -1, -1, -1, { 0, 0, "" }, "\\d192\\d224\\d224\\d224\\d192\\d224\\d224\\d224\\d192\\d224\\d224\\d224\\d192\\d224\\d224\\d224\\d192\\d224\\d224\\d224\\d192", -1, "", 0, 30, "(144) 04 3C 00 3D 3D 00 00 00 3C 00 34 39 0E 35 1D 25 00 1B 28 03 00 00 00 3C 00 00 00 00", 1, 1, "BWIPP PR #279" },
  226. /* 68*/ { ESCAPE_MODE, -1, 2, -1, { 0, 0, "" }, "1Z34567890\\GUPSN\\G102562\\G034\\G\\G1/1\\G\\GY\\G2201 Second St\\GFt Myers\\GFL\\R\\E", -1, "339010000840001", 0, 30, "(144) 02 34 21 13 03 15 02 12 07 00 0C 03 00 38 24 04 0B 1F 2F 21 31 1A 33 34 35 36 37 38", 1, 1, "" },
  227. /* 69*/ { DATA_MODE | ESCAPE_MODE, -1, -1, -1, { 0, 0, "" }, "ABabcdeAabcdABCabcdABabc\\d192\\d192 \\d192\\d224\\d224\\d028\\d224\\d001\\d001\\d001\\d029\\d00112345678a123456789aABCDa\\d192\\d224\\d001\\d192\\d001\\d224\\d030\\d004", -1, "", 0, 30, "(144) 04 01 02 3F 01 02 03 04 05 3B 25 28 3F 32 0D 10 0D 0F 35 11 01 01 02 03 04 39 01 02", 1, 1, "Exercises all latches & no. of shifts" },
  228. /* 70*/ { UNICODE_MODE, 1023, 3, 96 + 1, { 2, 3, "" }, "A", -1, "P144275001", 0, 30, "(144) 03 08 08 0D 1D 0C 34 04 05 00 13 29 0C 17 0F 15 2E 38 00 0B 21 0A 3B 2A 29 3B 28 1E", 1, 1, "ECI, Structured Append, SCM" },
  229. };
  230. const int data_size = ARRAY_SIZE(data);
  231. int i, length, ret;
  232. struct zint_symbol *symbol = NULL;
  233. char escaped[1024];
  234. char cmp_buf[32768];
  235. char cmp_msg[1024];
  236. int do_bwipp = (debug & ZINT_DEBUG_TEST_BWIPP) && testUtilHaveGhostscript(); /* Only do BWIPP test if asked, too slow otherwise */
  237. int do_zxingcpp = (debug & ZINT_DEBUG_TEST_ZXINGCPP) && testUtilHaveZXingCPPDecoder(); /* Only do ZXing-C++ test if asked, too slow otherwise */
  238. testStartSymbol("test_input", &symbol);
  239. for (i = 0; i < data_size; i++) {
  240. if (testContinue(p_ctx, i)) continue;
  241. symbol = ZBarcode_Create();
  242. assert_nonnull(symbol, "Symbol not created\n");
  243. symbol->debug = ZINT_DEBUG_TEST; /* Needed to get codeword dump in errtxt */
  244. length = testUtilSetSymbol(symbol, BARCODE_MAXICODE, data[i].input_mode, data[i].eci, data[i].option_1, data[i].option_2, -1, -1 /*output_options*/, data[i].data, data[i].length, debug);
  245. if (data[i].structapp.count) {
  246. symbol->structapp = data[i].structapp;
  247. }
  248. strcpy(symbol->primary, data[i].primary);
  249. ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length);
  250. assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
  251. if (p_ctx->generate) {
  252. printf(" /*%3d*/ { %s, %d, %d, %d, { %d, %d, \"%s\" }, \"%s\", %d, \"%s\", %s, %d, \"%s\", %d, %d, \"%s\" },\n",
  253. i, testUtilInputModeName(data[i].input_mode), data[i].eci, data[i].option_1, data[i].option_2,
  254. data[i].structapp.index, data[i].structapp.count, data[i].structapp.id,
  255. testUtilEscape(data[i].data, length, escaped, sizeof(escaped)), data[i].length, data[i].primary,
  256. testUtilErrorName(data[i].ret), symbol->width, symbol->errtxt, data[i].bwipp_cmp, data[i].zxingcpp_cmp, data[i].comment);
  257. } else {
  258. if (ret < ZINT_ERROR) {
  259. assert_equal(symbol->width, data[i].expected_width, "i:%d symbol->width %d != %d (%s)\n", i, symbol->width, data[i].expected_width, data[i].data);
  260. }
  261. assert_zero(strcmp(symbol->errtxt, data[i].expected), "i:%d strcmp(%s, %s) != 0\n", i, symbol->errtxt, data[i].expected);
  262. if (ret < ZINT_ERROR) {
  263. if (do_bwipp && testUtilCanBwipp(i, symbol, data[i].option_1, data[i].option_2, -1, debug)) {
  264. if (!data[i].bwipp_cmp) {
  265. if (debug & ZINT_DEBUG_TEST_PRINT) printf("i:%d %s not BWIPP compatible (%s)\n", i, testUtilBarcodeName(symbol->symbology), data[i].comment);
  266. } else {
  267. char modules_dump[33 * 33 + 1];
  268. assert_notequal(testUtilModulesDump(symbol, modules_dump, sizeof(modules_dump)), -1, "i:%d testUtilModulesDump == -1\n", i);
  269. ret = testUtilBwipp(i, symbol, data[i].option_1, data[i].option_2, -1, data[i].data, length, symbol->primary, cmp_buf, sizeof(cmp_buf), NULL);
  270. assert_zero(ret, "i:%d %s testUtilBwipp ret %d != 0\n", i, testUtilBarcodeName(symbol->symbology), ret);
  271. ret = testUtilBwippCmp(symbol, cmp_msg, cmp_buf, modules_dump);
  272. assert_zero(ret, "i:%d %s testUtilBwippCmp %d != 0 %s\n actual: %s\nexpected: %s\n",
  273. i, testUtilBarcodeName(symbol->symbology), ret, cmp_msg, cmp_buf, modules_dump);
  274. }
  275. }
  276. if (do_zxingcpp && testUtilCanZXingCPP(i, symbol, data[i].data, length, debug)) {
  277. if (!data[i].zxingcpp_cmp) {
  278. if (debug & ZINT_DEBUG_TEST_PRINT) printf("i:%d %s not ZXing-C++ compatible (%s)\n", i, testUtilBarcodeName(symbol->symbology), data[i].comment);
  279. } else {
  280. int cmp_len, ret_len;
  281. char modules_dump[33 * 33 + 1];
  282. assert_notequal(testUtilModulesDump(symbol, modules_dump, sizeof(modules_dump)), -1, "i:%d testUtilModulesDump == -1\n", i);
  283. ret = testUtilZXingCPP(i, symbol, data[i].data, length, modules_dump, cmp_buf, sizeof(cmp_buf), &cmp_len);
  284. assert_zero(ret, "i:%d %s testUtilZXingCPP ret %d != 0\n", i, testUtilBarcodeName(symbol->symbology), ret);
  285. ret = testUtilZXingCPPCmp(symbol, cmp_msg, cmp_buf, cmp_len, data[i].data, length, symbol->primary, escaped, &ret_len);
  286. assert_zero(ret, "i:%d %s testUtilZXingCPPCmp %d != 0 %s\n actual: %.*s\nexpected: %.*s\n",
  287. i, testUtilBarcodeName(symbol->symbology), ret, cmp_msg, cmp_len, cmp_buf, ret_len, escaped);
  288. }
  289. }
  290. }
  291. }
  292. ZBarcode_Delete(symbol);
  293. }
  294. testFinish();
  295. }
  296. static void test_encode(const testCtx *const p_ctx) {
  297. int debug = p_ctx->debug;
  298. struct item {
  299. int input_mode;
  300. int option_1;
  301. int option_2;
  302. struct zint_structapp structapp;
  303. char *data;
  304. int length;
  305. char *primary;
  306. int ret;
  307. int expected_rows;
  308. int expected_width;
  309. int bwipp_cmp;
  310. char *comment;
  311. char *expected;
  312. };
  313. static const struct item data[] = {
  314. /* 0*/ { -1, -1, -1, { 0, 0, "" }, "THIS IS A 93 CHARACTER CODE SET A MESSAGE THAT FILLS A MODE 4, UNAPPENDED, MAXICODE SYMBOL...", -1, "", 0, 33, 30, 1, "ISO/IEC 16023:2000 Figure 2 (and L1), same",
  315. "011111010000001000001000100111"
  316. "000100000001000000001010000000"
  317. "001011001100100110110010010010"
  318. "100000010001100010010000000000"
  319. "001011000000101000001010110011"
  320. "111010001000001011001000111100"
  321. "100000000110000010010000000000"
  322. "000010100010010010001001111100"
  323. "111011100000001000000110000000"
  324. "000000011011000000010100011000"
  325. "101111000001010110001100000011"
  326. "001110001010000000111010001110"
  327. "000111100000000000100001011000"
  328. "100010000000000000000111001000"
  329. "100000001000000000011000001000"
  330. "000010111000000000000010000010"
  331. "111000001000000000001000001101"
  332. "011000000000000000001000100100"
  333. "000000101100000000001001010001"
  334. "101010001000000000100111001100"
  335. "001000011000000000011100001010"
  336. "000000000000000000110000100000"
  337. "101011001010100001000101010001"
  338. "100011110010101001101010001010"
  339. "011010000000000101011010011111"
  340. "000001110011111111111100010100"
  341. "001110100111000101011000011100"
  342. "110111011100100001101001010110"
  343. "000001011011101010010111001100"
  344. "111000110111100010001111011110"
  345. "101111010111111000010110111001"
  346. "001001101111101101101010011100"
  347. "001011000000111101100100001000"
  348. },
  349. /* 1*/ { -1, 4, -1, { 0, 0, "" }, "MaxiCode (19 chars)", -1, "", 0, 33, 30, 1, "ISO/IEC 16023:2000 Figure H1 **NOT SAME** different encodation (figure uses '3 Shift A' among other differences)",
  350. "000111011111010000001010110111"
  351. "101101010001110001000000110110"
  352. "101110001010111100100111111011"
  353. "010101010101010101010101010100"
  354. "000000000000000000000000000011"
  355. "101010101010101010101010101010"
  356. "010101010101010101010101010111"
  357. "000000000000000000000000000010"
  358. "101010101010101010101010101011"
  359. "010101011111111100000001010100"
  360. "000000000011110110001000000001"
  361. "101010101110000000111010101010"
  362. "010101100010000000001101010110"
  363. "000000101000000000001000000010"
  364. "101010000000000000011010101001"
  365. "010101010000000000001101010110"
  366. "000000001000000000001000000010"
  367. "101010110000000000001010101010"
  368. "010101101100000000010101010111"
  369. "000000100000000000000000000000"
  370. "101010010110000000000110101011"
  371. "010101010110000000001001010110"
  372. "000000000110001011000000000011"
  373. "101010100110111001010010101010"
  374. "010101010101010101011100100010"
  375. "000000000000000000000000101100"
  376. "101010101010101010101010101101"
  377. "011000111100100001011011100100"
  378. "001010011100001010001111100100"
  379. "111010000011101011110001010100"
  380. "000111001100100000010011000110"
  381. "100000101101100000001000111110"
  382. "011101000100000001001111101001"
  383. },
  384. /* 2*/ { ESCAPE_MODE, 2, 96 + 1, { 0, 0, "" }, "1Z00004951\\GUPSN\\G06X610\\G159\\G1234567\\G1/1\\G\\GY\\G634 ALPHA DR\\GPITTSBURGH\\GPA\\R\\E", -1, "152382802840001", 0, 33, 30, 1, "ISO/IEC 16023:2000 Figure B2 **NOT SAME** uses different encodation (figure precedes PAD chars with Latch B)",
  385. "110101110110111110111111101111"
  386. "010101010111000011011000010010"
  387. "110110110001001010100110010001"
  388. "111000101010101111111111111110"
  389. "001111000010110010011000000011"
  390. "001001110010101010100000000000"
  391. "111011111110111111101111111110"
  392. "100110000011001001110000001010"
  393. "010001100010101010101001110001"
  394. "110111100011010000011011111100"
  395. "001100110011110000001110101001"
  396. "101110101000000001011111011010"
  397. "101010000000000000010110111111"
  398. "111101100000000000011011100010"
  399. "101010010000000000000110011101"
  400. "001000010000000000011100011110"
  401. "010011001000000000001000001010"
  402. "000000101000000000001010000010"
  403. "000100111100000000001110101010"
  404. "000010101100000000001000110000"
  405. "100000111010000000011101100000"
  406. "101000100000000000110110100000"
  407. "001000001110100101100110100101"
  408. "011001110010101001100000001000"
  409. "000010100010110001010101111010"
  410. "100111000011111000001101101010"
  411. "110010001001010010100000001101"
  412. "000001000110110100111010111100"
  413. "010111010010100100001111011010"
  414. "110111001110101010101101110100"
  415. "011011110001010100010111010011"
  416. "000111101001100001111000010110"
  417. "000100101000110000000111110011"
  418. },
  419. /* 3*/ { ESCAPE_MODE, 2, 96 + 1, { 0, 0, "" }, "1Z00004951\\GUPSN\\G06X610\\G159\\G1234567\\G1/1\\G\\GY\\G634 ALPHA DR\\GPITTSBURGH\\GPA\\R\\E", -1, "15238840001", 0, 33, 30, 1, "OkapiBarcode zero-pad postcode lacking +4 (US 840 only), ISO/IEC 16023:2000 Annex B.1.4a",
  420. "110101110110111110111111101111"
  421. "010101010111000011011000010010"
  422. "110110110001001010100110010001"
  423. "111000101010101111111111111110"
  424. "001111000010110010011000000011"
  425. "001001110010101010100000000000"
  426. "111011111110111111101111111110"
  427. "100110000011001001110000001010"
  428. "010001100010101010101001110001"
  429. "110111101111010000011011111100"
  430. "001100111111000000001010101001"
  431. "101110100000000001010011011010"
  432. "101010010010000000010110111111"
  433. "111101110000000000010011100010"
  434. "101010110000000000000110011101"
  435. "001000010000000000001100011110"
  436. "010011001000000000001000001010"
  437. "000000101000000000001010000010"
  438. "000100001100000000000010101010"
  439. "000010010100000000000100110000"
  440. "100000111100000000010001100000"
  441. "101000101000000000111110100000"
  442. "001000001110100101011010100101"
  443. "011001111110011001010100001000"
  444. "000010100010110001010101111010"
  445. "100111000011111000001101101010"
  446. "110010001001010010100000001101"
  447. "000001000110110100111010111100"
  448. "010111010010100100001111011010"
  449. "110111001110101010101101110100"
  450. "011011110001010100010111010011"
  451. "000111101001100001111000010110"
  452. "000100101000110000000111110011"
  453. },
  454. /* 4*/ { -1, 3, -1, { 0, 0, "" }, "CEN", -1, "B1050056999", 0, 33, 30, 1, "ISO/IEC 16023:2000 B.1 Example (primary only given, data arbitrary); verified manually against tec-it",
  455. "000000010101010101010101010111"
  456. "001011000000000000000000000010"
  457. "111001101010101010101010101000"
  458. "010101010101010101010101010110"
  459. "000000000000000000000000000001"
  460. "101010101010101010101010101010"
  461. "010101010101010101010101010100"
  462. "000000000000000000000000000010"
  463. "101010101010101010101010101000"
  464. "010101010111100000100101010110"
  465. "000000000001110000010100000010"
  466. "101010101000000011010010101010"
  467. "010101111100000000100001010110"
  468. "000000001100000000011000000010"
  469. "101010100100000000011110101001"
  470. "010101011000000000000001010110"
  471. "000000101000000000001000000001"
  472. "101010110000000000001010101010"
  473. "010101010000000000011101010101"
  474. "000000101000000000011100000000"
  475. "101010111100000000001010101001"
  476. "010101011110000000011101010110"
  477. "000000001110000001111000000011"
  478. "101010101011011001000110101010"
  479. "010101010101010101011100100010"
  480. "000000000000000000000011011100"
  481. "101010101010101010101001110100"
  482. "111011101110000110101011010110"
  483. "100001011111111101000011100111"
  484. "110100001000001101100010100110"
  485. "110110111111011110000011011111"
  486. "010010001001110010000101000010"
  487. "010001011010000011010010011100"
  488. },
  489. /* 5*/ { UNICODE_MODE | ESCAPE_MODE, -1, -1, { 0, 0, "" }, "Comité Européen de Normalisation\034rue de Stassart 36\034B-1050 BRUXELLES\034TEL +3225196811", -1, "", 0, 33, 30, 1, "ISO/IEC 16023:2000 Example F.5 **NOT SAME** uses different encodation (2 Shift A among other things)",
  490. "110010100010110000000100000111"
  491. "011010001100110110111110101100"
  492. "111010011100101010011100101101"
  493. "000000100010000000001000001100"
  494. "111101100000011100110011110110"
  495. "011110001011100010100111011110"
  496. "101010000100000111101000101010"
  497. "110010101110101101001000000010"
  498. "000110101100101111110010111111"
  499. "111101111011111000111110100000"
  500. "100000110101111010011110000000"
  501. "011100110100000000101100011000"
  502. "100001000110000000101011111100"
  503. "110011101100000000111000001000"
  504. "000110111100000000011010001011"
  505. "101010010000000000001000011100"
  506. "011000001000000000001000000000"
  507. "001001010000000000001101000010"
  508. "000000100100000000010000101010"
  509. "101111101100000000010010001110"
  510. "100000101110000000011110110000"
  511. "101101011010000001110000001010"
  512. "110001000110001011000111101001"
  513. "111111000110000001110000100010"
  514. "001000010001010101010111010000"
  515. "110100110100000000000010001010"
  516. "101111001110101010101101100111"
  517. "011010000110010001100100101010"
  518. "011100000011000100100111111110"
  519. "010100011110011011111011000100"
  520. "000000100010100101010010010010"
  521. "001111010001110000011001100110"
  522. "000100001011101000111010000010"
  523. },
  524. /* 6*/ { -1, -1, -1, { 0, 0, "" }, "999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999", -1, "", 0, 33, 30, 1, "Numeric compaction, verified manually against TEC-IT",
  525. "101101010111101101010111101111"
  526. "110110111011110110111011110100"
  527. "111101001111111101001111111100"
  528. "010111101101010111101101010110"
  529. "111001111110111001111110111000"
  530. "000111111111000111111111000110"
  531. "011110110101011110110101011111"
  532. "101111011011101111011011101100"
  533. "111111110100111111110100111101"
  534. "101101011111110100101001111010"
  535. "111110111111011010010110011111"
  536. "111111000000000000000101111100"
  537. "110101001100000000110001111010"
  538. "011011101100000000001110111100"
  539. "110100101100000000010111111110"
  540. "101101111000000000001101011110"
  541. "111110001000000000001011100100"
  542. "111111101000000000001100011110"
  543. "110101111000000000011001111000"
  544. "011011001100000000111010111110"
  545. "110100110110000000111011111110"
  546. "111011010010000000100101011100"
  547. "011111101110111111111011100101"
  548. "111111110110011001111000011100"
  549. "010101111011010101111010001110"
  550. "101110111101101110110110000000"
  551. "010011111111010011110011000000"
  552. "101010001001110111000101100100"
  553. "110111101010011001100011111000"
  554. "111000110011011001001101000110"
  555. "111010010010001000101000010101"
  556. "101111000100011110110011011100"
  557. "011111000110100011001101000000"
  558. },
  559. /* 7*/ { -1, 5, -1, { 0, 0, "" }, "\000\001\002\003\004\005\006\007\010\011\012\013\014\015\016\017\020\021\022\023\024\025\026\027\030\031\032\033\037\237\240\242\243\244\245\246\247\251\255\256\266\225\226\227\230\231\232\233\234\235\236", 51, "", 0, 33, 30, 1, "Mode 5 set E",
  560. "000000000000000000101010101011"
  561. "100101010111111111000000001000"
  562. "110010011100100111001001110011"
  563. "010101010101011010101010101000"
  564. "010110101010001101010110101010"
  565. "100011011000110101100011011000"
  566. "010101010101111111111111111100"
  567. "010111111111000000001010101010"
  568. "011100100111001001110010011110"
  569. "101010101011110000001010111100"
  570. "111111111111110010010011010110"
  571. "000000000110000010001000100010"
  572. "101010110010000000001110101011"
  573. "111111111000000000001011111100"
  574. "000000110100000000001100000010"
  575. "101010010000000000001010101000"
  576. "111111001000000000001011111101"
  577. "000000100000000000001000000010"
  578. "101010100000000000001010101001"
  579. "111111000000000000000011111110"
  580. "000000100100000000011100000000"
  581. "001011110100000001110111111000"
  582. "000111000010110101110111101111"
  583. "001110100010110001001010110010"
  584. "110011000100101011100101101100"
  585. "101111101011010011111111100110"
  586. "010001100101111110101001111101"
  587. "001000011101100111100101110010"
  588. "110100001111010010010010001111"
  589. "100010011100101000100000101100"
  590. "110100100100100001111100000111"
  591. "011111011011101100100101001010"
  592. "000011101111000101100100011101"
  593. },
  594. /* 8*/ { -1, 6, -1, { 0, 0, "" }, "\340\341\342\343\344\345\346\347\350\351\352\353\354\355\356\357\360\361\362\363\364\365\366\367\370\371\372\373\374\375\376\377\241\250\253\257\260\264\267\270\273\277\212\213\214\215\216\217\220\221\222\223\224", -1, "", 0, 33, 30, 1, "Mode 6 set D",
  595. "000000000000000000101010101011"
  596. "100101010111111111000000001010"
  597. "110010011100100111001001110001"
  598. "010101010101010110101010101010"
  599. "101010100000000001010110101000"
  600. "110110001101100001100011011000"
  601. "010101010101010111111111111111"
  602. "010101011111111100000000101000"
  603. "001001110010011100100111001001"
  604. "010111110111110000000011111110"
  605. "000001011011110010011101101011"
  606. "101001101110000001000100110110"
  607. "010101110000000000000001010110"
  608. "000000101000000000000000000010"
  609. "101010110100000000000110101010"
  610. "010101010000000000001001010100"
  611. "000000001000000000001000000011"
  612. "101010100000000000001010101010"
  613. "010101101100000000001001010111"
  614. "000000101000000000001000000010"
  615. "101010010110000000011010101001"
  616. "010101011100000000111101010100"
  617. "000000001110110111011000000011"
  618. "101010100110110001100110101010"
  619. "010101010101010101011001011100"
  620. "000000000000000000001000000000"
  621. "101010101010101010101010100010"
  622. "101100011100101000011001110100"
  623. "011100110000010001111110111110"
  624. "101101100000111001011101001010"
  625. "001100111110101100001101010101"
  626. "011111001010000101000011000110"
  627. "101111010010011100100011110010"
  628. },
  629. /* 9*/ { -1, 6, -1, { 0, 0, "" }, "\300\301\302\303\304\305\306\307\310\311\312\313\314\315\316\317\320\321\322\323\324\325\326\327\330\331\332\333\334\335\336\337\252\254\261\262\263\265\271\272\274\275\276\200\201\202\203\204\205\206\207\210\211", -1, "", 0, 33, 30, 1, "Mode 6 set C",
  630. "000000000000000000101010101011"
  631. "100101010111111111000000001010"
  632. "110010011100100111001001110001"
  633. "010101010101010110101010101010"
  634. "101010100000000001010110101000"
  635. "110110001101100001100011011000"
  636. "010101010101010111111111111111"
  637. "010101011111111100000000101000"
  638. "001001110010011100100111001001"
  639. "010111111111110000000111111110"
  640. "000001010111110010010001101011"
  641. "101001101010000001001100110110"
  642. "010101100000000000000101010110"
  643. "000000011000000000000100000010"
  644. "101010110100000000000010101010"
  645. "010101010000000000001001010100"
  646. "000000001000000000001000000011"
  647. "101010100000000000001010101010"
  648. "010101110000000000001001010111"
  649. "000000111100000000001100000010"
  650. "101010110000000000010110101001"
  651. "010101010100000000101101010100"
  652. "000000001010110101011000000011"
  653. "101010100010110001010110101010"
  654. "010101010101010101011001011100"
  655. "000000000000000000001000000000"
  656. "101010101010101010101010100010"
  657. "101100011100101000011001110100"
  658. "011100110000010001111110111110"
  659. "101101100000111001011101001010"
  660. "001100111110101100001101010101"
  661. "011111001010000101000011000110"
  662. "101111010010011100100011110010"
  663. },
  664. /* 10*/ { UNICODE_MODE | ESCAPE_MODE, 4, -1, { 0, 0, "" }, "`abcdefghijklmnopqrstuvwxyz\034\\G\\R{}~\177;<=>?[\\\\]^_ ,./:@!|", -1, "", 0, 33, 30, 1, "Mode 4 Set B",
  665. "000000000000000010101010101011"
  666. "010101011111111100000000101010"
  667. "001001110010011100100111001000"
  668. "010101010101101010101010101010"
  669. "101010000000111111010101101000"
  670. "011000110100011000011000110110"
  671. "010101010101010101111111111110"
  672. "100101010111111111000000001010"
  673. "110010011100100111001001110010"
  674. "010101011111000000000101111110"
  675. "000000001101001010011000101000"
  676. "101010101000000000100110011000"
  677. "010101010000000000001001010101"
  678. "000000111000000000001000000000"
  679. "101010111100000000011010101010"
  680. "010101010000000000000101010110"
  681. "000000001000000000001000000010"
  682. "101010100000000000001010101010"
  683. "010101110100000000001101010101"
  684. "000000010100000000101100000000"
  685. "101010110100000000001010101000"
  686. "010101010000000001010001010110"
  687. "000000000010111111001000000010"
  688. "101010101010110001011110101000"
  689. "010101010101010101010010101000"
  690. "000000000000000000000101100100"
  691. "101010101010101010100010010110"
  692. "001101100000000100111111111100"
  693. "011101101001110010100010011010"
  694. "111001101111100110001001101000"
  695. "000001100000101010001100101010"
  696. "100100110011010101001011100100"
  697. "001000101111010000111000010101"
  698. },
  699. /* 11*/ { UNICODE_MODE | ESCAPE_MODE, 4, -1, { 0, 0, "" }, "\\rABCDEFGHIJKLMNOPQRSTUVWXYZ\034\\G\\R \"#$%&'()*+,-./0123456789:", -1, "", 0, 33, 30, 1, "Mode 4 Set A",
  700. "000000000000001010101010101011"
  701. "010101111111110000000010101010"
  702. "100111001001110010011100100101"
  703. "010101010101011010101010101000"
  704. "101010100000001111110101011011"
  705. "110110001101000110000110001100"
  706. "010101010101010111100010111101"
  707. "010101011111111100111010111000"
  708. "001001110010011100111101000000"
  709. "010101010011000000000001111000"
  710. "000000001001001010010100011001"
  711. "101010100010000000010010011010"
  712. "010101000000000000000001010111"
  713. "000000110100000000100100000010"
  714. "101010110000000000001010101001"
  715. "010101010000000000001101010110"
  716. "000000001000000000001000000000"
  717. "101010100000000000001010101000"
  718. "010101001100000000001101010100"
  719. "000000111000000000101100000000"
  720. "101010000010000000011110101001"
  721. "010101010000000000100101010110"
  722. "000000001110000001101000000000"
  723. "101010100011000001001110101000"
  724. "010101010101010101011100010100"
  725. "000000000000000000001011000100"
  726. "101010101010101010101011110001"
  727. "100101110110110010101111111100"
  728. "101101011111001110100110100100"
  729. "010001101100100011100111010100"
  730. "010000101010001111010111011001"
  731. "010010011001101010010001111100"
  732. "100111100111001110011000011011"
  733. },
  734. /* 12*/ { UNICODE_MODE, 4, -1, { 0, 0, "" }, "ABCDabcdAabcABabcABCabcABCDaABCabABCabcABCéa", -1, "", 0, 33, 30, 1, "Mode 4 LCHB SHA 2SHA 3SHA LCHA SHB LCHB 3SHA 3SHA SHD",
  735. "110000000011000000000011000011"
  736. "010000000001000000000001000000"
  737. "111010011100100110011110100101"
  738. "000000001100000000110000000000"
  739. "000000000110000000110000000010"
  740. "110110101100110110111101101100"
  741. "110000110000000000001100000000"
  742. "110000010000000000000100000000"
  743. "111001101001111001111010011110"
  744. "010101010011000000001000001100"
  745. "000000000001000010001000011111"
  746. "101010100110000000010010101000"
  747. "010101000010000000000001010101"
  748. "000000001000000000101000000000"
  749. "101010100000000000010010101010"
  750. "010101011000000000001101010110"
  751. "000000001000000000001000000001"
  752. "101010001000000000001010101000"
  753. "010101001100000000001001010111"
  754. "000000111000000000011000000010"
  755. "101010101000000000001110101000"
  756. "010101010110000000010101010100"
  757. "000000001110001111001100000001"
  758. "101010101111000001101110101000"
  759. "010101010101010101011101000110"
  760. "000000000000000000000000000110"
  761. "101010101010101010101101100100"
  762. "000010001010001010000101010000"
  763. "101000000111100010010001111100"
  764. "101001111000010101010110110010"
  765. "011101111110011111011100001000"
  766. "110001000010011110111101111000"
  767. "011010011011111110001000000010"
  768. },
  769. /* 13*/ { UNICODE_MODE, 4, -1, { 0, 0, "" }, "ÀÁÂÃ1", -1, "", 0, 33, 30, 1, "Mode 4 LCKC LCHA",
  770. "010101010101010101010101010111"
  771. "000000000000000000000000000000"
  772. "101010101010101010101010101010"
  773. "010101010101010101010101010110"
  774. "000000000000000000000000000001"
  775. "101010101010101010101010101000"
  776. "010101010101010101010101010110"
  777. "000000000000000000000000000010"
  778. "101010101010101010101010101001"
  779. "010101011111110000111001010100"
  780. "000000001111110010001000000000"
  781. "101010101010000000011110101010"
  782. "010101000100000000000101010110"
  783. "000000110000000000000100000000"
  784. "101010011000000000001110101000"
  785. "010101110000000000001001010110"
  786. "000000101000000000001000000010"
  787. "101010000000000000001110101000"
  788. "010101001100000000000001010111"
  789. "000000100100000000001000000010"
  790. "101010010000000000010110101011"
  791. "010101011100000000001101010100"
  792. "000000001010110101111100000011"
  793. "101010101010110001111110101010"
  794. "010101010101010101011111010111"
  795. "000000000000000000001111010110"
  796. "101010101010101010100000000010"
  797. "111111110000111100000101000000"
  798. "010110101111000011110101010100"
  799. "101010100000010101011111101010"
  800. "111101011010000011110101101010"
  801. "010110101111010110101010111100"
  802. "010100000000010110101010010100"
  803. },
  804. /* 14*/ { UNICODE_MODE, 4, -1, { 0, 0, "" }, "ÀÁÂÃ123456789", -1, "", 0, 33, 30, 1, "Mode 4 LCKC NS",
  805. "111110110101010101010101010111"
  806. "111010010000000000000000000000"
  807. "000010011010101010101010101000"
  808. "010101010101010101010101010100"
  809. "000000000000000000000000000001"
  810. "101010101010101010101010101010"
  811. "010101010101010101010101010101"
  812. "000000000000000000000000000000"
  813. "101010101010101010101010101001"
  814. "010101010111110000110001010110"
  815. "000000000011110010010000000010"
  816. "101010100110000000111010101010"
  817. "010101011000000000001001010101"
  818. "000000101000000000001000000000"
  819. "101010000100000000000110101011"
  820. "010101010000000000001101010110"
  821. "000000001000000000001000000000"
  822. "101010100000000000001010101000"
  823. "010101100000000000001001010100"
  824. "000000001000000000001100000010"
  825. "101010110000000000011010101001"
  826. "010101010100000000011001010100"
  827. "000000001110110101111000000000"
  828. "101010101010110001000110101010"
  829. "010101010101010101010000101101"
  830. "000000000000000000001110011100"
  831. "101010101010101010100111100010"
  832. "011101100110110110100011110010"
  833. "010001101101001001100100011011"
  834. "100011011110110000101000000010"
  835. "101101111000011101010000100101"
  836. "000000111100011110100001110000"
  837. "101000000010100111001011110101"
  838. },
  839. /* 15*/ { UNICODE_MODE, 4, -1, { 0, 0, "" }, "àáâã1", -1, "", 0, 33, 30, 1, "Mode 4 LCKD LCHA",
  840. "010101010101010101010101010111"
  841. "000000000000000000000000000000"
  842. "101010101010101010101010101010"
  843. "010101010101010101010101010110"
  844. "000000000000000000000000000001"
  845. "101010101010101010101010101000"
  846. "010101010101010101010101010110"
  847. "000000000000000000000000000010"
  848. "101010101010101010101010101001"
  849. "010101010111110000111101010100"
  850. "000000000011110010000100000000"
  851. "101010101110000000010110101010"
  852. "010101010100000000000001010110"
  853. "000000000000000000000000000000"
  854. "101010011000000000001010101000"
  855. "010101110000000000001001010110"
  856. "000000101000000000001000000010"
  857. "101010000000000000001110101000"
  858. "010101010000000000000001010111"
  859. "000000110000000000001100000010"
  860. "101010110110000000011010101011"
  861. "010101010100000000011101010100"
  862. "000000001110110111111100000011"
  863. "101010101110110001001110101010"
  864. "010101010101010101011111010111"
  865. "000000000000000000001111010110"
  866. "101010101010101010100000000010"
  867. "111111110000111100000101000000"
  868. "010110101111000011110101010100"
  869. "101010100000010101011111101010"
  870. "111101011010000011110101101010"
  871. "010110101111010110101010111100"
  872. "010100000000010110101010010100"
  873. },
  874. /* 16*/ { UNICODE_MODE, 4, -1, { 0, 0, "" }, "¢£¤¥1", -1, "", 0, 33, 30, 1, "Mode 4 LCKE LCHA",
  875. "010101010101010101010101010111"
  876. "000000000000000000000000000000"
  877. "101010101010101010101010101010"
  878. "010101010101010101010101010110"
  879. "000000000000000000000000000001"
  880. "101010101010101010101010101000"
  881. "010101010101010101010101010110"
  882. "000000000000000000000000000010"
  883. "101010101010101010101010101001"
  884. "010101010111110100110001010100"
  885. "000000000101110110000100000000"
  886. "101010101010000000011110101010"
  887. "010101010110000000001001010110"
  888. "000000010000000000111000000000"
  889. "101010011000000000001110101000"
  890. "010101111000000000001001010110"
  891. "000000101000000000001000000010"
  892. "101010000000000000001110101000"
  893. "010101111000000000001101010111"
  894. "000000111100000000111000000010"
  895. "101010001100000000111110101011"
  896. "010101011110000001011101010100"
  897. "000000001010110001011100000011"
  898. "101010101010110101101010101010"
  899. "010101010101010101011111010111"
  900. "000000000000000000001111010110"
  901. "101010101010101010100000000010"
  902. "111111110000111100000101000000"
  903. "010110101111000011110101010100"
  904. "101010100000010101011111101010"
  905. "111101011010000011110101101010"
  906. "010110101111010110101010111100"
  907. "010100000000010110101010010100"
  908. },
  909. /* 17*/ { UNICODE_MODE, 4, -1, { 0, 0, "" }, "¢£¤¥123456789", -1, "", 0, 33, 30, 1, "Mode 4 LCKE NS",
  910. "111110101010101010101010101011"
  911. "111010111111111111111111111100"
  912. "000010000000000000000000000011"
  913. "101010101010101010101010101010"
  914. "111111111111111111111111111101"
  915. "000000000000000000000000000010"
  916. "101010101010101010101010101011"
  917. "111111111111111111111111111100"
  918. "000000000000000000000000000011"
  919. "101010101111110100111010101000"
  920. "111111111001110110011111111101"
  921. "000000000110000000111000000000"
  922. "101010001010000000000110101011"
  923. "111111001000000000110111111110"
  924. "000000000100000000000100000011"
  925. "101010011000000000001110101010"
  926. "111111001000000000001011111101"
  927. "000000100000000000001000000000"
  928. "101010010100000000000110101001"
  929. "111111010000000000111111111100"
  930. "000000101100000000110000000001"
  931. "101010100110000001001010101010"
  932. "111111111110110001011011111101"
  933. "000000001010110101010000000010"
  934. "101010101010101010100110111001"
  935. "111111111111111111110110001100"
  936. "000000000000000000001100010001"
  937. "001110001011100101010100110000"
  938. "010000101010111000100010110100"
  939. "111011010110010000010100011000"
  940. "111100010011001010110101010101"
  941. "011100101001010011011100111100"
  942. "101101110111011101011010011101"
  943. },
  944. /* 18*/ { UNICODE_MODE, 4, -1, { 0, 0, "" }, "ABCDE12abcde1ÀÁÂ⣤¥1àáâãabcde123A123456789àáâ㢣¤¥abc", -1, "", 0, 33, 30, 1, "Mode 4 mixed sets",
  945. "000000001111111100000000111111"
  946. "000010101100111100000000111100"
  947. "011100101110000000100111010111"
  948. "001100000000111111110101010110"
  949. "001100000000111100010101101010"
  950. "101111011000101010011000110110"
  951. "000000001111111100100010111110"
  952. "000010101100000000111010111000"
  953. "011100101110011110111101000010"
  954. "000000001011001100010111111010"
  955. "000000000001000010000111111000"
  956. "110110001110000000011110101000"
  957. "111101000010000000001101010101"
  958. "111110110000000000100110010100"
  959. "010101101000000000010111001001"
  960. "010100110000000000001100001110"
  961. "000000101000000000001000001110"
  962. "101011110000000000001101101110"
  963. "010101101000000000000001010101"
  964. "000000000100000000010000000010"
  965. "101010100000000000000110101001"
  966. "010101010100000000000101010100"
  967. "000000001010001011100000000011"
  968. "101010101011000001011010101000"
  969. "010101010101010101011001101001"
  970. "000000000000000000001010110000"
  971. "101010101010101010100111000000"
  972. "001010111101110100110011111010"
  973. "011101101010101100110000010101"
  974. "011100101111011110010010111010"
  975. "100101101011010111110011101011"
  976. "100010001001110010101010111000"
  977. "111010110110001100101000010001"
  978. },
  979. /* 19*/ { UNICODE_MODE, 4, -1, { 0, 0, "" }, "A123456789B123456789C123456789D123456789E123456789F123456789G123456789H123456789I123456789J123456789K123456789L123456789MNO123456789", -1, "", 0, 33, 30, 1, "Mode 4 spaced NSs",
  980. "001011111000100010111110001011"
  981. "101011101000111010111010101100"
  982. "110100001011111101000010001101"
  983. "100010111110001000101111100010"
  984. "111010101110101110101011101011"
  985. "110110000001111110100000011110"
  986. "001011111000100010111110001010"
  987. "101011101010111010111010011110"
  988. "110100001011111101000010001110"
  989. "100010110111101100010011100000"
  990. "110110100001111010011111101010"
  991. "111010000100000000101100011100"
  992. "001011101010000000001011100010"
  993. "101011111100000000110110100110"
  994. "110100001100000000010000100100"
  995. "101111011000000000000110001000"
  996. "101011001000000000001010101100"
  997. "100000001000000000001001111110"
  998. "001000101100000000000110111101"
  999. "011110001100000000111010111010"
  1000. "111111100010000000000101000001"
  1001. "111110000010000000001010001010"
  1002. "101110101010000011011011111011"
  1003. "000001110111001001101011001010"
  1004. "100000001000101111100001000111"
  1005. "101111111110101110101001010000"
  1006. "101001111111010000100110111011"
  1007. "101100110110010001111000100000"
  1008. "111101100110001110010001110001"
  1009. "000101001110100101000001111000"
  1010. "101101001001111010110101100000"
  1011. "011101000011011001001111111000"
  1012. "111010010011100000100100111111"
  1013. },
  1014. /* 20*/ { UNICODE_MODE, 4, -1, { 3, 7, "" }, "THIS IS A 91 CHARACTER CODE SET A MESSAGE THAT FILLS A MODE 4, APPENDED, MAXICODE SYMBOL...", -1, "", 0, 33, 30, 1, "Mode 4 Structured Append",
  1015. "010001111101000000100000100011"
  1016. "000000010000000100000000101000"
  1017. "001000101000110010011011001000"
  1018. "000100011000100100000000011000"
  1019. "110000001010000010101100000010"
  1020. "100010000010110010001111000100"
  1021. "001010000000011000001001000010"
  1022. "100000001010001001001000100110"
  1023. "101111101110000000100000011010"
  1024. "000100010011101000000110000010"
  1025. "110000000111100010001100111100"
  1026. "100010001010000000000011000010"
  1027. "000000001010000000010101110101"
  1028. "111010110000000000010100101100"
  1029. "110010111100000000001100000011"
  1030. "000010010000000000001010000100"
  1031. "111000001000000000001000000000"
  1032. "011000010000000000001100100000"
  1033. "000000001100000000011001010000"
  1034. "101010010100000000000111001100"
  1035. "001000000000000000001000001001"
  1036. "000000000010000000000000100000"
  1037. "101011000110011011000001010001"
  1038. "100011111010000001000010001000"
  1039. "011010000000000101011111110010"
  1040. "000001110011111111111010100000"
  1041. "001110100111000101011001001100"
  1042. "011010010100110111100101011100"
  1043. "101101001001011111000110110111"
  1044. "110001110110110001000011001010"
  1045. "011100001000111100110111011110"
  1046. "010101011101100110111011100100"
  1047. "011001000011110011011110111010"
  1048. },
  1049. /* 21*/ { UNICODE_MODE, 3, -1, { 1, 8, "" }, "COMMISSION FOR EUROPEAN NORMALIZATION, RUE DE STASSART 36, B-1050 BRUXELLES", -1, "B1050056999", 0, 33, 30, 1, "Mode 3 Structured Append",
  1050. "010000000000001010000000010011"
  1051. "001000111111010000011111001000"
  1052. "101111111010101111101101000101"
  1053. "000001000000100010100001100010"
  1054. "111100110010001100101000001110"
  1055. "110100011010001101101000011100"
  1056. "100000000010001000000001011010"
  1057. "001100110101001001111111000010"
  1058. "011010001001100010110100000111"
  1059. "100100000111100000100101001000"
  1060. "000010100001110000010100101010"
  1061. "110010001000000011010000101000"
  1062. "100010111100000000100010001001"
  1063. "100000001100000000011000000000"
  1064. "001011100100000000011111100100"
  1065. "010111011000000000000011011010"
  1066. "001110101000000000001000001000"
  1067. "000001110000000000001011000000"
  1068. "000111010000000000011111111101"
  1069. "001100101000000000011100100010"
  1070. "011010111100000000001000100000"
  1071. "000010101110000000011110000110"
  1072. "111001101110000001111000000000"
  1073. "001000101011011001000101010000"
  1074. "000010010101010101010000111101"
  1075. "111000000000000000001110100000"
  1076. "001011101010101010101000100010"
  1077. "001100110110100101101100010110"
  1078. "111100110000110110000010011001"
  1079. "011100011110101010001100000000"
  1080. "011001100010001111111000101001"
  1081. "011111110000111010001010001100"
  1082. "110010001001001011011111100111"
  1083. },
  1084. /* 22*/ { UNICODE_MODE, -1, -1, { 0, 0, "" }, "am.//ab,\034TA# z\015!", -1, "", 0, 33, 30, 1, "Was test_best_supported_set",
  1085. "101110000101101100110101010111"
  1086. "110110000011010100100000000010"
  1087. "001000101111011100101010101010"
  1088. "010101010101010101010101010110"
  1089. "000000000000000000000000000001"
  1090. "101010101010101010101010101010"
  1091. "010101010101010101010101010100"
  1092. "000000000000000000000000000010"
  1093. "101010101010101010101010101011"
  1094. "010101010111001100000101010110"
  1095. "000000001011000010000000000001"
  1096. "101010101100000000100110101010"
  1097. "010101001100000000101101010110"
  1098. "000000100000000000010000000010"
  1099. "101010110000000000010010101011"
  1100. "010101011000000000000101010100"
  1101. "000000001000000000001000000000"
  1102. "101010001000000000001010101000"
  1103. "010101010000000000001101010101"
  1104. "000000001100000000000000000010"
  1105. "101010110010000000010110101011"
  1106. "010101010100000001111001010110"
  1107. "000000001110110111111100000000"
  1108. "101010100110111101011010101000"
  1109. "010101010101010101011101100010"
  1110. "000000000000000000000101101000"
  1111. "101010101010101010100011011000"
  1112. "000000100000111000011101111100"
  1113. "110001011111000111110010001000"
  1114. "001011000001011000000110100000"
  1115. "110010000110011010101100011010"
  1116. "011011001001000010000110011100"
  1117. "000010111111111111001110001110"
  1118. },
  1119. };
  1120. const int data_size = ARRAY_SIZE(data);
  1121. int i, length, ret;
  1122. struct zint_symbol *symbol = NULL;
  1123. char escaped[1024];
  1124. char cmp_buf[8192];
  1125. char cmp_msg[1024];
  1126. int do_bwipp = (debug & ZINT_DEBUG_TEST_BWIPP) && testUtilHaveGhostscript(); /* Only do BWIPP test if asked, too slow otherwise */
  1127. int do_zxingcpp = (debug & ZINT_DEBUG_TEST_ZXINGCPP) && testUtilHaveZXingCPPDecoder(); /* Only do ZXing-C++ test if asked, too slow otherwise */
  1128. testStartSymbol("test_encode", &symbol);
  1129. for (i = 0; i < data_size; i++) {
  1130. if (testContinue(p_ctx, i)) continue;
  1131. symbol = ZBarcode_Create();
  1132. assert_nonnull(symbol, "Symbol not created\n");
  1133. length = testUtilSetSymbol(symbol, BARCODE_MAXICODE, data[i].input_mode, -1 /*eci*/, data[i].option_1, data[i].option_2, -1, -1 /*output_options*/, data[i].data, data[i].length, debug);
  1134. if (data[i].structapp.count) {
  1135. symbol->structapp = data[i].structapp;
  1136. }
  1137. strcpy(symbol->primary, data[i].primary);
  1138. ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length);
  1139. assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
  1140. if (p_ctx->generate) {
  1141. printf(" /*%3d*/ { %s, %d, %d, { %d, %d, \"%s\" }, \"%s\", %d, \"%s\", %s, %d, %d, %d, \"%s\",\n",
  1142. i, testUtilInputModeName(data[i].input_mode), data[i].option_1, data[i].option_2,
  1143. data[i].structapp.index, data[i].structapp.count, data[i].structapp.id,
  1144. testUtilEscape(data[i].data, length, escaped, sizeof(escaped)), data[i].length,
  1145. data[i].primary, testUtilErrorName(data[i].ret), symbol->rows, symbol->width, data[i].bwipp_cmp, data[i].comment);
  1146. testUtilModulesPrint(symbol, " ", "\n");
  1147. printf(" },\n");
  1148. } else {
  1149. if (ret < ZINT_ERROR) {
  1150. int width, row;
  1151. assert_equal(symbol->rows, data[i].expected_rows, "i:%d symbol->rows %d != %d (%s)\n", i, symbol->rows, data[i].expected_rows, data[i].data);
  1152. assert_equal(symbol->width, data[i].expected_width, "i:%d symbol->width %d != %d (%s)\n", i, symbol->width, data[i].expected_width, data[i].data);
  1153. ret = testUtilModulesCmp(symbol, data[i].expected, &width, &row);
  1154. assert_zero(ret, "i:%d testUtilModulesCmp ret %d != 0 width %d row %d (%s)\n", i, ret, width, row, data[i].data);
  1155. if (do_bwipp && testUtilCanBwipp(i, symbol, data[i].option_1, data[i].option_2, -1, debug)) {
  1156. if (!data[i].bwipp_cmp) {
  1157. if (debug & ZINT_DEBUG_TEST_PRINT) printf("i:%d %s not BWIPP compatible (%s)\n", i, testUtilBarcodeName(symbol->symbology), data[i].comment);
  1158. } else {
  1159. ret = testUtilBwipp(i, symbol, data[i].option_1, data[i].option_2, -1, data[i].data, length, data[i].primary, cmp_buf, sizeof(cmp_buf), NULL);
  1160. assert_zero(ret, "i:%d %s testUtilBwipp ret %d != 0\n", i, testUtilBarcodeName(symbol->symbology), ret);
  1161. ret = testUtilBwippCmp(symbol, cmp_msg, cmp_buf, data[i].expected);
  1162. assert_zero(ret, "i:%d %s testUtilBwippCmp %d != 0 %s\n actual: %s\nexpected: %s\n",
  1163. i, testUtilBarcodeName(symbol->symbology), ret, cmp_msg, cmp_buf, data[i].expected);
  1164. }
  1165. }
  1166. if (do_zxingcpp && testUtilCanZXingCPP(i, symbol, data[i].data, length, debug)) {
  1167. int cmp_len, ret_len;
  1168. char modules_dump[17984 + 1];
  1169. assert_notequal(testUtilModulesDump(symbol, modules_dump, sizeof(modules_dump)), -1, "i:%d testUtilModulesDump == -1\n", i);
  1170. ret = testUtilZXingCPP(i, symbol, data[i].data, length, modules_dump, cmp_buf, sizeof(cmp_buf), &cmp_len);
  1171. assert_zero(ret, "i:%d %s testUtilZXingCPP ret %d != 0\n", i, testUtilBarcodeName(symbol->symbology), ret);
  1172. ret = testUtilZXingCPPCmp(symbol, cmp_msg, cmp_buf, cmp_len, data[i].data, length, data[i].primary, escaped, &ret_len);
  1173. assert_zero(ret, "i:%d %s testUtilZXingCPPCmp %d != 0 %s\n actual: %.*s\nexpected: %.*s\n",
  1174. i, testUtilBarcodeName(symbol->symbology), ret, cmp_msg, cmp_len, cmp_buf, ret_len, escaped);
  1175. }
  1176. }
  1177. }
  1178. ZBarcode_Delete(symbol);
  1179. }
  1180. testFinish();
  1181. }
  1182. static void test_encode_segs(const testCtx *const p_ctx) {
  1183. int debug = p_ctx->debug;
  1184. struct item {
  1185. int input_mode;
  1186. int option_1;
  1187. int option_2;
  1188. struct zint_structapp structapp;
  1189. struct zint_seg segs[3];
  1190. char *primary;
  1191. int ret;
  1192. int expected_rows;
  1193. int expected_width;
  1194. int bwipp_cmp;
  1195. char *comment;
  1196. char *expected;
  1197. };
  1198. static const struct item data[] = {
  1199. /* 0*/ { UNICODE_MODE, -1, -1, { 0, 0, "" }, { { TU("¶"), -1, 0 }, { TU("Ж"), -1, 7 }, { TU(""), 0, 0 } }, "", 0, 33, 30, 1, "ISO 16023:2000 4.15.4 example",
  1200. "010101010101010101010101010111"
  1201. "000000000000000000000000000000"
  1202. "101010101010101010101010101010"
  1203. "010101010101010101010101010110"
  1204. "000000000000000000000000000001"
  1205. "101010101010101010101010101000"
  1206. "010101010101010101010101010110"
  1207. "000000000000000000000000000010"
  1208. "101010101010101010101010101001"
  1209. "010101010011010100000101010100"
  1210. "000000000011111110001000000000"
  1211. "101010101110000000101010101010"
  1212. "010101110110000000110101010110"
  1213. "000000110000000000100100000000"
  1214. "101010011000000000010010101000"
  1215. "010101111000000000001001010110"
  1216. "000000001000000000001000000010"
  1217. "101010001000000000001110101000"
  1218. "010101111100000000000001010111"
  1219. "000000010000000000110100000010"
  1220. "101010000110000000010110101011"
  1221. "010101011010000001110001010100"
  1222. "000000000010110101000100000011"
  1223. "101010100111110001001110101010"
  1224. "010101010101010101011111010111"
  1225. "000000000000000000001111010110"
  1226. "101010101010101010100000000010"
  1227. "111111110000111100000101000000"
  1228. "010110101111000011110101010100"
  1229. "101010100000010101011111101010"
  1230. "111101011010000011110101101010"
  1231. "010110101111010110101010111100"
  1232. "010100000000010110101010010100"
  1233. },
  1234. /* 1*/ { UNICODE_MODE, -1, -1, { 0, 0, "" }, { { TU("¶"), -1, 0 }, { TU("Ж"), -1, 0 }, { TU(""), 0, 0 } }, "", ZINT_WARN_USES_ECI, 33, 30, 1, "ISO 16023:2000 4.15.4 example auto-ECI",
  1235. "010101010101010101010101010111"
  1236. "000000000000000000000000000000"
  1237. "101010101010101010101010101010"
  1238. "010101010101010101010101010110"
  1239. "000000000000000000000000000001"
  1240. "101010101010101010101010101000"
  1241. "010101010101010101010101010110"
  1242. "000000000000000000000000000010"
  1243. "101010101010101010101010101001"
  1244. "010101010011010100000101010100"
  1245. "000000000011111110001000000000"
  1246. "101010101110000000101010101010"
  1247. "010101110110000000110101010110"
  1248. "000000110000000000100100000000"
  1249. "101010011000000000010010101000"
  1250. "010101111000000000001001010110"
  1251. "000000001000000000001000000010"
  1252. "101010001000000000001110101000"
  1253. "010101111100000000000001010111"
  1254. "000000010000000000110100000010"
  1255. "101010000110000000010110101011"
  1256. "010101011010000001110001010100"
  1257. "000000000010110101000100000011"
  1258. "101010100111110001001110101010"
  1259. "010101010101010101011111010111"
  1260. "000000000000000000001111010110"
  1261. "101010101010101010100000000010"
  1262. "111111110000111100000101000000"
  1263. "010110101111000011110101010100"
  1264. "101010100000010101011111101010"
  1265. "111101011010000011110101101010"
  1266. "010110101111010110101010111100"
  1267. "010100000000010110101010010100"
  1268. },
  1269. /* 2*/ { UNICODE_MODE, -1, -1, { 0, 0, "" }, { { TU("Ж"), -1, 7 }, { TU("¶"), -1, 0 }, { TU(""), 0, 0 } }, "", 0, 33, 30, 1, "ISO 16023:2000 4.15.4 example inverted",
  1270. "010101010101010101010101010111"
  1271. "000000000000000000000000000000"
  1272. "101010101010101010101010101010"
  1273. "010101010101010101010101010110"
  1274. "000000000000000000000000000001"
  1275. "101010101010101010101010101000"
  1276. "010101010101010101010101010110"
  1277. "000000000000000000000000000010"
  1278. "101010101010101010101010101001"
  1279. "010101010011000000110101010100"
  1280. "000000000111100010011000000000"
  1281. "101010100110000000011010101010"
  1282. "010101010110000000110101010110"
  1283. "000000000000000000111100000000"
  1284. "101010101000000000001110101000"
  1285. "010101110000000000001101010110"
  1286. "000000001000000000001000000010"
  1287. "101010111000000000001110101000"
  1288. "010101101000000000010101010111"
  1289. "000000100100000000111000000010"
  1290. "101010011010000000110110101011"
  1291. "010101010110000001111001010100"
  1292. "000000001010101111101100000011"
  1293. "101010101110010101110010101010"
  1294. "010101010101010101011111010111"
  1295. "000000000000000000001111010110"
  1296. "101010101010101010100000000010"
  1297. "111111110000111100000101000000"
  1298. "010110101111000011110101010100"
  1299. "101010100000010101011111101010"
  1300. "111101011010000011110101101010"
  1301. "010110101111010110101010111100"
  1302. "010100000000010110101010010100"
  1303. },
  1304. /* 3*/ { UNICODE_MODE, -1, -1, { 0, 0, "" }, { { TU("Ж"), -1, 0 }, { TU("¶"), -1, 0 }, { TU(""), 0, 0 } }, "", ZINT_WARN_USES_ECI, 33, 30, 1, "ISO 16023:2000 4.15.4 example inverted auto-ECI",
  1305. "010101010101010101010101010111"
  1306. "000000000000000000000000000000"
  1307. "101010101010101010101010101010"
  1308. "010101010101010101010101010110"
  1309. "000000000000000000000000000001"
  1310. "101010101010101010101010101000"
  1311. "010101010101010101010101010110"
  1312. "000000000000000000000000000010"
  1313. "101010101010101010101010101001"
  1314. "010101010011000000110101010100"
  1315. "000000000111100010011000000000"
  1316. "101010100110000000011010101010"
  1317. "010101010110000000110101010110"
  1318. "000000000000000000111100000000"
  1319. "101010101000000000001110101000"
  1320. "010101110000000000001101010110"
  1321. "000000001000000000001000000010"
  1322. "101010111000000000001110101000"
  1323. "010101101000000000010101010111"
  1324. "000000100100000000111000000010"
  1325. "101010011010000000110110101011"
  1326. "010101010110000001111001010100"
  1327. "000000001010101111101100000011"
  1328. "101010101110010101110010101010"
  1329. "010101010101010101011111010111"
  1330. "000000000000000000001111010110"
  1331. "101010101010101010100000000010"
  1332. "111111110000111100000101000000"
  1333. "010110101111000011110101010100"
  1334. "101010100000010101011111101010"
  1335. "111101011010000011110101101010"
  1336. "010110101111010110101010111100"
  1337. "010100000000010110101010010100"
  1338. },
  1339. /* 4*/ { UNICODE_MODE, -1, -1, { 0, 0, "" }, { { TU("Pixel 4a 128 GB:$439.97"), -1, 3 }, { TU("Pixel 4a 128 GB:¥3149.79"), -1, 29 }, { TU("Pixel 4a 128 GB:444,90 €"), -1, 17 } }, "", 0, 33, 30, 1, "AIM ITS/04-023:2022 Annex A example (shortened)",
  1340. "011111000111111101000011011111"
  1341. "001001000000000100100001101010"
  1342. "000011100010010000110101000001"
  1343. "110000100011101010111101111110"
  1344. "111110010111001101100111010000"
  1345. "110010001011001011111001101110"
  1346. "011111000111111101000011110110"
  1347. "001001000000000100100001111000"
  1348. "000011100010010000110101011100"
  1349. "011111111011001000000111011110"
  1350. "110110000101000110011000011100"
  1351. "011000101100000000100011000100"
  1352. "111110001110000000011010101110"
  1353. "100101101100000000001000001110"
  1354. "111011001100000000001110001100"
  1355. "011100010000000000000000100010"
  1356. "001111001000000000001010010111"
  1357. "001100110000000000001010001000"
  1358. "111100011100000000011001111110"
  1359. "100100110000000000110100000010"
  1360. "001110000110000000011100100110"
  1361. "111111001110000001011000011100"
  1362. "101001000110101011001110000100"
  1363. "000001010110011101111011000000"
  1364. "110111110111010101011111010000"
  1365. "101101000011010000000101101100"
  1366. "000010000001001010100001001111"
  1367. "001010001101110010110101001000"
  1368. "111110111100101100111101000110"
  1369. "010000000001111110111001010000"
  1370. "110101000010011011010111000110"
  1371. "100010110010010000000010010100"
  1372. "100011010011101111001011000001"
  1373. },
  1374. /* 5*/ { UNICODE_MODE, -1, -1, { 0, 0, "" }, { { TU("$439.97"), -1, 3 }, { TU("¥3149.79"), -1, 29 }, { TU("444,90 €"), -1, 17 } }, "", 0, 33, 30, 1, "AIM ITS/04-023:2022 Annex A example price only",
  1375. "101011011101111111110111111011"
  1376. "011111101101000010011110010100"
  1377. "111001110100111000100111101110"
  1378. "010101010111011111011111111010"
  1379. "000000000111000001111010100011"
  1380. "101010100001000010000000001010"
  1381. "010101010101010101010101010111"
  1382. "000000000000000000000000000010"
  1383. "101010101010101010101010101000"
  1384. "010101010111001100100001010100"
  1385. "000000001001000110011100000010"
  1386. "101010100010000000011110101010"
  1387. "010101011110000000001101010100"
  1388. "000000101000000000010000000000"
  1389. "101010001100000000000110101000"
  1390. "010101111000000000001001010110"
  1391. "000000101000000000001000000010"
  1392. "101010011000000000001110101010"
  1393. "010101110100000000001101010101"
  1394. "000000001000000000011000000000"
  1395. "101010010010000000101010101000"
  1396. "010101010100000001111101010100"
  1397. "000000000110101111101000000011"
  1398. "101010100110011101000110101000"
  1399. "010101010101010101011001001110"
  1400. "000000000000000000000000000100"
  1401. "101010101010101010100101100101"
  1402. "001001110101111010110011011100"
  1403. "001100001100101000100101110110"
  1404. "011101100101000100110011000100"
  1405. "000100101101010011010011101111"
  1406. "010111011011100000011000101000"
  1407. "001111010010000100010110011110"
  1408. },
  1409. /* 6*/ { DATA_MODE, -1, -1, { 0, 0, "" }, { { TU("\266"), 1, 0 }, { TU("\266"), 1, 7 }, { TU("\266"), 1, 0 } }, "", 0, 33, 30, 1, "Standard example + extra seg, data mode",
  1410. "101010101010101010101010101011"
  1411. "111111111111111111111111111100"
  1412. "000000000000000000000000000011"
  1413. "101010101010101010101010101010"
  1414. "111111111111111111111111111111"
  1415. "000000000000000000000000000000"
  1416. "101010101010101010101010101011"
  1417. "111111111111111111111111111110"
  1418. "000000000000000000000000000011"
  1419. "101010100011110100111010101000"
  1420. "111111110011111110000011111111"
  1421. "000000001110000000111000000010"
  1422. "101010110110000000101110101010"
  1423. "111111111100000000110011111100"
  1424. "000000001100000000010100000011"
  1425. "101010010000000000001110101010"
  1426. "111111001000000000001011111110"
  1427. "000000000000000000001000000010"
  1428. "101010101000000000010010101001"
  1429. "111111110100000000100011111110"
  1430. "000000110000000000111100000010"
  1431. "101010100100000001110110101010"
  1432. "111111111110111101101111111101"
  1433. "000000000011111001100100000010"
  1434. "101010101010101010101010010110"
  1435. "111111111111111111110101111110"
  1436. "000000000000000000000101101010"
  1437. "000001010101000010100101111110"
  1438. "101001011111101011111010000010"
  1439. "111111110000101011110101101010"
  1440. "000000001111111101011111000010"
  1441. "111100001111010101010101111110"
  1442. "000010100101010111111010101010"
  1443. },
  1444. /* 7*/ { UNICODE_MODE, -1, -1, { 0, 0, "" }, { { TU("αβ"), -1, 0 }, { TU("ÿ"), -1, 0 }, { TU("貫やぐ禁"), -1, 20 } }, "", ZINT_WARN_USES_ECI, 33, 30, 1, "Auto-ECI",
  1445. "101001111110111100111101111111"
  1446. "011011111100001100001111110010"
  1447. "110011000010011001010101100010"
  1448. "010101010101010101010101111000"
  1449. "000000000000000000000000011010"
  1450. "101010101010101010101010010100"
  1451. "010101010101010101010101010101"
  1452. "000000000000000000000000000010"
  1453. "101010101010101010101010101011"
  1454. "010101010111000000110101010110"
  1455. "000000001011010010000000000000"
  1456. "101010100000000000111010101000"
  1457. "010101100100000000110101010111"
  1458. "000000011000000000011100000000"
  1459. "101010010000000000010010101010"
  1460. "010101010000000000001101010110"
  1461. "000000001000000000001000000011"
  1462. "101010000000000000001010101010"
  1463. "010101100000000000010001010100"
  1464. "000000000000000000010100000010"
  1465. "101010110010000000110010101000"
  1466. "010101011000000001001001010110"
  1467. "000000000010101011101100000000"
  1468. "101010100010011101101110101000"
  1469. "010101010101010101011111011101"
  1470. "000000000000000000000110001000"
  1471. "101010101010101010100100010011"
  1472. "001001001011101100110001101010"
  1473. "100011101101100100001001100101"
  1474. "110000000110011111100001111000"
  1475. "000011110000100000101100001100"
  1476. "101111001101000010111111110000"
  1477. "001001000010100001000011101011"
  1478. },
  1479. /* 8*/ { UNICODE_MODE, -1, -1, { 1, 2, "" }, { { TU("αβ"), -1, 9 }, { TU("ÿ"), -1, 3 }, { TU("貫やぐ禁"), -1, 20 } }, "", 0, 33, 30, 1, "Structured Append",
  1480. "000110100111111011110011110111"
  1481. "001001101111110000110000111100"
  1482. "110011001100001001100101010101"
  1483. "010101010101010101011110111110"
  1484. "000000000000000000000110001101"
  1485. "101010101010101010100101001010"
  1486. "010101010101010101010101010111"
  1487. "000000000000000000000000000010"
  1488. "101010101010101010101010101000"
  1489. "010101010011001100000001010110"
  1490. "000000000101001110001000000011"
  1491. "101010101010000000101110101000"
  1492. "010101111000000000110001010101"
  1493. "000000110100000000100000000010"
  1494. "101010001100000000011010101011"
  1495. "010101011000000000000101010100"
  1496. "000000001000000000001000000010"
  1497. "101010001000000000001010101000"
  1498. "010101100000000000011101010110"
  1499. "000000001000000000001000000010"
  1500. "101010101110000000011010101001"
  1501. "010101010110000000010101010110"
  1502. "000000001110011011011000000010"
  1503. "101010100011000001100010101010"
  1504. "010101010101010101011010110111"
  1505. "000000000000000000001111011010"
  1506. "101010101010101010101101010010"
  1507. "111001010001101011001010011100"
  1508. "001101001101101110010010110011"
  1509. "101000100011001111100000101000"
  1510. "100000000110100010001110000100"
  1511. "101000101011101111110001101000"
  1512. "000010101010000010000100110100"
  1513. },
  1514. /* 9*/ { UNICODE_MODE, -1, -1, { 0, 0, "" }, { { TU("ab"), -1, 3 }, { TU("ABCD"), -1, 4 }, { TU(""), 0, 0 } }, "", 0, 33, 30, 1, "Code Set B then A",
  1515. "000000010101010101010101010111"
  1516. "000010000000000000000000000010"
  1517. "011100101010101010101010101001"
  1518. "010101010101010101010101010110"
  1519. "000000000000000000000000000010"
  1520. "101010101010101010101010101010"
  1521. "010101010101010101010101010100"
  1522. "000000000000000000000000000000"
  1523. "101010101010101010101010101011"
  1524. "010101010111000000110001010100"
  1525. "000000001011000010000100000000"
  1526. "101010100000000000111110101010"
  1527. "010101110010000000111001010110"
  1528. "000000000000000000101000000010"
  1529. "101010011000000000010110101011"
  1530. "010101011000000000000001010110"
  1531. "000000001000000000001000000001"
  1532. "101010101000000000001010101000"
  1533. "010101000000000000001001010101"
  1534. "000000001000000000001100000010"
  1535. "101010001110000000111010101001"
  1536. "010101010010000001111101010100"
  1537. "000000000110101111011000000010"
  1538. "101010101010010001101010101010"
  1539. "010101010101010101011110000100"
  1540. "000000000000000000001100111010"
  1541. "101010101010101010101100000000"
  1542. "110000011010110101000110100010"
  1543. "100100110111110111001111101011"
  1544. "011111111011111001110100101100"
  1545. "101000010001001011101111001010"
  1546. "011011011101010101001101001000"
  1547. "001010010110100000100111101000"
  1548. },
  1549. /* 10*/ { UNICODE_MODE, -1, -1, { 0, 0, "" }, { { TU("\004\004\004\004"), -1, 3 }, { TU("ABCD"), -1, 4 }, { TU("abcd"), -1, 5 } }, "", 0, 33, 30, 0, "Code Set E then A then B; BWIPP different encodation, LCHA before 2nd ECI not after, same codeword count, same result",
  1550. "001100000000100011000000000111"
  1551. "100100000010011011000000100000"
  1552. "000110011100111011100111001010"
  1553. "010101010101010101010101010100"
  1554. "000000000000000000000000000011"
  1555. "101010101010101010101010101010"
  1556. "010101010101010101010101010111"
  1557. "000000000000000000000000000010"
  1558. "101010101010101010101010101000"
  1559. "010101010111000000000001010110"
  1560. "000000001001001010011100000011"
  1561. "101010100100000000000110101010"
  1562. "010101101010000000110101010100"
  1563. "000000100100000000111000000010"
  1564. "101010111100000000000010101001"
  1565. "010101010000000000000001010110"
  1566. "000000001000000000001000000001"
  1567. "101010100000000000001010101010"
  1568. "010101110100000000010101010110"
  1569. "000000111000000000110100000000"
  1570. "101010000110000000101010101011"
  1571. "010101010000000001010101010110"
  1572. "000000000110100011101100000011"
  1573. "101010100011011101111110101010"
  1574. "010101010101010101010101101000"
  1575. "000000000000000000001001000010"
  1576. "101010101010101010101010110111"
  1577. "100010010101100011100111000100"
  1578. "110110101110100010100011010011"
  1579. "100001111011001010101000111000"
  1580. "101100010110101111011111100011"
  1581. "111010100101000101001011011000"
  1582. "011111000111001010010000111100"
  1583. },
  1584. /* 11*/ { UNICODE_MODE, -1, -1, { 0, 0, "" }, { { TU("12345678"), -1, 3 }, { TU("91234567901"), -1, 4 }, { TU("12345678"), -1, 5 } }, "", 0, 33, 30, 1, "Digits spanning ECIs",
  1585. "111000111110001111011010001111"
  1586. "010110010011111100001101100010"
  1587. "001100101011100111111011101001"
  1588. "010101010101011111111111111110"
  1589. "000000000000000110101010000010"
  1590. "101010101010100011011000110110"
  1591. "010101010101010101010101010111"
  1592. "000000000000000000000000000010"
  1593. "101010101010101010101010101001"
  1594. "010101011111001100010001010100"
  1595. "000000000001001010011000000010"
  1596. "101010100000000000101010101000"
  1597. "010101011110000000011001010110"
  1598. "000000011000000000001100000010"
  1599. "101010101100000000011110101010"
  1600. "010101111000000000000101010100"
  1601. "000000101000000000001000000000"
  1602. "101010101000000000001110101000"
  1603. "010101010100000000000101010110"
  1604. "000000001100000000100000000000"
  1605. "101010001110000000101110101001"
  1606. "010101011100000001010101010110"
  1607. "000000001010101111111000000011"
  1608. "101010101010011101101110101000"
  1609. "010101010101010101011010001010"
  1610. "000000000000000000000110111110"
  1611. "101010101010101010100011111111"
  1612. "011111100011010101000000000110"
  1613. "111111010001111000000100101010"
  1614. "011101100000010110110001000100"
  1615. "101110111111001001111001110000"
  1616. "010101101100001010110111001100"
  1617. "101011011010100110010010100111"
  1618. },
  1619. /* 12*/ { UNICODE_MODE, -1, 96 + 1, { 0, 0, "" }, { { TU("12345678"), -1, 3 }, { TU("91234567901"), -1, 4 }, { TU("12345678"), -1, 5 } }, "9999840012", 0, 33, 30, 1, "SCM prefix mode 2",
  1620. "110101110110111110111110001111"
  1621. "010101010111000011011001000000"
  1622. "110110110001001010100111111001"
  1623. "110010111100101111111111111110"
  1624. "111111000110010110101010000010"
  1625. "011011101000110011011000110100"
  1626. "110110100011111111111111110100"
  1627. "000011011000000010101010010010"
  1628. "111110111010011100100111001001"
  1629. "010101010011010000011101010110"
  1630. "000000000001100000000100000001"
  1631. "101010101110000001011010101000"
  1632. "010101100010000000000001010100"
  1633. "000000100000000000001000000000"
  1634. "101010110000000000001110101000"
  1635. "010101110000000000011101010110"
  1636. "000000101000000000001000000011"
  1637. "101010000000000000011010101010"
  1638. "010101011100000000000101010110"
  1639. "000000111000000000000100000010"
  1640. "101010100110000000001010101011"
  1641. "010101011000000001101101010100"
  1642. "000000001010000011010100000010"
  1643. "101010100110000001010110101000"
  1644. "010101010101010101010010100111"
  1645. "000000000000000000001111100100"
  1646. "101010101010101010100000011011"
  1647. "001001001110011001111101100010"
  1648. "110000110000100111010010101000"
  1649. "110001111010010001001101000010"
  1650. "100110000010010001101011000111"
  1651. "110011010111010010100011101000"
  1652. "111010011111011100110001010110"
  1653. },
  1654. /* 13*/ { UNICODE_MODE, 3, 96 + 1, { 0, 0, "" }, { { TU("12345678"), -1, 3 }, { TU("91234567901"), -1, 4 }, { TU("12345678"), -1, 5 } }, "B999840012", 0, 33, 30, 1, "SCM prefix mode 3",
  1655. "110101110110111110111110001111"
  1656. "010101010111000011011001000000"
  1657. "110110110001001010100111111001"
  1658. "110010111100101111111111111110"
  1659. "111111000110010110101010000010"
  1660. "011011101000110011011000110100"
  1661. "110110100011111111111111110100"
  1662. "000011011000000010101010010010"
  1663. "111110111010011100100111001001"
  1664. "010101011011100000011101010110"
  1665. "000000000101010000001000000001"
  1666. "101010100100000011011010101000"
  1667. "010101000000000000110001010100"
  1668. "000000100000000000110000000000"
  1669. "101010000000000000000110101000"
  1670. "010101111000000000001101010110"
  1671. "000000101000000000001000000011"
  1672. "101010000000000000001010101010"
  1673. "010101100100000000010101010110"
  1674. "000000101000000000110100000010"
  1675. "101010110100000000001110101011"
  1676. "010101011110000000001001010100"
  1677. "000000000010000101110100000010"
  1678. "101010100111011001110010101000"
  1679. "010101010101010101010010100111"
  1680. "000000000000000000001111100100"
  1681. "101010101010101010100000011011"
  1682. "001001001110011001111101100010"
  1683. "110000110000100111010010101000"
  1684. "110001111010010001001101000010"
  1685. "100110000010010001101011000111"
  1686. "110011010111010010100011101000"
  1687. "111010011111011100110001010110"
  1688. },
  1689. };
  1690. const int data_size = ARRAY_SIZE(data);
  1691. int i, j, seg_count, ret;
  1692. struct zint_symbol *symbol = NULL;
  1693. char escaped[1024];
  1694. char cmp_buf[8192];
  1695. char cmp_msg[1024];
  1696. int do_bwipp = (debug & ZINT_DEBUG_TEST_BWIPP) && testUtilHaveGhostscript(); /* Only do BWIPP test if asked, too slow otherwise */
  1697. int do_zxingcpp = (debug & ZINT_DEBUG_TEST_ZXINGCPP) && testUtilHaveZXingCPPDecoder(); /* Only do ZXing-C++ test if asked, too slow otherwise */
  1698. testStartSymbol("test_encode_segs", &symbol);
  1699. for (i = 0; i < data_size; i++) {
  1700. if (testContinue(p_ctx, i)) continue;
  1701. symbol = ZBarcode_Create();
  1702. assert_nonnull(symbol, "Symbol not created\n");
  1703. testUtilSetSymbol(symbol, BARCODE_MAXICODE, data[i].input_mode, -1 /*eci*/,
  1704. data[i].option_1, data[i].option_2, -1, -1 /*output_options*/, NULL, 0, debug);
  1705. if (data[i].structapp.count) {
  1706. symbol->structapp = data[i].structapp;
  1707. }
  1708. strcpy(symbol->primary, data[i].primary);
  1709. for (j = 0, seg_count = 0; j < 3 && data[i].segs[j].length; j++, seg_count++);
  1710. ret = ZBarcode_Encode_Segs(symbol, data[i].segs, seg_count);
  1711. assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode_Segs ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
  1712. if (p_ctx->generate) {
  1713. char escaped1[4096];
  1714. char escaped2[4096];
  1715. int length = data[i].segs[0].length == -1 ? (int) ustrlen(data[i].segs[0].source) : data[i].segs[0].length;
  1716. int length1 = data[i].segs[1].length == -1 ? (int) ustrlen(data[i].segs[1].source) : data[i].segs[1].length;
  1717. int length2 = data[i].segs[2].length == -1 ? (int) ustrlen(data[i].segs[2].source) : data[i].segs[2].length;
  1718. printf(" /*%3d*/ { %s, %d, %d, { %d, %d, \"%s\" }, { { TU(\"%s\"), %d, %d }, { TU(\"%s\"), %d, %d }, { TU(\"%s\"), %d, %d } }, \"%s\", %s, %d, %d, %d, \"%s\",\n",
  1719. i, testUtilInputModeName(data[i].input_mode), data[i].option_1, data[i].option_2,
  1720. data[i].structapp.index, data[i].structapp.count, data[i].structapp.id,
  1721. testUtilEscape((const char *) data[i].segs[0].source, length, escaped, sizeof(escaped)), data[i].segs[0].length, data[i].segs[0].eci,
  1722. testUtilEscape((const char *) data[i].segs[1].source, length1, escaped1, sizeof(escaped1)), data[i].segs[1].length, data[i].segs[1].eci,
  1723. testUtilEscape((const char *) data[i].segs[2].source, length2, escaped2, sizeof(escaped2)), data[i].segs[2].length, data[i].segs[2].eci,
  1724. data[i].primary, testUtilErrorName(data[i].ret), symbol->rows, symbol->width, data[i].bwipp_cmp, data[i].comment);
  1725. testUtilModulesPrint(symbol, " ", "\n");
  1726. printf(" },\n");
  1727. } else {
  1728. if (ret < ZINT_ERROR) {
  1729. int width, row;
  1730. assert_equal(symbol->rows, data[i].expected_rows, "i:%d symbol->rows %d != %d\n", i, symbol->rows, data[i].expected_rows);
  1731. assert_equal(symbol->width, data[i].expected_width, "i:%d symbol->width %d != %d\n", i, symbol->width, data[i].expected_width);
  1732. ret = testUtilModulesCmp(symbol, data[i].expected, &width, &row);
  1733. assert_zero(ret, "i:%d testUtilModulesCmp ret %d != 0 width %d row %d\n", i, ret, width, row);
  1734. if (do_bwipp && testUtilCanBwipp(i, symbol, data[i].option_1, data[i].option_2, -1, debug)) {
  1735. if (!data[i].bwipp_cmp) {
  1736. if (debug & ZINT_DEBUG_TEST_PRINT) printf("i:%d %s not BWIPP compatible (%s)\n", i, testUtilBarcodeName(symbol->symbology), data[i].comment);
  1737. } else {
  1738. ret = testUtilBwippSegs(i, symbol, data[i].option_1, data[i].option_2, -1, data[i].segs, seg_count, data[i].primary, cmp_buf, sizeof(cmp_buf));
  1739. assert_zero(ret, "i:%d %s testUtilBwippSegs ret %d != 0\n", i, testUtilBarcodeName(symbol->symbology), ret);
  1740. ret = testUtilBwippCmp(symbol, cmp_msg, cmp_buf, data[i].expected);
  1741. assert_zero(ret, "i:%d %s testUtilBwippCmp %d != 0 %s\n actual: %s\nexpected: %s\n",
  1742. i, testUtilBarcodeName(symbol->symbology), ret, cmp_msg, cmp_buf, data[i].expected);
  1743. }
  1744. }
  1745. if (do_zxingcpp && testUtilCanZXingCPP(i, symbol, (const char *) data[i].segs[0].source, data[i].segs[0].length, debug)) {
  1746. if (data[i].input_mode == DATA_MODE) {
  1747. if (debug & ZINT_DEBUG_TEST_PRINT) {
  1748. printf("i:%d multiple segments in DATA_MODE not currently supported for ZXing-C++ testing (%s)\n",
  1749. i, testUtilBarcodeName(symbol->symbology));
  1750. }
  1751. } else {
  1752. int cmp_len, ret_len;
  1753. char modules_dump[17984 + 1];
  1754. assert_notequal(testUtilModulesDump(symbol, modules_dump, sizeof(modules_dump)), -1, "i:%d testUtilModulesDump == -1\n", i);
  1755. ret = testUtilZXingCPP(i, symbol, (const char *) data[i].segs[0].source, data[i].segs[0].length,
  1756. modules_dump, cmp_buf, sizeof(cmp_buf), &cmp_len);
  1757. assert_zero(ret, "i:%d %s testUtilZXingCPP ret %d != 0\n", i, testUtilBarcodeName(symbol->symbology), ret);
  1758. ret = testUtilZXingCPPCmpSegs(symbol, cmp_msg, cmp_buf, cmp_len, data[i].segs, seg_count,
  1759. data[i].primary, escaped, &ret_len);
  1760. assert_zero(ret, "i:%d %s testUtilZXingCPPCmpSegs %d != 0 %s\n actual: %.*s\nexpected: %.*s\n",
  1761. i, testUtilBarcodeName(symbol->symbology), ret, cmp_msg, cmp_len, cmp_buf, ret_len, escaped);
  1762. }
  1763. }
  1764. }
  1765. }
  1766. ZBarcode_Delete(symbol);
  1767. }
  1768. testFinish();
  1769. }
  1770. /* #181 Nico Gunkel OSS-Fuzz */
  1771. static void test_fuzz(const testCtx *const p_ctx) {
  1772. int debug = p_ctx->debug;
  1773. struct item {
  1774. int eci;
  1775. char *data;
  1776. int length;
  1777. int ret;
  1778. };
  1779. /* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */
  1780. static const struct item data[] = {
  1781. /* 0*/ { -1, "\223\223\223\223\223\200\000\060\060\020\122\104\060\343\000\000\040\104\104\104\104\177\377\040\000\324\336\000\000\000\000\104\060\060\060\060\104\104\104\104\104\104\104\104\104\104\104\104\104\104\104\104\104\104\104\104\104\104\104\104\104\104\104\060\104\104\000\000\000\040\104\104\104\104\177\377\377\377\324\336\000\000\000\000\104\377\104\001\104\104\104\104\104\104\233\233\060\060\060\060\060\060\060\060\060\325\074", 107, ZINT_ERROR_TOO_LONG }, /* Original OSS-Fuzz triggering data */
  1782. /* 1*/ { -1, "AaAaAaAaAaAaAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA123456789", -1, ZINT_ERROR_TOO_LONG }, /* Add 6 lowercase a's so 6 SHIFTS inserted so 6 + 138 (max input len) = 144 and numbers come at end of buffer */
  1783. /* 2*/ { -1, "AaAaAaAaAaAaAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA123456789A", -1, ZINT_ERROR_TOO_LONG },
  1784. /* 3*/ { -1, "1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789", -1, ZINT_ERROR_TOO_LONG },
  1785. /* 4*/ { 32768, "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678", -1, ZINT_ERROR_TOO_LONG },
  1786. /* 5*/ { -1, "AaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAa", -1, ZINT_ERROR_TOO_LONG },
  1787. };
  1788. const int data_size = ARRAY_SIZE(data);
  1789. int i, length, ret;
  1790. struct zint_symbol *symbol = NULL;
  1791. testStartSymbol("test_fuzz", &symbol);
  1792. for (i = 0; i < data_size; i++) {
  1793. if (testContinue(p_ctx, i)) continue;
  1794. symbol = ZBarcode_Create();
  1795. assert_nonnull(symbol, "Symbol not created\n");
  1796. length = testUtilSetSymbol(symbol, BARCODE_MAXICODE, -1 /*input_mode*/, data[i].eci, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data[i].data, data[i].length, debug);
  1797. ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length);
  1798. assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
  1799. ZBarcode_Delete(symbol);
  1800. }
  1801. testFinish();
  1802. }
  1803. #include <time.h>
  1804. #define TEST_PERF_ITER_MILLES 10
  1805. #define TEST_PERF_ITERATIONS (TEST_PERF_ITER_MILLES * 1000)
  1806. #define TEST_PERF_TIME(arg) (((arg) * 1000.0) / CLOCKS_PER_SEC)
  1807. /* Not a real test, just performance indicator */
  1808. static void test_perf(const testCtx *const p_ctx) {
  1809. int debug = p_ctx->debug;
  1810. struct item {
  1811. int symbology;
  1812. int input_mode;
  1813. int option_1;
  1814. int option_2;
  1815. char *data;
  1816. char *primary;
  1817. int ret;
  1818. int expected_rows;
  1819. int expected_width;
  1820. char *comment;
  1821. };
  1822. static const struct item data[] = {
  1823. /* 0*/ { BARCODE_MAXICODE, UNICODE_MODE | ESCAPE_MODE, -1, -1,
  1824. "1Z34567890\\GUPSN\\G102562\\G034\\G\\G1/1\\G\\GY\\G2201 Second St\\GFt Myers\\GFL\\R\\E",
  1825. "339010000840001", 0, 33, 30, "Mode 2" },
  1826. /* 1*/ { BARCODE_MAXICODE, UNICODE_MODE, 4, -1, "MaxiCode (19 chars)", "", 0, 33, 30, "Mode 4 small" },
  1827. /* 2*/ { BARCODE_MAXICODE, DATA_MODE | ESCAPE_MODE, 4, -1, "ABCDabcdAabcABabcABCabcABCDaABCabABCabcABC\\d233a", "", 0, 33, 30, "Mode 4 medium" },
  1828. /* 3*/ { BARCODE_MAXICODE, DATA_MODE | ESCAPE_MODE, 4, -1,
  1829. "ABabcdeAabcdABCabcdABabc\\d192\\d192 \\d192\\d224\\d224\\d028\\d224\\d001\\d001\\d001\\d029\\d00112345678a123456789aABCDa\\d192\\d224\\d001\\d192\\d001\\d224\\d030\\d004",
  1830. "", 0, 33, 30, "Mode 4 latches" },
  1831. /* 4*/ { BARCODE_MAXICODE, UNICODE_MODE, 4, -1,
  1832. "THIS IS A 93 CHARACTER CODE SET A MESSAGE THAT FILLS A MODE 4, UNAPPENDED, MAXICODE SYMBOL...", "", 0, 33, 30, "Mode 4 txt max" },
  1833. /* 5*/ { BARCODE_MAXICODE, UNICODE_MODE, 4, -1,
  1834. "999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999",
  1835. "", 0, 33, 30, "Mode 4 num max" },
  1836. };
  1837. const int data_size = ARRAY_SIZE(data);
  1838. int i, length, ret;
  1839. struct zint_symbol *symbol;
  1840. clock_t start;
  1841. clock_t total_create = 0, total_encode = 0, total_buffer = 0;
  1842. clock_t diff_create, diff_encode, diff_buffer;
  1843. int comment_max = 0;
  1844. if (!(debug & ZINT_DEBUG_TEST_PERFORMANCE)) { /* -d 256 */
  1845. return;
  1846. }
  1847. for (i = 0; i < data_size; i++) if ((int) strlen(data[i].comment) > comment_max) comment_max = (int) strlen(data[i].comment);
  1848. printf("Iterations %d\n", TEST_PERF_ITERATIONS);
  1849. for (i = 0; i < data_size; i++) {
  1850. int j;
  1851. if (testContinue(p_ctx, i)) continue;
  1852. diff_create = diff_encode = diff_buffer = 0;
  1853. for (j = 0; j < TEST_PERF_ITERATIONS; j++) {
  1854. start = clock();
  1855. symbol = ZBarcode_Create();
  1856. diff_create += clock() - start;
  1857. assert_nonnull(symbol, "Symbol not created\n");
  1858. length = testUtilSetSymbol(symbol, data[i].symbology, data[i].input_mode, -1 /*eci*/, data[i].option_1, data[i].option_2, -1, -1 /*output_options*/, data[i].data, -1, debug);
  1859. strcpy(symbol->primary, data[i].primary);
  1860. start = clock();
  1861. ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length);
  1862. diff_encode += clock() - start;
  1863. assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
  1864. assert_equal(symbol->rows, data[i].expected_rows, "i:%d symbol->rows %d != %d (%s)\n", i, symbol->rows, data[i].expected_rows, data[i].data);
  1865. assert_equal(symbol->width, data[i].expected_width, "i:%d symbol->width %d != %d (%s)\n", i, symbol->width, data[i].expected_width, data[i].data);
  1866. #if 0
  1867. start = clock();
  1868. ret = ZBarcode_Buffer(symbol, 0 /*rotate_angle*/);
  1869. diff_buffer += clock() - start;
  1870. assert_zero(ret, "i:%d ZBarcode_Buffer ret %d != 0 (%s)\n", i, ret, symbol->errtxt);
  1871. #endif
  1872. ZBarcode_Delete(symbol);
  1873. }
  1874. printf("%*s: encode % 8gms, buffer % 8gms, create % 8gms\n", comment_max, data[i].comment,
  1875. TEST_PERF_TIME(diff_encode), TEST_PERF_TIME(diff_buffer), TEST_PERF_TIME(diff_create));
  1876. total_create += diff_create;
  1877. total_encode += diff_encode;
  1878. total_buffer += diff_buffer;
  1879. }
  1880. if (p_ctx->index == -1) {
  1881. printf("%*s: encode % 8gms, buffer % 8gms, create % 8gms\n", comment_max, "totals",
  1882. TEST_PERF_TIME(total_encode), TEST_PERF_TIME(total_buffer), TEST_PERF_TIME(total_create));
  1883. }
  1884. }
  1885. int main(int argc, char *argv[]) {
  1886. testFunction funcs[] = { /* name, func */
  1887. { "test_large", test_large },
  1888. { "test_input", test_input },
  1889. { "test_encode", test_encode },
  1890. { "test_encode_segs", test_encode_segs },
  1891. { "test_fuzz", test_fuzz },
  1892. { "test_perf", test_perf },
  1893. };
  1894. testRun(argc, argv, funcs, ARRAY_SIZE(funcs));
  1895. testReport();
  1896. return 0;
  1897. }
  1898. /* vim: set ts=4 sw=4 et : */