Esempio n. 1
0
        public virtual void UriResolverTest08()
        {
            UriResolver resolver = new UriResolver("http://itextpdf.com/itext7/");

            NUnit.Framework.Assert.AreEqual("http://itextpdf.com/itext7/", resolver.GetBaseUri());
            NUnit.Framework.Assert.AreEqual("http://itextpdf.com/itext7/innerTest", resolver.ResolveAgainstBaseUri("innerTest"
                                                                                                                   ).ToExternalForm());
            NUnit.Framework.Assert.AreEqual("http://itextpdf.com/folder2/innerTest2", resolver.ResolveAgainstBaseUri("/folder2/innerTest2"
                                                                                                                     ).ToExternalForm());
            NUnit.Framework.Assert.AreEqual("http://folder2.com/innerTest2", resolver.ResolveAgainstBaseUri("//folder2.com/innerTest2"
                                                                                                            ).ToExternalForm());
        }
Esempio n. 2
0
        public virtual void UriResolverTest14()
        {
            UriResolver resolver  = new UriResolver("base/uri/index.html");
            String      runFolder = new Uri(Path.GetFullPath(Directory.GetCurrentDirectory())).ToExternalForm() + "/";

            NUnit.Framework.Assert.AreEqual(runFolder + "base/uri/index.html", resolver.GetBaseUri());
            NUnit.Framework.Assert.AreEqual("file:///c:/test/folder/img.txt", resolver.ResolveAgainstBaseUri("file:/c:/test/folder/img.txt"
                                                                                                             ).ToExternalForm());
            NUnit.Framework.Assert.AreEqual("file:///c:/test/folder/img.txt", resolver.ResolveAgainstBaseUri("file://c:/test/folder/img.txt"
                                                                                                             ).ToExternalForm());
            NUnit.Framework.Assert.AreEqual("file:///c:/test/folder/data.jpg", resolver.ResolveAgainstBaseUri("file:///c:/test/folder/data.jpg"
                                                                                                              ).ToExternalForm());
        }
Esempio n. 3
0
        public virtual void UriResolverTest16C()
        {
            String      absolutePathRoot = new Uri(new Uri("file://"), Path.GetPathRoot(Directory.GetCurrentDirectory())).ToString();
            UriResolver resolver         = new UriResolver(absolutePathRoot + "path%2Fwith%2Fspaces/test/folder/index.html");
            String      rootFolder       = new Uri(new Uri("file://"), Path.GetPathRoot(Directory.GetCurrentDirectory())).ToExternalForm();
            String      uriRoot          = rootFolder + "path%2Fwith%2Fspaces/";

            NUnit.Framework.Assert.AreNotEqual(uriRoot + "test/folder/innerTest", resolver.ResolveAgainstBaseUri
                                                   ("innerTest").ToExternalForm());
            NUnit.Framework.Assert.AreNotEqual(uriRoot + "test/folder2/innerTest2", resolver.ResolveAgainstBaseUri
                                                   ("../folder2/innerTest2").ToExternalForm());
// Look to commentary in TestPaths() method
//            NUnit.Framework.Assert.AreNotEqual(uriRoot + "test/folder/folder2/innerTest2", resolver.ResolveAgainstBaseUri
//                ("/folder2/innerTest2").ToExternalForm());
//            NUnit.Framework.Assert.AreNotEqual(uriRoot + "test/folder/folder2/innerTest2", resolver.ResolveAgainstBaseUri
//                ("//folder2/innerTest2").ToExternalForm());
        }
Esempio n. 4
0
        public void quoteInPercentsBasePath()
        {
            String      expectedUrl  = "https://he.wikipedia.org/wiki%27/%D7%90%D7%91%D7%92%D7%93";
            String      baseUri      = "https://he.wikipedia.org/wiki%27/";
            String      relativePath = "%D7%90%D7%91%D7%92%D7%93";
            UriResolver resolver     = new UriResolver(baseUri);

            NUnit.Framework.Assert.AreEqual(expectedUrl, resolver.ResolveAgainstBaseUri(relativePath).ToExternalForm());
        }
