Esempio n. 1
0
        public void testHandoverStreamWithDeferedProperties()
        {
            log.info("testHandoverStreamWithDeferedProperties(");

            BContentStream bstrm1 = (BContentStream)remote.GetStreamDeferedProperies();

            TestUtils.assertEquals(log, "contentType", "", bstrm1.ContentType);
            TestUtils.assertEquals(log, "contentLength", -1L, bstrm1.ContentLength);
            TestUtils.assertEquals(log, "fileName", "", bstrm1.FileName);
            TestUtils.assertEquals(log, "attachmentCode", 0, bstrm1.AttachmentCode);

            remote.SetStreamDoNotMaterialize(bstrm1);
            BContentStream bstrm = (BContentStream)remote.GetStreamDoNotClone();

            TestUtils.assertEquals(log, "contentType", "", bstrm.ContentType);
            TestUtils.assertEquals(log, "contentLength", -1L, bstrm.ContentLength);
            TestUtils.assertEquals(log, "fileName", "", bstrm.FileName);
            TestUtils.assertEquals(log, "attachmentCode", 0, bstrm.AttachmentCode);

            bstrm.ensureProperties();
            TestUtils.assertEquals(log, "contentType", "application/mycontentype", bstrm.ContentType);
            TestUtils.assertEquals(log, "contentLength", 5L, bstrm.ContentLength);
            TestUtils.assertEquals(log, "fileName", "myfilename", bstrm.FileName);
            TestUtils.assertEquals(log, "attachmentCode", BContentStream.ATTACHMENT, bstrm.AttachmentCode);

            log.info(")testHandoverStreamWithDeferedProperties");
        }
Esempio n. 2
0
        public void testRemoteStreamsFileStream()
        {
            log.info("testRemoteStreamsFileStream(");
            String   str  = "hallo";
            FileInfo file = new FileInfo(Path.GetTempFileName() + " € ß.txt");

            File.WriteAllText(file.FullName, str);
            BContentStream istrm = new BContentStreamWrapper(file.OpenRead(), "text/plain", file.Length);

            istrm.FileName = file.Name;
            remote.SetImage(istrm);
            BContentStream istrmR = (BContentStream)remote.GetImage();

            TestUtils.assertEquals(log, "Content-Type", "text/plain", istrmR.ContentType);
            TestUtils.assertEquals(log, "Content-Length", file.Length, istrmR.ContentLength);
            TestUtils.assertEquals(log, "FileName", file.Name, istrmR.FileName);

            ByteBuffer buf  = BWire.bufferFromStream(istrmR, false);
            String     strR = File.ReadAllText(file.FullName);

            TestUtils.assertEquals(log, "stream", str, strR);

            TestUtils.assertEquals(log, "Content-Type", "text/plain", istrmR.ContentType);
            TestUtils.assertEquals(log, "Content-Length", file.Length, istrmR.ContentLength);
            TestUtils.assertEquals(log, "FileName", file.Name, istrmR.FileName);

            file.Delete();
            log.info(")testRemoteStreamsFileStream");
        }
Esempio n. 3
0
        public static void assertEquals(Log log, String msg, Stream estrm, Stream rstrm)
        {
            if (estrm is BContentStream)
            {
                BContentStream ecs = (BContentStream)estrm;
                if (rstrm is BContentStream)
                {
                    BContentStream rcs = (BContentStream)rstrm;
                    assertEquals(log, msg + ".contentType", ecs.ContentType, rcs.ContentType);
                    assertEquals(log, msg + ".contentLength", ecs.ContentLength, rcs.ContentLength);
                }
            }

            byte[] ebuf = new byte[10 * 1000];
            byte[] rbuf = new byte[10 * 1000];
            int    n = 0, p = 0;

            do
            {
                n = estrm.Read(ebuf, 0, ebuf.Length);

                if (n == 0)
                {
                    int n2 = rstrm.Read(rbuf, 0, rbuf.Length);
                    TestUtils.assertEquals(log, msg + ". stream byte, p=" + p, n, n2);
                    break;
                }
                else
                {
                    int n2 = 0;
                    while (n2 < n)
                    {
                        int n3 = rstrm.Read(rbuf, n2, n - n2);
                        Assert.IsTrue(n3 > 0);
                        n2 += n3;
                    }

                    for (int i = 0; i < n; i++)
                    {
                        byte e = ebuf[i];
                        byte r = rbuf[i];
                        if (e != r)
                        {
                            TestUtils.assertEquals(log, msg + ". stream byte, p=" + p, e, r);
                        }
                        p++;
                    }
                }
            } while (n != 0);
        }