示例#1
0
 // Return debug String.
 public override System.String ToString()
 {
     System.Text.StringBuilder result = new System.Text.StringBuilder(200);
     result.Append("<<\n");
     result.Append(" mode: ");
     result.Append(mode);
     result.Append("\n m_EcLevelInternal: ");
     result.Append(m_EcLevelInternal);
     result.Append("\n version: ");
     result.Append(version);
     result.Append("\n matrixWidth: ");
     result.Append(matrixWidth);
     result.Append("\n maskPattern: ");
     result.Append(maskPattern);
     result.Append("\n numTotalBytes: ");
     result.Append(numTotalBytes);
     result.Append("\n numDataBytes: ");
     result.Append(numDataBytes);
     result.Append("\n numECBytes: ");
     result.Append(numECBytes);
     result.Append("\n numRSBlocks: ");
     result.Append(numRSBlocks);
     if (matrix == null)
     {
         result.Append("\n matrix: null\n");
     }
     else
     {
         result.Append("\n matrix:\n");
         result.Append(matrix.ToString());
     }
     result.Append(">>\n");
     return(result.ToString());
 }
示例#2
0
        public void testEmbedDataBits()
        {
            // Cells other than basic patterns should be filled with zero.
            String expected =
                " 1 1 1 1 1 1 1 0 0 0 0 0 0 0 1 1 1 1 1 1 1\n" +
                " 1 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 0 1\n" +
                " 1 0 1 1 1 0 1 0 0 0 0 0 0 0 1 0 1 1 1 0 1\n" +
                " 1 0 1 1 1 0 1 0 0 0 0 0 0 0 1 0 1 1 1 0 1\n" +
                " 1 0 1 1 1 0 1 0 0 0 0 0 0 0 1 0 1 1 1 0 1\n" +
                " 1 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 0 1\n" +
                " 1 1 1 1 1 1 1 0 1 0 1 0 1 0 1 1 1 1 1 1 1\n" +
                " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n" +
                " 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n" +
                " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n" +
                " 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n" +
                " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n" +
                " 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n" +
                " 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0\n" +
                " 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n" +
                " 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n" +
                " 1 0 1 1 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n" +
                " 1 0 1 1 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n" +
                " 1 0 1 1 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n" +
                " 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n" +
                " 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n";
            BitArray   bits   = new BitArray();
            ByteMatrix matrix = new ByteMatrix(21, 21);

            MatrixUtil.clearMatrix(matrix);
            MatrixUtil.embedBasicPatterns(Version.getVersionForNumber(1), matrix);
            MatrixUtil.embedDataBits(bits, -1, matrix);
            Assert.AreEqual(expected, matrix.ToString());
        }
示例#3
0
        public override string ToString()
        {
            StringBuilder result = new StringBuilder(200);

            result.Append("<<\n");
            result.Append(" mode: ");
            result.Append(mode);
            result.Append("\n ecLevel: ");
            result.Append(ecLevel);
            result.Append("\n version: ");
            result.Append(version);
            result.Append("\n maskPattern: ");
            result.Append(maskPattern);
            if (matrix == null)
            {
                result.Append("\n matrix: null\n");
            }
            else
            {
                result.Append("\n matrix:\n");
                result.Append(matrix.ToString());
            }
            result.Append(">>\n");
            return(result.ToString());
        }
示例#4
0
        public void testEmbedVersionInfo()
        {
            // Version info bits = 000111 110010 010100
            String expected =
                "                     0 0 1                \n" +
                "                     0 1 0                \n" +
                "                     0 1 0                \n" +
                "                     0 1 1                \n" +
                "                     1 1 1                \n" +
                "                     0 0 0                \n" +
                "                                          \n" +
                "                                          \n" +
                "                                          \n" +
                "                                          \n" +
                " 0 0 0 0 1 0                              \n" +
                " 0 1 1 1 1 0                              \n" +
                " 1 0 0 1 1 0                              \n" +
                "                                          \n" +
                "                                          \n" +
                "                                          \n" +
                "                                          \n" +
                "                                          \n" +
                "                                          \n" +
                "                                          \n" +
                "                                          \n";
            // Actually, version 7 QR Code has 45x45 matrix but we use 21x21 here
            // since 45x45 matrix is too big to depict.
            ByteMatrix matrix = new ByteMatrix(21, 21);

            MatrixUtil.clearMatrix(matrix);
            MatrixUtil.maybeEmbedVersionInfo(Version.getVersionForNumber(7), matrix);
            Assert.AreEqual(expected, matrix.ToString());
        }