Esempio n. 5
0
        public virtual void ResourceResolverConstructorTest()
        {
            ResourceResolver rr    = new ResourceResolver(null);
            UriResolver      ur    = new UriResolver("");
            String           rrUrl = rr.ResolveAgainstBaseUri("").ToString();
            String           urUrl = ur.ResolveAgainstBaseUri("").ToString();

            NUnit.Framework.Assert.AreEqual(rrUrl, urUrl);
        }
Esempio n. 6
0
        public virtual void ConstructorWithBaseUriAndResourceRetrieverTest()
        {
            ResourceResolver resolver = new ResourceResolver("folder", new CustomResourceRetriever());

            UriResolver uriResolver = new UriResolver("folder");
            String      resolveUrl  = resolver.ResolveAgainstBaseUri("").ToString();
            String      expectedUrl = uriResolver.ResolveAgainstBaseUri("").ToString();

            Assert.AreEqual(resolveUrl, expectedUrl);
            Assert.AreEqual(typeof(CustomResourceRetriever), resolver.GetRetriever().GetType());
        }
Esempio n. 7
0
        public virtual void ReadingByteArrayWithOffsetAfterFileReadingTest()
        {
            UriResolver uriResolver = new UriResolver(baseUri);
            Uri         url         = uriResolver.ResolveAgainstBaseUri("retrieveStyleSheetTest.css.dat");
            // retrieveStyleSheetTest.css.dat size is 89 bytes
            Stream stream = new LimitedInputStream(UrlUtil.OpenStream(url), 100);

            // The user can call the reading methods as many times as he want, and if the
            // stream has been read, then should not throw an ReadingByteLimitException exception
            stream.JRead(new byte[100], 0, 100);
            stream.JRead(new byte[1], 0, 1);
        }
Esempio n. 8
0
        public virtual void ByteArrayOverwritingTest()
        {
            UriResolver uriResolver = new UriResolver(baseUri);
            Uri         url         = uriResolver.ResolveAgainstBaseUri("retrieveStyleSheetTest.css.dat");
            // retrieveStyleSheetTest.css.dat size is 89 bytes
            Stream stream = new LimitedInputStream(UrlUtil.OpenStream(url), 90);

            byte[] bytes = new byte[100];
            bytes[89] = 13;
            NUnit.Framework.Assert.AreEqual(89, stream.Read(bytes));
            // Check that when calling the read(byte[]) method, as many bytes were copied into
            // the original array as were read, and not all bytes from the auxiliary array.
            NUnit.Framework.Assert.AreEqual(13, bytes[89]);
        }
Esempio n. 9
0
        public virtual void ReadingByteArrayWithOffsetAndBigBufferTest()
        {
            UriResolver uriResolver = new UriResolver(baseUri);
            Uri         url         = uriResolver.ResolveAgainstBaseUri("retrieveStyleSheetTest.css.dat");
            // retrieveStyleSheetTest.css.dat size is 89 bytes
            Stream stream = new LimitedInputStream(UrlUtil.OpenStream(url), 89);

            byte[] bytes = new byte[100];
            NUnit.Framework.Assert.AreEqual(89, stream.JRead(bytes, 0, 100));
            byte[] tempBytes = (byte[])bytes.Clone();
            NUnit.Framework.Assert.AreEqual(-1, stream.JRead(bytes, 0, 100));
            // Check that the array has not changed when we have read the entire LimitedInputStream
            NUnit.Framework.Assert.AreEqual(tempBytes, bytes);
        }
Esempio n. 10
0
        public virtual void UriResolverTest04()
        {
            UriResolver resolver  = new UriResolver("index.html");
            String      runFolder = new Uri(Path.GetFullPath(Directory.GetCurrentDirectory() + "/")).ToExternalForm();

            NUnit.Framework.Assert.AreEqual(runFolder + "index.html", resolver.GetBaseUri());
            NUnit.Framework.Assert.AreEqual(runFolder + "innerTest", resolver.ResolveAgainstBaseUri("innerTest").ToExternalForm
                                                ());

// Look to commentary below in TestPaths() method
//            NUnit.Framework.Assert.AreEqual(runFolder + "folder2/innerTest2", resolver.ResolveAgainstBaseUri("/folder2/innerTest2"
//                ).ToExternalForm());
//            NUnit.Framework.Assert.AreEqual(runFolder + "folder2/innerTest2", resolver.ResolveAgainstBaseUri("//folder2/innerTest2"
//                ).ToExternalForm());
        }
