private static void testWriter(String data, String charset, int eccPercent, bool compact, int layers) { // 1. Perform an encode-decode round-trip because it can be lossy. // 2. Aztec Decoder currently always decodes the data with a LATIN-1 charset: var byteData = Encoding.GetEncoding(charset).GetBytes(data); var expectedData = LATIN_1.GetString(byteData, 0, byteData.Length); var hints = new Dictionary <EncodeHintType, Object>() ; hints[EncodeHintType.CHARACTER_SET] = charset; hints[EncodeHintType.ERROR_CORRECTION] = eccPercent; var writer = new AztecWriter(); var matrix = writer.encode(data, BarcodeFormat.AZTEC, 0, 0, hints); var aztec = Internal.Encoder.encode(Encoding.GetEncoding(charset).GetBytes(data), eccPercent, Internal.Encoder.DEFAULT_AZTEC_LAYERS); Assert.AreEqual(compact, aztec.isCompact, "Unexpected symbol format (compact)"); Assert.AreEqual(layers, aztec.Layers, "Unexpected nr. of layers"); var matrix2 = aztec.Matrix; Assert.AreEqual(matrix, matrix2); var r = new AztecDetectorResult(matrix, NO_POINTS, aztec.isCompact, aztec.CodeWords, aztec.Layers); var res = new Internal.Decoder().decode(r); Assert.AreEqual(expectedData, res.Text); // Check error correction by introducing up to eccPercent/2 errors int ecWords = aztec.CodeWords * eccPercent / 100 / 2; var random = getPseudoRandom(); for (int i = 0; i < ecWords; i++) { // don't touch the core int x = random.Next(1) > 0 ? random.Next(aztec.Layers * 2) : matrix.Width - 1 - random.Next(aztec.Layers * 2); int y = random.Next(1) > 0 ? random.Next(aztec.Layers * 2) : matrix.Height - 1 - random.Next(aztec.Layers * 2); matrix.flip(x, y); } r = new AztecDetectorResult(matrix, NO_POINTS, aztec.isCompact, aztec.CodeWords, aztec.Layers); res = new Internal.Decoder().decode(r); Assert.AreEqual(expectedData, res.Text); }
private static void testEncodeDecode(String data, bool compact, int layers) { AztecCode aztec = Internal.Encoder.encode(LATIN_1.GetBytes(data), 25); Assert.AreEqual(compact, aztec.isCompact, "Unexpected symbol format (compact)"); Assert.AreEqual(layers, aztec.Layers, "Unexpected nr. of layers"); BitMatrix matrix = aztec.Matrix; AztecDetectorResult r = new AztecDetectorResult(matrix, NO_POINTS, aztec.isCompact, aztec.CodeWords, aztec.Layers); DecoderResult res = new Internal.Decoder().decode(r); Assert.AreEqual(data, res.Text); // Check error correction by introducing a few minor errors Random random = getPseudoRandom(); matrix.flip(random.Next(matrix.Width), random.Next(2)); matrix.flip(random.Next(matrix.Width), matrix.Height - 2 + random.Next(2)); matrix.flip(random.Next(2), random.Next(matrix.Height)); matrix.flip(matrix.Width - 2 + random.Next(2), random.Next(matrix.Height)); r = new AztecDetectorResult(matrix, NO_POINTS, aztec.isCompact, aztec.CodeWords, aztec.Layers); res = new Internal.Decoder().decode(r); Assert.AreEqual(data, res.Text); }
private static void testWriter(String data, String charset, int eccPercent, bool compact, int layers) { // 1. Perform an encode-decode round-trip because it can be lossy. // 2. Aztec Decoder currently always decodes the data with a LATIN-1 charset: var byteData = Encoding.GetEncoding(charset).GetBytes(data); var expectedData = LATIN_1.GetString(byteData, 0, byteData.Length); var hints = new Dictionary<EncodeHintType, Object>() ; hints[EncodeHintType.CHARACTER_SET] = charset; hints[EncodeHintType.ERROR_CORRECTION] = eccPercent; var writer = new AztecWriter(); var matrix = writer.encode(data, BarcodeFormat.AZTEC, 0, 0, hints); var aztec = Internal.Encoder.encode(Encoding.GetEncoding(charset).GetBytes(data), eccPercent, Internal.Encoder.DEFAULT_AZTEC_LAYERS); Assert.AreEqual(compact, aztec.isCompact, "Unexpected symbol format (compact)"); Assert.AreEqual(layers, aztec.Layers, "Unexpected nr. of layers"); var matrix2 = aztec.Matrix; Assert.AreEqual(matrix, matrix2); var r = new AztecDetectorResult(matrix, NO_POINTS, aztec.isCompact, aztec.CodeWords, aztec.Layers); var res = new Internal.Decoder().decode(r); Assert.AreEqual(expectedData, res.Text); // Check error correction by introducing up to eccPercent errors int ecWords = aztec.CodeWords*eccPercent/100; var random = getPseudoRandom(); for (int i = 0; i < ecWords; i++) { // don't touch the core int x = random.Next(1) > 0 ? random.Next(aztec.Layers*2) : matrix.Width - 1 - random.Next(aztec.Layers*2); int y = random.Next(1) > 0 ? random.Next(aztec.Layers*2) : matrix.Height - 1 - random.Next(aztec.Layers*2); matrix.flip(x, y); } r = new AztecDetectorResult(matrix, NO_POINTS, aztec.isCompact, aztec.CodeWords, aztec.Layers); res = new Internal.Decoder().decode(r); Assert.AreEqual(expectedData, res.Text); }
private static void testEncodeDecode(String data, bool compact, int layers) { AztecCode aztec = Internal.Encoder.encode(LATIN_1.GetBytes(data), 25, Internal.Encoder.DEFAULT_AZTEC_LAYERS); Assert.AreEqual(compact, aztec.isCompact, "Unexpected symbol format (compact)"); Assert.AreEqual(layers, aztec.Layers, "Unexpected nr. of layers"); BitMatrix matrix = aztec.Matrix; AztecDetectorResult r = new AztecDetectorResult(matrix, NO_POINTS, aztec.isCompact, aztec.CodeWords, aztec.Layers); DecoderResult res = new Internal.Decoder().decode(r); Assert.AreEqual(data, res.Text); // Check error correction by introducing a few minor errors Random random = getPseudoRandom(); matrix.flip(random.Next(matrix.Width), random.Next(2)); matrix.flip(random.Next(matrix.Width), matrix.Height - 2 + random.Next(2)); matrix.flip(random.Next(2), random.Next(matrix.Height)); matrix.flip(matrix.Width - 2 + random.Next(2), random.Next(matrix.Height)); r = new AztecDetectorResult(matrix, NO_POINTS, aztec.isCompact, aztec.CodeWords, aztec.Layers); res = new Internal.Decoder().decode(r); Assert.AreEqual(data, res.Text); }