test_qzint.cpp 67 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401
  1. /***************************************************************************
  2. * Copyright (C) 2021-2024 by Robin Stuart <rstuart114@gmail.com> *
  3. * *
  4. * This program is free software: you can redistribute it and/or modify *
  5. * it under the terms of the GNU General Public License as published by *
  6. * the Free Software Foundation, either version 3 of the License, or *
  7. * (at your option) any later version. *
  8. * This program is distributed in the hope that it will be useful, *
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of *
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
  11. * GNU General Public License for more details. *
  12. * You should have received a copy of the GNU General Public License *
  13. * along with this program. If not, see <http://www.gnu.org/licenses/>. *
  14. ***************************************************************************/
  15. /* SPDX-License-Identifier: GPL-3.0-or-later */
  16. #include <QtTest/QSignalSpy>
  17. #include <QtTest/QTest>
  18. #include "../qzint.h" /* Don't use <qzint.h> in case it's been changed */
  19. #define ARRAY_SIZE(x) ((int) (sizeof(x) / sizeof((x)[0])))
  20. // Whether using ZINT_SANITIZE
  21. #if !defined(__has_feature)
  22. # define __has_feature(x) 0
  23. #endif
  24. #if defined(__SANITIZE_ADDRESS__) || __has_feature(address_sanitizer)
  25. # define TESTQZINT_HAVE_ASAN
  26. #endif
  27. class TestQZint : public QObject
  28. {
  29. Q_OBJECT
  30. // This avoids WaylandClient memory leaks for Qt5 > 5.15.2 (taken from "frontend_qt/main.cpp")
  31. #if defined(__linux__) && QT_VERSION > 0x50F02
  32. public:
  33. static void initMain()
  34. {
  35. /* Not compatible with Wayland for some reason(s) so use X11 unless overridden */
  36. if (qEnvironmentVariableIsEmpty("QT_QPA_PLATFORM")) {
  37. qputenv("QT_QPA_PLATFORM", QByteArrayLiteral("xcb"));
  38. }
  39. }
  40. #endif
  41. public:
  42. TestQZint() : m_skipIfFontUsed(false)
  43. {
  44. // Qt will trigger "detected memory leaks" if font used (libfontconfig) so skip if ASAN enabled
  45. #ifdef TESTQZINT_HAVE_ASAN
  46. m_skipIfFontUsed = true;
  47. #endif
  48. // Unfortunately Qt5 > 5.15.13 & Qt6 > 6.4.2 have further libfontconfig leaks which this doesn't address...
  49. // ...only option found so far is to use `QTEST_GUILESS_MAIN()` and skip `renderTest()` completely
  50. #if defined(__linux__) && ((QT_VERSION > 0x50F0D && QT_VERSION < 0x60000) || QT_VERSION > 0x60402) \
  51. && defined(TESTQZINT_HAVE_ASAN)
  52. #define TESTQZINT_GUILESS
  53. #endif
  54. }
  55. virtual ~TestQZint() {} // Seems to be needed to generate vtable
  56. private:
  57. bool m_skipIfFontUsed; // Hack to get around Qt5 ASAN leaks
  58. private slots:
  59. void setGetTest()
  60. {
  61. Zint::QZint bc;
  62. int symbology = BARCODE_CODE11;
  63. bc.setSymbol(symbology);
  64. QCOMPARE(bc.symbol(), symbology);
  65. int inputMode = UNICODE_MODE;
  66. bc.setInputMode(inputMode);
  67. QCOMPARE(bc.inputMode(), inputMode);
  68. QString text("text");
  69. bc.setText(text);
  70. QCOMPARE(bc.text(), text);
  71. QCOMPARE(bc.segs().empty(), true);
  72. std::vector<QString> segTexts;
  73. std::vector<int> segECIs;
  74. segTexts.push_back(QString("Τεχτ"));
  75. segECIs.push_back(9);
  76. segTexts.push_back(QString("貫やぐ禁"));
  77. segECIs.push_back(20);
  78. segTexts.push_back(QString("กขฯ"));
  79. segECIs.push_back(13);
  80. std::vector<Zint::QZintSeg> segs;
  81. for (int i = 0; i < (int) segTexts.size(); i++) {
  82. segs.push_back(Zint::QZintSeg(segTexts[i]));
  83. segs.back().m_eci = segECIs[i];
  84. }
  85. bc.setSegs(segs);
  86. QCOMPARE(bc.segs().size(), segs.size());
  87. for (int i = 0; i < (int) segs.size(); i++) {
  88. QCOMPARE(bc.segs()[i].m_text, segTexts[i]);
  89. QCOMPARE(bc.segs()[i].m_eci, segECIs[i]);
  90. }
  91. QCOMPARE(bc.text().isEmpty(), true);
  92. QCOMPARE(bc.eci(), segECIs[0]);
  93. bc.setText(text);
  94. QCOMPARE(bc.text(), text);
  95. QCOMPARE(bc.segs().empty(), true);
  96. QString primaryMessage("primary message");
  97. bc.setPrimaryMessage(primaryMessage);
  98. QCOMPARE(bc.primaryMessage(), primaryMessage);
  99. float height = 12.345f;
  100. bc.setHeight(height);
  101. QCOMPARE(bc.height(), height);
  102. int option1 = 1;
  103. bc.setOption1(option1);
  104. QCOMPARE(bc.option1(), option1);
  105. int option2 = 2;
  106. bc.setOption2(option2);
  107. QCOMPARE(bc.option2(), option2);
  108. int option3 = 3;
  109. bc.setOption3(option3);
  110. QCOMPARE(bc.option3(), option3);
  111. float scale = 0.678f;
  112. bc.setScale(scale);
  113. QCOMPARE(bc.scale(), scale);
  114. float dpmm = 11.811f;
  115. bc.setDPMM(dpmm);
  116. QCOMPARE(bc.dpmm(), dpmm);
  117. bool dotty = true;
  118. bc.setDotty(dotty);
  119. QCOMPARE(bc.dotty(), dotty);
  120. float dotSize = 1.234f;
  121. bc.setDotSize(dotSize);
  122. QCOMPARE(bc.dotSize(), dotSize);
  123. float textGap = 4.321f;
  124. bc.setTextGap(textGap);
  125. QCOMPARE(bc.textGap(), textGap);
  126. float guardDescent = 0.678f;
  127. bc.setGuardDescent(guardDescent);
  128. QCOMPARE(bc.guardDescent(), guardDescent);
  129. struct zint_structapp structapp = { 2, 3, "ID" };
  130. bc.setStructApp(structapp.count, structapp.index, structapp.id);
  131. QCOMPARE(bc.structAppCount(), structapp.count);
  132. QCOMPARE(bc.structAppIndex(), structapp.index);
  133. QCOMPARE(bc.structAppID(), QString(structapp.id));
  134. QString fgStr("12344567");
  135. bc.setFgStr(fgStr);
  136. QCOMPARE(bc.fgStr(), fgStr);
  137. QColor fgColor(0x12, 0x34, 0x45, 0x67);
  138. bc.setFgColor(fgColor);
  139. QCOMPARE(bc.fgColor(), fgColor);
  140. QCOMPARE(bc.fgStr(), fgStr);
  141. QString bgStr("89ABCDEF");
  142. bc.setBgStr(bgStr);
  143. QCOMPARE(bc.bgStr(), bgStr);
  144. QColor bgColor(0x89, 0xAB, 0xCD, 0xEF);
  145. bc.setBgColor(bgColor);
  146. QCOMPARE(bc.bgColor(), bgColor);
  147. QCOMPARE(bc.bgStr(), bgStr);
  148. QString bgStr2("71,0,40,44");
  149. bc.setBgStr(bgStr2);
  150. QCOMPARE(bc.bgStr(), bgStr2);
  151. bool cmyk = true;
  152. bc.setCMYK(cmyk);
  153. QCOMPARE(bc.cmyk(), cmyk);
  154. int borderTypes[] = { 0, BARCODE_BIND, BARCODE_BOX, BARCODE_BIND_TOP };
  155. for (int i = 0; i < ARRAY_SIZE(borderTypes); i++) {
  156. bc.setBorderType(i);
  157. QCOMPARE(bc.borderType(), borderTypes[i]);
  158. }
  159. int borderWidth = 4;
  160. bc.setBorderWidth(borderWidth);
  161. QCOMPARE(bc.borderWidth(), borderWidth);
  162. int whitespace = 5;
  163. bc.setWhitespace(whitespace);
  164. QCOMPARE(bc.whitespace(), whitespace);
  165. int vWhitespace = 6;
  166. bc.setVWhitespace(vWhitespace);
  167. QCOMPARE(bc.vWhitespace(), vWhitespace);
  168. int fontSettings[] = { 0, BOLD_TEXT, SMALL_TEXT, SMALL_TEXT | BOLD_TEXT };
  169. for (int i = 0; i < ARRAY_SIZE(fontSettings); i++) {
  170. bc.setFontSetting(i);
  171. QCOMPARE(bc.fontSetting(), fontSettings[i]);
  172. bc.setFontSettingValue(fontSettings[i]);
  173. QCOMPARE(bc.fontSetting(), fontSettings[i]);
  174. }
  175. bc.setFontSetting(ARRAY_SIZE(fontSettings));
  176. QCOMPARE(bc.fontSetting(), 0);
  177. bc.setFontSetting(-1);
  178. QCOMPARE(bc.fontSetting(), 0);
  179. bc.setFontSettingValue(-1);
  180. QCOMPARE(bc.fontSetting(), 0);
  181. bc.setFontSettingValue(CMYK_COLOUR);
  182. QCOMPARE(bc.fontSetting(), 0);
  183. bool showText = false;
  184. bc.setShowText(showText);
  185. QCOMPARE(bc.showText(), showText);
  186. bool gsSep = true;
  187. bc.setGSSep(gsSep);
  188. QCOMPARE(bc.gsSep(), gsSep);
  189. bool quietZones = true;
  190. bc.setQuietZones(quietZones);
  191. QCOMPARE(bc.quietZones(), quietZones);
  192. bool noQuietZones = true;
  193. bc.setNoQuietZones(noQuietZones);
  194. QCOMPARE(bc.noQuietZones(), noQuietZones);
  195. bool compliantHeight = true;
  196. bc.setCompliantHeight(compliantHeight);
  197. QCOMPARE(bc.compliantHeight(), compliantHeight);
  198. int rotateAngles[] = { 0, 90, 180, 270 };
  199. for (int i = 0; i < ARRAY_SIZE(rotateAngles); i++) {
  200. bc.setRotateAngle(i);
  201. QCOMPARE(bc.rotateAngle(), rotateAngles[i]);
  202. bc.setRotateAngleValue(rotateAngles[i]);
  203. QCOMPARE(bc.rotateAngle(), rotateAngles[i]);
  204. }
  205. bc.setRotateAngle(ARRAY_SIZE(rotateAngles));
  206. QCOMPARE(bc.rotateAngle(), 0);
  207. bc.setRotateAngle(-1);
  208. QCOMPARE(bc.rotateAngle(), 0);
  209. bc.setRotateAngleValue(-1);
  210. QCOMPARE(bc.rotateAngle(), 0);
  211. bc.setRotateAngleValue(45);
  212. QCOMPARE(bc.rotateAngle(), 0);
  213. int ecis[] = {
  214. 0, 3, 4, 5, 6, 7, 8, 9, 10, 11,
  215. 12, 13, 15, 16, 17, 18, 20, 21, 22, 23,
  216. 24, 25, 26, 27, 28, 29, 30, 31, 32, 33,
  217. 34, 35, 170, 899,
  218. };
  219. for (int i = 0; i < ARRAY_SIZE(ecis); i++) {
  220. bc.setECI(i);
  221. QCOMPARE(bc.eci(), ecis[i]);
  222. bc.setECIValue(ecis[i]);
  223. QCOMPARE(bc.eci(), ecis[i]);
  224. }
  225. bc.setECI(ARRAY_SIZE(ecis));
  226. QCOMPARE(bc.eci(), 0);
  227. bc.setECI(-1);
  228. QCOMPARE(bc.eci(), 0);
  229. // See also setGetECIValueTest()
  230. bool gs1Parens = true;
  231. bc.setGS1Parens(gs1Parens);
  232. QCOMPARE(bc.gs1Parens(), gs1Parens);
  233. bool gs1NoCheck = true;
  234. bc.setGS1NoCheck(gs1NoCheck);
  235. QCOMPARE(bc.gs1NoCheck(), gs1NoCheck);
  236. bool readerInit = true;
  237. bc.setReaderInit(readerInit);
  238. QCOMPARE(bc.readerInit(), readerInit);
  239. bool guardWhitespace = true;
  240. bc.setGuardWhitespace(guardWhitespace);
  241. QCOMPARE(bc.guardWhitespace(), guardWhitespace);
  242. bool embedVectorFont = true;
  243. bc.setEmbedVectorFont(embedVectorFont);
  244. QCOMPARE(bc.embedVectorFont(), embedVectorFont);
  245. int warnLevel = WARN_FAIL_ALL;
  246. bc.setWarnLevel(warnLevel);
  247. QCOMPARE(bc.warnLevel(), warnLevel);
  248. bool debug = true;
  249. bc.setDebug(debug);
  250. QCOMPARE(bc.debug(), debug);
  251. QCOMPARE(bc.encodedWidth(), 0); // Read-only
  252. QCOMPARE(bc.encodedRows(), 0); // Read-only
  253. QCOMPARE(bc.encodedHeight(), 0.0f); // Read-only
  254. QCOMPARE(bc.vectorWidth(), 0.0f); // Read-only
  255. QCOMPARE(bc.vectorHeight(), 0.0f); // Read-only
  256. QCOMPARE(bc.takesGS1AIData(BARCODE_CODE128), false);
  257. QCOMPARE(bc.takesGS1AIData(BARCODE_GS1_128), true);
  258. }
  259. void setGetECIValueTest_data()
  260. {
  261. QTest::addColumn<int>("value");
  262. QTest::addColumn<int>("eci");
  263. QTest::newRow("-1") << -1 << 0;
  264. QTest::newRow("0") << 0 << 0;
  265. QTest::newRow("1") << 1 << 0;
  266. QTest::newRow("2") << 2 << 0;
  267. QTest::newRow("14") << 14 << 0;
  268. QTest::newRow("19") << 19 << 0;
  269. QTest::newRow("31") << 31 << 31;
  270. QTest::newRow("36") << 36 << 0;
  271. QTest::newRow("169") << 169 << 0;
  272. QTest::newRow("171") << 171 << 0;
  273. QTest::newRow("898") << 898 << 0;
  274. QTest::newRow("900") << 900 << 0;
  275. QTest::newRow("1000") << 1000 << 0;
  276. }
  277. void setGetECIValueTest()
  278. {
  279. Zint::QZint bc;
  280. QFETCH(int, value);
  281. QFETCH(int, eci);
  282. bc.setECIValue(value);
  283. QCOMPARE(bc.eci(), eci);
  284. }
  285. void legacyTest()
  286. {
  287. Zint::QZint bc;
  288. int width = 12;
  289. bc.setWidth(width);
  290. QCOMPARE(bc.width(), width);
  291. QCOMPARE(bc.option2(), width);
  292. int securityLevel = 2;
  293. bc.setSecurityLevel(securityLevel);
  294. QCOMPARE(bc.securityLevel(), securityLevel);
  295. QCOMPARE(bc.option1(), securityLevel);
  296. int pdf417CodeWords = 123;
  297. bc.setPdf417CodeWords(pdf417CodeWords);
  298. QCOMPARE(bc.pdf417CodeWords(), 0); // No-op
  299. bool hideText = true;
  300. bc.setHideText(hideText);
  301. QCOMPARE(bc.showText(), !hideText);
  302. // No get for target size
  303. }
  304. void capTest_data()
  305. {
  306. QTest::addColumn<int>("symbology");
  307. QTest::addColumn<int>("cap_flag");
  308. QTest::newRow("BARCODE_CODE11") << BARCODE_CODE11
  309. << (ZINT_CAP_HRT | ZINT_CAP_STACKABLE);
  310. QTest::newRow("BARCODE_CODE128") << BARCODE_CODE128
  311. << (ZINT_CAP_HRT | ZINT_CAP_STACKABLE | ZINT_CAP_READER_INIT);
  312. QTest::newRow("BARCODE_EANX") << BARCODE_EANX
  313. << (ZINT_CAP_HRT | ZINT_CAP_STACKABLE | ZINT_CAP_EXTENDABLE | ZINT_CAP_QUIET_ZONES
  314. | ZINT_CAP_COMPLIANT_HEIGHT);
  315. QTest::newRow("BARCODE_EANX_CC") << BARCODE_EANX_CC
  316. << (ZINT_CAP_HRT | ZINT_CAP_EXTENDABLE | ZINT_CAP_COMPOSITE | ZINT_CAP_GS1 | ZINT_CAP_QUIET_ZONES
  317. | ZINT_CAP_COMPLIANT_HEIGHT);
  318. QTest::newRow("BARCODE_QRCODE") << BARCODE_QRCODE
  319. << (ZINT_CAP_ECI | ZINT_CAP_GS1 | ZINT_CAP_DOTTY | ZINT_CAP_FIXED_RATIO | ZINT_CAP_FULL_MULTIBYTE
  320. | ZINT_CAP_MASK | ZINT_CAP_STRUCTAPP);
  321. }
  322. void capTest()
  323. {
  324. Zint::QZint bc;
  325. QFETCH(int, symbology);
  326. QFETCH(int, cap_flag);
  327. bc.setSymbol(symbology);
  328. QCOMPARE(bc.hasHRT(), (cap_flag & ZINT_CAP_HRT) != 0);
  329. QCOMPARE(bc.isStackable(), (cap_flag & ZINT_CAP_STACKABLE) != 0);
  330. QCOMPARE(bc.isExtendable(), (cap_flag & ZINT_CAP_EXTENDABLE) != 0);
  331. QCOMPARE(bc.isComposite(), (cap_flag & ZINT_CAP_COMPOSITE) != 0);
  332. QCOMPARE(bc.supportsECI(), (cap_flag & ZINT_CAP_ECI) != 0);
  333. QCOMPARE(bc.supportsGS1(), (cap_flag & ZINT_CAP_GS1) != 0);
  334. QCOMPARE(bc.isDotty(), (cap_flag & ZINT_CAP_DOTTY) != 0);
  335. QCOMPARE(bc.hasDefaultQuietZones(), (cap_flag & ZINT_CAP_QUIET_ZONES) != 0);
  336. QCOMPARE(bc.isFixedRatio(), (cap_flag & ZINT_CAP_FIXED_RATIO) != 0);
  337. QCOMPARE(bc.supportsReaderInit(), (cap_flag & ZINT_CAP_READER_INIT) != 0);
  338. QCOMPARE(bc.supportsFullMultibyte(), (cap_flag & ZINT_CAP_FULL_MULTIBYTE) != 0);
  339. QCOMPARE(bc.hasMask(), (cap_flag & ZINT_CAP_MASK) != 0);
  340. QCOMPARE(bc.supportsStructApp(), (cap_flag & ZINT_CAP_STRUCTAPP) != 0);
  341. QCOMPARE(bc.hasCompliantHeight(), (cap_flag & ZINT_CAP_COMPLIANT_HEIGHT) != 0);
  342. }
  343. void renderTest_data()
  344. {
  345. QTest::addColumn<int>("symbology");
  346. QTest::addColumn<QString>("text");
  347. QTest::addColumn<float>("scale");
  348. QTest::addColumn<int>("getError");
  349. QTest::addColumn<QString>("error_message");
  350. QTest::addColumn<int>("encodedWidth");
  351. QTest::addColumn<int>("encodedRows");
  352. QTest::addColumn<float>("encodedHeight");
  353. QTest::addColumn<float>("vectorWidth");
  354. QTest::addColumn<float>("vectorHeight");
  355. QTest::newRow("BARCODE_CODE128") << BARCODE_CODE128 << "1234" << 0.0f << 0 << "" << 57 << 1 << 50.0f << 114.0f << 100.0f;
  356. QTest::newRow("BARCODE_CODE128 Scale 2") << BARCODE_CODE128 << "1234" << 2.0f << 0 << "" << 57 << 1 << 50.0f << 228.0f << 200.0f;
  357. QTest::newRow("BARCODE_QRCODE") << BARCODE_QRCODE << "1234" << 0.0f << 0 << "" << 21 << 21 << 21.0f << 42.0f << 42.0f;
  358. QTest::newRow("BARCODE_QRCODE Scale 1.5") << BARCODE_QRCODE << "1234" << 1.5f << 0 << "" << 21 << 21 << 21.0f << 63.0f << 63.0f;
  359. if (!m_skipIfFontUsed) {
  360. QTest::newRow("BARCODE_QRCODE no text") << BARCODE_QRCODE << "" << 0.0f << ZINT_ERROR_INVALID_DATA << "Error 228: No input data (segment 0 empty)" << 0 << 0 << 0.0f << 0.0f << 0.0f;
  361. }
  362. QTest::newRow("BARCODE_MAXICODE") << BARCODE_MAXICODE << "1234" << 0.0f << 0 << "" << 30 << 33 << 28.578f << 60.0f << 57.7334f;
  363. QTest::newRow("BARCODE_MAXICODE Scale 2") << BARCODE_MAXICODE << "1234" << 2.0f << 0 << "" << 30 << 33 << 28.578f << 120.0f << 115.467f;
  364. }
  365. void renderTest()
  366. {
  367. #ifdef TESTQZINT_GUILESS
  368. QSKIP("disabled on Linux for Qt5 > 5.15.13 & Qt6 > 6.4.2 due to memory leaks (ZINT_SANITIZE)");
  369. #endif
  370. Zint::QZint bc;
  371. bool bRet;
  372. QPainter painter;
  373. constexpr int width = 100, height = 100;
  374. QPixmap paintDevice(width, height);
  375. QRectF paintRect(0, 0, width, height);
  376. Zint::QZint::AspectRatioMode mode;
  377. QSignalSpy spyEncoded(&bc, SIGNAL(encoded()));
  378. QSignalSpy spyErrored(&bc, SIGNAL(errored()));
  379. mode = Zint::QZint::AspectRatioMode::KeepAspectRatio; // Legacy - ignored
  380. QFETCH(int, symbology);
  381. QFETCH(QString, text);
  382. QFETCH(float, scale);
  383. QFETCH(int, getError);
  384. QFETCH(QString, error_message);
  385. QFETCH(int, encodedWidth);
  386. QFETCH(int, encodedRows);
  387. QFETCH(float, encodedHeight);
  388. QFETCH(float, vectorWidth);
  389. QFETCH(float, vectorHeight);
  390. bc.setSymbol(symbology);
  391. bc.setText(text);
  392. bc.setShowText(false);
  393. if (scale) {
  394. bc.setScale(scale);
  395. }
  396. bRet = painter.begin(&paintDevice);
  397. QCOMPARE(bRet, true);
  398. bc.render(painter, paintRect, mode);
  399. bRet = painter.end();
  400. QCOMPARE(bRet, true);
  401. QCOMPARE(bc.getError(), getError);
  402. QCOMPARE(bc.error_message(), error_message);
  403. QCOMPARE(bc.lastError(), error_message);
  404. QCOMPARE(bc.hasErrors(), getError != 0);
  405. QCOMPARE(bc.encodedWidth(), encodedWidth);
  406. QCOMPARE(bc.encodedRows(), encodedRows);
  407. QCOMPARE(bc.encodedHeight(), encodedHeight);
  408. QCOMPARE(bc.vectorWidth(), vectorWidth);
  409. QCOMPARE(bc.vectorHeight(), vectorHeight);
  410. if (getError) {
  411. QCOMPARE(spyEncoded.count(), 0);
  412. QCOMPARE(spyErrored.count(), 1);
  413. } else {
  414. QCOMPARE(spyEncoded.count(), 1);
  415. QCOMPARE(spyErrored.count(), 0);
  416. }
  417. }
  418. void saveToFileTest_data()
  419. {
  420. QTest::addColumn<int>("symbology");
  421. QTest::addColumn<QString>("text");
  422. QTest::addColumn<QString>("fileName");
  423. QTest::addColumn<bool>("expected_bRet");
  424. QTest::newRow("BARCODE_DATAMATRIX gif") << BARCODE_DATAMATRIX << "1234" << "test_save_to_file.gif" << true;
  425. QTest::newRow("BARCODE_DATAMATRIX unknown format") << BARCODE_DATAMATRIX << "1234" << "test_save_to_file.ext" << false;
  426. QTest::newRow("BARCODE_DATAMATRIX UTF8 gif") << BARCODE_DATAMATRIX << "1234" << "test_save_to_file_τ.gif" << true;
  427. QTest::newRow("BARCODE_DATAMATRIX too long (unknown format)") << BARCODE_DATAMATRIX << "1234"
  428. << "test_6789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012.gif" // 256 long so should be truncated to end in ".gi"
  429. << false;
  430. }
  431. void saveToFileTest()
  432. {
  433. Zint::QZint bc;
  434. bool bRet;
  435. QFETCH(int, symbology);
  436. QFETCH(QString, text);
  437. QFETCH(QString, fileName);
  438. QFETCH(bool, expected_bRet);
  439. bc.setSymbol(symbology);
  440. bc.setText(text);
  441. bRet = bc.save_to_file(fileName);
  442. QCOMPARE(bRet, expected_bRet);
  443. if (bRet) {
  444. bRet = QFile::remove(fileName);
  445. QCOMPARE(bRet, true);
  446. }
  447. }
  448. void getAsCLITest_data()
  449. {
  450. QTest::addColumn<bool>("autoHeight");
  451. QTest::addColumn<float>("heightPerRow");
  452. QTest::addColumn<QString>("outfile");
  453. QTest::addColumn<int>("symbology");
  454. QTest::addColumn<int>("inputMode");
  455. QTest::addColumn<QString>("text");
  456. QTest::addColumn<QString>("primary");
  457. QTest::addColumn<float>("height");
  458. QTest::addColumn<int>("option1");
  459. QTest::addColumn<int>("option2");
  460. QTest::addColumn<int>("option3");
  461. QTest::addColumn<float>("scale");
  462. QTest::addColumn<float>("dpmm");
  463. QTest::addColumn<bool>("dotty");
  464. QTest::addColumn<float>("dotSize");
  465. QTest::addColumn<float>("textGap");
  466. QTest::addColumn<float>("guardDescent");
  467. QTest::addColumn<int>("structAppCount");
  468. QTest::addColumn<int>("structAppIndex");
  469. QTest::addColumn<QString>("structAppID");
  470. QTest::addColumn<QString>("fgStr");
  471. QTest::addColumn<QString>("bgStr");
  472. QTest::addColumn<QColor>("fgColor");
  473. QTest::addColumn<QColor>("bgColor");
  474. QTest::addColumn<bool>("cmyk");
  475. QTest::addColumn<int>("borderTypeIndex");
  476. QTest::addColumn<int>("borderWidth");
  477. QTest::addColumn<int>("whitespace");
  478. QTest::addColumn<int>("vWhitespace");
  479. QTest::addColumn<int>("fontSetting");
  480. QTest::addColumn<bool>("showText");
  481. QTest::addColumn<bool>("gsSep");
  482. QTest::addColumn<bool>("quietZones");
  483. QTest::addColumn<bool>("noQuietZones");
  484. QTest::addColumn<bool>("compliantHeight");
  485. QTest::addColumn<int>("rotateAngle");
  486. QTest::addColumn<int>("eci");
  487. QTest::addColumn<bool>("gs1Parens");
  488. QTest::addColumn<bool>("gs1NoCheck");
  489. QTest::addColumn<bool>("readerInit");
  490. QTest::addColumn<bool>("guardWhitespace");
  491. QTest::addColumn<bool>("embedVectorFont");
  492. QTest::addColumn<int>("warnLevel");
  493. QTest::addColumn<bool>("debug");
  494. QTest::addColumn<double>("xdimdp_x_dim");
  495. QTest::addColumn<int>("xdimdp_x_dim_units");
  496. QTest::addColumn<int>("xdimdp_resolution");
  497. QTest::addColumn<int>("xdimdp_resolution_units");
  498. QTest::addColumn<int>("xdimdp_filetype");
  499. QTest::addColumn<int>("xdimdp_filetype_maxicode");
  500. QTest::addColumn<QString>("expected_cmd");
  501. QTest::addColumn<QString>("expected_win");
  502. QTest::addColumn<QString>("expected_longOptOnly");
  503. QTest::addColumn<QString>("expected_barcodeNames");
  504. QTest::addColumn<QString>("expected_noexe");
  505. QTest::addColumn<QString>("expected_xdimdp");
  506. QTest::newRow("BARCODE_AUSPOST") << true << 0.0f << ""
  507. << BARCODE_AUSPOST << DATA_MODE // symbology-inputMode
  508. << "12345678" << "" // text-primary
  509. << 30.0f << -1 << 0 << 0 << 1.0f << 0.0f << false << 0.8f << 1.0f // height-textGap
  510. << 5.0f << 0 << 0 << "" // guardDescent-structAppID
  511. << "" << "" << QColor(Qt::black) << QColor(Qt::white) << false // fgStr-cmyk
  512. << 0 << 0 << 0 << 0 << 0 // borderTypeIndex-fontSetting
  513. << true << false << false << false << true << 0 // showText-rotateAngle
  514. << 0 << false << false << false << false << false << WARN_DEFAULT << false // eci-debug
  515. << 0.0 << 0 << 0 << 0 << 0 << 0 // xdimdp
  516. << "zint -b 63 --binary --compliantheight -d '12345678'"
  517. << "zint.exe -b 63 --binary --compliantheight -d \"12345678\""
  518. << "zint --barcode=63 --binary --compliantheight --data='12345678'"
  519. << "zint -b AUSPOST --binary --compliantheight -d '12345678'"
  520. << "zint -b 63 --binary --compliantheight -d \"12345678\""
  521. << "";
  522. QTest::newRow("BARCODE_AZTEC") << false << 0.0f << ""
  523. << BARCODE_AZTEC << UNICODE_MODE // symbology-inputMode
  524. << "12345678Ж0%var%" << "" // text-primary
  525. << 0.0f << 1 << 0 << 0 << 4.0f << 0.0f << true << 0.9f << 1.0f // height-textGap
  526. << 5.0f << 2 << 1 << "as\"dfa'sdf" // guardDescent-structAppID
  527. << "" << "" << QColor(Qt::blue) << QColor(Qt::white) << true // fgStr-cmyk
  528. << 0 << 0 << 2 << 3 << 0 // borderTypeIndex-fontSetting
  529. << true << false << false << false << false << 0 // showText-rotateAngle
  530. << 7 << false << false << false << false << false << WARN_DEFAULT << false // eci-debug
  531. << 0.0 << 0 << 0 << 0 << 0 << 0 // xdimdp
  532. << "zint -b 92 --cmyk --eci=7 -d '12345678Ж0%var%' --dotsize=0.9 --dotty --fg=0000FF --scale=4"
  533. " --secure=1 --structapp='1,2,as\"dfa'\\''sdf' --vwhitesp=3 -w 2"
  534. << "zint.exe -b 92 --cmyk --eci=7 -d \"12345678Ж0%var%\" --dotsize=0.9 --dotty --fg=0000FF --scale=4"
  535. " --secure=1 --structapp=\"1,2,as\\\"dfa'sdf\" --vwhitesp=3 -w 2"
  536. << "" << "" << "" << "";
  537. QTest::newRow("BARCODE_AZTEC (bgStr CMYK, fgStr CMYK)") << false << 0.0f << ""
  538. << BARCODE_AZTEC << UNICODE_MODE // symbology-inputMode
  539. << "12345678Ж0%var%" << "" // text-primary
  540. << 0.0f << 1 << 0 << 0 << 4.0f << 0.0f << true << 0.9f << 1.0f // height-textGap
  541. << 5.0f << 2 << 1 << "as\"dfa'sdf" // guardDescent-structAppID
  542. << "71,0,40,44" << "0,0,0,0" << QColor(Qt::black) << QColor(Qt::white) << true // fgStr-cmyk
  543. << 0 << 0 << 2 << 3 << 0 // borderTypeIndex-fontSetting
  544. << true << false << false << false << false << 0 // showText-rotateAngle
  545. << 7 << false << false << false << false << false << WARN_DEFAULT << false // eci-debug
  546. << 0.0 << 0 << 0 << 0 << 0 << 0 // xdimdp
  547. << "zint -b 92 --bg=0,0,0,0 --cmyk --eci=7 -d '12345678Ж0%var%' --dotsize=0.9 --dotty --fg=71,0,40,44 --scale=4"
  548. " --secure=1 --structapp='1,2,as\"dfa'\\''sdf' --vwhitesp=3 -w 2"
  549. << "zint.exe -b 92 --bg=0,0,0,0 --cmyk --eci=7 -d \"12345678Ж0%var%\" --dotsize=0.9 --dotty --fg=71,0,40,44 --scale=4"
  550. " --secure=1 --structapp=\"1,2,as\\\"dfa'sdf\" --vwhitesp=3 -w 2"
  551. << "" << "" << "" << "";
  552. QTest::newRow("BARCODE_C25INTER") << true << 0.0f << ""
  553. << BARCODE_C25INTER << UNICODE_MODE // symbology-inputMode
  554. << "12345" << "" // text-primary
  555. << 0.0f << -1 << 2 << 0 << 1.0f << 0.0f << false << 0.8f << 1.0f // height-textGap
  556. << 5.0f << 0 << 0 << "" // guardDescent-structAppID
  557. << "" << "" << QColor(Qt::black) << QColor(Qt::white) << false // fgStr-cmyk
  558. << 0 << 0 << 0 << 0 << SMALL_TEXT // borderTypeIndex-fontSetting
  559. << true << false << false << false << true << 0 // showText-rotateAngle
  560. << 0 << false << false << false << false << false << WARN_DEFAULT << false // eci-debug
  561. << 0.0 << 0 << 0 << 0 << 0 << 0 // xdimdp
  562. << "zint -b 3 --compliantheight -d '12345' --small --vers=2"
  563. << "zint.exe -b 3 --compliantheight -d \"12345\" --small --vers=2"
  564. << "" << "" << "" << "";
  565. QTest::newRow("BARCODE_CHANNEL") << false << 0.0f << ""
  566. << BARCODE_CHANNEL << UNICODE_MODE // symbology-inputMode
  567. << "453678" << "" // text-primary
  568. << 19.7f << -1 << 7 << 0 << 1.0f << 0.0f << false << 0.8f << 1.0f // height-textGap
  569. << 5.0f << 0 << 0 << "" // guardDescent-structAppID
  570. << "" << "" << QColor(Qt::black) << QColor(255, 255, 255, 0) << false // fgStr-cmyk
  571. << 1 << 2 << 0 << 0 << BOLD_TEXT // borderTypeIndex-fontSetting
  572. << true << false << true << false << false << 90 // showText-rotateAngle
  573. << 0 << false << false << false << false << false << WARN_DEFAULT << true // eci-debug
  574. << 0.0 << 0 << 0 << 0 << 0 << 0 // xdimdp
  575. << "zint -b 140 --bind --bold --border=2 -d '453678' --height=19.7 --nobackground --quietzones"
  576. " --rotate=90 --verbose --vers=7"
  577. << "zint.exe -b 140 --bind --bold --border=2 -d \"453678\" --height=19.7 --nobackground --quietzones"
  578. " --rotate=90 --verbose --vers=7"
  579. << "" << "" << "" << "";
  580. QTest::newRow("BARCODE_CHANNEL (bgStr FFFFFF00)") << false << 0.0f << ""
  581. << BARCODE_CHANNEL << UNICODE_MODE // symbology-inputMode
  582. << "453678" << "" // text-primary
  583. << 19.7f << -1 << 7 << 0 << 1.0f << 0.0f << false << 0.8f << 1.0f // height-textGap
  584. << 5.0f << 0 << 0 << "" // guardDescent-structAppID
  585. << "" << "FFFFFF00" << QColor(Qt::black) << QColor(Qt::white) << false // fgStr-cmyk
  586. << 1 << 2 << 0 << 0 << BOLD_TEXT // borderTypeIndex-fontSetting
  587. << true << false << true << false << false << 90 // showText-rotateAngle
  588. << 0 << false << false << false << false << false << WARN_DEFAULT << true // eci-debug
  589. << 0.0 << 0 << 0 << 0 << 0 << 0 // xdimdp
  590. << "zint -b 140 --bind --bold --border=2 -d '453678' --height=19.7 --nobackground --quietzones"
  591. " --rotate=90 --verbose --vers=7"
  592. << "zint.exe -b 140 --bind --bold --border=2 -d \"453678\" --height=19.7 --nobackground --quietzones"
  593. " --rotate=90 --verbose --vers=7"
  594. << "" << "" << "" << "";
  595. QTest::newRow("BARCODE_CHANNEL (bgStr 12345600)") << false << 0.0f << ""
  596. << BARCODE_CHANNEL << UNICODE_MODE // symbology-inputMode
  597. << "453678" << "" // text-primary
  598. << 19.7f << -1 << 7 << 0 << 1.0f << 0.0f << false << 0.8f << 1.0f // height-textGap
  599. << 5.0f << 0 << 0 << "" // guardDescent-structAppID
  600. << "" << "12345600" << QColor(Qt::black) << QColor(Qt::white) << false // fgStr-cmyk
  601. << 1 << 2 << 0 << 0 << BOLD_TEXT // borderTypeIndex-fontSetting
  602. << true << false << true << false << false << 90 // showText-rotateAngle
  603. << 0 << false << false << false << false << false << WARN_DEFAULT << true // eci-debug
  604. << 0.0 << 0 << 0 << 0 << 0 << 0 // xdimdp
  605. << "zint -b 140 --bind --bold --border=2 -d '453678' --height=19.7 --nobackground --quietzones"
  606. " --rotate=90 --verbose --vers=7"
  607. << "zint.exe -b 140 --bind --bold --border=2 -d \"453678\" --height=19.7 --nobackground --quietzones"
  608. " --rotate=90 --verbose --vers=7"
  609. << "" << "" << "" << "";
  610. QTest::newRow("BARCODE_CODE128") << false << 0.0f << ""
  611. << BARCODE_CODE128 << (UNICODE_MODE | EXTRA_ESCAPE_MODE) // symbology-inputMode
  612. << "1234\\^A56" << "" // text-primary
  613. << 0.0f << -1 << 0 << 0 << 1.0f << 0.0f << false << 0.8f << 1.0f // height-textGap
  614. << 5.0f << 0 << 0 << "" // guardDescent-structAppID
  615. << "" << "" << QColor(Qt::black) << QColor(Qt::white) << false // fgStr-cmyk
  616. << 0 << 0 << 0 << 0 << 0 // borderTypeIndex-fontSetting
  617. << false << false << true << false << true << 0 // showText-rotateAngle
  618. << 0 << false << false << false << false << false << WARN_DEFAULT << false // eci-debug
  619. << 0.0 << 0 << 0 << 0 << 0 << 0 // xdimdp
  620. << "zint -b 20 -d '1234\\^A56' --extraesc --notext --quietzones"
  621. << "zint.exe -b 20 -d \"1234\\^A56\" --extraesc --notext --quietzones"
  622. << "" << "" << "" << "";
  623. QTest::newRow("BARCODE_GS1_128_CC") << false << 0.0f << ""
  624. << BARCODE_GS1_128_CC << UNICODE_MODE // symbology-inputMode
  625. << "[01]12345678901231[15]121212" << "[11]901222[99]ABCDE" // text-primary
  626. << 71.142f << 3 << 0 << 0 << 3.5f << 0.0f << false << 0.8f << 1.0f // height-textGap
  627. << 5.0f << 0 << 0 << "" // guardDescent-structAppID
  628. << "" << "" << QColor(Qt::black) << QColor(Qt::white) << false // fgStr-cmyk
  629. << 0 << 0 << 0 << 0 << 0 // borderTypeIndex-fontSetting
  630. << false << false << true << false << true << 0 // showText-rotateAngle
  631. << 0 << false << false << false << false << false << WARN_DEFAULT << false // eci-debug
  632. << 0.0 << 0 << 0 << 0 << 0 << 0 // xdimdp
  633. << "zint -b 131 --compliantheight -d '[11]901222[99]ABCDE' --height=71.142 --mode=3 --notext"
  634. " --primary='[01]12345678901231[15]121212' --quietzones --scale=3.5"
  635. << "zint.exe -b 131 --compliantheight -d \"[11]901222[99]ABCDE\" --height=71.142 --mode=3 --notext"
  636. " --primary=\"[01]12345678901231[15]121212\" --quietzones --scale=3.5"
  637. << "" << "" << "" << "";
  638. QTest::newRow("BARCODE_CODE16K") << false << 11.7f << ""
  639. << BARCODE_CODE16K << (UNICODE_MODE | HEIGHTPERROW_MODE) // symbology-inputMode
  640. << "12345678901234567890123456789012" << "" // text-primary
  641. << 0.0f << 4 << 0 << 2 << 1.0f << 0.0f << false << 0.8f << 1.0f // height-textGap
  642. << 5.0f << 0 << 0 << "" // guardDescent-structAppID
  643. << "" << "" << QColor(Qt::black) << QColor(Qt::white) << false // fgStr-cmyk
  644. << 1 << 1 << 0 << 0 << SMALL_TEXT // borderTypeIndex-fontSetting
  645. << true << false << false << true << true << 0 // showText-rotateAngle
  646. << 0 << false << false << false << false << false << WARN_DEFAULT << false // eci-debug
  647. << 0.0 << 0 << 0 << 0 << 0 << 0 // xdimdp
  648. << "zint -b 23 --compliantheight -d '12345678901234567890123456789012'"
  649. " --height=11.7 --heightperrow --noquietzones --rows=4 --separator=2 --small"
  650. << "zint.exe -b 23 --compliantheight -d \"12345678901234567890123456789012\""
  651. " --height=11.7 --heightperrow --noquietzones --rows=4 --separator=2 --small"
  652. << "" << "" << "" << "";
  653. QTest::newRow("BARCODE_CODE49") << true << 0.0f << ""
  654. << BARCODE_CODE49 << UNICODE_MODE // symbology-inputMode
  655. << "12345678901234567890" << "" // text-primary
  656. << 30.0f << -1 << 0 << 0 << 1.0f << 0.0f << false << 0.8f << 1.0f // height-textGap
  657. << 5.0f << 0 << 0 << "" // guardDescent-structAppID
  658. << "" << "" << QColor(Qt::black) << QColor(Qt::white) << false // fgStr-cmyk
  659. << 0 << 0 << 0 << 0 << 0 // borderTypeIndex-fontSetting
  660. << true << false << false << false << true << 0 // showText-rotateAngle
  661. << 0 << false << false << false << false << false << WARN_DEFAULT << false // eci-debug
  662. << 0.0 << 0 << 0 << 0 << 0 << 0 // xdimdp
  663. << "zint -b 24 --compliantheight -d '12345678901234567890'"
  664. << "zint.exe -b 24 --compliantheight -d \"12345678901234567890\""
  665. << "" << "" << "" << "";
  666. QTest::newRow("BARCODE_CODABLOCKF") << true << 0.0f << ""
  667. << BARCODE_CODABLOCKF << (DATA_MODE | ESCAPE_MODE) // symbology-inputMode
  668. << "T\\n\\xA0t\\\"" << "" // text-primary
  669. << 0.0f << 2 << 5 << 3 << 3.0f << 0.0f << false << 0.8f << 1.0f // height-textGap
  670. << 5.0f << 0 << 0 << "" // guardDescent-structAppID
  671. << "" << "" << QColor(Qt::black) << QColor(Qt::white) << false // fgStr-cmyk
  672. << 2 << 4 << 0 << 0 << 0 // borderTypeIndex-fontSetting
  673. << true << false << false << false << true << 0 // showText-rotateAngle
  674. << 0 << false << false << true << false << false << WARN_DEFAULT << false // eci-debug
  675. << 0.0 << 0 << 0 << 0 << 0 << 0 // xdimdp
  676. << "zint -b 74 --binary --border=4 --box --cols=5 --compliantheight -d 'T\\n\\xA0t\\\"' --esc --init"
  677. " --rows=2 --scale=3 --separator=3"
  678. << "zint.exe -b 74 --binary --border=4 --box --cols=5 --compliantheight -d \"T\\n\\xA0t\\\\\"\" --esc --init"
  679. " --rows=2 --scale=3 --separator=3"
  680. << "" << "" << "" << "";
  681. QTest::newRow("BARCODE_DAFT") << false << 0.0f << ""
  682. << BARCODE_DAFT << UNICODE_MODE // symbology-inputMode
  683. << "daft" << "" // text-primary
  684. << 9.2f << -1 << 251 << 0 << 1.0f << 0.0f << false << 0.7f << 1.0f // height-textGap
  685. << 5.0f << 0 << 0 << "" // guardDescent-structAppID
  686. << "" << "" << QColor(0x30, 0x31, 0x32, 0x33) << QColor(0xBF, 0xBE, 0xBD, 0xBC) << false // fgStr-cmyk
  687. << 0 << 0 << 0 << 0 << 0 // borderTypeIndex-fontSetting
  688. << true << false << false << false << true << 0 // showText-rotateAngle
  689. << 0 << false << false << false << false << false << WARN_DEFAULT << false // eci-debug
  690. << 0.0 << 0 << 0 << 0 << 0 << 0 // xdimdp
  691. << "zint -b 93 --bg=BFBEBDBC -d 'daft' --fg=30313233 --height=9.2 --vers=251"
  692. << "zint.exe -b 93 --bg=BFBEBDBC -d \"daft\" --fg=30313233 --height=9.2 --vers=251"
  693. << "" << "" << "" << "";
  694. QTest::newRow("BARCODE_DATAMATRIX (GS1)") << true << 0.0f << ""
  695. << BARCODE_DATAMATRIX << GS1_MODE // symbology-inputMode
  696. << "[20]12" << "" // text-primary
  697. << 0.0f << -1 << 0 << DM_SQUARE << 1.0f << 0.0f << false << 0.7f << 1.0f // height-textGap
  698. << 5.0f << 0 << 0 << "" // guardDescent-structAppID
  699. << "" << "" << QColor(Qt::black) << QColor(Qt::white) << false // fgStr-cmyk
  700. << 0 << 0 << 0 << 0 << 0 // borderTypeIndex-fontSetting
  701. << true << true << false << false << true << 0 // showText-rotateAngle
  702. << 0 << false << false << false << false << false << WARN_DEFAULT << false // eci-debug
  703. << 0.0 << 0 << 0 << 0 << 0 << 0 // xdimdp
  704. << "zint -b 71 -d '[20]12' --gs1 --gssep --square"
  705. << "zint.exe -b 71 -d \"[20]12\" --gs1 --gssep --square"
  706. << "" << "" << "" << "";
  707. QTest::newRow("BARCODE_DATAMATRIX") << false << 0.0f << ""
  708. << BARCODE_DATAMATRIX << (DATA_MODE | ESCAPE_MODE | FAST_MODE) // symbology-inputMode
  709. << "ABCDEFGH\\x01I" << "" // text-primary
  710. << 0.0f << -1 << 0 << DM_ISO_144 << 1.0f << 0.0f << false << 0.7f << 1.0f // height-textGap
  711. << 5.0f << 0 << 0 << "" // guardDescent-structAppID
  712. << "" << "" << QColor(Qt::black) << QColor(Qt::white) << false // fgStr-cmyk
  713. << 0 << 0 << 0 << 0 << 0 // borderTypeIndex-fontSetting
  714. << true << false << false << false << true << 0 // showText-rotateAngle
  715. << 0 << false << false << false << false << false << WARN_DEFAULT << false // eci-debug
  716. << 0.0 << 0 << 0 << 0 << 0 << 0 // xdimdp
  717. << "zint -b 71 --binary -d 'ABCDEFGH\\x01I' --dmiso144 --esc --fast"
  718. << "zint.exe -b 71 --binary -d \"ABCDEFGH\\x01I\" --dmiso144 --esc --fast"
  719. << "" << "" << "" << "";
  720. QTest::newRow("BARCODE_DBAR_EXPSTK_CC") << false << 40.8f << ""
  721. << BARCODE_DBAR_EXPSTK_CC << (DATA_MODE | HEIGHTPERROW_MODE) // symbology-inputMode
  722. << "[91]ABCDEFGHIJKL" << "[11]901222[99]ABCDE" // text-primary
  723. << 0.0f << -1 << 0 << 2 << 1.0f << 0.0f << true << 0.9f << 1.0f // height-textGap
  724. << 3.0f << 2 << 1 << "" // guardDescent-structAppID
  725. << "" << "" << QColor(Qt::black) << QColor(Qt::white) << false // fgStr-cmyk
  726. << 0 << 0 << 0 << 0 << 0 // borderTypeIndex-fontSetting
  727. << true << false << false << false << true << 0 // showText-rotateAngle
  728. << 0 << false << false << false << false << false << WARN_DEFAULT << false // eci-debug
  729. << 0.0 << 0 << 0 << 0 << 0 << 0 // xdimdp
  730. << "zint -b 139 --binary --compliantheight -d '[11]901222[99]ABCDE' --height=40.8 --heightperrow"
  731. " --primary='[91]ABCDEFGHIJKL' --rows=2"
  732. << "zint.exe -b 139 --binary --compliantheight -d \"[11]901222[99]ABCDE\" --height=40.8 --heightperrow"
  733. " --primary=\"[91]ABCDEFGHIJKL\" --rows=2"
  734. << "" << "" << "" << "";
  735. QTest::newRow("BARCODE_DOTCODE") << false << 1.0f << ""
  736. << BARCODE_DOTCODE << GS1_MODE // symbology-inputMode
  737. << "[20]01" << "" // text-primary
  738. << 30.0f << -1 << 8 << ((0 + 1) << 8) << 1.0f << 0.0f << false << 0.7f << 1.0f // height-textGap
  739. << 0.0f << 0 << 0 << "" // guardDescent-structAppID
  740. << "" << "" << QColor(Qt::black) << QColor(Qt::white) << false // fgStr-cmyk
  741. << 0 << 0 << 0 << 0 << 0 // borderTypeIndex-fontSetting
  742. << true << false << false << false << true << 0 // showText-rotateAngle
  743. << 0 << false << false << false << false << false << WARN_DEFAULT << false // eci-debug
  744. << 0.0 << 0 << 0 << 0 << 0 << 0 // xdimdp
  745. << "zint -b 115 --cols=8 -d '[20]01' --dotsize=0.7 --gs1 --mask=0"
  746. << "zint.exe -b 115 --cols=8 -d \"[20]01\" --dotsize=0.7 --gs1 --mask=0"
  747. << "" << "" << "" << "";
  748. QTest::newRow("BARCODE_DPD") << true << 0.0f << ""
  749. << BARCODE_DPD << UNICODE_MODE // symbology-inputMode
  750. << "1234567890123456789012345678" << "" // text-primary
  751. << 0.0f << -1 << 0 << 0 << 4.5f << 24.0f << true << 0.8f << 1.0f // height-textGap
  752. << 0.0f << 0 << 0 << "" // guardDescent-structAppID
  753. << "" << "" << QColor(Qt::black) << QColor(Qt::white) << false // fgStr-cmyk
  754. << 0 << 0 << 0 << 0 << 0 // borderTypeIndex-fontSetting
  755. << true << false << false << false << true << 0 // showText-rotateAngle
  756. << 0 << false << false << false << false << false << WARN_DEFAULT << false // eci-debug
  757. << 0.375 << 0 << 600 << 1 << 0 << 0 // xdimdp
  758. << "zint -b 96 --compliantheight -d '1234567890123456789012345678' --scalexdimdp=0.375,24"
  759. << "zint.exe -b 96 --compliantheight -d \"1234567890123456789012345678\" --scalexdimdp=0.375,24"
  760. << "" << "" << ""
  761. << "zint -b 96 --compliantheight -d '1234567890123456789012345678' --scalexdimdp=0.375mm,600dpi";
  762. QTest::newRow("BARCODE_EANX") << true << 0.0f << ""
  763. << BARCODE_EANX << UNICODE_MODE // symbology-inputMode
  764. << "123456789012+12" << "" // text-primary
  765. << 0.0f << -1 << 8 << 0 << 1.0f << 0.0f << true << 0.8f << 1.0f // height-textGap
  766. << 0.0f << 0 << 0 << "" // guardDescent-structAppID
  767. << "" << "" << QColor(Qt::black) << QColor(Qt::white) << false // fgStr-cmyk
  768. << 0 << 0 << 0 << 0 << 0 // borderTypeIndex-fontSetting
  769. << true << false << false << false << true << 0 // showText-rotateAngle
  770. << 0 << false << false << false << false << false << WARN_DEFAULT << false // eci-debug
  771. << 0.0 << 0 << 0 << 0 << 0 << 0 // xdimdp
  772. << "zint -b 13 --addongap=8 --compliantheight -d '123456789012+12' --guarddescent=0"
  773. << "zint.exe -b 13 --addongap=8 --compliantheight -d \"123456789012+12\" --guarddescent=0"
  774. << "" << "" << "" << "";
  775. QTest::newRow("BARCODE_EANX (guardWhitespace/embedVectorFont") << true << 0.0f << ""
  776. << BARCODE_EANX << UNICODE_MODE // symbology-inputMode
  777. << "123456789012+12" << "" // text-primary
  778. << 0.0f << -1 << 8 << 0 << 1.0f << 0.0f << true << 0.8f << 1.0f // height-textGap
  779. << 0.0f << 0 << 0 << "" // guardDescent-structAppID
  780. << "" << "" << QColor(Qt::black) << QColor(Qt::white) << false // fgStr-cmyk
  781. << 0 << 0 << 0 << 0 << 0 // borderTypeIndex-fontSetting
  782. << true << false << false << false << true << 0 // showText-rotateAngle
  783. << 0 << false << false << false << true << true << WARN_DEFAULT << false // eci-debug
  784. << 0.0 << 0 << 0 << 0 << 0 << 0 // xdimdp
  785. << "zint -b 13 --addongap=8 --compliantheight -d '123456789012+12' --embedfont --guarddescent=0 --guardwhitespace"
  786. << "zint.exe -b 13 --addongap=8 --compliantheight -d \"123456789012+12\" --embedfont --guarddescent=0 --guardwhitespace"
  787. << "" << "" << "" << "";
  788. QTest::newRow("BARCODE_GRIDMATRIX") << false << 0.0f << ""
  789. << BARCODE_GRIDMATRIX << UNICODE_MODE // symbology-inputMode
  790. << "Your Data Here!" << "" // text-primary
  791. << 0.0f << 1 << 5 << 0 << 0.5f << 0.0f << false << 0.8f << 1.0f // height-textGap
  792. << 5.0f << 0 << 0 << "" // guardDescent-structAppID
  793. << "" << "" << QColor(Qt::black) << QColor(Qt::white) << false // fgStr-cmyk
  794. << 0 << 0 << 0 << 0 << 0 // borderTypeIndex-fontSetting
  795. << true << false << true << false << true << 270 // showText-rotateAngle
  796. << 0 << false << false << false << false << false << WARN_DEFAULT << false // eci-debug
  797. << 0.0 << 0 << 0 << 0 << 0 << 0 // xdimdp
  798. << "zint -b 142 -d 'Your Data Here!' --quietzones --rotate=270 --scale=0.5 --secure=1 --vers=5"
  799. << "zint.exe -b 142 -d \"Your Data Here!\" --quietzones --rotate=270 --scale=0.5 --secure=1 --vers=5"
  800. << "" << "" << "" << "";
  801. QTest::newRow("BARCODE_HANXIN") << false << 0.0f << ""
  802. << BARCODE_HANXIN << (UNICODE_MODE | ESCAPE_MODE) // symbology-inputMode
  803. << "éβÿ啊\\e\"'" << "" // text-primary
  804. << 30.0f << 2 << 5 << ((0 + 1) << 8) << 1.0f << 0.0f << false << 0.8f << 1.0f // height-textGap
  805. << 5.0f << 0 << 0 << "" // guardDescent-structAppID
  806. << "" << "" << QColor(Qt::black) << QColor(Qt::white) << false // fgStr-cmyk
  807. << 0 << 0 << 0 << 0 << 0 // borderTypeIndex-fontSetting
  808. << true << false << false << false << true << 0 // showText-rotateAngle
  809. << 29 << false << false << false << false << false << WARN_DEFAULT << false // eci-debug
  810. << 0.0 << 0 << 0 << 0 << 0 << 0 // xdimdp
  811. << "zint -b 116 --eci=29 -d 'éβÿ啊\\e\"'\\''' --esc --mask=0 --secure=2 --vers=5"
  812. << "zint.exe -b 116 --eci=29 -d \"éβÿ啊\\e\\\"'\" --esc --mask=0 --secure=2 --vers=5"
  813. << "" << "" << "" << "";
  814. QTest::newRow("BARCODE_HIBC_DM") << false << 10.0f << ""
  815. << BARCODE_HIBC_DM << UNICODE_MODE // symbology-inputMode
  816. << "1234" << "" // text-primary
  817. << 0.0f << -1 << 8 << DM_DMRE << 1.0f << 0.0f << false << 0.7f << 1.0f // height-textGap
  818. << 5.0f << 0 << 0 << "" // guardDescent-structAppID
  819. << "" << "" << QColor(Qt::black) << QColor(Qt::white) << false // fgStr-cmyk
  820. << 0 << 0 << 0 << 0 << 0 // borderTypeIndex-fontSetting
  821. << true << true << false << false << true << 0 // showText-rotateAngle
  822. << 0 << false << false << false << false << false << WARN_DEFAULT << false // eci-debug
  823. << 0.0 << 0 << 0 << 0 << 0 << 0 // xdimdp
  824. << "zint -b 102 -d '1234' --dmre --vers=8"
  825. << "zint.exe -b 102 -d \"1234\" --dmre --vers=8"
  826. << "" << "" << "" << "";
  827. QTest::newRow("BARCODE_HIBC_PDF") << false << 0.0f << ""
  828. << BARCODE_HIBC_PDF << (DATA_MODE | HEIGHTPERROW_MODE) // symbology-inputMode
  829. << "TEXT" << "" // text-primary
  830. << 3.5f << 3 << 4 << 10 << 10.0f << 0.0f << false << 0.8f << 1.0f // height-textGap
  831. << 5.0f << 2 << 1 << "" // guardDescent-structAppID
  832. << "" << "" << QColor(Qt::black) << QColor(Qt::white) << false // fgStr-cmyk
  833. << 0 << 0 << 0 << 0 << 0 // borderTypeIndex-fontSetting
  834. << true << false << true << false << true << 0 // showText-rotateAngle
  835. << 0 << false << false << false << false << false << WARN_DEFAULT << false // eci-debug
  836. << 0.0 << 0 << 0 << 0 << 0 << 0 // xdimdp
  837. << "zint -b 106 --binary --cols=4 -d 'TEXT' --height=3.5 --heightperrow --quietzones"
  838. " --rows=10 --scale=10 --secure=3 --structapp=1,2"
  839. << "zint.exe -b 106 --binary --cols=4 -d \"TEXT\" --height=3.5 --heightperrow --quietzones"
  840. " --rows=10 --scale=10 --secure=3 --structapp=1,2"
  841. << "" << "" << "" << "";
  842. QTest::newRow("BARCODE_ITF14") << true << 0.0f << ""
  843. << BARCODE_ITF14 << UNICODE_MODE // symbology-inputMode
  844. << "9212320967145" << "" // text-primary
  845. << 30.0f << -1 << 0 << 0 << 1.0f << 0.0f << false << 0.8f << 1.0f // height-textGap
  846. << 5.0f << 0 << 0 << "" // guardDescent-structAppID
  847. << "" << "" << QColor(Qt::black) << QColor(Qt::white) << false // fgStr-cmyk
  848. << 0 << 0 << 0 << 0 << 0 // borderTypeIndex-fontSetting
  849. << true << false << false << false << true << 0 // showText-rotateAngle
  850. << 0 << false << false << false << false << false << WARN_DEFAULT << false // eci-debug
  851. << 0.0 << 0 << 0 << 0 << 0 << 0 // xdimdp
  852. << "zint -b 89 --compliantheight -d '9212320967145'"
  853. << "zint.exe -b 89 --compliantheight -d \"9212320967145\""
  854. << "" << "" << "" << "";
  855. QTest::newRow("BARCODE_ITF14 (border)") << true << 0.0f << ""
  856. << BARCODE_ITF14 << UNICODE_MODE // symbology-inputMode
  857. << "9212320967145" << "" // text-primary
  858. << 30.0f << -1 << 0 << 0 << 1.0f << 0.0f << false << 0.8f << 1.0f // height-textGap
  859. << 5.0f << 0 << 0 << "" // guardDescent-structAppID
  860. << "" << "" << QColor(Qt::black) << QColor(Qt::white) << false // fgStr-cmyk
  861. << 0 << 1 << 0 << 0 << 0 // borderTypeIndex-fontSetting
  862. << true << false << false << false << true << 0 // showText-rotateAngle
  863. << 0 << false << false << false << false << false << WARN_DEFAULT << false // eci-debug
  864. << 0.0 << 0 << 0 << 0 << 0 << 0 // xdimdp
  865. << "zint -b 89 --border=1 --compliantheight -d '9212320967145'"
  866. << "zint.exe -b 89 --border=1 --compliantheight -d \"9212320967145\""
  867. << "" << "" << "" << "";
  868. QTest::newRow("BARCODE_MAXICODE") << true << 0.0f << ""
  869. << BARCODE_MAXICODE << (UNICODE_MODE | ESCAPE_MODE) // symbology-inputMode
  870. << "152382802840001"
  871. << "1Z00004951\\GUPSN\\G06X610\\G159\\G1234567\\G1/1\\G\\GY\\G1 MAIN ST\\GTOWN\\GNY\\R\\E" // text-primary
  872. << 0.0f << -1 << (96 + 1) << 0 << 2.5f << 0.0f << false << 0.8f << 1.0f // height-textGap
  873. << 5.0f << 0 << 0 << "" // guardDescent-structAppID
  874. << "" << "" << QColor(Qt::black) << QColor(Qt::white) << false // fgStr-cmyk
  875. << 0 << 0 << 0 << 0 << 0 // borderTypeIndex-fontSetting
  876. << true << false << true << false << true << 0 // showText-rotateAngle
  877. << 0 << false << false << false << false << false << WARN_DEFAULT << false // eci-debug
  878. << 0.0 << 0 << 0 << 0 << 0 << 0 // xdimdp
  879. << "zint -b 57 -d '1Z00004951\\GUPSN\\G06X610\\G159\\G1234567\\G1/1\\G\\GY\\G1 MAIN ST\\GTOWN\\GNY\\R\\E'"
  880. " --esc --primary='152382802840001' --quietzones --scale=2.5 --scmvv=96"
  881. << "zint.exe -b 57 -d \"1Z00004951\\GUPSN\\G06X610\\G159\\G1234567\\G1/1\\G\\GY\\G1 MAIN ST\\GTOWN\\GNY\\R\\E\""
  882. " --esc --primary=\"152382802840001\" --quietzones --scale=2.5 --scmvv=96"
  883. << "" << "" << "" << "";
  884. QTest::newRow("BARCODE_MICROQR") << false << 0.0f << ""
  885. << BARCODE_MICROQR << UNICODE_MODE // symbology-inputMode
  886. << "1234" << "" // text-primary
  887. << 30.0f << 2 << 3 << (ZINT_FULL_MULTIBYTE | (3 + 1) << 8) << 1.0f << 0.0f << false << 0.8f << 1.0f // height-textGap
  888. << 5.0f << 0 << 0 << "" // guardDescent-structAppID
  889. << "" << "" << QColor(Qt::black) << QColor(Qt::white) << false // fgStr-cmyk
  890. << 0 << 0 << 0 << 0 << 0 // borderTypeIndex-fontSetting
  891. << true << false << false << false << true << 0 // showText-rotateAngle
  892. << 0 << false << false << false << false << false << WARN_DEFAULT << false // eci-debug
  893. << 0.0 << 0 << 0 << 0 << 0 << 0 // xdimdp
  894. << "zint -b 97 -d '1234' --fullmultibyte --mask=3 --secure=2 --vers=3"
  895. << "zint.exe -b 97 -d \"1234\" --fullmultibyte --mask=3 --secure=2 --vers=3"
  896. << "" << "" << "" << "";
  897. QTest::newRow("BARCODE_QRCODE") << true << 0.0f << ""
  898. << BARCODE_QRCODE << GS1_MODE // symbology-inputMode
  899. << "(01)12" << "" // text-primary
  900. << 0.0f << 1 << 5 << (ZINT_FULL_MULTIBYTE | (0 + 1) << 8) << 1.0f << 0.0f << false << 0.8f << 1.0f // height-textGap
  901. << 5.0f << 0 << 0 << "" // guardDescent-structAppID
  902. << "" << "" << QColor(Qt::black) << QColor(Qt::white) << false // fgStr-cmyk
  903. << 0 << 0 << 0 << 0 << 0 // borderTypeIndex-fontSetting
  904. << true << false << true << false << true << 0 // showText-rotateAngle
  905. << 0 << true << true << false << false << false << WARN_DEFAULT << false // eci-debug
  906. << 0.0 << 0 << 0 << 0 << 0 << 0 // xdimdp
  907. << "zint -b 58 -d '(01)12' --fullmultibyte --gs1 --gs1parens --gs1nocheck --mask=0 --quietzones"
  908. " --secure=1 --vers=5"
  909. << "zint.exe -b 58 -d \"(01)12\" --fullmultibyte --gs1 --gs1parens --gs1nocheck --mask=0 --quietzones"
  910. " --secure=1 --vers=5"
  911. << "" << "" << "" << "";
  912. QTest::newRow("BARCODE_RMQR") << true << 0.0f << ""
  913. << BARCODE_RMQR << UNICODE_MODE // symbology-inputMode
  914. << "テ" << "" // text-primary
  915. << 30.0f << -1 << 8 << 0 << 1.0f << 0.0f << false << 0.8f << 1.0f // height-textGap
  916. << 5.0f << 0 << 0 << "" // guardDescent-structAppID
  917. << "" << "" << QColor(Qt::black) << QColor(Qt::white) << false // fgStr-cmyk
  918. << 0 << 0 << 0 << 0 << 0 // borderTypeIndex-fontSetting
  919. << true << false << false << false << true << 180 // showText-rotateAngle
  920. << 20 << false << false << false << false << false << WARN_DEFAULT << false // eci-debug
  921. << 0.0 << 0 << 0 << 0 << 0 << 0 // xdimdp
  922. << "zint -b 145 --eci=20 -d 'テ' --rotate=180 --vers=8"
  923. << "zint.exe -b 145 --eci=20 -d \"テ\" --rotate=180 --vers=8"
  924. << "" << "" << "" << "";
  925. QTest::newRow("BARCODE_ULTRA") << false << 0.0f << ""
  926. << BARCODE_ULTRA << (GS1_MODE | GS1PARENS_MODE | GS1NOCHECK_MODE) // symbology-inputMode
  927. << "(01)1" << "" // text-primary
  928. << 0.0f << 6 << 2 << 0 << 1.0f << 0.0f << true << 0.8f << 1.0f // height-textGap
  929. << 5.0f << 2 << 1 << "4" // guardDescent-structAppID
  930. << "" << "" << QColor(Qt::black) << QColor(Qt::white) << false // fgStr-cmyk
  931. << 0 << 0 << 0 << 0 << 0 // borderTypeIndex-fontSetting
  932. << true << false << false << false << true << 0 // showText-rotateAngle
  933. << 0 << false << false << false << false << false << WARN_DEFAULT << false // eci-debug
  934. << 0.0 << 0 << 0 << 0 << 0 << 0 // xdimdp
  935. << "zint -b 144 -d '(01)1' --gs1 --gs1parens --gs1nocheck --secure=6 --structapp='1,2,4' --vers=2"
  936. << "zint.exe -b 144 -d \"(01)1\" --gs1 --gs1parens --gs1nocheck --secure=6 --structapp=\"1,2,4\" --vers=2"
  937. << "" << "" << "" << "";
  938. QTest::newRow("BARCODE_UPCE_CC") << true << 0.0f << "out.svg"
  939. << BARCODE_UPCE_CC << UNICODE_MODE // symbology-inputMode
  940. << "12345670+1234" << "[11]901222[99]ABCDE" // text-primary
  941. << 0.0f << -1 << 0 << 0 << 1.0f << 0.0f << false << 0.8f << 1.0f // height-textGap
  942. << 6.5f << 0 << 0 << "" // guardDescent-structAppID
  943. << "" << "" << QColor(0xEF, 0x29, 0x29) << QColor(Qt::white) << false // fgStr-cmyk
  944. << 0 << 0 << 0 << 0 << (BOLD_TEXT | SMALL_TEXT) // borderTypeIndex-fontSetting
  945. << true << false << false << true << true << 0 // showText-rotateAngle
  946. << 0 << false << false << false << false << false << WARN_FAIL_ALL << false // eci-debug
  947. << 0.0 << 0 << 0 << 0 << 0 << 0 // xdimdp
  948. << "zint -b 136 --compliantheight -d '[11]901222[99]ABCDE' --fg=EF2929 --guarddescent=6.5"
  949. " --noquietzones -o 'out.svg' --primary='12345670+1234' --small --werror"
  950. << "zint.exe -b 136 --compliantheight -d \"[11]901222[99]ABCDE\" --fg=EF2929 --guarddescent=6.5"
  951. " --noquietzones -o \"out.svg\" --primary=\"12345670+1234\" --small --werror"
  952. << "zint --barcode=136 --compliantheight --data='[11]901222[99]ABCDE' --fg=EF2929"
  953. " --guarddescent=6.5 --noquietzones --output='out.svg' --primary='12345670+1234' --small --werror"
  954. << "zint -b UPCE_CC --compliantheight -d '[11]901222[99]ABCDE' --fg=EF2929 --guarddescent=6.5"
  955. " --noquietzones -o 'out.svg' --primary='12345670+1234' --small --werror"
  956. << "zint -b 136 --compliantheight -d \"[11]901222[99]ABCDE\" --fg=EF2929 --guarddescent=6.5"
  957. " --noquietzones -o \"out.svg\" --primary=\"12345670+1234\" --small --werror"
  958. << "";
  959. QTest::newRow("BARCODE_VIN") << false << 2.0f << ""
  960. << BARCODE_VIN << UNICODE_MODE // symbology-inputMode
  961. << "12345678701234567" << "" // text-primary
  962. << 20.0f << -1 << 1 << 0 << 1.0f << 0.0f << false << 0.8f << 1.2f // height-textGap
  963. << 5.0f << 0 << 0 << "" // guardDescent-structAppID
  964. << "" << "" << QColor(Qt::black) << QColor(Qt::white) << false // fgStr-cmyk
  965. << 0 << 0 << 0 << 0 << (BOLD_TEXT | SMALL_TEXT) // borderTypeIndex-fontSetting
  966. << true << false << false << false << true << 0 // showText-rotateAngle
  967. << 0 << false << false << false << false << false << WARN_DEFAULT << false // eci-debug
  968. << 0.0 << 0 << 0 << 0 << 0 << 0 // xdimdp
  969. << "zint -b 73 --bold -d '12345678701234567' --height=20 --small --textgap=1.2 --vers=1"
  970. << "zint.exe -b 73 --bold -d \"12345678701234567\" --height=20 --small --textgap=1.2 --vers=1"
  971. << "" << "" << "" << "";
  972. QTest::newRow("BARCODE_VIN (notext)") << false << 2.0f << ""
  973. << BARCODE_VIN << UNICODE_MODE // symbology-inputMode
  974. << "12345678701234567" << "" // text-primary
  975. << 20.0f << -1 << 1 << 0 << 1.0f << 0.0f << false << 0.8f << 1.2f // height-textGap
  976. << 5.0f << 0 << 0 << "" // guardDescent-structAppID
  977. << "" << "" << QColor(Qt::black) << QColor(Qt::white) << false // fgStr-cmyk
  978. << 0 << 0 << 0 << 0 << (BOLD_TEXT | SMALL_TEXT) // borderTypeIndex-fontSetting
  979. << false << false << false << false << true << 0 // showText-rotateAngle
  980. << 0 << false << false << false << false << false << WARN_DEFAULT << false // eci-debug
  981. << 0.0 << 0 << 0 << 0 << 0 << 0 // xdimdp
  982. << "zint -b 73 -d '12345678701234567' --height=20 --notext --vers=1"
  983. << "zint.exe -b 73 -d \"12345678701234567\" --height=20 --notext --vers=1"
  984. << "" << "" << "" << "";
  985. }
  986. void getAsCLITest()
  987. {
  988. Zint::QZint bc;
  989. QString cmd;
  990. QFETCH(bool, autoHeight);
  991. QFETCH(float, heightPerRow);
  992. QFETCH(QString, outfile);
  993. QFETCH(int, symbology);
  994. QFETCH(int, inputMode);
  995. QFETCH(QString, text);
  996. QFETCH(QString, primary);
  997. QFETCH(float, height);
  998. QFETCH(int, option1);
  999. QFETCH(int, option2);
  1000. QFETCH(int, option3);
  1001. QFETCH(float, scale);
  1002. QFETCH(float, dpmm);
  1003. QFETCH(bool, dotty);
  1004. QFETCH(float, dotSize);
  1005. QFETCH(float, textGap);
  1006. QFETCH(float, guardDescent);
  1007. QFETCH(int, structAppCount);
  1008. QFETCH(int, structAppIndex);
  1009. QFETCH(QString, structAppID);
  1010. QFETCH(QString, fgStr);
  1011. QFETCH(QString, bgStr);
  1012. QFETCH(QColor, fgColor);
  1013. QFETCH(QColor, bgColor);
  1014. QFETCH(bool, cmyk);
  1015. QFETCH(int, borderTypeIndex);
  1016. QFETCH(int, borderWidth);
  1017. QFETCH(int, whitespace);
  1018. QFETCH(int, vWhitespace);
  1019. QFETCH(int, fontSetting);
  1020. QFETCH(bool, showText);
  1021. QFETCH(bool, gsSep);
  1022. QFETCH(bool, quietZones);
  1023. QFETCH(bool, noQuietZones);
  1024. QFETCH(bool, compliantHeight);
  1025. QFETCH(int, rotateAngle);
  1026. QFETCH(int, eci);
  1027. QFETCH(bool, gs1Parens);
  1028. QFETCH(bool, gs1NoCheck);
  1029. QFETCH(bool, readerInit);
  1030. QFETCH(bool, guardWhitespace);
  1031. QFETCH(bool, embedVectorFont);
  1032. QFETCH(int, warnLevel);
  1033. QFETCH(bool, debug);
  1034. QFETCH(double, xdimdp_x_dim);
  1035. QFETCH(int, xdimdp_x_dim_units);
  1036. QFETCH(int, xdimdp_resolution);
  1037. QFETCH(int, xdimdp_resolution_units);
  1038. QFETCH(int, xdimdp_filetype);
  1039. QFETCH(int, xdimdp_filetype_maxicode);
  1040. QFETCH(QString, expected_cmd);
  1041. QFETCH(QString, expected_win);
  1042. QFETCH(QString, expected_longOptOnly);
  1043. QFETCH(QString, expected_barcodeNames);
  1044. QFETCH(QString, expected_noexe);
  1045. QFETCH(QString, expected_xdimdp);
  1046. bc.setSymbol(symbology);
  1047. bc.setInputMode(inputMode);
  1048. if (primary.isEmpty()) {
  1049. bc.setText(text);
  1050. } else {
  1051. bc.setText(primary);
  1052. bc.setPrimaryMessage(text);
  1053. }
  1054. bc.setHeight(height);
  1055. bc.setOption1(option1);
  1056. bc.setOption2(option2);
  1057. bc.setOption3(option3);
  1058. bc.setScale(scale);
  1059. bc.setDPMM(dpmm);
  1060. bc.setDotty(dotty);
  1061. bc.setDotSize(dotSize);
  1062. bc.setTextGap(textGap);
  1063. bc.setGuardDescent(guardDescent);
  1064. bc.setStructApp(structAppCount, structAppIndex, structAppID);
  1065. if (fgStr.isEmpty()) {
  1066. bc.setFgColor(fgColor);
  1067. } else {
  1068. bc.setFgStr(fgStr);
  1069. }
  1070. if (bgStr.isEmpty()) {
  1071. bc.setBgColor(bgColor);
  1072. } else {
  1073. bc.setBgStr(bgStr);
  1074. }
  1075. bc.setCMYK(cmyk);
  1076. bc.setBorderType(borderTypeIndex);
  1077. bc.setBorderWidth(borderWidth);
  1078. bc.setWhitespace(whitespace);
  1079. bc.setVWhitespace(vWhitespace);
  1080. bc.setFontSettingValue(fontSetting);
  1081. bc.setShowText(showText);
  1082. bc.setGSSep(gsSep);
  1083. bc.setQuietZones(quietZones);
  1084. bc.setNoQuietZones(noQuietZones);
  1085. bc.setCompliantHeight(compliantHeight);
  1086. bc.setRotateAngleValue(rotateAngle);
  1087. bc.setECIValue(eci);
  1088. bc.setGS1Parens(gs1Parens);
  1089. bc.setGS1NoCheck(gs1NoCheck);
  1090. bc.setReaderInit(readerInit);
  1091. bc.setGuardWhitespace(guardWhitespace);
  1092. bc.setEmbedVectorFont(embedVectorFont);
  1093. bc.setWarnLevel(warnLevel);
  1094. bc.setDebug(debug);
  1095. cmd = bc.getAsCLI(false /*win*/, false /*longOptOnly*/, false /*barcodeNames*/, false /*noEXE*/,
  1096. autoHeight, heightPerRow, outfile);
  1097. QCOMPARE(cmd, expected_cmd);
  1098. cmd = bc.getAsCLI(true /*win*/, false /*longOptOnly*/, false /*barcodeNames*/, false /*noEXE*/,
  1099. autoHeight, heightPerRow, outfile);
  1100. QCOMPARE(cmd, expected_win);
  1101. if (!expected_longOptOnly.isEmpty()) {
  1102. cmd = bc.getAsCLI(false /*win*/, true /*longOptOnly*/, false /*barcodeNames*/, false /*noEXE*/,
  1103. autoHeight, heightPerRow, outfile);
  1104. QCOMPARE(cmd, expected_longOptOnly);
  1105. }
  1106. if (!expected_barcodeNames.isEmpty()) {
  1107. cmd = bc.getAsCLI(false /*win*/, false /*longOptOnly*/, true /*barcodeNames*/, false /*noEXE*/,
  1108. autoHeight, heightPerRow, outfile);
  1109. QCOMPARE(cmd, expected_barcodeNames);
  1110. }
  1111. if (!expected_noexe.isEmpty()) {
  1112. cmd = bc.getAsCLI(true /*win*/, false /*longOptOnly*/, false /*barcodeNames*/, true /*noEXE*/,
  1113. autoHeight, heightPerRow, outfile);
  1114. QCOMPARE(cmd, expected_noexe);
  1115. }
  1116. if (xdimdp_x_dim) {
  1117. /* Avoid clang 14 error "no matching constructor for initialization" by initializing field-wise */
  1118. struct Zint::QZintXdimDpVars vars;
  1119. vars.x_dim = xdimdp_x_dim;
  1120. vars.x_dim_units = xdimdp_x_dim_units;
  1121. vars.resolution = xdimdp_resolution;
  1122. vars.resolution_units = xdimdp_resolution_units;
  1123. vars.filetype = xdimdp_filetype;
  1124. vars.filetype_maxicode = xdimdp_filetype_maxicode;
  1125. vars.set = 1;
  1126. cmd = bc.getAsCLI(false /*win*/, false /*longOptOnly*/, false /*barcodeNames*/, false /*noEXE*/,
  1127. autoHeight, heightPerRow, outfile, &vars);
  1128. QCOMPARE(cmd, expected_xdimdp);
  1129. }
  1130. }
  1131. void getAsCLISegsTest()
  1132. {
  1133. Zint::QZint bc;
  1134. QString cmd;
  1135. QString expected_cmd;
  1136. QString expected_win;
  1137. std::vector<QString> segTexts;
  1138. std::vector<int> segECIs;
  1139. segTexts.push_back(QString("Τεχτ"));
  1140. segECIs.push_back(9);
  1141. segTexts.push_back(QString("Téxt"));
  1142. segECIs.push_back(3);
  1143. segTexts.push_back(QString("กขฯ"));
  1144. segECIs.push_back(13);
  1145. segTexts.push_back(QString("貫やぐ禁"));
  1146. segECIs.push_back(20);
  1147. std::vector<Zint::QZintSeg> segs;
  1148. for (int i = 0; i < (int) segTexts.size(); i++) {
  1149. segs.push_back(Zint::QZintSeg(segTexts[i]));
  1150. segs.back().m_eci = segECIs[i];
  1151. }
  1152. bc.setSymbol(BARCODE_QRCODE);
  1153. bc.setSegs(segs);
  1154. bc.setDotty(true);
  1155. expected_cmd = "zint -b 58 --eci=9 -d 'Τεχτ' --seg1=3,'Téxt' --seg2=13,'กขฯ' --seg3=20,'貫やぐ禁' --dotty";
  1156. cmd = bc.getAsCLI(false /*win*/);
  1157. QCOMPARE(cmd, expected_cmd);
  1158. expected_win = "zint.exe -b 58 --eci=9 -d \"Τεχτ\" --seg1=3,\"Téxt\" --seg2=13,\"กขฯ\" --seg3=20,\"貫やぐ禁\" --dotty";
  1159. cmd = bc.getAsCLI(true /*win*/);
  1160. QCOMPARE(cmd, expected_win);
  1161. }
  1162. void qZintAndLibZintEqualTest_data()
  1163. {
  1164. QTest::addColumn<int>("symbology");
  1165. QTest::addColumn<int>("rotateAngles");
  1166. QTest::addColumn<QString>("text");
  1167. QTest::newRow("symbology=BARCODE_DATAMATRIX rotateAngles=0 text=1234") << BARCODE_DATAMATRIX << 0 << "1234";
  1168. QTest::newRow("symbology=BARCODE_QRCODE rotateAngles=0 text=Hello%20World") << BARCODE_QRCODE << 0 << "Hello%20World";
  1169. QTest::newRow("symbology=BARCODE_QRCODE rotateAngles=90 text=Hello%20World") << BARCODE_QRCODE << 90 << "Hello%20World";
  1170. QTest::newRow("symbology=BARCODE_QRCODE rotateAngles=180 text=Hello%20World") << BARCODE_QRCODE << 180 << "Hello%20World";
  1171. QTest::newRow("symbology=BARCODE_QRCODE rotateAngles=270 text=Hello%20World") << BARCODE_QRCODE << 270 << "Hello%20World";
  1172. }
  1173. void qZintAndLibZintEqualTest()
  1174. {
  1175. QFETCH(int, symbology);
  1176. QFETCH(int, rotateAngles);
  1177. QFETCH(QString, text);
  1178. QString fileName("test_qZintAndLibZintEqual_%1.gif");
  1179. QString fileNameForLibZint(fileName.arg("libZint"));
  1180. QString fileNameForQZint(fileName.arg("qZint"));
  1181. Zint::QZint bc;
  1182. QSharedPointer<zint_symbol> symbol(ZBarcode_Create(), ZBarcode_Delete);
  1183. bc.setSymbol(symbology);
  1184. symbol->symbology = symbology;
  1185. bc.setText(text);
  1186. bc.setRotateAngleValue(rotateAngles);
  1187. qstrcpy(symbol->outfile, qUtf8Printable(fileNameForLibZint));
  1188. bc.save_to_file(fileNameForQZint);
  1189. ZBarcode_Encode_and_Print(symbol.data(), reinterpret_cast<const unsigned char*>(qUtf8Printable(text)), 0, rotateAngles);
  1190. QImage imageWrittenByVanilla(fileNameForLibZint);
  1191. QImage imageWrittenByQZint(fileNameForQZint);
  1192. QCOMPARE(imageWrittenByQZint.isNull(), false);
  1193. QCOMPARE(imageWrittenByVanilla.isNull(), false);
  1194. QCOMPARE(imageWrittenByQZint == imageWrittenByVanilla, true);
  1195. QFile::remove(fileNameForLibZint);
  1196. QFile::remove(fileNameForQZint);
  1197. }
  1198. void barcodeNameTest_data()
  1199. {
  1200. QTest::addColumn<int>("symbology");
  1201. QTest::addColumn<QString>("expected_name");
  1202. QTest::newRow("BARCODE_MAXICODE") << BARCODE_MAXICODE << "BARCODE_MAXICODE";
  1203. QTest::newRow("BARCODE_CODE128AB") << BARCODE_CODE128AB << "BARCODE_CODE128AB";
  1204. QTest::newRow("BARCODE_CODE128B") << BARCODE_CODE128B << "BARCODE_CODE128AB";
  1205. }
  1206. void barcodeNameTest()
  1207. {
  1208. QFETCH(int, symbology);
  1209. QFETCH(QString, expected_name);
  1210. QString name = Zint::QZint::barcodeName(symbology);
  1211. QCOMPARE(name, expected_name);
  1212. }
  1213. };
  1214. #ifdef TESTQZINT_GUILESS
  1215. QTEST_GUILESS_MAIN(TestQZint)
  1216. #else
  1217. QTEST_MAIN(TestQZint)
  1218. #endif
  1219. #include "test_qzint.moc"
  1220. /* vim: set ts=4 sw=4 et : */