示例#1
0
        public virtual void SeekTest()
        {
            String data = "/Name1 70";

            PdfTokenizer.TokenType[] expectedTypes = new PdfTokenizer.TokenType[] { PdfTokenizer.TokenType.Name, PdfTokenizer.TokenType
                                                                                    .Number, PdfTokenizer.TokenType.EndOfFile };
            RandomAccessSourceFactory factory = new RandomAccessSourceFactory();
            PdfTokenizer tok = new PdfTokenizer(new RandomAccessFileOrArray(factory.CreateSource(data.GetBytes(iText.IO.Util.EncodingUtil.ISO_8859_1
                                                                                                               ))));

            tok.Seek(0);
            tok.NextValidToken();
            NUnit.Framework.Assert.AreEqual(expectedTypes[0], tok.GetTokenType());
            NUnit.Framework.Assert.AreEqual("Name1", tok.GetStringValue());
            tok.Seek(7);
            tok.NextValidToken();
            NUnit.Framework.Assert.AreEqual(expectedTypes[1], tok.GetTokenType());
            NUnit.Framework.Assert.AreEqual("70", tok.GetStringValue());
            tok.Seek(8);
            tok.NextValidToken();
            NUnit.Framework.Assert.AreEqual(expectedTypes[1], tok.GetTokenType());
            NUnit.Framework.Assert.AreEqual("0", tok.GetStringValue());
            tok.Seek(9);
            tok.NextValidToken();
            NUnit.Framework.Assert.AreEqual(expectedTypes[2], tok.GetTokenType());
        }
示例#2
0
        public virtual void CheckPdfHeaderTest()
        {
            RandomAccessSourceFactory factory = new RandomAccessSourceFactory();
            PdfTokenizer tok = new PdfTokenizer(new RandomAccessFileOrArray(factory.CreateBestSource(sourceFolder + "test.pdf"
                                                                                                     )));

            NUnit.Framework.Assert.AreEqual("PDF-1.7", tok.CheckPdfHeader());
        }
示例#3
0
        public virtual void GetHeaderOffsetTest()
        {
            RandomAccessSourceFactory factory = new RandomAccessSourceFactory();
            PdfTokenizer tok = new PdfTokenizer(new RandomAccessFileOrArray(factory.CreateBestSource(sourceFolder + "test.pdf"
                                                                                                     )));

            NUnit.Framework.Assert.AreEqual(0, tok.GetHeaderOffset());
        }
示例#4
0
        public virtual void ReadStringLongerThenDataTest()
        {
            String data = "/Name1 15";
            RandomAccessSourceFactory factory = new RandomAccessSourceFactory();
            PdfTokenizer tok = new PdfTokenizer(new RandomAccessFileOrArray(factory.CreateSource(data.GetBytes(iText.IO.Util.EncodingUtil.ISO_8859_1
                                                                                                               ))));

            NUnit.Framework.Assert.AreEqual(data, tok.ReadString(data.Length + 10));
        }
示例#5
0
        public virtual void TokenValueEqualsToNullTest()
        {
            String data = "SomeString";
            RandomAccessSourceFactory factory = new RandomAccessSourceFactory();
            PdfTokenizer tok = new PdfTokenizer(new RandomAccessFileOrArray(factory.CreateSource(data.GetBytes(iText.IO.Util.EncodingUtil.ISO_8859_1
                                                                                                               ))));

            tok.NextToken();
            NUnit.Framework.Assert.IsFalse(tok.TokenValueEqualsTo(null));
        }
示例#6
0
        public virtual void GetIntValueTest()
        {
            String data = "15";
            RandomAccessSourceFactory factory = new RandomAccessSourceFactory();
            PdfTokenizer tok = new PdfTokenizer(new RandomAccessFileOrArray(factory.CreateSource(data.GetBytes(iText.IO.Util.EncodingUtil.ISO_8859_1
                                                                                                               ))));

            tok.NextValidToken();
            NUnit.Framework.Assert.AreEqual(PdfTokenizer.TokenType.Number, tok.GetTokenType());
            NUnit.Framework.Assert.AreEqual(15, tok.GetIntValue());
        }
