public void Render_Barcode1D() { // Arrange IBarcodeIntCS barcode = Code128.Encode("Wikipedia"); var renderer = new SvgRenderer(); // Act string svg; using (var stream = new MemoryStream()) using (var reader = new StreamReader(stream)) { renderer.Render(barcode, stream); stream.Position = 0; svg = reader.ReadToEnd(); } // Assert svg.Length.Should().BeGreaterOrEqualTo(0); string expected; using (Stream stream = typeof(SvgRendererTests).Assembly.GetManifestResourceStream("Barcoder.Renderer.Svg.Tests.ExpectedSvgOutput.txt")) using (var reader = new StreamReader(stream)) expected = reader.ReadToEnd().Replace("\r", "").Replace("\n", ""); var actual = svg.Replace("\r", "").Replace("\n", ""); actual.Should().Be(expected); }
public void Encode_ContentTooLong_ShouldThrowException() { Action action = () => Code128.Encode("123456789012345678901234567890123456789012345678901234567890123456789012345678901"); action.Should().Throw <ArgumentException>() .And.Message.StartsWith("Content length should be between 1 and 80 but got 81"); }
public void Encode_EmptyString_ShouldThrowException() { Action action = () => Code128.Encode(string.Empty); action.Should().Throw <ArgumentException>() .And.Message.StartsWith("Content length should be between 1 and 80 but got 0"); }
/// <summary> /// Tests the code128 C. /// </summary> /// <externalUnit/> /// <revision revisor="dev13" date="11/19/2009" version="1.1.3.7"> /// Added documentation header /// </revision> private static void TestCode128C() { string text = "98723493871103000000"; Bitmap barcode = Code128.Encode(text, 1, 0.125F, 96, 12, 0); PixelChar.DrawChar(barcode, 'M', 0, 2); Bitmap pixelchar = new Bitmap(70, 40); Graphics g = Graphics.FromImage(pixelchar); g.Clear(Color.White); g.Dispose(); pixelchar.SetResolution(96, 96); for (int i = 0; i < 7; i++) { for (int j = 0; j < 4; j++) { if (j * 7 + i < 26) { char ch = (char)(j * 7 + i + 65); PixelChar.DrawChar(pixelchar, ch, 10 * i, 10 * j); } } } MemoryInputStream misStream = new MemoryInputStream(barcode, 100); barcode.Dispose(); barcode.Dispose(); DSxInput pdfInput = new DSxInput(misStream); DSxSystem.setLicenseKey( "[Insert your license key here]"); DSxTask task = new DSxTask(); PDFxDocument pdfDoc = PDF.createDocument(task); PDFxContext context = pdfDoc.getContext(); PDFxPage pdfPage = pdfDoc.createCustomPage(5, 2); PDFxImage bar = PDFxImage.createImageFromJPEG(pdfInput); double dpi = 96D, k = 72D / dpi; pdfPage.drawImage( 18, 18, k * bar.getWidth(), k * bar.getHeight(), bar); bar = PDFxImage.createImageFromJPEG( new DSxInput(new MemoryInputStream(pixelchar, 100))); pixelchar.Dispose(); pdfPage.drawImage( 18, 72, k * bar.getWidth(), k * bar.getHeight(), bar); DSxPDFDocument dsDocument = new DSxPDFDocument(pdfDoc); dsDocument.save(new DSxOutput(@"bin\Debug\DSxInput2.pdf")); }
/// <summary> /// Tests the code128 C_B. /// </summary> /// <externalUnit/> /// <revision revisor="dev13" date="11/19/2009" version="1.1.3.7"> /// Added documentation header /// </revision> private static void TestCode128C_b() { string text = "982739487"; Bitmap barcode = Code128.Encode(text, 2, 0.125F, 96); barcode.RotateFlip(RotateFlipType.Rotate90FlipY); barcode.Save(text + ".bmp", ImageFormat.Bmp); }
"1100011101011")] // STOP public void Encode(string txt, string testResult) { IBarcodeIntCS code = Code128.Encode(txt); code.Bounds.X.Should().Be(testResult.Length); code.Bounds.Y.Should().Be(1); code.Metadata.CodeKind.Should().Be(BarcodeType.Code128); 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); }