Esempio n. 11
0
        public virtual void UriResolverTest07B()
        {
            String      absolutePathRoot = new Uri(new Uri("file://"), Path.GetPathRoot(Directory.GetCurrentDirectory())).ToExternalForm();
            UriResolver resolver         = new UriResolver(absolutePathRoot + "#r%e%25s@o%urces/folder/index.html");
            String      malformedPath    = absolutePathRoot;

            NUnit.Framework.Assert.AreEqual(malformedPath + "#r%25e%25s@o%25urces/folder/index.html", resolver.GetBaseUri());
            NUnit.Framework.Assert.AreEqual(malformedPath + "test/folder/innerTest", resolver.ResolveAgainstBaseUri
                                                ("test/folder/innerTest").ToExternalForm());
// Look to commentary below in TestPaths() method
//            NUnit.Framework.Assert.AreEqual(malformedPath + "folder2/innerTest2", resolver.ResolveAgainstBaseUri
//              ("/folder2/innerTest2").ToExternalForm());
//            NUnit.Framework.Assert.AreEqual(malformedPath + "folder2/innerTest2", resolver.ResolveAgainstBaseUri
//                ("//folder2/innerTest2").ToExternalForm());
        }
Esempio n. 12
0
        public virtual void ReadingByteWithLimitOfOneLessThenFileSizeTest()
        {
            UriResolver uriResolver = new UriResolver(baseUri);
            Uri         url         = uriResolver.ResolveAgainstBaseUri("retrieveStyleSheetTest.css.dat");
            // retrieveStyleSheetTest.css.dat size is 89 bytes
            Stream stream = new LimitedInputStream(UrlUtil.OpenStream(url), 88);

            for (int i = 0; i < 88; i++)
            {
                NUnit.Framework.Assert.AreNotEqual(-1, stream.Read());
            }
            NUnit.Framework.Assert.That(() => {
                stream.Read();
            }
                                        , NUnit.Framework.Throws.InstanceOf <ReadingByteLimitException>())
            ;
        }
Esempio n. 13
0
        public virtual void ReadingByteArrayWithLimitOfOneLessThenFileSizeTest()
        {
            UriResolver uriResolver = new UriResolver(baseUri);
            Uri         url         = uriResolver.ResolveAgainstBaseUri("retrieveStyleSheetTest.css.dat");
            // retrieveStyleSheetTest.css.dat size is 89 bytes
            Stream stream = new LimitedInputStream(UrlUtil.OpenStream(url), 88);

            byte[] bytes          = new byte[100];
            int    numOfReadBytes = stream.Read(bytes);

            NUnit.Framework.Assert.AreEqual(88, numOfReadBytes);
            NUnit.Framework.Assert.AreEqual(10, bytes[87]);
            NUnit.Framework.Assert.AreEqual(0, bytes[88]);
            NUnit.Framework.Assert.That(() => {
                stream.Read(new byte[1]);
            }
                                        , NUnit.Framework.Throws.InstanceOf <ReadingByteLimitException>())
            ;
        }
Esempio n. 14
0
        public virtual void ReadingByteArrayWithSmallBufferTest()
        {
            UriResolver uriResolver = new UriResolver(baseUri);
            Uri         url         = uriResolver.ResolveAgainstBaseUri("retrieveStyleSheetTest.css.dat");
            // retrieveStyleSheetTest.css.dat size is 89 bytes
            Stream stream = new LimitedInputStream(UrlUtil.OpenStream(url), 89);

            byte[]       bytes  = new byte[20];
            MemoryStream output = new MemoryStream();

            while (true)
            {
                int read = stream.Read(bytes);
                if (read < 1)
                {
                    break;
                }
                output.Write(bytes, 0, read);
            }
            NUnit.Framework.Assert.AreEqual(89, output.Length);
            output.Dispose();
        }
