diff options
author | Andreas Kling <awesomekling@gmail.com> | 2019-08-14 11:02:49 +0200 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2019-08-14 11:04:19 +0200 |
commit | f75b1127b2f0ae22af04ae590ba22652f5092f5f (patch) | |
tree | 577d35786fa61716c7adda0504bc2a0e86799598 /AK/Tests | |
parent | 99ed4ce30cad04f6fed3758c94fdf4357e27ae6c (diff) | |
download | serenity-f75b1127b2f0ae22af04ae590ba22652f5092f5f.zip |
OwnPtr: Add a way to turn an OwnPtr into a NonnullOwnPtr
Okay, so, OwnPtr<T>::release_nonnull() returns a NonnullOwnPtr<T>.
It assumes that the OwnPtr is non-null to begin with.
Note that this removes the value from the OwnPtr, as there can only be
a single owner.
Diffstat (limited to 'AK/Tests')
-rw-r--r-- | AK/Tests/TestVector.cpp | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/AK/Tests/TestVector.cpp b/AK/Tests/TestVector.cpp index 351a7aeedd..1ad7aa7c26 100644 --- a/AK/Tests/TestVector.cpp +++ b/AK/Tests/TestVector.cpp @@ -1,6 +1,7 @@ #include <AK/TestSuite.h> #include <AK/AKString.h> +#include <AK/NonnullOwnPtrVector.h> #include <AK/OwnPtr.h> #include <AK/Vector.h> @@ -252,4 +253,20 @@ TEST_CASE(vector_remove) EXPECT_EQ(ints[0], 4); } +TEST_CASE(nonnullownptrvector) +{ + struct Object { + String string; + }; + NonnullOwnPtrVector<Object> objects; + + objects.append(make<Object>()); + EXPECT_EQ(objects.size(), 1); + + OwnPtr<Object> o = make<Object>(); + objects.append(o.release_nonnull()); + EXPECT(o == nullptr); + EXPECT_EQ(objects.size(), 2); +} + TEST_MAIN(Vector) |