示例#7
0
 public virtual void ThrowErrorTest()
 {
     NUnit.Framework.Assert.That(() => {
         RandomAccessSourceFactory factory = new RandomAccessSourceFactory();
         PdfTokenizer tok = new PdfTokenizer(new RandomAccessFileOrArray(factory.CreateSource("/Name1".GetBytes(iText.IO.Util.EncodingUtil.ISO_8859_1
                                                                                                                ))));
         tok.ThrowError(iText.IO.IOException.ErrorAtFilePointer1, 0);
     }
                                 , NUnit.Framework.Throws.InstanceOf <iText.IO.IOException>().With.Message.EqualTo(MessageFormatUtil.Format(iText.IO.IOException.ErrorAtFilePointer1, 0)))
     ;
 }
示例#8
0
        public virtual void ReadTest()
        {
            String data = "/Name1 15";
            RandomAccessSourceFactory factory = new RandomAccessSourceFactory();
            PdfTokenizer tok = new PdfTokenizer(new RandomAccessFileOrArray(factory.CreateSource(data.GetBytes(iText.IO.Util.EncodingUtil.ISO_8859_1
                                                                                                               ))));

            byte[] read = new byte[] { (byte)tok.Read(), (byte)tok.Read(), (byte)tok.Read(), (byte)tok.Read(), (byte)tok
                                       .Read(), (byte)tok.Read(), (byte)tok.Read() };
            NUnit.Framework.Assert.AreEqual("/Name1 ", iText.IO.Util.JavaUtil.GetStringForBytes(read));
        }
示例#9
0
        private void CheckTokenValues(String data, params byte[][] expectedValues)
        {
            RandomAccessSourceFactory factory = new RandomAccessSourceFactory();
            PdfTokenizer tok = new PdfTokenizer(new RandomAccessFileOrArray(factory.CreateSource(data.GetBytes(iText.IO.Util.EncodingUtil.ISO_8859_1
                                                                                                               ))));

            for (int i = 0; i < expectedValues.Length; i++)
            {
                tok.NextValidToken();
                NUnit.Framework.Assert.AreEqual(expectedValues[i], tok.GetByteContent(), "Position " + i);
            }
        }
示例#10
0
        public virtual void GetDecodedStringContentHexTest()
        {
            String data = "<736f6d652068657820737472696e67>";
            RandomAccessSourceFactory factory = new RandomAccessSourceFactory();
            PdfTokenizer tok = new PdfTokenizer(new RandomAccessFileOrArray(factory.CreateSource(data.GetBytes(iText.IO.Util.EncodingUtil.ISO_8859_1
                                                                                                               ))));

            tok.NextToken();
            NUnit.Framework.Assert.IsTrue(tok.IsHexString());
            NUnit.Framework.Assert.AreEqual("some hex string", iText.IO.Util.JavaUtil.GetStringForBytes(tok.GetDecodedStringContent
                                                                                                            ()));
        }
示例#11
0
        public virtual void GetPositionTest()
        {
            String data = "/Name1 70";
            RandomAccessSourceFactory factory = new RandomAccessSourceFactory();
            PdfTokenizer tok = new PdfTokenizer(new RandomAccessFileOrArray(factory.CreateSource(data.GetBytes(iText.IO.Util.EncodingUtil.ISO_8859_1
                                                                                                               ))));

            NUnit.Framework.Assert.AreEqual(0, tok.GetPosition());
            tok.NextValidToken();
            NUnit.Framework.Assert.AreEqual(6, tok.GetPosition());
            tok.NextValidToken();
            NUnit.Framework.Assert.AreEqual(11, tok.GetPosition());
        }
