Skip to content

Code Coverage

metafloor edited this page Aug 29, 2016 · 2 revisions

This is the state of the test cases coverage as of 2016-06-14.

Total number of branches:    3877
Number of covered branches:  3027
Percent branch coverage:     78.1%
Total lines of code:        25219
Covered lines of code:      19735
Percent LOC coverage:        78.3%
Barcode Type Total Branches Branches Covered Percent
auspost 32 32 100%
azteccode 135 128 95%
azteccodecompact 2 2 100%
aztecrune 2 2 100%
bc412 23 16 70%
channelcode 25 19 76%
codablockf 117 81 69%
code11 30 16 53%
code128 89 72 81%
code16k 142 72 51%
code2of5 23 22 96%
code32 14 10 71%
code39 24 24 100%
code39ext 8 7 88%
code49 76 48 63%
code93 18 17 94%
code93ext 6 6 100%
codeone 260 135 52%
coop2of5 2 2 100%
daft 10 8 80%
databarexpanded 209 149 71%
databarexpandedcomposite 15 13 87%
databarexpandedstacked 2 2 100%
databarexpandedstackedcomposite 13 12 92%
databarlimited 56 51 91%
databarlimitedcomposite 5 3 60%
databaromni 98 93 95%
databaromnicomposite 14 12 86%
databarstacked 10 6 60%
databarstackedcomposite 12 9 75%
databarstackedomni 10 6 60%
databarstackedomnicomposite 12 9 75%
databartruncated 10 6 60%
databartruncatedcomposite 14 12 86%
datalogic2of5 2 2 100%
datamatrix 315 265 84%
datamatrixrectangular 2 1 50%
ean13 42 42 100%
ean13composite 6 5 83%
ean14 14 9 64%
ean2 16 16 100%
ean5 19 19 100%
ean8 40 40 100%
ean8composite 6 5 83%
flattermarken 10 8 80%
gs1-128 24 23 96%
gs1-128composite 13 11 85%
gs1-cc 181 103 57%
gs1datamatrix 21 19 90%
gs1datamatrixrectangular 21 19 90%
gs1qrcode 21 19 90%
hanxin 109 98 90%
hibcazteccode 9 4 44%
hibccodablockf 9 4 44%
hibccode128 10 5 50%
hibccode39 10 5 50%
hibcdatamatrix 9 4 44%
hibcdatamatrixrectangular 9 4 44%
hibcmicropdf417 9 4 44%
hibcpdf417 9 4 44%
hibcqrcode 9 4 44%
iata2of5 2 2 100%
identcode 10 7 70%
industrial2of5 2 2 100%
interleaved2of5 17 15 88%
isbn 57 53 93%
ismn 50 29 58%
issn 33 19 58%
itf14 13 10 77%
japanpost 18 17 94%
kix 13 12 92%
leitcode 10 7 70%
matrix2of5 2 2 100%
maxicode 85 58 68%
micropdf417 127 96 76%
microqrcode 2 1 50%
msi 30 28 93%
onecode 47 43 91%
pdf417 130 118 91%
pdf417compact 2 2 100%
pharmacode 12 9 75%
pharmacode2 11 8 73%
planet 19 14 74%
plessey 20 15 75%
posicode 64 40 63%
postnet 19 14 74%
pzn 12 5 42%
qrcode 285 256 90%
rationalizedCodabar 29 19 66%
raw 7 6 86%
royalmail 19 18 95%
sscc18 14 10 71%
symbol 7 7 100%
telepen 16 13 81%
telepennumeric 2 2 100%
upca 56 56 100%
upcacomposite 6 5 83%
upce 58 58 100%
upcecomposite 9 8 89%

If there is a barcode encoder that has low test coverage that you would like to adopt, please help out.

To run the tests, you will first need to follow the instructions in Compiling bwipjs. Make sure to install ghostscript and create the gs wrapper script, if necessary.

Next we need to create test cases. Take a look at the bwip-js/runtests script to see the existing test cases. The format reflects what you would enter in the bwipjs demo:

run <encoder> "<barcode text>" "<options>"

Then click on the encoder link in the table above. That takes you to the code coverage map for the encoder. Black text has been covered. Red text needs a test case.

Low priority are the branches that contain a call to raiseerror (although test cases for them will be happily accepted).

Highest priority are forall loops that have either of the following structures:

// With callback
$forall(<expression>, function() {
	<lots of red code here>
});

// Without callback
$forall(<expression>);

Those loops implement a slow-path as the trace compiler was not able to properly analyze the type of object in the forall-expression and had to let the runtime library determine the correct postscript semantics.

The goal is to have test coverage for all of these worst-case loops. The cross-compiler can then be enhanced with runtime feedback that allows it to emit optimized code.

Next highest priority are loop bodies with any red code. Loops can be tricky in postscript and may manipulate the operand stack in unexpected ways. Each one needs testing.

Trying to determine a test case that will exercise a branch of code is a bit of an art. Postscript is not an intuitive language and has a fairly steep learning curve. The code generated by the cross-compiler, in my opinion, is actually easier to read than the original postscript (Terry will likely disagree!).

Before running your test cases, you need to build bwipjs with code coverage enabled. Simply:

$ ./psc --with-coverage

The new bwipp.js will contain embedded logic to record branch coverage at runtime. This code is not as performant as the standard bwipp.js code so remember to re-compile your code without coverage after you are done:

$ ./psc  # do this only after you are done with code coverage testing

Now, add your test cases to runtests under the existing test cases for the encoder. Run the tests and generate a new coverage map:

$ ./runtests <encoder>
$ ./uncover

Where <encoder> is the name of the encoder you added test cases for.

uncover will update covermap.html in your local directory. Go to your browser and use a file:/// URL to navigate to the page. For example, if you installed bwipjs under C:\, the URL will be:

file:///c:/bwip-js/covermap.html#encoder

Where encoder is the name of the encoder. Verify that the test cases covered the code branches you were targetting.

Finally, use the demo to verify that your test cases are either generating a barcode or the expected error message.

Please submit your tests cases as a new issue on the project's github pages. I will not take pull requests for the runtests file as I often modify it and only push changes when releasing.

After you submit your tests cases, a 2D bar code scanner is used to verify the barcodes are readable and contain the correct data. If all goes ok, your test cases (and my warm thanks!) will be part of the next release.