示例#5
0
        public void testEmbedTypeInfo()
        {
            // Type info bits = 100000011001110.
            String expected =
                "                 0                        \n" +
                "                 1                        \n" +
                "                 1                        \n" +
                "                 1                        \n" +
                "                 0                        \n" +
                "                 0                        \n" +
                "                                          \n" +
                "                 1                        \n" +
                " 1 0 0 0 0 0   0 1         1 1 0 0 1 1 1 0\n" +
                "                                          \n" +
                "                                          \n" +
                "                                          \n" +
                "                                          \n" +
                "                                          \n" +
                "                 0                        \n" +
                "                 0                        \n" +
                "                 0                        \n" +
                "                 0                        \n" +
                "                 0                        \n" +
                "                 0                        \n" +
                "                 1                        \n";
            ByteMatrix matrix = new ByteMatrix(21, 21);

            MatrixUtil.clearMatrix(matrix);
            MatrixUtil.embedTypeInfo(ErrorCorrectionLevel.M, 5, matrix);
            Assert.AreEqual(expected, matrix.ToString());
        }
示例#6
0
        public void testToString()
        {
            ByteMatrix array = new ByteMatrix(3, 3);

            array.set(0, 0, 0);
            array.set(1, 0, 1);
            array.set(2, 0, 0);
            array.set(0, 1, 1);
            array.set(1, 1, 0);
            array.set(2, 1, 1);
            array.set(0, 2, -1);
            array.set(1, 2, -1);
            array.set(2, 2, -1);
            String expected = " 0 1 0\n" + " 1 0 1\n" + "      \n";

            Assert.AreEqual(expected, array.ToString());
        }
示例#7
0
        public void testBuildMatrix()
        {
            // From http://www.swetake.com/qr/qr7.html
            String expected =
                " 1 1 1 1 1 1 1 0 0 1 1 0 0 0 1 1 1 1 1 1 1\n" +
                " 1 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 0 1\n" +
                " 1 0 1 1 1 0 1 0 0 0 0 1 0 0 1 0 1 1 1 0 1\n" +
                " 1 0 1 1 1 0 1 0 0 1 1 0 0 0 1 0 1 1 1 0 1\n" +
                " 1 0 1 1 1 0 1 0 1 1 0 0 1 0 1 0 1 1 1 0 1\n" +
                " 1 0 0 0 0 0 1 0 0 0 1 1 1 0 1 0 0 0 0 0 1\n" +
                " 1 1 1 1 1 1 1 0 1 0 1 0 1 0 1 1 1 1 1 1 1\n" +
                " 0 0 0 0 0 0 0 0 1 1 0 1 1 0 0 0 0 0 0 0 0\n" +
                " 0 0 1 1 0 0 1 1 1 0 0 1 1 1 1 0 1 0 0 0 0\n" +
                " 1 0 1 0 1 0 0 0 0 0 1 1 1 0 0 1 0 1 1 1 0\n" +
                " 1 1 1 1 0 1 1 0 1 0 1 1 1 0 0 1 1 1 0 1 0\n" +
                " 1 0 1 0 1 1 0 1 1 1 0 0 1 1 1 0 0 1 0 1 0\n" +
                " 0 0 1 0 0 1 1 1 0 0 0 0 0 0 1 0 1 1 1 1 1\n" +
                " 0 0 0 0 0 0 0 0 1 1 0 1 0 0 0 0 0 1 0 1 1\n" +
                " 1 1 1 1 1 1 1 0 1 1 1 1 0 0 0 0 1 0 1 1 0\n" +
                " 1 0 0 0 0 0 1 0 0 0 0 1 0 1 1 1 0 0 0 0 0\n" +
                " 1 0 1 1 1 0 1 0 0 1 0 0 1 1 0 0 1 0 0 1 1\n" +
                " 1 0 1 1 1 0 1 0 1 1 0 1 0 0 0 0 0 1 1 1 0\n" +
                " 1 0 1 1 1 0 1 0 1 1 1 1 0 0 0 0 1 1 1 0 0\n" +
                " 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 0 1 0 0\n" +
                " 1 1 1 1 1 1 1 0 0 0 1 1 1 1 1 0 1 0 0 1 0\n";

            int[]    bytes = { 32,  65, 205,  69,  41, 220,  46, 128, 236,
                               42,    159,  74, 221, 244, 169, 239, 150, 138,
                               70,    237,  85, 224,  96,  74, 219, 61 };
            BitArray bits = new BitArray();

            foreach (char c in bytes)
            {
                bits.appendBits(c, 8);
            }
            ByteMatrix matrix = new ByteMatrix(21, 21);

            MatrixUtil.buildMatrix(bits,
                                   ErrorCorrectionLevel.H,
                                   Version.getVersionForNumber(1), // Version 1
                                   3,                              // Mask pattern 3
                                   matrix);
            Assert.AreEqual(expected, matrix.ToString());
        }