示例#12
0
        public virtual void GetDecodedStringContentTest()
        {
            String data = "/Name1 15";
            RandomAccessSourceFactory factory = new RandomAccessSourceFactory();
            PdfTokenizer tok = new PdfTokenizer(new RandomAccessFileOrArray(factory.CreateSource(data.GetBytes(iText.IO.Util.EncodingUtil.ISO_8859_1
                                                                                                               ))));

            tok.NextToken();
            NUnit.Framework.Assert.AreEqual("Name1", iText.IO.Util.JavaUtil.GetStringForBytes(tok.GetDecodedStringContent
                                                                                                  ()));
            tok.NextToken();
            NUnit.Framework.Assert.AreEqual("15", iText.IO.Util.JavaUtil.GetStringForBytes(tok.GetDecodedStringContent
                                                                                               ()));
            tok.NextToken();
            NUnit.Framework.Assert.AreEqual("", iText.IO.Util.JavaUtil.GetStringForBytes(tok.GetDecodedStringContent()
                                                                                         ));
        }
示例#13
0
        public virtual void PrimitivesTest()
        {
            String data = "<</Size 70.%comment\n" + "/Value#20 .1" + "/Root 46 0 R" + "/Info 44 0 R" + "/ID[<736f6d652068657820737472696e672>(some simple string )<8C2547D58D4BD2C6F3D32B830BE3259D2>-70.1--0.2]"
                          + "/Name1 --15" + "/Prev ---116.23 >>";
            RandomAccessSourceFactory factory = new RandomAccessSourceFactory();
            PdfTokenizer tok = new PdfTokenizer(new RandomAccessFileOrArray(factory.CreateSource(data.GetBytes(iText.IO.Util.EncodingUtil.ISO_8859_1
                                                                                                               ))));

            tok.NextValidToken();
            NUnit.Framework.Assert.AreEqual(PdfTokenizer.TokenType.StartDic, tok.GetTokenType());
            tok.NextValidToken();
            NUnit.Framework.Assert.AreEqual(PdfTokenizer.TokenType.Name, tok.GetTokenType());
            NUnit.Framework.Assert.AreEqual("Size", iText.IO.Util.JavaUtil.GetStringForBytes(tok.GetByteContent()));
            tok.NextValidToken();
            NUnit.Framework.Assert.AreEqual(PdfTokenizer.TokenType.Number, tok.GetTokenType());
            NUnit.Framework.Assert.AreEqual("70.", iText.IO.Util.JavaUtil.GetStringForBytes(tok.GetByteContent()));
            tok.NextValidToken();
            NUnit.Framework.Assert.AreEqual(PdfTokenizer.TokenType.Name, tok.GetTokenType());
            NUnit.Framework.Assert.AreEqual("Value#20", iText.IO.Util.JavaUtil.GetStringForBytes(tok.GetByteContent())
                                            );
            tok.NextValidToken();
            NUnit.Framework.Assert.AreEqual(PdfTokenizer.TokenType.Number, tok.GetTokenType());
            NUnit.Framework.Assert.AreEqual(".1", iText.IO.Util.JavaUtil.GetStringForBytes(tok.GetByteContent()));
            tok.NextValidToken();
            NUnit.Framework.Assert.AreEqual(PdfTokenizer.TokenType.Name, tok.GetTokenType());
            NUnit.Framework.Assert.AreEqual("Root", iText.IO.Util.JavaUtil.GetStringForBytes(tok.GetByteContent()));
            tok.NextValidToken();
            NUnit.Framework.Assert.AreEqual(PdfTokenizer.TokenType.Ref, tok.GetTokenType());
            NUnit.Framework.Assert.AreEqual("46 0 R", "" + tok.GetObjNr() + " " + tok.GetGenNr() + " " + iText.IO.Util.JavaUtil.GetStringForBytes
                                                (tok.GetByteContent()));
            tok.NextValidToken();
            NUnit.Framework.Assert.AreEqual(PdfTokenizer.TokenType.Name, tok.GetTokenType());
            NUnit.Framework.Assert.AreEqual("Info", iText.IO.Util.JavaUtil.GetStringForBytes(tok.GetByteContent()));
            tok.NextValidToken();
            NUnit.Framework.Assert.AreEqual(PdfTokenizer.TokenType.Ref, tok.GetTokenType());
            NUnit.Framework.Assert.AreEqual("44 0 R", "" + tok.GetObjNr() + " " + tok.GetGenNr() + " " + iText.IO.Util.JavaUtil.GetStringForBytes
                                                (tok.GetByteContent()));
            tok.NextValidToken();
            NUnit.Framework.Assert.AreEqual(PdfTokenizer.TokenType.Name, tok.GetTokenType());
            NUnit.Framework.Assert.AreEqual("ID", iText.IO.Util.JavaUtil.GetStringForBytes(tok.GetByteContent()));
            tok.NextValidToken();
            NUnit.Framework.Assert.AreEqual(PdfTokenizer.TokenType.StartArray, tok.GetTokenType());
            tok.NextValidToken();
            NUnit.Framework.Assert.AreEqual(PdfTokenizer.TokenType.String, tok.GetTokenType());
            NUnit.Framework.Assert.IsTrue(tok.IsHexString());
            NUnit.Framework.Assert.AreEqual("736f6d652068657820737472696e672", iText.IO.Util.JavaUtil.GetStringForBytes
                                                (tok.GetByteContent()));
            tok.NextValidToken();
            NUnit.Framework.Assert.AreEqual(PdfTokenizer.TokenType.String, tok.GetTokenType());
            NUnit.Framework.Assert.IsFalse(tok.IsHexString());
            NUnit.Framework.Assert.AreEqual("some simple string ", iText.IO.Util.JavaUtil.GetStringForBytes(tok.GetByteContent
                                                                                                                ()));
            tok.NextValidToken();
            NUnit.Framework.Assert.AreEqual(PdfTokenizer.TokenType.String, tok.GetTokenType());
            NUnit.Framework.Assert.IsTrue(tok.IsHexString());
            NUnit.Framework.Assert.AreEqual("8C2547D58D4BD2C6F3D32B830BE3259D2", iText.IO.Util.JavaUtil.GetStringForBytes
                                                (tok.GetByteContent()));
            tok.NextValidToken();
            NUnit.Framework.Assert.AreEqual(PdfTokenizer.TokenType.Number, tok.GetTokenType());
            NUnit.Framework.Assert.AreEqual("-70.1", iText.IO.Util.JavaUtil.GetStringForBytes(tok.GetByteContent()));
            tok.NextValidToken();
            NUnit.Framework.Assert.AreEqual(PdfTokenizer.TokenType.Number, tok.GetTokenType());
            NUnit.Framework.Assert.AreEqual("-0.2", iText.IO.Util.JavaUtil.GetStringForBytes(tok.GetByteContent()));
            tok.NextValidToken();
            NUnit.Framework.Assert.AreEqual(PdfTokenizer.TokenType.EndArray, tok.GetTokenType());
            tok.NextValidToken();
            NUnit.Framework.Assert.AreEqual(PdfTokenizer.TokenType.Name, tok.GetTokenType());
            NUnit.Framework.Assert.AreEqual("Name1", iText.IO.Util.JavaUtil.GetStringForBytes(tok.GetByteContent()));
            tok.NextValidToken();
            NUnit.Framework.Assert.AreEqual(PdfTokenizer.TokenType.Number, tok.GetTokenType());
            NUnit.Framework.Assert.AreEqual("0", iText.IO.Util.JavaUtil.GetStringForBytes(tok.GetByteContent()));
            tok.NextValidToken();
            NUnit.Framework.Assert.AreEqual(PdfTokenizer.TokenType.Name, tok.GetTokenType());
            NUnit.Framework.Assert.AreEqual("Prev", iText.IO.Util.JavaUtil.GetStringForBytes(tok.GetByteContent()));
            tok.NextValidToken();
            NUnit.Framework.Assert.AreEqual(PdfTokenizer.TokenType.Number, tok.GetTokenType());
            NUnit.Framework.Assert.AreEqual("-116.23", iText.IO.Util.JavaUtil.GetStringForBytes(tok.GetByteContent()));
        }