public void IsNonBlocking_InitializedStream_ReturnsTrue() { byte[] data = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; ByteArrayInputStream stream = ByteArrayInputStream.Create(data); Assert.AreEqual(true, stream.IsNonBlocking()); }
public void Available_InitializedStream_ReturnsNumberOfAvailableBytes() { byte[] data = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; ByteArrayInputStream stream = ByteArrayInputStream.Create(data); Assert.AreEqual(11, stream.Available()); }
public void Read_InitializedStream_ShouldReturnCorrectResults() { byte[] data = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; ByteArrayInputStream stream = ByteArrayInputStream.Create(data); IntPtr aBuf = Marshal.AllocCoTaskMem(1); // Read first byte stream.Read(aBuf, 1); byte result = Marshal.ReadByte(aBuf); Assert.AreEqual(0, result); // Read second byte. stream.Read(aBuf, 1); result = Marshal.ReadByte(aBuf); Assert.AreEqual(1, result); Marshal.FreeCoTaskMem(aBuf); }
protected void InternalLoadContent(string content, string url, string contentType) { if (!IsHandleCreated) { WpfExtensions.DoEvents(); } using (var sContentType = new nsACString(contentType)) using (var sUtf8 = new nsACString("UTF8")) { ByteArrayInputStream inputStream = null; try { inputStream = ByteArrayInputStream.Create(System.Text.Encoding.UTF8.GetBytes(content != null ? content : string.Empty)); var docShell = Xpcom.QueryInterface <nsIDocShell> (this.WebBrowser); nsIURI uri = null; if (!string.IsNullOrEmpty(url)) { uri = IOService.CreateNsIUri(url); } nsIDocShellLoadInfo l = null; if (true) { l = Xpcom.QueryInterface <nsIDocShellLoadInfo> (this.WebBrowser); docShell.CreateLoadInfo(ref l); l.SetLoadTypeAttribute(new IntPtr(16)); } docShell.LoadStream(inputStream, uri, sContentType, sUtf8, l); Marshal.ReleaseComObject(docShell); if (l != null) { Marshal.ReleaseComObject(l); } } finally { if (inputStream != null) { inputStream.Close(); } } } }