Example #1
0
        public void DjvuChunk_Theory(DjvuJsonDocument doc, int index)
        {
            int pageCount = 0;

            using (DjvuDocument document = DjvuNet.Tests.Util.GetTestDocument(index, out pageCount))
            {
                DjvuNet.Tests.Util.VerifyDjvuDocument(pageCount, document);
                DjvuNet.Tests.Util.VerifyDjvuDocumentCtor(pageCount, document);

                if (pageCount <= 1)
                {
                    Assert.IsNotType <DjvmChunk>(document.RootForm);
                    Assert.IsType <DjvuChunk>(document.RootForm);
                    DjvuChunk djvu = document.RootForm as DjvuChunk;
                    Assert.NotNull(djvu);
                    Assert.NotNull(djvu.Info);
                    // TODO - Json deserialization is not supporting single page docs
                    // data are sliced to fit into other format - need to fix
                }
                else
                {
                    Assert.IsType <DjvmChunk>(document.RootForm);
                    DjvmChunk djvm = document.RootForm as DjvmChunk;
                    Assert.NotNull(djvm);
                    Assert.NotNull(djvm.Pages);
                    Assert.True(djvm.Pages.Count > 1);
                }
            }
        }
Example #2
0
        public void InclChunk_Theory(string file, DjvuJsonDocument doc)
        {
            byte[] buffer = null;
            using (FileStream fs = new FileStream(file, FileMode.Open, FileAccess.Read, FileShare.Read))
            {
                buffer = new byte[fs.Length];
                int result = fs.Read(buffer, 0, buffer.Length);
                Assert.Equal <long>(fs.Length, result);
            }
            Mock <IDjvuDocument> docMock    = new Mock <IDjvuDocument>();
            Mock <IDjvuElement>  parentMock = new Mock <IDjvuElement>();
            IDjvuElement         parent     = parentMock.Object;
            IDjvuDocument        document   = docMock.Object;

            using (MemoryStream ms = new MemoryStream(buffer, false))
                using (IDjvuReader reader = new DjvuReader(ms))
                {
                    InclChunk chunk = new InclChunk(reader, parent, document, "INCL", buffer.Length);
                    Assert.False(chunk.IsInitialized);
                    // Support multiple INCL chunks in single DjvuChunk
                    var testChunk = doc.Data.Pages[0].Children
                                    .Where(x => x.ID == "INCL" && x.Name == chunk.IncludeID)
                                    .FirstOrDefault <DjvuJsonDocument.Chunk>();
                    Assert.NotNull(testChunk);
                    Assert.Equal(testChunk.Name, chunk.IncludeID);
                }
        }
Example #3
0
        public void Palette_Theory(string file, DjvuJsonDocument doc)
        {
            byte[] buffer = null;
            using (FileStream fs = new FileStream(file, FileMode.Open, FileAccess.Read, FileShare.Read))
            {
                buffer = new byte[fs.Length];
                int result = fs.Read(buffer, 0, buffer.Length);
                Assert.Equal <long>(fs.Length, result);
            }
            Mock <IDjvuDocument> docMock    = new Mock <IDjvuDocument>();
            Mock <IDjvuElement>  parentMock = new Mock <IDjvuElement>();
            IDjvuElement         parent     = parentMock.Object;
            IDjvuDocument        document   = docMock.Object;

            using (MemoryStream ms = new MemoryStream(buffer, false))
                using (IDjvuReader reader = new DjvuReader(ms))
                {
                    FGbzChunk chunk = new FGbzChunk(reader, parent, document, "FGBZ", buffer.Length);
                    Assert.False(chunk.IsInitialized);
                    var testChunk = doc.Data.Pages[0].Children
                                    .Where(x => x.ID == "FGbz")
                                    .FirstOrDefault <DjvuJsonDocument.Chunk>();
                    Assert.Equal <int>((int)testChunk?.Version.Value, chunk.Version);
                    Assert.Equal <int>((int)testChunk.Colors.Value, (int)chunk.Palette?.PaletteColors?.Length);
                }
        }
Example #4
0
        public void DjvmChunk_Theory(DjvuJsonDocument doc, int index)
        {
            // TODO Fix libdjvulibre DjvuDumpHelper implementation - fails
            // for index 39, 63, 64 in some tests - need DjVuLibre tests
            if (index == 63)
            {
                return;
            }

            int pageCount = 0;

            using (DjvuDocument document = DjvuNet.Tests.Util.GetTestDocument(index, out pageCount))
            {
                DjvuNet.Tests.Util.VerifyDjvuDocument(pageCount, document);
                DjvuNet.Tests.Util.VerifyDjvuDocumentCtor(pageCount, document);

                if (pageCount <= 1)
                {
                    Assert.IsNotType <DjvmChunk>(document.RootForm);
                }
                else
                {
                    Assert.IsType <DjvmChunk>(document.RootForm);

                    DjvmChunk djvm = document.RootForm as DjvmChunk;
                    Assert.NotNull(djvm);

                    Assert.NotNull(djvm.Dirm);
                    Assert.NotNull(djvm.Pages);
                    Assert.True(djvm.Pages.Count > 1);
                    Assert.Equal <int>(pageCount, djvm.Pages.Count);
                    Assert.Equal <int>(doc.Data.Files.Length, djvm.Files.Count);
                    if (doc.Data.Includes != null)
                    {
                        Assert.Equal <int>(doc.Data.Includes.Length, djvm.Includes.Count);
                    }
                    if (doc.Data.Thumbnails != null)
                    {
                        Assert.Equal <int>(doc.Data.Thumbnails.Length, djvm.Thumbnails.Count);
                    }
                }
            }
        }
