Skip to content
Open
Changes from 1 commit
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
66 changes: 66 additions & 0 deletions test/old_tests/UnitTests/async.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -407,13 +407,16 @@ TEST_CASE("async, Throw_IAsyncAction")

bool completed = false;

handle eventCompleted { CreateEvent(nullptr, false, false, nullptr)};
async.Completed([&](const IAsyncAction & sender, AsyncStatus status)
{
completed = true;
REQUIRE(async == sender);
REQUIRE(status == AsyncStatus::Error);
SetEvent(eventCompleted.get());
});

REQUIRE(WaitForSingleObject(eventCompleted.get(), INFINITE) == WAIT_OBJECT_0);
REQUIRE(completed);
Comment thread
YexuanXiao marked this conversation as resolved.
Outdated

try
Expand Down Expand Up @@ -498,13 +501,16 @@ TEST_CASE("async, Throw_IAsyncActionWithProgress")

bool completed = false;

handle eventCompleted { CreateEvent(nullptr, false, false, nullptr)};
async.Completed([&](const IAsyncActionWithProgress<double> & sender, AsyncStatus status)
{
completed = true;
REQUIRE(async == sender);
REQUIRE(status == AsyncStatus::Error);
SetEvent(eventCompleted.get());
});

REQUIRE(WaitForSingleObject(eventCompleted.get(), INFINITE) == WAIT_OBJECT_0);
REQUIRE(completed);

try
Expand Down Expand Up @@ -589,13 +595,16 @@ TEST_CASE("async, Throw_IAsyncOperation")

bool completed = false;

handle eventCompleted { CreateEvent(nullptr, false, false, nullptr)};
async.Completed([&](const IAsyncOperation<uint32_t> & sender, AsyncStatus status)
{
completed = true;
REQUIRE(async == sender);
REQUIRE(status == AsyncStatus::Error);
SetEvent(eventCompleted.get());
});

REQUIRE(WaitForSingleObject(eventCompleted.get(), INFINITE) == WAIT_OBJECT_0);
REQUIRE(completed);

try
Expand Down Expand Up @@ -680,13 +689,16 @@ TEST_CASE("async, Throw_IAsyncOperationWithProgress")

bool completed = false;

handle eventCompleted { CreateEvent(nullptr, false, false, nullptr)};
async.Completed([&](const IAsyncOperationWithProgress<uint64_t, uint64_t> & sender, AsyncStatus status)
{
completed = true;
REQUIRE(async == sender);
REQUIRE(status == AsyncStatus::Error);
SetEvent(eventCompleted.get());
});

REQUIRE(WaitForSingleObject(eventCompleted.get(), INFINITE) == WAIT_OBJECT_0);
REQUIRE(completed);

try
Expand Down Expand Up @@ -830,13 +842,16 @@ TEST_CASE("async, Cancel_IAsyncAction")
bool objectMatches = false;
bool statusMatches = false;

handle eventCompleted { CreateEvent(nullptr, false, false, nullptr)};
async.Completed([&](const IAsyncAction & sender, AsyncStatus status)
{
completed = true;
objectMatches = (async == sender);
statusMatches = (status == AsyncStatus::Canceled);
SetEvent(eventCompleted.get());
});

REQUIRE(WaitForSingleObject(eventCompleted.get(), INFINITE) == WAIT_OBJECT_0);
REQUIRE(completed);
REQUIRE(objectMatches);
REQUIRE(statusMatches);
Expand All @@ -858,16 +873,19 @@ TEST_CASE("async, Cancel_IAsyncAction, 2")
bool objectMatches = false;
bool statusMatches = false;

handle eventCompleted { CreateEvent(nullptr, false, false, nullptr)};
async.Completed([&](const IAsyncAction & sender, AsyncStatus status)
{
completed = true;
objectMatches = (async == sender);
statusMatches = (status == AsyncStatus::Canceled);
SetEvent(eventCompleted.get());
});

