-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
52 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
using System; | ||
using System.IO; | ||
using Xunit; | ||
|
||
namespace Microsoft.Maui.Graphics.Tests; | ||
|
||
public class PlatformImageTests | ||
{ | ||
[Theory] | ||
[InlineData(true)] | ||
[InlineData(false)] | ||
public void PlatformImageFromStreamTest(bool seekable) | ||
{ | ||
byte[] orange1x1pxPngBytes = Convert.FromBase64String("iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVQIW2P4v5ThPwAG7wKklwQ/bwAAAABJRU5ErkJggg=="); | ||
using MemoryStream memoryStream = new(orange1x1pxPngBytes); | ||
Stream stream = seekable ? memoryStream : new NonSeekableReadOnlyStream(memoryStream); | ||
|
||
var image = Microsoft.Maui.Graphics.Platform.PlatformImage.FromStream(stream); | ||
|
||
Assert.NotNull(image); | ||
} | ||
|
||
private class NonSeekableReadOnlyStream(Stream stream) : Stream | ||
{ | ||
public override bool CanRead => stream.CanRead; | ||
|
||
public override bool CanSeek => false; | ||
|
||
public override bool CanWrite => false; | ||
|
||
public override long Length => throw new NotSupportedException(); | ||
|
||
public override long Position | ||
{ | ||
get { return stream.Position; } | ||
set { throw new NotSupportedException(); } | ||
} | ||
|
||
public override void Flush() => throw new NotSupportedException(); | ||
|
||
public override int Read(byte[] buffer, int offset, int count) | ||
{ | ||
return stream.Read(buffer, offset, count); | ||
} | ||
|
||
public override long Seek(long offset, SeekOrigin origin) => throw new NotSupportedException(); | ||
|
||
public override void SetLength(long value) => throw new NotSupportedException(); | ||
|
||
public override void Write(byte[] buffer, int offset, int count) => throw new NotSupportedException(); | ||
} | ||
} |