forked from dotnet/winforms
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding custom DataObject Tests (dotnet#12807)
Co-authored-by: Jeremy Kuhne <[email protected]>
- Loading branch information
1 parent
e3f172f
commit df75fe5
Showing
13 changed files
with
319 additions
and
10 deletions.
There are no files selected for viewing
2 changes: 1 addition & 1 deletion
2
src/System.Windows.Forms.Analyzers.CSharp/src/System.Windows.Forms.Analyzers.CSharp.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...s.Forms.Analyzers.CodeFixes.CSharp/System.Windows.Forms.Analyzers.CodeFixes.CSharp.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...alyzers.CodeFixes.VisualBasic/System.Windows.Forms.Analyzers.CodeFixes.VisualBasic.vbproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...Windows.Forms.Analyzers.VisualBasic/src/System.Windows.Forms.Analyzers.VisualBasic.vbproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
21 changes: 21 additions & 0 deletions
21
src/System.Windows.Forms/tests/TestUtilities/Data/ManagedAndRuntimeDataObject.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
#nullable enable | ||
|
||
using ComTypes = System.Runtime.InteropServices.ComTypes; | ||
|
||
namespace System.Windows.Forms.TestUtilities; | ||
|
||
internal class ManagedAndRuntimeDataObject : ManagedDataObject, ComTypes.IDataObject | ||
{ | ||
public int DAdvise(ref ComTypes.FORMATETC pFormatetc, ComTypes.ADVF advf, ComTypes.IAdviseSink adviseSink, out int connection) => throw new NotImplementedException(); | ||
public void DUnadvise(int connection) => throw new NotImplementedException(); | ||
public int EnumDAdvise(out ComTypes.IEnumSTATDATA enumAdvise) => throw new NotImplementedException(); | ||
public ComTypes.IEnumFORMATETC EnumFormatEtc(ComTypes.DATADIR direction) => throw new NotImplementedException(); | ||
public int GetCanonicalFormatEtc(ref ComTypes.FORMATETC formatIn, out ComTypes.FORMATETC formatOut) => throw new NotImplementedException(); | ||
public void GetData(ref ComTypes.FORMATETC format, out ComTypes.STGMEDIUM medium) => throw new NotImplementedException(); | ||
public void GetDataHere(ref ComTypes.FORMATETC format, ref ComTypes.STGMEDIUM medium) => throw new NotImplementedException(); | ||
public int QueryGetData(ref ComTypes.FORMATETC format) => throw new NotImplementedException(); | ||
public void SetData(ref ComTypes.FORMATETC formatIn, ref ComTypes.STGMEDIUM medium, bool release) => throw new NotImplementedException(); | ||
} |
39 changes: 39 additions & 0 deletions
39
src/System.Windows.Forms/tests/TestUtilities/Data/ManagedDataObject.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
#nullable enable | ||
|
||
namespace System.Windows.Forms.TestUtilities; | ||
|
||
internal class ManagedDataObject : IDataObject | ||
{ | ||
public static string s_format = nameof(SerializableTestData); | ||
protected SerializableTestData? _data; | ||
|
||
public object? GetData(string format, bool autoConvert) => format == s_format ? _data : null; | ||
public object? GetData(string format) => format == s_format ? _data : null; | ||
public object? GetData(Type format) => null; | ||
public bool GetDataPresent(string format, bool autoConvert) => format == s_format && _data is not null; | ||
public bool GetDataPresent(string format) => format == s_format && _data is not null; | ||
public bool GetDataPresent(Type format) => false; | ||
public string[] GetFormats(bool autoConvert) => [s_format]; | ||
public string[] GetFormats() => [s_format]; | ||
public void SetData(string format, bool autoConvert, object? data) | ||
{ | ||
if (format == s_format) | ||
{ | ||
_data = data as SerializableTestData; | ||
} | ||
} | ||
|
||
public void SetData(string format, object? data) | ||
{ | ||
if (format == s_format) | ||
{ | ||
_data = data as SerializableTestData; | ||
} | ||
} | ||
|
||
public void SetData(Type format, object? data) => _data = data as SerializableTestData; | ||
public void SetData(object? data) => _data = data as SerializableTestData; | ||
} |
12 changes: 12 additions & 0 deletions
12
src/System.Windows.Forms/tests/TestUtilities/Data/SerializableTestData.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
#nullable enable | ||
|
||
namespace System.Windows.Forms.TestUtilities; | ||
|
||
[Serializable] | ||
public class SerializableTestData | ||
{ | ||
public string Text { get; } = "a"; | ||
} |
31 changes: 31 additions & 0 deletions
31
src/System.Windows.Forms/tests/TestUtilities/Data/TypedAndRuntimeDataObject.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
#nullable enable | ||
|
||
using System.Diagnostics.CodeAnalysis; | ||
using System.Reflection.Metadata; | ||
|
||
namespace System.Windows.Forms.TestUtilities; | ||
|
||
internal class TypedAndRuntimeDataObject : ManagedAndRuntimeDataObject, ITypedDataObject | ||
{ | ||
public bool TryGetData<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] T>([MaybeNullWhen(false), NotNullWhen(true)] out T data) => | ||
throw new NotImplementedException(); | ||
public bool TryGetData<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] T>(string format, [MaybeNullWhen(false), NotNullWhen(true)] out T data) | ||
{ | ||
data = default; | ||
if (format == s_format && _data is T t) | ||
{ | ||
data = t; | ||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
public bool TryGetData<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] T>(string format, bool autoConvert, [MaybeNullWhen(false), NotNullWhen(true)] out T data) => | ||
throw new NotImplementedException(); | ||
public bool TryGetData<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] T>(string format, Func<TypeName, Type> resolver, bool autoConvert, [MaybeNullWhen(false), NotNullWhen(true)] out T data) => | ||
throw new NotImplementedException(); | ||
} |
31 changes: 31 additions & 0 deletions
31
src/System.Windows.Forms/tests/TestUtilities/Data/TypedDataObject.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
#nullable enable | ||
|
||
using System.Diagnostics.CodeAnalysis; | ||
using System.Reflection.Metadata; | ||
|
||
namespace System.Windows.Forms.TestUtilities; | ||
|
||
internal class TypedDataObject : ManagedDataObject, ITypedDataObject | ||
{ | ||
public bool TryGetData<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] T>([MaybeNullWhen(false), NotNullWhen(true)] out T data) => | ||
throw new NotImplementedException(); | ||
public bool TryGetData<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] T>(string format, [MaybeNullWhen(false), NotNullWhen(true)] out T data) | ||
{ | ||
data = default; | ||
if (format == s_format && _data is T t) | ||
{ | ||
data = t; | ||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
public bool TryGetData<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] T>(string format, bool autoConvert, [MaybeNullWhen(false), NotNullWhen(true)] out T data) => | ||
throw new NotImplementedException(); | ||
public bool TryGetData<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] T>(string format, Func<TypeName, Type> resolver, bool autoConvert, [MaybeNullWhen(false), NotNullWhen(true)] out T data) => | ||
throw new NotImplementedException(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.