async.Cancel();
SetEvent(event.get()); // signal async to run
REQUIRE(WaitForSingleObject(event.get(), INFINITE) == WAIT_OBJECT_0); // wait for async to be canceled
REQUIRE(WaitForSingleObject(eventCompleted.get(), INFINITE) == WAIT_OBJECT_0);
REQUIRE(async.Status() == AsyncStatus::Canceled);
REQUIRE_THROWS_AS(async.GetResults(), hresult_canceled);
REQUIRE(async.ErrorCode() == HRESULT_FROM_WIN32(ERROR_CANCELLED));
Expand Down Expand Up @@ -901,13 +919,16 @@ TEST_CASE("async, Cancel_IAsyncActionWithProgress")
bool objectMatches = false;
bool statusMatches = false;

handle eventCompleted { CreateEvent(nullptr, false, false, nullptr)};
async.Completed([&](const IAsyncActionWithProgress<double> & sender, AsyncStatus status)
{
completed = true;
objectMatches = (async == sender);
statusMatches = (status == AsyncStatus::Canceled);
SetEvent(eventCompleted.get());
});

REQUIRE(WaitForSingleObject(eventCompleted.get(), INFINITE) == WAIT_OBJECT_0);
REQUIRE(completed);
REQUIRE(objectMatches);
REQUIRE(statusMatches);
Expand All @@ -930,16 +951,19 @@ TEST_CASE("async, Cancel_IAsyncActionWithProgress, 2")
bool objectMatches = false;
bool statusMatches = false;

handle eventCompleted { CreateEvent(nullptr, false, false, nullptr)};
async.Completed([&](const IAsyncActionWithProgress<double> & sender, AsyncStatus status)
{
completed = true;
objectMatches = (async == sender);
statusMatches = (status == AsyncStatus::Canceled);
SetEvent(eventCompleted.get());
});

async.Cancel();
SetEvent(event.get()); // signal async to run
REQUIRE(WaitForSingleObject(event.get(), INFINITE) == WAIT_OBJECT_0); // wait for async to be canceled
REQUIRE(WaitForSingleObject(eventCompleted.get(), INFINITE) == WAIT_OBJECT_0);
REQUIRE(async.Status() == AsyncStatus::Canceled);
REQUIRE_THROWS_AS(async.GetResults(), hresult_canceled);
REQUIRE(async.ErrorCode() == HRESULT_FROM_WIN32(ERROR_CANCELLED));
Expand Down Expand Up @@ -972,13 +996,16 @@ TEST_CASE("async, Cancel_IAsyncOperation")
bool objectMatches = false;
bool statusMatches = false;

handle eventCompleted { CreateEvent(nullptr, false, false, nullptr)};
async.Completed([&](const IAsyncOperation<uint32_t> & sender, AsyncStatus status)
{
completed = true;
objectMatches = (async == sender);
statusMatches = (status == AsyncStatus::Canceled);
SetEvent(eventCompleted.get());
});

REQUIRE(WaitForSingleObject(eventCompleted.get(), INFINITE) == WAIT_OBJECT_0);
REQUIRE(completed);
REQUIRE(objectMatches);
REQUIRE(statusMatches);
Expand All @@ -1000,16 +1027,20 @@ TEST_CASE("async, Cancel_IAsyncOperation, 2")
bool objectMatches = false;
bool statusMatches = false;

handle eventCompleted { CreateEvent(nullptr, false, false, nullptr)};
async.Completed([&](const IAsyncOperation<uint32_t> & sender, AsyncStatus status)
{
completed = true;
objectMatches = (async == sender);
statusMatches = (status == AsyncStatus::Canceled);
SetEvent(eventCompleted.get());
});

async.Cancel();
SetEvent(event.get()); // signal async to run
REQUIRE(WaitForSingleObject(event.get(), INFINITE) == WAIT_OBJECT_0); // wait for async to be canceled

REQUIRE(WaitForSingleObject(eventCompleted.get(), INFINITE) == WAIT_OBJECT_0);
REQUIRE(async.Status() == AsyncStatus::Canceled);
REQUIRE_THROWS_AS(async.GetResults(), hresult_canceled);
REQUIRE(async.ErrorCode() == HRESULT_FROM_WIN32(ERROR_CANCELLED));
Expand Down Expand Up @@ -1043,13 +1074,16 @@ TEST_CASE("async, Cancel_IAsyncOperationWithProgress")
bool objectMatches = false;
bool statusMatches = false;

