4a927df56cdf68771472c97b56cb7316e66cf930
[platform/upstream/dotnet/runtime.git] /
1 //using System.Runtime.InteropServices.Tests.Common;
2 using Xunit;
3
4 namespace System.Runtime.InteropServices.Tests
5 {
6     [PlatformSpecific(TestPlatforms.Windows)]
7     public partial class MarshalComDisabledTests
8     {
9         [Fact]
10         public void GetTypeFromCLSID_ThrowsNotSupportedException()
11         {
12             Assert.Throws<NotSupportedException>(() => Marshal.GetTypeFromCLSID(Guid.Empty));
13         }
14
15         [Fact]
16         public void CreateAggregatedObject_ThrowsNotSupportedException()
17         {
18             object value = new object();
19             Assert.Throws<NotSupportedException>(() => Marshal.CreateAggregatedObject(IntPtr.Zero, value));
20         }
21
22         [Fact]
23         public void CreateAggregatedObject_T_ThrowsNotSupportedException()
24         {
25             object value = new object();
26             Assert.Throws<NotSupportedException>(() => Marshal.CreateAggregatedObject<object>(IntPtr.Zero, value));
27         }
28
29
30         [Fact]
31         public void ReleaseComObject_ThrowsNotSupportedException()
32         {
33             Assert.Throws<NotSupportedException>(() => Marshal.ReleaseComObject(new object()));
34         }
35         
36         [Fact]
37         public void FinalReleaseComObject_ThrowsNotSupportedException()
38         {
39             Assert.Throws<NotSupportedException>(() => Marshal.FinalReleaseComObject(new object()));
40         }        
41
42         [Fact]
43         public void GetComObjectData_ThrowsNotSupportedException()
44         {
45             Assert.Throws<NotSupportedException>(() => Marshal.GetComObjectData("key", "value"));
46         }        
47
48         [Fact]
49         public void SetComObjectData_ThrowsNotSupportedException()
50         {
51             Assert.Throws<NotSupportedException>(() => Marshal.SetComObjectData(new object(), "key", "value"));
52         }        
53
54         [Fact]
55         public void CreateWrapperOfType_ThrowsNotSupportedException()
56         {
57             Assert.Throws<NotSupportedException>(() => Marshal.CreateWrapperOfType(new object(), typeof(object)));
58         }        
59
60         [Fact]
61         public void CreateWrapperOfType_T_TWrapper_ThrowsNotSupportedException()
62         {
63             Assert.Throws<NotSupportedException>(() => Marshal.CreateWrapperOfType<object, object>(new object()));
64         }        
65
66         [Fact]
67         public void GetNativeVariantForObject_ThrowsNotSupportedException()
68         {
69             Assert.Throws<NotSupportedException>(() => Marshal.GetNativeVariantForObject(99, IntPtr.Zero));
70         }
71
72         [Fact]
73         public void GetNativeVariantForObject_T_ThrowsNotSupportedException()
74         {
75             Assert.Throws<NotSupportedException>(() => Marshal.GetNativeVariantForObject<double>(99, IntPtr.Zero));
76         }
77
78         public struct NativeVariant{}
79
80         [Fact]
81         public void GetObjectForNativeVariant_ThrowsNotSupportedException()
82         {
83             NativeVariant variant = new NativeVariant();
84             IntPtr ptr = Marshal.AllocHGlobal(Marshal.SizeOf<NativeVariant>());
85             try
86             {
87                 Marshal.StructureToPtr(variant, ptr, fDeleteOld: false);
88                 Assert.Throws<NotSupportedException>(() => Marshal.GetObjectForNativeVariant(ptr));
89             }
90             finally
91             {
92                 Marshal.DestroyStructure<NativeVariant>(ptr);
93                 Marshal.FreeHGlobal(ptr);
94             }
95         }        
96
97         public struct NativeVariant_T{}
98
99         [Fact]
100         public void GetObjectForNativeVariant_T_ThrowsNotSupportedException()
101         {
102             NativeVariant_T variant = new NativeVariant_T();
103             IntPtr ptr = Marshal.AllocHGlobal(Marshal.SizeOf<NativeVariant_T>());
104             try
105             {
106                 Marshal.StructureToPtr(variant, ptr, fDeleteOld: false);
107                 Assert.Throws<NotSupportedException>(() => Marshal.GetObjectForNativeVariant<NativeVariant_T>(ptr));
108             }
109             finally
110             {
111                 Marshal.DestroyStructure<NativeVariant_T>(ptr);
112                 Marshal.FreeHGlobal(ptr);
113             }
114         }        
115
116         [Fact]
117         public void GetObjectsForNativeVariants_ThrowsNotSupportedException()
118         {
119             IntPtr ptr = Marshal.AllocHGlobal(2 * Marshal.SizeOf<NativeVariant>());
120             try
121             {
122                 Assert.Throws<NotSupportedException>(() => Marshal.GetObjectsForNativeVariants(ptr, 2));
123             }
124             finally
125             {
126                 Marshal.FreeHGlobal(ptr);
127             }
128         }        
129
130         [Fact]
131         public void GetObjectsForNativeVariants_T_ThrowsNotSupportedException()
132         {
133             IntPtr ptr = Marshal.AllocHGlobal(2 * Marshal.SizeOf<NativeVariant_T>());
134             try
135             {
136                 Assert.Throws<NotSupportedException>(() => Marshal.GetObjectsForNativeVariants<sbyte>(ptr, 2));
137             }
138             finally
139             {
140                 Marshal.FreeHGlobal(ptr);
141             }
142         }        
143
144         [Fact]
145         public void BindToMoniker_ThrowsNotSupportedException()
146         {            
147             Assert.Throws<NotSupportedException>(() => Marshal.BindToMoniker("test"));
148         }        
149
150         [Fact]
151         public void GetIUnknownForObject_ThrowsNotSupportedException()
152         {
153             Assert.Throws<NotSupportedException>(() => Marshal.GetIUnknownForObject(new object()));
154         }        
155
156         [Fact]
157         public void GetIDispatchForObject_ThrowsNotSupportedException()
158         {
159             Assert.Throws<NotSupportedException>(() => Marshal.GetIDispatchForObject(new object()));
160         }        
161
162         public struct StructForIUnknown{}
163
164         [Fact]
165         public void GetObjectForIUnknown_ThrowsNotSupportedException()
166         {
167             StructForIUnknown test = new StructForIUnknown();
168             IntPtr ptr = Marshal.AllocHGlobal(Marshal.SizeOf<StructForIUnknown>());
169             try
170             {
171                 Marshal.StructureToPtr(test, ptr, fDeleteOld: false);
172                 Assert.Throws<NotSupportedException>(() => Marshal.GetObjectForIUnknown(ptr));
173             }
174             finally
175             {
176                 Marshal.DestroyStructure<StructForIUnknown>(ptr);
177                 Marshal.FreeHGlobal(ptr);
178             }
179         }        
180     }
181 }