Exemplo n.º 1
0
 public void testClearMatrix()
 {
    ByteMatrix matrix = new ByteMatrix(2, 2);
    MatrixUtil.clearMatrix(matrix);
    Assert.AreEqual(2, matrix[0, 0]);
    Assert.AreEqual(2, matrix[1, 0]);
    Assert.AreEqual(2, matrix[0, 1]);
    Assert.AreEqual(2, matrix[1, 1]);
 }
Exemplo n.º 2
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, 2);
    array.set(1, 2, 2);
    array.set(2, 2, 2);
    String expected = " 0 1 0\n" + " 1 0 1\n" + "      \n";
    Assert.AreEqual(expected, array.ToString());
 }
Exemplo n.º 3
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());
    }
 }
Exemplo n.º 4
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());
 }
Exemplo n.º 5
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());
 }
Exemplo n.º 6
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());
 }
Exemplo n.º 7
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());
 }