Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jatinchowdhury18 committed Oct 23, 2024
1 parent 0dac914 commit 099baf1
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,14 @@ struct OptionalPointer
OptionalPointer (OptionalPointer&& other) noexcept
{
invalidate();
pointer = other.pointer;
other.pointer.set (nullptr);
pointer.swap (other.pointer);
}

/** Move assignment */
OptionalPointer& operator= (OptionalPointer&& other) noexcept
{
invalidate();
pointer = other.pointer;
other.pointer.set (nullptr);
pointer.swap (other.pointer);
return *this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,14 @@ struct PackedPointer
[[nodiscard]] T& operator*() { return *get_ptr(); }
[[nodiscard]] const T& operator*() const { return *get_ptr(); }

void swap (PackedPointer& other) noexcept
{
std::swap (other.ptr_with_flags, ptr_with_flags);
#if JUCE_DEBUG
std::swap (other.actual_ptr, actual_ptr);
#endif
}

private:
T* ptr_with_flags = nullptr;
#if JUCE_DEBUG
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,4 +130,21 @@ TEST_CASE ("Optional Pointer Test", "[common][data-structures]")
REQUIRE (x == y);
REQUIRE_FALSE (x != y);
}

SECTION ("Move Constructor")
{
chowdsp::OptionalPointer<TestType> x { 4, 5 };
chowdsp::OptionalPointer<TestType> y { std::move (x) };
REQUIRE (x == nullptr); // NOLINT
REQUIRE (y->x == 4);
REQUIRE (y->y == 5);
}

SECTION ("Move Assignment")
{
chowdsp::OptionalPointer<TestType> y {};
y = chowdsp::OptionalPointer<TestType> { 4, 5 };
REQUIRE (y->x == 4);
REQUIRE (y->y == 5);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,17 @@ TEST_CASE ("Packed Pointer Test", "[common][data-structures]")

SECTION ("Modify")
{
chowdsp::PackedPointer<TestType> ptr { &t1, 5 };
chowdsp::PackedPointer ptr { &t1, 5 };
ptr->x = 100;
REQUIRE (std::as_const (ptr)->x == t1.x);
}

SECTION ("Swap")
{
chowdsp::PackedPointer ptr { &t1, 5 };
chowdsp::PackedPointer<TestType> ptr2 {};
ptr.swap (ptr2);
REQUIRE (ptr == nullptr);
REQUIRE (std::as_const (ptr2)->x == t1.x);
}
}

0 comments on commit 099baf1

Please sign in to comment.