Skip to content

Commit df75fe5

Browse files
Adding custom DataObject Tests (#12807)
Co-authored-by: Jeremy Kuhne <[email protected]>
1 parent e3f172f commit df75fe5

File tree

13 files changed

+319
-10
lines changed

13 files changed

+319
-10
lines changed

src/System.Windows.Forms.Analyzers.CSharp/src/System.Windows.Forms.Analyzers.CSharp.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<RootNamespace>System.Windows.Forms.Analyzers</RootNamespace>
4+
<RootNamespace/>
55
<TargetFramework>netstandard2.0</TargetFramework>
66
<LangVersion>Preview</LangVersion>
77
<Nullable>enable</Nullable>

src/System.Windows.Forms.Analyzers.CodeFixes.CSharp/System.Windows.Forms.Analyzers.CodeFixes.CSharp.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<RootNamespace>System.Windows.Forms.Analyzers</RootNamespace>
4+
<RootNamespace/>
55
<TargetFramework>netstandard2.0</TargetFramework>
66
<LangVersion>Preview</LangVersion>
77
<Nullable>enable</Nullable>

src/System.Windows.Forms.Analyzers.CodeFixes.VisualBasic/System.Windows.Forms.Analyzers.CodeFixes.VisualBasic.vbproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<RootNamespace>System.Windows.Forms.Analyzers</RootNamespace>
4+
<RootNamespace/>
55
<TargetFramework>netstandard2.0</TargetFramework>
66
<Deterministic>true</Deterministic>
77
<RootNamespace></RootNamespace>

src/System.Windows.Forms.Analyzers.VisualBasic/src/System.Windows.Forms.Analyzers.VisualBasic.vbproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<RootNamespace>System.Windows.Forms.Analyzers</RootNamespace>
4+
<RootNamespace/>
55
<TargetFramework>netstandard2.0</TargetFramework>
66
<Deterministic>true</Deterministic>
77
<RootNamespace></RootNamespace>

src/System.Windows.Forms.Analyzers/src/System.Windows.Forms.Analyzers.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
<PropertyGroup>
44
<TargetFramework>netstandard2.0</TargetFramework>
5+
<RootNamespace />
56
<LangVersion>Preview</LangVersion>
67
<Nullable>enable</Nullable>
78
<EnforceExtendedAnalyzerRules>true</EnforceExtendedAnalyzerRules>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
#nullable enable
5+
6+
using ComTypes = System.Runtime.InteropServices.ComTypes;
7+
8+
namespace System.Windows.Forms.TestUtilities;
9+
10+
internal class ManagedAndRuntimeDataObject : ManagedDataObject, ComTypes.IDataObject
11+
{
12+
public int DAdvise(ref ComTypes.FORMATETC pFormatetc, ComTypes.ADVF advf, ComTypes.IAdviseSink adviseSink, out int connection) => throw new NotImplementedException();
13+
public void DUnadvise(int connection) => throw new NotImplementedException();
14+
public int EnumDAdvise(out ComTypes.IEnumSTATDATA enumAdvise) => throw new NotImplementedException();
15+
public ComTypes.IEnumFORMATETC EnumFormatEtc(ComTypes.DATADIR direction) => throw new NotImplementedException();
16+
public int GetCanonicalFormatEtc(ref ComTypes.FORMATETC formatIn, out ComTypes.FORMATETC formatOut) => throw new NotImplementedException();
17+
public void GetData(ref ComTypes.FORMATETC format, out ComTypes.STGMEDIUM medium) => throw new NotImplementedException();
18+
public void GetDataHere(ref ComTypes.FORMATETC format, ref ComTypes.STGMEDIUM medium) => throw new NotImplementedException();
19+
public int QueryGetData(ref ComTypes.FORMATETC format) => throw new NotImplementedException();
20+
public void SetData(ref ComTypes.FORMATETC formatIn, ref ComTypes.STGMEDIUM medium, bool release) => throw new NotImplementedException();
21+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
#nullable enable
5+
6+
namespace System.Windows.Forms.TestUtilities;
7+
8+
internal class ManagedDataObject : IDataObject
9+
{
10+
public static string s_format = nameof(SerializableTestData);
11+
protected SerializableTestData? _data;
12+
13+
public object? GetData(string format, bool autoConvert) => format == s_format ? _data : null;
14+
public object? GetData(string format) => format == s_format ? _data : null;
15+
public object? GetData(Type format) => null;
16+
public bool GetDataPresent(string format, bool autoConvert) => format == s_format && _data is not null;
17+
public bool GetDataPresent(string format) => format == s_format && _data is not null;
18+
public bool GetDataPresent(Type format) => false;
19+
public string[] GetFormats(bool autoConvert) => [s_format];
20+
public string[] GetFormats() => [s_format];
21+
public void SetData(string format, bool autoConvert, object? data)
22+
{
23+
if (format == s_format)
24+
{
25+
_data = data as SerializableTestData;
26+
}
27+
}
28+
29+
public void SetData(string format, object? data)
30+
{
31+
if (format == s_format)
32+
{
33+
_data = data as SerializableTestData;
34+
}
35+
}
36+
37+
public void SetData(Type format, object? data) => _data = data as SerializableTestData;
38+
public void SetData(object? data) => _data = data as SerializableTestData;
39+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
#nullable enable
5+
6+
namespace System.Windows.Forms.TestUtilities;
7+
8+
[Serializable]
9+
public class SerializableTestData
10+
{
11+
public string Text { get; } = "a";
12+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
#nullable enable
5+
6+
using System.Diagnostics.CodeAnalysis;
7+
using System.Reflection.Metadata;
8+
9+
namespace System.Windows.Forms.TestUtilities;
10+
11+
internal class TypedAndRuntimeDataObject : ManagedAndRuntimeDataObject, ITypedDataObject
12+
{
13+
public bool TryGetData<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] T>([MaybeNullWhen(false), NotNullWhen(true)] out T data) =>
14+
throw new NotImplementedException();
15+
public bool TryGetData<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] T>(string format, [MaybeNullWhen(false), NotNullWhen(true)] out T data)
16+
{
17+
data = default;
18+
if (format == s_format && _data is T t)
19+
{
20+
data = t;
21+
return true;
22+
}
23+
24+
return false;
25+
}
26+
27+
public bool TryGetData<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] T>(string format, bool autoConvert, [MaybeNullWhen(false), NotNullWhen(true)] out T data) =>
28+
throw new NotImplementedException();
29+
public bool TryGetData<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] T>(string format, Func<TypeName, Type> resolver, bool autoConvert, [MaybeNullWhen(false), NotNullWhen(true)] out T data) =>
30+
throw new NotImplementedException();
31+
}

0 commit comments

Comments
 (0)