mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-25 17:10:23 +00:00
Tests+LibThreading: Add new tests for LibThreading for detach()
This commit is contained in:
parent
48731e9f17
commit
dd3996e207
Notes:
sideshowbarker
2024-07-18 11:07:01 +09:00
Author: https://github.com/SpencerCDixon Commit: https://github.com/SerenityOS/serenity/commit/dd3996e2075 Pull-request: https://github.com/SerenityOS/serenity/pull/8385 Reviewed-by: https://github.com/gunnarbeutner
2 changed files with 38 additions and 0 deletions
4
Tests/LibThreading/CMakeLists.txt
Normal file
4
Tests/LibThreading/CMakeLists.txt
Normal file
|
@ -0,0 +1,4 @@
|
|||
file(GLOB TEST_SOURCES CONFIGURE_DEPENDS "*.cpp")
|
||||
foreach(source ${TEST_SOURCES})
|
||||
serenity_test(${source} LibThreading LIBS LibThreading LibPthread)
|
||||
endforeach()
|
34
Tests/LibThreading/TestThread.cpp
Normal file
34
Tests/LibThreading/TestThread.cpp
Normal file
|
@ -0,0 +1,34 @@
|
|||
/*
|
||||
* Copyright (c) 2021, Spencer Dixon <spencercdixon@gmail.com>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <LibTest/TestCase.h>
|
||||
#include <LibThreading/Thread.h>
|
||||
#include <unistd.h>
|
||||
|
||||
TEST_CASE(threads_can_detach)
|
||||
{
|
||||
int should_be_42 = 0;
|
||||
|
||||
auto thread = Threading::Thread::construct([&should_be_42]() {
|
||||
usleep(10 * 1000);
|
||||
should_be_42 = 42;
|
||||
return 0;
|
||||
});
|
||||
thread->start();
|
||||
thread->detach();
|
||||
usleep(20 * 1000);
|
||||
|
||||
EXPECT(should_be_42 == 42);
|
||||
}
|
||||
|
||||
TEST_CASE(joining_detached_thread_errors)
|
||||
{
|
||||
auto thread = Threading::Thread::construct([]() { return 0; });
|
||||
thread->start();
|
||||
thread->detach();
|
||||
|
||||
EXPECT(thread->join().is_error());
|
||||
}
|
Loading…
Reference in a new issue