test_dotcode.c 102 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775
  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_2;
  33. char datum;
  34. int length;
  35. int ret;
  36. char *expected_errtxt;
  37. };
  38. /* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */
  39. static const struct item data[] = {
  40. /* 0*/ { 200, '0', 2940, 0, "" }, /* 2940 largest Code Set C data that fits in 200x199 HxW */
  41. /* 1*/ { 200, '0', 2941, ZINT_ERROR_INVALID_OPTION, "Error 528: Symbol height '201' is too large" },
  42. /* 2*/ { 200, '9', 200, 0, "" }, /* Changes a number of mask scores re pre-Rev. 4 version, but best score still the same (7) */
  43. /* 3*/ { 201, '0', 2940, ZINT_ERROR_INVALID_OPTION, "Error 528: Symbol width '201' is too large" },
  44. /* 4*/ { 201, '0', 2974, ZINT_ERROR_INVALID_OPTION, "Error 526: Symbol size '201x202' (WxH) is too large" }, /* Height > 200 also */
  45. /* 5*/ { 30, '\001', 71, 0, "" }, /* Codeword length 72, ECC length 39, for ND + 1 == 112 */
  46. };
  47. const int data_size = ARRAY_SIZE(data);
  48. int i, length, ret;
  49. struct zint_symbol *symbol = NULL;
  50. char data_buf[4096];
  51. testStartSymbol("test_large", &symbol);
  52. for (i = 0; i < data_size; i++) {
  53. if (testContinue(p_ctx, i)) continue;
  54. symbol = ZBarcode_Create();
  55. assert_nonnull(symbol, "Symbol not created\n");
  56. memset(data_buf, data[i].datum, data[i].length);
  57. length = testUtilSetSymbol(symbol, BARCODE_DOTCODE, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, data[i].option_2, -1, -1 /*output_options*/, data_buf, data[i].length, debug);
  58. ret = ZBarcode_Encode(symbol, (unsigned char *) data_buf, length);
  59. assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
  60. assert_zero(strcmp(symbol->errtxt, data[i].expected_errtxt), "i:%d strcmp(%s, %s) != 0\n", i, symbol->errtxt, data[i].expected_errtxt);
  61. ZBarcode_Delete(symbol);
  62. }
  63. testFinish();
  64. }
  65. static void test_options(const testCtx *const p_ctx) {
  66. int debug = p_ctx->debug;
  67. struct item {
  68. int input_mode;
  69. int eci;
  70. int output_options;
  71. int option_2;
  72. int option_3;
  73. struct zint_structapp structapp;
  74. char *data;
  75. int ret;
  76. int expected_rows;
  77. int expected_width;
  78. const char *expected_errtxt;
  79. };
  80. /* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */
  81. static const struct item data[] = {
  82. /* 0*/ { -1, -1, -1, -1, -1, { 0, 0, "" }, "1", 0, 9, 14, "" },
  83. /* 1*/ { -1, -1, -1, -1, -1, { 0, 0, "" }, "1234567890", 0, 12, 19, "" },
  84. /* 2*/ { -1, -1, -1, 19, -1, { 0, 0, "" }, "1234567890", 0, 12, 19, "" },
  85. /* 3*/ { -1, -1, -1, 12, -1, { 0, 0, "" }, "1234567890", 0, 19, 12, "" },
  86. /* 4*/ { -1, -1, -1, 5, -1, { 0, 0, "" }, "1234567890", 0, 44, 5, "" },
  87. /* 5*/ { -1, -1, -1, 4, -1, { 0, 0, "" }, "1234567890", ZINT_ERROR_INVALID_OPTION, -1, -1, "Error 529: Symbol width '4' is too small" }, /* Cols < 5 */
  88. /* 6*/ { -1, -1, -1, 200, -1, { 0, 0, "" }, "1234567890", ZINT_ERROR_INVALID_OPTION, -1, -1, "Error 529: Symbol height '3' is too small" }, /* Not enough data - height 3 too small */
  89. /* 7*/ { -1, -1, -1, 200, -1, { 0, 0, "" }, "1234567890123456789012345678901234567890", 0, 5, 200, "" }, /* Cols 200 max */
  90. /* 8*/ { -1, -1, -1, 200, -1, { 0, 0, "" }, "12345678901234567890123456789012345678901234567890123456789012345678901234567890", 0, 7, 200, "" },
  91. /* 9*/ { -1, -1, -1, 201, -1, { 0, 0, "" }, "12345678901234567890123456789012345678901234567890123456789012345678901234567890", ZINT_ERROR_INVALID_OPTION, -1, -1, "Error 528: Symbol width '201' is too large" },
  92. /* 10*/ { -1, -1, -1, -1, 10 << 8, { 0, 0, "" }, "1", 0, 9, 14, "" }, /* Mask > 8 + 1 ignored */
  93. /* 11*/ { -1, -1, -1, 19, -1, { 0, 0, "" }, "ABCDE", 0, 12, 19, "" },
  94. /* 12*/ { -1, -1, -1, 19, -1, { 35, 35, "" }, "ABCDE", 0, 16, 19, "" },
  95. /* 13*/ { -1, -1, -1, 19, -1, { 1, 1, "" }, "ABCDE", ZINT_ERROR_INVALID_OPTION, -1, -1, "Error 730: Structured Append count '1' out of range (2 to 35)" },
  96. /* 14*/ { -1, -1, -1, 19, -1, { 1, 36, "" }, "ABCDE", ZINT_ERROR_INVALID_OPTION, -1, -1, "Error 730: Structured Append count '36' out of range (2 to 35)" },
  97. /* 15*/ { -1, -1, -1, 19, -1, { 3, 2, "" }, "ABCDE", ZINT_ERROR_INVALID_OPTION, -1, -1, "Error 731: Structured Append index '3' out of range (1 to count 2)" },
  98. /* 16*/ { -1, -1, -1, 19, -1, { 1, 2, "1" }, "ABCDE", ZINT_ERROR_INVALID_OPTION, -1, -1, "Error 732: Structured Append ID not available for DotCode" },
  99. /* 17*/ { GS1_MODE, 3, -1, -1, -1, { 0, 0, "" }, "[20]01", ZINT_WARN_NONCOMPLIANT, 11, 16, "Warning 733: Using ECI in GS1 mode not supported by GS1 standards" },
  100. /* 18*/ { GS1_MODE, -1, -1, -1, -1, { 1, 2, "" }, "[20]01", ZINT_WARN_NONCOMPLIANT, 12, 19, "Warning 734: Using Structured Append in GS1 mode not supported by GS1 standards" },
  101. /* 19*/ { GS1_MODE, 3, -1, -1, -1, { 1, 2, "" }, "[20]01", ZINT_WARN_NONCOMPLIANT, 14, 21, "Warning 733: Using ECI in GS1 mode not supported by GS1 standards" }, /* ECI trumps Structured Append */
  102. };
  103. const int data_size = ARRAY_SIZE(data);
  104. int i, length, ret;
  105. struct zint_symbol *symbol = NULL;
  106. testStartSymbol("test_options", &symbol);
  107. for (i = 0; i < data_size; i++) {
  108. if (testContinue(p_ctx, i)) continue;
  109. symbol = ZBarcode_Create();
  110. assert_nonnull(symbol, "Symbol not created\n");
  111. length = testUtilSetSymbol(symbol, BARCODE_DOTCODE, data[i].input_mode, data[i].eci, -1 /*option_1*/, data[i].option_2, data[i].option_3, data[i].output_options, data[i].data, -1, debug);
  112. if (data[i].structapp.count) {
  113. symbol->structapp = data[i].structapp;
  114. }
  115. ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length);
  116. assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
  117. if (ret < ZINT_ERROR) {
  118. assert_equal(symbol->rows, data[i].expected_rows, "i:%d symbol->rows %d != %d (%s)\n", i, symbol->rows, data[i].expected_rows, symbol->errtxt);
  119. assert_equal(symbol->width, data[i].expected_width, "i:%d symbol->width %d != %d (%s)\n", i, symbol->width, data[i].expected_width, symbol->errtxt);
  120. }
  121. assert_zero(strcmp(symbol->errtxt, data[i].expected_errtxt), "i:%d strcmp(%s, %s) != 0\n", i, symbol->errtxt, data[i].expected_errtxt);
  122. ZBarcode_Delete(symbol);
  123. }
  124. testFinish();
  125. }
  126. static void test_input(const testCtx *const p_ctx) {
  127. int debug = p_ctx->debug;
  128. struct item {
  129. int input_mode;
  130. int eci;
  131. int option_2;
  132. int option_3;
  133. struct zint_structapp structapp;
  134. char *data;
  135. int length;
  136. int ret;
  137. char *expected;
  138. int bwipp_cmp;
  139. char *comment;
  140. };
  141. static const struct item data[] = {
  142. /* 0*/ { UNICODE_MODE, -1, 13, -1, { 0, 0, "" }, "A", -1, 0, "66 21 6A", 1, "" },
  143. /* 1*/ { UNICODE_MODE, 3, -1, -1, { 0, 0, "" }, "A", -1, 0, "6C 03 66 21", 1, "" },
  144. /* 2*/ { UNICODE_MODE, 40, 18, -1, { 0, 0, "" }, "A", -1, 0, "6C 28 00 00 66 21", 1, "" },
  145. /* 3*/ { UNICODE_MODE, 113, 18, -1, { 0, 0, "" }, "A", -1, 0, "6C 28 00 49 66 21", 1, "" },
  146. /* 4*/ { UNICODE_MODE, 899, 18, -1, { 0, 0, "" }, "A", -1, 0, "6C 28 07 44 66 21", 1, "" },
  147. /* 5*/ { UNICODE_MODE, 12769, 18, 8 << 8, { 0, 0, "" }, "A", -1, 0, "6C 28 70 49 66 21", 1, "" },
  148. /* 6*/ { UNICODE_MODE, 811799, 18, -1, { 0, 0, "" }, "A", -1, 0, "6C 67 40 50 66 21", 1, "" },
  149. /* 7*/ { UNICODE_MODE, 811800, -1, -1, { 0, 0, "" }, "A", -1, ZINT_ERROR_INVALID_OPTION, "Error 525: ECI code '811800' out of range (0 to 811799)", 1, "" },
  150. /* 8*/ { UNICODE_MODE, -1, 13, -1, { 0, 0, "" }, "\000", 1, 0, "65 40 6A", 1, "LatchA (0x65) NUL PAD" },
  151. /* 9*/ { UNICODE_MODE, -1, 13, -1, { 0, 0, "" }, "\010", -1, 0, "65 48 6A", 1, "LatchA (0x65) BS PAD" },
  152. /* 10*/ { UNICODE_MODE, -1, 13, -1, { 0, 0, "" }, "\011", -1, 0, "65 49 6A", 1, "Lead special; LatchA (0x65) HT PAD" },
  153. /* 11*/ { UNICODE_MODE, -1, 13, -1, { 0, 0, "" }, "\034", -1, 0, "65 5C 6A", 1, "Lead special; LatchA (0x65) FS PAD" },
  154. /* 12*/ { UNICODE_MODE, -1, 13, -1, { 0, 0, "" }, "\035", -1, 0, "65 5D 6A", 1, "Lead special; LatchA (0x65) GS PAD" },
  155. /* 13*/ { UNICODE_MODE, -1, 13, -1, { 0, 0, "" }, "\036", -1, 0, "65 5E 6A", 1, "Lead special; LatchA (0x65) RS PAD" },
  156. /* 14*/ { UNICODE_MODE, -1, 13, -1, { 0, 0, "" }, "\037", -1, 0, "65 5F 6A", 1, "LatchA (0x65) US PAD" },
  157. /* 15*/ { UNICODE_MODE, -1, 13, -1, { 0, 0, "" }, "\177", -1, 0, "66 5F 6A", 1, "ShiftB (0x66) DEL PAD" },
  158. /* 16*/ { UNICODE_MODE, -1, -1, -1, { 0, 0, "" }, "[)>\03605\035A\036\004", -1, 0, "6A 61 21", 1, "[)>RS 05 GS A RS EOT; LatchB (0x6A) Macro97 (0x61) A" },
  159. /* 17*/ { UNICODE_MODE, -1, 17, -1, { 0, 0, "" }, "[)>\03606\035\011\034\035\036\036\004", -1, 0, "6A 62 61 62 63 64 6A", 1, "[)>RS 06 GS HT FS GS RS RS EOT; LatchB (0x6A) Macro98 (0x62) HT FS GS RS PAD" },
  160. /* 18*/ { UNICODE_MODE, -1, 17, -1, { 0, 0, "" }, "[)>\03612\03512345\036\004", -1, 0, "6A 63 11 67 17 2D 6A", 1, "[)>RS 12 GS A RS EOT; LatchB (0x6A) Macro99 (0x63) 1 2xShiftC (0x67) 23 45 PAD" },
  161. /* 19*/ { UNICODE_MODE, -1, -1, -1, { 0, 0, "" }, "[)>\03601Blah\004", -1, 0, "6A 64 10 11 22 4C 41 48 6A", 1, "[)>RS 01 Blah EOT; LatchB (0x6A) Macro100 (0x64) 0 1 B l a h PAD" },
  162. /* 20*/ { UNICODE_MODE, -1, 22, -1, { 0, 0, "" }, "[)>\03605\035A\004", -1, 0, "65 3B 09 1E 5E 10 15 5D 21 44", 1, "NOTE: no longer using Macro for malformed 05/06/12" },
  163. /* 21*/ { UNICODE_MODE, -1, -1, -1, { 0, 0, "" }, "[)>\03606A\004", -1, 0, "65 3B 09 1E 5E 10 16 21 44", 1, "NOTE: no longer using Macro for malformed 05/06/12" },
  164. /* 22*/ { UNICODE_MODE, -1, 13, -1, { 0, 0, "" }, "[)>\036991\036\004", -1, 0, "6A 64 19 19 11 64", 1, "[)>RS 99 1 RS EOT; LatchB (0x6A) Macro100 (0x64) 9 9 1 RS" },
  165. /* 23*/ { UNICODE_MODE, -1, -1, -1, { 0, 0, "" }, "1712345610", -1, 0, "6B 64 0C 22 38", 1, "FNC1 (0x6B) 17..10 12 34 56" },
  166. /* 24*/ { GS1_MODE, -1, -1, -1, { 0, 0, "" }, "[17]123456[10]123", -1, ZINT_WARN_NONCOMPLIANT, "64 0C 22 38 0C 66 13", 0, "17..10 12 34 56 12 ShiftB (0x66) 3; BWIPP does not allow bad month" },
  167. /* 25*/ { GS1_MODE, -1, -1, -1, { 0, 0, "" }, "[90]ABC[90]abc[90]123", -1, 0, "5A 6A 21 22 23 6B 19 10 41 42 43 6B 19 67 01 17 6A", 1, "90 LatchB (0x6A) A B C FNC1 (0x6B) 9 0 a b c FNC1 (0x6B) 9 2xShitfC (0x67) 01 23 PAD" },
  168. /* 26*/ { GS1_MODE | GS1PARENS_MODE, -1, -1, -1, { 0, 0, "" }, "(90)ABC(90)abc(90)123", -1, 0, "5A 6A 21 22 23 6B 19 10 41 42 43 6B 19 67 01 17 6A", 1, "90 LatchB (0x6A) A B C FNC1 (0x6B) 9 0 a b c FNC1 (0x6B) 9 2xShitfC (0x67) 01 23 PAD" },
  169. /* 27*/ { UNICODE_MODE, -1, -1, -1, { 0, 0, "" }, "99aA[{00\000", 9, 0, "6B 63 6A 41 21 3B 5B 10 10 65 40", 1, "FNC1 (0x6B) 99 LatchB (0x6A) a A [ { 0 0 ShiftA (0x65) NUL" },
  170. /* 28*/ { UNICODE_MODE, -1, -1, -1, { 0, 0, "" }, "\015\012", -1, 0, "66 60", 0, "ShiftB (0x66) CR/LF; BWIPP different encodation" },
  171. /* 29*/ { UNICODE_MODE, -1, -1, -1, { 0, 0, "" }, "A\015\012", -1, 0, "67 21 60", 0, "2xShiftB (0x67) A CR/LF; BWIPP different encodation" },
  172. /* 30*/ { UNICODE_MODE, -1, -1, -1, { 0, 0, "" }, "\015\015\012", -1, 0, "65 4D 4D 4A", 1, "LatchA (0x65) CR CR LF" },
  173. /* 31*/ { UNICODE_MODE, -1, -1, -1, { 0, 0, "" }, "ABCDE12345678", -1, 0, "6A 21 22 23 24 25 69 0C 22 38 4E", 1, "LatchB (0x6A) A B C D 4xShiftC 12 34 56 78" },
  174. /* 32*/ { UNICODE_MODE, -1, -1, -1, { 0, 0, "" }, "\000ABCD1234567890", 15, 0, "65 40 21 22 23 24 6A 0C 22 38 4E 5A 6A", 1, "LatchA (0x65) NULL A B C D LatchC (0x6A) 12 34 56 78 90 PAD" },
  175. /* 33*/ { DATA_MODE, -1, -1, 2 << 8, { 0, 0, "" }, "\141\142\143\144\145\200\201\202\203\204\377", -1, 0, "6A 41 42 43 44 45 70 31 5A 35 21 5A 5F 02 31", 1, "LatchB (0x6A) a b c d e BinaryLatch (0x70) 0x80 0x81 0x82 0x83 0x84 0xFF" },
  176. /* 34*/ { DATA_MODE, -1, -1, -1, { 0, 0, "" }, "\200\061\062\240\063\064\201\202\065\066", -1, 0, "6E 40 0C 6F 00 22 70 03 10 42 6E 15 16", 1, "UpperShiftA (0x6E) NUL 12 UpperShiftB (0x6F) SP 34 BinaryLatch (0x70) 0x81 0x82 TermB (0x6E) 5 6" },
  177. /* 35*/ { DATA_MODE, -1, -1, -1, { 0, 0, "" }, "\200\201\202\203\061\062\063\064", -1, 0, "70 13 56 0A 59 2C 67 0C 22", 1, "BinaryLatch (0x70) 0x80 0x81 0x82 0x83 Intr2xShiftC (0x67) 12 3" },
  178. /* 36*/ { DATA_MODE, -1, -1, -1, { 0, 0, "" }, "\001\200\201\202\203\204\200\201\202\203\204", -1, 0, "65 41 70 31 5A 35 21 5A 5F 31 5A 35 21 5A 5F", 1, "LatchA (0x65) SOH BinaryLatch (0x70) 0x80 0x81 0x82 0x83 0x80 0x81 0x82 0x83" },
  179. /* 37*/ { UNICODE_MODE, -1, -1, -1, { 0, 0, "" }, "\001abc\011\015\012\036", -1, 0, "65 41 65 41 42 43 61 60 64", 1, "LatchA (0x65) SOH 6xShiftB (0x65) a b c HT CR/LF RS" },
  180. /* 38*/ { UNICODE_MODE, -1, -1, -1, { 35, 35, "" }, "ABCDE", -1, 0, "6A 21 22 23 24 25 3A 3A 6C", 1, "LatchB (0x6A) A B C D E Z Z FNC2" },
  181. /* 39*/ { UNICODE_MODE, -1, -1, -1, { 9, 10, "" }, "1234567890", -1, 0, "6B 0C 22 38 4E 5A 65 19 21 6C", 1, "FNC1 (0x6B) 12 34 56 78 90 LatchA (0x65) 9 A FNC2" },
  182. /* 40*/ { UNICODE_MODE, -1, -1, -1, { 2, 3, "" }, "\001\002\003\004", -1, 0, "65 41 42 43 44 6A 12 13 6C", 1, "LatchA (0x65) <SOH> <STX> <ETX> <EOT> PAD 2 3 FNC2" },
  183. /* 41*/ { DATA_MODE, -1, -1, -1, { 1, 34, "" }, "\200\201\202\203", -1, 0, "70 13 56 0A 59 2C 6D 11 39 6C", 1, "BinaryLatch (0x70) (...) TermA (0x6D) 1 Y FNC2" },
  184. };
  185. const int data_size = ARRAY_SIZE(data);
  186. int i, length, ret;
  187. struct zint_symbol *symbol = NULL;
  188. char escaped[1024];
  189. char cmp_buf[32768];
  190. char cmp_msg[1024];
  191. int do_bwipp = (debug & ZINT_DEBUG_TEST_BWIPP) && testUtilHaveGhostscript(); /* Only do BWIPP test if asked, too slow otherwise */
  192. int do_zxingcpp = (debug & ZINT_DEBUG_TEST_ZXINGCPP) && testUtilHaveZXingCPPDecoder(); /* Only do ZXing-C++ test if asked, too slow otherwise */
  193. testStartSymbol("test_input", &symbol);
  194. for (i = 0; i < data_size; i++) {
  195. if (testContinue(p_ctx, i)) continue;
  196. symbol = ZBarcode_Create();
  197. assert_nonnull(symbol, "Symbol not created\n");
  198. debug |= ZINT_DEBUG_TEST; /* Needed to get codeword dump in errtxt */
  199. length = testUtilSetSymbol(symbol, BARCODE_DOTCODE, data[i].input_mode, data[i].eci,
  200. -1 /*option_1*/, data[i].option_2, data[i].option_3, -1 /*output_options*/,
  201. data[i].data, data[i].length, debug);
  202. if (data[i].structapp.count) {
  203. symbol->structapp = data[i].structapp;
  204. }
  205. ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length);
  206. assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
  207. if (p_ctx->generate) {
  208. printf(" /*%3d*/ { %s, %d, %d, %d, { %d, %d, \"%s\" }, \"%s\", %d, %s, \"%s\", %d, \"%s\" },\n",
  209. i, testUtilInputModeName(data[i].input_mode), data[i].eci, data[i].option_2, data[i].option_3,
  210. data[i].structapp.index, data[i].structapp.count, data[i].structapp.id,
  211. testUtilEscape(data[i].data, length, escaped, sizeof(escaped)),
  212. data[i].length, testUtilErrorName(data[i].ret), symbol->errtxt, data[i].bwipp_cmp, data[i].comment);
  213. } else {
  214. assert_zero(strcmp((char *) symbol->errtxt, data[i].expected), "i:%d strcmp(%s, %s) != 0\n", i, symbol->errtxt, data[i].expected);
  215. if (ret < ZINT_ERROR) {
  216. if (do_bwipp && testUtilCanBwipp(i, symbol, -1, data[i].option_2, data[i].option_3, debug)) {
  217. if (!data[i].bwipp_cmp) {
  218. if (debug & ZINT_DEBUG_TEST_PRINT) printf("i:%d %s not BWIPP compatible (%s)\n", i, testUtilBarcodeName(symbol->symbology), data[i].comment);
  219. } else {
  220. char modules_dump[200 * 200 + 1];
  221. assert_notequal(testUtilModulesDump(symbol, modules_dump, sizeof(modules_dump)), -1, "i:%d testUtilModulesDump == -1\n", i);
  222. ret = testUtilBwipp(i, symbol, -1, data[i].option_2, data[i].option_3, data[i].data, length, NULL, cmp_buf, sizeof(cmp_buf), NULL);
  223. assert_zero(ret, "i:%d %s testUtilBwipp ret %d != 0\n", i, testUtilBarcodeName(symbol->symbology), ret);
  224. ret = testUtilBwippCmp(symbol, cmp_msg, cmp_buf, modules_dump);
  225. assert_zero(ret, "i:%d %s testUtilBwippCmp %d != 0 %s\n actual: %s\nexpected: %s\n",
  226. i, testUtilBarcodeName(symbol->symbology), ret, cmp_msg, cmp_buf, modules_dump);
  227. }
  228. }
  229. if (do_zxingcpp && testUtilCanZXingCPP(i, symbol, data[i].data, length, debug)) {
  230. int cmp_len, ret_len;
  231. char modules_dump[200 * 200 + 1];
  232. assert_notequal(testUtilModulesDump(symbol, modules_dump, sizeof(modules_dump)), -1, "i:%d testUtilModulesDump == -1\n", i);
  233. ret = testUtilZXingCPP(i, symbol, data[i].data, length, modules_dump, cmp_buf, sizeof(cmp_buf), &cmp_len);
  234. assert_zero(ret, "i:%d %s testUtilZXingCPP ret %d != 0\n", i, testUtilBarcodeName(symbol->symbology), ret);
  235. ret = testUtilZXingCPPCmp(symbol, cmp_msg, cmp_buf, cmp_len, data[i].data, length, NULL /*primary*/, escaped, &ret_len);
  236. assert_zero(ret, "i:%d %s testUtilZXingCPPCmp %d != 0 %s\n actual: %.*s\nexpected: %.*s\n",
  237. i, testUtilBarcodeName(symbol->symbology), ret, cmp_msg, cmp_len, cmp_buf, ret_len, escaped);
  238. }
  239. }
  240. }
  241. ZBarcode_Delete(symbol);
  242. }
  243. testFinish();
  244. }
  245. static void test_encode(const testCtx *const p_ctx) {
  246. int debug = p_ctx->debug;
  247. struct item {
  248. int input_mode;
  249. int option_2;
  250. int option_3;
  251. struct zint_structapp structapp;
  252. char *data;
  253. int length;
  254. int ret;
  255. int expected_rows;
  256. int expected_width;
  257. int bwipp_cmp;
  258. int zxingcpp_cmp;
  259. char *comment;
  260. char *expected;
  261. };
  262. /* ISS DotCode, Rev 4.0, DRAFT 0.15, TSC Pre-PR #5, MAY 28, 2019 */
  263. static const struct item data[] = {
  264. /* 0*/ { GS1_MODE, 64, -1, { 0, 0, "" }, "[01]00012345678905[17]201231[10]ABC123456", -1, 0, 9, 64, 1, 1, "ISS DotCode Rev 4.0 Figure 1 (left), same",
  265. "1010000000101000101010000010000010001010100010101000101000001010"
  266. "0100010001010001010001000001010100010100010001000100010101000001"
  267. "1010001010000000101010100010001010000010101000000010100010100000"
  268. "0000000101000101010001010100000001000100010001000100010100000001"
  269. "1000001000000010100010101000001010100000101010100000100010001010"
  270. "0101000101000001000001010001010100000001000100010101000101010001"
  271. "1000000010100010001000001000100010101000100010000010101000100000"
  272. "0001010100010001010100010001010000010001010000000101010001010101"
  273. "1000100010001000100010100010001010001000101000101000100010000010"
  274. },
  275. /* 1*/ { GS1_MODE, -1, -1, { 0, 0, "" }, "[01]00012345678905[17]201231[10]ABC123456", -1, 0, 20, 29, 1, 1, "ISS DotCode Rev 4.0 Figure 1 (right) (and Figure 10), same",
  276. "10101000101010100010101000101"
  277. "00010100010100010100000001010"
  278. "00001010100010000000101010000"
  279. "01000001010101010101010101000"
  280. "10101010100000000010100010101"
  281. "01000100000000000101010101010"
  282. "00100010001010101000100000101"
  283. "00000101010000000001010000010"
  284. "10001010100010101010001010100"
  285. "01010000000000010000000100010"
  286. "00100000000010100000100000000"
  287. "00010000000101000001000001000"
  288. "10101000101000001010001010001"
  289. "01010001010001010101000000010"
  290. "00001000001010001010100000101"
  291. "01000100010100000000010100010"
  292. "10100010000010101000101010001"
  293. "00010101000001010100010100010"
  294. "10000010101000100000001000001"
  295. "01000100010101010000000101010"
  296. },
  297. /* 2*/ { GS1_MODE, -1, 1 << 8, { 0, 0, "" }, "[17]070620[10]ABC123456", -1, 0, 16, 23, 1, 1, "ISS DotCode Rev 4.0 Figure 5 (and Figure 6 top-left) when Mask = 0, same",
  298. "10101000100010000000001"
  299. "01000101010001010000000"
  300. "00100010001000101000100"
  301. "01010001010000000101010"
  302. "00001000100010100010101"
  303. "00000101010101010000010"
  304. "00100010101000000010001"
  305. "00010100000101000100010"
  306. "00001000001000001010101"
  307. "01010101010001000001010"
  308. "10100000100010001000101"
  309. "01000100000100010101000"
  310. "10000010000010100010001"
  311. "00010000010100010101010"
  312. "10101000001000101010001"
  313. "01000001010101010000010"
  314. },
  315. /* 3*/ { GS1_MODE, -1, 2 << 8, { 0, 0, "" }, "[17]070620[10]ABC123456", -1, 0, 16, 23, 1, 1, "ISS DotCode Rev 4.0 Figure 6 top-right Mask = 1, same",
  316. "10000000001010001000101"
  317. "01010101000100000101000"
  318. "00100010000000100000001"
  319. "01010001000001000001000"
  320. "10101010100000001010101"
  321. "00000100010100000100010"
  322. "00000000001010101010001"
  323. "00010001010001000001000"
  324. "00101010101000001010001"
  325. "01000100000001010000000"
  326. "10101000101000101000001"
  327. "00010101000100010101010"
  328. "10001000001010100000101"
  329. "01010001010001000001010"
  330. "10000010101010100010101"
  331. "01000101000101010101010"
  332. },
  333. /* 4*/ { GS1_MODE, -1, 3 << 8, { 0, 0, "" }, "[17]070620[10]ABC123456", -1, 0, 16, 23, 1, 1, "ISS DotCode Rev 4.0 Figure 6 bottom-left Mask = 2, same",
  334. "10100000101010100010001"
  335. "01000101000100000000010"
  336. "10101010001010000010000"
  337. "01010100010000010101010"
  338. "00001000101000001000101"
  339. "00000000000001010000010"
  340. "00100010101010101000001"
  341. "00010101010100010000000"
  342. "00001000100010101010001"
  343. "01000000010101010101000"
  344. "10100010100000101000101"
  345. "00000000000101000001010"
  346. "10000010000010100010101"
  347. "01010100010100010001010"
  348. "10101010000000001010001"
  349. "01010101000001000101010"
  350. },
  351. /* 5*/ { GS1_MODE, -1, 4 << 8, { 0, 0, "" }, "[17]070620[10]ABC123456", -1, 0, 16, 23, 1, 1, "ISS DotCode Rev 4.0 Figure 6 bottom-right Mask = 3, same",
  352. "10000000100000001010101"
  353. "01010001010100010001000"
  354. "10001000001010101010100"
  355. "01010101000101010000010"
  356. "10101010001000000010101"
  357. "00000100000100010101000"
  358. "00001000101010101000101"
  359. "00000001010000000101010"
  360. "00100010000000000000001"
  361. "01010100010101010101010"
  362. "10000000101010100010001"
  363. "01010101000001010000010"
  364. "10101010100000001000001"
  365. "01000001010001000001010"
  366. "10001000001010001000001"
  367. "01010100000101000100010"
  368. },
  369. /* 6*/ { GS1_MODE, -1, -1, { 0, 0, "" }, "[17]070620[10]ABC123456", -1, 0, 16, 23, 1, 1, "ISS DotCode Rev 4.0 Figure 6 top-right, auto Mask = 1, same",
  370. "10000000001010001000101"
  371. "01010101000100000101000"
  372. "00100010000000100000001"
  373. "01010001000001000001000"
  374. "10101010100000001010101"
  375. "00000100010100000100010"
  376. "00000000001010101010001"
  377. "00010001010001000001000"
  378. "00101010101000001010001"
  379. "01000100000001010000000"
  380. "10101000101000101000001"
  381. "00010101000100010101010"
  382. "10001000001010100000101"
  383. "01010001010001000001010"
  384. "10000010101010100010101"
  385. "01000101000101010101010"
  386. },
  387. /* 7*/ { UNICODE_MODE, -1, 1 << 8, { 0, 0, "" }, "2741", -1, 0, 10, 13, 0, 0, "ISS DotCode Rev 4.0 Figure 7A top-left Mask = 0, same; BWIPP automatically primes mask; ZXing-C++ can't handle zero row",
  388. "1010101010100"
  389. "0000010001010"
  390. "0000101000101"
  391. "0101000000000"
  392. "0000101010100"
  393. "0100010101000"
  394. "1000001000001"
  395. "0101000101010"
  396. "1000100010001"
  397. "0000000000000"
  398. },
  399. /* 8*/ { UNICODE_MODE, -1, 2 << 8, { 0, 0, "" }, "2741", -1, 0, 10, 13, 0, 1, "ISS DotCode Rev 4.0 Figure 7A top-right Mask = 1, same; BWIPP automatically primes mask",
  400. "1010001000101"
  401. "0000000100010"
  402. "0000100000001"
  403. "0101010001000"
  404. "1000101000000"
  405. "0101010101010"
  406. "1000101000101"
  407. "0100010101010"
  408. "0000000010001"
  409. "0001000001000"
  410. },
  411. /* 9*/ { UNICODE_MODE, -1, 3 << 8, { 0, 0, "" }, "2741", -1, 0, 10, 13, 0, 1, "ISS DotCode Rev 4.0 Figure 7A bottom-left Mask = 2, same; BWIPP automatically primes mask",
  412. "1010001010100"
  413. "0001000000000"
  414. "1000100010101"
  415. "0100000101000"
  416. "0000101000100"
  417. "0100010000010"
  418. "1000101010001"
  419. "0101010001000"
  420. "1000100010101"
  421. "0001000100000"
  422. },
  423. /* 10*/ { UNICODE_MODE, -1, 4 << 8, { 0, 0, "" }, "2741", -1, 0, 10, 13, 0, 1, "ISS DotCode Rev 4.0 Figure 7A bottom-right Mask = 3, same; BWIPP automatically primes mask",
  424. "1010001000100"
  425. "0001000001010"
  426. "1000001000000"
  427. "0101000100010"
  428. "1000101010100"
  429. "0101010000010"
  430. "1000100000000"
  431. "0100000101000"
  432. "1000001010001"
  433. "0101010101010"
  434. },
  435. /* 11*/ { UNICODE_MODE, -1, 5 << 8, { 0, 0, "" }, "2741", -1, 0, 10, 13, 1, 1, "ISS DotCode Rev 4.0 Figure 7B top-left Mask = 0' (4), same",
  436. "1010101010101"
  437. "0000010001010"
  438. "0000101000101"
  439. "0101000000000"
  440. "0000101010100"
  441. "0100010101000"
  442. "1000001000001"
  443. "0101000101010"
  444. "1000100010001"
  445. "0100000000010"
  446. },
  447. /* 12*/ { UNICODE_MODE, -1, 6 << 8, { 0, 0, "" }, "2741", -1, 0, 10, 13, 1, 1, "ISS DotCode Rev 4.0 Figure 7B top-right Mask = 1' (5), same",
  448. "1010001000101"
  449. "0000000100010"
  450. "0000100000001"
  451. "0101010001000"
  452. "1000101000000"
  453. "0101010101010"
  454. "1000101000101"
  455. "0100010101010"
  456. "1000000010001"
  457. "0101000001010"
  458. },
  459. /* 13*/ { UNICODE_MODE, -1, 7 << 8, { 0, 0, "" }, "2741", -1, 0, 10, 13, 1, 1, "ISS DotCode Rev 4.0 Figure 7B bottom-left Mask = 2' (6), same",
  460. "1010001010101"
  461. "0001000000000"
  462. "1000100010101"
  463. "0100000101000"
  464. "0000101000100"
  465. "0100010000010"
  466. "1000101010001"
  467. "0101010001000"
  468. "1000100010101"
  469. "0101000100010"
  470. },
  471. /* 14*/ { UNICODE_MODE, -1, 8 << 8, { 0, 0, "" }, "2741", -1, 0, 10, 13, 1, 1, "ISS DotCode Rev 4.0 Figure 7B bottom-right Mask = 3' (7), same",
  472. "1010001000101"
  473. "0001000001010"
  474. "1000001000000"
  475. "0101000100010"
  476. "1000101010100"
  477. "0101010000010"
  478. "1000100000000"
  479. "0100000101000"
  480. "1000001010001"
  481. "0101010101010"
  482. },
  483. /* 15*/ { UNICODE_MODE, -1, -1, { 0, 0, "" }, "2741", -1, 0, 10, 13, 1, 1, "ISS DotCode Rev 4.0 Figure 7B bottom-left auto Mask = 2' (6), same",
  484. "1010001010101"
  485. "0001000000000"
  486. "1000100010101"
  487. "0100000101000"
  488. "0000101000100"
  489. "0100010000010"
  490. "1000101010001"
  491. "0101010001000"
  492. "1000100010101"
  493. "0101000100010"
  494. },
  495. /* 16*/ { GS1_MODE, 40, -1, { 0, 0, "" }, "[01]00012345678905", -1, 0, 7, 40, 1, 1, "ISS DotCode Rev 4.0 Figure 8 top-left 7x40, Mask = 1, same",
  496. "1010101010001000100010100010101000001000"
  497. "0000010101000100010100010000010001000001"
  498. "1010001000001000001000101010001000101000"
  499. "0001010101000000010100010001000001010001"
  500. "1010100010001010000010001010000000101010"
  501. "0001010001010001000100000001010100010001"
  502. "1000100010001000100010100010001010001000"
  503. },
  504. /* 17*/ { GS1_MODE, 18, -1, { 0, 0, "" }, "[01]00012345678905", -1, 0, 17, 18, 1, 1, "ISS DotCode Rev 4.0 Figure 8 top-right 17x18 **NOT SAME** no matter what mask; but same as BWIPP and verified manually against tec-it",
  505. "101000001000101010"
  506. "010100000101010001"
  507. "000000101000001010"
  508. "000100010101000101"
  509. "001010000000100010"
  510. "010100000100010101"
  511. "100010001000001010"
  512. "010001000100010100"
  513. "001000001010000010"
  514. "010100000001010001"
  515. "000000101010001010"
  516. "000101000001000101"
  517. "100010001010100010"
  518. "000100010000000101"
  519. "100010001010001010"
  520. "010001010001000101"
  521. "100010001000100010"
  522. },
  523. /* 18*/ { GS1_MODE, 35, -1, { 0, 0, "" }, "[01]00012345678905", -1, 0, 8, 35, 1, 1, "ISS DotCode Rev 4.0 Figure 8 bottom-left 8x35, Mask = 3, same",
  524. "10100010000000000010100000100010101"
  525. "00010101010001000000010100010100000"
  526. "10001000101010101010001010000010101"
  527. "01010001000100000101000100010101010"
  528. "10101000100000101000100010001000001"
  529. "00010100010000010001010001010000000"
  530. "10000010101010101010000010000010001"
  531. "01000001000101000100010100010001000"
  532. },
  533. /* 19*/ { GS1_MODE, 17, -1, { 0, 0, "" }, "[01]00012345678905", -1, 0, 18, 17, 1, 1, "ISS DotCode Rev 4.0 Figure 8 bottom-right 18x17 **NOT SAME** no matter what mask; same as BWIPP; verified manually against tec-it",
  534. "10101000001000001"
  535. "01000001010100010"
  536. "00000000100010001"
  537. "00010101000101010"
  538. "10101000001010000"
  539. "01000100010000000"
  540. "00000010000000100"
  541. "01010000000001000"
  542. "10101010101000101"
  543. "00000000010101010"
  544. "00101010100000000"
  545. "01000101000001010"
  546. "10001000000010001"
  547. "00000001010100010"
  548. "00100010001000101"
  549. "01010100010101000"
  550. "10101010101010101"
  551. "01010101000101010"
  552. },
  553. /* 20*/ { UNICODE_MODE, 35, -1, { 0, 0, "" }, "Dots can be Square!", -1, 0, 18, 35, 1, 1, "ISS DotCode Rev 4.0 Figure 11 **NOT SAME**; same as BWIPP; verified manually against tec-it",
  554. "10000010101000000000000000101010101"
  555. "01010101000101000100010100000001000"
  556. "00001000000010101000101010101010000"
  557. "01000001000100000001010001000000000"
  558. "00100010101010101000000010100000101"
  559. "00000001010001010101010100010101000"
  560. "10101000100010000010101010001010001"
  561. "00010001010100010101000101000101010"
  562. "00101010001000001010101000100000101"
  563. "00010100010001010000000001010001010"
  564. "00101000100010100000100000000000101"
  565. "01010100010001010100010100000100000"
  566. "10000010000000000010001000101010100"
  567. "00010000000100010001000000010001010"
  568. "10001000001010101010001010101000001"
  569. "01000101010101000100000100010101000"
  570. "10101000101000001000100010101000101"
  571. "01000001000001000101010001000000010"
  572. },
  573. /* 21*/ { GS1_MODE, -1, 1 << 8, { 0, 0, "" }, "[99]8766", -1, 0, 10, 13, 0, 0, "ISS DotCode Rev 4.0 Table G.1 Mask 0, same; BWIPP automatically primes mask; ZXing-C++ can't handle zero col",
  574. "0000001010000"
  575. "0001010000010"
  576. "0000000010001"
  577. "0100010101000"
  578. "0010101000101"
  579. "0100010101010"
  580. "0010000010000"
  581. "0101010000010"
  582. "0010000000101"
  583. "0101000101010"
  584. },
  585. /* 22*/ { GS1_MODE, -1, 2 << 8, { 0, 0, "" }, "[99]8766", -1, 0, 10, 13, 0, 1, "ISS DotCode Rev 4.0 Table G.1 Mask 1, same; BWIPP automatically primes mask",
  586. "0000100000001"
  587. "0001010000000"
  588. "0000000000001"
  589. "0101010000010"
  590. "1010101010101"
  591. "0100000101010"
  592. "0010000010100"
  593. "0100010101000"
  594. "0010101000101"
  595. "0100010101000"
  596. },
  597. /* 23*/ { GS1_MODE, -1, 3 << 8, { 0, 0, "" }, "[99]8766", -1, 0, 10, 13, 0, 1, "ISS DotCode Rev 4.0 Table G.1 Mask 2, same; BWIPP automatically primes mask",
  598. "0000100010100"
  599. "0000000000000"
  600. "1000101010101"
  601. "0100010101010"
  602. "0010101000101"
  603. "0101010101010"
  604. "0010100000000"
  605. "0101010100000"
  606. "0000000010001"
  607. "0100000001010"
  608. },
  609. /* 24*/ { GS1_MODE, -1, 4 << 8, { 0, 0, "" }, "[99]8766", -1, 0, 10, 13, 0, 0, "ISS DotCode Rev 4.0 Table G.1 Mask 3, same; BWIPP automatically primes mask; ZXing-C++ can't handle zero col",
  610. "0000000000000"
  611. "0001010001000"
  612. "1000001010000"
  613. "0101010100010"
  614. "1010101000101"
  615. "0101010101010"
  616. "0010001000101"
  617. "0101010101010"
  618. "1000000010000"
  619. "0100000000010"
  620. },
  621. /* 25*/ { GS1_MODE, -1, 5 << 8, { 0, 0, "" }, "[99]8766", -1, 0, 10, 13, 1, 1, "ISS DotCode Rev 4.0 Table G.1 Mask 0' (4), same",
  622. "1000001010001"
  623. "0001010000010"
  624. "0000000010001"
  625. "0100010101000"
  626. "0010101000101"
  627. "0100010101010"
  628. "0010000010000"
  629. "0101010000010"
  630. "1010000000101"
  631. "0101000101010"
  632. },
  633. /* 26*/ { GS1_MODE, -1, 6 << 8, { 0, 0, "" }, "[99]8766", -1, 0, 10, 13, 1, 1, "ISS DotCode Rev 4.0 Table G.1 Mask 1' (5), same",
  634. "1000100000001"
  635. "0001010000000"
  636. "0000000000001"
  637. "0101010000010"
  638. "1010101010101"
  639. "0100000101010"
  640. "0010000010100"
  641. "0100010101000"
  642. "1010101000101"
  643. "0100010101010"
  644. },
  645. /* 27*/ { GS1_MODE, -1, 7 << 8, { 0, 0, "" }, "[99]8766", -1, 0, 10, 13, 1, 1, "ISS DotCode Rev 4.0 Table G.1 Mask 2' (6), same",
  646. "1000100010101"
  647. "0000000000000"
  648. "1000101010101"
  649. "0100010101010"
  650. "0010101000101"
  651. "0101010101010"
  652. "0010100000000"
  653. "0101010100000"
  654. "1000000010001"
  655. "0100000001010"
  656. },
  657. /* 28*/ { GS1_MODE, -1, 8 << 8, { 0, 0, "" }, "[99]8766", -1, 0, 10, 13, 1, 1, "ISS DotCode Rev 4.0 Table G.1 Mask 3' (7), same",
  658. "1000000000001"
  659. "0001010001000"
  660. "1000001010000"
  661. "0101010100010"
  662. "1010101000101"
  663. "0101010101010"
  664. "0010001000101"
  665. "0101010101010"
  666. "1000000010001"
  667. "0100000000010"
  668. },
  669. /* 29*/ { GS1_MODE, -1, -1, { 0, 0, "" }, "[99]8766", -1, 0, 10, 13, 1, 1, "ISS DotCode Rev 4.0 Table G.1 auto Mask 0' (4); all mask scores match Table G.1",
  670. "1000001010001"
  671. "0001010000010"
  672. "0000000010001"
  673. "0100010101000"
  674. "0010101000101"
  675. "0100010101010"
  676. "0010000010000"
  677. "0101010000010"
  678. "1010000000101"
  679. "0101000101010"
  680. },
  681. /* 30*/ { UNICODE_MODE, 6, -1, { 0, 0, "" }, "A", -1, 0, 19, 6, 1, 1, "ISS DotCode Rev 4.0 5.2.1.4 2) Table 4, 1 padding dot available; verified manually against tec-it",
  682. "101000"
  683. "000101"
  684. "101010"
  685. "000001"
  686. "100010"
  687. "000100"
  688. "001010"
  689. "000101"
  690. "101000"
  691. "010000"
  692. "100010"
  693. "010000"
  694. "000010"
  695. "000101"
  696. "101010"
  697. "000001"
  698. "101000"
  699. "010000"
  700. "101000"
  701. },
  702. /* 31*/ { UNICODE_MODE, 94, -1, { 0, 0, "" }, "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRS", -1, 0, 37, 94, 1, 1, "Interleaved R-S; verified manually against tec-it",
  703. "1000001010000000100010000010101010101000001000100000001010101000001000001000101010001000101010"
  704. "0101010000000101000001010001010001010100010001000001000000010101010000000101010100010001010100"
  705. "0010101000100010000010101010000000101010000010101000001000100010100000100010100010001000101000"
  706. "0000000100010101000001010000010000010101010100010100000100000101000100010001000001010001010001"
  707. "0010100000100010101000001000101010000010001000001010100000101000101010000010001000101010100010"
  708. "0100000101010001010001000101000001000100000101010001000101000100010100000100010100010001010100"
  709. "1010000000100010100000101010000010101000001000001010001010000010001010100000101010100000100000"
  710. "0001010100000101000001000000010001010100000101000100010101000001000101000100010000010101010001"
  711. "1010001010001010000000100000101010100000100010101000000010100010001010100010000010100010001010"
  712. "0001000100010100010001010000000101010100010000010100000100000101010100010000010100010001000001"
  713. "1000001010001010100010000010001000100010100010100010000010001000101010100000101000001000101010"
  714. "0101000001000101000100000001010001010101010001000001000000010001010100010101010000010100000001"
  715. "0000100000001010100010101000000010001010001010000000101010001000101010001000101000100000100010"
  716. "0000000100000100000101010101000000010101010001000100010001000101010001000100010000010100010101"
  717. "0010101000001010001000101000000000101010001010000010101010000010001000100000001010101010001010"
  718. "0100010001010100010000010100010001010100010000010001000100000100010101000101000100000101010001"
  719. "1000001000100010101010101000000010001000001010000010101010000010101010000000100010001000101000"
  720. "0000010000010101010000010101000000010101000001000101000100010001000101010001000100010000010100"
  721. "1000001000101010000010001000001000101010100000100000001010001010101000000010001010101010001000"
  722. "0100010001010001000100010000010100000100010100010100010001000001010100010101000100000101000101"
  723. "1010000000101000100000001000101010100010000000101010101010000010101000000010100010001000100010"
  724. "0100000101010000010100010001010100010000010101000100000100000101000001010100010000000101010001"
  725. "1000001000001010001010001000101000001000101010000010101000100010100000101000100000001000101010"
  726. "0101010100010001010101000000010101010000010100000100010100010001000100000100010001010100010100"
  727. "1000100000101000000010100010101000001010100010100000100000101010000010101000100000001010000000"
  728. "0001000001000101000101010000010001000100000101010001000100010100000101000101000100000101010001"
  729. "0000000010001000101000100000100000101010101000000010101010001000100010001000101010001000100010"
  730. "0101010100010000000100010101010001010100000001010101000001000001000001010100000101010001010101"
  731. "1000100010101000100000101010001000101010000010001010001010001010000010100010100010000000100000"
  732. "0000010101010000010101000000010101000001000101000100010001000101010001000100010000010100010000"
  733. "1000101010000010001000001000101010100000100000001010001010101000000010001010101010001000000010"
  734. "0100000101000001010001010000000100010100010100010001000001010100010101000100000101000101010000"
  735. "0000001010001000100010100010000010101000100010001000101000001000100000101000100010100010001010"
  736. "0101010000010100010000010100000101010100000101000001000000010101000101000101010000000101010101"
  737. "1000001010001010001000101000001000101010000010101000100010100000101000100000001000101010100000"
  738. "0001000101010100000001010101000001010000010001010001000100010000010001000101010001010001000001"
  739. "0010001000001010101000000010101000101000001000001010100000101010001000000010100000001010101000"
  740. },
  741. /* 32*/ { GS1_MODE, 50, -1, { 0, 0, "" }, "[17]070620[10]ABC123456", -1, 0, 7, 50, 1, 1, "GS1 Gen Spec Figure 5.1-8.",
  742. "10000010101000100010101010001000000010100000100000"
  743. "01000101000101010100000100010000010001000001010101"
  744. "00001010001000101000101000100010001010100000000010"
  745. "01000001000100000101010101010001000001000101000001"
  746. "10001000001010100010001010100000100010100010000010"
  747. "00010001010000000100010101000100010001010001000101"
  748. "10001000001010101000001000100010100010100000101010"
  749. },
  750. /* 33*/ { UNICODE_MODE, 200, -1, { 0, 0, "" }, "123456789012345678901234567890123456789012345678901234567890", -1, 0, 5, 200, 1, 1, "Max cols",
  751. "10101000100010101010000010101000000010001000100000101010100010100000101000100010000000101000101010001010100000100000101010100000001000101000001010100010001010000010001010001010100000100010101000000010"
  752. "00010101010000000101000100010001000101000101000100010001000001010001000001010100000001000101010000000101010100010101010000010001000101010001000001000001010000010100010001010101000001000001010100000001"
  753. "10100010000000100010101000101010100000001010001000100000101000101000001000101010001000000010101010100010101000000010100010001000001010100000101000100000101010100010000000001000001010101000101010100000"
  754. "00010001010001010000000101000100010001010000010000010100010100000100010101010001000101000000010100010001010100010000010100000101000100010100000101010000000101000001010100010100010001000101000001010001"
  755. "10100010001010101000000010001000001010001010001000001010100010000000101010001010000010101010000000101000100010100010100000100010100010001010100000001010101000001010000000001000101000101010000010101010"
  756. },
  757. /* 34*/ { UNICODE_MODE, 19, -1, { 0, 0, "" }, "4", -1, 0, 6, 19, 1, 1, "Mask 1 selected",
  758. "1010100000101000101"
  759. "0100000000010001010"
  760. "0010101010000000000"
  761. "0000010100000100000"
  762. "1000100010001010001"
  763. "0001010101010101010"
  764. },
  765. /* 35*/ { UNICODE_MODE, 19, 3 << 8, { 0, 0, "" }, "4", -1, 0, 6, 19, 0, 1, "Mask 2 specified, unlit right edge mask; BWIPP automatically primes mask",
  766. "1010101010000000100"
  767. "0000000101000100010"
  768. "1010100000001010100"
  769. "0000010101010000000"
  770. "1000001010100010100"
  771. "0101000100010001010"
  772. },
  773. /* 36*/ { UNICODE_MODE, 19, 7 << 8, { 0, 0, "" }, "4", -1, 0, 6, 19, 1, 1, "Mask 2' specified",
  774. "1010101010000000101"
  775. "0000000101000100010"
  776. "1010100000001010100"
  777. "0000010101010000000"
  778. "1000001010100010101"
  779. "0101000100010001010"
  780. },
  781. /* 37*/ { GS1_MODE, -1, -1, { 0, 0, "" }, "[10]12[20]12", -1, 0, 12, 17, 1, 1, "Code Set C with FNC1",
  782. "10100000001000001"
  783. "00010100010101010"
  784. "10001000100000001"
  785. "01010100000101000"
  786. "10000010000010001"
  787. "01010001010100010"
  788. "00001010100000001"
  789. "00000101010001010"
  790. "10101000001010001"
  791. "01010101000101010"
  792. "10000010100000101"
  793. "01000100010101010"
  794. },
  795. /* 38*/ { UNICODE_MODE, -1, -1, { 0, 0, "" }, "1234\011\034\035\036", -1, 0, 14, 21, 1, 1, "Code Set B HT FS GS RS",
  796. "100010001000001010101"
  797. "010001000001000001000"
  798. "100010100010101010001"
  799. "010100000000010100010"
  800. "101000100010001000000"
  801. "010000010000000001000"
  802. "100000101010100000000"
  803. "000101010101010000000"
  804. "001000001010101010101"
  805. "000000000100010001010"
  806. "101010000000000000101"
  807. "000101010101000101010"
  808. "001010101000101010001"
  809. "010101010001000101000"
  810. },
  811. /* 39*/ { UNICODE_MODE, 17, -1, { 0, 0, "" }, "abcd\015\012", -1, 0, 14, 17, 1, 1, "Code Set B CRLF",
  812. "00001000001000101"
  813. "01000101010001000"
  814. "10100000100010101"
  815. "01000001010000010"
  816. "00100010101000101"
  817. "01010000010101000"
  818. "10101010000010001"
  819. "01000001000100010"
  820. "00001010101010101"
  821. "00000100010100010"
  822. "00101010000000000"
  823. "00010100010000000"
  824. "10100000001010000"
  825. "01010001000101000"
  826. },
  827. /* 40*/ { DATA_MODE, -1, -1, { 0, 0, "" }, "\101\102\103\104\105\106\107\200\101\102\240\101", -1, 0, 18, 27, 1, 1, "Code Set B Upper Shift A Upper Shift B",
  828. "101010100000101000101000001"
  829. "010100010101000100010101000"
  830. "000010001010100000101010101"
  831. "010100010100000001010101000"
  832. "001010000010001010101000101"
  833. "000001000001010101000000010"
  834. "101000101010100000001000001"
  835. "000101000001010101010100010"
  836. "001010101000101010100010101"
  837. "000101010001000100010001010"
  838. "000000001000100000000000001"
  839. "010000000000010100000100010"
  840. "101010101010101010101010101"
  841. "000101010001000100010101010"
  842. "100000000000100000000010101"
  843. "000000010100010000000100010"
  844. "100010101000000010001000001"
  845. "010001000100000101000001010"
  846. },
  847. /* 41*/ { UNICODE_MODE, -1, -1, { 0, 0, "" }, "ABCDEF\001G1234H", -1, 0, 16, 25, 1, 1, "Code Set A 4x Shift C",
  848. "0010101010100000100000101"
  849. "0000000100010101000001000"
  850. "1000100000101000100000101"
  851. "0101000001010100000101010"
  852. "0000000000101010001010000"
  853. "0100000000010101010100000"
  854. "0010101010000000101010101"
  855. "0100010101000000010100000"
  856. "1010001000100010001000101"
  857. "0101010001010000000001010"
  858. "0000001010100010001010101"
  859. "0001000000000001010001000"
  860. "0010100000101010100000000"
  861. "0101010100000100010100010"
  862. "1010101010001000101000000"
  863. "0000010100010101000101010"
  864. },
  865. /* 42*/ { UNICODE_MODE, -1, -1, { 0, 0, "" }, "ABCDEF\001ab\011\034\035\036\001A", -1, 0, 19, 28, 1, 1, "Code Set A 6x Shift B HT FS GS RS",
  866. "1000001010100010101010101010"
  867. "0101000000010100010101010001"
  868. "0010001010100000101000001010"
  869. "0001000101000001010001010000"
  870. "1000001010100000101010001000"
  871. "0100010101010001000000010001"
  872. "0000001010100010100010000010"
  873. "0000010100000001010100010101"
  874. "0000001010001010101000001010"
  875. "0100010101010101000001010000"
  876. "0010000000101000101000000010"
  877. "0101000101000101000101000001"
  878. "1000100000001010101000001000"
  879. "0101000001010000010001010100"
  880. "1010000000100010001010100010"
  881. "0101010100000001000100010001"
  882. "1010000010100000100000101000"
  883. "0001010000010100000100010101"
  884. "1010100010000000101010101010"
  885. },
  886. /* 43*/ { UNICODE_MODE, -1, -1, { 0, 0, "" }, "ABCDEF\001abcdefgA", -1, 0, 19, 28, 1, 1, "Code Set A Latch B",
  887. "1010001010100010101010101010"
  888. "0100010101010000000100010001"
  889. "1010000010100000100010101000"
  890. "0001010001000001010100000001"
  891. "0010001010100000000010101010"
  892. "0101000000010100010101000001"
  893. "0000101010100000001000001010"
  894. "0000010101010000000100010101"
  895. "0000101010100000101000001010"
  896. "0001010100010001010000000101"
  897. "1010000010100010100000001010"
  898. "0101000101000000010001010001"
  899. "1000100000001010101000001000"
  900. "0101000001010000010100010001"
  901. "1010000000100010001010100010"
  902. "0101010100000001000100010001"
  903. "1010000010100000100000101000"
  904. "0001010000010100000100010101"
  905. "1010100010000000101010101010"
  906. },
  907. /* 44*/ { DATA_MODE, -1, -1, { 0, 0, "" }, "\200\200\200\200\061\062\063\064\065\066\067\070\071\060\061\062\063\064\065\066\200", -1, 0, 20, 29, 1, 1, "Binary Latch C",
  908. "10101010000010100010101010001"
  909. "01010001000101010001000000010"
  910. "00001010101000101010001000001"
  911. "00010100000001000101010100000"
  912. "00100000101000100000000000101"
  913. "00000001010101010100000101000"
  914. "10101000001010000010101000100"
  915. "01010100010000000101000000010"
  916. "10101000101000001010100010100"
  917. "00010101000101010001000101010"
  918. "10000010101000100010101010001"
  919. "01000001010100000001010001010"
  920. "00001010101010101000000010001"
  921. "00010100000000010000010101010"
  922. "00101000100010001000101000001"
  923. "00000100000101010101000000000"
  924. "10000000000000001000000010101"
  925. "01010001010001010000010101000"
  926. "10000010100010000010001000101"
  927. "01000100000100010001010101010"
  928. },
  929. /* 45*/ { UNICODE_MODE, -1, -1, { 11, 24, "" }, "ABCDEFG", -1, 0, 16, 23, 1, 1, "Structured Append",
  930. "10101000001000101000001"
  931. "01010101000001010001010"
  932. "10101010100010000000001"
  933. "01000001010000010100010"
  934. "10000000101010100010101"
  935. "01010100010101010101000"
  936. "10000010101010101000101"
  937. "00010100010100000000010"
  938. "00101000100000001010001"
  939. "00010100000001000100000"
  940. "00100010000000001010101"
  941. "01010101010001010101000"
  942. "10000000001010000000001"
  943. "00000000010100010001010"
  944. "10001010101000100010001"
  945. "01000001000100010101010"
  946. },
  947. /* 46*/ { UNICODE_MODE, -1, -1, { 0, 0, "" }, "1234", -1, 0, 10, 13, 1, 1, "",
  948. "0010100000001"
  949. "0000000001010"
  950. "1000000010101"
  951. "0101010101000"
  952. "1000101000000"
  953. "0100010100010"
  954. "1000000010100"
  955. "0101010000010"
  956. "1000101000001"
  957. "0101010101000"
  958. },
  959. /* 47*/ { UNICODE_MODE, -1, -1, { 0, 0, "" }, "[)>\03605\035101\036\004", -1, 0, 12, 17, 1, 1, "Macro 05",
  960. "10000010001000101"
  961. "00000001000000010"
  962. "10001010100010001"
  963. "01010000010000000"
  964. "10001010000010001"
  965. "01000000010000010"
  966. "10100010101000001"
  967. "01010100000001010"
  968. "00001000101010101"
  969. "01010001000101000"
  970. "10101010101010101"
  971. "01010001010101010"
  972. },
  973. /* 48*/ { UNICODE_MODE, -1, -1, { 0, 0, "" }, "[)>\03607Text\036\004", -1, 0, 14, 21, 1, 1, "Macro 07 (free form text)",
  974. "100010001000001000101"
  975. "010001000000010101010"
  976. "000010101000100000101"
  977. "010100000000010000000"
  978. "001000100000000000100"
  979. "010101010001010101010"
  980. "101010101010100010100"
  981. "010000010101000000000"
  982. "001010001000001010001"
  983. "000000000101010101010"
  984. "001000000010001000001"
  985. "000101000101000100000"
  986. "100010101010100010101"
  987. "000001010100010100000"
  988. },
  989. /* 49*/ { UNICODE_MODE, -1, -1, { 0, 0, "" }, "[)>\03605\035Študentska št.\0352198390\036\004", -1, ZINT_WARN_USES_ECI, 23, 34, 1, 1, "Macro 05 with ECI",
  990. "1010101000100000101000001010000010"
  991. "0101000001000101010100000101000001"
  992. "1000101000101000100010100010001000"
  993. "0000010001010001000100010001010000"
  994. "0000101000100010000010001010101000"
  995. "0001010001000100010000010101010100"
  996. "0000100010100000101010001000001010"
  997. "0100010100010100010000010101000001"
  998. "1010101000100010000010000010001010"
  999. "0101000100000100010001010000010001"
  1000. "0010101000100010001000001010101000"
  1001. "0100010100010001000101010000010000"
  1002. "0000101010100010000010100010100010"
  1003. "0101000000000001010001010001000001"
  1004. "0010100010000000101010100010100010"
  1005. "0101000100010101000100000100010100"
  1006. "0010100010000010101000101000001000"
  1007. "0001000100000101000100010000010101"
  1008. "1000100010100000100010001010100010"
  1009. "0101010001000001000101000101000100"
  1010. "0010000010001010100010001000001000"
  1011. "0100000001000100010001010100010101"
  1012. "1010001000001010101000000010101000"
  1013. },
  1014. /* 50*/ { UNICODE_MODE, -1, -1, { 0, 0, "" }, "[)>\03607Τεχτ\036\004", -1, ZINT_WARN_USES_ECI, 17, 26, 1, 1, "Macro 07 with ECI",
  1015. "10001010001000100000101000"
  1016. "00010101000101000000010101"
  1017. "00100010100000100010001000"
  1018. "00010101000101010101000100"
  1019. "10101000100010001010000000"
  1020. "00000100010100010100000001"
  1021. "00001010101000100000001010"
  1022. "01010000010001010100010100"
  1023. "00000010100010101010000010"
  1024. "00010101000101000101000001"
  1025. "00101000101000100010001000"
  1026. "00010101000100000001010100"
  1027. "10100010000010001010001000"
  1028. "00010100010100010000010001"
  1029. "10001000101000101010001000"
  1030. "01000101010100000000000101"
  1031. "10100010000010101010000010"
  1032. },
  1033. };
  1034. const int data_size = ARRAY_SIZE(data);
  1035. int i, length, ret;
  1036. struct zint_symbol *symbol = NULL;
  1037. char escaped[1024];
  1038. char cmp_buf[8192];
  1039. char cmp_msg[1024];
  1040. int do_bwipp = (debug & ZINT_DEBUG_TEST_BWIPP) && testUtilHaveGhostscript(); /* Only do BWIPP test if asked, too slow otherwise */
  1041. int do_zxingcpp = (debug & ZINT_DEBUG_TEST_ZXINGCPP) && testUtilHaveZXingCPPDecoder(); /* Only do ZXing-C++ test if asked, too slow otherwise */
  1042. testStartSymbol("test_encode", &symbol);
  1043. for (i = 0; i < data_size; i++) {
  1044. if (testContinue(p_ctx, i)) continue;
  1045. symbol = ZBarcode_Create();
  1046. assert_nonnull(symbol, "Symbol not created\n");
  1047. length = testUtilSetSymbol(symbol, BARCODE_DOTCODE, data[i].input_mode, -1 /*eci*/, -1, data[i].option_2, data[i].option_3, -1 /*output_options*/, data[i].data, data[i].length, debug);
  1048. if (data[i].structapp.count) {
  1049. symbol->structapp = data[i].structapp;
  1050. }
  1051. ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length);
  1052. assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
  1053. if (p_ctx->generate) {
  1054. printf(" /*%3d*/ { %s, %d, %s, { %d, %d, \"%s\" }, \"%s\", %d, %s, %d, %d, %d, %d, \"%s\",\n",
  1055. i, testUtilInputModeName(data[i].input_mode), data[i].option_2,
  1056. testUtilOption3Name(BARCODE_DOTCODE, data[i].option_3),
  1057. data[i].structapp.index, data[i].structapp.count, data[i].structapp.id,
  1058. testUtilEscape(data[i].data, length, escaped, sizeof(escaped)), data[i].length,
  1059. testUtilErrorName(data[i].ret), symbol->rows, symbol->width, data[i].bwipp_cmp, data[i].zxingcpp_cmp, data[i].comment);
  1060. testUtilModulesPrint(symbol, " ", "\n");
  1061. printf(" },\n");
  1062. } else {
  1063. if (ret < ZINT_ERROR) {
  1064. int width, row;
  1065. 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);
  1066. 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);
  1067. ret = testUtilModulesCmp(symbol, data[i].expected, &width, &row);
  1068. assert_zero(ret, "i:%d testUtilModulesCmp ret %d != 0 width %d row %d (%s)\n", i, ret, width, row, data[i].data);
  1069. if (do_bwipp && testUtilCanBwipp(i, symbol, -1, data[i].option_2, data[i].option_3, debug)) {
  1070. if (!data[i].bwipp_cmp) {
  1071. if (debug & ZINT_DEBUG_TEST_PRINT) printf("i:%d %s not BWIPP compatible (%s)\n", i, testUtilBarcodeName(symbol->symbology), data[i].comment);
  1072. } else {
  1073. ret = testUtilBwipp(i, symbol, -1, data[i].option_2, data[i].option_3, data[i].data, length, NULL, cmp_buf, sizeof(cmp_buf), NULL);
  1074. assert_zero(ret, "i:%d %s testUtilBwipp ret %d != 0\n", i, testUtilBarcodeName(symbol->symbology), ret);
  1075. ret = testUtilBwippCmp(symbol, cmp_msg, cmp_buf, data[i].expected);
  1076. assert_zero(ret, "i:%d %s testUtilBwippCmp %d != 0 %s\n actual: %s\nexpected: %s\n",
  1077. i, testUtilBarcodeName(symbol->symbology), ret, cmp_msg, cmp_buf, data[i].expected);
  1078. }
  1079. }
  1080. if (do_zxingcpp && testUtilCanZXingCPP(i, symbol, data[i].data, length, debug)) {
  1081. if (!data[i].zxingcpp_cmp) {
  1082. if (debug & ZINT_DEBUG_TEST_PRINT) printf("i:%d %s not ZXing-C++ compatible (%s)\n", i, testUtilBarcodeName(symbol->symbology), data[i].comment);
  1083. } else {
  1084. int cmp_len, ret_len;
  1085. char modules_dump[16384];
  1086. assert_notequal(testUtilModulesDump(symbol, modules_dump, sizeof(modules_dump)), -1, "i:%d testUtilModulesDump == -1\n", i);
  1087. ret = testUtilZXingCPP(i, symbol, data[i].data, length, modules_dump, cmp_buf, sizeof(cmp_buf), &cmp_len);
  1088. assert_zero(ret, "i:%d %s testUtilZXingCPP ret %d != 0\n", i, testUtilBarcodeName(symbol->symbology), ret);
  1089. ret = testUtilZXingCPPCmp(symbol, cmp_msg, cmp_buf, cmp_len, data[i].data, length, NULL /*primary*/, escaped, &ret_len);
  1090. assert_zero(ret, "i:%d %s testUtilZXingCPPCmp %d != 0 %s\n actual: %.*s\nexpected: %.*s\n",
  1091. i, testUtilBarcodeName(symbol->symbology), ret, cmp_msg, cmp_len, cmp_buf, ret_len, escaped);
  1092. }
  1093. }
  1094. }
  1095. }
  1096. ZBarcode_Delete(symbol);
  1097. }
  1098. testFinish();
  1099. }
  1100. static void test_encode_segs(const testCtx *const p_ctx) {
  1101. int debug = p_ctx->debug;
  1102. struct item {
  1103. int input_mode;
  1104. int option_2;
  1105. int option_3;
  1106. struct zint_structapp structapp;
  1107. struct zint_seg segs[3];
  1108. int ret;
  1109. int expected_rows;
  1110. int expected_width;
  1111. int bwipp_cmp;
  1112. int zxingcpp_cmp;
  1113. char *comment;
  1114. char *expected;
  1115. };
  1116. /* ISS DotCode, Rev 4.0, DRAFT 0.15, TSC Pre-PR #5, MAY 28, 2019 */
  1117. static const struct item data[] = {
  1118. /* 0*/ { UNICODE_MODE, 18, -1, { 0, 0, "" }, { { TU("¶"), -1, 0 }, { TU("Ж"), -1, 7 }, { TU(""), 0, 0 } }, 0, 13, 18, 1, 1, "ISS DotCode Rev 4.0 13.5 example **NOT SAME** different encodation",
  1119. "100000001010101010"
  1120. "000100000100010101"
  1121. "001010000010101000"
  1122. "010101010001010001"
  1123. "100010100010000000"
  1124. "010100010100000101"
  1125. "001000101000000010"
  1126. "000001010101000100"
  1127. "100010100010000010"
  1128. "000001000101000001"
  1129. "101000101010100010"
  1130. "010100000000010001"
  1131. "100000101010000010"
  1132. },
  1133. /* 1*/ { UNICODE_MODE, 18, -1, { 0, 0, "" }, { { TU("¶"), -1, 0 }, { TU("Ж"), -1, 0 }, { TU(""), 0, 0 } }, ZINT_WARN_USES_ECI, 13, 18, 1, 1, "ISS DotCode Rev 4.0 13.5 example auto-ECI",
  1134. "100000001010101010"
  1135. "000100000100010101"
  1136. "001010000010101000"
  1137. "010101010001010001"
  1138. "100010100010000000"
  1139. "010100010100000101"
  1140. "001000101000000010"
  1141. "000001010101000100"
  1142. "100010100010000010"
  1143. "000001000101000001"
  1144. "101000101010100010"
  1145. "010100000000010001"
  1146. "100000101010000010"
  1147. },
  1148. /* 2*/ { UNICODE_MODE, -1, -1, { 0, 0, "" }, { { TU("Ж"), -1, 7 }, { TU("¶"), -1, 0 }, { TU(""), 0, 0 } }, 0, 14, 21, 1, 1, "ISS DotCode Rev 4.0 13.5 example inverted",
  1149. "100010001010101010000"
  1150. "000100000101000001010"
  1151. "101000101000001000101"
  1152. "000001010100000101000"
  1153. "001010101010100010001"
  1154. "010001000001010101000"
  1155. "101000101000101010100"
  1156. "010101010001010001000"
  1157. "100010001000000000100"
  1158. "010100000001000100010"
  1159. "001000100010000000101"
  1160. "000000000100010100010"
  1161. "100010001000100000001"
  1162. "010101000100010001000"
  1163. },
  1164. /* 3*/ { UNICODE_MODE, -1, -1, { 0, 0, "" }, { { TU("Ж"), -1, 0 }, { TU("¶"), -1, 0 }, { TU(""), 0, 0 } }, ZINT_WARN_USES_ECI, 14, 21, 1, 1, "ISS DotCode Rev 4.0 13.5 example inverted auto-ECI",
  1165. "100010001010101010000"
  1166. "000100000101000001010"
  1167. "101000101000001000101"
  1168. "000001010100000101000"
  1169. "001010101010100010001"
  1170. "010001000001010101000"
  1171. "101000101000101010100"
  1172. "010101010001010001000"
  1173. "100010001000000000100"
  1174. "010100000001000100010"
  1175. "001000100010000000101"
  1176. "000000000100010100010"
  1177. "100010001000100000001"
  1178. "010101000100010001000"
  1179. },
  1180. /* 4*/ { UNICODE_MODE, 95, -1, { 0, 0, "" }, { { TU("product:Google Pixel 4a - 128 GB of Storage - Black;price:$439.97"), -1, 3 }, { TU("品名:Google 谷歌 Pixel 4a -128 GB的存储空间-黑色;零售价:¥3149.79"), -1, 29 }, { TU("Produkt:Google Pixel 4a - 128 GB Speicher - Schwarz;Preis:444,90 €"), -1, 17 } }, 0, 64, 95, 0, 1, "AIM ITS/04-023:2022 Annex A example; BWIPP different encodation",
  1181. "10101000100000001010000000101000101010100010001010000010001000101000101000001000001000100010101"
  1182. "00000101010001010000010101000000010100000001010101000101010100010101000101000100000100000100000"
  1183. "10100010100010001000100000001010100000001000101000101010001010001010000000101000001000101000101"
  1184. "01010001000100000000000001010000010100010101010100010001010001010000010000010000010100010000010"
  1185. "10000010101000100000001010000010000000000000000000100010100010100000101010001000000010001000000"
  1186. "00010100000101000001010100000101010101010000010001010100000100010101010001010101000101000000010"
  1187. "10001010001010101010000010001010000010101000001000101000001000101000100010101010001000000010100"
  1188. "00010100010100010101000000010001010101000101000101010001010101000000000101010001010100000101000"
  1189. "10100000000000000000101000100010101010001000101010001010101010000000000010000000100010101010001"
  1190. "01000100010001010001000000000000000001000100000100000001010100010100010001010001010101010100010"
  1191. "00101000101010101000000010101000001010001010100010101000000000101010101000101010101010100000101"
  1192. "00000101010101010100010001010101000101010000010001010001000001010101000100000100000001010001010"
  1193. "00101010000010101000101000100000101000100010001000101000101010000010100010100000001000001010101"
  1194. "01000000010001000101010100000100000000010101000100000100010000010000010100000101000100000001010"
  1195. "00001010101000101000100000001000001010100010000010101010100000101010100010000000100010001000001"
  1196. "01010101010101010100000000010100010000010101000101010100000101010000000000010000010100010101000"
  1197. "10000000001010000010101000100010000010100000100000100010100010000000101010101010100010000000100"
  1198. "00010000000000010001010101000101010101000000010100000100010001000101010101010001000001010101010"
  1199. "10100000100000101010101010100000100010101010100010000010001010100010100010000010100000001010001"
  1200. "01000001010000000101010001010001000001010100010000000100000000000001000100000100000101000101010"
  1201. "10000010101010100010001010101010000000000010101000101010000000101000001000101010101010100000100"
  1202. "00010101000100000100000101010000010100010001000001010100000100010101010001010101010001010001010"
  1203. "00001010101000000010000010001010001000101000100000000000001010000000001000001010000000100010100"
  1204. "01000001000101000101010000000101010101010101000001000001010101000101010100010001010000010000000"
  1205. "10101010000010001000000000000000101010001010001010001000100000100010101010101000101010101010000"
  1206. "01010100000101010000010101010001000101000100010101000100010001010001010101000000010101010101000"
  1207. "00100010101000100010100010101000101000001000001010001010001010001010100000100010000010100010001"
  1208. "00000000010100010001000000000100010000010000010101000001000001000101000101010100010100010100000"
  1209. "10100000101010001000001000101010100000100000101000100010100000101000001000100000101000001010000"
  1210. "00010101000101000101010101000101000001000001000000010001010100000100000100000101010000000101010"
  1211. "00100000000010100010101010101010101000100010100010100010001010100010001000101010101000100010000"
  1212. "01000100010000010000000101000101010100000100010100010101000101010001010001000100010100000000010"
  1213. "10001000001000001010101010000000001010101000101010000000100010001010000010001000101010100000101"
  1214. "01010101000001000100000001010000010100010100000101000000010100000000000000010101000001010001000"
  1215. "00001010100000000000001000100010100010101010000000001000100000001010100010000010000000001010001"
  1216. "01010101000101000001010100010000000001010100000100010101000101010101010001010000010101000100000"
  1217. "00001010001000101000000000001010101010000010001000101010001000101000101010001000000010100010101"
  1218. "00010001010000010100000000000101000001010001000101010101010001010101010101000101010100000101010"
  1219. "10101000100010000000101010100010000000001010100010101010001010000010101000101010001010100010101"
  1220. "01000100010000010101000101010000010101000101010001010001000001000000000000010101010101010001010"
  1221. "10000010001000100010100010101000001010100010001010000000101000101010000010000010100010001000100"
  1222. "01010000010101010101010100000001010100010000010000000000010100010100000100000000000001010000010"
  1223. "00100000000010101010001000001010001010001000101010101010101010001000100010101000001000001000100"
  1224. "00000100000101010001010101010100000001010101010000000100010100010001010001010101000001000101000"
  1225. "00001010001010001010000000100000100000101000101000101000100010101010101000000010101000101000101"
  1226. "01010101010001010100000000010001000001010001010101010101010100000001000000010101000101010100000"
  1227. "10100010101000101010101010100010100000000010100000000010001000100010001010001000101010001010001"
  1228. "01010001010000000001010101010101010100000101010001000100000001010000010100000000000101000001010"
  1229. "00001010100010101000101010001000101000101010001010101010001000100000001010100000100000101010100"
  1230. "00000001000101000101010001010001000001000001010101010101000000000101010101010000010000010000010"
  1231. "10100000000010101000001000000000000010001010100010001000001010000000000000001000000010101000000"
  1232. "00000100000100000100000000000100010100000100010000000000010000000101010001000001010101010101000"
  1233. "00101000101000000010000000001000101010100000000010100010100010001010101010101010001010000000100"
  1234. "01000101010000010000010100000001010100010001000001010101000101010100000101000101010100010100000"
  1235. "10101010101010000010100010101010000000000010001000100000001000100000100000100010100010101000101"
  1236. "01010000010001010001010100000101010001010001000101010001000101010000000101010001000000000101010"
  1237. "10000000000010101000100010100010101010100000001000101000100010000000100000101010000010100010001"
  1238. "00010101010100000001010101010000000101000100000100010001010001000100010000000101010100000001010"
  1239. "10101010001010101010001000101010000010101010100010001000100000001000101000000000101000001000001"
  1240. "01010100000101010100000000000100010101000101010100000000010101010001010000000100000001000100010"
  1241. "10000010100000100000101010001000100000000000100000000010100010001010001010100010100010000010100"
  1242. "00010000010101000101010101010101010000010100010000010001010000010100000101000100010000010000000"
  1243. "10100000100000001010101010101010001010001010000010100010001010101010000010001010000000100010001"
  1244. "01000001000100000101000101010100000000010001000100000101000100000100010101010101000101010100010"
  1245. },
  1246. /* 5*/ { DATA_MODE, -1, -1, { 0, 0, "" }, { { TU("\266"), 1, 0 }, { TU("\266"), 1, 7 }, { TU("\266"), 1, 0 } }, 0, 15, 22, 1, 1, "Standard example + extra seg, data mode",
  1247. "1000101010000000001000"
  1248. "0100000101000101000001"
  1249. "1000001000100010101000"
  1250. "0000010001000001010101"
  1251. "1000100000100010101010"
  1252. "0001010000010000010001"
  1253. "0010101000101010100010"
  1254. "0000010101000101000000"
  1255. "1000100010001010100000"
  1256. "0101000101000100010100"
  1257. "0010100000100000001010"
  1258. "0001000101000001010100"
  1259. "1010000010100010001010"
  1260. "0000010000010000010101"
  1261. "1010001010100000101010"
  1262. },
  1263. /* 6*/ { UNICODE_MODE, 38, -1, { 0, 0, "" }, { { TU("1234567890β"), -1, 9 }, { TU("1234567890点"), -1, 20 }, { TU("1234567890"), -1, 0 } }, 0, 23, 38, 0, 1, "FNC2 ECI & BIN_LATCH ECI; BWIPP different encodation",
  1264. "10000000001010100000101010100000100010"
  1265. "00000001010001000001010001010101000100"
  1266. "10001010100000101000001010001010101000"
  1267. "01000101010001010001000100000000010101"
  1268. "00001000100010001010100000101000100000"
  1269. "01000101010000010101010001000000010101"
  1270. "10001000101000101010000000100010000010"
  1271. "01000100010001010001010000010100010001"
  1272. "10101000000010001010000010101010000000"
  1273. "01010100010000010100010000010000010101"
  1274. "00000010100010001010000010000010100010"
  1275. "01010000010001010001000101000001010101"
  1276. "10000000000010001010101000101000000010"
  1277. "00010001010001010100010000010101000101"
  1278. "10000010101010101000000010001000100010"
  1279. "00000101000101010100010000010100010000"
  1280. "00001010101000000010100010001010000010"
  1281. "01010001000100000100010001010000010101"
  1282. "00001010001010001000000000101010100010"
  1283. "01010101010000000100010101010000010100"
  1284. "00101010100010000010100010000010000010"
  1285. "01010000010100010001010000010000010101"
  1286. "10000010100000001010100000100010001010"
  1287. },
  1288. /* 7*/ { UNICODE_MODE, 29, -1, { 0, 0, "" }, { { TU("çèéêëì"), -1, 0 }, { TU("òóô"), -1, 899 }, { TU(""), 0, 0 } }, 0, 20, 29, 1, 0, "BIN_LATCH ECI > 0xFF; ZXing-C++ test can't handle binary",
  1289. "10001010001010101000000010001"
  1290. "01000001000100010100010101010"
  1291. "10000000100000100000000010101"
  1292. "00010100010001000101010000000"
  1293. "10001000000000001010101010101"
  1294. "00000100010100010000010101000"
  1295. "10001000101000001000100000000"
  1296. "01010101000101010101000101010"
  1297. "10101010101010000010001010000"
  1298. "00000001000001010101010001010"
  1299. "10001000000010100000101010101"
  1300. "01000001010100010101010100000"
  1301. "00000010101000101000000000101"
  1302. "01000101000001000100000000000"
  1303. "00100010000010100010100000101"
  1304. "01010000010101000101010100010"
  1305. "10100000100010000010001000001"
  1306. "01010101000000000100000001010"
  1307. "10101000101010000010001010001"
  1308. "01010101010100010001010001010"
  1309. },
  1310. /* 8*/ { UNICODE_MODE, 29, -1, { 0, 0, "" }, { { TU("çèéêëì"), -1, 0 }, { TU("òóô"), -1, 65536 }, { TU(""), 0, 0 } }, 0, 22, 29, 1, 0, "BIN_LATCH ECI > 0xFFFF; ZXing-C++ test can't handle binary",
  1311. "10101000100000101000001010001"
  1312. "00010101000000000100010100000"
  1313. "10100010001010000010101010100"
  1314. "00010100010101000100010001010"
  1315. "00001000001010101010101010101"
  1316. "00010000000001000100010100010"
  1317. "10001000001010000010000010001"
  1318. "00000001010101010000000101010"
  1319. "10101010101000001010100010101"
  1320. "01000100000100010001010001000"
  1321. "10000000000000101010100000001"
  1322. "00010101000101000001000001000"
  1323. "00101010101000100000001000101"
  1324. "00010001010001000101000100010"
  1325. "00000000100010100010000000001"
  1326. "01000001000100000000010101010"
  1327. "10100010100010001010001010101"
  1328. "01000100010001010100010100000"
  1329. "10101010001000100010100000101"
  1330. "01000001000000010001000001000"
  1331. "10001010101000101010000010001"
  1332. "01010101010101010001010000010"
  1333. },
  1334. /* 9*/ { UNICODE_MODE, -1, -1, { 0, 0, "" }, { { TU("[)>\03605\035"), -1, 0 }, { TU("A\036\004"), -1, 0 }, { TU(""), 0, 0 } }, 0, 10, 13, 1, 1, "Macro 05",
  1335. "1010001010101"
  1336. "0001000001010"
  1337. "1010100010001"
  1338. "0000000001000"
  1339. "1000101000100"
  1340. "0101010101000"
  1341. "1000001000001"
  1342. "0100010000010"
  1343. "0000100000100"
  1344. "0001010101010"
  1345. },
  1346. /* 10*/ { UNICODE_MODE, -1, -1, { 0, 0, "" }, { { TU("[)>\03605\035"), -1, 0 }, { TU("Študentska št."), -1, 4 }, { TU("\0352198390\036\004"), -1, 0 } }, 0, 24, 35, 1, 1, "Macro 05 with ECI",
  1347. "10101000000010101000000000101010001"
  1348. "00010100000001000000000101010001010"
  1349. "00000010001000000010100010001000101"
  1350. "00000000010100010101000001010001010"
  1351. "00000010101010000000101010100010000"
  1352. "00010000000101000101010001000100000"
  1353. "10001000000000001010100000001000101"
  1354. "01000001010101010100000101010101010"
  1355. "00100010000010100010001010101000000"
  1356. "00010101010000000001010100010101000"
  1357. "00101000100010001000001000100010101"
  1358. "00010000010101010000010001010100000"
  1359. "10100010101010101010000010000000001"
  1360. "01010100000100010100000100000000010"
  1361. "10001000100010100010101000001010101"
  1362. "01010101010000000101000001000100010"
  1363. "10001010101000001010101000001000100"
  1364. "01000101010101000101010101010101000"
  1365. "10101010101000100010100000000000000"
  1366. "01000101010000000000010000000001000"
  1367. "00100010001000101000100010101000100"
  1368. "01000000000101010101010100000101010"
  1369. "10001010000010100000001010000010001"
  1370. "01010001000001010001010001010101010"
  1371. },
  1372. /* 11*/ { UNICODE_MODE, -1, -1, { 35, 35, "" }, { { TU("Τεχτ"), -1, 9 }, { TU("กขฯ"), -1, 0 }, { TU(""), 0, 0 } }, ZINT_WARN_USES_ECI, 20, 29, 0, 1, "Structured Append with Terminate Latch A replaced",
  1373. "10101000001010000000001000101"
  1374. "01010101010101000000000100000"
  1375. "00101010001010100010101010001"
  1376. "01000100010000000101010100010"
  1377. "10000010100010001000100000000"
  1378. "00010000010101010100000101010"
  1379. "10100010101010101010001000001"
  1380. "00010101000000010101010001000"
  1381. "10000000100000101000101000101"
  1382. "01010000010001010001000100010"
  1383. "00101000000000100010001010101"
  1384. "01000001000101010001000001010"
  1385. "00001010000000000000100010101"
  1386. "00000101010101000100010001000"
  1387. "00101000001010001000001010101"
  1388. "01010101010100000100010001000"
  1389. "10000000101000100010100010001"
  1390. "00000000000000010001010101000"
  1391. "10101010001010101010100000001"
  1392. "01000101000001010100000100010"
  1393. },
  1394. };
  1395. const int data_size = ARRAY_SIZE(data);
  1396. int i, j, seg_count, ret;
  1397. struct zint_symbol *symbol = NULL;
  1398. char escaped[1024];
  1399. char cmp_buf[8192];
  1400. char cmp_msg[1024];
  1401. int do_bwipp = (debug & ZINT_DEBUG_TEST_BWIPP) && testUtilHaveGhostscript(); /* Only do BWIPP test if asked, too slow otherwise */
  1402. int do_zxingcpp = (debug & ZINT_DEBUG_TEST_ZXINGCPP) && testUtilHaveZXingCPPDecoder(); /* Only do ZXing-C++ test if asked, too slow otherwise */
  1403. testStartSymbol("test_encode_segs", &symbol);
  1404. for (i = 0; i < data_size; i++) {
  1405. if (testContinue(p_ctx, i)) continue;
  1406. symbol = ZBarcode_Create();
  1407. assert_nonnull(symbol, "Symbol not created\n");
  1408. testUtilSetSymbol(symbol, BARCODE_DOTCODE, data[i].input_mode, -1 /*eci*/,
  1409. -1 /* option_1*/, data[i].option_2, data[i].option_3, -1 /*output_options*/, NULL, 0, debug);
  1410. if (data[i].structapp.count) {
  1411. symbol->structapp = data[i].structapp;
  1412. }
  1413. for (j = 0, seg_count = 0; j < 3 && data[i].segs[j].length; j++, seg_count++);
  1414. ret = ZBarcode_Encode_Segs(symbol, data[i].segs, seg_count);
  1415. assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode_Segs ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
  1416. if (p_ctx->generate) {
  1417. char escaped1[4096];
  1418. char escaped2[4096];
  1419. int length = data[i].segs[0].length == -1 ? (int) ustrlen(data[i].segs[0].source) : data[i].segs[0].length;
  1420. int length1 = data[i].segs[1].length == -1 ? (int) ustrlen(data[i].segs[1].source) : data[i].segs[1].length;
  1421. int length2 = data[i].segs[2].length == -1 ? (int) ustrlen(data[i].segs[2].source) : data[i].segs[2].length;
  1422. printf(" /*%3d*/ { %s, %d, %s, { %d, %d, \"%s\" }, { { TU(\"%s\"), %d, %d }, { TU(\"%s\"), %d, %d }, { TU(\"%s\"), %d, %d } }, %s, %d, %d, %d, %d, \"%s\",\n",
  1423. i, testUtilInputModeName(data[i].input_mode), data[i].option_2,
  1424. testUtilOption3Name(BARCODE_DOTCODE, data[i].option_3),
  1425. data[i].structapp.index, data[i].structapp.count, data[i].structapp.id,
  1426. testUtilEscape((const char *) data[i].segs[0].source, length, escaped, sizeof(escaped)), data[i].segs[0].length, data[i].segs[0].eci,
  1427. testUtilEscape((const char *) data[i].segs[1].source, length1, escaped1, sizeof(escaped1)), data[i].segs[1].length, data[i].segs[1].eci,
  1428. testUtilEscape((const char *) data[i].segs[2].source, length2, escaped2, sizeof(escaped2)), data[i].segs[2].length, data[i].segs[2].eci,
  1429. testUtilErrorName(data[i].ret), symbol->rows, symbol->width, data[i].bwipp_cmp, data[i].zxingcpp_cmp, data[i].comment);
  1430. testUtilModulesPrint(symbol, " ", "\n");
  1431. printf(" },\n");
  1432. } else {
  1433. if (ret < ZINT_ERROR) {
  1434. int width, row;
  1435. assert_equal(symbol->rows, data[i].expected_rows, "i:%d symbol->rows %d != %d\n", i, symbol->rows, data[i].expected_rows);
  1436. assert_equal(symbol->width, data[i].expected_width, "i:%d symbol->width %d != %d\n", i, symbol->width, data[i].expected_width);
  1437. ret = testUtilModulesCmp(symbol, data[i].expected, &width, &row);
  1438. assert_zero(ret, "i:%d testUtilModulesCmp ret %d != 0 width %d row %d\n", i, ret, width, row);
  1439. if (do_bwipp && testUtilCanBwipp(i, symbol, -1, data[i].option_2, data[i].option_3, debug)) {
  1440. if (!data[i].bwipp_cmp) {
  1441. if (debug & ZINT_DEBUG_TEST_PRINT) printf("i:%d %s not BWIPP compatible (%s)\n", i, testUtilBarcodeName(symbol->symbology), data[i].comment);
  1442. } else {
  1443. ret = testUtilBwippSegs(i, symbol, -1, data[i].option_2, data[i].option_3, data[i].segs, seg_count, NULL, cmp_buf, sizeof(cmp_buf));
  1444. assert_zero(ret, "i:%d %s testUtilBwippSegs ret %d != 0\n", i, testUtilBarcodeName(symbol->symbology), ret);
  1445. ret = testUtilBwippCmp(symbol, cmp_msg, cmp_buf, data[i].expected);
  1446. assert_zero(ret, "i:%d %s testUtilBwippCmp %d != 0 %s\n actual: %s\nexpected: %s\n",
  1447. i, testUtilBarcodeName(symbol->symbology), ret, cmp_msg, cmp_buf, data[i].expected);
  1448. }
  1449. }
  1450. if (do_zxingcpp && testUtilCanZXingCPP(i, symbol, (const char *) data[i].segs[0].source, data[i].segs[0].length, debug)) {
  1451. if (!data[i].zxingcpp_cmp) {
  1452. if (debug & ZINT_DEBUG_TEST_PRINT) printf("i:%d %s not ZXing-C++ compatible (%s)\n", i, testUtilBarcodeName(symbol->symbology), data[i].comment);
  1453. } else if (data[i].input_mode == DATA_MODE) {
  1454. if (debug & ZINT_DEBUG_TEST_PRINT) {
  1455. printf("i:%d multiple segments in DATA_MODE not currently supported for ZXing-C++ testing (%s)\n",
  1456. i, testUtilBarcodeName(symbol->symbology));
  1457. }
  1458. } else {
  1459. int cmp_len, ret_len;
  1460. char modules_dump[16384];
  1461. assert_notequal(testUtilModulesDump(symbol, modules_dump, sizeof(modules_dump)), -1, "i:%d testUtilModulesDump == -1\n", i);
  1462. ret = testUtilZXingCPP(i, symbol, (const char *) data[i].segs[0].source, data[i].segs[0].length,
  1463. modules_dump, cmp_buf, sizeof(cmp_buf), &cmp_len);
  1464. assert_zero(ret, "i:%d %s testUtilZXingCPP ret %d != 0\n", i, testUtilBarcodeName(symbol->symbology), ret);
  1465. ret = testUtilZXingCPPCmpSegs(symbol, cmp_msg, cmp_buf, cmp_len, data[i].segs, seg_count,
  1466. NULL /*primary*/, escaped, &ret_len);
  1467. assert_zero(ret, "i:%d %s testUtilZXingCPPCmpSegs %d != 0 %s\n actual: %.*s\nexpected: %.*s\n",
  1468. i, testUtilBarcodeName(symbol->symbology), ret, cmp_msg, cmp_len, cmp_buf, ret_len, escaped);
  1469. }
  1470. }
  1471. }
  1472. }
  1473. ZBarcode_Delete(symbol);
  1474. }
  1475. testFinish();
  1476. }
  1477. /* #181 Christian Hartlage / Nico Gunkel OSS-Fuzz */
  1478. static void test_fuzz(const testCtx *const p_ctx) {
  1479. int debug = p_ctx->debug;
  1480. struct item {
  1481. int input_mode;
  1482. char *data;
  1483. int length;
  1484. int ret;
  1485. };
  1486. /* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */
  1487. static const struct item data[] = {
  1488. /* 0*/ { DATA_MODE, "(\207'", -1, 0 }, /* 0x28,0x87,0x27 Note: should but doesn't trigger sanitize error if no length check, for some reason; UPDATE: use up-to-date gcc (9)! */
  1489. /* 1*/ { DATA_MODE,
  1490. "\133\061\106\133\061\106\070\161\116\133\116\116\067\040\116\016\000\116\125\111\125\125\316\125\125\116\116\116\116\117\116\125"
  1491. "\111\125\103\316\125\125\116\116\116\116\117\000\000\116\136\116\116\001\116\316\076\116\116\057\136\116\116\134\000\000\116\116"
  1492. "\116\230\116\116\116\116\125\125\125\257\257\257\000\001\116\130\212\212\212\212\212\212\212\377\377\210\212\212\177\000\212\212"
  1493. "\212\212\212\212\175\212\212\212\212\212\212\116\117\001\116\116\112\116\116\116\116\176\136\000\000\000\000\000\000\000\000\000"
  1494. "\000\000\000\000\000\000\000\000\005\377\377\005\125\125\125\325\001\116\116\116\266\116\020\000\200\000\116\116\177\000\000\377"
  1495. "\377\257\257\257\125\112\117\116\001\000\000\044\241\001\116\116\116\136\116\116\116\056\116\125\111\125\125\316\125\125\116\116"
  1496. "\116\116\057\000\000\116\136\116\116\001\116\116\076\342\116\057\136\116\116\134\000\000\116\116\116\241\116\116\116\116\125\125"
  1497. "\125\257\257\257\000\001\116\130\212\212\212\212\212\212\212\212\172\212\071\071\071\071\071\071\071\071\071\071\071\071\071\071"
  1498. "\071\071\071\071\071\110\071\071\051\071\065\071\071\071\071\071\071\071\071\071\071\071\071\071\071\071\071\071\071\071\071\071"
  1499. "\071\071\071\071\071\330\330\330\330\330\330\330\330\330\330\330\330\330\330\330\330\330\330\330\330\330\330\330\330\330\330\330"
  1500. "\330\330\071\071\071\071\071\071\071\071\071\071\071\071\071\071\071\071\065\071\071\071\071\071\071\071\071\071\071\071\071\071"
  1501. "\071\071\071\071\071\072\071\071\277\071\071\077\071\071\071\071\071\071\071\071\154\071\071\071\071\071\071\071\071\071\071\071"
  1502. "\071\071\071\011\071\071\071\071\071\071\071\071\071\071\071\071\071\071\105\105\105\105\105\105\105\105\105\105\105\105\105\071"
  1503. "\071\071\071\071\071", /* Original OSS-Fuzz triggering data for index out of bounds (encoding of HT/FS/GS/RS when shifting to code set B) */
  1504. 421, 0 },
  1505. /* 2*/ { DATA_MODE, "\233:", -1, 0 }, /* Original OSS-Fuzz triggering data for codeword_array buffer overflow, L777 */
  1506. /* 3*/ { DATA_MODE, "\241\034", -1, 0 }, /* As above L793 */
  1507. /* 4*/ { DATA_MODE, "\270\036", -1, 0 }, /* As above L799 */
  1508. /* 5*/ { DATA_MODE, "\237\032", -1, 0 }, /* As above L904 */
  1509. /* 6*/ { DATA_MODE, "\237", -1, 0 }, /* As above L1090 */
  1510. };
  1511. const int data_size = ARRAY_SIZE(data);
  1512. int i, length, ret;
  1513. struct zint_symbol *symbol = NULL;
  1514. testStartSymbol("test_fuzz", &symbol);
  1515. for (i = 0; i < data_size; i++) {
  1516. if (testContinue(p_ctx, i)) continue;
  1517. symbol = ZBarcode_Create();
  1518. assert_nonnull(symbol, "Symbol not created\n");
  1519. length = testUtilSetSymbol(symbol, BARCODE_DOTCODE, data[i].input_mode, -1 /*eci*/, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data[i].data, data[i].length, debug);
  1520. ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length);
  1521. assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
  1522. ZBarcode_Delete(symbol);
  1523. }
  1524. testFinish();
  1525. }
  1526. #define GF 113
  1527. /* Dummy to generate pre-calculated coefficients for GF(113) of generator polys of degree 3 to 39 */
  1528. static void test_generate(const testCtx *const p_ctx) {
  1529. /* roots (antilogs): root[0] = 1; for (i = 1; i < GF - 1; i++) root[i] = (PM * root[i - 1]) % GF; */
  1530. static const int root[GF - 1] = {
  1531. 1, 3, 9, 27, 81, 17, 51, 40, 7, 21,
  1532. 63, 76, 2, 6, 18, 54, 49, 34, 102, 80,
  1533. 14, 42, 13, 39, 4, 12, 36, 108, 98, 68,
  1534. 91, 47, 28, 84, 26, 78, 8, 24, 72, 103,
  1535. 83, 23, 69, 94, 56, 55, 52, 43, 16, 48,
  1536. 31, 93, 53, 46, 25, 75, 112, 110, 104, 86,
  1537. 32, 96, 62, 73, 106, 92, 50, 37, 111, 107,
  1538. 95, 59, 64, 79, 11, 33, 99, 71, 100, 74,
  1539. 109, 101, 77, 5, 15, 45, 22, 66, 85, 29,
  1540. 87, 35, 105, 89, 41, 10, 30, 90, 44, 19,
  1541. 57, 58, 61, 70, 97, 65, 82, 20, 60, 67,
  1542. 88, 38
  1543. };
  1544. int i, j, nc, cind, ci;
  1545. /* Degree nc has nc + 1 terms */
  1546. char coefs[820 - 5] = {0}; /* 40*(41 + 1)/2 == 820 less 2 + 3 (degrees 1 and 2) */
  1547. int cinds[39 - 2] = {0};
  1548. if (!p_ctx->generate) {
  1549. return;
  1550. }
  1551. printf(" static const char coefs[820 - 5] = { /* 40*(41 + 1)/2 == 820 less 2 + 3 (degrees 1 and 2) */\n");
  1552. for (nc = 3, cind = 0, ci = 0; nc <= 39; cind += nc + 1, ci++, nc++) {
  1553. cinds[ci] = cind;
  1554. coefs[cind] = 1;
  1555. for (i = 1; i <= nc; i++) {
  1556. for (j = nc; j >= 1; j--) {
  1557. coefs[cind + j] = (GF + coefs[cind + j] - (root[i] * coefs[cind + j - 1]) % GF) % GF;
  1558. }
  1559. }
  1560. printf(" ");
  1561. for (i = 0; i <= nc; i++) {
  1562. if (i == 22) printf("\n ");
  1563. printf(" %3d,", coefs[cinds[ci] + i]);
  1564. }
  1565. printf("\n");
  1566. }
  1567. printf(" };\n");
  1568. printf(" static const short cinds[39 - 2] = { /* Indexes into above coefs[] array */\n ");
  1569. for (i = 0; i < ARRAY_SIZE(cinds); i++) {
  1570. if (i == 22) printf("\n ");
  1571. printf(" %3d,", cinds[i]);
  1572. }
  1573. printf("\n };\n");
  1574. }
  1575. #include <time.h>
  1576. #define TEST_PERF_ITERATIONS 1000
  1577. /* Not a real test, just performance indicator */
  1578. static void test_perf(const testCtx *const p_ctx) {
  1579. int debug = p_ctx->debug;
  1580. struct item {
  1581. int symbology;
  1582. int input_mode;
  1583. int option_1;
  1584. int option_2;
  1585. char *data;
  1586. int ret;
  1587. int expected_rows;
  1588. int expected_width;
  1589. char *comment;
  1590. };
  1591. static const struct item data[] = {
  1592. /* 0*/ { BARCODE_DOTCODE, -1, -1, -1,
  1593. "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890abcdefghijklmnopqrstuvwxyz&,:#-.$/+%*=^ABCDEFGHIJKLMNOPQRSTUVWXYZ12345678901234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLM"
  1594. "NOPQRSTUVWXYZ;<>@[]_`~!||()?{}'123456789012345678901234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJK"
  1595. "LMNOPQRSTUVWXYZ12345678912345678912345678912345678900001234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890abcdefghijklmnopqrstuvwxyzABCDEFG"
  1596. "HIJKLMNOPQRSTUVWXYZ1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ12345678901234567"
  1597. "890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890abcde"
  1598. "fghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNO",
  1599. 0, 124, 185, "960 chars, text/numeric" },
  1600. };
  1601. const int data_size = ARRAY_SIZE(data);
  1602. int i, length, ret;
  1603. clock_t start, total_encode = 0, total_buffer = 0, diff_encode, diff_buffer;
  1604. if (!(debug & ZINT_DEBUG_TEST_PERFORMANCE)) { /* -d 256 */
  1605. return;
  1606. }
  1607. for (i = 0; i < data_size; i++) {
  1608. int j;
  1609. if (testContinue(p_ctx, i)) continue;
  1610. diff_encode = diff_buffer = 0;
  1611. for (j = 0; j < TEST_PERF_ITERATIONS; j++) {
  1612. struct zint_symbol *symbol = ZBarcode_Create();
  1613. assert_nonnull(symbol, "Symbol not created\n");
  1614. 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);
  1615. start = clock();
  1616. ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length);
  1617. diff_encode += clock() - start;
  1618. assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
  1619. 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);
  1620. 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);
  1621. start = clock();
  1622. ret = ZBarcode_Buffer(symbol, 0 /*rotate_angle*/);
  1623. diff_buffer += clock() - start;
  1624. assert_zero(ret, "i:%d ZBarcode_Buffer ret %d != 0 (%s)\n", i, ret, symbol->errtxt);
  1625. ZBarcode_Delete(symbol);
  1626. }
  1627. printf("%s: diff_encode %gms, diff_buffer %gms\n", data[i].comment, diff_encode * 1000.0 / CLOCKS_PER_SEC, diff_buffer * 1000.0 / CLOCKS_PER_SEC);
  1628. total_encode += diff_encode;
  1629. total_buffer += diff_buffer;
  1630. }
  1631. if (p_ctx->index != -1) {
  1632. printf("totals: encode %gms, buffer %gms\n", total_encode * 1000.0 / CLOCKS_PER_SEC, total_buffer * 1000.0 / CLOCKS_PER_SEC);
  1633. }
  1634. }
  1635. int main(int argc, char *argv[]) {
  1636. testFunction funcs[] = { /* name, func */
  1637. { "test_large", test_large },
  1638. { "test_options", test_options },
  1639. { "test_input", test_input },
  1640. { "test_encode", test_encode },
  1641. { "test_encode_segs", test_encode_segs },
  1642. { "test_fuzz", test_fuzz },
  1643. { "test_generate", test_generate },
  1644. { "test_perf", test_perf },
  1645. };
  1646. testRun(argc, argv, funcs, ARRAY_SIZE(funcs));
  1647. testReport();
  1648. return 0;
  1649. }
  1650. /* vim: set ts=4 sw=4 et : */