Skip to content

Commit

Permalink
Merge branch 'master' into 124-GetTempPath
Browse files Browse the repository at this point in the history
  • Loading branch information
opalmer authored Oct 29, 2017
2 parents 08d6fa0 + f2db400 commit e07024b
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 2 deletions.
1 change: 1 addition & 0 deletions docs/source/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ Notable enhancements and changes are:
nosetests with pytest, transition from pep8 to pycodestyle and upgrading
tools and libraries to more modern versions.
* :issue:`124` - Implemented :func:`pywincffi.kernel32.file.GetTempPath`
* :issue:`123` - Implemented :func:`pywincffi.kernel32.event.SetEvent`

0.4.0
~~~~~
Expand Down
5 changes: 5 additions & 0 deletions pywincffi/core/cdefs/headers/functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,11 @@ BOOL WINAPI ResetEvent(
_In_ HANDLE hEvent
);

// https://msdn.microsoft.com/en-us/library/ms686211
BOOL WINAPI SetEvent(
_In_ HANDLE hEvent
);

///////////////////////
// Communications
///////////////////////
Expand Down
3 changes: 2 additions & 1 deletion pywincffi/kernel32/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
from pywincffi.kernel32.process import (
GetProcessId, GetCurrentProcess, OpenProcess, GetExitCodeProcess,
TerminateProcess, CreateToolhelp32Snapshot, CreateProcess, pid_exists)
from pywincffi.kernel32.events import CreateEvent, OpenEvent, ResetEvent
from pywincffi.kernel32.events import (
CreateEvent, OpenEvent, ResetEvent, SetEvent)
from pywincffi.kernel32.comms import ClearCommError
from pywincffi.kernel32.synchronization import WaitForSingleObject
from pywincffi.kernel32.overlapped import GetOverlappedResult
19 changes: 19 additions & 0 deletions pywincffi/kernel32/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,3 +125,22 @@ def ResetEvent(hEvent):
_, library = dist.load()
code = library.ResetEvent(wintype_to_cdata(hEvent))
error_check("ResetEvent", code=code, expected=NON_ZERO)


def SetEvent(hEvent):
"""
Sets the specified event object to the signaled state.
.. seealso::
https://msdn.microsoft.com/en-us/library/ms686211
:param pywincffi.wintypes.HANDLE hEvent:
A handle to the event object. The handle must have the
``EVENT_MODIFY_STATE`` access right.
"""
input_check("hEvent", hEvent, HANDLE)

_, library = dist.load()
code = library.SetEvent(wintype_to_cdata(hEvent))
error_check("SetEvent", code=code, expected=NON_ZERO)
23 changes: 22 additions & 1 deletion tests/test_kernel32/test_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
from pywincffi.exceptions import WindowsAPIError, InputError
from pywincffi.kernel32 import events # used by mocks
from pywincffi.kernel32 import (
CloseHandle, CreateEvent, OpenEvent, ResetEvent, WaitForSingleObject)
CloseHandle, CreateEvent, OpenEvent, ResetEvent, WaitForSingleObject,
SetEvent)


# These tests cause TestPidExists and others to fail under Python 3.4 so for
Expand Down Expand Up @@ -108,3 +109,23 @@ def test_resets_event(self):

_, library = dist.load()
self.assertEqual(WaitForSingleObject(handle, 0), library.WAIT_TIMEOUT)


class TestSetEvent(TestCase):
"""
Tests for :func:`pywincffi.kernel32.SetEvent`
"""
def test_signaled(self):
handle = CreateEvent(True, False)
self.addCleanup(CloseHandle, handle)
_, library = dist.load()
SetEvent(handle)
self.assertEqual(
WaitForSingleObject(handle, 0), library.WAIT_OBJECT_0)

def test_not_signaled(self):
handle = CreateEvent(True, False)
self.addCleanup(CloseHandle, handle)
_, library = dist.load()
self.assertEqual(
WaitForSingleObject(handle, 0), library.WAIT_TIMEOUT)

0 comments on commit e07024b

Please sign in to comment.