Summary

Class:ICSharpCode.SharpZipLib.Zip.Compression.InflaterDynHeader
Assembly:ICSharpCode.SharpZipLib
File(s):C:\Users\Neil\Documents\Visual Studio 2015\Projects\icsharpcode\SZL_master\ICSharpCode.SharpZipLib\Zip\Compression\InflaterDynHeader.cs
Covered lines:63
Uncovered lines:10
Coverable lines:73
Total lines:170
Line coverage:86.3%
Branch coverage:54.2%

Metrics

MethodCyclomatic ComplexitySequence CoverageBranch Coverage
Decode(...)2184.1355.56
BuildLitLenTree()1100100
BuildDistTree()1100100
.cctor()1100100

File(s)

C:\Users\Neil\Documents\Visual Studio 2015\Projects\icsharpcode\SZL_master\ICSharpCode.SharpZipLib\Zip\Compression\InflaterDynHeader.cs

#LineLine coverage
 1using System;
 2using ICSharpCode.SharpZipLib.Zip.Compression.Streams;
 3
 4namespace ICSharpCode.SharpZipLib.Zip.Compression
 5{
 6  class InflaterDynHeader
 7  {
 8    #region Constants
 9    const int LNUM = 0;
 10    const int DNUM = 1;
 11    const int BLNUM = 2;
 12    const int BLLENS = 3;
 13    const int LENS = 4;
 14    const int REPS = 5;
 15
 116    static readonly int[] repMin = { 3, 3, 11 };
 117    static readonly int[] repBits = { 2, 3, 7 };
 18
 119    static readonly int[] BL_ORDER =
 120    { 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15 };
 21    #endregion
 22
 23    public bool Decode(StreamManipulator input)
 24    {
 25      decode_loop:
 26      for (;;) {
 1027         switch (mode) {
 28          case LNUM:
 129            lnum = input.PeekBits(5);
 130             if (lnum < 0) {
 031              return false;
 32            }
 133            lnum += 257;
 134            input.DropBits(5);
 35            //        System.err.println("LNUM: "+lnum);
 136            mode = DNUM;
 37            goto case DNUM; // fall through
 38          case DNUM:
 139            dnum = input.PeekBits(5);
 140             if (dnum < 0) {
 041              return false;
 42            }
 143            dnum++;
 144            input.DropBits(5);
 45            //        System.err.println("DNUM: "+dnum);
 146            num = lnum + dnum;
 147            litdistLens = new byte[num];
 148            mode = BLNUM;
 49            goto case BLNUM; // fall through
 50          case BLNUM:
 151            blnum = input.PeekBits(4);
 152             if (blnum < 0) {
 053              return false;
 54            }
 155            blnum += 4;
 156            input.DropBits(4);
 157            blLens = new byte[19];
 158            ptr = 0;
 59            //        System.err.println("BLNUM: "+blnum);
 160            mode = BLLENS;
 161            goto case BLLENS; // fall through
 62          case BLLENS:
 1963             while (ptr < blnum) {
 1864              int len = input.PeekBits(3);
 1865               if (len < 0) {
 066                return false;
 67              }
 1868              input.DropBits(3);
 69              //      System.err.println("blLens["+BL_ORDER[ptr]+"]: "+len);
 1870              blLens[BL_ORDER[ptr]] = (byte)len;
 1871              ptr++;
 72            }
 173            blTree = new InflaterHuffmanTree(blLens);
 174            blLens = null;
 175            ptr = 0;
 176            mode = LENS;
 177            goto case LENS; // fall through
 78          case LENS: {
 79              int symbol;
 4580               while (((symbol = blTree.GetSymbol(input)) & ~15) == 0) {
 81                /* Normal case: symbol in [0..15] */
 82
 83                //        System.err.println("litdistLens["+ptr+"]: "+symbol);
 3684                litdistLens[ptr++] = lastLen = (byte)symbol;
 85
 3686                 if (ptr == num) {
 87                  /* Finished */
 188                  return true;
 89                }
 90              }
 91
 92              /* need more input ? */
 993               if (symbol < 0) {
 094                return false;
 95              }
 96
 97              /* otherwise repeat code */
 998               if (symbol >= 17) {
 99                /* repeat zero */
 100                //        System.err.println("repeating zero");
 9101                lastLen = 0;
 9102              } else {
 0103                 if (ptr == 0) {
 0104                  throw new SharpZipBaseException();
 105                }
 106              }
 9107              repSymbol = symbol - 16;
 108            }
 9109            mode = REPS;
 110            goto case REPS; // fall through
 111          case REPS: {
 9112              int bits = repBits[repSymbol];
 9113              int count = input.PeekBits(bits);
 9114               if (count < 0) {
 0115                return false;
 116              }
 9117              input.DropBits(bits);
 9118              count += repMin[repSymbol];
 119              //          System.err.println("litdistLens repeated: "+count);
 120
 9121               if (ptr + count > num) {
 0122                throw new SharpZipBaseException();
 123              }
 239124               while (count-- > 0) {
 230125                litdistLens[ptr++] = lastLen;
 126              }
 127
 9128               if (ptr == num) {
 129                /* Finished */
 0130                return true;
 131              }
 132            }
 9133            mode = LENS;
 9134            goto decode_loop;
 135        }
 136      }
 137    }
 138
 139    public InflaterHuffmanTree BuildLitLenTree()
 140    {
 1141      byte[] litlenLens = new byte[lnum];
 1142      Array.Copy(litdistLens, 0, litlenLens, 0, lnum);
 1143      return new InflaterHuffmanTree(litlenLens);
 144    }
 145
 146    public InflaterHuffmanTree BuildDistTree()
 147    {
 1148      byte[] distLens = new byte[dnum];
 1149      Array.Copy(litdistLens, lnum, distLens, 0, dnum);
 1150      return new InflaterHuffmanTree(distLens);
 151    }
 152
 153    #region Instance Fields
 154    byte[] blLens;
 155    byte[] litdistLens;
 156
 157    InflaterHuffmanTree blTree;
 158
 159    /// <summary>
 160    /// The current decode mode
 161    /// </summary>
 162    int mode;
 163    int lnum, dnum, blnum, num;
 164    int repSymbol;
 165    byte lastLen;
 166    int ptr;
 167    #endregion
 168
 169  }
 170}