Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyWinVirtualDesktop/shobjidl_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
)

CLSID_VirtualDesktopManager = GUID(
'{AA509086-5CA9-4C25-8f95-589D3C07B48A}'
'{AA509086-5CA9-4C25-8F95-589D3C07B48A}'
)

IID_IVirtualDesktopManager = GUID(
Expand Down
371 changes: 371 additions & 0 deletions tests/fixtures.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,371 @@
import ctypes

from collections import namedtuple
from ctypes import HRESULT, POINTER
from ctypes.wintypes import BOOL, BYTE, FLOAT, INT, ULONG

import pytest
from comtypes.GUID import GUID

import pyWinVirtualDesktop


Enum = namedtuple("Enum", "module name fields")
EnumField = namedtuple("EnumField", "name value")

Interface = namedtuple("Interface", "module name case_insensitive_ iid_ idlflags_ methods_")
Method = namedtuple("Method", "restype name argtypes paramflags")

Structure = namedtuple("Structure", "module name fields")
StructureField = namedtuple("StructureField", "name type")

Uid = namedtuple("Uid", "module name value")

BASETRUST = EnumField("BaseTrust", 0)
PARTIALTRUST = EnumField("PartialTrust", BASETRUST.value + 1)

IID = GUID

# NOTE get a paramflag by addition of its components values: ["out", "retval"] gives 8
# _PARAMFLAGS = {"in": 1, "out": 2, "lcid": 4, "retval": 8, "optional": 16}

## HELPERS
def get_attr(module, name):
"""Returns attribute with the ``name`` from provided ``module``."""
return getattr(getattr(pyWinVirtualDesktop.__original_module__, module), name)


def get_class(module, name):
"""Returns class with the ``name`` from provided ``module``."""
return get_attr(module, name)


## DATA
def clsids():
"""Returns all the CLSID instances defined as ``Uid`` named tuple

:returns: list
"""
return [
Uid("servprov", "ImmersiveShell", "C2F03A33-21F5-47FA-B4BB-156362A2F239"),
Uid(
"shobjidl_core",
"VirtualDesktopNotificationService",
"A501FDEC-4A09-464C-AE4E-1B9C21B84918",
),
Uid(
"shobjidl_core",
"VirtualDesktopManagerInternal",
"C5E0CDCA-7B6E-41B2-9FC4-D93975CC467B",
),
Uid(
"shobjidl_core",
"VirtualDesktopManager",
"AA509086-5CA9-4C25-8F95-589D3C07B48A",
),
Uid(
"shobjidl_core",
"VirtualDesktopPinnedApps",
"B5A399E7-1C87-46B8-88E9-FC5747B171BD",
),
Uid(
"windows_ui_viewmanagement",
"ApplicationViewCollection",
"1841C6D7-4F9D-42C0-AF41-8747538F10E5",
),
]


def enums():
"""Returns all the enums defined as ``Enum`` named tuple

and with ``field`` (third element) as tuple of ``EnumField`` named tuples.

:returns: list
"""
return [
Enum(
"inspectable",
"TrustLevel",
(BASETRUST, PARTIALTRUST, EnumField("FullTrust", PARTIALTRUST.value + 1)),
),
Enum(
"shobjidl_core",
"AdjacentDesktop",
(EnumField("LeftDirection", 3), EnumField("RightDirection", 4)),
),
Enum(
"windows_ui_viewmanagement",
"ApplicationViewOrientation",
(
EnumField("ApplicationViewOrientation_Landscape", 0),
EnumField("ApplicationViewOrientation_Portrait", 1),
),
),
Enum(
"windows_ui_viewmanagement",
"ApplicationViewBoundsMode",
(
EnumField("ApplicationViewBoundsMode_UseVisible", 0),
EnumField("ApplicationViewBoundsMode_UseCoreWindow", 1),
),
),
Enum(
"windows_ui_viewmanagement",
"FullScreenSystemOverlayMode",
(
EnumField("FullScreenSystemOverlayMode_Standard", 0),
EnumField("FullScreenSystemOverlayMode_Minimal", 1),
),
),
Enum(
"windows_ui_viewmanagement",
"ApplicationViewMode",
(
EnumField("ApplicationViewMode_Default", 0),
EnumField("ApplicationViewMode_CompactOverlay", 1),
),
),
Enum(
"windows_ui_viewmanagement",
"ViewSizePreference",
(
EnumField("ViewSizePreference_Default", 0),
EnumField("ViewSizePreference_UseLess", 1),
EnumField("ViewSizePreference_UseHalf", 2),
EnumField("ViewSizePreference_UseMore", 3),
EnumField("ViewSizePreference_UseMinimum", 4),
EnumField("ViewSizePreference_UseNone", 5),
),
),
Enum(
"windows_ui_windowmanagement",
"WindowingEnvironmentKind",
(EnumField("WindowingEnvironmentKind", 0),),
),
]


# TODO create functions for IApplicationView, IApplicationView2,
# IApplicationView3, IApplicationView4, IApplicationView7


def iids():
"""Returns all the IID instances defined as ``Uid`` named tuple

:returns: list
"""
return [
Uid("inspectable", "IInspectable", "AF86E2E0-B12D-4C6A-9C5A-D7AA65101E90"),
Uid("objectarray", "IObjectArray", "92CA9DCD-5622-4BBA-A805-5E9F541BD8C9"),
Uid("servprov", "IServiceProvider", "6D5140C1-7436-11CE-8034-00AA006009FA"),
Uid("shobjidl_core", "IVirtualDesktop", "FF72FFDD-BE7E-43FC-9C03-AD81681E88E4"),
Uid(
"shobjidl_core",
"IVirtualDesktopNotification",
"C179334C-4295-40D3-BEA1-C654D965605A",
),
Uid(
"shobjidl_core",
"IVirtualDesktopNotificationService",
"0CD45E71-D927-4F15-8B0A-8FEF525337BF",
),
Uid(
"shobjidl_core",
"IVirtualDesktopManagerInternal",
"F31574D6-B682-4CDC-BD56-1827860ABEC6",
),
Uid(
"shobjidl_core",
"IVirtualDesktopManager",
"A5CD92FF-29BE-454C-8D04-D82879FB3F1B",
),
Uid(
"shobjidl_core",
"IVirtualDesktopPinnedApps",
"4CE81583-1E4C-4632-A621-07A53543148F",
),
Uid(
"windows_ui_viewmanagement",
"IApplicationView",
"D222D519-4361-451E-96C4-60F4F9742DB0",
),
Uid(
"windows_ui_viewmanagement",
"IApplicationView2",
"E876B196-A545-40DC-B594-450CBA68CC00",
),
Uid(
"windows_ui_viewmanagement",
"IApplicationView3",
"903C9CE5-793A-4FDF-A2B2-AF1AC21E3108",
),
Uid(
"windows_ui_viewmanagement",
"IApplicationView4",
"15E5CBEC-9E0F-46B5-BC3F-9BF653E74B5E",
),
Uid(
"windows_ui_viewmanagement",
"IApplicationView7",
"A0369647-5FAF-5AA6-9C38-BEFBB12A071E",
),
Uid(
"windows_ui_viewmanagement",
"IApplicationView9",
"9C6516F9-021A-5F01-93E5-9BDAD2647574",
),
Uid(
"windows_ui_viewmanagement",
"IApplicationViewTitleBar",
"00924AC0-932B-4A6B-9C4B-DC38C82478CE",
),
Uid(
"windows_ui_viewmanagement",
"IViewModePreferences",
"878FCD3A-0B99-42C9-84D0-D3F1D403554B",
),
Uid(
"windows_ui_viewmanagement",
"IApplicationViewCollection",
"1841C6D7-4F9D-42C0-AF41-8747538F10E5",
),
Uid(
"windows_ui_viewmanagement",
"IApplicationViewConsolidatedEventArgs",
"514449EC-7EA2-4DE7-A6A6-7DFBAAEBB6FB",
),
Uid(
"windows_ui_windowmanagement",
"IWindowingEnvironment",
"264363C0-2A49-5417-B3AE-48A71C63A3BD",
),
Uid(
"windows_ui_windowmanagement",
"IDisplayRegion",
"DB50C3A2-4094-5F47-8CB1-EA01DDAFAA94",
),
Uid(
"windows_ui_windowmanagement",
"IWindowingEnvironmentChangedEventArgs",
"4160CFC6-023D-5E9A-B431-350E67DC978A",
),
]


def iinspectables():
"""Returns all the classes subclassed from IInspectable

defined as ``Interface`` named tuple with ``methods`` (last field) as
tuple of ``Method`` named tuples.

:returns: list
"""
return [
Interface(
"windows_ui_viewmanagement",
"IApplicationViewConsolidatedEventArgs",
True,
get_attr(
"windows_ui_viewmanagement", "IID_IApplicationViewConsolidatedEventArgs"
),
[],
(
Method(
HRESULT, "get_IsUserInitiated", (POINTER(BOOL),), ((10, "value"),)
),
),
),
# TODO the rest of IInspectable
]


def iunknowns():
"""Returns all the classes subclassed from comtypes.IUnknown

defined as ``Interface`` named tuple with ``methods`` (last field) as
tuple of ``Method`` named tuples.

:returns: list
"""
return [
Interface(
"inspectable",
"IInspectable",
True,
get_attr("inspectable", "IID_IInspectable"),
[],
(
Method(
HRESULT,
"GetIids",
(POINTER(ULONG), POINTER(POINTER(IID))),
((2, "iidCount"), (2, "iids")),
),
Method(
HRESULT,
"GetRuntimeClassName",
(POINTER(POINTER(get_attr("inspectable", "HSTRING__"))),),
((2, "className"),),
),
Method(
HRESULT,
"GetTrustLevel",
(POINTER(get_attr("inspectable", "TrustLevel")),),
((2, "trustLevel"),),
),
),
),
# TODO the rest of comtypes.IUnknown
]


# Interface = namedtuple("Interface", "module name case iid idlflags methods")
# Method = namedtuple("Method", "restype name argtypes paramflags idlflags helptext")


def structures():
"""Returns all the structures defined as ``Structure`` named tuple

and with ``field`` (third element) as tuple of ``StructureField`` named tuples.

:returns: list
"""
return [
Structure(
"eventtoken",
"EventRegistrationToken",
(StructureField("value", ctypes.c_int64),),
),
Structure("inspectable", "HSTRING__", (StructureField("unused", INT),)),
Structure(
"windows_foundation",
"Rect",
(
StructureField("X", FLOAT),
StructureField("Y", FLOAT),
StructureField("Width", FLOAT),
StructureField("Height", FLOAT),
),
),
Structure(
"windows_foundation",
"Size",
(StructureField("Width", FLOAT), StructureField("Height", FLOAT)),
),
Structure(
"windows_foundation",
"Point",
(StructureField("X", FLOAT), StructureField("Y", FLOAT)),
),
Structure(
"windows_ui",
"Color",
(
StructureField("A", BYTE),
StructureField("R", BYTE),
StructureField("G", BYTE),
StructureField("B", BYTE),
),
),
]
2 changes: 2 additions & 0 deletions tests/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
comtypes>=1.1.4
pytest>=4.0
Loading