Skip to content

Commit 78e9abd

Browse files
committed
Fix DllImportGenerator unit tests
1 parent 2ecc899 commit 78e9abd

File tree

3 files changed

+26
-28
lines changed

3 files changed

+26
-28
lines changed

src/libraries/System.Runtime.InteropServices/tests/DllImportGenerator.UnitTests/AdditionalAttributesOnStub.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ struct S
3131
{
3232
}
3333
34+
[CustomTypeMarshaller(typeof(S))]
3435
struct Native
3536
{
3637
public Native(S s) { }
@@ -120,6 +121,7 @@ struct S
120121
{
121122
}
122123
124+
[CustomTypeMarshaller(typeof(S))]
123125
struct Native
124126
{
125127
public Native(S s) { }
@@ -152,6 +154,7 @@ struct S
152154
{
153155
}
154156
157+
[CustomTypeMarshaller(typeof(S))]
155158
struct Native
156159
{
157160
public Native(S s) { }
@@ -184,6 +187,7 @@ struct S
184187
{
185188
}
186189
190+
[CustomTypeMarshaller(typeof(S))]
187191
struct Native
188192
{
189193
public Native(S s) { }

src/libraries/System.Runtime.InteropServices/tests/DllImportGenerator.UnitTests/AttributeForwarding.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ struct S
3838
{{
3939
}}
4040
41+
[CustomTypeMarshaller(typeof(S))]
4142
struct Native
4243
{{
4344
public Native(S s) {{ }}
@@ -79,6 +80,7 @@ struct S
7980
{
8081
}
8182
83+
[CustomTypeMarshaller(typeof(S))]
8284
struct Native
8385
{
8486
public Native(S s) { }
@@ -122,6 +124,7 @@ struct S
122124
{
123125
}
124126
127+
[CustomTypeMarshaller(typeof(S))]
125128
struct Native
126129
{
127130
public Native(S s) { }
@@ -169,6 +172,7 @@ struct S
169172
{
170173
}
171174
175+
[CustomTypeMarshaller(typeof(S))]
172176
struct Native
173177
{
174178
public Native(S s) { }
@@ -224,6 +228,7 @@ struct S
224228
{
225229
}
226230
231+
[CustomTypeMarshaller(typeof(S))]
227232
struct Native
228233
{
229234
public Native(S s) { }

src/libraries/System.Runtime.InteropServices/tests/DllImportGenerator.UnitTests/CodeSnippets.cs

Lines changed: 17 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -593,7 +593,7 @@ struct S
593593
public bool b;
594594
}
595595
596-
[CustomTypeMarshaller]
596+
[CustomTypeMarshaller(typeof(S))]
597597
struct Native
598598
{
599599
private int i;
@@ -612,6 +612,7 @@ struct S
612612
public bool b;
613613
}
614614
615+
[CustomTypeMarshaller(typeof(S))]
615616
struct Native
616617
{
617618
private int i;
@@ -631,7 +632,7 @@ struct S
631632
public bool b;
632633
}
633634
634-
[CustomTypeMarshaller]
635+
[CustomTypeMarshaller(typeof(S), BufferSize = 1)]
635636
struct Native
636637
{
637638
private int i;
@@ -641,8 +642,6 @@ public Native(S s, System.Span<byte> b)
641642
}
642643
643644
public S ToManaged() => new S { b = i != 0 };
644-
645-
public const int BufferSize = 1;
646645
}
647646
";
648647
public static string CustomStructMarshallingStackallocOnlyRefParameter = BasicParameterWithByRefModifier("ref", "S", DisableRuntimeMarshalling) + @"
@@ -652,7 +651,7 @@ struct S
652651
public bool b;
653652
}
654653
655-
[CustomTypeMarshaller]
654+
[CustomTypeMarshaller(typeof(S), BufferSize = 1, RequiresStackBuffer = false)]
656655
struct Native
657656
{
658657
private int i;
@@ -662,9 +661,6 @@ public Native(S s, System.Span<byte> b)
662661
}
663662
664663
public S ToManaged() => new S { b = i != 0 };
665-
666-
public const int BufferSize = 1;
667-
public const bool RequiresStackBuffer = false;
668664
}
669665
";
670666
public static string CustomStructMarshallingOptionalStackallocParametersAndModifiers = BasicParametersAndModifiers("S", DisableRuntimeMarshalling) + @"
@@ -674,7 +670,7 @@ struct S
674670
public bool b;
675671
}
676672
677-
[CustomTypeMarshaller]
673+
[CustomTypeMarshaller(typeof(S), BufferSize = 1, RequiresStackBuffer = true)]
678674
struct Native
679675
{
680676
private int i;
@@ -688,9 +684,6 @@ public Native(S s)
688684
}
689685
690686
public S ToManaged() => new S { b = i != 0 };
691-
692-
public const int BufferSize = 1;
693-
public const bool RequiresStackBuffer = true;
694687
}
695688
";
696689

@@ -701,7 +694,7 @@ struct S
701694
public bool b;
702695
}
703696
704-
[CustomTypeMarshaller]
697+
[CustomTypeMarshaller(typeof(S), BufferSize = 1)]
705698
struct Native
706699
{
707700
public Native(S s, System.Span<byte> b)
@@ -712,8 +705,6 @@ public Native(S s, System.Span<byte> b)
712705
public S ToManaged() => new S { b = Value != 0 };
713706
714707
public int Value { get; set; }
715-
716-
public const int BufferSize = 1;
717708
}
718709
";
719710
public static string CustomStructMarshallingValuePropertyParametersAndModifiers = BasicParametersAndModifiers("S", DisableRuntimeMarshalling) + @"
@@ -723,7 +714,7 @@ struct S
723714
public bool b;
724715
}
725716
726-
[CustomTypeMarshaller]
717+
[CustomTypeMarshaller(typeof(S))]
727718
struct Native
728719
{
729720
public Native(S s)
@@ -745,7 +736,7 @@ class S
745736
public ref int GetPinnableReference() => ref i;
746737
}
747738
748-
[CustomTypeMarshaller]
739+
[CustomTypeMarshaller(typeof(S))]
749740
unsafe struct Native
750741
{
751742
private int* ptr;
@@ -777,7 +768,7 @@ class S
777768
public byte c;
778769
}
779770
780-
[CustomTypeMarshaller]
771+
[CustomTypeMarshaller(typeof(S), BufferSize = 1)]
781772
unsafe ref struct Native
782773
{
783774
private byte* ptr;
@@ -815,8 +806,6 @@ public void FreeNative()
815806
Marshal.FreeCoTaskMem((IntPtr)ptr);
816807
}
817808
}
818-
819-
public const int BufferSize = 1;
820809
}
821810
822811
partial class Test
@@ -835,7 +824,7 @@ class S
835824
public byte c = 0;
836825
}
837826
838-
[CustomTypeMarshaller]
827+
[CustomTypeMarshaller(typeof(S))]
839828
unsafe struct Native
840829
{
841830
private S value;
@@ -886,7 +875,7 @@ struct S
886875
public bool b;
887876
}
888877
889-
[CustomTypeMarshaller]
878+
[CustomTypeMarshaller(typeof(S))]
890879
struct Native
891880
{
892881
private int i;
@@ -905,7 +894,7 @@ struct S
905894
public bool b;
906895
}
907896
908-
[CustomTypeMarshaller]
897+
[CustomTypeMarshaller(typeof(S))]
909898
struct Native
910899
{
911900
private int i;
@@ -938,7 +927,7 @@ public struct IntStructWrapper
938927
public int Value;
939928
}
940929
941-
[CustomTypeMarshaller]
930+
[CustomTypeMarshaller(typeof(IntStructWrapper))]
942931
public struct IntStructWrapperNative
943932
{
944933
public IntStructWrapperNative(IntStructWrapper managed)
@@ -959,7 +948,7 @@ public struct IntStructWrapper
959948
public int Value;
960949
}
961950
962-
[CustomTypeMarshaller]
951+
[CustomTypeMarshaller(typeof(IntStructWrapper))]
963952
public struct IntStructWrapperNative
964953
{
965954
private int value;
@@ -1085,7 +1074,7 @@ public static string CollectionByValue(string elementType) => BasicParameterByVa
10851074
[NativeMarshalling(typeof(Marshaller<>))]
10861075
class TestCollection<T> {}
10871076
1088-
[CustomTypeMarshaller(CustomTypeMarshallerKind.SpanCollection)]
1077+
[CustomTypeMarshaller(typeof(TestCollection<>), CustomTypeMarshallerKind.SpanCollection)]
10891078
ref struct Marshaller<T>
10901079
{
10911080
public Marshaller(TestCollection<T> managed, int nativeElementSize) : this() {}
@@ -1119,7 +1108,7 @@ public static string CustomCollectionWithMarshaller(bool enableDefaultMarshallin
11191108
string nativeMarshallingAttribute = enableDefaultMarshalling ? "[NativeMarshalling(typeof(Marshaller<>))]" : string.Empty;
11201109
return nativeMarshallingAttribute + @"class TestCollection<T> {}
11211110
1122-
[CustomTypeMarshaller(CustomTypeMarshallerKind.SpanCollection)]
1111+
[CustomTypeMarshaller(typeof(TestCollection<>), CustomTypeMarshallerKind.SpanCollection)]
11231112
ref struct Marshaller<T>
11241113
{
11251114
public Marshaller(int nativeElementSize) : this() {}
@@ -1216,7 +1205,7 @@ public static partial void Method(
12161205
[NativeMarshalling(typeof(Marshaller<,>))]
12171206
class TestCollection<T> {}
12181207
1219-
[CustomTypeMarshaller(CustomTypeMarshallerKind.SpanCollection)]
1208+
[CustomTypeMarshaller(typeof(TestCollection<>), CustomTypeMarshallerKind.SpanCollection)]
12201209
ref struct Marshaller<T, U>
12211210
{
12221211
public Marshaller(TestCollection<T> managed, int nativeElementSize) : this() {}

0 commit comments

Comments
 (0)