Skip to content

Commit

Permalink
improve test code coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolaasuni committed Aug 31, 2016
2 parents d3beaa0 + b8be4f0 commit f268cb4
Show file tree
Hide file tree
Showing 13 changed files with 521 additions and 20 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.12.1
1.13.0
5 changes: 5 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@
"Com\\Tecnick\\Barcode\\": "src"
}
},
"autoload-dev": {
"psr-4":{
"Test\\": "test"
}
},
"repositories": [
{
"type": "vcs",
Expand Down
2 changes: 1 addition & 1 deletion example/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
'EAN8' => array('1234567', 'EAN 8'),
'I25+' => array('0123456789', 'Interleaved 2 of 5 + CHECKSUM'),
'I25' => array('0123456789', 'Interleaved 2 of 5'),
'IMB' => array('0123456789', 'IMB - Intelligent Mail Barcode - Onecode - USPS-B-3200'),
'IMB' => array('00040123456123456789-12345', 'IMB - Intelligent Mail Barcode - Onecode - USPS-B-3200'),
'IMBPRE' => array('fatdfatdfatdfatdfatdfatdfatdfatdfatdfatdfatdfatdfatdfatdfatdfatdf', 'IMB pre-processed'),
'KIX' => array('0123456789', 'KIX (Klant index - Customer index)'),
'MSI+' => array('0123456789', 'MSI + CHECKSUM (modulo 11)'),
Expand Down
6 changes: 3 additions & 3 deletions src/Type/Linear/Imb.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* @category Library
* @package Barcode
* @author Nicola Asuni <info@tecnick.com>
* @copyright 2015-2015 Nicola Asuni - Tecnick.com LTD
* @copyright 2015-2016 Nicola Asuni - Tecnick.com LTD
* @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT)
* @link https://github.com/tecnickcom/tc-lib-barcode
*
Expand Down Expand Up @@ -42,13 +42,13 @@
* when used with a 9 digit Mailer ID. e. The Delivery Point ZIP Code shall be assigned by the mailer for routing
* the mailpiece. This shall replace POSTNET for routing the mailpiece to its final delivery point.
* The length may be 0, 5, 9, or 11 digits. The allowable encoding ranges shall be no ZIP Code, 00000–99999,
* 000000000–999999999, and 00000000000–99999999999.
* 000000000–999999999, and 00000000000–99999999999. An hyphen '-' is required before the zip/delivery point.
*
* @since 2015-02-21
* @category Library
* @package Barcode
* @author Nicola Asuni <info@tecnick.com>
* @copyright 2015-2015 Nicola Asuni - Tecnick.com LTD
* @copyright 2015-2016 Nicola Asuni - Tecnick.com LTD
* @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT)
* @link https://github.com/tecnickcom/tc-lib-barcode
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Type/Square/Datamatrix.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ protected function addPadding($size, $ncw)
*/
protected function getCodewords()
{
if (empty($this->code)) {
if (strlen((string)$this->code) == 0) {
throw new BarcodeException('Empty input');
}

Expand Down
13 changes: 4 additions & 9 deletions src/Type/Square/PdfFourOneSeven.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ protected function setMacroBlockParam()
*/
protected function setBars()
{
if (empty($this->code)) {
if (strlen((string)$this->code) == 0) {
throw new BarcodeException('Empty input');
}
$barcode = $this->getBinSequence();
Expand Down Expand Up @@ -222,7 +222,7 @@ public function getCodewords(&$rows, &$cols, &$ecl)
// count number of codewords
$numcw = count($codewords);
if ($numcw > 925) {
throw new BarcodeException('The maximum codeword capaciy has been reached');
throw new BarcodeException('The maximum codeword capaciy has been reached: '.$numcw.' > 925');
}
$macrocw = $this->getMacroBlock($numcw);
// set error correction level
Expand All @@ -248,13 +248,8 @@ public function getCodewords(&$rows, &$cols, &$ecl)
// calculate padding
$pad = ($size - $nce);
if ($pad > 0) {
if (($size - $rows) == $nce) {
--$rows;
$size -= $rows;
} else {
// add padding
$codewords = array_merge($codewords, array_fill(0, $pad, 900));
}
// add padding
$codewords = array_merge($codewords, array_fill(0, $pad, 900));
}
if (!empty($macrocw)) {
// add macro section
Expand Down
3 changes: 1 addition & 2 deletions src/Type/Square/PdfFourOneSeven/Compaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,11 +165,10 @@ protected function processByteCompaction($code, &$codewords)
protected function processNumericCompaction($code, &$codewords)
{
while (($codelen = strlen($code)) > 0) {
$rest = '';
if ($codelen > 44) {
$rest = substr($code, 44);
$code = substr($code, 0, 44);
} else {
$rest = '';
}
$tdg = '1'.$code;
do {
Expand Down
2 changes: 1 addition & 1 deletion src/Type/Square/PdfFourOneSeven/Sequence.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ protected function getInputSequences($code)
$sequence_array = array(); // array to be returned
$numseq = array();
// get numeric sequences
preg_match_all('/([0-9]{13,44})/', $code, $numseq, PREG_OFFSET_CAPTURE);
preg_match_all('/([0-9]{13,})/', $code, $numseq, PREG_OFFSET_CAPTURE);
$numseq[1][] = array('', strlen($code));
$offset = 0;
foreach ($numseq[1] as $seq) {
Expand Down
2 changes: 1 addition & 1 deletion src/Type/Square/QrCode.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ protected function setParameters()
*/
protected function setBars()
{
if (empty($this->code)) {
if (strlen((string)$this->code) == 0) {
throw new BarcodeException('Empty input');
}
$this->bsObj = new ByteStream($this->hint, $this->version, $this->level);
Expand Down
38 changes: 38 additions & 0 deletions test/Square/DatamatrixTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,4 +129,42 @@ public function testLongInput()
$code = str_pad('', 3000, 'X');
$this->obj->getBarcodeObj('DATAMATRIX', $code);
}

/**
* @dataProvider getStringDataProvider
*/
public function testStrings($code)
{
$bobj = $this->obj->getBarcodeObj('DATAMATRIX', $code);
$this->assertNotNull($bobj);
}

public function getStringDataProvider()
{
return \Test\TestStrings::getDataProvider();
}

public function testEncodeTXTC40shiftException()
{
$this->setExpectedException('\Com\Tecnick\Barcode\Exception');
$obj = new \Com\Tecnick\Barcode\Type\Square\Datamatrix\Encode();
$chr = null;
$enc = null;
$temp_cw = null;
$ptr = null;
$obj->encodeTXTC40shift($chr, $enc, $temp_cw, $ptr);
}

public function testEncodeTXTC40Exception()
{
$this->setExpectedException('\Com\Tecnick\Barcode\Exception');
$obj = new \Com\Tecnick\Barcode\Type\Square\Datamatrix\Encode();
$data = array(chr(0x80));
$enc = \Com\Tecnick\Barcode\Type\Square\Datamatrix\Data::ENC_X12;
$temp_cw = null;
$ptr = null;
$epos = 0;
$charset = null;
$obj->encodeTXTC40($data, $enc, $temp_cw, $ptr, $epos, $charset);
}
}
18 changes: 17 additions & 1 deletion test/Square/PdfFourOneSevenTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,12 @@ public function testGetGrid($options, $code, $expected)
public function getGridDataProvider()
{
return array(
array('', str_pad('', 1850, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'), '38e205c911b94a62c72b7d20fa4361f8'), // max text
array('', str_pad('', 2710, '123456789'), '32ba9be56f3e66559b4d4a50f6276da7'), // max digits
array('', '0123456789', '4f9cdac81d62f0020beb93fc3ecdd8ad'),
array(',2,8,1,0,0,0,1,2', str_pad('', 1750, 'X'), 'f0874a35e15f11f9aa8bc070a4be24bf'),
array(',15,8,1,0,0,0,1,2', str_pad('', 1750, 'X'), '0288f0a87cc069fc34d6168d7a9f7846'),
array('', str_pad('', 350, '0123456789'), '0cc58a566988776b05f9ec1eb046bd7c'),
array('', str_pad('', 350, '0123456789'), '394d93048831fee232413da29fb709fb'),
array('', 'abcdefghijklmnopqrstuvwxyz01234567890123456789', 'bd4f4215aca0bbc3452a35b81fcf7bdb'),
array(
'',
Expand Down Expand Up @@ -192,4 +194,18 @@ public function getGridDataProvider()
),
);
}

/**
* @dataProvider getStringDataProvider
*/
public function testStrings($code)
{
$bobj = $this->obj->getBarcodeObj('PDF417', $code);
$this->assertNotNull($bobj);
}

public function getStringDataProvider()
{
return \Test\TestStrings::getDataProvider();
}
}
14 changes: 14 additions & 0 deletions test/Square/QrCodeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -265,4 +265,18 @@ public function testLong()
$code = str_pad('', 4000, 'iVoo{[O17n~>(FXC9{*t1P532}l7E{7/R\' ObO`y?`9G(qjBmu7 GM3ZK!qp|)!P1" sRanqC(:Ky');
$this->obj->getBarcodeObj('QRCODE', $code);
}

/**
* @dataProvider getStringDataProvider
*/
public function testStrings($code)
{
$bobj = $this->obj->getBarcodeObj('QRCODE', $code);
$this->assertNotNull($bobj);
}

public function getStringDataProvider()
{
return \Test\TestStrings::getDataProvider();
}
}

0 comments on commit f268cb4

Please sign in to comment.