You've already forked linux-packaging-mono
Imported Upstream version 5.8.0.22
Former-commit-id: df344e34b07851d296efb3e6604c8db42b6f7aa3
This commit is contained in:
parent
5f4a27cc8a
commit
7d05485754
@@ -23,6 +23,10 @@ namespace System.Resources
|
||||
// of Initialize() and GetString() below.
|
||||
internal sealed class WindowsRuntimeResourceManager : WindowsRuntimeResourceManagerBase
|
||||
{
|
||||
// Setting invariant culture to Windows Runtime doesn't work because Windows Runtime expects language name in the form of BCP-47 tags while
|
||||
// invariant name is an empty string. We will use the private invariant culture name x-VL instead.
|
||||
private const string c_InvariantCulturePrivateName = "x-VL";
|
||||
|
||||
private ResourceMap _resourceMap;
|
||||
private ResourceContext _clonedResourceContext;
|
||||
private string _clonedResourceContextFallBackList;
|
||||
@@ -227,8 +231,26 @@ namespace System.Resources
|
||||
Debug.Assert(s_globalResourceContextFallBackList != null);
|
||||
Debug.Assert(s_globalResourceContext != null);
|
||||
|
||||
List<String> languages = new List<string>(s_globalResourceContext.Languages);
|
||||
IReadOnlyList<string> langs;
|
||||
|
||||
try
|
||||
{
|
||||
langs = s_globalResourceContext.Languages;
|
||||
}
|
||||
catch (ArgumentException)
|
||||
{
|
||||
// Sometimes Windows Runtime fails and we get Argument Exception which can fail fast the whole app
|
||||
// to avoid that we ignore the exception.
|
||||
return;
|
||||
}
|
||||
|
||||
List<String> languages = new List<string>(langs);
|
||||
|
||||
if (languages.Count > 0 && languages[0] == c_InvariantCulturePrivateName)
|
||||
{
|
||||
languages[0] = CultureInfo.InvariantCulture.Name;
|
||||
}
|
||||
|
||||
s_globalResourceContextBestFitCultureInfo = GetBestFitCultureFromLanguageList(languages);
|
||||
s_globalResourceContextFallBackList = ReadOnlyListToString(languages);
|
||||
}
|
||||
@@ -448,7 +470,7 @@ namespace System.Resources
|
||||
}
|
||||
|
||||
List<String> languages = new List<String>(s_globalResourceContext.Languages);
|
||||
languages.Insert(0, ci.Name);
|
||||
languages.Insert(0, ci.Name == CultureInfo.InvariantCulture.Name ? c_InvariantCulturePrivateName : ci.Name);
|
||||
|
||||
// remove any duplication in the list
|
||||
int i = languages.Count - 1;
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Specialized;
|
||||
using System.ComponentModel;
|
||||
using System.Diagnostics;
|
||||
@@ -474,16 +475,14 @@ namespace System.Runtime.InteropServices.WindowsRuntime
|
||||
EventHandler key,
|
||||
ConditionalWeakTable<EventHandler, EventHandler<object>>.CreateValueCallback callback)
|
||||
{
|
||||
EventHandler<object> value;
|
||||
|
||||
// Find the key in the table using a value check rather than an instance check.
|
||||
EventHandler existingKey = table.FindEquivalentKeyUnsafe(key, out value);
|
||||
if (existingKey == null)
|
||||
foreach (KeyValuePair<EventHandler, EventHandler<object>> item in table)
|
||||
{
|
||||
value = callback(key);
|
||||
table.Add(key, value);
|
||||
if (Object.Equals(item.Key, key))
|
||||
return item.Value;
|
||||
}
|
||||
|
||||
EventHandler<object> value = callback(key);
|
||||
table.Add(key, value);
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -76,18 +76,18 @@ namespace System.Runtime.InteropServices.WindowsRuntime
|
||||
|
||||
// This object handles IMarshal calls for us:
|
||||
[ThreadStatic]
|
||||
private static IMarshal s_winRtMarshalProxy = null;
|
||||
private static IMarshal t_winRtMarshalProxy = null;
|
||||
|
||||
private static void EnsureHasMarshalProxy()
|
||||
{
|
||||
if (s_winRtMarshalProxy != null)
|
||||
if (t_winRtMarshalProxy != null)
|
||||
return;
|
||||
|
||||
try
|
||||
{
|
||||
IMarshal proxy;
|
||||
Int32 hr = Interop.mincore.RoGetBufferMarshaler(out proxy);
|
||||
s_winRtMarshalProxy = proxy;
|
||||
t_winRtMarshalProxy = proxy;
|
||||
|
||||
if (hr != HResults.S_OK)
|
||||
{
|
||||
@@ -278,42 +278,42 @@ namespace System.Runtime.InteropServices.WindowsRuntime
|
||||
void IMarshal.DisconnectObject(UInt32 dwReserved)
|
||||
{
|
||||
EnsureHasMarshalProxy();
|
||||
s_winRtMarshalProxy.DisconnectObject(dwReserved);
|
||||
t_winRtMarshalProxy.DisconnectObject(dwReserved);
|
||||
}
|
||||
|
||||
|
||||
void IMarshal.GetMarshalSizeMax(ref Guid riid, IntPtr pv, UInt32 dwDestContext, IntPtr pvDestContext, UInt32 mshlflags, out UInt32 pSize)
|
||||
{
|
||||
EnsureHasMarshalProxy();
|
||||
s_winRtMarshalProxy.GetMarshalSizeMax(ref riid, pv, dwDestContext, pvDestContext, mshlflags, out pSize);
|
||||
t_winRtMarshalProxy.GetMarshalSizeMax(ref riid, pv, dwDestContext, pvDestContext, mshlflags, out pSize);
|
||||
}
|
||||
|
||||
|
||||
void IMarshal.GetUnmarshalClass(ref Guid riid, IntPtr pv, UInt32 dwDestContext, IntPtr pvDestContext, UInt32 mshlFlags, out Guid pCid)
|
||||
{
|
||||
EnsureHasMarshalProxy();
|
||||
s_winRtMarshalProxy.GetUnmarshalClass(ref riid, pv, dwDestContext, pvDestContext, mshlFlags, out pCid);
|
||||
t_winRtMarshalProxy.GetUnmarshalClass(ref riid, pv, dwDestContext, pvDestContext, mshlFlags, out pCid);
|
||||
}
|
||||
|
||||
|
||||
void IMarshal.MarshalInterface(IntPtr pStm, ref Guid riid, IntPtr pv, UInt32 dwDestContext, IntPtr pvDestContext, UInt32 mshlflags)
|
||||
{
|
||||
EnsureHasMarshalProxy();
|
||||
s_winRtMarshalProxy.MarshalInterface(pStm, ref riid, pv, dwDestContext, pvDestContext, mshlflags);
|
||||
t_winRtMarshalProxy.MarshalInterface(pStm, ref riid, pv, dwDestContext, pvDestContext, mshlflags);
|
||||
}
|
||||
|
||||
|
||||
void IMarshal.ReleaseMarshalData(IntPtr pStm)
|
||||
{
|
||||
EnsureHasMarshalProxy();
|
||||
s_winRtMarshalProxy.ReleaseMarshalData(pStm);
|
||||
t_winRtMarshalProxy.ReleaseMarshalData(pStm);
|
||||
}
|
||||
|
||||
|
||||
void IMarshal.UnmarshalInterface(IntPtr pStm, ref Guid riid, out IntPtr ppv)
|
||||
{
|
||||
EnsureHasMarshalProxy();
|
||||
s_winRtMarshalProxy.UnmarshalInterface(pStm, ref riid, out ppv);
|
||||
t_winRtMarshalProxy.UnmarshalInterface(pStm, ref riid, out ppv);
|
||||
}
|
||||
#endregion Implementation of IMarshal
|
||||
|
||||
|
||||
@@ -107,7 +107,6 @@ namespace System.Runtime.InteropServices.WindowsRuntime
|
||||
if (destination == null) throw new ArgumentNullException(nameof(destination));
|
||||
if (count < 0) throw new ArgumentOutOfRangeException(nameof(count));
|
||||
if (sourceIndex < 0) throw new ArgumentOutOfRangeException(nameof(sourceIndex));
|
||||
if (destinationIndex < 0) throw new ArgumentOutOfRangeException(nameof(destinationIndex));
|
||||
if (source.Length <= sourceIndex) throw new ArgumentException(SR.Argument_IndexOutOfArrayBounds, nameof(sourceIndex));
|
||||
if (source.Length - sourceIndex < count) throw new ArgumentException(SR.Argument_InsufficientArrayElementsAfterOffset);
|
||||
if (destination.Capacity - destinationIndex < count) throw new ArgumentException(SR.Argument_InsufficientSpaceInTargetBuffer);
|
||||
@@ -146,7 +145,6 @@ namespace System.Runtime.InteropServices.WindowsRuntime
|
||||
{
|
||||
if (source == null) throw new ArgumentNullException(nameof(source));
|
||||
if (count < 0) throw new ArgumentOutOfRangeException(nameof(count));
|
||||
if (sourceIndex < 0) throw new ArgumentOutOfRangeException(nameof(sourceIndex));
|
||||
if (source.Capacity <= sourceIndex) throw new ArgumentException(SR.Argument_BufferIndexExceedsCapacity);
|
||||
if (source.Capacity - sourceIndex < count) throw new ArgumentException(SR.Argument_InsufficientSpaceInSourceBuffer);
|
||||
Contract.EndContractBlock();
|
||||
@@ -181,7 +179,6 @@ namespace System.Runtime.InteropServices.WindowsRuntime
|
||||
if (source == null) throw new ArgumentNullException(nameof(source));
|
||||
if (destination == null) throw new ArgumentNullException(nameof(destination));
|
||||
if (count < 0) throw new ArgumentOutOfRangeException(nameof(count));
|
||||
if (sourceIndex < 0) throw new ArgumentOutOfRangeException(nameof(sourceIndex));
|
||||
if (destinationIndex < 0) throw new ArgumentOutOfRangeException(nameof(destinationIndex));
|
||||
if (source.Capacity <= sourceIndex) throw new ArgumentException(SR.Argument_BufferIndexExceedsCapacity);
|
||||
if (source.Capacity - sourceIndex < count) throw new ArgumentException(SR.Argument_InsufficientSpaceInSourceBuffer);
|
||||
@@ -223,9 +220,6 @@ namespace System.Runtime.InteropServices.WindowsRuntime
|
||||
{
|
||||
if (source == null) throw new ArgumentNullException(nameof(source));
|
||||
if (destination == null) throw new ArgumentNullException(nameof(destination));
|
||||
if (count < 0) throw new ArgumentOutOfRangeException(nameof(count));
|
||||
if (sourceIndex < 0) throw new ArgumentOutOfRangeException(nameof(sourceIndex));
|
||||
if (destinationIndex < 0) throw new ArgumentOutOfRangeException(nameof(destinationIndex));
|
||||
if (source.Capacity <= sourceIndex) throw new ArgumentException(SR.Argument_BufferIndexExceedsCapacity);
|
||||
if (source.Capacity - sourceIndex < count) throw new ArgumentException(SR.Argument_InsufficientSpaceInSourceBuffer);
|
||||
if (destination.Capacity <= destinationIndex) throw new ArgumentException(SR.Argument_BufferIndexExceedsCapacity);
|
||||
@@ -441,9 +435,6 @@ namespace System.Runtime.InteropServices.WindowsRuntime
|
||||
}
|
||||
|
||||
Int32 originInStream = streamData.Offset;
|
||||
|
||||
Debug.Assert(underlyingStream.Length <= Int32.MaxValue);
|
||||
|
||||
Int32 buffCapacity = Math.Min(length, underlyingStream.Capacity - positionInStream);
|
||||
Int32 buffLength = Math.Max(0, Math.Min(length, ((Int32)underlyingStream.Length) - positionInStream));
|
||||
return new WindowsRuntimeBuffer(streamData.Array, originInStream + positionInStream, buffLength, buffCapacity);
|
||||
@@ -485,7 +476,6 @@ namespace System.Runtime.InteropServices.WindowsRuntime
|
||||
public static Byte GetByte(this IBuffer source, UInt32 byteOffset)
|
||||
{
|
||||
if (source == null) throw new ArgumentNullException(nameof(source));
|
||||
if (byteOffset < 0) throw new ArgumentOutOfRangeException(nameof(byteOffset));
|
||||
if (source.Capacity <= byteOffset) throw new ArgumentException(SR.Argument_BufferIndexExceedsCapacity, nameof(byteOffset));
|
||||
|
||||
Contract.EndContractBlock();
|
||||
|
||||
@@ -20,6 +20,32 @@ using System.Diagnostics.Tracing;
|
||||
namespace System.Threading
|
||||
{
|
||||
#if FEATURE_APPX
|
||||
|
||||
[WindowsRuntimeImport]
|
||||
[Guid("DFA2DC9C-1A2D-4917-98F2-939AF1D6E0C8")]
|
||||
public delegate void DispatcherQueueHandler();
|
||||
|
||||
public enum DispatcherQueuePriority
|
||||
{
|
||||
Low = -10,
|
||||
Normal = 0,
|
||||
High = 10
|
||||
}
|
||||
|
||||
[ComImport]
|
||||
[WindowsRuntimeImport]
|
||||
[Guid("603E88E4-A338-4FFE-A457-A5CFB9CEB899")]
|
||||
internal interface IDispatcherQueue
|
||||
{
|
||||
// This returns a DispatcherQueueTimer but we don't use this method, so I
|
||||
// just made it 'object' to avoid declaring it.
|
||||
object CreateTimer();
|
||||
|
||||
bool TryEnqueue(DispatcherQueueHandler callback);
|
||||
|
||||
bool TryEnqueue(DispatcherQueuePriority priority, DispatcherQueueHandler callback);
|
||||
}
|
||||
|
||||
#region class WinRTSynchronizationContextFactory
|
||||
|
||||
[FriendAccessAllowed]
|
||||
@@ -32,28 +58,47 @@ namespace System.Threading
|
||||
// To accomplish this, we use a ConditionalWeakTable to track which instances of WinRTSynchronizationContext are bound
|
||||
// to each ICoreDispatcher instance.
|
||||
//
|
||||
private static readonly ConditionalWeakTable<CoreDispatcher, WinRTSynchronizationContext> s_contextCache =
|
||||
new ConditionalWeakTable<CoreDispatcher, WinRTSynchronizationContext>();
|
||||
private static readonly ConditionalWeakTable<CoreDispatcher, WinRTCoreDispatcherBasedSynchronizationContext> s_coreDispatcherContextCache =
|
||||
new ConditionalWeakTable<CoreDispatcher, WinRTCoreDispatcherBasedSynchronizationContext>();
|
||||
|
||||
private static readonly ConditionalWeakTable<IDispatcherQueue, WinRTDispatcherQueueBasedSynchronizationContext> s_dispatcherQueueContextCache =
|
||||
new ConditionalWeakTable<IDispatcherQueue, WinRTDispatcherQueueBasedSynchronizationContext>();
|
||||
|
||||
public override SynchronizationContext Create(object dispatcherObj)
|
||||
{
|
||||
Debug.Assert(dispatcherObj != null);
|
||||
Debug.Assert(dispatcherObj is CoreDispatcher || dispatcherObj is IDispatcherQueue);
|
||||
|
||||
//
|
||||
// Get the RCW for the dispatcher
|
||||
//
|
||||
CoreDispatcher dispatcher = (CoreDispatcher)dispatcherObj;
|
||||
if (dispatcherObj is CoreDispatcher)
|
||||
{
|
||||
//
|
||||
// Get the RCW for the dispatcher
|
||||
//
|
||||
CoreDispatcher dispatcher = (CoreDispatcher)dispatcherObj;
|
||||
|
||||
//
|
||||
// The dispatcher is supposed to belong to this thread
|
||||
//
|
||||
Debug.Assert(dispatcher == CoreWindow.GetForCurrentThread().Dispatcher);
|
||||
Debug.Assert(dispatcher.HasThreadAccess);
|
||||
//
|
||||
// The dispatcher is supposed to belong to this thread
|
||||
//
|
||||
Debug.Assert(dispatcher == CoreWindow.GetForCurrentThread().Dispatcher);
|
||||
Debug.Assert(dispatcher.HasThreadAccess);
|
||||
|
||||
//
|
||||
// Get the WinRTSynchronizationContext instance that represents this CoreDispatcher.
|
||||
//
|
||||
return s_contextCache.GetValue(dispatcher, _dispatcher => new WinRTSynchronizationContext(_dispatcher));
|
||||
//
|
||||
// Get the WinRTSynchronizationContext instance that represents this CoreDispatcher.
|
||||
//
|
||||
return s_coreDispatcherContextCache.GetValue(dispatcher, _dispatcher => new WinRTCoreDispatcherBasedSynchronizationContext(_dispatcher));
|
||||
}
|
||||
else // dispatcherObj is IDispatcherQueue
|
||||
{
|
||||
//
|
||||
// Get the RCW for the dispatcher
|
||||
//
|
||||
IDispatcherQueue dispatcherQueue = (IDispatcherQueue)dispatcherObj;
|
||||
|
||||
//
|
||||
// Get the WinRTSynchronizationContext instance that represents this IDispatcherQueue.
|
||||
//
|
||||
return s_dispatcherQueueContextCache.GetValue(dispatcherQueue, _dispatcherQueue => new WinRTDispatcherQueueBasedSynchronizationContext(_dispatcherQueue));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,18 +107,62 @@ namespace System.Threading
|
||||
|
||||
#region class WinRTSynchronizationContext
|
||||
|
||||
internal sealed class WinRTSynchronizationContext : SynchronizationContext
|
||||
internal sealed class WinRTCoreDispatcherBasedSynchronizationContext : WinRTSynchronizationContextBase
|
||||
{
|
||||
private readonly CoreDispatcher _dispatcher;
|
||||
|
||||
internal WinRTSynchronizationContext(CoreDispatcher dispatcher)
|
||||
internal WinRTCoreDispatcherBasedSynchronizationContext(CoreDispatcher dispatcher)
|
||||
{
|
||||
_dispatcher = dispatcher;
|
||||
}
|
||||
|
||||
[SecuritySafeCritical]
|
||||
public override void Post(SendOrPostCallback d, object state)
|
||||
{
|
||||
if (d == null)
|
||||
throw new ArgumentNullException("d");
|
||||
Contract.EndContractBlock();
|
||||
|
||||
var ignored = _dispatcher.RunAsync(CoreDispatcherPriority.Normal, new Invoker(d, state).Invoke);
|
||||
}
|
||||
|
||||
public override SynchronizationContext CreateCopy()
|
||||
{
|
||||
return new WinRTCoreDispatcherBasedSynchronizationContext(_dispatcher);
|
||||
}
|
||||
}
|
||||
|
||||
internal sealed class WinRTDispatcherQueueBasedSynchronizationContext : WinRTSynchronizationContextBase
|
||||
{
|
||||
private readonly IDispatcherQueue _dispatcherQueue;
|
||||
internal WinRTDispatcherQueueBasedSynchronizationContext(IDispatcherQueue dispatcherQueue)
|
||||
{
|
||||
_dispatcherQueue = dispatcherQueue;
|
||||
}
|
||||
|
||||
[SecuritySafeCritical]
|
||||
public override void Post(SendOrPostCallback d, object state)
|
||||
{
|
||||
if (d == null)
|
||||
throw new ArgumentNullException("d");
|
||||
Contract.EndContractBlock();
|
||||
|
||||
// We explicitly choose to ignore the return value here. This enqueue operation might fail if the
|
||||
// dispatcher queue was shut down before we got here. In that case, we choose to just move on and
|
||||
// pretend nothing happened.
|
||||
var ignored = _dispatcherQueue.TryEnqueue(DispatcherQueuePriority.Normal, new Invoker(d, state).Invoke);
|
||||
}
|
||||
|
||||
public override SynchronizationContext CreateCopy()
|
||||
{
|
||||
return new WinRTDispatcherQueueBasedSynchronizationContext(_dispatcherQueue);
|
||||
}
|
||||
}
|
||||
|
||||
internal abstract class WinRTSynchronizationContextBase : SynchronizationContext
|
||||
{
|
||||
#region class WinRTSynchronizationContext.Invoker
|
||||
|
||||
private class Invoker
|
||||
protected class Invoker
|
||||
{
|
||||
private readonly ExecutionContext _executionContext;
|
||||
private readonly SendOrPostCallback _callback;
|
||||
@@ -192,26 +281,11 @@ namespace System.Threading
|
||||
|
||||
#endregion class WinRTSynchronizationContext.Invoker
|
||||
|
||||
[SecuritySafeCritical]
|
||||
public override void Post(SendOrPostCallback d, object state)
|
||||
{
|
||||
if (d == null)
|
||||
throw new ArgumentNullException("d");
|
||||
Contract.EndContractBlock();
|
||||
|
||||
var ignored = _dispatcher.RunAsync(CoreDispatcherPriority.Normal, new Invoker(d, state).Invoke);
|
||||
}
|
||||
|
||||
[SecuritySafeCritical]
|
||||
public override void Send(SendOrPostCallback d, object state)
|
||||
{
|
||||
throw new NotSupportedException(SR.InvalidOperation_SendNotSupportedOnWindowsRTSynchronizationContext);
|
||||
}
|
||||
|
||||
public override SynchronizationContext CreateCopy()
|
||||
{
|
||||
return new WinRTSynchronizationContext(_dispatcher);
|
||||
}
|
||||
}
|
||||
#endregion class WinRTSynchronizationContext
|
||||
#endif //FEATURE_APPX
|
||||
|
||||
@@ -86,22 +86,6 @@ namespace Windows.Foundation
|
||||
}
|
||||
}
|
||||
|
||||
internal static Rect Create(double x,
|
||||
double y,
|
||||
double width,
|
||||
double height)
|
||||
{
|
||||
if (x == EmptyX && y == EmptyY && width == EmptyWidth && height == EmptyHeight)
|
||||
{
|
||||
return Rect.Empty;
|
||||
}
|
||||
else
|
||||
{
|
||||
return new Rect(x, y, width, height);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public double X
|
||||
{
|
||||
get { return _x; }
|
||||
@@ -313,7 +297,7 @@ namespace Windows.Foundation
|
||||
{
|
||||
if (IsEmpty)
|
||||
{
|
||||
return global::System.SR.DirectUI_Empty;
|
||||
return SR.DirectUI_Empty;
|
||||
}
|
||||
|
||||
// Helper to get the numeric list separator for a given culture.
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
<Directives xmlns="http://schemas.microsoft.com/netfx/2013/01/metadata">
|
||||
<Library>
|
||||
<!-- Needed because of WindowsRuntimeBuffer instance in [Theory] data which causes xunit to reflect on its ToString() -->
|
||||
<Type Name="System.Runtime.InteropServices.WindowsRuntime.WindowsRuntimeBuffer" Dynamic="Required Public" />
|
||||
</Library>
|
||||
</Directives>
|
||||
@@ -8,12 +8,24 @@
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'uap-Windows_NT-Debug|AnyCPU'" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'uap-Windows_NT-Release|AnyCPU'" />
|
||||
<ItemGroup>
|
||||
<Compile Include="System\IO\AsWinRTStreamTests.cs" />
|
||||
<Compile Include="System\IO\TestStreamProvider.cs" />
|
||||
<Compile Include="System\IO\StorageFileMock.cs" />
|
||||
<Compile Include="System\IO\CreateSafeFileHandleTests.cs" />
|
||||
<Compile Include="System\IO\StorageFolderMock.cs" />
|
||||
<Compile Include="System\IO\WriteOnlyStream.cs" />
|
||||
<Compile Include="System\Runtime\InteropServices\WindowsRuntimeBufferExtensionsTests.cs" />
|
||||
<Compile Include="System\Runtime\InteropServices\WindowsRuntimeBufferTests.cs" />
|
||||
<Compile Include="Windows\Foundation\PointTests.cs" />
|
||||
<Compile Include="Windows\Foundation\RectTests.cs" />
|
||||
<Compile Include="Windows\Foundation\SizeTests.cs" />
|
||||
<Compile Include="Windows\UI\ColorTests.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="Windows" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="Resources\$(AssemblyName).rd.xml" />
|
||||
</ItemGroup>
|
||||
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
|
||||
</Project>
|
||||
396
external/corefx/src/System.Runtime.WindowsRuntime/tests/System/IO/AsWinRTStreamTests.cs
vendored
Normal file
396
external/corefx/src/System.Runtime.WindowsRuntime/tests/System/IO/AsWinRTStreamTests.cs
vendored
Normal file
@@ -0,0 +1,396 @@
|
||||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices.WindowsRuntime;
|
||||
using System.Threading;
|
||||
using Windows.Foundation;
|
||||
using Windows.Storage.Streams;
|
||||
using Xunit;
|
||||
|
||||
namespace System.IO
|
||||
{
|
||||
public class AsWinRTStreamTests
|
||||
{
|
||||
[Fact]
|
||||
public static void AsInputStream_FromReadOnlyStream()
|
||||
{
|
||||
Stream managedStream = TestStreamProvider.CreateReadOnlyStream();
|
||||
using (IInputStream ins = managedStream.AsInputStream())
|
||||
{
|
||||
Assert.NotNull(ins);
|
||||
|
||||
// Adapting a read-only managed Stream to IOutputStream must throw a NotSupportedException
|
||||
Assert.Throws<NotSupportedException>(() => { IOutputStream outs = managedStream.AsOutputStream(); });
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public static void AsOutputStream_FromWriteOnlyStream()
|
||||
{
|
||||
Stream managedStream = TestStreamProvider.CreateWriteOnlyStream();
|
||||
using (IOutputStream outs = managedStream.AsOutputStream())
|
||||
{
|
||||
Assert.NotNull(outs);
|
||||
|
||||
// Adapting a write-only managed Stream to IInputStream must throw a NotSupportedException
|
||||
Assert.Throws<NotSupportedException>(() => { IInputStream ins = managedStream.AsInputStream(); });
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public static void AsInputStream_WrapsToSameInstance()
|
||||
{
|
||||
Stream managedStream = TestStreamProvider.CreateReadOnlyStream();
|
||||
using (IInputStream ins = managedStream.AsInputStream())
|
||||
{
|
||||
Assert.NotNull(ins);
|
||||
Assert.Same(ins, managedStream.AsInputStream());
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public static void AsOutputStream_WrapsToSameInstance()
|
||||
{
|
||||
Stream managedStream = TestStreamProvider.CreateWriteOnlyStream();
|
||||
using (IOutputStream outs = managedStream.AsOutputStream())
|
||||
{
|
||||
Assert.NotNull(outs);
|
||||
Assert.Same(outs, managedStream.AsOutputStream());
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public static void AsInputStream_RoundtripUnwrap()
|
||||
{
|
||||
// NetFx Stream -> IInputStream -> NetFx Stream -> roundtrip reference equality is preserved
|
||||
Stream managedStream = TestStreamProvider.CreateReadOnlyStream();
|
||||
using (IInputStream ins = managedStream.AsInputStream())
|
||||
{
|
||||
Assert.Same(managedStream, ins.AsStreamForRead());
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public static void AsOutputStream_RoundtripUnwrap()
|
||||
{
|
||||
// NetFx Stream -> IOutputStream -> NetFx Stream -> roundtrip reference equality is preserved
|
||||
Stream managedStream = TestStreamProvider.CreateWriteOnlyStream();
|
||||
using (IOutputStream outs = managedStream.AsOutputStream())
|
||||
{
|
||||
Assert.Same(managedStream, outs.AsStreamForWrite());
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public static void AsInputStream_Equal()
|
||||
{
|
||||
Stream stream = TestStreamProvider.CreateReadOnlyStream();
|
||||
|
||||
using (IInputStream insOne = stream.AsInputStream())
|
||||
using (IInputStream insTwo = stream.AsInputStream())
|
||||
{
|
||||
Assert.Equal(insOne, insTwo);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public static void AsInputStream_NotEqual()
|
||||
{
|
||||
Stream streamOne = TestStreamProvider.CreateReadOnlyStream();
|
||||
Stream streamTwo = TestStreamProvider.CreateReadOnlyStream();
|
||||
|
||||
Assert.NotEqual(streamOne, streamTwo);
|
||||
|
||||
using (IInputStream insOne = streamOne.AsInputStream())
|
||||
using (IInputStream insTwo = streamTwo.AsInputStream())
|
||||
{
|
||||
Assert.NotEqual(insOne, insTwo);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public static void AsOutputStream_Equal()
|
||||
{
|
||||
Stream stream = TestStreamProvider.CreateWriteOnlyStream();
|
||||
|
||||
using (IOutputStream outsOne = stream.AsOutputStream())
|
||||
using (IOutputStream outsTwo = stream.AsOutputStream())
|
||||
{
|
||||
Assert.Equal(outsOne, outsOne);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public static void AsOutputStream_NotEqual()
|
||||
{
|
||||
Stream streamOne = TestStreamProvider.CreateWriteOnlyStream();
|
||||
Stream streamTwo = TestStreamProvider.CreateWriteOnlyStream();
|
||||
|
||||
Assert.NotEqual(streamOne, streamTwo);
|
||||
|
||||
using (IOutputStream outsOne = streamOne.AsOutputStream())
|
||||
using (IOutputStream outsTwo = streamTwo.AsOutputStream())
|
||||
{
|
||||
Assert.NotEqual(outsOne, outsTwo);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public static void TestRead_MemoryStream_None()
|
||||
{
|
||||
DoTestRead(TestStreamProvider.CreateMemoryStreamAsInputStream, InputStreamOptions.None, mustInvokeProgressHandler: false, completesSynchronously: true);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public static void TestRead_MemoryStream_Partial()
|
||||
{
|
||||
DoTestRead(TestStreamProvider.CreateMemoryStreamAsInputStream, InputStreamOptions.Partial, mustInvokeProgressHandler: false, completesSynchronously: true);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public static void TestWrite_MemoryStream()
|
||||
{
|
||||
DoTestWrite(TestStreamProvider.CreateMemoryStream, mustInvokeProgressHandler: false);
|
||||
}
|
||||
|
||||
private static void DoTestRead(Func<IInputStream> createStreamFunc, InputStreamOptions inputStreamOptions, bool mustInvokeProgressHandler, bool completesSynchronously)
|
||||
{
|
||||
|
||||
IInputStream stream = createStreamFunc();
|
||||
IBuffer buffer = WindowsRuntimeBuffer.Create(TestStreamProvider.ModelStreamLength);
|
||||
|
||||
IAsyncOperationWithProgress<IBuffer, uint> readOp = stream.ReadAsync(buffer, (uint)TestStreamProvider.ModelStreamLength, inputStreamOptions);
|
||||
|
||||
if (completesSynchronously)
|
||||
{
|
||||
// New readOp for a stream where we know that reading is sycnhronous must have Status = Completed
|
||||
Assert.Equal(AsyncStatus.Completed, readOp.Status);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Note the race. By the tie we get here, the status of the op may be started or already completed.
|
||||
AsyncStatus readOpStatus = readOp.Status;
|
||||
Assert.True(readOpStatus == AsyncStatus.Completed || readOpStatus == AsyncStatus.Started, "New readOp must have Status = Started or Completed (race)");
|
||||
}
|
||||
|
||||
bool progressCallbackInvoked = false;
|
||||
bool completedCallbackInvoked = false;
|
||||
|
||||
uint readOpId = readOp.Id;
|
||||
EventWaitHandle waitHandle = new ManualResetEvent(false);
|
||||
|
||||
readOp.Progress = (asyncReadOp, bytesCompleted) =>
|
||||
{
|
||||
progressCallbackInvoked = true;
|
||||
|
||||
// asyncReadOp.Id in a progress callback must match the ID of the asyncReadOp to which the callback was assigned
|
||||
Assert.Equal(readOpId, asyncReadOp.Id);
|
||||
|
||||
// asyncReadOp.Status must be 'Started' for a asyncReadOp in progress
|
||||
Assert.Equal(AsyncStatus.Started, asyncReadOp.Status);
|
||||
|
||||
// bytesCompleted must be in range [0, maxBytesToRead] asyncReadOp in progress
|
||||
Assert.InRange(bytesCompleted, 0u, (uint)TestStreamProvider.ModelStreamLength);
|
||||
};
|
||||
|
||||
readOp.Completed = (asyncReadOp, passedStatus) =>
|
||||
{
|
||||
try
|
||||
{
|
||||
completedCallbackInvoked = true;
|
||||
|
||||
// asyncReadOp.Id in a completion callback must match the ID of the asyncReadOp to which the callback was assigned
|
||||
Assert.Equal(readOpId, asyncReadOp.Id);
|
||||
|
||||
// asyncReadOp.Status must match passedStatus for a completed asyncReadOp
|
||||
Assert.Equal(passedStatus, asyncReadOp.Status);
|
||||
|
||||
// asyncReadOp.Status must be 'Completed' for a completed asyncReadOp
|
||||
Assert.Equal(AsyncStatus.Completed, asyncReadOp.Status);
|
||||
|
||||
IBuffer resultBuffer = asyncReadOp.GetResults();
|
||||
|
||||
// asyncReadOp.GetResults() must not return null for a completed asyncReadOp
|
||||
Assert.NotNull(resultBuffer);
|
||||
|
||||
AssertExtensions.GreaterThan(resultBuffer.Capacity, 0u, "resultBuffer.Capacity should be more than zero in completed callback");
|
||||
AssertExtensions.GreaterThan(resultBuffer.Length, 0u, "resultBuffer.Length should be more than zero in completed callback");
|
||||
AssertExtensions.LessThanOrEqualTo(resultBuffer.Length, resultBuffer.Capacity, "resultBuffer.Length should be <= Capacity in completed callback");
|
||||
|
||||
if (inputStreamOptions == InputStreamOptions.None)
|
||||
{
|
||||
// resultBuffer.Length must be equal to requested number of bytes when an asyncReadOp with
|
||||
// InputStreamOptions.None completes successfully
|
||||
Assert.Equal(resultBuffer.Length, (uint)TestStreamProvider.ModelStreamLength);
|
||||
}
|
||||
|
||||
if (inputStreamOptions == InputStreamOptions.Partial)
|
||||
{
|
||||
AssertExtensions.LessThanOrEqualTo(resultBuffer.Length, (uint)TestStreamProvider.ModelStreamLength,
|
||||
"resultBuffer.Length must be <= requested number of bytes with InputStreamOptions.Partial in completed callback");
|
||||
}
|
||||
buffer = resultBuffer;
|
||||
}
|
||||
finally
|
||||
{
|
||||
waitHandle.Set();
|
||||
}
|
||||
};
|
||||
|
||||
// Now, let's block until the read op is complete.
|
||||
// We speculate that it will complete within 3500 msec, although under high load it may not be.
|
||||
// If the test fails we should use a better way to determine if callback is really not invoked, or if it's just too slow.
|
||||
waitHandle.WaitOne(500);
|
||||
waitHandle.WaitOne(1000);
|
||||
waitHandle.WaitOne(2000);
|
||||
|
||||
if (mustInvokeProgressHandler)
|
||||
{
|
||||
Assert.True(progressCallbackInvoked,
|
||||
"Progress callback specified to ReadAsync callback must be invoked when reading from this kind of stream");
|
||||
}
|
||||
|
||||
Assert.True(completedCallbackInvoked,
|
||||
"Completion callback specified to ReadAsync callback must be invoked");
|
||||
|
||||
// readOp.Status must be 'Completed' for a completed async readOp
|
||||
Assert.Equal(AsyncStatus.Completed, readOp.Status);
|
||||
|
||||
AssertExtensions.GreaterThan(buffer.Capacity, 0u, "buffer.Capacity should be greater than zero bytes");
|
||||
AssertExtensions.GreaterThan(buffer.Length, 0u, "buffer.Length should be greater than zero bytes");
|
||||
AssertExtensions.LessThanOrEqualTo(buffer.Length, buffer.Capacity, "buffer.Length <= buffer.Capacity is required for a completed async readOp");
|
||||
|
||||
if (inputStreamOptions == InputStreamOptions.None)
|
||||
{
|
||||
// buffer.Length must be equal to requested number of bytes when an async readOp with
|
||||
// InputStreamOptions.None completes successfully
|
||||
Assert.Equal((uint)TestStreamProvider.ModelStreamLength, buffer.Length);
|
||||
}
|
||||
|
||||
if (inputStreamOptions == InputStreamOptions.Partial)
|
||||
{
|
||||
AssertExtensions.LessThanOrEqualTo(buffer.Length, (uint)TestStreamProvider.ModelStreamLength,
|
||||
"resultBuffer.Length must be <= requested number of bytes with InputStreamOptions.Partial");
|
||||
}
|
||||
|
||||
byte[] results = new byte[buffer.Length];
|
||||
buffer.CopyTo(0, results, 0, (int)buffer.Length);
|
||||
|
||||
Assert.True(TestStreamProvider.CheckContent(results, 0, (int)buffer.Length),
|
||||
"Result data returned from AsyncRead must be the same as expected from the test data source");
|
||||
}
|
||||
|
||||
private static void DoTestWrite(Func<Stream> createStreamFunc, bool mustInvokeProgressHandler)
|
||||
{
|
||||
Stream backingStream = createStreamFunc();
|
||||
using (IOutputStream stream = backingStream.AsOutputStream())
|
||||
{
|
||||
// Create test data
|
||||
Random rnd = new Random(20100720); // Must be a different seed than used for TestStreamProvider.ModelStreamContents
|
||||
byte[] modelWriteData = new byte[0xA000];
|
||||
rnd.NextBytes(modelWriteData);
|
||||
|
||||
// Start test
|
||||
|
||||
IBuffer buffer = modelWriteData.AsBuffer();
|
||||
|
||||
// ibuffer.Length for IBuffer created by Array.ToBuffer(void) must equal to array.Length
|
||||
Assert.Equal((uint)modelWriteData.Length, buffer.Length);
|
||||
|
||||
// ibuffer.Capacity for IBuffer created by Array.ToBuffer(void) must equal to array.Length
|
||||
Assert.Equal((uint)modelWriteData.Length, buffer.Capacity);
|
||||
|
||||
IAsyncOperationWithProgress<uint, uint> writeOp = stream.WriteAsync(buffer);
|
||||
|
||||
// Note the race. By the tie we get here, the status of the op may be started or already completed.
|
||||
AsyncStatus writeOpStatus = writeOp.Status;
|
||||
Assert.True(writeOpStatus == AsyncStatus.Completed || writeOpStatus == AsyncStatus.Started, "New writeOp must have Status = Started or Completed (race)");
|
||||
|
||||
uint writeOpId = writeOp.Id;
|
||||
bool progressCallbackInvoked = false;
|
||||
bool completedCallbackInvoked = false;
|
||||
uint resultBytesWritten = 0;
|
||||
|
||||
EventWaitHandle waitHandle = new ManualResetEvent(false);
|
||||
|
||||
writeOp.Progress = (asyncWriteOp, bytesCompleted) =>
|
||||
{
|
||||
progressCallbackInvoked = true;
|
||||
|
||||
// asyncWriteOp.Id in a progress callback must match the ID of the asyncWriteOp to which the callback was assigned
|
||||
Assert.Equal(writeOpId, asyncWriteOp.Id);
|
||||
|
||||
// asyncWriteOp.Status must be 'Started' for a asyncWriteOp in progress
|
||||
Assert.Equal(AsyncStatus.Started, asyncWriteOp.Status);
|
||||
|
||||
// bytesCompleted must be in range [0, maxBytesToWrite] asyncWriteOp in progress
|
||||
Assert.InRange(bytesCompleted, 0u, (uint)TestStreamProvider.ModelStreamLength);
|
||||
};
|
||||
|
||||
writeOp.Completed = (asyncWriteOp, passedStatus) =>
|
||||
{
|
||||
try
|
||||
{
|
||||
completedCallbackInvoked = true;
|
||||
|
||||
// asyncWriteOp.Id in a completion callback must match the ID of the asyncWriteOp to which the callback was assigned
|
||||
Assert.Equal(writeOpId, asyncWriteOp.Id);
|
||||
|
||||
// asyncWriteOp.Status must match passedStatus for a completed asyncWriteOp
|
||||
Assert.Equal(passedStatus, asyncWriteOp.Status);
|
||||
|
||||
// asyncWriteOp.Status must be 'Completed' for a completed asyncWriteOp
|
||||
Assert.Equal(AsyncStatus.Completed, asyncWriteOp.Status);
|
||||
|
||||
uint bytesWritten = asyncWriteOp.GetResults();
|
||||
|
||||
// asyncWriteOp.GetResults() must return that all required bytes were written for a completed asyncWriteOp
|
||||
Assert.Equal((uint)modelWriteData.Length, bytesWritten);
|
||||
|
||||
resultBytesWritten = bytesWritten;
|
||||
}
|
||||
finally
|
||||
{
|
||||
waitHandle.Set();
|
||||
}
|
||||
};
|
||||
|
||||
// Now, let's block until the write op is complete.
|
||||
// We speculate that it will complete within 3500 msec, although under high load it may not be.
|
||||
// If the test fails we should use a better way to determine if callback is really not invoked, or if it's just too slow.
|
||||
waitHandle.WaitOne(500);
|
||||
waitHandle.WaitOne(1000);
|
||||
waitHandle.WaitOne(2000);
|
||||
|
||||
if (mustInvokeProgressHandler)
|
||||
{
|
||||
Assert.True(progressCallbackInvoked,
|
||||
"Progress callback specified to WriteAsync callback must be invoked when reading from this kind of stream");
|
||||
}
|
||||
|
||||
Assert.True(completedCallbackInvoked, "Completion callback specified to WriteAsync callback must be invoked");
|
||||
|
||||
// writeOp.Status must be 'Completed' for a completed async writeOp
|
||||
Assert.Equal(AsyncStatus.Completed, writeOp.Status);
|
||||
|
||||
// writeOp.GetResults() must return that all required bytes were written for a completed async writeOp
|
||||
Assert.Equal((uint)modelWriteData.Length, resultBytesWritten);
|
||||
|
||||
// Check contents
|
||||
|
||||
backingStream.Seek(0, SeekOrigin.Begin);
|
||||
byte[] verifyBuff = new byte[modelWriteData.Length + 1024];
|
||||
|
||||
int r = backingStream.Read(verifyBuff, 0, verifyBuff.Length);
|
||||
|
||||
for (int i = 0; i < modelWriteData.Length; i++)
|
||||
{
|
||||
Assert.Equal(modelWriteData[i], verifyBuff[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,28 +15,28 @@ namespace System.IO
|
||||
public void NullStorageFile_ThrowsArgumentNull()
|
||||
{
|
||||
IStorageFile file = null;
|
||||
Assert.Throws<ArgumentNullException>("windowsRuntimeFile", () => file.CreateSafeFileHandle());
|
||||
AssertExtensions.Throws<ArgumentNullException>("windowsRuntimeFile", () => file.CreateSafeFileHandle());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void FromStorageFile_BadAccessThrowsOutOfRange()
|
||||
{
|
||||
IStorageFile file = new StorageFileMock();
|
||||
Assert.Throws<ArgumentOutOfRangeException>("access", () => file.CreateSafeFileHandle((FileAccess)100));
|
||||
AssertExtensions.Throws<ArgumentOutOfRangeException>("access", () => file.CreateSafeFileHandle((FileAccess)100));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void FromStorageFile_BadSharingThrowsOutOfRange()
|
||||
{
|
||||
IStorageFile file = new StorageFileMock();
|
||||
Assert.Throws<ArgumentOutOfRangeException>("share", () => file.CreateSafeFileHandle(FileAccess.ReadWrite, (FileShare)100));
|
||||
AssertExtensions.Throws<ArgumentOutOfRangeException>("share", () => file.CreateSafeFileHandle(FileAccess.ReadWrite, (FileShare)100));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void FromStorageFile_BadOptionsThrowsOutOfRange()
|
||||
{
|
||||
IStorageFile file = new StorageFileMock();
|
||||
Assert.Throws<ArgumentOutOfRangeException>("options", () => file.CreateSafeFileHandle(FileAccess.ReadWrite, FileShare.Read, (FileOptions)100));
|
||||
AssertExtensions.Throws<ArgumentOutOfRangeException>("options", () => file.CreateSafeFileHandle(FileAccess.ReadWrite, FileShare.Read, (FileOptions)100));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -65,42 +65,42 @@ namespace System.IO
|
||||
public void NullStorageFolder_ThrowsArgumentNull()
|
||||
{
|
||||
IStorageFolder folder = null;
|
||||
Assert.Throws<ArgumentNullException>("rootDirectory", () => folder.CreateSafeFileHandle("foo", FileMode.OpenOrCreate));
|
||||
AssertExtensions.Throws<ArgumentNullException>("rootDirectory", () => folder.CreateSafeFileHandle("foo", FileMode.OpenOrCreate));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void NullStorageFolder_ThrowsArgumentNull2()
|
||||
{
|
||||
IStorageFolder folder = null;
|
||||
Assert.Throws<ArgumentNullException>("rootDirectory", () => folder.CreateSafeFileHandle("foo", FileMode.OpenOrCreate, FileAccess.Write));
|
||||
AssertExtensions.Throws<ArgumentNullException>("rootDirectory", () => folder.CreateSafeFileHandle("foo", FileMode.OpenOrCreate, FileAccess.Write));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void FromStorageFolder_BadModeThrowsOutOfRange()
|
||||
{
|
||||
IStorageFolder folder = new StorageFolderMock();
|
||||
Assert.Throws<ArgumentOutOfRangeException>("mode", () => folder.CreateSafeFileHandle("Foo", (FileMode)100));
|
||||
AssertExtensions.Throws<ArgumentOutOfRangeException>("mode", () => folder.CreateSafeFileHandle("Foo", (FileMode)100));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void FromStorageFolder_BadAccessThrowsOutOfRange()
|
||||
{
|
||||
IStorageFolder folder = new StorageFolderMock();
|
||||
Assert.Throws<ArgumentOutOfRangeException>("access", () => folder.CreateSafeFileHandle("Foo", FileMode.OpenOrCreate, (FileAccess)100));
|
||||
AssertExtensions.Throws<ArgumentOutOfRangeException>("access", () => folder.CreateSafeFileHandle("Foo", FileMode.OpenOrCreate, (FileAccess)100));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void FromStorageFolder_BadSharingThrowsOutOfRange()
|
||||
{
|
||||
IStorageFolder folder = new StorageFolderMock();
|
||||
Assert.Throws<ArgumentOutOfRangeException>("share", () => folder.CreateSafeFileHandle("Foo", FileMode.OpenOrCreate, FileAccess.ReadWrite, (FileShare)100));
|
||||
AssertExtensions.Throws<ArgumentOutOfRangeException>("share", () => folder.CreateSafeFileHandle("Foo", FileMode.OpenOrCreate, FileAccess.ReadWrite, (FileShare)100));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void FromStorageFolder_BadOptionsThrowsOutOfRange()
|
||||
{
|
||||
IStorageFolder folder = new StorageFolderMock();
|
||||
Assert.Throws<ArgumentOutOfRangeException>("options", () => folder.CreateSafeFileHandle("Foo", FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.Read, (FileOptions)100));
|
||||
AssertExtensions.Throws<ArgumentOutOfRangeException>("options", () => folder.CreateSafeFileHandle("Foo", FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.Read, (FileOptions)100));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
||||
112
external/corefx/src/System.Runtime.WindowsRuntime/tests/System/IO/TestStreamProvider.cs
vendored
Normal file
112
external/corefx/src/System.Runtime.WindowsRuntime/tests/System/IO/TestStreamProvider.cs
vendored
Normal file
@@ -0,0 +1,112 @@
|
||||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using Windows.Storage.Streams;
|
||||
|
||||
namespace System.IO
|
||||
{
|
||||
public class TestStreamProvider
|
||||
{
|
||||
private const string TempFileNameBase = @"WinRT.Testing.IO.Streams.NetFxStreamProvider.DataFile";
|
||||
private const string TempFileNameExt = @".tmp";
|
||||
private const string TempFileName = TempFileNameBase + TempFileNameExt;
|
||||
|
||||
private static byte[] s_modelStreamContents = null;
|
||||
private static int s_modelStreamLength = 0x100000;
|
||||
|
||||
private static readonly string s_tempFileFolder;
|
||||
private static readonly string s_tempFilePath;
|
||||
|
||||
static TestStreamProvider()
|
||||
{
|
||||
s_tempFileFolder = ".";
|
||||
s_tempFilePath = Path.Combine(s_tempFileFolder, TempFileName);
|
||||
}
|
||||
|
||||
public static byte[] ModelStreamContents
|
||||
{
|
||||
get
|
||||
{
|
||||
if (s_modelStreamContents != null)
|
||||
return s_modelStreamContents;
|
||||
|
||||
const int randomSeed = 20090918;
|
||||
|
||||
Random rnd = new Random(randomSeed);
|
||||
s_modelStreamContents = new byte[ModelStreamLength];
|
||||
rnd.NextBytes(s_modelStreamContents);
|
||||
|
||||
return s_modelStreamContents;
|
||||
}
|
||||
}
|
||||
|
||||
public static int ModelStreamLength
|
||||
{
|
||||
get
|
||||
{
|
||||
return s_modelStreamLength;
|
||||
}
|
||||
set
|
||||
{
|
||||
s_modelStreamContents = null;
|
||||
s_modelStreamLength = value;
|
||||
}
|
||||
}
|
||||
|
||||
public static bool CheckContent(byte[] values, int offsInModelContents, int count)
|
||||
{
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
|
||||
if (!CheckContent(values[i], i + offsInModelContents))
|
||||
{
|
||||
|
||||
Console.WriteLine("Fail on {0}, {1}, {2}, {3}", i, i + offsInModelContents, values[i], ModelStreamContents[i + offsInModelContents]);
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static bool CheckContent(byte value, int index)
|
||||
{
|
||||
return value == ModelStreamContents[index];
|
||||
}
|
||||
|
||||
public static MemoryStream CreateMemoryStream()
|
||||
{
|
||||
byte[] data = new byte[ModelStreamLength];
|
||||
Array.Copy(ModelStreamContents, data, data.Length);
|
||||
|
||||
MemoryStream stream = new MemoryStream(data, 0, data.Length, true);
|
||||
return stream;
|
||||
}
|
||||
|
||||
public static Stream CreateReadOnlyStream()
|
||||
{
|
||||
byte[] data = new byte[ModelStreamLength];
|
||||
Array.Copy(ModelStreamContents, data, data.Length);
|
||||
|
||||
MemoryStream stream = new MemoryStream(data, 0, data.Length, false);
|
||||
return stream;
|
||||
}
|
||||
|
||||
public static Stream CreateWriteOnlyStream()
|
||||
{
|
||||
byte[] data = new byte[ModelStreamLength];
|
||||
Array.Copy(ModelStreamContents, data, data.Length);
|
||||
|
||||
MemoryStream stream = new WriteOnlyStream(data);
|
||||
return stream;
|
||||
}
|
||||
|
||||
public static IInputStream CreateMemoryStreamAsInputStream()
|
||||
{
|
||||
MemoryStream memStream = CreateMemoryStream();
|
||||
return memStream.AsInputStream();
|
||||
}
|
||||
}
|
||||
}
|
||||
16
external/corefx/src/System.Runtime.WindowsRuntime/tests/System/IO/WriteOnlyStream.cs
vendored
Normal file
16
external/corefx/src/System.Runtime.WindowsRuntime/tests/System/IO/WriteOnlyStream.cs
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
namespace System.IO
|
||||
{
|
||||
public class WriteOnlyStream : MemoryStream
|
||||
{
|
||||
internal WriteOnlyStream(byte[] data) : base(data, 0, data.Length, true) { }
|
||||
public override bool CanRead { get { return false; } }
|
||||
public override int Read(byte[] buffer, int offset, int count) { throw new NotSupportedException("This is a write-only stream"); }
|
||||
public override int ReadByte() { throw new NotSupportedException("This is a write-only stream"); }
|
||||
public override byte[] ToArray() { throw new NotSupportedException("This is a write-only stream"); }
|
||||
public override void WriteTo(Stream stream) { throw new NotSupportedException("This is a write-only stream"); }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,463 @@
|
||||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using Windows.Storage.Streams;
|
||||
using Xunit;
|
||||
|
||||
namespace System.Runtime.InteropServices.WindowsRuntime.Tests
|
||||
{
|
||||
public class WindowsRuntimeBufferExtensionsTests
|
||||
{
|
||||
public static IEnumerable<object[]> AsBuffer_TestData()
|
||||
{
|
||||
yield return new object[] { new byte[0], 0, 0, 0 };
|
||||
yield return new object[] { new byte[] { 1, 2, 3 }, 2, 0, 0 };
|
||||
yield return new object[] { new byte[] { 1, 2, 3 }, 2, 0, 1 };
|
||||
yield return new object[] { new byte[] { 1, 2, 3 }, 0, 3, 3 };
|
||||
yield return new object[] { new byte[] { 1, 2, 3 }, 1, 2, 2 };
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(AsBuffer_TestData))]
|
||||
public void AsBuffer_Buffer_ReturnsExpected(byte[] source, int offset, int length, int capacity)
|
||||
{
|
||||
if (capacity == length)
|
||||
{
|
||||
if (offset == 0 && length == source.Length)
|
||||
{
|
||||
Verify(WindowsRuntimeBufferExtensions.AsBuffer(source), source, offset, length, capacity);
|
||||
}
|
||||
|
||||
Verify(WindowsRuntimeBufferExtensions.AsBuffer(source, offset, length), source, offset, length, capacity);
|
||||
}
|
||||
|
||||
Verify(WindowsRuntimeBufferExtensions.AsBuffer(source, offset, length, capacity), source, offset, length, capacity);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AsBuffer_NullBuffer_ThrowsArgumentNullException()
|
||||
{
|
||||
AssertExtensions.Throws<ArgumentNullException>("source", () => WindowsRuntimeBufferExtensions.AsBuffer(null));
|
||||
AssertExtensions.Throws<ArgumentNullException>("source", () => WindowsRuntimeBufferExtensions.AsBuffer(null, 0, 0));
|
||||
AssertExtensions.Throws<ArgumentNullException>("source", () => WindowsRuntimeBufferExtensions.AsBuffer(null, 0, 0, 0));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AsBuffer_NegativeOffset_ThrowsArgumentOutOfRangeException()
|
||||
{
|
||||
AssertExtensions.Throws<ArgumentOutOfRangeException>("offset", () => WindowsRuntimeBufferExtensions.AsBuffer(new byte[0], -1, 0));
|
||||
AssertExtensions.Throws<ArgumentOutOfRangeException>("offset", () => WindowsRuntimeBufferExtensions.AsBuffer(new byte[0], -1, 0, 0));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AsBuffer_NegativeLength_ThrowsArgumentOutOfRangeException()
|
||||
{
|
||||
AssertExtensions.Throws<ArgumentOutOfRangeException>("length", () => WindowsRuntimeBufferExtensions.AsBuffer(new byte[0], 0, -1));
|
||||
AssertExtensions.Throws<ArgumentOutOfRangeException>("length", () => WindowsRuntimeBufferExtensions.AsBuffer(new byte[0], 0, -1, 0));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(new byte[0], 0, 1, 0)]
|
||||
[InlineData(new byte[0], 1, 0, 0)]
|
||||
[InlineData(new byte[] { 0, 0 }, 1, 2, 0)]
|
||||
[InlineData(new byte[] { 0, 0 }, int.MaxValue, 0, 0)]
|
||||
[InlineData(new byte[] { 0, 0 }, 0, 0, 3)]
|
||||
[InlineData(new byte[] { 0, 0 }, 0, 0, int.MaxValue)]
|
||||
[InlineData(new byte[] { 0, 0 }, 0, 2, 1)]
|
||||
public void AsBuffer_InvalidOffsetLengthCapacity_ThrowsArgumentException(byte[] data, int offset, int length, int capacity)
|
||||
{
|
||||
if (capacity == 0)
|
||||
{
|
||||
AssertExtensions.Throws<ArgumentException>(null, () => WindowsRuntimeBufferExtensions.AsBuffer(data, offset, length));
|
||||
}
|
||||
|
||||
AssertExtensions.Throws<ArgumentException>(null, () => WindowsRuntimeBufferExtensions.AsBuffer(data, offset, length, capacity));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AsBuffer_NegativeCapacity_ThrowsArgumentOutOfRangeException()
|
||||
{
|
||||
AssertExtensions.Throws<ArgumentOutOfRangeException>("capacity", () => WindowsRuntimeBufferExtensions.AsBuffer(new byte[0], 0, 0, -1));
|
||||
}
|
||||
|
||||
public static IEnumerable<object[]> AsStream_TestData()
|
||||
{
|
||||
yield return new object[] { new byte[0].AsBuffer(), new byte[0] };
|
||||
yield return new object[] { new byte[] { 1, 2, 3 }.AsBuffer(), new byte[] { 1, 2, 3 } };
|
||||
yield return new object[] { new byte[] { 1, 2, 3 }.AsBuffer(1, 2), new byte[] { 2, 3 } };
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(AsStream_TestData))]
|
||||
public void AsStream_Buffer_Success(IBuffer buffer, byte[] expected)
|
||||
{
|
||||
using (MemoryStream stream = (MemoryStream)buffer.AsStream())
|
||||
{
|
||||
Assert.Equal(expected.Length, stream.Length);
|
||||
Assert.True(stream.CanWrite);
|
||||
|
||||
Assert.Equal(expected, stream.ToArray());
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AsStream_NullBuffer_ThrowsArgumentNullException()
|
||||
{
|
||||
AssertExtensions.Throws<ArgumentNullException>("source", () => WindowsRuntimeBufferExtensions.AsStream(null));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AsStream_CustomBuffer_ThrowsInvalidCastException()
|
||||
{
|
||||
Assert.Throws<InvalidCastException>(() => WindowsRuntimeBufferExtensions.AsStream(new CustomBuffer()));
|
||||
}
|
||||
|
||||
public static IEnumerable<object[]> CopyTo_TestData()
|
||||
{
|
||||
yield return new object[] { new byte[] { 1, 2, 3 }, 0, new byte[] { 2, 3, 4 }, 0, 3, new byte[] { 1, 2, 3 } };
|
||||
yield return new object[] { new byte[] { 1, 2, 3, 4, 5 }, 3, new byte[] { 255, 254, 253, 252 }, 2, 1, new byte[] { 255, 254, 4, 252 } };
|
||||
yield return new object[] { new byte[] { 1, 2, 3, 4, 5 }, 0, new byte[] { 255, 254, 253, 252 }, 0, 0, new byte[] { 255, 254, 253, 252 } };
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(CopyTo_TestData))]
|
||||
public void CopyTo_Buffer_Success(byte[] source, int sourceIndex, byte[] destination, int destinationIndex, int count, byte[] expected)
|
||||
{
|
||||
byte[] Clone(byte[] array) => (byte[])array.Clone();
|
||||
IBuffer Buffer(byte[] array) => Clone(array).AsBuffer();
|
||||
|
||||
if (sourceIndex == 0 && destinationIndex == 0 && count == source.Length)
|
||||
{
|
||||
// CopyTo(byte[], IBuffer)
|
||||
byte[] source1 = Clone(source);
|
||||
IBuffer destination1 = Buffer(destination);
|
||||
WindowsRuntimeBufferExtensions.CopyTo(source1, destination1);
|
||||
Assert.Equal(expected, destination1.ToArray());
|
||||
|
||||
// CopyTo(IBuffer, byte[])
|
||||
IBuffer source2 = Buffer(source);
|
||||
byte[] destination2 = Clone(destination);
|
||||
WindowsRuntimeBufferExtensions.CopyTo(source2, destination2);
|
||||
Assert.Equal(expected, destination2);
|
||||
|
||||
// CopyTo(IBuffer, IBuffer)
|
||||
IBuffer source3 = Buffer(source);
|
||||
IBuffer destination3 = Buffer(destination);
|
||||
WindowsRuntimeBufferExtensions.CopyTo(source3, destination3);
|
||||
Assert.Equal(expected, destination3.ToArray());
|
||||
}
|
||||
|
||||
// CopyTo(byte[], int, IBuffer, int, int)
|
||||
byte[] source4 = Clone(source);
|
||||
IBuffer destination4 = Buffer(destination);
|
||||
WindowsRuntimeBufferExtensions.CopyTo(source4, sourceIndex, destination4, (uint)destinationIndex, count);
|
||||
Assert.Equal(expected, destination4.ToArray());
|
||||
|
||||
// CopyTo(IBuffer, int, byte[], int, int)
|
||||
IBuffer source5 = Buffer(source);
|
||||
byte[] destination5 = Clone(destination);
|
||||
WindowsRuntimeBufferExtensions.CopyTo(source5, (uint)sourceIndex, destination5, destinationIndex, count);
|
||||
Assert.Equal(expected, destination5);
|
||||
|
||||
// CopyTo(IBuffer, int, IBuffer, int, int)
|
||||
IBuffer source6 = Buffer(source);
|
||||
IBuffer destination6 = Buffer(destination);
|
||||
WindowsRuntimeBufferExtensions.CopyTo(source6, (uint)sourceIndex, destination6, (uint)destinationIndex, (uint)count);
|
||||
Assert.Equal(expected, destination6.ToArray());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CopyTo_NullSource_ThrowsArgumentNullException()
|
||||
{
|
||||
IBuffer buffer = WindowsRuntimeBufferExtensions.AsBuffer(new byte[0]);
|
||||
AssertExtensions.Throws<ArgumentNullException>("source", () => WindowsRuntimeBufferExtensions.CopyTo((byte[])null, buffer));
|
||||
AssertExtensions.Throws<ArgumentNullException>("source", () => WindowsRuntimeBufferExtensions.CopyTo(null, new byte[0]));
|
||||
AssertExtensions.Throws<ArgumentNullException>("source", () => WindowsRuntimeBufferExtensions.CopyTo((IBuffer)null, buffer));
|
||||
AssertExtensions.Throws<ArgumentNullException>("source", () => WindowsRuntimeBufferExtensions.CopyTo(null, 0, buffer, 0, 0));
|
||||
AssertExtensions.Throws<ArgumentNullException>("source", () => WindowsRuntimeBufferExtensions.CopyTo(null, 0, new byte[0], 0, 0));
|
||||
AssertExtensions.Throws<ArgumentNullException>("source", () => WindowsRuntimeBufferExtensions.CopyTo((IBuffer)null, 0, buffer, 0, 0));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CopyTo_NullDestination_ThrowsArgumentNullException()
|
||||
{
|
||||
IBuffer buffer = WindowsRuntimeBufferExtensions.AsBuffer(new byte[0]);
|
||||
AssertExtensions.Throws<ArgumentNullException>("destination", () => WindowsRuntimeBufferExtensions.CopyTo(new byte[0], null));
|
||||
AssertExtensions.Throws<ArgumentNullException>("destination", () => WindowsRuntimeBufferExtensions.CopyTo(buffer, (IBuffer)null));
|
||||
AssertExtensions.Throws<ArgumentNullException>("destination", () => WindowsRuntimeBufferExtensions.CopyTo(buffer, (byte[])null));
|
||||
AssertExtensions.Throws<ArgumentNullException>("destination", () => WindowsRuntimeBufferExtensions.CopyTo(new byte[0], 0, null, 0, 0));
|
||||
AssertExtensions.Throws<ArgumentNullException>("destination", () => WindowsRuntimeBufferExtensions.CopyTo(buffer, 0, null, 0, 0));
|
||||
AssertExtensions.Throws<ArgumentNullException>("destination", () => WindowsRuntimeBufferExtensions.CopyTo(buffer, 0, (IBuffer)null, 0, 0));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CopyTo_NegativeSourceIndex_ThrowsArgumentOutOfRangeException()
|
||||
{
|
||||
IBuffer buffer = WindowsRuntimeBufferExtensions.AsBuffer(new byte[0]);
|
||||
AssertExtensions.Throws<ArgumentOutOfRangeException>("sourceIndex", () => WindowsRuntimeBufferExtensions.CopyTo(new byte[0], -1, buffer, 0, 0));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CopyTo_NegativeDestinationIndex_ThrowsArgumentOutOfRangeException()
|
||||
{
|
||||
IBuffer buffer = WindowsRuntimeBufferExtensions.AsBuffer(new byte[0]);
|
||||
AssertExtensions.Throws<ArgumentOutOfRangeException>("destinationIndex", () => WindowsRuntimeBufferExtensions.CopyTo(buffer, 0, new byte[0], -1, 0));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CopyTo_LargeSourceIndex_ThrowsArgumentException()
|
||||
{
|
||||
IBuffer buffer = WindowsRuntimeBufferExtensions.AsBuffer(new byte[0]);
|
||||
AssertExtensions.Throws<ArgumentException>("sourceIndex", () => WindowsRuntimeBufferExtensions.CopyTo(new byte[0], 1, buffer, 0, 0));
|
||||
AssertExtensions.Throws<ArgumentException>(null, () => WindowsRuntimeBufferExtensions.CopyTo(buffer, 1, buffer, 0, 0));
|
||||
AssertExtensions.Throws<ArgumentException>(null, () => WindowsRuntimeBufferExtensions.CopyTo(buffer, 1, new byte[0], 0, 0));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CopyTo_NegativeCount_ThrowsArgumentOutOfRangeException()
|
||||
{
|
||||
IBuffer buffer = WindowsRuntimeBufferExtensions.AsBuffer(new byte[0]);
|
||||
AssertExtensions.Throws<ArgumentOutOfRangeException>("count", () => WindowsRuntimeBufferExtensions.CopyTo(new byte[0], 0, buffer, 0, -1));
|
||||
AssertExtensions.Throws<ArgumentOutOfRangeException>("count", () => WindowsRuntimeBufferExtensions.CopyTo(buffer, 0, new byte[0], 0, -1));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(new byte[0], 0, 0)]
|
||||
[InlineData(new byte[0], 0, 1)]
|
||||
[InlineData(new byte[] { 0, 0 }, 2, 0)]
|
||||
[InlineData(new byte[] { 0, 0 }, 1, 2)]
|
||||
public void CopyTo_InvalidSourceIndexCount_ThrowsArgumentException(byte[] bytes, uint sourceIndex, uint count)
|
||||
{
|
||||
IBuffer buffer = WindowsRuntimeBufferExtensions.AsBuffer(bytes);
|
||||
AssertExtensions.Throws<ArgumentException>(sourceIndex >= bytes.Length ? "sourceIndex" : null, () => WindowsRuntimeBufferExtensions.CopyTo(bytes, (int)sourceIndex, buffer, 0, (int)count));
|
||||
AssertExtensions.Throws<ArgumentException>(null, () => WindowsRuntimeBufferExtensions.CopyTo(buffer, sourceIndex, buffer, 0, count));
|
||||
AssertExtensions.Throws<ArgumentException>(null, () => WindowsRuntimeBufferExtensions.CopyTo(buffer, sourceIndex, new byte[0], 0, (int)count));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(new byte[] { 0, 0 }, 2, 1)]
|
||||
[InlineData(new byte[] { 0, 0 }, 1, 2)]
|
||||
public void CopyTo_InvalidDestinationIndexCount_ThrowsArgumentException(byte[] bytes, uint destinationIndex, uint count)
|
||||
{
|
||||
IBuffer buffer = WindowsRuntimeBufferExtensions.AsBuffer(bytes);
|
||||
AssertExtensions.Throws<ArgumentException>(null, () => WindowsRuntimeBufferExtensions.CopyTo(new byte[10], 0, buffer, destinationIndex, (int)count));
|
||||
AssertExtensions.Throws<ArgumentException>(null, () => WindowsRuntimeBufferExtensions.CopyTo(new byte[10].AsBuffer(), 0, bytes, (int)destinationIndex, (int)count));
|
||||
AssertExtensions.Throws<ArgumentException>(null, () => WindowsRuntimeBufferExtensions.CopyTo(new byte[10].AsBuffer(), 0, buffer, destinationIndex, count));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CopyTo_CustomBuffer_ThrowsInvalidCastException()
|
||||
{
|
||||
Assert.Throws<InvalidCastException>(() => WindowsRuntimeBufferExtensions.CopyTo(new byte[10], new CustomBuffer()));
|
||||
Assert.Throws<InvalidCastException>(() => WindowsRuntimeBufferExtensions.CopyTo(new CustomBuffer(), new byte[10]));
|
||||
Assert.Throws<InvalidCastException>(() => WindowsRuntimeBufferExtensions.CopyTo(new CustomBuffer(), new CustomBuffer()));
|
||||
Assert.Throws<InvalidCastException>(() => WindowsRuntimeBufferExtensions.CopyTo(new byte[10], 0, new CustomBuffer(), 0, 0));
|
||||
Assert.Throws<InvalidCastException>(() => WindowsRuntimeBufferExtensions.CopyTo(new CustomBuffer(), 0, new byte[10], 0, 0));
|
||||
|
||||
Assert.Throws<InvalidCastException>(() => WindowsRuntimeBufferExtensions.CopyTo(new CustomBuffer(), 0, new CustomBuffer(), 0, 0));
|
||||
Assert.Throws<InvalidCastException>(() => WindowsRuntimeBufferExtensions.CopyTo(new CustomBuffer(), 0, new byte[10].AsBuffer(), 0, 0));
|
||||
Assert.Throws<InvalidCastException>(() => WindowsRuntimeBufferExtensions.CopyTo(new byte[10].AsBuffer(), 0, new CustomBuffer(), 0, 0));
|
||||
}
|
||||
|
||||
public static IEnumerable<object[]> IsSameData_TestData()
|
||||
{
|
||||
byte[] data = new byte[] { 1, 2, 3 };
|
||||
IBuffer buffer = data.AsBuffer();
|
||||
yield return new object[] { buffer, buffer, true };
|
||||
yield return new object[] { buffer, data.AsBuffer(), true };
|
||||
yield return new object[] { buffer, new byte[] { 1, 3, 3 }.AsBuffer(), false };
|
||||
|
||||
yield return new object[] { buffer, new CustomBuffer(), false };
|
||||
yield return new object[] { buffer, null, false };
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(IsSameData_TestData))]
|
||||
public void IsSameData_Buffer_ReturnsExpected(IBuffer buffer, IBuffer other, bool expected)
|
||||
{
|
||||
Assert.Equal(expected, WindowsRuntimeBufferExtensions.IsSameData(buffer, other));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void IsSameData_CustomBuffer_ThrowsInvalidCastException()
|
||||
{
|
||||
Assert.Throws<InvalidCastException>(() => WindowsRuntimeBufferExtensions.IsSameData(new CustomBuffer(), new CustomBuffer()));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void IsSameData_NullBuffer_ThrowsArgumentNullException()
|
||||
{
|
||||
AssertExtensions.Throws<ArgumentNullException>("buffer", () => WindowsRuntimeBufferExtensions.IsSameData(null, new byte[0].AsBuffer()));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetByte_NullBuffer_ThrowsArgumentNullException()
|
||||
{
|
||||
AssertExtensions.Throws<ArgumentNullException>("source", () => WindowsRuntimeBufferExtensions.GetByte(null, 0));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(1)]
|
||||
[InlineData(2)]
|
||||
public void GetByte_InvalidOffset_ThrowsArgumentException(uint byteOffset)
|
||||
{
|
||||
IBuffer buffer = new byte[1].AsBuffer();
|
||||
AssertExtensions.Throws<ArgumentException>("byteOffset", () => WindowsRuntimeBufferExtensions.GetByte(buffer, byteOffset));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetByte_CustomBuffer_ThrowsInvalidCastExceptionException()
|
||||
{
|
||||
Assert.Throws<InvalidCastException>(() => WindowsRuntimeBufferExtensions.GetByte(new CustomBuffer(), 2));
|
||||
}
|
||||
|
||||
public static IEnumerable<object[]> GetWindowsRuntimeBuffer_TestData()
|
||||
{
|
||||
yield return new object[] { new byte[] { 1, 2, 3 }, 0, 3 };
|
||||
yield return new object[] { new byte[] { 1, 2, 3 }, 1, 2 };
|
||||
yield return new object[] { new byte[] { 1, 2, 3 }, 3, 0 };
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(GetWindowsRuntimeBuffer_TestData))]
|
||||
public void GetWindowsRuntimeBuffer_Stream_Success(byte[] bytes, int positionInStream, int length)
|
||||
{
|
||||
using (var stream = new MemoryStream())
|
||||
{
|
||||
stream.Write(bytes, 0, bytes.Length);
|
||||
stream.Position = 0;
|
||||
|
||||
if (positionInStream == 0 && length == bytes.Length)
|
||||
{
|
||||
Verify(WindowsRuntimeBufferExtensions.GetWindowsRuntimeBuffer(stream), bytes, positionInStream, length, stream.Capacity);
|
||||
}
|
||||
|
||||
stream.Position = 0;
|
||||
Verify(WindowsRuntimeBufferExtensions.GetWindowsRuntimeBuffer(stream, positionInStream, length), bytes, positionInStream, length, length);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetWindowsRuntimeBuffer_NullStream_ThrowsArgumentNullException()
|
||||
{
|
||||
AssertExtensions.Throws<ArgumentNullException>("underlyingStream", () => WindowsRuntimeBufferExtensions.GetWindowsRuntimeBuffer(null));
|
||||
AssertExtensions.Throws<ArgumentNullException>("underlyingStream", () => WindowsRuntimeBufferExtensions.GetWindowsRuntimeBuffer(null, 0, 0));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetWindowsRuntimeBuffer_NonWritableStream_ThrowsUnauthorizedAccessException()
|
||||
{
|
||||
var memoryStream = new MemoryStream(new byte[10], false);
|
||||
Assert.Throws<UnauthorizedAccessException>(() => WindowsRuntimeBufferExtensions.GetWindowsRuntimeBuffer(memoryStream));
|
||||
Assert.Throws<UnauthorizedAccessException>(() => WindowsRuntimeBufferExtensions.GetWindowsRuntimeBuffer(memoryStream, 0, 0));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetWindowsRuntimeBuffer_NegativePositionInStream_ThrowsArgumentOufOfRangeException()
|
||||
{
|
||||
var memoryStream = new MemoryStream();
|
||||
AssertExtensions.Throws<ArgumentOutOfRangeException>("positionInStream", () => WindowsRuntimeBufferExtensions.GetWindowsRuntimeBuffer(memoryStream, -1, 0));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetWindowsRuntimeBuffer_NegativeLength_ThrowsArgumentOufOfRangeException()
|
||||
{
|
||||
var memoryStream = new MemoryStream();
|
||||
AssertExtensions.Throws<ArgumentOutOfRangeException>("length", () => WindowsRuntimeBufferExtensions.GetWindowsRuntimeBuffer(memoryStream, 0, -1));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetWindowsRuntimeBuffer_EmptyStream_ThrowsArgumentException()
|
||||
{
|
||||
using (var stream = new MemoryStream())
|
||||
{
|
||||
Assert.Throws<ArgumentException>(null, () => WindowsRuntimeBufferExtensions.GetWindowsRuntimeBuffer(stream, 0, 0));
|
||||
}
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(1)]
|
||||
[InlineData(2)]
|
||||
public void GetWindowsRuntimeBuffer_PositonInStreamGreaterOrEqualToCapacity_ThrowsArgumentException(int positionInStream)
|
||||
{
|
||||
var memoryStream = new MemoryStream(1);
|
||||
AssertExtensions.Throws<ArgumentException>(null, () => WindowsRuntimeBufferExtensions.GetWindowsRuntimeBuffer(memoryStream, positionInStream, 0));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetWindowsRuntimeBuffer_BufferWithLengthGreaterThanIntMax_Throws()
|
||||
{
|
||||
var memoryStream = new SubMemoryStream(10);
|
||||
WindowsRuntimeBufferExtensions.GetWindowsRuntimeBuffer(memoryStream, 0, 0);
|
||||
}
|
||||
|
||||
public static IEnumerable<object[]> ToArray_TestData()
|
||||
{
|
||||
yield return new object[] { new byte[] { 1, 2, 3 }, 0, 3, new byte[] { 1, 2, 3 } };
|
||||
yield return new object[] { new byte[] { 1, 2, 3 }, 2, 0, new byte[0] };
|
||||
yield return new object[] { new byte[] { 1, 2, 3 }, 1, 2, new byte[] { 2, 3 } };
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(ToArray_TestData))]
|
||||
public void ToArray_Buffer_ReturnsExpected(byte[] buffer, uint index, int count, byte[] expected)
|
||||
{
|
||||
if (index == 0 && count == buffer.Length)
|
||||
{
|
||||
Assert.Equal(expected, buffer.AsBuffer().ToArray());
|
||||
}
|
||||
|
||||
Assert.Equal(expected, buffer.AsBuffer().ToArray(index, count));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToArray_NullBuffer_ThrowsArgumentNullException()
|
||||
{
|
||||
AssertExtensions.Throws<ArgumentNullException>("source", () => WindowsRuntimeBufferExtensions.ToArray(null));
|
||||
AssertExtensions.Throws<ArgumentNullException>("source", () => WindowsRuntimeBufferExtensions.ToArray(null, 0, 0));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToArray_NegativeCount_ThrowsArgumentOutOfRangeException()
|
||||
{
|
||||
AssertExtensions.Throws<ArgumentOutOfRangeException>("count", () => WindowsRuntimeBufferExtensions.ToArray(new byte[0].AsBuffer(), 0, -1));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(new byte[0], 0, 0)]
|
||||
[InlineData(new byte[] { 0 }, 1, 0)]
|
||||
[InlineData(new byte[] { 0, 0, 0 }, 0, 4)]
|
||||
[InlineData(new byte[] { 0, 0, 0 }, 1, 3)]
|
||||
public void ToArray_InvalidIndexCount_ThrowsArgumentException(byte[] buffer, uint index, int count)
|
||||
{
|
||||
AssertExtensions.Throws<ArgumentException>(null, () => WindowsRuntimeBufferExtensions.ToArray(buffer.AsBuffer(), index, count));
|
||||
}
|
||||
|
||||
private static void Verify(IBuffer buffer, byte[] source, int offset, int length, int capacity)
|
||||
{
|
||||
Assert.Equal(length, (int)buffer.Length);
|
||||
Assert.Equal(capacity, (int)buffer.Capacity);
|
||||
|
||||
for (uint i = 0; i < length; i++)
|
||||
{
|
||||
Assert.Equal(source[i + offset], buffer.GetByte(i));
|
||||
}
|
||||
}
|
||||
|
||||
private class SubMemoryStream : MemoryStream
|
||||
{
|
||||
public SubMemoryStream(int capacity) : base(capacity) { }
|
||||
|
||||
public override long Length => long.MaxValue;
|
||||
}
|
||||
|
||||
private class CustomBuffer : IBuffer
|
||||
{
|
||||
public uint Capacity => 10;
|
||||
public uint Length { get; set; } = 10;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using Windows.Storage.Streams;
|
||||
using Xunit;
|
||||
|
||||
namespace System.Runtime.InteropServices.WindowsRuntime.Tests
|
||||
{
|
||||
public class WindowsRuntimeBufferTests
|
||||
{
|
||||
[Theory]
|
||||
[InlineData(0)]
|
||||
[InlineData(1)]
|
||||
public void Create_Capacity_ReturnsExpected(int capacity)
|
||||
{
|
||||
IBuffer buffer = WindowsRuntimeBuffer.Create(capacity);
|
||||
Assert.Equal(capacity, (int)buffer.Capacity);
|
||||
Assert.Equal(0, (int)buffer.Length);
|
||||
}
|
||||
|
||||
public static IEnumerable<object[]> Create_TestData()
|
||||
{
|
||||
yield return new object[] { new byte[0], 0, 0, 0 };
|
||||
yield return new object[] { new byte[] { 1, 2, 3 }, 0, 3, 3 };
|
||||
yield return new object[] { new byte[] { 1, 2, 3, 4, 5, 6 }, 2, 1, 4 };
|
||||
yield return new object[] { new byte[] { 1, 2, 3 }, 1, 2, 2 };
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(Create_TestData))]
|
||||
public void Create_Buffer_ReturnsExpected(byte[] source, int offset, int length, int capacity)
|
||||
{
|
||||
IBuffer buffer = WindowsRuntimeBuffer.Create(source, offset, length, capacity);
|
||||
Assert.Equal(capacity, (int)buffer.Capacity);
|
||||
Assert.Equal(length, (int)buffer.Length);
|
||||
|
||||
for (uint i = 0; i < length; i++)
|
||||
{
|
||||
Assert.Equal(source[i + offset], buffer.GetByte(i));
|
||||
}
|
||||
|
||||
// The source byte array should be copied.
|
||||
if (source.Length > 0)
|
||||
{
|
||||
source[0] = 45;
|
||||
Assert.NotEqual(45, buffer.GetByte(0));
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Create_NegativeCapacity_ThrowsArgumentOutOfRangeException()
|
||||
{
|
||||
AssertExtensions.Throws<ArgumentOutOfRangeException>("capacity", () => WindowsRuntimeBuffer.Create(-1));
|
||||
AssertExtensions.Throws<ArgumentOutOfRangeException>("capacity", () => WindowsRuntimeBuffer.Create(new byte[0], 0, 0, -1));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Create_NullData_ThrowsArgumentNullException()
|
||||
{
|
||||
AssertExtensions.Throws<ArgumentNullException>("data", () => WindowsRuntimeBuffer.Create(null, 0, 0, 0));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Create_NegativeOffset_ThrowsArgumentOutOfRangeException()
|
||||
{
|
||||
AssertExtensions.Throws<ArgumentOutOfRangeException>("offset", () => WindowsRuntimeBuffer.Create(new byte[0], -1, 0, 0));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Create_NegativeLength_ThrowsArgumentOutOfRangeException()
|
||||
{
|
||||
AssertExtensions.Throws<ArgumentOutOfRangeException>("length", () => WindowsRuntimeBuffer.Create(new byte[0], 0, -1, 0));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(new byte[0], 0, 1, 0)]
|
||||
[InlineData(new byte[0], 1, 0, 0)]
|
||||
[InlineData(new byte[] { 0, 0 }, 1, 2, 0)]
|
||||
[InlineData(new byte[] { 0, 0 }, int.MaxValue, 0, 0)]
|
||||
[InlineData(new byte[] { 0, 0 }, 0, 0, 3)]
|
||||
[InlineData(new byte[] { 0, 0 }, 0, 0, int.MaxValue)]
|
||||
[InlineData(new byte[] { 0, 0 }, 0, 2, 1)]
|
||||
public void Create_InvalidOffsetLengthCapacity_ThrowsArgumentException(byte[] data, int offset, int length, int capacity)
|
||||
{
|
||||
AssertExtensions.Throws<ArgumentException>(null, () => WindowsRuntimeBuffer.Create(data, offset, length, capacity));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Length_SetGreaterThanCapacity_ThrowsArgumentException()
|
||||
{
|
||||
IBuffer buffer = WindowsRuntimeBuffer.Create(2);
|
||||
AssertExtensions.Throws<ArgumentOutOfRangeException>("value", () => buffer.Length = 3);
|
||||
}
|
||||
}
|
||||
}
|
||||
118
external/corefx/src/System.Runtime.WindowsRuntime/tests/Windows/Foundation/PointTests.cs
vendored
Normal file
118
external/corefx/src/System.Runtime.WindowsRuntime/tests/Windows/Foundation/PointTests.cs
vendored
Normal file
@@ -0,0 +1,118 @@
|
||||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using Xunit;
|
||||
|
||||
namespace Windows.Foundation.Tests
|
||||
{
|
||||
public class PointTests
|
||||
{
|
||||
[Fact]
|
||||
public void Ctor_Default()
|
||||
{
|
||||
var point = new Point();
|
||||
Assert.Equal(0, point.X);
|
||||
Assert.Equal(0, point.Y);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(double.MinValue, double.MinValue, double.NegativeInfinity, double.NegativeInfinity)]
|
||||
[InlineData(-1, -2, -1 , -2)]
|
||||
[InlineData(0, 0, 0, 0)]
|
||||
[InlineData(1, 2, 1, 2)]
|
||||
[InlineData(double.MaxValue, double.MaxValue, double.PositiveInfinity, double.PositiveInfinity)]
|
||||
[InlineData(double.NaN, double.NaN, double.NaN, double.NaN)]
|
||||
[InlineData(double.PositiveInfinity, double.PositiveInfinity, double.PositiveInfinity, double.PositiveInfinity)]
|
||||
[InlineData(double.NegativeInfinity, double.NegativeInfinity, double.NegativeInfinity, double.NegativeInfinity)]
|
||||
public void Ctor_X_Y(double x, double y, double expectedX, double expectedY)
|
||||
{
|
||||
var point = new Point(x, y);
|
||||
Assert.Equal(expectedX, point.X);
|
||||
Assert.Equal(expectedY, point.Y);
|
||||
}
|
||||
|
||||
public static IEnumerable<object[]> Coordinate_TestData()
|
||||
{
|
||||
yield return new object[] { double.MinValue, double.NegativeInfinity };
|
||||
yield return new object[] { -1, -1 };
|
||||
yield return new object[] { 0, 0 };
|
||||
yield return new object[] { 1, 1 };
|
||||
yield return new object[] { double.MaxValue, double.PositiveInfinity };
|
||||
yield return new object[] { double.NaN, double.NaN };
|
||||
yield return new object[] { double.NegativeInfinity, double.NegativeInfinity };
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(Coordinate_TestData))]
|
||||
public void X_Set_GetReturnsExpected(double x, double expectedX)
|
||||
{
|
||||
var point = new Point { X = x };
|
||||
Assert.Equal(expectedX, point.X);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(Coordinate_TestData))]
|
||||
public void Y_Set_GetReturnsExpected(double y, double expectedY)
|
||||
{
|
||||
var point = new Point { Y = y };
|
||||
Assert.Equal(expectedY, point.Y);
|
||||
}
|
||||
|
||||
public static IEnumerable<object[]> Equals_TestData()
|
||||
{
|
||||
yield return new object[] { new Point(1, 2), new Point(1, 2), true };
|
||||
yield return new object[] { new Point(1, 2), new Point(2, 2), false };
|
||||
yield return new object[] { new Point(1, 2), new Point(1, 3), false };
|
||||
|
||||
yield return new object[] { new Point(1, 2), new object(), false };
|
||||
yield return new object[] { new Point(1, 2), null, false };
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(Equals_TestData))]
|
||||
public void Equals_Other_ReturnsExpected(Point point, object other, bool expected)
|
||||
{
|
||||
Assert.Equal(expected, point.Equals(other));
|
||||
if (other is Point otherPoint)
|
||||
{
|
||||
Assert.Equal(expected, point == otherPoint);
|
||||
Assert.Equal(!expected, point != otherPoint);
|
||||
Assert.Equal(expected, point.Equals(otherPoint));
|
||||
Assert.Equal(expected, point.GetHashCode().Equals(other.GetHashCode()));
|
||||
}
|
||||
}
|
||||
|
||||
public static IEnumerable<object[]> ToString_TestData()
|
||||
{
|
||||
yield return new object[] { new Point(1, 2), null, null, "1,2" };
|
||||
yield return new object[] { new Point(1, 2), null, CultureInfo.InvariantCulture, "1,2" };
|
||||
|
||||
yield return new object[] { new Point(1, 2), "", CultureInfo.InvariantCulture, "1,2" };
|
||||
yield return new object[] { new Point(1, 2), "abc", null, "abc,abc" };
|
||||
yield return new object[] { new Point(1, 2), "N4", CultureInfo.InvariantCulture, "1.0000,2.0000" };
|
||||
|
||||
yield return new object[] { new Point(1, 2), "", new NumberFormatInfo { NumberDecimalSeparator = "," }, "1;2" };
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(ToString_TestData))]
|
||||
public void ToString_Invoke_ReturnsExpected(Point point, string format, IFormatProvider formatProvider, string expected)
|
||||
{
|
||||
if (format == null)
|
||||
{
|
||||
if (formatProvider == null)
|
||||
{
|
||||
Assert.Equal(expected, point.ToString());
|
||||
}
|
||||
|
||||
Assert.Equal(expected, point.ToString(formatProvider));
|
||||
}
|
||||
|
||||
Assert.Equal(expected, ((IFormattable)point).ToString(format, formatProvider));
|
||||
}
|
||||
}
|
||||
}
|
||||
330
external/corefx/src/System.Runtime.WindowsRuntime/tests/Windows/Foundation/RectTests.cs
vendored
Normal file
330
external/corefx/src/System.Runtime.WindowsRuntime/tests/Windows/Foundation/RectTests.cs
vendored
Normal file
@@ -0,0 +1,330 @@
|
||||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using Xunit;
|
||||
|
||||
namespace Windows.Foundation.Tests
|
||||
{
|
||||
public class RectTests
|
||||
{
|
||||
[Fact]
|
||||
public void Ctor_Default()
|
||||
{
|
||||
var rect = new Rect();
|
||||
Assert.Equal(0, rect.X);
|
||||
Assert.Equal(0, rect.Y);
|
||||
Assert.Equal(0, rect.Width);
|
||||
Assert.Equal(0, rect.Height);
|
||||
|
||||
Assert.Equal(0, rect.Left);
|
||||
Assert.Equal(0, rect.Right);
|
||||
Assert.Equal(0, rect.Top);
|
||||
Assert.Equal(0, rect.Bottom);
|
||||
|
||||
Assert.False(rect.IsEmpty);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(0, 0, 0, 0, 0, 0, 0, 0)]
|
||||
[InlineData(1, 2, 3, 4, 1, 2, 3, 4)]
|
||||
[InlineData(double.MaxValue, double.MaxValue, double.MaxValue, double.MaxValue, double.PositiveInfinity, double.PositiveInfinity, double.PositiveInfinity, double.PositiveInfinity)]
|
||||
[InlineData(double.NaN, double.NaN, double.NaN, double.NaN, double.NaN, double.NaN, double.NaN, double.NaN)]
|
||||
[InlineData(double.PositiveInfinity, double.PositiveInfinity, double.PositiveInfinity, double.PositiveInfinity, double.PositiveInfinity, double.PositiveInfinity, double.PositiveInfinity, double.PositiveInfinity)]
|
||||
public void Ctor_X_Y_Width_Height(double x, double y, double width, double height, double expectedX, double expectedY, double expectedWidth, double expectedHeight)
|
||||
{
|
||||
var rect = new Rect(x, y, width, height);
|
||||
Assert.Equal(expectedX, rect.X);
|
||||
Assert.Equal(expectedY, rect.Y);
|
||||
Assert.Equal(expectedWidth, rect.Width);
|
||||
Assert.Equal(expectedHeight, rect.Height);
|
||||
|
||||
Assert.Equal(expectedX, rect.Left);
|
||||
Assert.Equal(expectedX + expectedWidth, rect.Right);
|
||||
Assert.Equal(expectedY, rect.Top);
|
||||
Assert.Equal(expectedY + expectedHeight, rect.Bottom);
|
||||
|
||||
Assert.False(rect.IsEmpty);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(-1)]
|
||||
[InlineData(double.NegativeInfinity)]
|
||||
[ActiveIssue(21704, TargetFrameworkMonikers.UapAot)]
|
||||
public void Ctor_NegativeWidth_ThrowsArgumentOutOfRangeException(double width)
|
||||
{
|
||||
AssertExtensions.Throws<ArgumentOutOfRangeException>("width", () => new Rect(1, 1, width, 1));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(-1)]
|
||||
[InlineData(double.NegativeInfinity)]
|
||||
[ActiveIssue(21704, TargetFrameworkMonikers.UapAot)]
|
||||
public void Ctor_NegativeHeight_ThrowsArgumentOutOfRangeException(double height)
|
||||
{
|
||||
AssertExtensions.Throws<ArgumentOutOfRangeException>("height", () => new Rect(1, 1, 1, height));
|
||||
}
|
||||
|
||||
public static IEnumerable<object[]> Ctor_Point_Point_TestData()
|
||||
{
|
||||
yield return new object[] { new Point(1, 2), new Point(1, 2), 1, 2, 0, 0 };
|
||||
yield return new object[] { new Point(1, 2), new Point(3, 4), 1, 2, 2, 2 };
|
||||
yield return new object[] { new Point(3, 4), new Point(1, 2), 1, 2, 2, 2 };
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(Ctor_Point_Point_TestData))]
|
||||
public void Ctor_Point_Point(Point point1, Point point2, double expectedX, double expectedY, double expectedWidth, double expectedHeight)
|
||||
{
|
||||
var rect = new Rect(point1, point2);
|
||||
Assert.Equal(expectedX, rect.X);
|
||||
Assert.Equal(expectedY, rect.Y);
|
||||
Assert.Equal(expectedWidth, rect.Width);
|
||||
Assert.Equal(expectedHeight, rect.Height);
|
||||
}
|
||||
|
||||
public static IEnumerable<object[]> Ctor_Point_Size_TestData()
|
||||
{
|
||||
yield return new object[] { new Point(1, 2), Size.Empty, double.PositiveInfinity, double.PositiveInfinity, double.NegativeInfinity, double.NegativeInfinity };
|
||||
yield return new object[] { new Point(1, 2), new Size(0, 0), 1, 2, 0, 0 };
|
||||
yield return new object[] { new Point(1, 2), new Size(3, 4), 1, 2, 3, 4 };
|
||||
yield return new object[] { new Point(1, 2), new Size(double.MaxValue, double.MaxValue), 1, 2, double.PositiveInfinity, double.PositiveInfinity };
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(Ctor_Point_Size_TestData))]
|
||||
public void Ctor_Point_Size(Point point, Size size, double expectedX, double expectedY, double expectedWidth, double expectedHeight)
|
||||
{
|
||||
var rect = new Rect(point, size);
|
||||
Assert.Equal(expectedX, rect.X);
|
||||
Assert.Equal(expectedY, rect.Y);
|
||||
Assert.Equal(expectedWidth, rect.Width);
|
||||
Assert.Equal(expectedHeight, rect.Height);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Empty_Get_ReturnsExpected()
|
||||
{
|
||||
Rect rect = Rect.Empty;
|
||||
Assert.Equal(double.PositiveInfinity, rect.X);
|
||||
Assert.Equal(double.PositiveInfinity, rect.Y);
|
||||
Assert.Equal(double.NegativeInfinity, rect.Width);
|
||||
Assert.Equal(double.NegativeInfinity, rect.Height);
|
||||
|
||||
Assert.Equal(double.PositiveInfinity, rect.Left);
|
||||
Assert.Equal(double.NegativeInfinity, rect.Right);
|
||||
Assert.Equal(double.PositiveInfinity, rect.Top);
|
||||
Assert.Equal(double.NegativeInfinity, rect.Bottom);
|
||||
|
||||
Assert.True(rect.IsEmpty);
|
||||
}
|
||||
|
||||
public static IEnumerable<object[]> Coordinate_TestData()
|
||||
{
|
||||
yield return new object[] { double.MinValue, double.NegativeInfinity };
|
||||
yield return new object[] { -1, -1 };
|
||||
yield return new object[] { 0, 0 };
|
||||
yield return new object[] { 1, 1 };
|
||||
yield return new object[] { double.MaxValue, double.PositiveInfinity };
|
||||
yield return new object[] { double.NaN, double.NaN };
|
||||
yield return new object[] { double.NegativeInfinity, double.NegativeInfinity };
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(Coordinate_TestData))]
|
||||
public void X_Set_GetReturnsExpected(double x, double expectedX)
|
||||
{
|
||||
var rect = new Rect { X = x };
|
||||
Assert.Equal(expectedX, rect.X);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(Coordinate_TestData))]
|
||||
public void Y_Set_GetReturnsExpected(double y, double expectedY)
|
||||
{
|
||||
var rect = new Rect { Y = y };
|
||||
Assert.Equal(expectedY, rect.Y);
|
||||
}
|
||||
|
||||
public static IEnumerable<object[]> Size_TestData()
|
||||
{
|
||||
yield return new object[] { 0, 0 };
|
||||
yield return new object[] { 1, 1 };
|
||||
yield return new object[] { double.MaxValue, double.PositiveInfinity };
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(Size_TestData))]
|
||||
public void Width_SetValid_GetReturnsExpected(double width, double expectedWidth)
|
||||
{
|
||||
var rect = new Rect { Width = width };
|
||||
Assert.Equal(expectedWidth, rect.Width);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(-1)]
|
||||
[InlineData(double.NegativeInfinity)]
|
||||
[ActiveIssue(21704, TargetFrameworkMonikers.UapAot)]
|
||||
public void Width_SetNegative_ThrowsArgumentOutOfRangeException(double width)
|
||||
{
|
||||
var rect = new Rect();
|
||||
AssertExtensions.Throws<ArgumentOutOfRangeException>("Width", () => rect.Width = width);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(Size_TestData))]
|
||||
public void Height_SetValid_GetReturnsExpected(double height, double expectedHeight)
|
||||
{
|
||||
var rect = new Rect { Height = height };
|
||||
Assert.Equal(expectedHeight, rect.Height);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(-1)]
|
||||
[InlineData(double.NegativeInfinity)]
|
||||
[ActiveIssue(21704, TargetFrameworkMonikers.UapAot)]
|
||||
public void Height_SetNegative_ThrowsArgumentOutOfRangeException(double height)
|
||||
{
|
||||
var rect = new Rect();
|
||||
AssertExtensions.Throws<ArgumentOutOfRangeException>("Height", () => rect.Height = height);
|
||||
}
|
||||
|
||||
public static IEnumerable<object[]> Contains_TestData()
|
||||
{
|
||||
yield return new object[] { new Rect(1, 2, 3, 4), new Point(1, 2), true };
|
||||
yield return new object[] { new Rect(1, 2, 3, 4), new Point(3, 4), true };
|
||||
yield return new object[] { new Rect(1, 2, 3, 4), new Point(4, 6), true };
|
||||
yield return new object[] { new Rect(1, 2, 3, 4), new Point(5, 7), false };
|
||||
yield return new object[] { Rect.Empty, new Point(1, 2), false };
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(Contains_TestData))]
|
||||
public void Contains_Point_ReturnsExpected(Rect rect, Point point, bool expected)
|
||||
{
|
||||
Assert.Equal(expected, rect.Contains(point));
|
||||
}
|
||||
|
||||
public static IEnumerable<object[]> Intersect_TestData()
|
||||
{
|
||||
yield return new object[] { Rect.Empty, Rect.Empty, Rect.Empty };
|
||||
yield return new object[] { Rect.Empty, new Rect(1,2 , 3, 4), Rect.Empty };
|
||||
yield return new object[] { new Rect(1, 2, 3, 4), Rect.Empty, Rect.Empty };
|
||||
yield return new object[] { new Rect(1, 2, 3, 4), new Rect(1, 2, 3, 4), new Rect(1, 2, 3, 4) };
|
||||
yield return new object[] { new Rect(1, 2, 3, 4), new Rect(0, 0, 0, 0), Rect.Empty };
|
||||
yield return new object[] { new Rect(1, 2, 3, 4), new Rect(2, 2, 6, 6), new Rect(2, 2, 2, 4) };
|
||||
yield return new object[] { new Rect(1, 2, 3, 4), new Rect(2, 2, 2, 2), new Rect(2, 2, 2, 2) };
|
||||
yield return new object[] { new Rect(1, 2, 3, 4), new Rect(-2, -2, 12, 12), new Rect(1, 2, 3, 4) };
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(Intersect_TestData))]
|
||||
public void Intersect_Rect_ReturnsExpected(Rect rect, Rect other, Rect expected)
|
||||
{
|
||||
rect.Intersect(other);
|
||||
Assert.Equal(expected, rect);
|
||||
}
|
||||
|
||||
public static IEnumerable<object[]> Union_Rect_TestData()
|
||||
{
|
||||
yield return new object[] { Rect.Empty, Rect.Empty, Rect.Empty };
|
||||
yield return new object[] { Rect.Empty, new Rect(1, 2, 3, 4), new Rect(1, 2, 3, 4) };
|
||||
yield return new object[] { new Rect(1, 2, 3, 4), Rect.Empty, new Rect(1, 2, 3, 4) };
|
||||
yield return new object[] { new Rect(1, 2, 3, 4), new Rect(1, 2, 3, 4), new Rect(1, 2, 3, 4) };
|
||||
yield return new object[] { new Rect(1, 2, 3, 4), new Rect(0, 0, 0, 0), new Rect(0, 0, 4, 6) };
|
||||
yield return new object[] { new Rect(1, 2, 3, 4), new Rect(2, 2, 6, 6), new Rect(1, 2, 7, 6) };
|
||||
yield return new object[] { new Rect(1, 2, 3, 4), new Rect(2, 2, 2, 2), new Rect(1, 2, 3, 4) };
|
||||
yield return new object[] { new Rect(1, 2, 3, 4), new Rect(-2, -2, 2, 2), new Rect(-2, -2, 6, 8) };
|
||||
yield return new object[] { new Rect(-1, -2, 3, 4), new Rect(2, 2, 2, 2), new Rect(-1, -2, 5, 6) };
|
||||
|
||||
yield return new object[] { new Rect(1, 2, double.PositiveInfinity, double.PositiveInfinity), new Rect(-1, -2, 3, 4), new Rect(-1, -2, double.PositiveInfinity, double.PositiveInfinity) };
|
||||
yield return new object[] { new Rect(-1, -2, 3, 4), new Rect(1, 2, double.PositiveInfinity, double.PositiveInfinity), new Rect(-1, -2, double.PositiveInfinity, double.PositiveInfinity) };
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(Union_Rect_TestData))]
|
||||
public void Union_Rect_ReturnsExpected(Rect rect, Rect other, Rect expected)
|
||||
{
|
||||
rect.Union(other);
|
||||
Assert.Equal(expected, rect);
|
||||
}
|
||||
|
||||
public static IEnumerable<object[]> Union_Point_TestData()
|
||||
{
|
||||
yield return new object[] { Rect.Empty, new Point(1, 2), new Rect(1, 2, 0, 0) };
|
||||
yield return new object[] { new Rect(2, 3, 4, 5), new Point(1, 2), new Rect(1, 2, 5, 6) };
|
||||
yield return new object[] { new Rect(2, 3, 4, 5), new Point(-1, -2), new Rect(-1, -2, 7, 10) };
|
||||
yield return new object[] { new Rect(2, 3, 4, 5), new Point(2, 3), new Rect(2, 3, 4, 5) };
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(Union_Point_TestData))]
|
||||
public void Union_Point_ReturnsExpected(Rect rect, Point point, Rect expected)
|
||||
{
|
||||
rect.Union(point);
|
||||
Assert.Equal(expected, rect);
|
||||
}
|
||||
|
||||
public static IEnumerable<object[]> Equals_TestData()
|
||||
{
|
||||
yield return new object[] { new Rect(1, 2, 3, 4), new Rect(1, 2, 3, 4), true };
|
||||
yield return new object[] { new Rect(1, 2, 3, 4), new Rect(2, 2, 3, 4), false };
|
||||
yield return new object[] { new Rect(1, 2, 3, 4), new Rect(1, 3, 3, 4), false };
|
||||
yield return new object[] { new Rect(1, 2, 3, 4), new Rect(1, 2, 4, 4), false };
|
||||
yield return new object[] { new Rect(1, 2, 3, 4), new Rect(1, 3, 3, 5), false };
|
||||
yield return new object[] { new Rect(1, 2, 3, 4), Rect.Empty, false };
|
||||
|
||||
yield return new object[] { Rect.Empty, Rect.Empty, true };
|
||||
yield return new object[] { Rect.Empty, new Rect(1, 2, 3, 4), false };
|
||||
|
||||
yield return new object[] { new Rect(1, 2, 3, 4), new object(), false };
|
||||
yield return new object[] { new Rect(1, 2, 3, 4), null, false };
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(Equals_TestData))]
|
||||
public void Equals_Other_ReturnsExpected(Rect rect, object other, bool expected)
|
||||
{
|
||||
Assert.Equal(expected, rect.Equals(other));
|
||||
if (other is Rect otherRect)
|
||||
{
|
||||
Assert.Equal(expected, rect == otherRect);
|
||||
Assert.Equal(!expected, rect != otherRect);
|
||||
Assert.Equal(expected, rect.Equals(otherRect));
|
||||
Assert.Equal(expected, rect.GetHashCode().Equals(other.GetHashCode()));
|
||||
}
|
||||
}
|
||||
|
||||
public static IEnumerable<object[]> ToString_TestData()
|
||||
{
|
||||
yield return new object[] { new Rect(1, 2, 3, 4), null, null, "1,2,3,4" };
|
||||
yield return new object[] { new Rect(1, 2, 3, 4), null, CultureInfo.InvariantCulture, "1,2,3,4" };
|
||||
|
||||
yield return new object[] { new Rect(1, 2, 3, 4), "", CultureInfo.InvariantCulture, "1,2,3,4" };
|
||||
yield return new object[] { new Rect(1, 2, 3, 4), "abc", null, "abc,abc,abc,abc" };
|
||||
yield return new object[] { new Rect(1, 2, 3, 4), "N4", CultureInfo.InvariantCulture, "1.0000,2.0000,3.0000,4.0000" };
|
||||
|
||||
yield return new object[] { new Rect(1, 2, 3, 4), "", new NumberFormatInfo { NumberDecimalSeparator = "," }, "1;2;3;4" };
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(ToString_TestData))]
|
||||
public void ToString_Invoke_ReturnsExpected(Rect rect, string format, IFormatProvider formatProvider, string expected)
|
||||
{
|
||||
if (format == null)
|
||||
{
|
||||
if (formatProvider == null)
|
||||
{
|
||||
Assert.Equal(expected, rect.ToString());
|
||||
}
|
||||
|
||||
Assert.Equal(expected, rect.ToString(formatProvider));
|
||||
}
|
||||
|
||||
Assert.Equal(expected, ((IFormattable)rect).ToString(format, formatProvider));
|
||||
}
|
||||
}
|
||||
}
|
||||
149
external/corefx/src/System.Runtime.WindowsRuntime/tests/Windows/Foundation/SizeTests.cs
vendored
Normal file
149
external/corefx/src/System.Runtime.WindowsRuntime/tests/Windows/Foundation/SizeTests.cs
vendored
Normal file
@@ -0,0 +1,149 @@
|
||||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Xunit;
|
||||
|
||||
namespace Windows.Foundation.Tests
|
||||
{
|
||||
public class SizeTests
|
||||
{
|
||||
[Fact]
|
||||
public void Ctor_Default()
|
||||
{
|
||||
var size = new Size();
|
||||
Assert.Equal(0, size.Width);
|
||||
Assert.Equal(0, size.Height);
|
||||
|
||||
Assert.False(size.IsEmpty);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(0, 0, 0, 0)]
|
||||
[InlineData(1, 2, 1, 2)]
|
||||
[InlineData(double.NaN, double.NaN, double.NaN, double.NaN)]
|
||||
[InlineData(double.MaxValue, double.MaxValue, double.PositiveInfinity, double.PositiveInfinity)]
|
||||
[InlineData(double.PositiveInfinity, double.PositiveInfinity, double.PositiveInfinity, double.PositiveInfinity)]
|
||||
public void Ctor_Width_Height(double width, double height, double expectedWidth, double expectedHeight)
|
||||
{
|
||||
var size = new Size(width, height);
|
||||
Assert.Equal(expectedWidth, size.Width);
|
||||
Assert.Equal(expectedHeight, size.Height);
|
||||
|
||||
Assert.False(size.IsEmpty);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(-1)]
|
||||
[InlineData(double.NegativeInfinity)]
|
||||
[ActiveIssue(21704, TargetFrameworkMonikers.UapAot)]
|
||||
public void Ctor_NegativeWidth_ThrowsArgumentOutOfRangeException(double width)
|
||||
{
|
||||
AssertExtensions.Throws<ArgumentOutOfRangeException>("width", () => new Size(width, 1));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(-1)]
|
||||
[InlineData(double.NegativeInfinity)]
|
||||
[ActiveIssue(21704, TargetFrameworkMonikers.UapAot)]
|
||||
public void Ctor_NegativeHeight_ThrowsArgumentOutOfRangeException(double height)
|
||||
{
|
||||
AssertExtensions.Throws<ArgumentOutOfRangeException>("height", () => new Size(1, height));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(0)]
|
||||
[InlineData(1)]
|
||||
[InlineData(double.PositiveInfinity)]
|
||||
[InlineData(double.NaN)]
|
||||
public void Width_SetValid_GetReturnsExpected(double width)
|
||||
{
|
||||
var size = new Size { Width = width };
|
||||
Assert.Equal(width, size.Width);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(-1)]
|
||||
[InlineData(double.NegativeInfinity)]
|
||||
[ActiveIssue(21704, TargetFrameworkMonikers.UapAot)]
|
||||
public void Width_SetNegative_ThrowsArgumentOutOfRangeException(double width)
|
||||
{
|
||||
var size = new Size();
|
||||
AssertExtensions.Throws<ArgumentOutOfRangeException>("Width", () => size.Width = width);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(0)]
|
||||
[InlineData(1)]
|
||||
[InlineData(double.PositiveInfinity)]
|
||||
[InlineData(double.NaN)]
|
||||
public void Height_SetValid_GetReturnsExpected(double height)
|
||||
{
|
||||
var size = new Size { Height = height };
|
||||
Assert.Equal(height, size.Height);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(-1)]
|
||||
[InlineData(double.NegativeInfinity)]
|
||||
[ActiveIssue(21704, TargetFrameworkMonikers.UapAot)]
|
||||
public void Height_SetNegative_ThrowsArgumentOutOfRangeException(double height)
|
||||
{
|
||||
var size = new Size();
|
||||
AssertExtensions.Throws<ArgumentOutOfRangeException>("Height", () => size.Height = height);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Empty_Get_ReturnsExpected()
|
||||
{
|
||||
Size size = Size.Empty;
|
||||
Assert.Equal(double.NegativeInfinity, size.Width);
|
||||
Assert.Equal(double.NegativeInfinity, size.Height);
|
||||
Assert.True(size.IsEmpty);
|
||||
}
|
||||
|
||||
public static IEnumerable<object[]> Equals_TestData()
|
||||
{
|
||||
yield return new object[] { new Size(1, 2), new Size(1, 2), true };
|
||||
yield return new object[] { new Size(1, 2), new Size(2, 2), false };
|
||||
yield return new object[] { new Size(1, 2), new Size(1, 3), false };
|
||||
yield return new object[] { new Size(1, 2), Size.Empty, false };
|
||||
|
||||
yield return new object[] { Size.Empty, Size.Empty, true };
|
||||
yield return new object[] { Size.Empty, new Size(1, 2), false };
|
||||
|
||||
yield return new object[] { new Size(1, 2), new object(), false };
|
||||
yield return new object[] { new Size(1, 2), null, false };
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(Equals_TestData))]
|
||||
public void Equals_Other_ReturnsExpected(Size size, object other, bool expected)
|
||||
{
|
||||
Assert.Equal(expected, size.Equals(other));
|
||||
if (other is Size otherSize)
|
||||
{
|
||||
Assert.Equal(expected, size == otherSize);
|
||||
Assert.Equal(!expected, size != otherSize);
|
||||
Assert.Equal(expected, size.Equals(otherSize));
|
||||
Assert.Equal(expected, size.GetHashCode().Equals(other.GetHashCode()));
|
||||
}
|
||||
}
|
||||
|
||||
public static IEnumerable<object[]> ToString_TestData()
|
||||
{
|
||||
yield return new object[] { Size.Empty, "Empty" };
|
||||
yield return new object[] { new Size(0, 0), "0,0" };
|
||||
yield return new object[] { new Size(1, 2), "1,2" };
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(ToString_TestData))]
|
||||
public void ToString_Invoke_ReturnsExpected(Size size, string expected)
|
||||
{
|
||||
Assert.Equal(expected, size.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
92
external/corefx/src/System.Runtime.WindowsRuntime/tests/Windows/UI/ColorTests.cs
vendored
Normal file
92
external/corefx/src/System.Runtime.WindowsRuntime/tests/Windows/UI/ColorTests.cs
vendored
Normal file
@@ -0,0 +1,92 @@
|
||||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using Xunit;
|
||||
|
||||
namespace Windows.UI.Tests
|
||||
{
|
||||
public class ColorTests
|
||||
{
|
||||
[Fact]
|
||||
public void Ctor_Default()
|
||||
{
|
||||
var color = new Color();
|
||||
Assert.Equal(0, color.A);
|
||||
Assert.Equal(0, color.R);
|
||||
Assert.Equal(0, color.G);
|
||||
Assert.Equal(0, color.B);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(0, 0, 0, 0)]
|
||||
[InlineData(1, 2, 3, 4)]
|
||||
[InlineData(255, 255, 255, 255)]
|
||||
public void FromArgb_Invoke_ReturnsExpectedColor(byte a, byte r, byte g, byte b)
|
||||
{
|
||||
Color color = Color.FromArgb(a, r, g, b);
|
||||
Assert.Equal(a, color.A);
|
||||
Assert.Equal(r, color.R);
|
||||
Assert.Equal(g, color.G);
|
||||
Assert.Equal(b, color.B);
|
||||
}
|
||||
|
||||
public static IEnumerable<object[]> Equals_TestData()
|
||||
{
|
||||
yield return new object[] { Color.FromArgb(1, 2, 3, 4), Color.FromArgb(1, 2, 3, 4), true };
|
||||
yield return new object[] { Color.FromArgb(1, 2, 3, 4), Color.FromArgb(2, 2, 3, 4), false };
|
||||
yield return new object[] { Color.FromArgb(1, 2, 3, 4), Color.FromArgb(1, 3, 3, 4), false };
|
||||
yield return new object[] { Color.FromArgb(1, 2, 3, 4), Color.FromArgb(1, 2, 4, 4), false };
|
||||
yield return new object[] { Color.FromArgb(1, 2, 3, 4), Color.FromArgb(1, 2, 3, 5), false };
|
||||
|
||||
yield return new object[] { Color.FromArgb(1, 2, 3, 4), new object(), false };
|
||||
yield return new object[] { Color.FromArgb(1, 2, 3, 4), null, false };
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(Equals_TestData))]
|
||||
public void Equals_Other_ReturnsExpected(Color color, object other, bool expected)
|
||||
{
|
||||
Assert.Equal(expected, color.Equals(other));
|
||||
if (other is Color otherColor)
|
||||
{
|
||||
Assert.Equal(expected, color == otherColor);
|
||||
Assert.Equal(!expected, color != otherColor);
|
||||
Assert.Equal(expected, color.Equals(otherColor));
|
||||
Assert.Equal(expected, color.GetHashCode().Equals(other.GetHashCode()));
|
||||
}
|
||||
}
|
||||
|
||||
public static IEnumerable<object[]> ToString_TestData()
|
||||
{
|
||||
yield return new object[] { Color.FromArgb(1, 2, 3, 4), null, null, "#01020304" };
|
||||
yield return new object[] { Color.FromArgb(1, 2, 3, 4), null, CultureInfo.InvariantCulture, "#01020304" };
|
||||
|
||||
yield return new object[] { Color.FromArgb(1, 2, 3, 4), "", CultureInfo.InvariantCulture, "sc#1, 2, 3, 4" };
|
||||
yield return new object[] { Color.FromArgb(1, 2, 3, 4), "abc", null, "sc#abc, abc, abc, abc" };
|
||||
yield return new object[] { Color.FromArgb(1, 2, 3, 4), "D4", CultureInfo.InvariantCulture, "sc#0001, 0002, 0003, 0004" };
|
||||
|
||||
yield return new object[] { Color.FromArgb(1, 2, 3, 4), "", new NumberFormatInfo { NumberDecimalSeparator = "," }, "sc#1; 2; 3; 4" };
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(ToString_TestData))]
|
||||
public void ToString_Invoke_ReturnsExpected(Color color, string format, IFormatProvider formatProvider, string expected)
|
||||
{
|
||||
if (format == null)
|
||||
{
|
||||
if (formatProvider == null)
|
||||
{
|
||||
Assert.Equal(expected, color.ToString());
|
||||
}
|
||||
|
||||
Assert.Equal(expected, color.ToString(formatProvider));
|
||||
}
|
||||
|
||||
Assert.Equal(expected, ((IFormattable)color).ToString(format, formatProvider));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user