Example #5
0
        public void ThumChunk_Theory(DjvuJsonDocument doc, int index)
        {
            int pageCount = 0;

            using (DjvuDocument document = DjvuNet.Tests.Util.GetTestDocument(index, out pageCount))
            {
                DjvuNet.Tests.Util.VerifyDjvuDocument(pageCount, document);
                DjvuNet.Tests.Util.VerifyDjvuDocumentCtor(pageCount, document);

                if (doc.Data.Thumbnails?.Length > 0)
                {
                    DjvuJsonDocument.RootChild[] thumbsJson = doc.Data.Thumbnails;

                    var thumbs = document.RootForm.Children.Where((x) => x.ChunkType == ChunkType.Thum).ToArray();
                    Assert.Equal <int>(thumbsJson.Length, thumbs.Length);

                    for (int i = 0; i < thumbs.Length; i++)
                    {
                        IDjvuNode    th              = thumbs[i];
                        IDjvuElement thum            = th as IDjvuElement;
                        DjvuJsonDocument.RootChild r = thumbsJson[i];
                        Assert.Equal <int>(thum.Children.Count, r.Children.Length);

                        //DumpTH44ChunkList(index, thum.Children, i);

                        for (int k = 0; k < thum.Children.Count; k++)
                        {
                            IDjvuNode th44 = thum.Children[k];
                            Assert.Equal <ChunkType>(ChunkType.TH44, th44.ChunkType);

                            DjvuJsonDocument.Chunk c = r.Children[k];
                            Assert.Equal <long>(th44.Length, c.Size);
                        }
                    }
                }
                else
                {
                    var thumbs = document.RootForm.Children.Where((x) => x.ChunkType == ChunkType.Thum).ToArray();
                    Assert.Equal <int>(0, thumbs.Length);
                }
            }
        }
Example #6
0
        public void InfoChunk_Theory(DjvuJsonDocument doc, int index)
        {
            int pageCount = 0;

            using (DjvuDocument document = DjvuNet.Tests.Util.GetTestDocument(index, out pageCount))
            {
                DjvuNet.Tests.Util.VerifyDjvuDocument(pageCount, document);
                DjvuNet.Tests.Util.VerifyDjvuDocumentCtor(pageCount, document);

                for (int i = 0; i < pageCount; i++)
                {
                    var page = document.Pages[i];
                    var info = page.Info;
                    if (doc.Data.Pages != null && doc.Data.Pages.Length > 0)
                    {
                        var pageJson = doc.Data.Pages[i];
                        var infoJson = pageJson.Children[0];
                        try
                        {
                            Assert.Equal <int>(infoJson.Dpi.Value, info.DPI);
                            Assert.Equal <double>(infoJson.Gamma.Value, Math.Round(info.Gamma, 3));
                            Assert.Equal <int>(infoJson.Height.Value, info.Height);
                            Assert.Equal <int>(infoJson.Width.Value, info.Width);

                            var major     = info.MajorVersion;
                            var minor     = info.MinorVersion;
                            var rotation  = info.PageRotation;
                            var minorJson = (int)(infoJson.Version.HasValue ? infoJson.Version.Value : 0);
                            Assert.Equal(0, major);
                            Assert.Equal(minorJson, minor);
                        }
                        catch (Exception e)
                        {
                            throw new AggregateException(
                                      $"Validation InfoChunk value mismatch Document index: {index}, page: {i + 1}", e);
                        }
                    }
                }
            }
        }
Example #7
0
        public void DirmChunk_Theory(DjvuJsonDocument doc, int index)
        {
            int pageCount = 0;

            using (DjvuDocument document = DjvuNet.Tests.Util.GetTestDocument(index, out pageCount))
            {
                DjvuNet.Tests.Util.VerifyDjvuDocument(pageCount, document);
                DjvuNet.Tests.Util.VerifyDjvuDocumentCtor(pageCount, document);

                // DirmChunk is present only in multi page documents
                // in which root form is of DjvmChunk type
                if (document.RootForm.ChunkType == ChunkType.Djvm)
                {
                    DirmChunk dirm = ((DjvmChunk)document.RootForm).Dirm;

                    Assert.NotNull(dirm);

                    Assert.True(dirm.IsBundled ? doc.Data.Dirm.DocumentType == "bundled" : doc.Data.Dirm.DocumentType == "indirect");

                    var components = dirm.Components;
                    Assert.Equal <int>(components.Count, doc.Data.Dirm.FileCount);
                }
            }
        }