score/containers: Extend unit tests#264
Open
crimson11 wants to merge 1 commit into
Open
Conversation
|
The created documentation from the pull request is available at: docu-html |
e8fe2ce to
2052bf6
Compare
Added test infrastructure for allocater/ pointer mocking/spying. Added unit tests for handling of bounds-checking support.
2052bf6 to
7da90c1
Compare
There was a problem hiding this comment.
Pull request overview
This PR extends score/containers unit test capabilities by introducing a new “mockable” allocator/pointer infrastructure that can spy on fancy-pointer operations (useful for validating bounds-checking related behavior), and adds targeted tests for NonRelocatableVector pointer interactions.
Changes:
- Added
MockableAllocator,MockablePointer, andPointerSpyMocktest utilities (plus an RAII guard) to support pointer-operation spying in tests. - Replaced/removes the previous
custom_allocator_mocktest helper and updates Bazel targets/deps accordingly. - Added new
NonRelocatableVectortests that assert first/last element address checks are performed via fancy-pointer operations.
Reviewed changes
Copilot reviewed 14 out of 14 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| score/containers/test/pointer_spy_mock.h | Adds gMock-based spy interface for recording pointer operations. |
| score/containers/test/pointer_spy_mock.cpp | TU wrapper include for the new spy header. |
| score/containers/test/mockable_pointer.h | Adds a fancy-pointer wrapper that can report operations to the spy. |
| score/containers/test/mockable_pointer.cpp | TU wrapper include for the new mockable pointer header. |
| score/containers/test/mockable_pointer_mock_guard.h | Adds RAII guard to set/clear the global spy pointer during a scope. |
| score/containers/test/mockable_pointer_mock_guard.cpp | TU wrapper include for the new guard header. |
| score/containers/test/mockable_allocator.h | Adds allocator wrapper returning MockablePointer<T> for allocator-aware container tests. |
| score/containers/test/mockable_allocator.cpp | Updates TU wrapper to include mockable_allocator.h. |
| score/containers/test/custom_allocator_mock.h | Removes legacy custom allocator mock helper. |
| score/containers/test/BUILD | Replaces custom_allocator_mock with mockable_allocator library target and updates sources/headers. |
| score/containers/non_relocatable_vector.h | Removes an unused <iostream> include. |
| score/containers/non_relocatable_vector_test.cpp | Adds pointer-interaction tests using the new spy infrastructure. |
| score/containers/dynamic_array_test.cpp | Removes legacy custom allocator mock include and adjusts comment formatting. |
| score/containers/BUILD | Switches unit tests from custom_allocator_mock to mockable_allocator dependency. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+263
to
+264
| score::memory::shared::test::MyMemoryResource memory_resource_{}; | ||
| std::unique_ptr<NonRelocatableVector<ElementType, Allocator>> unit_{nullptr}; |
Comment on lines
+57
to
+61
| /// \brief Clear the spy mock. Operations revert to pure pointer behavior (no recording). | ||
| static void ClearMock() noexcept | ||
| { | ||
| mock_ = nullptr; | ||
| } |
Comment on lines
+28
to
+46
| template <typename T> | ||
| class MockablePointerMockGuard | ||
| { | ||
| public: | ||
| explicit MockablePointerMockGuard(PointerSpyMock<T>* mock) noexcept | ||
| { | ||
| MockablePointer<T>::SetMock(mock); | ||
| } | ||
|
|
||
| ~MockablePointerMockGuard() noexcept | ||
| { | ||
| MockablePointer<T>::ClearMock(); | ||
| } | ||
|
|
||
| MockablePointerMockGuard(const MockablePointerMockGuard&) = delete; | ||
| MockablePointerMockGuard& operator=(const MockablePointerMockGuard&) = delete; | ||
| MockablePointerMockGuard(MockablePointerMockGuard&&) = delete; | ||
| MockablePointerMockGuard& operator=(MockablePointerMockGuard&&) = delete; | ||
| }; |
Comment on lines
+28
to
+29
| /// By default, MockablePointer behaves identically to a raw pointer. All arithmetic, compare and dereference | ||
| /// operations are forwarded to the underlying raw pointer. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Added test infrastructure for allocater/
pointer mocking/spying.
Added unit tests for handling of bounds-checking
support.