-
Notifications
You must be signed in to change notification settings - Fork 2
Ensure Records are treated as separate namespaces for IDs #63
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| /* | ||
| * Copyright (c) 2026 Brill Power. | ||
| * | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
| #include "gtest/gtest.h" | ||
| #include <thingset++/ThingSet.hpp> | ||
|
|
||
| // >>> NOTE <<< | ||
| // | ||
| // If this test binary links successfully, static init didn't trip the | ||
| // spurious dedup assert which is a regression in itself | ||
|
|
||
| using namespace ThingSet; | ||
|
|
||
| namespace { | ||
|
|
||
| // Two distinct record types declaring members with the same raw template | ||
| // ids (0x7BA, 0x7BB) under different parent record ids (0x7B0, 0x7B1). | ||
| // Record members are namespaced by their parent record | ||
| struct RecordA | ||
| { | ||
| ThingSetReadOnlyRecordMember<0x7BA, 0x7B0, "alpha", uint64_t> alpha; | ||
| ThingSetReadOnlyRecordMember<0x7BB, 0x7B0, "beta", uint32_t> beta; | ||
| }; | ||
|
|
||
| struct RecordB | ||
| { | ||
| ThingSetReadOnlyRecordMember<0x7BA, 0x7B1, "alpha", uint64_t> alpha; | ||
| ThingSetReadOnlyRecordMember<0x7BB, 0x7B1, "beta", uint32_t> beta; | ||
| }; | ||
|
|
||
| ThingSetReadOnlyProperty<std::array<RecordA, 2>> recordsA{ 0x7B0, 0x0, "recordsA" }; | ||
| ThingSetReadOnlyProperty<std::array<RecordB, 1>> recordsB{ 0x7B1, 0x0, "recordsB" }; | ||
|
|
||
| } // namespace | ||
|
|
||
| TEST(RecordMemberNamespaces, BothParentRecordsRegister) | ||
| { | ||
| ThingSetNode *node; | ||
| ASSERT_TRUE(ThingSetRegistry::findById(0x7B0, &node)); | ||
| EXPECT_EQ("recordsA", node->getName()); | ||
| ASSERT_TRUE(ThingSetRegistry::findById(0x7B1, &node)); | ||
| EXPECT_EQ("recordsB", node->getName()); | ||
| } | ||
|
|
||
| TEST(RecordMemberNamespaces, FindByIdDisambiguatesByParent) | ||
| { | ||
| // Both record types share raw member id 0x7BA. Their proxies land in | ||
| // the same bucket because the parent id contribution to the bucket | ||
| // hash is a multiple of 8 and cancels. findById(rawId, parentId) must | ||
| // therefore also filter on parent id | ||
| ThingSetNode *alphaA = nullptr; | ||
| ASSERT_TRUE(ThingSetRegistry::findById(0x7BA, 0x7B0, &alphaA)); | ||
| EXPECT_EQ(0x7B0, alphaA->getParentId()); | ||
|
|
||
| ThingSetNode *alphaB = nullptr; | ||
| ASSERT_TRUE(ThingSetRegistry::findById(0x7BA, 0x7B1, &alphaB)); | ||
| EXPECT_EQ(0x7B1, alphaB->getParentId()); | ||
|
|
||
| EXPECT_NE(alphaA, alphaB) << "findById returned the same proxy for both parents"; | ||
|
|
||
| // And again for the second shared id, to cover the neighbouring bucket | ||
| ThingSetNode *betaA = nullptr; | ||
| ASSERT_TRUE(ThingSetRegistry::findById(0x7BB, 0x7B0, &betaA)); | ||
| EXPECT_EQ(0x7B0, betaA->getParentId()); | ||
|
|
||
| ThingSetNode *betaB = nullptr; | ||
| ASSERT_TRUE(ThingSetRegistry::findById(0x7BB, 0x7B1, &betaB)); | ||
| EXPECT_EQ(0x7B1, betaB->getParentId()); | ||
|
|
||
| EXPECT_NE(betaA, betaB); | ||
| } | ||
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is this comment regarding?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was in regards to the
alphaandbetamembers of the two records. Pre-this-fix, this wouldn't build, so any build failure linked to these properties is a regressionThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, we're at quite an exciting point now where we are working on system integration as a whole - keep an eye on this space!