handle eventCompleted { CreateEvent(nullptr, false, false, nullptr)};
async.Completed([&](const IAsyncOperationWithProgress<uint64_t, uint64_t> & sender, AsyncStatus status)
{
completed = true;
objectMatches = (async == sender);
statusMatches = (status == AsyncStatus::Canceled);
SetEvent(eventCompleted.get());
});

REQUIRE(WaitForSingleObject(eventCompleted.get(), INFINITE) == WAIT_OBJECT_0);
REQUIRE(completed);
REQUIRE(objectMatches);
REQUIRE(statusMatches);
Expand All @@ -1072,16 +1106,20 @@ TEST_CASE("async, Cancel_IAsyncOperationWithProgress, 2")
bool objectMatches = false;
bool statusMatches = false;

handle eventCompleted { CreateEvent(nullptr, false, false, nullptr)};
async.Completed([&](const IAsyncOperationWithProgress<uint64_t, uint64_t> & sender, AsyncStatus status)
{
completed = true;
objectMatches = (async == sender);
statusMatches = (status == AsyncStatus::Canceled);
SetEvent(eventCompleted.get());
});

async.Cancel();
SetEvent(event.get()); // signal async to run
REQUIRE(WaitForSingleObject(event.get(), INFINITE) == WAIT_OBJECT_0); // wait for async to be canceled

REQUIRE(WaitForSingleObject(eventCompleted.get(), INFINITE) == WAIT_OBJECT_0);
REQUIRE(async.Status() == AsyncStatus::Canceled);
REQUIRE_THROWS_AS(async.GetResults(), hresult_canceled);
REQUIRE(async.ErrorCode() == HRESULT_FROM_WIN32(ERROR_CANCELLED));
Expand Down Expand Up @@ -1164,13 +1202,16 @@ TEST_CASE("async, AutoCancel_IAsyncAction")
bool objectMatches = false;
bool statusMatches = false;

handle eventCompleted { CreateEvent(nullptr, false, false, nullptr)};
async.Completed([&](const IAsyncAction & sender, AsyncStatus status)
{
completed = true;
objectMatches = (async == sender);
statusMatches = (status == AsyncStatus::Canceled);
SetEvent(eventCompleted.get());
});

REQUIRE(WaitForSingleObject(eventCompleted.get(), INFINITE) == WAIT_OBJECT_0);
REQUIRE(completed);
REQUIRE(objectMatches);
REQUIRE(statusMatches);
Expand All @@ -1191,16 +1232,20 @@ TEST_CASE("async, AutoCancel_IAsyncAction, 2")
bool objectMatches = false;
bool statusMatches = false;

handle eventCompleted { CreateEvent(nullptr, false, false, nullptr)};
async.Completed([&](const IAsyncAction & sender, AsyncStatus status)
{
completed = true;
objectMatches = (async == sender);
statusMatches = (status == AsyncStatus::Canceled);
SetEvent(eventCompleted.get());
});

async.Cancel();
SetEvent(event.get()); // signal async to run
REQUIRE(WaitForSingleObject(event.get(), INFINITE) == WAIT_OBJECT_0); // wait for async to be canceled

REQUIRE(WaitForSingleObject(eventCompleted.get(), INFINITE) == WAIT_OBJECT_0);
REQUIRE(async.Status() == AsyncStatus::Canceled);
REQUIRE_THROWS_AS(async.GetResults(), hresult_canceled);

Expand Down Expand Up @@ -1230,13 +1275,16 @@ TEST_CASE("async, AutoCancel_IAsyncActionWithProgress")
bool objectMatches = false;
bool statusMatches = false;

handle eventCompleted { CreateEvent(nullptr, false, false, nullptr)};
async.Completed([&](const IAsyncActionWithProgress<double> & sender, AsyncStatus status)
{
completed = true;
objectMatches = (async == sender);
statusMatches = (status == AsyncStatus::Canceled);
SetEvent(eventCompleted.get());
});

REQUIRE(WaitForSingleObject(eventCompleted.get(), INFINITE) == WAIT_OBJECT_0);
REQUIRE(completed);
REQUIRE(objectMatches);
REQUIRE(statusMatches);
Expand All @@ -1257,16 +1305,20 @@ TEST_CASE("async, AutoCancel_IAsyncActionWithProgress, 2")
bool objectMatches = false;
bool statusMatches = false;