Esempio n. 15
0
 /// <summary>
 /// Open an
 /// <see cref="System.IO.Stream"/>
 /// to a style sheet URI.
 /// </summary>
 /// <param name="uri">the URI</param>
 /// <returns>
 /// the
 /// <see cref="System.IO.Stream"/>
 /// </returns>
 public virtual Stream RetrieveStyleSheet(String uri)
 {
     return(UrlUtil.OpenStream(uriResolver.ResolveAgainstBaseUri(uri)));
 }
Esempio n. 16
0
        public virtual void UriResolverTest17()
        {
            String      absolutePathRoot = new Uri(new Uri("file://"), Path.GetPathRoot(Directory.GetCurrentDirectory())).ToString();
            String      absoluteBaseUri  = absolutePathRoot + "test/fol ders/wi@th/diffe#rent/$characters/test/folder/index.html\t\t\t\t\t\t";
            UriResolver resolver         = new UriResolver(absoluteBaseUri);
            String      malformedPath    = absolutePathRoot + "test/fol%20ders/wi@th/diffe#rent/$characters/";

            NUnit.Framework.Assert.AreNotEqual(malformedPath + "test/folder/innerTest", resolver.ResolveAgainstBaseUri
                                                   ("innerTest").ToExternalForm());
            NUnit.Framework.Assert.AreNotEqual(malformedPath + "test/folder2/innerTest2", resolver.ResolveAgainstBaseUri
                                                   ("../folder2/innerTest2").ToExternalForm());
// Look to commentary in TestPaths() method
//            NUnit.Framework.Assert.AreNotEqual(malformedPath + "test/folder/folder2/innerTest2", resolver.ResolveAgainstBaseUri
//                ("/folder2/innerTest2").ToExternalForm());
//            NUnit.Framework.Assert.AreNotEqual(malformedPath + "test/folder/folder2/innerTest2", resolver.ResolveAgainstBaseUri
//                ("//folder2/innerTest2").ToExternalForm());
        }
Esempio n. 17
0
        private void TestPaths(String absolutePathRoot, UriResolver resolver)
        {
            NUnit.Framework.Assert.AreEqual(absolutePathRoot + "test/folder/index.html", resolver.GetBaseUri());
            NUnit.Framework.Assert.AreEqual(absolutePathRoot + "test/folder/innerTest", resolver.ResolveAgainstBaseUri
                                                ("innerTest").ToExternalForm());
            NUnit.Framework.Assert.AreEqual(absolutePathRoot + "test/folder2/innerTest2", resolver.ResolveAgainstBaseUri
                                                ("../folder2/innerTest2").ToExternalForm());

            /*
             *  Resolving relative paths like "/folder" works correct on Linux and .NET, but fails on Java because of strong
             *  corresponding with URI standard RFC3986.
             *
             *  Look to this memo for specifying "file" URI scheme:
             *  https://tools.ietf.org/id/draft-ietf-appsawg-file-scheme-12.html
             *
             *  Expected results after resolving "/folder2/innerTest2":
             *      - .NET: "file:///C:/folder2/innerTest2"
             *      - Java (Windows): "file:/folder2/innerTest2" - incorrect
             *      - Java (Linux): "file:/folder2/innerTest2" - correct
             */

//            NUnit.Framework.Assert.AreEqual(absolutePathRoot + "test/folder/folder2/innerTest2", resolver.ResolveAgainstBaseUri
//                ("/folder2/innerTest2").ToExternalForm());
//            NUnit.Framework.Assert.AreEqual(absolutePathRoot + "test/folder/folder2/innerTest2", resolver.ResolveAgainstBaseUri
//                ("//folder2/innerTest2").ToExternalForm());
        }
Esempio n. 18
0
 public virtual Stream RetrieveStyleSheet(String uri)
 {
     return(retriever.GetInputStreamByUrl(uriResolver.ResolveAgainstBaseUri(uri)));
 }