Related to Issue 205, but not the direct issue: read both copies of the format info...
[zxing.git] / core / test / src / com / google / zxing / qrcode / decoder / FormatInformationTestCase.java
index cd810cb..6bf1ef7 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2007 Google Inc.
+ * Copyright 2007 ZXing authors
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -19,30 +19,50 @@ package com.google.zxing.qrcode.decoder;
 import junit.framework.TestCase;
 
 /**
- * @author srowen@google.com (Sean Owen)
+ * @author Sean Owen
  */
 public final class FormatInformationTestCase extends TestCase {
 
+  private static final int MASKED_TEST_FORMAT_INFO = 0x2BED;
+  private static final int UNMASKED_TEST_FORMAT_INFO = MASKED_TEST_FORMAT_INFO ^ 0x5412;
+
   public void testBitsDiffering() {
     assertEquals(0, FormatInformation.numBitsDiffering(1, 1));
     assertEquals(1, FormatInformation.numBitsDiffering(0, 2));
     assertEquals(2, FormatInformation.numBitsDiffering(1, 2));
-    assertEquals(32, FormatInformation.numBitsDiffering(-1,0));       
+    assertEquals(32, FormatInformation.numBitsDiffering(-1, 0));
   }
 
   public void testDecode() {
     // Normal case
-    FormatInformation expected = FormatInformation.decodeFormatInformation(0x2BED ^ 0x5412);
+    FormatInformation expected =
+        FormatInformation.decodeFormatInformation(MASKED_TEST_FORMAT_INFO, MASKED_TEST_FORMAT_INFO);
     assertEquals((byte) 0x07, expected.getDataMask());
-    assertEquals(ErrorCorrectionLevel.Q, expected.getErrorCorrectionLevel());
+    assertSame(ErrorCorrectionLevel.Q, expected.getErrorCorrectionLevel());
     // where the code forgot the mask!
-    assertEquals(expected, FormatInformation.decodeFormatInformation(0x2BED));
+    assertEquals(expected,
+                 FormatInformation.decodeFormatInformation(UNMASKED_TEST_FORMAT_INFO, MASKED_TEST_FORMAT_INFO));
+  }
 
+  public void testDecodeWithBitDifference() {
+    FormatInformation expected =
+        FormatInformation.decodeFormatInformation(MASKED_TEST_FORMAT_INFO, MASKED_TEST_FORMAT_INFO);
     // 1,2,3,4 bits difference
-    assertEquals(expected, FormatInformation.decodeFormatInformation(0x2BEF ^ 0x5412));
-    assertEquals(expected, FormatInformation.decodeFormatInformation(0x2BEE ^ 0x5412));
-    assertEquals(expected, FormatInformation.decodeFormatInformation(0x2BEA ^ 0x5412));
-    assertNull(FormatInformation.decodeFormatInformation(0x2BE2 ^ 0x5412));
+    assertEquals(expected, FormatInformation.decodeFormatInformation(
+        MASKED_TEST_FORMAT_INFO ^ 0x01, MASKED_TEST_FORMAT_INFO ^ 0x01));
+    assertEquals(expected, FormatInformation.decodeFormatInformation(
+        MASKED_TEST_FORMAT_INFO ^ 0x03, MASKED_TEST_FORMAT_INFO ^ 0x03));
+    assertEquals(expected, FormatInformation.decodeFormatInformation(
+        MASKED_TEST_FORMAT_INFO ^ 0x07, MASKED_TEST_FORMAT_INFO ^ 0x07));
+    assertNull(FormatInformation.decodeFormatInformation(
+        MASKED_TEST_FORMAT_INFO ^ 0x0F, MASKED_TEST_FORMAT_INFO ^ 0x0F));
+  }
+
+  public void testDecodeWithMisread() {
+    FormatInformation expected =
+        FormatInformation.decodeFormatInformation(MASKED_TEST_FORMAT_INFO, MASKED_TEST_FORMAT_INFO);
+    assertEquals(expected, FormatInformation.decodeFormatInformation(
+        MASKED_TEST_FORMAT_INFO ^ 0x03, MASKED_TEST_FORMAT_INFO ^ 0x0F));
   }
 
 }
\ No newline at end of file