示例#8
0
 public void testEmbedBasicPatterns()
 {
     {
         // Version 1.
         String expected =
             " 1 1 1 1 1 1 1 0           0 1 1 1 1 1 1 1\n" +
             " 1 0 0 0 0 0 1 0           0 1 0 0 0 0 0 1\n" +
             " 1 0 1 1 1 0 1 0           0 1 0 1 1 1 0 1\n" +
             " 1 0 1 1 1 0 1 0           0 1 0 1 1 1 0 1\n" +
             " 1 0 1 1 1 0 1 0           0 1 0 1 1 1 0 1\n" +
             " 1 0 0 0 0 0 1 0           0 1 0 0 0 0 0 1\n" +
             " 1 1 1 1 1 1 1 0 1 0 1 0 1 0 1 1 1 1 1 1 1\n" +
             " 0 0 0 0 0 0 0 0           0 0 0 0 0 0 0 0\n" +
             "             1                            \n" +
             "             0                            \n" +
             "             1                            \n" +
             "             0                            \n" +
             "             1                            \n" +
             " 0 0 0 0 0 0 0 0 1                        \n" +
             " 1 1 1 1 1 1 1 0                          \n" +
             " 1 0 0 0 0 0 1 0                          \n" +
             " 1 0 1 1 1 0 1 0                          \n" +
             " 1 0 1 1 1 0 1 0                          \n" +
             " 1 0 1 1 1 0 1 0                          \n" +
             " 1 0 0 0 0 0 1 0                          \n" +
             " 1 1 1 1 1 1 1 0                          \n";
         ByteMatrix matrix = new ByteMatrix(21, 21);
         MatrixUtil.clearMatrix(matrix);
         MatrixUtil.embedBasicPatterns(Version.getVersionForNumber(1), matrix);
         Assert.AreEqual(expected, matrix.ToString());
     }
     {
         // Version 2.  Position adjustment pattern should apppear at right
         // bottom corner.
         String expected =
             " 1 1 1 1 1 1 1 0                   0 1 1 1 1 1 1 1\n" +
             " 1 0 0 0 0 0 1 0                   0 1 0 0 0 0 0 1\n" +
             " 1 0 1 1 1 0 1 0                   0 1 0 1 1 1 0 1\n" +
             " 1 0 1 1 1 0 1 0                   0 1 0 1 1 1 0 1\n" +
             " 1 0 1 1 1 0 1 0                   0 1 0 1 1 1 0 1\n" +
             " 1 0 0 0 0 0 1 0                   0 1 0 0 0 0 0 1\n" +
             " 1 1 1 1 1 1 1 0 1 0 1 0 1 0 1 0 1 0 1 1 1 1 1 1 1\n" +
             " 0 0 0 0 0 0 0 0                   0 0 0 0 0 0 0 0\n" +
             "             1                                    \n" +
             "             0                                    \n" +
             "             1                                    \n" +
             "             0                                    \n" +
             "             1                                    \n" +
             "             0                                    \n" +
             "             1                                    \n" +
             "             0                                    \n" +
             "             1                   1 1 1 1 1        \n" +
             " 0 0 0 0 0 0 0 0 1               1 0 0 0 1        \n" +
             " 1 1 1 1 1 1 1 0                 1 0 1 0 1        \n" +
             " 1 0 0 0 0 0 1 0                 1 0 0 0 1        \n" +
             " 1 0 1 1 1 0 1 0                 1 1 1 1 1        \n" +
             " 1 0 1 1 1 0 1 0                                  \n" +
             " 1 0 1 1 1 0 1 0                                  \n" +
             " 1 0 0 0 0 0 1 0                                  \n" +
             " 1 1 1 1 1 1 1 0                                  \n";
         ByteMatrix matrix = new ByteMatrix(25, 25);
         MatrixUtil.clearMatrix(matrix);
         MatrixUtil.embedBasicPatterns(Version.getVersionForNumber(2), matrix);
         Assert.AreEqual(expected, matrix.ToString());
     }
 }