-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Expand file tree
/
Copy pathIPictureTests.cs
More file actions
91 lines (78 loc) · 3.34 KB
/
Copy pathIPictureTests.cs
File metadata and controls
91 lines (78 loc) · 3.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System.Drawing;
using System.Windows.Forms.Primitives.Tests.Interop.Mocks;
using Windows.Win32.Graphics.GdiPlus;
using Windows.Win32.System.Com;
using Windows.Win32.System.Ole;
using Windows.Win32.System.Variant;
namespace System.Windows.Forms.Primitives.Tests.Interop.Ole32;
[Collection("Sequential")]
public unsafe class IPictureTests
{
[StaFact]
public void GetIPictureFromCursor()
{
using MockCursor arrow = new(PInvoke.IDC_ARROW);
using var picture = Icon.FromHandle(arrow.Handle).CreateIPicture(copy: true);
Assert.False(picture.IsNull);
picture.Value->get_Type(out PICTYPE type);
Assert.Equal(PICTYPE.PICTYPE_ICON, type);
picture.Value->get_Height(out int height);
Assert.Equal(arrow.Size.Height, GdiHelper.HimetricToPixelY(height));
picture.Value->get_Width(out int width);
Assert.Equal(arrow.Size.Width, GdiHelper.HimetricToPixelX(width));
}
[StaFact]
public void GetIPictureFromImage()
{
using MockCursor arrow = new(PInvoke.IDC_ARROW);
using Icon icon = Icon.FromHandle(arrow.Handle);
using Bitmap bitmap = icon.ToBitmap();
using var picture = bitmap.CreateIPicture();
Assert.False(picture.IsNull);
picture.Value->get_Type(out PICTYPE type);
Assert.Equal(PICTYPE.PICTYPE_BITMAP, type);
picture.Value->get_Height(out int height);
Assert.Equal(bitmap.Size.Height, GdiHelper.HimetricToPixelY(height));
picture.Value->get_Width(out int width);
Assert.Equal(bitmap.Size.Width, GdiHelper.HimetricToPixelX(width));
}
[StaFact]
public void GetIPictureDispFromImage()
{
using Icon icon = SystemIcons.Question;
using Bitmap bitmap = icon.ToBitmap();
using var picture = bitmap.CreateIPictureDisp();
Assert.False(picture.IsNull);
using VARIANT variant = default;
IDispatch* dispatch = (IDispatch*)picture.Value;
dispatch->TryGetProperty(PInvokeCore.DISPID_PICT_TYPE, &variant).ThrowOnFailure();
Assert.Equal(PICTYPE.PICTYPE_BITMAP, (PICTYPE)variant.data.iVal);
dispatch->TryGetProperty(PInvokeCore.DISPID_PICT_HEIGHT, &variant).ThrowOnFailure();
Assert.Equal(bitmap.Size.Height, GdiHelper.HimetricToPixelY((int)variant.data.uintVal));
dispatch->TryGetProperty(PInvokeCore.DISPID_PICT_WIDTH, &variant).ThrowOnFailure();
Assert.Equal(bitmap.Size.Width, GdiHelper.HimetricToPixelX((int)variant.data.uintVal));
}
[StaFact]
public void GetPictureFromIPicture()
{
using Icon icon = SystemIcons.Exclamation;
using Bitmap bitmap = icon.ToBitmap();
using var picture = bitmap.CreateIPicture();
Assert.False(picture.IsNull);
using Image? image = ImageExtensions.ToImage(picture);
Assert.NotNull(image);
Assert.Equal(bitmap.Size, image.Size);
}
[StaFact]
public void GetPictureFromIPictureDisp()
{
using Bitmap bitmap = new(100, 200);
using var picture = bitmap.CreateIPictureDisp();
Assert.False(picture.IsNull);
using Image? image = ImageExtensions.ToImage(picture);
Assert.NotNull(image);
Assert.Equal(bitmap.Size, image.Size);
}
}