mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 07:37:46 +00:00
Tests: Move AK tests to Tests/AK
This commit is contained in:
parent
fd0dbd1ebf
commit
67322b0702
64 changed files with 1 additions and 2 deletions
73
Tests/AK/TestNeverDestroyed.cpp
Normal file
73
Tests/AK/TestNeverDestroyed.cpp
Normal file
|
@ -0,0 +1,73 @@
|
|||
/*
|
||||
* Copyright (c) 2020, the SerenityOS developers.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <LibTest/TestCase.h>
|
||||
|
||||
#include <AK/NeverDestroyed.h>
|
||||
#include <AK/StdLibExtras.h>
|
||||
|
||||
struct Counter {
|
||||
Counter() = default;
|
||||
|
||||
~Counter() { ++num_destroys; }
|
||||
|
||||
Counter(const Counter&)
|
||||
{
|
||||
++num_copies;
|
||||
}
|
||||
|
||||
Counter(Counter&&) { ++num_moves; }
|
||||
|
||||
int num_copies {};
|
||||
int num_moves {};
|
||||
int num_destroys {};
|
||||
};
|
||||
|
||||
TEST_CASE(should_construct_by_copy)
|
||||
{
|
||||
Counter c {};
|
||||
AK::NeverDestroyed<Counter> n { c };
|
||||
|
||||
EXPECT_EQ(1, n->num_copies);
|
||||
EXPECT_EQ(0, n->num_moves);
|
||||
}
|
||||
|
||||
TEST_CASE(should_construct_by_move)
|
||||
{
|
||||
Counter c {};
|
||||
AK::NeverDestroyed<Counter> n { move(c) };
|
||||
|
||||
EXPECT_EQ(0, n->num_copies);
|
||||
EXPECT_EQ(1, n->num_moves);
|
||||
}
|
||||
|
||||
TEST_CASE(should_not_destroy)
|
||||
{
|
||||
Counter* c = nullptr;
|
||||
{
|
||||
AK::NeverDestroyed<Counter> n {};
|
||||
c = &n.get();
|
||||
}
|
||||
EXPECT_EQ(0, c->num_destroys);
|
||||
}
|
||||
|
||||
TEST_CASE(should_provide_dereference_operator)
|
||||
{
|
||||
AK::NeverDestroyed<Counter> n {};
|
||||
EXPECT_EQ(0, n->num_destroys);
|
||||
}
|
||||
|
||||
TEST_CASE(should_provide_indirection_operator)
|
||||
{
|
||||
AK::NeverDestroyed<Counter> n {};
|
||||
EXPECT_EQ(0, (*n).num_destroys);
|
||||
}
|
||||
|
||||
TEST_CASE(should_provide_basic_getter)
|
||||
{
|
||||
AK::NeverDestroyed<Counter> n {};
|
||||
EXPECT_EQ(0, n.get().num_destroys);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue