winpty/misc/buffer-tests/harness/Event.cc
Ryan Prichard 3575c55c8c Expand console handle testing for XP through Windows 7.
* The tests are mostly wrong for Windows 8 and up.
2015-10-21 19:56:06 -05:00

32 lines
709 B
C++

#include "Event.h"
#include "UnicodeConversions.h"
#include <WinptyAssert.h>
Event::Event(const std::string &name) {
// Create manual-reset, not signaled initially.
m_handle = CreateEventW(NULL, TRUE, FALSE, widenString(name).c_str());
ASSERT(m_handle != NULL);
}
Event::~Event() {
if (m_handle != NULL) {
CloseHandle(m_handle);
}
}
void Event::set() {
BOOL ret = SetEvent(m_handle);
ASSERT(ret && "SetEvent failed");
}
void Event::reset() {
BOOL ret = ResetEvent(m_handle);
ASSERT(ret && "ResetEvent failed");
}
void Event::wait() {
DWORD ret = WaitForSingleObject(m_handle, INFINITE);
ASSERT(ret == WAIT_OBJECT_0 && "WaitForSingleObject failed");
}