EncoderTest.php 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468
  1. <?php
  2. /**
  3. * BaconQrCode
  4. *
  5. * @link http://github.com/Bacon/BaconQrCode For the canonical source repository
  6. * @copyright 2013 Ben 'DASPRiD' Scholzen
  7. * @license http://opensource.org/licenses/BSD-2-Clause Simplified BSD License
  8. */
  9. namespace BaconQrCode\Encoder;
  10. use BaconQrCode\Common\BitArray;
  11. use BaconQrCode\Common\ErrorCorrectionLevel;
  12. use BaconQrCode\Common\Mode;
  13. use BaconQrCode\Common\Version;
  14. use PHPUnit_Framework_TestCase as TestCase;
  15. use ReflectionClass;
  16. use ReflectionMethod;
  17. use SplFixedArray;
  18. class EncoderTest extends TestCase
  19. {
  20. protected $methods = array();
  21. public function setUp()
  22. {
  23. // Hack to be able to test protected methods
  24. $reflection = new ReflectionClass('BaconQrCode\Encoder\Encoder');
  25. foreach ($reflection->getMethods(ReflectionMethod::IS_STATIC) as $method) {
  26. $method->setAccessible(true);
  27. $this->methods[$method->getName()] = $method;
  28. }
  29. }
  30. public function testGetAlphanumericCode()
  31. {
  32. // The first ten code points are numbers.
  33. for ($i = 0; $i < 10; $i++) {
  34. $this->assertEquals($i, $this->methods['getAlphanumericCode']->invoke(null, ord('0') + $i));
  35. }
  36. // The next 26 code points are capital alphabet letters.
  37. for ($i = 10; $i < 36; $i++) {
  38. // The first ten code points are numbers
  39. $this->assertEquals($i, $this->methods['getAlphanumericCode']->invoke(null, ord('A') + $i - 10));
  40. }
  41. // Others are symbol letters.
  42. $this->assertEquals(36, $this->methods['getAlphanumericCode']->invoke(null, ' '));
  43. $this->assertEquals(37, $this->methods['getAlphanumericCode']->invoke(null, '$'));
  44. $this->assertEquals(38, $this->methods['getAlphanumericCode']->invoke(null, '%'));
  45. $this->assertEquals(39, $this->methods['getAlphanumericCode']->invoke(null, '*'));
  46. $this->assertEquals(40, $this->methods['getAlphanumericCode']->invoke(null, '+'));
  47. $this->assertEquals(41, $this->methods['getAlphanumericCode']->invoke(null, '-'));
  48. $this->assertEquals(42, $this->methods['getAlphanumericCode']->invoke(null, '.'));
  49. $this->assertEquals(43, $this->methods['getAlphanumericCode']->invoke(null, '/'));
  50. $this->assertEquals(44, $this->methods['getAlphanumericCode']->invoke(null, ':'));
  51. // Should return -1 for other letters.
  52. $this->assertEquals(-1, $this->methods['getAlphanumericCode']->invoke(null, 'a'));
  53. $this->assertEquals(-1, $this->methods['getAlphanumericCode']->invoke(null, '#'));
  54. $this->assertEquals(-1, $this->methods['getAlphanumericCode']->invoke(null, "\0"));
  55. }
  56. public function testChooseMode()
  57. {
  58. // Numeric mode
  59. $this->assertSame(Mode::NUMERIC, $this->methods['chooseMode']->invoke(null, '0')->get());
  60. $this->assertSame(Mode::NUMERIC, $this->methods['chooseMode']->invoke(null, '0123456789')->get());
  61. // Alphanumeric mode
  62. $this->assertSame(Mode::ALPHANUMERIC, $this->methods['chooseMode']->invoke(null, 'A')->get());
  63. $this->assertSame(Mode::ALPHANUMERIC, $this->methods['chooseMode']->invoke(null, '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:')->get());
  64. // 8-bit byte mode
  65. $this->assertSame(Mode::BYTE, $this->methods['chooseMode']->invoke(null, 'a')->get());
  66. $this->assertSame(Mode::BYTE, $this->methods['chooseMode']->invoke(null, '#')->get());
  67. $this->assertSame(Mode::BYTE, $this->methods['chooseMode']->invoke(null, '')->get());
  68. // AIUE in Hiragana in SHIFT-JIS
  69. $this->assertSame(Mode::BYTE, $this->methods['chooseMode']->invoke(null, "\x8\xa\x8\xa\x8\xa\x8\xa6")->get());
  70. // Nihon in Kanji in SHIFT-JIS
  71. $this->assertSame(Mode::BYTE, $this->methods['chooseMode']->invoke(null, "\x9\xf\x9\x7b")->get());
  72. // Sou-Utso-Byou in Kanji in SHIFT-JIS
  73. $this->assertSame(Mode::BYTE, $this->methods['chooseMode']->invoke(null, "\xe\x4\x9\x5\x9\x61")->get());
  74. }
  75. public function testEncode()
  76. {
  77. $qrCode = Encoder::encode('ABCDEF', new ErrorCorrectionLevel(ErrorCorrectionLevel::H));
  78. $expected = "<<\n"
  79. . " mode: ALPHANUMERIC\n"
  80. . " ecLevel: H\n"
  81. . " version: 1\n"
  82. . " maskPattern: 0\n"
  83. . " matrix:\n"
  84. . " 1 1 1 1 1 1 1 0 1 1 1 1 0 0 1 1 1 1 1 1 1\n"
  85. . " 1 0 0 0 0 0 1 0 0 1 1 1 0 0 1 0 0 0 0 0 1\n"
  86. . " 1 0 1 1 1 0 1 0 0 1 0 1 1 0 1 0 1 1 1 0 1\n"
  87. . " 1 0 1 1 1 0 1 0 1 1 1 0 1 0 1 0 1 1 1 0 1\n"
  88. . " 1 0 1 1 1 0 1 0 0 1 1 1 0 0 1 0 1 1 1 0 1\n"
  89. . " 1 0 0 0 0 0 1 0 0 1 0 0 0 0 1 0 0 0 0 0 1\n"
  90. . " 1 1 1 1 1 1 1 0 1 0 1 0 1 0 1 1 1 1 1 1 1\n"
  91. . " 0 0 0 0 0 0 0 0 0 0 1 0 1 0 0 0 0 0 0 0 0\n"
  92. . " 0 0 1 0 1 1 1 0 1 1 0 0 1 1 0 0 0 1 0 0 1\n"
  93. . " 1 0 1 1 1 0 0 1 0 0 0 1 0 1 0 0 0 0 0 0 0\n"
  94. . " 0 0 1 1 0 0 1 0 1 0 0 0 1 0 1 0 1 0 1 1 0\n"
  95. . " 1 1 0 1 0 1 0 1 1 1 0 1 0 1 0 0 0 0 0 1 0\n"
  96. . " 0 0 1 1 0 1 1 1 1 0 0 0 1 0 1 0 1 1 1 1 0\n"
  97. . " 0 0 0 0 0 0 0 0 1 0 0 1 1 1 0 1 0 1 0 0 0\n"
  98. . " 1 1 1 1 1 1 1 0 0 0 1 0 1 0 1 1 0 0 0 0 1\n"
  99. . " 1 0 0 0 0 0 1 0 1 1 1 1 0 1 0 1 1 1 1 0 1\n"
  100. . " 1 0 1 1 1 0 1 0 1 0 1 1 0 1 0 1 0 0 0 0 1\n"
  101. . " 1 0 1 1 1 0 1 0 0 1 1 0 1 1 1 1 0 1 0 1 0\n"
  102. . " 1 0 1 1 1 0 1 0 1 0 0 0 1 0 1 0 1 1 1 0 1\n"
  103. . " 1 0 0 0 0 0 1 0 0 1 1 0 1 1 0 1 0 0 0 1 1\n"
  104. . " 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 1 0 1 0 1\n"
  105. . ">>\n";
  106. $this->assertEquals($expected, $qrCode->__toString());
  107. }
  108. public function testSimpleUtf8Eci()
  109. {
  110. $qrCode = Encoder::encode('hello', new ErrorCorrectionLevel(ErrorCorrectionLevel::H), 'utf-8');
  111. $expected = "<<\n"
  112. . " mode: BYTE\n"
  113. . " ecLevel: H\n"
  114. . " version: 1\n"
  115. . " maskPattern: 3\n"
  116. . " matrix:\n"
  117. . " 1 1 1 1 1 1 1 0 0 0 0 0 0 0 1 1 1 1 1 1 1\n"
  118. . " 1 0 0 0 0 0 1 0 0 0 1 0 1 0 1 0 0 0 0 0 1\n"
  119. . " 1 0 1 1 1 0 1 0 0 1 0 1 0 0 1 0 1 1 1 0 1\n"
  120. . " 1 0 1 1 1 0 1 0 0 1 1 0 1 0 1 0 1 1 1 0 1\n"
  121. . " 1 0 1 1 1 0 1 0 1 0 1 0 1 0 1 0 1 1 1 0 1\n"
  122. . " 1 0 0 0 0 0 1 0 0 0 0 0 1 0 1 0 0 0 0 0 1\n"
  123. . " 1 1 1 1 1 1 1 0 1 0 1 0 1 0 1 1 1 1 1 1 1\n"
  124. . " 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 0 0 0 0\n"
  125. . " 0 0 1 1 0 0 1 1 1 1 0 0 0 1 1 0 1 0 0 0 0\n"
  126. . " 0 0 1 1 1 0 0 0 0 0 1 1 0 0 0 1 0 1 1 1 0\n"
  127. . " 0 1 0 1 0 1 1 1 0 1 0 1 0 0 0 0 0 1 1 1 1\n"
  128. . " 1 1 0 0 1 0 0 1 1 0 0 1 1 1 1 0 1 0 1 1 0\n"
  129. . " 0 0 0 0 1 0 1 1 1 1 0 0 0 0 0 1 0 0 1 0 0\n"
  130. . " 0 0 0 0 0 0 0 0 1 1 1 1 0 0 1 1 1 0 0 0 1\n"
  131. . " 1 1 1 1 1 1 1 0 1 1 1 0 1 0 1 1 0 0 1 0 0\n"
  132. . " 1 0 0 0 0 0 1 0 0 0 1 0 0 1 1 1 1 1 1 0 1\n"
  133. . " 1 0 1 1 1 0 1 0 0 1 0 0 0 0 1 1 0 0 0 0 0\n"
  134. . " 1 0 1 1 1 0 1 0 1 1 1 0 1 0 0 0 1 1 0 0 0\n"
  135. . " 1 0 1 1 1 0 1 0 1 1 0 0 0 1 0 0 1 0 0 0 0\n"
  136. . " 1 0 0 0 0 0 1 0 0 0 0 1 1 0 1 0 1 0 1 1 0\n"
  137. . " 1 1 1 1 1 1 1 0 0 1 0 1 1 1 0 1 1 0 0 0 0\n"
  138. . ">>\n";
  139. $this->assertEquals($expected, $qrCode->__toString());
  140. }
  141. public function testAppendModeInfo()
  142. {
  143. $bits = new BitArray();
  144. $this->methods['appendModeInfo']->invoke(null, new Mode(Mode::NUMERIC), $bits);
  145. $this->assertEquals(' ...X', $bits->__toString());
  146. }
  147. public function testAppendLengthInfo()
  148. {
  149. // 1 letter (1/1), 10 bits.
  150. $bits = new BitArray();
  151. $this->methods['appendLengthInfo']->invoke(
  152. null,
  153. 1,
  154. Version::getVersionForNumber(1),
  155. new Mode(Mode::NUMERIC),
  156. $bits
  157. );
  158. $this->assertEquals(' ........ .X', $bits->__toString());
  159. // 2 letters (2/1), 11 bits.
  160. $bits = new BitArray();
  161. $this->methods['appendLengthInfo']->invoke(
  162. null,
  163. 2,
  164. Version::getVersionForNumber(10),
  165. new Mode(Mode::ALPHANUMERIC),
  166. $bits
  167. );
  168. $this->assertEquals(' ........ .X.', $bits->__toString());
  169. // 255 letters (255/1), 16 bits.
  170. $bits = new BitArray();
  171. $this->methods['appendLengthInfo']->invoke(
  172. null,
  173. 255,
  174. Version::getVersionForNumber(27),
  175. new Mode(Mode::BYTE),
  176. $bits
  177. );
  178. $this->assertEquals(' ........ XXXXXXXX', $bits->__toString());
  179. // 512 letters (1024/2), 12 bits.
  180. $bits = new BitArray();
  181. $this->methods['appendLengthInfo']->invoke(
  182. null,
  183. 512,
  184. Version::getVersionForNumber(40),
  185. new Mode(Mode::KANJI),
  186. $bits
  187. );
  188. $this->assertEquals(' ..X..... ....', $bits->__toString());
  189. }
  190. public function testAppendBytes()
  191. {
  192. // Should use appendNumericBytes.
  193. // 1 = 01 = 0001 in 4 bits.
  194. $bits = new BitArray();
  195. $this->methods['appendBytes']->invoke(
  196. null,
  197. '1',
  198. new Mode(Mode::NUMERIC),
  199. $bits,
  200. Encoder::DEFAULT_BYTE_MODE_ECODING
  201. );
  202. $this->assertEquals(' ...X', $bits->__toString());
  203. // Should use appendAlphaNumericBytes.
  204. // A = 10 = 0xa = 001010 in 6 bits.
  205. $bits = new BitArray();
  206. $this->methods['appendBytes']->invoke(
  207. null,
  208. 'A',
  209. new Mode(Mode::ALPHANUMERIC),
  210. $bits,
  211. Encoder::DEFAULT_BYTE_MODE_ECODING
  212. );
  213. $this->assertEquals(' ..X.X.', $bits->__toString());
  214. // Should use append8BitBytes.
  215. // 0x61, 0x62, 0x63
  216. $bits = new BitArray();
  217. $this->methods['appendBytes']->invoke(
  218. null,
  219. 'abc',
  220. new Mode(Mode::BYTE),
  221. $bits,
  222. Encoder::DEFAULT_BYTE_MODE_ECODING
  223. );
  224. $this->assertEquals(' .XX....X .XX...X. .XX...XX', $bits->__toString());
  225. // Should use appendKanjiBytes.
  226. // 0x93, 0x5f
  227. $bits = new BitArray();
  228. $this->methods['appendBytes']->invoke(
  229. null,
  230. "\x93\x5f",
  231. new Mode(Mode::KANJI),
  232. $bits,
  233. Encoder::DEFAULT_BYTE_MODE_ECODING
  234. );
  235. $this->assertEquals(' .XX.XX.. XXXXX', $bits->__toString());
  236. // Lower letters such as 'a' cannot be encoded in alphanumeric mode.
  237. $this->setExpectedException(
  238. 'BaconQrCode\Exception\WriterException',
  239. 'Invalid alphanumeric code'
  240. );
  241. $this->methods['appendBytes']->invoke(
  242. null,
  243. "a",
  244. new Mode(Mode::ALPHANUMERIC),
  245. $bits,
  246. Encoder::DEFAULT_BYTE_MODE_ECODING
  247. );
  248. }
  249. public function testTerminateBits()
  250. {
  251. $bits = new BitArray();
  252. $this->methods['terminateBits']->invoke(null, 0, $bits);
  253. $this->assertEquals('', $bits->__toString());
  254. $bits = new BitArray();
  255. $this->methods['terminateBits']->invoke(null, 1, $bits);
  256. $this->assertEquals(' ........', $bits->__toString());
  257. $bits = new BitArray();
  258. $bits->appendBits(0, 3);
  259. $this->methods['terminateBits']->invoke(null, 1, $bits);
  260. $this->assertEquals(' ........', $bits->__toString());
  261. $bits = new BitArray();
  262. $bits->appendBits(0, 5);
  263. $this->methods['terminateBits']->invoke(null, 1, $bits);
  264. $this->assertEquals(' ........', $bits->__toString());
  265. $bits = new BitArray();
  266. $bits->appendBits(0, 8);
  267. $this->methods['terminateBits']->invoke(null, 1, $bits);
  268. $this->assertEquals(' ........', $bits->__toString());
  269. $bits = new BitArray();
  270. $this->methods['terminateBits']->invoke(null, 2, $bits);
  271. $this->assertEquals(' ........ XXX.XX..', $bits->__toString());
  272. $bits = new BitArray();
  273. $bits->appendBits(0, 1);
  274. $this->methods['terminateBits']->invoke(null, 3, $bits);
  275. $this->assertEquals(' ........ XXX.XX.. ...X...X', $bits->__toString());
  276. }
  277. public function testGetNumDataBytesAndNumEcBytesForBlockId()
  278. {
  279. // Version 1-H.
  280. list($numDataBytes, $numEcBytes) = $this->methods['getNumDataBytesAndNumEcBytesForBlockId']->invoke(null, 26, 9, 1, 0);
  281. $this->assertEquals(9, $numDataBytes);
  282. $this->assertEquals(17, $numEcBytes);
  283. // Version 3-H. 2 blocks.
  284. list($numDataBytes, $numEcBytes) = $this->methods['getNumDataBytesAndNumEcBytesForBlockId']->invoke(null, 70, 26, 2, 0);
  285. $this->assertEquals(13, $numDataBytes);
  286. $this->assertEquals(22, $numEcBytes);
  287. list($numDataBytes, $numEcBytes) = $this->methods['getNumDataBytesAndNumEcBytesForBlockId']->invoke(null, 70, 26, 2, 1);
  288. $this->assertEquals(13, $numDataBytes);
  289. $this->assertEquals(22, $numEcBytes);
  290. // Version 7-H. (4 + 1) blocks.
  291. list($numDataBytes, $numEcBytes) = $this->methods['getNumDataBytesAndNumEcBytesForBlockId']->invoke(null, 196, 66, 5, 0);
  292. $this->assertEquals(13, $numDataBytes);
  293. $this->assertEquals(26, $numEcBytes);
  294. list($numDataBytes, $numEcBytes) = $this->methods['getNumDataBytesAndNumEcBytesForBlockId']->invoke(null, 196, 66, 5, 4);
  295. $this->assertEquals(14, $numDataBytes);
  296. $this->assertEquals(26, $numEcBytes);
  297. // Version 40-H. (20 + 61) blocks.
  298. list($numDataBytes, $numEcBytes) = $this->methods['getNumDataBytesAndNumEcBytesForBlockId']->invoke(null, 3706, 1276, 81, 0);
  299. $this->assertEquals(15, $numDataBytes);
  300. $this->assertEquals(30, $numEcBytes);
  301. list($numDataBytes, $numEcBytes) = $this->methods['getNumDataBytesAndNumEcBytesForBlockId']->invoke(null, 3706, 1276, 81, 20);
  302. $this->assertEquals(16, $numDataBytes);
  303. $this->assertEquals(30, $numEcBytes);
  304. list($numDataBytes, $numEcBytes) = $this->methods['getNumDataBytesAndNumEcBytesForBlockId']->invoke(null, 3706, 1276, 81, 80);
  305. $this->assertEquals(16, $numDataBytes);
  306. $this->assertEquals(30, $numEcBytes);
  307. }
  308. public function testInterleaveWithEcBytes()
  309. {
  310. $dataBytes = SplFixedArray::fromArray(array(32, 65, 205, 69, 41, 220, 46, 128, 236), false);
  311. $in = new BitArray();
  312. foreach ($dataBytes as $dataByte) {
  313. $in->appendBits($dataByte, 8);
  314. }
  315. $outBits = $this->methods['interleaveWithEcBytes']->invoke(null, $in, 26, 9, 1);
  316. $expected = SplFixedArray::fromArray(array(
  317. // Data bytes.
  318. 32, 65, 205, 69, 41, 220, 46, 128, 236,
  319. // Error correction bytes.
  320. 42, 159, 74, 221, 244, 169, 239, 150, 138, 70, 237, 85, 224, 96, 74, 219, 61,
  321. ), false);
  322. $out = $outBits->toBytes(0, count($expected));
  323. $this->assertEquals($expected, $out);
  324. }
  325. public function testAppendNumericBytes()
  326. {
  327. // 1 = 01 = 0001 in 4 bits.
  328. $bits = new BitArray();
  329. $this->methods['appendNumericBytes']->invoke(null, '1', $bits);
  330. $this->assertEquals(' ...X', $bits->__toString());
  331. // 12 = 0xc = 0001100 in 7 bits.
  332. $bits = new BitArray();
  333. $this->methods['appendNumericBytes']->invoke(null, '12', $bits);
  334. $this->assertEquals(' ...XX..', $bits->__toString());
  335. // 123 = 0x7b = 0001111011 in 10 bits.
  336. $bits = new BitArray();
  337. $this->methods['appendNumericBytes']->invoke(null, '123', $bits);
  338. $this->assertEquals(' ...XXXX. XX', $bits->__toString());
  339. // 1234 = "123" + "4" = 0001111011 + 0100 in 14 bits.
  340. $bits = new BitArray();
  341. $this->methods['appendNumericBytes']->invoke(null, '1234', $bits);
  342. $this->assertEquals(' ...XXXX. XX.X..', $bits->__toString());
  343. // Empty
  344. $bits = new BitArray();
  345. $this->methods['appendNumericBytes']->invoke(null, '', $bits);
  346. $this->assertEquals('', $bits->__toString());
  347. }
  348. public function testAppendAlphanumericBytes()
  349. {
  350. $bits = new BitArray();
  351. $this->methods['appendAlphanumericBytes']->invoke(null, 'A', $bits);
  352. $this->assertEquals(' ..X.X.', $bits->__toString());
  353. $bits = new BitArray();
  354. $this->methods['appendAlphanumericBytes']->invoke(null, 'AB', $bits);
  355. $this->assertEquals(' ..XXX..X X.X', $bits->__toString());
  356. $bits = new BitArray();
  357. $this->methods['appendAlphanumericBytes']->invoke(null, 'ABC', $bits);
  358. $this->assertEquals(' ..XXX..X X.X..XX. .', $bits->__toString());
  359. // Empty
  360. $bits = new BitArray();
  361. $this->methods['appendAlphanumericBytes']->invoke(null, '', $bits);
  362. $this->assertEquals('', $bits->__toString());
  363. // Invalid data
  364. $this->setExpectedException('BaconQrCode\Exception\WriterException', 'Invalid alphanumeric code');
  365. $bits = new BitArray();
  366. $this->methods['appendAlphanumericBytes']->invoke(null, 'abc', $bits);
  367. }
  368. public function testAppend8BitBytes()
  369. {
  370. // 0x61, 0x62, 0x63
  371. $bits = new BitArray();
  372. $this->methods['append8BitBytes']->invoke(null, 'abc', $bits, Encoder::DEFAULT_BYTE_MODE_ECODING);
  373. $this->assertEquals(' .XX....X .XX...X. .XX...XX', $bits->__toString());
  374. // Empty
  375. $bits = new BitArray();
  376. $this->methods['append8BitBytes']->invoke(null, '', $bits, Encoder::DEFAULT_BYTE_MODE_ECODING);
  377. $this->assertEquals('', $bits->__toString());
  378. }
  379. public function testAppendKanjiBytes()
  380. {
  381. // Numbers are from page 21 of JISX0510:2004
  382. $bits = new BitArray();
  383. $this->methods['appendKanjiBytes']->invoke(null, "\x93\x5f", $bits);
  384. $this->assertEquals(' .XX.XX.. XXXXX', $bits->__toString());
  385. $this->methods['appendKanjiBytes']->invoke(null, "\xe4\xaa", $bits);
  386. $this->assertEquals(' .XX.XX.. XXXXXXX. X.X.X.X. X.', $bits->__toString());
  387. }
  388. public function testGenerateEcBytes()
  389. {
  390. // Numbers are from http://www.swetake.com/qr/qr3.html and
  391. // http://www.swetake.com/qr/qr9.html
  392. $dataBytes = SplFixedArray::fromArray(array(32, 65, 205, 69, 41, 220, 46, 128, 236), false);
  393. $ecBytes = $this->methods['generateEcBytes']->invoke(null, $dataBytes, 17);
  394. $expected = SplFixedArray::fromArray(array(42, 159, 74, 221, 244, 169, 239, 150, 138, 70, 237, 85, 224, 96, 74, 219, 61), false);
  395. $this->assertEquals($expected, $ecBytes);
  396. $dataBytes = SplFixedArray::fromArray(array(67, 70, 22, 38, 54, 70, 86, 102, 118, 134, 150, 166, 182, 198, 214), false);
  397. $ecBytes = $this->methods['generateEcBytes']->invoke(null, $dataBytes, 18);
  398. $expected = SplFixedArray::fromArray(array(175, 80, 155, 64, 178, 45, 214, 233, 65, 209, 12, 155, 117, 31, 140, 214, 27, 187), false);
  399. $this->assertEquals($expected, $ecBytes);
  400. // High-order zero coefficient case.
  401. $dataBytes = SplFixedArray::fromArray(array(32, 49, 205, 69, 42, 20, 0, 236, 17), false);
  402. $ecBytes = $this->methods['generateEcBytes']->invoke(null, $dataBytes, 17);
  403. $expected = SplFixedArray::fromArray(array(0, 3, 130, 179, 194, 0, 55, 211, 110, 79, 98, 72, 170, 96, 211, 137, 213), false);
  404. $this->assertEquals($expected, $ecBytes);
  405. }
  406. }