handle eventCompleted { CreateEvent(nullptr, false, false, nullptr)};
async.Completed([&](const IAsyncActionWithProgress<double> & sender, AsyncStatus status)
{
completed = true;
objectMatches = (async == sender);
statusMatches = (status == AsyncStatus::Canceled);
SetEvent(eventCompleted.get());
});

async.Cancel();
SetEvent(event.get()); // signal async to run
REQUIRE(WaitForSingleObject(event.get(), INFINITE) == WAIT_OBJECT_0); // wait for async to be canceled

REQUIRE(WaitForSingleObject(eventCompleted.get(), INFINITE) == WAIT_OBJECT_0);
REQUIRE(async.Status() == AsyncStatus::Canceled);
REQUIRE_THROWS_AS(async.GetResults(), hresult_canceled);

Expand Down Expand Up @@ -1296,13 +1348,16 @@ TEST_CASE("async, AutoCancel_IAsyncOperation")
bool objectMatches = false;
bool statusMatches = false;

handle eventCompleted { CreateEvent(nullptr, false, false, nullptr)};
async.Completed([&](const IAsyncOperation<uint32_t> & sender, AsyncStatus status)
{
completed = true;
objectMatches = (async == sender);
statusMatches = (status == AsyncStatus::Canceled);
SetEvent(eventCompleted.get());
});

REQUIRE(WaitForSingleObject(eventCompleted.get(), INFINITE) == WAIT_OBJECT_0);
REQUIRE(completed);
REQUIRE(objectMatches);
REQUIRE(statusMatches);
Expand All @@ -1323,16 +1378,20 @@ TEST_CASE("async, AutoCancel_IAsyncOperation, 2")
bool objectMatches = false;
bool statusMatches = false;

handle eventCompleted { CreateEvent(nullptr, false, false, nullptr)};
async.Completed([&](const IAsyncOperation<uint32_t> & sender, AsyncStatus status)
{
completed = true;
objectMatches = (async == sender);
statusMatches = (status == AsyncStatus::Canceled);
SetEvent(eventCompleted.get());
});

async.Cancel();
SetEvent(event.get()); // signal async to run
REQUIRE(WaitForSingleObject(event.get(), INFINITE) == WAIT_OBJECT_0); // wait for async to be canceled

REQUIRE(WaitForSingleObject(eventCompleted.get(), INFINITE) == WAIT_OBJECT_0);
REQUIRE(async.Status() == AsyncStatus::Canceled);
REQUIRE_THROWS_AS(async.GetResults(), hresult_canceled);

Expand Down Expand Up @@ -1362,13 +1421,16 @@ TEST_CASE("async, AutoCancel_IAsyncOperationWithProgress")
bool objectMatches = false;
bool statusMatches = false;

handle eventCompleted { CreateEvent(nullptr, false, false, nullptr)};
async.Completed([&](const IAsyncOperationWithProgress<uint64_t, uint64_t> & sender, AsyncStatus status)
{
completed = true;
objectMatches = (async == sender);
statusMatches = (status == AsyncStatus::Canceled);
SetEvent(eventCompleted.get());
});

REQUIRE(WaitForSingleObject(eventCompleted.get(), INFINITE) == WAIT_OBJECT_0);
REQUIRE(completed);
REQUIRE(objectMatches);
REQUIRE(statusMatches);
Expand All @@ -1389,16 +1451,20 @@ TEST_CASE("async, AutoCancel_IAsyncOperationWithProgress, 2")
bool objectMatches = false;
bool statusMatches = false;

handle eventCompleted { CreateEvent(nullptr, false, false, nullptr)};
async.Completed([&](const IAsyncOperationWithProgress<uint64_t, uint64_t> & sender, AsyncStatus status)
{
completed = true;
objectMatches = (async == sender);
statusMatches = (status == AsyncStatus::Canceled);
SetEvent(eventCompleted.get());
});

async.Cancel();
SetEvent(event.get()); // signal async to run
REQUIRE(WaitForSingleObject(event.get(), INFINITE) == WAIT_OBJECT_0); // wait for async to be canceled

REQUIRE(WaitForSingleObject(eventCompleted.get(), INFINITE) == WAIT_OBJECT_0);
REQUIRE(async.Status() == AsyncStatus::Canceled);
REQUIRE_THROWS_AS(async.GetResults(), hresult_canceled);

Expand Down