ladybird/AK/Tests/TestNonnullRefPtr.cpp
Andreas Kling 73fdbba59c AK: Rename <AK/AKString.h> to <AK/String.h>
This was a workaround to be able to build on case-insensitive file
systems where it might get confused about <string.h> vs <String.h>.

Let's just not support building that way, so String.h can have an
objectively nicer name. :^)
2019-09-06 15:36:54 +02:00

36 lines
720 B
C++

#include <AK/TestSuite.h>
#include <AK/NonnullRefPtr.h>
#include <AK/String.h>
struct Object : public RefCounted<Object> {
int x;
};
TEST_CASE(basics)
{
auto object = adopt(*new Object);
EXPECT(object.ptr() != nullptr);
EXPECT_EQ(object->ref_count(), 1);
object->ref();
EXPECT_EQ(object->ref_count(), 2);
object->deref();
EXPECT_EQ(object->ref_count(), 1);
{
NonnullRefPtr another = object;
EXPECT_EQ(object->ref_count(), 2);
}
EXPECT_EQ(object->ref_count(), 1);
}
TEST_CASE(assign_reference)
{
auto object = adopt(*new Object);
EXPECT_EQ(object->ref_count(), 1);
object = *object;
EXPECT_EQ(object->ref_count(), 1);
}
TEST_MAIN(String)