Mercurial > hgrepos > Python2 > PyMuPDF
comparison mupdf-source/thirdparty/zxing-cpp/wrappers/dotnet/ZXingCpp.Tests/UnitTest1.cs @ 2:b50eed0cc0ef upstream
ADD: MuPDF v1.26.7: the MuPDF source as downloaded by a default build of PyMuPDF 1.26.4.
The directory name has changed: no version number in the expanded directory now.
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Mon, 15 Sep 2025 11:43:07 +0200 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 1:1d09e1dec1d9 | 2:b50eed0cc0ef |
|---|---|
| 1 using Xunit; | |
| 2 using System.Text; | |
| 3 using ZXingCpp; | |
| 4 | |
| 5 namespace ZXingCpp.Tests; | |
| 6 | |
| 7 public class UnitTest1 | |
| 8 { | |
| 9 [Fact] | |
| 10 public void ValidBarcodeFormatsParsing() | |
| 11 { | |
| 12 Assert.Equal(BarcodeFormats.QRCode, Barcode.FormatsFromString("qrcode")); | |
| 13 Assert.Equal(BarcodeFormats.LinearCodes, Barcode.FormatsFromString("linear_codes")); | |
| 14 Assert.Equal(BarcodeFormats.None, Barcode.FormatsFromString("")); | |
| 15 } | |
| 16 | |
| 17 [Fact] | |
| 18 public void InvalidBarcodeFormatsParsing() | |
| 19 { | |
| 20 Assert.Throws<Exception>(() => Barcode.FormatsFromString("nope")); | |
| 21 } | |
| 22 | |
| 23 [Fact] | |
| 24 public void InvalidImageView() | |
| 25 { | |
| 26 Assert.Throws<Exception>(() => new ImageView(new byte[0], 1, 1, ImageFormat.Lum)); | |
| 27 Assert.Throws<Exception>(() => new ImageView(new byte[1], 1, 1, ImageFormat.Lum, 2)); | |
| 28 } | |
| 29 | |
| 30 [Fact] | |
| 31 public void Read() | |
| 32 { | |
| 33 var data = new List<byte>(); | |
| 34 foreach (var v in "0000101000101101011110111101011011101010100111011100101000100101110010100000") | |
| 35 data.Add((byte)(v == '0' ? 255 : 0)); | |
| 36 | |
| 37 var iv = new ImageView(data.ToArray(), data.Count, 1, ImageFormat.Lum); | |
| 38 var br = new BarcodeReader() { | |
| 39 Binarizer = Binarizer.BoolCast, | |
| 40 }; | |
| 41 var res = br.From(iv); | |
| 42 | |
| 43 var expected = "96385074"; | |
| 44 | |
| 45 Assert.Single(res); | |
| 46 Assert.True(res[0].IsValid); | |
| 47 Assert.Equal(BarcodeFormats.EAN8, res[0].Format); | |
| 48 Assert.Equal(expected, res[0].Text); | |
| 49 Assert.Equal(Encoding.ASCII.GetBytes(expected), res[0].Bytes); | |
| 50 Assert.False(res[0].HasECI); | |
| 51 Assert.Equal(ContentType.Text, res[0].ContentType); | |
| 52 Assert.Equal(0, res[0].Orientation); | |
| 53 Assert.Equal(new PointI() { X = 4, Y = 0 }, res[0].Position.TopLeft); | |
| 54 Assert.Equal(1, res[0].LineCount); | |
| 55 Assert.False(res[0].IsMirrored); | |
| 56 Assert.False(res[0].IsInverted); | |
| 57 Assert.Equal(ErrorType.None, res[0].ErrorType); | |
| 58 Assert.Equal("", res[0].ErrorMsg); | |
| 59 } | |
| 60 | |
| 61 [Fact] | |
| 62 public void Create() | |
| 63 { | |
| 64 var text = "hello"; | |
| 65 var res = new Barcode(text, BarcodeFormats.DataMatrix); | |
| 66 | |
| 67 Assert.True(res.IsValid); | |
| 68 Assert.Equal(BarcodeFormats.DataMatrix, res.Format); | |
| 69 Assert.Equal(text, res.Text); | |
| 70 Assert.Equal(Encoding.ASCII.GetBytes(text), res.Bytes); | |
| 71 Assert.False(res.HasECI); | |
| 72 Assert.Equal(ContentType.Text, res.ContentType); | |
| 73 Assert.Equal(0, res.Orientation); | |
| 74 Assert.False(res.IsMirrored); | |
| 75 Assert.False(res.IsInverted); | |
| 76 Assert.Equal(new PointI() { X = 1, Y = 1 }, res.Position.TopLeft); | |
| 77 Assert.Equal(ErrorType.None, res.ErrorType); | |
| 78 Assert.Equal("", res.ErrorMsg); | |
| 79 } | |
| 80 } |
