1 //using System.Runtime.InteropServices.Tests.Common;
4 namespace System.Runtime.InteropServices.Tests
6 [PlatformSpecific(TestPlatforms.Windows)]
7 public partial class MarshalComDisabledTests
10 public void GetTypeFromCLSID_ThrowsNotSupportedException()
12 Assert.Throws<NotSupportedException>(() => Marshal.GetTypeFromCLSID(Guid.Empty));
16 public void CreateAggregatedObject_ThrowsNotSupportedException()
18 object value = new object();
19 Assert.Throws<NotSupportedException>(() => Marshal.CreateAggregatedObject(IntPtr.Zero, value));
23 public void CreateAggregatedObject_T_ThrowsNotSupportedException()
25 object value = new object();
26 Assert.Throws<NotSupportedException>(() => Marshal.CreateAggregatedObject<object>(IntPtr.Zero, value));
31 public void ReleaseComObject_ThrowsNotSupportedException()
33 Assert.Throws<NotSupportedException>(() => Marshal.ReleaseComObject(new object()));
37 public void FinalReleaseComObject_ThrowsNotSupportedException()
39 Assert.Throws<NotSupportedException>(() => Marshal.FinalReleaseComObject(new object()));
43 public void GetComObjectData_ThrowsNotSupportedException()
45 Assert.Throws<NotSupportedException>(() => Marshal.GetComObjectData("key", "value"));
49 public void SetComObjectData_ThrowsNotSupportedException()
51 Assert.Throws<NotSupportedException>(() => Marshal.SetComObjectData(new object(), "key", "value"));
55 public void CreateWrapperOfType_ThrowsNotSupportedException()
57 Assert.Throws<NotSupportedException>(() => Marshal.CreateWrapperOfType(new object(), typeof(object)));
61 public void CreateWrapperOfType_T_TWrapper_ThrowsNotSupportedException()
63 Assert.Throws<NotSupportedException>(() => Marshal.CreateWrapperOfType<object, object>(new object()));
67 public void GetNativeVariantForObject_ThrowsNotSupportedException()
69 Assert.Throws<NotSupportedException>(() => Marshal.GetNativeVariantForObject(99, IntPtr.Zero));
73 public void GetNativeVariantForObject_T_ThrowsNotSupportedException()
75 Assert.Throws<NotSupportedException>(() => Marshal.GetNativeVariantForObject<double>(99, IntPtr.Zero));
78 public struct NativeVariant{}
81 public void GetObjectForNativeVariant_ThrowsNotSupportedException()
83 NativeVariant variant = new NativeVariant();
84 IntPtr ptr = Marshal.AllocHGlobal(Marshal.SizeOf<NativeVariant>());
87 Marshal.StructureToPtr(variant, ptr, fDeleteOld: false);
88 Assert.Throws<NotSupportedException>(() => Marshal.GetObjectForNativeVariant(ptr));
92 Marshal.DestroyStructure<NativeVariant>(ptr);
93 Marshal.FreeHGlobal(ptr);
97 public struct NativeVariant_T{}
100 public void GetObjectForNativeVariant_T_ThrowsNotSupportedException()
102 NativeVariant_T variant = new NativeVariant_T();
103 IntPtr ptr = Marshal.AllocHGlobal(Marshal.SizeOf<NativeVariant_T>());
106 Marshal.StructureToPtr(variant, ptr, fDeleteOld: false);
107 Assert.Throws<NotSupportedException>(() => Marshal.GetObjectForNativeVariant<NativeVariant_T>(ptr));
111 Marshal.DestroyStructure<NativeVariant_T>(ptr);
112 Marshal.FreeHGlobal(ptr);
117 public void GetObjectsForNativeVariants_ThrowsNotSupportedException()
119 IntPtr ptr = Marshal.AllocHGlobal(2 * Marshal.SizeOf<NativeVariant>());
122 Assert.Throws<NotSupportedException>(() => Marshal.GetObjectsForNativeVariants(ptr, 2));
126 Marshal.FreeHGlobal(ptr);
131 public void GetObjectsForNativeVariants_T_ThrowsNotSupportedException()
133 IntPtr ptr = Marshal.AllocHGlobal(2 * Marshal.SizeOf<NativeVariant_T>());
136 Assert.Throws<NotSupportedException>(() => Marshal.GetObjectsForNativeVariants<sbyte>(ptr, 2));
140 Marshal.FreeHGlobal(ptr);
145 public void BindToMoniker_ThrowsNotSupportedException()
147 Assert.Throws<NotSupportedException>(() => Marshal.BindToMoniker("test"));
151 public void GetIUnknownForObject_ThrowsNotSupportedException()
153 Assert.Throws<NotSupportedException>(() => Marshal.GetIUnknownForObject(new object()));
157 public void GetIDispatchForObject_ThrowsNotSupportedException()
159 Assert.Throws<NotSupportedException>(() => Marshal.GetIDispatchForObject(new object()));
162 public struct StructForIUnknown{}
165 public void GetObjectForIUnknown_ThrowsNotSupportedException()
167 StructForIUnknown test = new StructForIUnknown();
168 IntPtr ptr = Marshal.AllocHGlobal(Marshal.SizeOf<StructForIUnknown>());
171 Marshal.StructureToPtr(test, ptr, fDeleteOld: false);
172 Assert.Throws<NotSupportedException>(() => Marshal.GetObjectForIUnknown(ptr));
176 Marshal.DestroyStructure<StructForIUnknown>(ptr);
177 Marshal.FreeHGlobal(ptr);