示例#1
0
        public void Encode_Barcoder_ShouldEncodePdf417CodeCorrectly()
        {
            // Arrange
            var content          = "Barcoder";
            var expectedDataBits = ImageStringToBools(@"
                ++++++++.+.+.+...+++.+.+.+++......+++.+.+...+++....+++.+..++...++++.++++.+.++..+++++.+++++.+.+.+++++..+++++++.+...+.+..+
                ++++++++.+.+.+...+++.+.+.+++......+++.+.+...+++....+++.+..++...++++.++++.+.++..+++++.+++++.+.+.+++++..+++++++.+...+.+..+
                ++++++++.+.+.+...++++++.+.+...+++.++++.+..+....+...+++.+..+++..++...+..++.+++++..+...++++++.+.+.+++...+++++++.+...+.+..+
                ++++++++.+.+.+...++++++.+.+...+++.++++.+..+....+...+++.+..+++..++...+..++.+++++..+...++++++.+.+.+++...+++++++.+...+.+..+
                ++++++++.+.+.+...+.+.+..++++......++...+++++..+..+.+...++..+....+++.+....++..++.++++.+++.+.+...++++++.+++++++.+...+.+..+
                ++++++++.+.+.+...+.+.+..++++......++...+++++..+..+.+...++..+....+++.+....++..++.++++.+++.+.+...++++++.+++++++.+...+.+..+
                ++++++++.+.+.+...++.+.++++.+++++..+.++....+++...++.+++.+..+..+++....++....++....+..+.++.+.++++..+++++.+++++++.+...+.+..+
                ++++++++.+.+.+...++.+.++++.+++++..+.++....+++...++.+++.+..+..+++....++....++....+..+.++.+.++++..+++++.+++++++.+...+.+..+
                ++++++++.+.+.+...+++.+.+++....++..+++..+.++..+.....+++.+...++.....+.+.++++++..+.++...+++.+.+++..++....+++++++.+...+.+..+
                ++++++++.+.+.+...+++.+.+++....++..+++..+.++..+.....+++.+...++.....+.+.++++++..+.++...+++.+.+++..++....+++++++.+...+.+..+
            ");

            // Act
            IBarcode pdf417 = Pdf417Encoder.Encode(content, 2);

            // Assert
            pdf417.Should().NotBeNull();
            expectedDataBits.Length.Should().Be(pdf417.Bounds.X * pdf417.Bounds.Y);
            for (int i = 0; i < expectedDataBits.Length; i++)
            {
                int x = i % pdf417.Bounds.X;
                int y = i / pdf417.Bounds.X;
                pdf417.At(x, y).Should().Be(expectedDataBits[i], $"of expected bit on index {i}");
            }
        }
示例#2
0
        public void Encode_Barcode_ShouldEncodeRm4ScCorrectly()
        {
            // Arrange
            var content          = "123ABC789XYZ"; // checksum character == 'K'
            var expectedDataBits = ImageStringToBools(@"
                +.....+.+.....+.+.....+.+...+...+...+...+...+.+.....+...+...+...+...+...+.+.+.....+.+.....+.+.....+.....+.+
                +.....+.+.....+.+.....+.+...+...+...+...+...+.+.....+...+...+...+...+...+.+.+.....+.+.....+.+.....+.....+.+
                +.....+.+.....+.+.....+.+...+...+...+...+...+.+.....+...+...+...+...+...+.+.+.....+.+.....+.+.....+.....+.+
                +.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+
                +.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+
                ....+...+...+.+...+.....+.+...+...+.+.........+.+...+...+...+.+...+.....+.+.....+.+...+...+.+.......+.+...+
                ....+...+...+.+...+.....+.+...+...+.+.........+.+...+...+...+.+...+.....+.+.....+.+...+...+.+.......+.+...+
                ....+...+...+.+...+.....+.+...+...+.+.........+.+...+...+...+.+...+.....+.+.....+.+...+...+.+.......+.+...+
            ");

            // Act
            IBarcode royalMailCode = RoyalMailFourStateCodeEncoder.Encode(content);

            // Assert
            royalMailCode.Should().NotBeNull();
            royalMailCode.Metadata.CodeKind.Should().Be(BarcodeType.RM4SC);
            expectedDataBits.Length.Should().Be(royalMailCode.Bounds.X * royalMailCode.Bounds.Y);
            for (int i = 0; i < expectedDataBits.Length; i++)
            {
                int x = i % royalMailCode.Bounds.X;
                int y = i / royalMailCode.Bounds.X;
                royalMailCode.At(x, y).Should().Be(expectedDataBits[i], $"of expected bit on index {i}");
            }
        }
示例#3
0
        public void Encode_Barcode_ShouldEncodeKixCorrectly()
        {
            // Arrange
            var content          = "123ABC789XYZ"; // checksum character == 'K'
            var expectedDataBits = ImageStringToBools(@"
                ....+.+.....+.+.....+.+...+...+...+...+...+.+.....+...+...+...+...+...+.+.+.....+.+.....+.+....
                ....+.+.....+.+.....+.+...+...+...+...+...+.+.....+...+...+...+...+...+.+.+.....+.+.....+.+....
                ....+.+.....+.+.....+.+...+...+...+...+...+.+.....+...+...+...+...+...+.+.+.....+.+.....+.+....
                +.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+
                +.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+
                ..+...+...+.+...+.....+.+...+...+.+.........+.+...+...+...+.+...+.....+.+.....+.+...+...+.+....
                ..+...+...+.+...+.....+.+...+...+.+.........+.+...+...+...+.+...+.....+.+.....+.+...+...+.+....
                ..+...+...+.+...+.....+.+...+...+.+.........+.+...+...+...+.+...+.....+.+.....+.+...+...+.+....
            ");

            // Act
            IBarcode kixCode = KixEncoder.Encode(content);

            // Assert
            kixCode.Should().NotBeNull();
            kixCode.Metadata.CodeKind.Should().Be(BarcodeType.KixCode);
            expectedDataBits.Length.Should().Be(kixCode.Bounds.X * kixCode.Bounds.Y);
            for (int i = 0; i < expectedDataBits.Length; i++)
            {
                int x = i % kixCode.Bounds.X;
                int y = i / kixCode.Bounds.X;
                kixCode.At(x, y).Should().Be(expectedDataBits[i], $"of expected bit on index {i}");
            }
        }
示例#4
0
        public void Encode_ValidUnicodeContent_ShouldEncodeQrCodeCorrectly()
        {
            // Arrange
            var content          = "hello world";
            var expectedDataBits = ImageStringToBools(@"
                +++++++.+.+.+...+.+++++++
                +.....+.++...+++..+.....+
                +.+++.+.+.+.++.++.+.+++.+
                +.+++.+....++.++..+.+++.+
                +.+++.+..+...++.+.+.+++.+
                +.....+.+..+..+++.+.....+
                +++++++.+.+.+.+.+.+++++++
                ........++..+..+.........
                ..+++.+.+++.+.++++++..+++
                +++..+..+...++.+...+..+..
                +...+.++++....++.+..++.++
                ++.+.+.++...+...+.+....++
                ..+..+++.+.+++++.++++++++
                +.+++...+..++..++..+..+..
                +.....+..+.+.....+++++.++
                +.+++.....+...+.+.+++...+
                +.+..+++...++.+.+++++++..
                ........+....++.+...+.+..
                +++++++......++++.+.+.+++
                +.....+....+...++...++.+.
                +.+++.+.+.+...+++++++++..
                +.+++.+.++...++...+.++..+
                +.+++.+.++.+++++..++.+..+
                +.....+..+++..++.+.++...+
                +++++++....+..+.+..+..+++
            ");

            // Act
            IBarcode qr = QrEncoder.Encode(content, ErrorCorrectionLevel.H, Encoding.Unicode);

            // Assert
            qr.Should().NotBeNull();
            expectedDataBits.Length.Should().Be(qr.Bounds.X * qr.Bounds.Y);
            for (int i = 0; i < expectedDataBits.Length; i++)
            {
                int x = i % qr.Bounds.X;
                int y = i / qr.Bounds.X;
                qr.At(x, y).Should().Be(expectedDataBits[i], $"of expected bit on index {i}");
            }
        }
示例#5
0
        public void Encode(string txt, string testResult)
        {
            IBarcode code = Codabar.Encode(txt);

            code.Should().NotBeNull();
            code.Bounds.X.Should().Be(testResult.Length);
            code.Bounds.Y.Should().Be(1);
            code.Metadata.CodeKind.Should().Be(BarcodeType.Codabar);
            code.Metadata.Dimensions.Should().Be(1);
            string encoded = string.Empty;
            int    i       = 0;

            foreach (var r in testResult)
            {
                encoded += code.At(i++, 0) ? "1" : "0";
            }
            encoded.Should().Be(testResult);
        }